@@ -371,6 +371,77 @@ static int nand_davinci_correct_4bit(struct nand_chip *chip, u_char *data,
371
371
return corrected ;
372
372
}
373
373
374
+ /**
375
+ * nand_read_page_hwecc_oob_first - hw ecc, read oob first
376
+ * @chip: nand chip info structure
377
+ * @buf: buffer to store read data
378
+ * @oob_required: caller requires OOB data read to chip->oob_poi
379
+ * @page: page number to read
380
+ *
381
+ * Hardware ECC for large page chips, require OOB to be read first. For this
382
+ * ECC mode, the write_page method is re-used from ECC_HW. These methods
383
+ * read/write ECC from the OOB area, unlike the ECC_HW_SYNDROME support with
384
+ * multiple ECC steps, follows the "infix ECC" scheme and reads/writes ECC from
385
+ * the data area, by overwriting the NAND manufacturer bad block markings.
386
+ */
387
+ static int nand_davinci_read_page_hwecc_oob_first (struct nand_chip * chip ,
388
+ uint8_t * buf ,
389
+ int oob_required , int page )
390
+ {
391
+ struct mtd_info * mtd = nand_to_mtd (chip );
392
+ int i , eccsize = chip -> ecc .size , ret ;
393
+ int eccbytes = chip -> ecc .bytes ;
394
+ int eccsteps = chip -> ecc .steps ;
395
+ uint8_t * p = buf ;
396
+ uint8_t * ecc_code = chip -> ecc .code_buf ;
397
+ uint8_t * ecc_calc = chip -> ecc .calc_buf ;
398
+ unsigned int max_bitflips = 0 ;
399
+
400
+ /* Read the OOB area first */
401
+ ret = nand_read_oob_op (chip , page , 0 , chip -> oob_poi , mtd -> oobsize );
402
+ if (ret )
403
+ return ret ;
404
+
405
+ ret = nand_read_page_op (chip , page , 0 , NULL , 0 );
406
+ if (ret )
407
+ return ret ;
408
+
409
+ ret = mtd_ooblayout_get_eccbytes (mtd , ecc_code , chip -> oob_poi , 0 ,
410
+ chip -> ecc .total );
411
+ if (ret )
412
+ return ret ;
413
+
414
+ for (i = 0 ; eccsteps ; eccsteps -- , i += eccbytes , p += eccsize ) {
415
+ int stat ;
416
+
417
+ chip -> ecc .hwctl (chip , NAND_ECC_READ );
418
+
419
+ ret = nand_read_data_op (chip , p , eccsize , false, false);
420
+ if (ret )
421
+ return ret ;
422
+
423
+ chip -> ecc .calculate (chip , p , & ecc_calc [i ]);
424
+
425
+ stat = chip -> ecc .correct (chip , p , & ecc_code [i ], NULL );
426
+ if (stat == - EBADMSG &&
427
+ (chip -> ecc .options & NAND_ECC_GENERIC_ERASED_CHECK )) {
428
+ /* check for empty pages with bitflips */
429
+ stat = nand_check_erased_ecc_chunk (p , eccsize ,
430
+ & ecc_code [i ],
431
+ eccbytes , NULL , 0 ,
432
+ chip -> ecc .strength );
433
+ }
434
+
435
+ if (stat < 0 ) {
436
+ mtd -> ecc_stats .failed ++ ;
437
+ } else {
438
+ mtd -> ecc_stats .corrected += stat ;
439
+ max_bitflips = max_t (unsigned int , max_bitflips , stat );
440
+ }
441
+ }
442
+ return max_bitflips ;
443
+ }
444
+
374
445
/*----------------------------------------------------------------------*/
375
446
376
447
/* An ECC layout for using 4-bit ECC with small-page flash, storing
@@ -530,6 +601,13 @@ static int davinci_nand_attach_chip(struct nand_chip *chip)
530
601
break ;
531
602
case NAND_ECC_HW :
532
603
if (pdata -> ecc_bits == 4 ) {
604
+ int chunks = mtd -> writesize / 512 ;
605
+
606
+ if (!chunks || mtd -> oobsize < 16 ) {
607
+ dev_dbg (& info -> pdev -> dev , "too small\n" );
608
+ return - EINVAL ;
609
+ }
610
+
533
611
/*
534
612
* No sanity checks: CPUs must support this,
535
613
* and the chips may not use NAND_BUSWIDTH_16.
@@ -552,6 +630,26 @@ static int davinci_nand_attach_chip(struct nand_chip *chip)
552
630
info -> chip .ecc .bytes = 10 ;
553
631
info -> chip .ecc .options = NAND_ECC_GENERIC_ERASED_CHECK ;
554
632
info -> chip .ecc .algo = NAND_ECC_BCH ;
633
+
634
+ /*
635
+ * Update ECC layout if needed ... for 1-bit HW ECC, the
636
+ * default is OK, but it allocates 6 bytes when only 3
637
+ * are needed (for each 512 bytes). For 4-bit HW ECC,
638
+ * the default is not usable: 10 bytes needed, not 6.
639
+ *
640
+ * For small page chips, preserve the manufacturer's
641
+ * badblock marking data ... and make sure a flash BBT
642
+ * table marker fits in the free bytes.
643
+ */
644
+ if (chunks == 1 ) {
645
+ mtd_set_ooblayout (mtd ,
646
+ & hwecc4_small_ooblayout_ops );
647
+ } else if (chunks == 4 || chunks == 8 ) {
648
+ mtd_set_ooblayout (mtd , & nand_ooblayout_lp_ops );
649
+ info -> chip .ecc .read_page = nand_davinci_read_page_hwecc_oob_first ;
650
+ } else {
651
+ return - EIO ;
652
+ }
555
653
} else {
556
654
/* 1bit ecc hamming */
557
655
info -> chip .ecc .calculate = nand_davinci_calculate_1bit ;
@@ -567,34 +665,6 @@ static int davinci_nand_attach_chip(struct nand_chip *chip)
567
665
return - EINVAL ;
568
666
}
569
667
570
- /*
571
- * Update ECC layout if needed ... for 1-bit HW ECC, the default
572
- * is OK, but it allocates 6 bytes when only 3 are needed (for
573
- * each 512 bytes). For the 4-bit HW ECC, that default is not
574
- * usable: 10 bytes are needed, not 6.
575
- */
576
- if (pdata -> ecc_bits == 4 ) {
577
- int chunks = mtd -> writesize / 512 ;
578
-
579
- if (!chunks || mtd -> oobsize < 16 ) {
580
- dev_dbg (& info -> pdev -> dev , "too small\n" );
581
- return - EINVAL ;
582
- }
583
-
584
- /* For small page chips, preserve the manufacturer's
585
- * badblock marking data ... and make sure a flash BBT
586
- * table marker fits in the free bytes.
587
- */
588
- if (chunks == 1 ) {
589
- mtd_set_ooblayout (mtd , & hwecc4_small_ooblayout_ops );
590
- } else if (chunks == 4 || chunks == 8 ) {
591
- mtd_set_ooblayout (mtd , & nand_ooblayout_lp_ops );
592
- info -> chip .ecc .mode = NAND_ECC_HW_OOB_FIRST ;
593
- } else {
594
- return - EIO ;
595
- }
596
- }
597
-
598
668
return ret ;
599
669
}
600
670
0 commit comments