Skip to content

Commit 66a3847

Browse files
committed
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: Miquel Raynal <[email protected]> Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 49aa76b commit 66a3847

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

drivers/mtd/nand/raw/docg4.c

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
12271227
* required within a nand driver because they are performed by the nand
12281228
* infrastructure code as part of nand_scan(). In this case they need
12291229
* to be initialized here because we skip call to nand_scan_ident() (the
1230-
* first half of nand_scan()). The call to nand_scan_ident() is skipped
1231-
* because for this device the chip id is not read in the manner of a
1232-
* standard nand device. Unfortunately, nand_scan_ident() does other
1233-
* things as well, such as call nand_set_defaults().
1230+
* first half of nand_scan()). The call to nand_scan_ident() could be
1231+
* skipped because for this device the chip id is not read in the manner
1232+
* of a standard nand device.
12341233
*/
12351234

12361235
struct nand_chip *nand = mtd_to_nand(mtd);
@@ -1315,6 +1314,40 @@ static int __init read_id_reg(struct mtd_info *mtd)
13151314

13161315
static char const *part_probes[] = { "cmdlinepart", "saftlpart", NULL };
13171316

1317+
static int docg4_attach_chip(struct nand_chip *chip)
1318+
{
1319+
struct mtd_info *mtd = nand_to_mtd(chip);
1320+
struct docg4_priv *doc = (struct docg4_priv *)(chip + 1);
1321+
int ret;
1322+
1323+
init_mtd_structs(mtd);
1324+
1325+
/* Initialize kernel BCH algorithm */
1326+
doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
1327+
if (!doc->bch)
1328+
return -EINVAL;
1329+
1330+
reset(mtd);
1331+
1332+
ret = read_id_reg(mtd);
1333+
if (ret)
1334+
free_bch(doc->bch);
1335+
1336+
return ret;
1337+
}
1338+
1339+
static void docg4_detach_chip(struct nand_chip *chip)
1340+
{
1341+
struct docg4_priv *doc = (struct docg4_priv *)(chip + 1);
1342+
1343+
free_bch(doc->bch);
1344+
}
1345+
1346+
static const struct nand_controller_ops docg4_controller_ops = {
1347+
.attach_chip = docg4_attach_chip,
1348+
.detach_chip = docg4_detach_chip,
1349+
};
1350+
13181351
static int __init probe_docg4(struct platform_device *pdev)
13191352
{
13201353
struct mtd_info *mtd;
@@ -1350,28 +1383,17 @@ static int __init probe_docg4(struct platform_device *pdev)
13501383
mtd->dev.parent = &pdev->dev;
13511384
doc->virtadr = virtadr;
13521385
doc->dev = dev;
1353-
1354-
init_mtd_structs(mtd);
1355-
1356-
/* initialize kernel bch algorithm */
1357-
doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY);
1358-
if (doc->bch == NULL) {
1359-
retval = -EINVAL;
1360-
goto free_nand;
1361-
}
1362-
13631386
platform_set_drvdata(pdev, doc);
13641387

1365-
reset(mtd);
1366-
retval = read_id_reg(mtd);
1367-
if (retval == -ENODEV) {
1368-
dev_warn(dev, "No diskonchip G4 device found.\n");
1369-
goto free_bch;
1370-
}
1371-
1372-
retval = nand_scan_tail(mtd);
1388+
/*
1389+
* Running nand_scan() with maxchips == 0 will skip nand_scan_ident(),
1390+
* which is a specific operation with this driver and done in the
1391+
* ->attach_chip callback.
1392+
*/
1393+
nand->dummy_controller.ops = &docg4_controller_ops;
1394+
retval = nand_scan(mtd, 0);
13731395
if (retval)
1374-
goto free_bch;
1396+
goto free_nand;
13751397

13761398
retval = read_factory_bbt(mtd);
13771399
if (retval)
@@ -1387,8 +1409,6 @@ static int __init probe_docg4(struct platform_device *pdev)
13871409

13881410
cleanup_nand:
13891411
nand_cleanup(nand);
1390-
free_bch:
1391-
free_bch(doc->bch);
13921412
free_nand:
13931413
kfree(nand);
13941414
unmap:
@@ -1401,7 +1421,6 @@ static int __exit cleanup_docg4(struct platform_device *pdev)
14011421
{
14021422
struct docg4_priv *doc = platform_get_drvdata(pdev);
14031423
nand_release(doc->mtd);
1404-
free_bch(doc->bch);
14051424
kfree(mtd_to_nand(doc->mtd));
14061425
iounmap(doc->virtadr);
14071426
return 0;

0 commit comments

Comments
 (0)