Commit a919619e authored by Paul Cercueil's avatar Paul Cercueil Committed by Miquel Raynal

mtd: rawnand: ingenic: Rename jz4780_nand driver to ingenic_nand

The jz4780_nand driver will be modified to handle all the Ingenic
JZ47xx SoCs that the upstream Linux kernel supports (JZ4740, JZ4725B,
JZ4770, JZ4780), so it makes sense to rename it.
Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 65bba52d
obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o
obj-$(CONFIG_MTD_NAND_JZ4780) += jz4780_nand.o jz4780_bch.o obj-$(CONFIG_MTD_NAND_JZ4780) += ingenic_nand.o jz4780_bch.o
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* /*
* JZ4780 NAND driver * Ingenic JZ47xx NAND driver
* *
* Copyright (c) 2015 Imagination Technologies * Copyright (c) 2015 Imagination Technologies
* Author: Alex Smith <alex.smith@imgtec.com> * Author: Alex Smith <alex.smith@imgtec.com>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "jz4780_bch.h" #include "jz4780_bch.h"
#define DRV_NAME "jz4780-nand" #define DRV_NAME "ingenic-nand"
#define OFFSET_DATA 0x00000000 #define OFFSET_DATA 0x00000000
#define OFFSET_CMD 0x00400000 #define OFFSET_CMD 0x00400000
...@@ -33,22 +33,22 @@ ...@@ -33,22 +33,22 @@
/* Command delay when there is no R/B pin. */ /* Command delay when there is no R/B pin. */
#define RB_DELAY_US 100 #define RB_DELAY_US 100
struct jz4780_nand_cs { struct ingenic_nand_cs {
unsigned int bank; unsigned int bank;
void __iomem *base; void __iomem *base;
}; };
struct jz4780_nand_controller { struct ingenic_nfc {
struct device *dev; struct device *dev;
struct jz4780_bch *bch; struct jz4780_bch *bch;
struct nand_controller controller; struct nand_controller controller;
unsigned int num_banks; unsigned int num_banks;
struct list_head chips; struct list_head chips;
int selected; int selected;
struct jz4780_nand_cs cs[]; struct ingenic_nand_cs cs[];
}; };
struct jz4780_nand_chip { struct ingenic_nand {
struct nand_chip chip; struct nand_chip chip;
struct list_head chip_list; struct list_head chip_list;
...@@ -57,22 +57,21 @@ struct jz4780_nand_chip { ...@@ -57,22 +57,21 @@ struct jz4780_nand_chip {
unsigned int reading: 1; unsigned int reading: 1;
}; };
static inline struct jz4780_nand_chip *to_jz4780_nand_chip(struct mtd_info *mtd) static inline struct ingenic_nand *to_ingenic_nand(struct mtd_info *mtd)
{ {
return container_of(mtd_to_nand(mtd), struct jz4780_nand_chip, chip); return container_of(mtd_to_nand(mtd), struct ingenic_nand, chip);
} }
static inline struct jz4780_nand_controller static inline struct ingenic_nfc *to_ingenic_nfc(struct nand_controller *ctrl)
*to_jz4780_nand_controller(struct nand_controller *ctrl)
{ {
return container_of(ctrl, struct jz4780_nand_controller, controller); return container_of(ctrl, struct ingenic_nfc, controller);
} }
static void jz4780_nand_select_chip(struct nand_chip *chip, int chipnr) static void ingenic_nand_select_chip(struct nand_chip *chip, int chipnr)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller);
struct jz4780_nand_cs *cs; struct ingenic_nand_cs *cs;
/* Ensure the currently selected chip is deasserted. */ /* Ensure the currently selected chip is deasserted. */
if (chipnr == -1 && nfc->selected >= 0) { if (chipnr == -1 && nfc->selected >= 0) {
...@@ -83,12 +82,12 @@ static void jz4780_nand_select_chip(struct nand_chip *chip, int chipnr) ...@@ -83,12 +82,12 @@ static void jz4780_nand_select_chip(struct nand_chip *chip, int chipnr)
nfc->selected = chipnr; nfc->selected = chipnr;
} }
static void jz4780_nand_cmd_ctrl(struct nand_chip *chip, int cmd, static void ingenic_nand_cmd_ctrl(struct nand_chip *chip, int cmd,
unsigned int ctrl) unsigned int ctrl)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller);
struct jz4780_nand_cs *cs; struct ingenic_nand_cs *cs;
if (WARN_ON(nfc->selected < 0)) if (WARN_ON(nfc->selected < 0))
return; return;
...@@ -106,25 +105,25 @@ static void jz4780_nand_cmd_ctrl(struct nand_chip *chip, int cmd, ...@@ -106,25 +105,25 @@ static void jz4780_nand_cmd_ctrl(struct nand_chip *chip, int cmd,
writeb(cmd, cs->base + OFFSET_CMD); writeb(cmd, cs->base + OFFSET_CMD);
} }
static int jz4780_nand_dev_ready(struct nand_chip *chip) static int ingenic_nand_dev_ready(struct nand_chip *chip)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
return !gpiod_get_value_cansleep(nand->busy_gpio); return !gpiod_get_value_cansleep(nand->busy_gpio);
} }
static void jz4780_nand_ecc_hwctl(struct nand_chip *chip, int mode) static void ingenic_nand_ecc_hwctl(struct nand_chip *chip, int mode)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
nand->reading = (mode == NAND_ECC_READ); nand->reading = (mode == NAND_ECC_READ);
} }
static int jz4780_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat, static int ingenic_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat,
u8 *ecc_code) u8 *ecc_code)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller);
struct jz4780_bch_params params; struct jz4780_bch_params params;
/* /*
...@@ -141,11 +140,11 @@ static int jz4780_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat, ...@@ -141,11 +140,11 @@ static int jz4780_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat,
return jz4780_bch_calculate(nfc->bch, &params, dat, ecc_code); return jz4780_bch_calculate(nfc->bch, &params, dat, ecc_code);
} }
static int jz4780_nand_ecc_correct(struct nand_chip *chip, u8 *dat, static int ingenic_nand_ecc_correct(struct nand_chip *chip, u8 *dat,
u8 *read_ecc, u8 *calc_ecc) u8 *read_ecc, u8 *calc_ecc)
{ {
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip));
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller);
struct jz4780_bch_params params; struct jz4780_bch_params params;
params.size = nand->chip.ecc.size; params.size = nand->chip.ecc.size;
...@@ -155,10 +154,10 @@ static int jz4780_nand_ecc_correct(struct nand_chip *chip, u8 *dat, ...@@ -155,10 +154,10 @@ static int jz4780_nand_ecc_correct(struct nand_chip *chip, u8 *dat,
return jz4780_bch_correct(nfc->bch, &params, dat, read_ecc); return jz4780_bch_correct(nfc->bch, &params, dat, read_ecc);
} }
static int jz4780_nand_attach_chip(struct nand_chip *chip) static int ingenic_nand_attach_chip(struct nand_chip *chip)
{ {
struct mtd_info *mtd = nand_to_mtd(chip); struct mtd_info *mtd = nand_to_mtd(chip);
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(chip->controller); struct ingenic_nfc *nfc = to_ingenic_nfc(chip->controller);
int eccbytes; int eccbytes;
chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) * chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) *
...@@ -167,14 +166,13 @@ static int jz4780_nand_attach_chip(struct nand_chip *chip) ...@@ -167,14 +166,13 @@ static int jz4780_nand_attach_chip(struct nand_chip *chip)
switch (chip->ecc.mode) { switch (chip->ecc.mode) {
case NAND_ECC_HW: case NAND_ECC_HW:
if (!nfc->bch) { if (!nfc->bch) {
dev_err(nfc->dev, dev_err(nfc->dev, "HW BCH selected, but BCH controller not found\n");
"HW BCH selected, but BCH controller not found\n");
return -ENODEV; return -ENODEV;
} }
chip->ecc.hwctl = jz4780_nand_ecc_hwctl; chip->ecc.hwctl = ingenic_nand_ecc_hwctl;
chip->ecc.calculate = jz4780_nand_ecc_calculate; chip->ecc.calculate = ingenic_nand_ecc_calculate;
chip->ecc.correct = jz4780_nand_ecc_correct; chip->ecc.correct = ingenic_nand_ecc_correct;
/* fall through */ /* fall through */
case NAND_ECC_SOFT: case NAND_ECC_SOFT:
dev_info(nfc->dev, "using %s (strength %d, size %d, bytes %d)\n", dev_info(nfc->dev, "using %s (strength %d, size %d, bytes %d)\n",
...@@ -209,18 +207,18 @@ static int jz4780_nand_attach_chip(struct nand_chip *chip) ...@@ -209,18 +207,18 @@ static int jz4780_nand_attach_chip(struct nand_chip *chip)
return 0; return 0;
} }
static const struct nand_controller_ops jz4780_nand_controller_ops = { static const struct nand_controller_ops ingenic_nand_controller_ops = {
.attach_chip = jz4780_nand_attach_chip, .attach_chip = ingenic_nand_attach_chip,
}; };
static int jz4780_nand_init_chip(struct platform_device *pdev, static int ingenic_nand_init_chip(struct platform_device *pdev,
struct jz4780_nand_controller *nfc, struct ingenic_nfc *nfc,
struct device_node *np, struct device_node *np,
unsigned int chipnr) unsigned int chipnr)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct jz4780_nand_chip *nand; struct ingenic_nand *nand;
struct jz4780_nand_cs *cs; struct ingenic_nand_cs *cs;
struct resource *res; struct resource *res;
struct nand_chip *chip; struct nand_chip *chip;
struct mtd_info *mtd; struct mtd_info *mtd;
...@@ -253,7 +251,7 @@ static int jz4780_nand_init_chip(struct platform_device *pdev, ...@@ -253,7 +251,7 @@ static int jz4780_nand_init_chip(struct platform_device *pdev,
dev_err(dev, "failed to request busy GPIO: %d\n", ret); dev_err(dev, "failed to request busy GPIO: %d\n", ret);
return ret; return ret;
} else if (nand->busy_gpio) { } else if (nand->busy_gpio) {
nand->chip.legacy.dev_ready = jz4780_nand_dev_ready; nand->chip.legacy.dev_ready = ingenic_nand_dev_ready;
} }
nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW); nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW);
...@@ -276,13 +274,13 @@ static int jz4780_nand_init_chip(struct platform_device *pdev, ...@@ -276,13 +274,13 @@ static int jz4780_nand_init_chip(struct platform_device *pdev,
chip->legacy.IO_ADDR_W = cs->base + OFFSET_DATA; chip->legacy.IO_ADDR_W = cs->base + OFFSET_DATA;
chip->legacy.chip_delay = RB_DELAY_US; chip->legacy.chip_delay = RB_DELAY_US;
chip->options = NAND_NO_SUBPAGE_WRITE; chip->options = NAND_NO_SUBPAGE_WRITE;
chip->legacy.select_chip = jz4780_nand_select_chip; chip->legacy.select_chip = ingenic_nand_select_chip;
chip->legacy.cmd_ctrl = jz4780_nand_cmd_ctrl; chip->legacy.cmd_ctrl = ingenic_nand_cmd_ctrl;
chip->ecc.mode = NAND_ECC_HW; chip->ecc.mode = NAND_ECC_HW;
chip->controller = &nfc->controller; chip->controller = &nfc->controller;
nand_set_flash_node(chip, np); nand_set_flash_node(chip, np);
chip->controller->ops = &jz4780_nand_controller_ops; chip->controller->ops = &ingenic_nand_controller_ops;
ret = nand_scan(chip, 1); ret = nand_scan(chip, 1);
if (ret) if (ret)
return ret; return ret;
...@@ -298,18 +296,19 @@ static int jz4780_nand_init_chip(struct platform_device *pdev, ...@@ -298,18 +296,19 @@ static int jz4780_nand_init_chip(struct platform_device *pdev,
return 0; return 0;
} }
static void jz4780_nand_cleanup_chips(struct jz4780_nand_controller *nfc) static void ingenic_nand_cleanup_chips(struct ingenic_nfc *nfc)
{ {
struct jz4780_nand_chip *chip; struct ingenic_nand *chip;
while (!list_empty(&nfc->chips)) { while (!list_empty(&nfc->chips)) {
chip = list_first_entry(&nfc->chips, struct jz4780_nand_chip, chip_list); chip = list_first_entry(&nfc->chips,
struct ingenic_nand, chip_list);
nand_release(&chip->chip); nand_release(&chip->chip);
list_del(&chip->chip_list); list_del(&chip->chip_list);
} }
} }
static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc, static int ingenic_nand_init_chips(struct ingenic_nfc *nfc,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -319,14 +318,15 @@ static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc, ...@@ -319,14 +318,15 @@ static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc,
int num_chips = of_get_child_count(dev->of_node); int num_chips = of_get_child_count(dev->of_node);
if (num_chips > nfc->num_banks) { if (num_chips > nfc->num_banks) {
dev_err(dev, "found %d chips but only %d banks\n", num_chips, nfc->num_banks); dev_err(dev, "found %d chips but only %d banks\n",
num_chips, nfc->num_banks);
return -EINVAL; return -EINVAL;
} }
for_each_child_of_node(dev->of_node, np) { for_each_child_of_node(dev->of_node, np) {
ret = jz4780_nand_init_chip(pdev, nfc, np, i); ret = ingenic_nand_init_chip(pdev, nfc, np, i);
if (ret) { if (ret) {
jz4780_nand_cleanup_chips(nfc); ingenic_nand_cleanup_chips(nfc);
return ret; return ret;
} }
...@@ -336,11 +336,11 @@ static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc, ...@@ -336,11 +336,11 @@ static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc,
return 0; return 0;
} }
static int jz4780_nand_probe(struct platform_device *pdev) static int ingenic_nand_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
unsigned int num_banks; unsigned int num_banks;
struct jz4780_nand_controller *nfc; struct ingenic_nfc *nfc;
int ret; int ret;
num_banks = jz4780_nemc_num_banks(dev); num_banks = jz4780_nemc_num_banks(dev);
...@@ -367,7 +367,7 @@ static int jz4780_nand_probe(struct platform_device *pdev) ...@@ -367,7 +367,7 @@ static int jz4780_nand_probe(struct platform_device *pdev)
nand_controller_init(&nfc->controller); nand_controller_init(&nfc->controller);
INIT_LIST_HEAD(&nfc->chips); INIT_LIST_HEAD(&nfc->chips);
ret = jz4780_nand_init_chips(nfc, pdev); ret = ingenic_nand_init_chips(nfc, pdev);
if (ret) { if (ret) {
if (nfc->bch) if (nfc->bch)
jz4780_bch_release(nfc->bch); jz4780_bch_release(nfc->bch);
...@@ -378,35 +378,35 @@ static int jz4780_nand_probe(struct platform_device *pdev) ...@@ -378,35 +378,35 @@ static int jz4780_nand_probe(struct platform_device *pdev)
return 0; return 0;
} }
static int jz4780_nand_remove(struct platform_device *pdev) static int ingenic_nand_remove(struct platform_device *pdev)
{ {
struct jz4780_nand_controller *nfc = platform_get_drvdata(pdev); struct ingenic_nfc *nfc = platform_get_drvdata(pdev);
if (nfc->bch) if (nfc->bch)
jz4780_bch_release(nfc->bch); jz4780_bch_release(nfc->bch);
jz4780_nand_cleanup_chips(nfc); ingenic_nand_cleanup_chips(nfc);
return 0; return 0;
} }
static const struct of_device_id jz4780_nand_dt_match[] = { static const struct of_device_id ingenic_nand_dt_match[] = {
{ .compatible = "ingenic,jz4780-nand" }, { .compatible = "ingenic,jz4780-nand" },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, jz4780_nand_dt_match); MODULE_DEVICE_TABLE(of, ingenic_nand_dt_match);
static struct platform_driver jz4780_nand_driver = { static struct platform_driver ingenic_nand_driver = {
.probe = jz4780_nand_probe, .probe = ingenic_nand_probe,
.remove = jz4780_nand_remove, .remove = ingenic_nand_remove,
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.of_match_table = of_match_ptr(jz4780_nand_dt_match), .of_match_table = of_match_ptr(ingenic_nand_dt_match),
}, },
}; };
module_platform_driver(jz4780_nand_driver); module_platform_driver(ingenic_nand_driver);
MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>");
MODULE_AUTHOR("Harvey Hunt <harveyhuntnexus@gmail.com>"); MODULE_AUTHOR("Harvey Hunt <harveyhuntnexus@gmail.com>");
MODULE_DESCRIPTION("Ingenic JZ4780 NAND driver"); MODULE_DESCRIPTION("Ingenic JZ47xx NAND driver");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment