|
47 | 47 | #include <linux/mtd/partitions.h>
|
48 | 48 | #include <linux/of_mtd.h>
|
49 | 49 |
|
| 50 | +static int nand_get_device(struct mtd_info *mtd, int new_state); |
| 51 | + |
| 52 | +static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, |
| 53 | + struct mtd_oob_ops *ops); |
| 54 | + |
50 | 55 | /* Define default oob placement schemes for large and small page devices */
|
51 |
| -static struct nand_ecclayout nand_oob_8 = { |
52 |
| - .eccbytes = 3, |
53 |
| - .eccpos = {0, 1, 2}, |
54 |
| - .oobfree = { |
55 |
| - {.offset = 3, |
56 |
| - .length = 2}, |
57 |
| - {.offset = 6, |
58 |
| - .length = 2} } |
59 |
| -}; |
| 56 | +static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section, |
| 57 | + struct mtd_oob_region *oobregion) |
| 58 | +{ |
| 59 | + struct nand_chip *chip = mtd_to_nand(mtd); |
| 60 | + struct nand_ecc_ctrl *ecc = &chip->ecc; |
60 | 61 |
|
61 |
| -static struct nand_ecclayout nand_oob_16 = { |
62 |
| - .eccbytes = 6, |
63 |
| - .eccpos = {0, 1, 2, 3, 6, 7}, |
64 |
| - .oobfree = { |
65 |
| - {.offset = 8, |
66 |
| - . length = 8} } |
67 |
| -}; |
| 62 | + if (section > 1) |
| 63 | + return -ERANGE; |
68 | 64 |
|
69 |
| -static struct nand_ecclayout nand_oob_64 = { |
70 |
| - .eccbytes = 24, |
71 |
| - .eccpos = { |
72 |
| - 40, 41, 42, 43, 44, 45, 46, 47, |
73 |
| - 48, 49, 50, 51, 52, 53, 54, 55, |
74 |
| - 56, 57, 58, 59, 60, 61, 62, 63}, |
75 |
| - .oobfree = { |
76 |
| - {.offset = 2, |
77 |
| - .length = 38} } |
78 |
| -}; |
| 65 | + if (!section) { |
| 66 | + oobregion->offset = 0; |
| 67 | + oobregion->length = 4; |
| 68 | + } else { |
| 69 | + oobregion->offset = 6; |
| 70 | + oobregion->length = ecc->total - 4; |
| 71 | + } |
79 | 72 |
|
80 |
| -static struct nand_ecclayout nand_oob_128 = { |
81 |
| - .eccbytes = 48, |
82 |
| - .eccpos = { |
83 |
| - 80, 81, 82, 83, 84, 85, 86, 87, |
84 |
| - 88, 89, 90, 91, 92, 93, 94, 95, |
85 |
| - 96, 97, 98, 99, 100, 101, 102, 103, |
86 |
| - 104, 105, 106, 107, 108, 109, 110, 111, |
87 |
| - 112, 113, 114, 115, 116, 117, 118, 119, |
88 |
| - 120, 121, 122, 123, 124, 125, 126, 127}, |
89 |
| - .oobfree = { |
90 |
| - {.offset = 2, |
91 |
| - .length = 78} } |
| 73 | + return 0; |
| 74 | +} |
| 75 | + |
| 76 | +static int nand_ooblayout_free_sp(struct mtd_info *mtd, int section, |
| 77 | + struct mtd_oob_region *oobregion) |
| 78 | +{ |
| 79 | + if (section > 1) |
| 80 | + return -ERANGE; |
| 81 | + |
| 82 | + if (mtd->oobsize == 16) { |
| 83 | + if (section) |
| 84 | + return -ERANGE; |
| 85 | + |
| 86 | + oobregion->length = 8; |
| 87 | + oobregion->offset = 8; |
| 88 | + } else { |
| 89 | + oobregion->length = 2; |
| 90 | + if (!section) |
| 91 | + oobregion->offset = 3; |
| 92 | + else |
| 93 | + oobregion->offset = 6; |
| 94 | + } |
| 95 | + |
| 96 | + return 0; |
| 97 | +} |
| 98 | + |
| 99 | +const struct mtd_ooblayout_ops nand_ooblayout_sp_ops = { |
| 100 | + .ecc = nand_ooblayout_ecc_sp, |
| 101 | + .free = nand_ooblayout_free_sp, |
92 | 102 | };
|
| 103 | +EXPORT_SYMBOL_GPL(nand_ooblayout_sp_ops); |
93 | 104 |
|
94 |
| -static int nand_get_device(struct mtd_info *mtd, int new_state); |
| 105 | +static int nand_ooblayout_ecc_lp(struct mtd_info *mtd, int section, |
| 106 | + struct mtd_oob_region *oobregion) |
| 107 | +{ |
| 108 | + struct nand_chip *chip = mtd_to_nand(mtd); |
| 109 | + struct nand_ecc_ctrl *ecc = &chip->ecc; |
95 | 110 |
|
96 |
| -static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, |
97 |
| - struct mtd_oob_ops *ops); |
| 111 | + if (section) |
| 112 | + return -ERANGE; |
| 113 | + |
| 114 | + oobregion->length = ecc->total; |
| 115 | + oobregion->offset = mtd->oobsize - oobregion->length; |
| 116 | + |
| 117 | + return 0; |
| 118 | +} |
| 119 | + |
| 120 | +static int nand_ooblayout_free_lp(struct mtd_info *mtd, int section, |
| 121 | + struct mtd_oob_region *oobregion) |
| 122 | +{ |
| 123 | + struct nand_chip *chip = mtd_to_nand(mtd); |
| 124 | + struct nand_ecc_ctrl *ecc = &chip->ecc; |
| 125 | + |
| 126 | + if (section) |
| 127 | + return -ERANGE; |
| 128 | + |
| 129 | + oobregion->length = mtd->oobsize - ecc->total - 2; |
| 130 | + oobregion->offset = 2; |
| 131 | + |
| 132 | + return 0; |
| 133 | +} |
| 134 | + |
| 135 | +const struct mtd_ooblayout_ops nand_ooblayout_lp_ops = { |
| 136 | + .ecc = nand_ooblayout_ecc_lp, |
| 137 | + .free = nand_ooblayout_free_lp, |
| 138 | +}; |
| 139 | +EXPORT_SYMBOL_GPL(nand_ooblayout_lp_ops); |
98 | 140 |
|
99 | 141 | static int check_offs_len(struct mtd_info *mtd,
|
100 | 142 | loff_t ofs, uint64_t len)
|
@@ -4109,22 +4151,25 @@ int nand_scan_tail(struct mtd_info *mtd)
|
4109 | 4151 | /* Set the internal oob buffer location, just after the page data */
|
4110 | 4152 | chip->oob_poi = chip->buffers->databuf + mtd->writesize;
|
4111 | 4153 |
|
| 4154 | + /* |
| 4155 | + * Set the provided ECC layout. If ecc->layout is NULL, the MTD core |
| 4156 | + * will just leave mtd->ooblayout to NULL, if it's not NULL, it will |
| 4157 | + * set ->ooblayout to the default ecclayout wrapper. |
| 4158 | + */ |
| 4159 | + mtd_set_ecclayout(mtd, ecc->layout); |
| 4160 | + |
4112 | 4161 | /*
|
4113 | 4162 | * If no default placement scheme is given, select an appropriate one.
|
4114 | 4163 | */
|
4115 |
| - if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) { |
| 4164 | + if (!mtd->ooblayout && (ecc->mode != NAND_ECC_SOFT_BCH)) { |
4116 | 4165 | switch (mtd->oobsize) {
|
4117 | 4166 | case 8:
|
4118 |
| - ecc->layout = &nand_oob_8; |
4119 |
| - break; |
4120 | 4167 | case 16:
|
4121 |
| - ecc->layout = &nand_oob_16; |
| 4168 | + mtd_set_ooblayout(mtd, &nand_ooblayout_sp_ops); |
4122 | 4169 | break;
|
4123 | 4170 | case 64:
|
4124 |
| - ecc->layout = &nand_oob_64; |
4125 |
| - break; |
4126 | 4171 | case 128:
|
4127 |
| - ecc->layout = &nand_oob_128; |
| 4172 | + mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops); |
4128 | 4173 | break;
|
4129 | 4174 | default:
|
4130 | 4175 | WARN(1, "No oob scheme defined for oobsize %d\n",
|
@@ -4285,7 +4330,6 @@ int nand_scan_tail(struct mtd_info *mtd)
|
4285 | 4330 | ecc->write_oob_raw = ecc->write_oob;
|
4286 | 4331 |
|
4287 | 4332 | /* propagate ecc info to mtd_info */
|
4288 |
| - mtd_set_ecclayout(mtd, ecc->layout); |
4289 | 4333 | mtd->ecc_strength = ecc->strength;
|
4290 | 4334 | mtd->ecc_step_size = ecc->size;
|
4291 | 4335 |
|
|
0 commit comments