@@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
1227
1227
* required within a nand driver because they are performed by the nand
1228
1228
* infrastructure code as part of nand_scan(). In this case they need
1229
1229
* 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.
1234
1233
*/
1235
1234
1236
1235
struct nand_chip * nand = mtd_to_nand (mtd );
@@ -1315,6 +1314,40 @@ static int __init read_id_reg(struct mtd_info *mtd)
1315
1314
1316
1315
static char const * part_probes [] = { "cmdlinepart" , "saftlpart" , NULL };
1317
1316
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
+
1318
1351
static int __init probe_docg4 (struct platform_device * pdev )
1319
1352
{
1320
1353
struct mtd_info * mtd ;
@@ -1350,28 +1383,17 @@ static int __init probe_docg4(struct platform_device *pdev)
1350
1383
mtd -> dev .parent = & pdev -> dev ;
1351
1384
doc -> virtadr = virtadr ;
1352
1385
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
-
1363
1386
platform_set_drvdata (pdev , doc );
1364
1387
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 );
1373
1395
if (retval )
1374
- goto free_bch ;
1396
+ goto free_nand ;
1375
1397
1376
1398
retval = read_factory_bbt (mtd );
1377
1399
if (retval )
@@ -1387,8 +1409,6 @@ static int __init probe_docg4(struct platform_device *pdev)
1387
1409
1388
1410
cleanup_nand :
1389
1411
nand_cleanup (nand );
1390
- free_bch :
1391
- free_bch (doc -> bch );
1392
1412
free_nand :
1393
1413
kfree (nand );
1394
1414
unmap :
@@ -1401,7 +1421,6 @@ static int __exit cleanup_docg4(struct platform_device *pdev)
1401
1421
{
1402
1422
struct docg4_priv * doc = platform_get_drvdata (pdev );
1403
1423
nand_release (doc -> mtd );
1404
- free_bch (doc -> bch );
1405
1424
kfree (mtd_to_nand (doc -> mtd ));
1406
1425
iounmap (doc -> virtadr );
1407
1426
return 0 ;
0 commit comments