Commit 66a38478 authored by Miquel Raynal's avatar Miquel Raynal

mtd: rawnand: docg4: convert driver to nand_scan()

Two helpers have been added to the core to do all kind of controller
side configuration/initialization between the detection phase and the
final NAND scan. Implement these hooks so that we can convert the driver
to just use nand_scan() instead of the nand_scan_ident() +
nand_scan_tail() pair.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent 49aa76b1
...@@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd) ...@@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
* required within a nand driver because they are performed by the nand * required within a nand driver because they are performed by the nand
* infrastructure code as part of nand_scan(). In this case they need * infrastructure code as part of nand_scan(). In this case they need
* to be initialized here because we skip call to nand_scan_ident() (the * to be initialized here because we skip call to nand_scan_ident() (the
* first half of nand_scan()). The call to nand_scan_ident() is skipped * first half of nand_scan()). The call to nand_scan_ident() could be
* because for this device the chip id is not read in the manner of a * skipped because for this device the chip id is not read in the manner
* standard nand device. Unfortunately, nand_scan_ident() does other * of a standard nand device.
* things as well, such as call nand_set_defaults().
*/ */
struct nand_chip *nand = mtd_to_nand(mtd); struct nand_chip *nand = mtd_to_nand(mtd);
...@@ -1315,6 +1314,40 @@ static int __init read_id_reg(struct mtd_info *mtd) ...@@ -1315,6 +1314,40 @@ static int __init read_id_reg(struct mtd_info *mtd)
static char const *part_probes[] = { "cmdlinepart", "saftlpart", NULL }; static char const *part_probes[] = { "cmdlinepart", "saftlpart", NULL };
static int docg4_attach_chip(struct nand_chip *chip)
{
struct mtd_info *mtd = nand_to_mtd(chip);
struct docg4_priv *doc = (struct docg4_priv *)(chip + 1);
int ret;
init_mtd_structs(mtd);
/* Initialize kernel BCH algorithm */
doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
if (!doc->bch)
return -EINVAL;
reset(mtd);
ret = read_id_reg(mtd);
if (ret)
free_bch(doc->bch);
return ret;
}
static void docg4_detach_chip(struct nand_chip *chip)
{
struct docg4_priv *doc = (struct docg4_priv *)(chip + 1);
free_bch(doc->bch);
}
static const struct nand_controller_ops docg4_controller_ops = {
.attach_chip = docg4_attach_chip,
.detach_chip = docg4_detach_chip,
};
static int __init probe_docg4(struct platform_device *pdev) static int __init probe_docg4(struct platform_device *pdev)
{ {
struct mtd_info *mtd; struct mtd_info *mtd;
...@@ -1350,28 +1383,17 @@ static int __init probe_docg4(struct platform_device *pdev) ...@@ -1350,28 +1383,17 @@ static int __init probe_docg4(struct platform_device *pdev)
mtd->dev.parent = &pdev->dev; mtd->dev.parent = &pdev->dev;
doc->virtadr = virtadr; doc->virtadr = virtadr;
doc->dev = dev; doc->dev = dev;
init_mtd_structs(mtd);
/* initialize kernel bch algorithm */
doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
if (doc->bch == NULL) {
retval = -EINVAL;
goto free_nand;
}
platform_set_drvdata(pdev, doc); platform_set_drvdata(pdev, doc);
reset(mtd); /*
retval = read_id_reg(mtd); * Running nand_scan() with maxchips == 0 will skip nand_scan_ident(),
if (retval == -ENODEV) { * which is a specific operation with this driver and done in the
dev_warn(dev, "No diskonchip G4 device found.\n"); * ->attach_chip callback.
goto free_bch; */
} nand->dummy_controller.ops = &docg4_controller_ops;
retval = nand_scan(mtd, 0);
retval = nand_scan_tail(mtd);
if (retval) if (retval)
goto free_bch; goto free_nand;
retval = read_factory_bbt(mtd); retval = read_factory_bbt(mtd);
if (retval) if (retval)
...@@ -1387,8 +1409,6 @@ static int __init probe_docg4(struct platform_device *pdev) ...@@ -1387,8 +1409,6 @@ static int __init probe_docg4(struct platform_device *pdev)
cleanup_nand: cleanup_nand:
nand_cleanup(nand); nand_cleanup(nand);
free_bch:
free_bch(doc->bch);
free_nand: free_nand:
kfree(nand); kfree(nand);
unmap: unmap:
...@@ -1401,7 +1421,6 @@ static int __exit cleanup_docg4(struct platform_device *pdev) ...@@ -1401,7 +1421,6 @@ static int __exit cleanup_docg4(struct platform_device *pdev)
{ {
struct docg4_priv *doc = platform_get_drvdata(pdev); struct docg4_priv *doc = platform_get_drvdata(pdev);
nand_release(doc->mtd); nand_release(doc->mtd);
free_bch(doc->bch);
kfree(mtd_to_nand(doc->mtd)); kfree(mtd_to_nand(doc->mtd));
iounmap(doc->virtadr); iounmap(doc->virtadr);
return 0; return 0;
......
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