@@ -68,21 +68,33 @@ MODULE_PARM_DESC(otp, "Corresponding behaviour of OneNAND in OTP"
6868 * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
6969 * For now, we expose only 64 out of 80 ecc bytes
7070 */
71- static struct nand_ecclayout flexonenand_oob_128 = {
72- .eccbytes = 64 ,
73- .eccpos = {
74- 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
75- 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
76- 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 ,
77- 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 ,
78- 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 ,
79- 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 ,
80- 102 , 103 , 104 , 105
81- },
82- .oobfree = {
83- {2 , 4 }, {18 , 4 }, {34 , 4 }, {50 , 4 },
84- {66 , 4 }, {82 , 4 }, {98 , 4 }, {114 , 4 }
85- }
71+ static int flexonenand_ooblayout_ecc (struct mtd_info * mtd , int section ,
72+ struct mtd_oob_region * oobregion )
73+ {
74+ if (section > 7 )
75+ return - ERANGE ;
76+
77+ oobregion -> offset = (section * 16 ) + 6 ;
78+ oobregion -> length = 10 ;
79+
80+ return 0 ;
81+ }
82+
83+ static int flexonenand_ooblayout_free (struct mtd_info * mtd , int section ,
84+ struct mtd_oob_region * oobregion )
85+ {
86+ if (section > 7 )
87+ return - ERANGE ;
88+
89+ oobregion -> offset = (section * 16 ) + 2 ;
90+ oobregion -> length = 4 ;
91+
92+ return 0 ;
93+ }
94+
95+ static const struct mtd_ooblayout_ops flexonenand_ooblayout_ops = {
96+ .ecc = flexonenand_ooblayout_ecc ,
97+ .free = flexonenand_ooblayout_free ,
8698};
8799
88100/*
@@ -91,56 +103,77 @@ static struct nand_ecclayout flexonenand_oob_128 = {
91103 * Based on specification:
92104 * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
93105 *
94- * For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout)
95- *
96- * oobfree uses the spare area fields marked as
97- * "Managed by internal ECC logic for Logical Sector Number area"
98- */
99- static struct nand_ecclayout onenand_oob_128 = {
100- .eccbytes = 64 ,
101- .eccpos = {
102- 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
103- 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
104- 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 ,
105- 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 ,
106- 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 ,
107- 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 ,
108- 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 ,
109- 119
110- },
111- .oobfree = {
112- {2 , 3 }, {18 , 3 }, {34 , 3 }, {50 , 3 },
113- {66 , 3 }, {82 , 3 }, {98 , 3 }, {114 , 3 }
114- }
106+ */
107+ static int onenand_ooblayout_128_ecc (struct mtd_info * mtd , int section ,
108+ struct mtd_oob_region * oobregion )
109+ {
110+ if (section > 7 )
111+ return - ERANGE ;
112+
113+ oobregion -> offset = (section * 16 ) + 7 ;
114+ oobregion -> length = 9 ;
115+
116+ return 0 ;
117+ }
118+
119+ static int onenand_ooblayout_128_free (struct mtd_info * mtd , int section ,
120+ struct mtd_oob_region * oobregion )
121+ {
122+ if (section >= 8 )
123+ return - ERANGE ;
124+
125+ /*
126+ * free bytes are using the spare area fields marked as
127+ * "Managed by internal ECC logic for Logical Sector Number area"
128+ */
129+ oobregion -> offset = (section * 16 ) + 2 ;
130+ oobregion -> length = 3 ;
131+
132+ return 0 ;
133+ }
134+
135+ static const struct mtd_ooblayout_ops onenand_oob_128_ooblayout_ops = {
136+ .ecc = onenand_ooblayout_128_ecc ,
137+ .free = onenand_ooblayout_128_free ,
115138};
116139
117140/**
118- * onenand_oob_64 - oob info for large (2KB) page
141+ * onenand_oob_32_64 - oob info for large (2KB) page
119142 */
120- static struct nand_ecclayout onenand_oob_64 = {
121- .eccbytes = 20 ,
122- .eccpos = {
123- 8 , 9 , 10 , 11 , 12 ,
124- 24 , 25 , 26 , 27 , 28 ,
125- 40 , 41 , 42 , 43 , 44 ,
126- 56 , 57 , 58 , 59 , 60 ,
127- },
128- .oobfree = {
129- {2 , 3 }, {14 , 2 }, {18 , 3 }, {30 , 2 },
130- {34 , 3 }, {46 , 2 }, {50 , 3 }, {62 , 2 }
143+ static int onenand_ooblayout_32_64_ecc (struct mtd_info * mtd , int section ,
144+ struct mtd_oob_region * oobregion )
145+ {
146+ if (section > 3 )
147+ return - ERANGE ;
148+
149+ oobregion -> offset = (section * 16 ) + 8 ;
150+ oobregion -> length = 5 ;
151+
152+ return 0 ;
153+ }
154+
155+ static int onenand_ooblayout_32_64_free (struct mtd_info * mtd , int section ,
156+ struct mtd_oob_region * oobregion )
157+ {
158+ int sections = (mtd -> oobsize / 32 ) * 2 ;
159+
160+ if (section >= sections )
161+ return - ERANGE ;
162+
163+ if (section & 1 ) {
164+ oobregion -> offset = ((section - 1 ) * 16 ) + 14 ;
165+ oobregion -> length = 2 ;
166+ } else {
167+ oobregion -> offset = (section * 16 ) + 2 ;
168+ oobregion -> length = 3 ;
131169 }
132- };
133170
134- /**
135- * onenand_oob_32 - oob info for middle (1KB) page
136- */
137- static struct nand_ecclayout onenand_oob_32 = {
138- .eccbytes = 10 ,
139- .eccpos = {
140- 8 , 9 , 10 , 11 , 12 ,
141- 24 , 25 , 26 , 27 , 28 ,
142- },
143- .oobfree = { {2 , 3 }, {14 , 2 }, {18 , 3 }, {30 , 2 } }
171+ return 0 ;
172+ }
173+
174+ static const struct mtd_ooblayout_ops onenand_oob_32_64_ooblayout_ops = {
175+ .ecc = onenand_ooblayout_32_64_ecc ,
176+ .free = onenand_ooblayout_32_64_free ,
144177};
145178
146179static const unsigned char ffchars [] = {
@@ -3957,22 +3990,22 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
39573990 switch (mtd -> oobsize ) {
39583991 case 128 :
39593992 if (FLEXONENAND (this )) {
3960- this -> ecclayout = & flexonenand_oob_128 ;
3993+ mtd_set_ooblayout ( mtd , & flexonenand_ooblayout_ops ) ;
39613994 mtd -> subpage_sft = 0 ;
39623995 } else {
3963- this -> ecclayout = & onenand_oob_128 ;
3996+ mtd_set_ooblayout ( mtd , & onenand_oob_128_ooblayout_ops ) ;
39643997 mtd -> subpage_sft = 2 ;
39653998 }
39663999 if (ONENAND_IS_NOP_1 (this ))
39674000 mtd -> subpage_sft = 0 ;
39684001 break ;
39694002 case 64 :
3970- this -> ecclayout = & onenand_oob_64 ;
4003+ mtd_set_ooblayout ( mtd , & onenand_oob_32_64_ooblayout_ops ) ;
39714004 mtd -> subpage_sft = 2 ;
39724005 break ;
39734006
39744007 case 32 :
3975- this -> ecclayout = & onenand_oob_32 ;
4008+ mtd_set_ooblayout ( mtd , & onenand_oob_32_64_ooblayout_ops ) ;
39764009 mtd -> subpage_sft = 1 ;
39774010 break ;
39784011
@@ -3981,7 +4014,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
39814014 __func__ , mtd -> oobsize );
39824015 mtd -> subpage_sft = 0 ;
39834016 /* To prevent kernel oops */
3984- this -> ecclayout = & onenand_oob_32 ;
4017+ mtd_set_ooblayout ( mtd , & onenand_oob_32_64_ooblayout_ops ) ;
39854018 break ;
39864019 }
39874020
@@ -3997,7 +4030,6 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
39974030
39984031 mtd -> oobavail = ret ;
39994032
4000- mtd_set_ecclayout (mtd , this -> ecclayout );
40014033 mtd -> ecc_strength = 1 ;
40024034
40034035 /* Fill in remaining MTD driver data */
0 commit comments