1313#include <linux/bitops.h>
1414#include <linux/mtd/mtd.h>
1515#include <linux/mtd/rawnand.h>
16+ #include <linux/mtd/nand.h>
1617#include <linux/mtd/nand-ecc-sw-bch.h>
1718#include <linux/bch.h>
1819
@@ -29,14 +30,15 @@ struct nand_bch_control {
2930};
3031
3132/**
32- * nand_bch_calcuate_ecc - Calculate the ECC corresponding to a data block
33- * @chip : NAND chip object
33+ * nand_ecc_sw_bch_calculate - Calculate the ECC corresponding to a data block
34+ * @nand : NAND device
3435 * @buf: Input buffer with raw data
3536 * @code: Output buffer with ECC
3637 */
37- int nand_bch_calculate_ecc (struct nand_chip * chip , const unsigned char * buf ,
38- unsigned char * code )
38+ int nand_ecc_sw_bch_calculate (struct nand_device * nand ,
39+ const unsigned char * buf , unsigned char * code )
3940{
41+ struct nand_chip * chip = mtd_to_nand (nanddev_to_mtd (nand ));
4042 struct nand_bch_control * nbc = chip -> ecc .priv ;
4143 unsigned int i ;
4244
@@ -49,20 +51,21 @@ int nand_bch_calculate_ecc(struct nand_chip *chip, const unsigned char *buf,
4951
5052 return 0 ;
5153}
52- EXPORT_SYMBOL (nand_bch_calculate_ecc );
54+ EXPORT_SYMBOL (nand_ecc_sw_bch_calculate );
5355
5456/**
55- * nand_bch_correct_data - Detect, correct and report bit error(s)
56- * @chip : NAND chip object
57+ * nand_ecc_sw_bch_correct - Detect, correct and report bit error(s)
58+ * @nand : NAND device
5759 * @buf: Raw data read from the chip
5860 * @read_ecc: ECC bytes from the chip
5961 * @calc_ecc: ECC calculated from the raw data
6062 *
6163 * Detect and correct bit errors for a data block.
6264 */
63- int nand_bch_correct_data (struct nand_chip * chip , unsigned char * buf ,
64- unsigned char * read_ecc , unsigned char * calc_ecc )
65+ int nand_ecc_sw_bch_correct (struct nand_device * nand , unsigned char * buf ,
66+ unsigned char * read_ecc , unsigned char * calc_ecc )
6567{
68+ struct nand_chip * chip = mtd_to_nand (nanddev_to_mtd (nand ));
6669 struct nand_bch_control * nbc = chip -> ecc .priv ;
6770 unsigned int * errloc = nbc -> errloc ;
6871 int i , count ;
@@ -86,11 +89,11 @@ int nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
8689
8790 return count ;
8891}
89- EXPORT_SYMBOL (nand_bch_correct_data );
92+ EXPORT_SYMBOL (nand_ecc_sw_bch_correct );
9093
9194/**
92- * nand_bch_init - Initialize software BCH ECC engine
93- * @chip : NAND chip object
95+ * nand_ecc_sw_bch_init - Initialize software BCH ECC engine
96+ * @nand : NAND device
9497 *
9598 * Returns: a pointer to a new NAND BCH control structure, or NULL upon failure
9699 *
@@ -105,9 +108,10 @@ EXPORT_SYMBOL(nand_bch_correct_data);
105108 * @eccsize = 512 (thus, m = 13 is the smallest integer such that 2^m - 1 > 512 * 8)
106109 * @eccbytes = 7 (7 bytes are required to store m * t = 13 * 4 = 52 bits)
107110 */
108- int nand_bch_init (struct nand_chip * chip )
111+ int nand_ecc_sw_bch_init (struct nand_device * nand )
109112{
110- struct mtd_info * mtd = nand_to_mtd (chip );
113+ struct mtd_info * mtd = nanddev_to_mtd (nand );
114+ struct nand_chip * chip = mtd_to_nand (mtd );
111115 unsigned int m , t , eccsteps , i ;
112116 struct nand_bch_control * nbc = NULL ;
113117 unsigned char * erased_page ;
@@ -198,18 +202,21 @@ int nand_bch_init(struct nand_chip *chip)
198202 chip -> ecc .strength = (eccbytes * 8 ) / fls (8 * eccsize );
199203
200204 return 0 ;
205+
201206fail :
202- nand_bch_free (chip );
207+ nand_ecc_sw_bch_cleanup (nand );
208+
203209 return - EINVAL ;
204210}
205- EXPORT_SYMBOL (nand_bch_init );
211+ EXPORT_SYMBOL (nand_ecc_sw_bch_init );
206212
207213/**
208- * nand_bch_free - Release NAND BCH ECC resources
209- * @nbc : NAND BCH control structure
214+ * nand_ecc_sw_bch_cleanup - Cleanup software BCH ECC resources
215+ * @nand : NAND device
210216 */
211- void nand_bch_free (struct nand_chip * chip )
217+ void nand_ecc_sw_bch_cleanup (struct nand_device * nand )
212218{
219+ struct nand_chip * chip = mtd_to_nand (nanddev_to_mtd (nand ));
213220 struct nand_bch_control * nbc = chip -> ecc .priv ;
214221
215222 if (nbc ) {
@@ -219,7 +226,7 @@ void nand_bch_free(struct nand_chip *chip)
219226 kfree (nbc );
220227 }
221228}
222- EXPORT_SYMBOL (nand_bch_free );
229+ EXPORT_SYMBOL (nand_ecc_sw_bch_cleanup );
223230
224231MODULE_LICENSE ("GPL" );
225232MODULE_AUTHOR ("Ivan Djelic <ivan.djelic@parrot.com>" );
0 commit comments