diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-11-21 04:03:04 -0500 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-11-21 05:55:59 -0500 |
commit | 8fcfba072420518fda4b2fe00a3f3c9c3e2774e2 (patch) | |
tree | 09628a41d1648e468e98c95b5caf0cd0a6583625 | |
parent | 4d6aecfb7e26d2e8746e2eb1eab5e0fe378065ab (diff) |
mtd: nand: tango: Use nand_to_mtd() instead of directly accessing chip->mtd
The nand_to_mtd() helper is here to hide internal mtd_info <-> nand_chip
association and ease future refactors.
Make use of this helper instead of directly accessing chip->mtd.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
-rw-r--r-- | drivers/mtd/nand/tango_nand.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c index 7ed35348993e..ec87516b87f5 100644 --- a/drivers/mtd/nand/tango_nand.c +++ b/drivers/mtd/nand/tango_nand.c | |||
@@ -171,6 +171,7 @@ static void tango_select_chip(struct mtd_info *mtd, int idx) | |||
171 | */ | 171 | */ |
172 | static int check_erased_page(struct nand_chip *chip, u8 *buf) | 172 | static int check_erased_page(struct nand_chip *chip, u8 *buf) |
173 | { | 173 | { |
174 | struct mtd_info *mtd = nand_to_mtd(chip); | ||
174 | u8 *meta = chip->oob_poi + BBM_SIZE; | 175 | u8 *meta = chip->oob_poi + BBM_SIZE; |
175 | u8 *ecc = chip->oob_poi + BBM_SIZE + METADATA_SIZE; | 176 | u8 *ecc = chip->oob_poi + BBM_SIZE + METADATA_SIZE; |
176 | const int ecc_size = chip->ecc.bytes; | 177 | const int ecc_size = chip->ecc.bytes; |
@@ -183,7 +184,7 @@ static int check_erased_page(struct nand_chip *chip, u8 *buf) | |||
183 | meta, meta_len, | 184 | meta, meta_len, |
184 | chip->ecc.strength); | 185 | chip->ecc.strength); |
185 | if (res < 0) | 186 | if (res < 0) |
186 | chip->mtd.ecc_stats.failed++; | 187 | mtd->ecc_stats.failed++; |
187 | 188 | ||
188 | bitflips = max(res, bitflips); | 189 | bitflips = max(res, bitflips); |
189 | buf += pkt_size; | 190 | buf += pkt_size; |
@@ -300,26 +301,30 @@ static int tango_write_page(struct mtd_info *mtd, struct nand_chip *chip, | |||
300 | 301 | ||
301 | static void aux_read(struct nand_chip *chip, u8 **buf, int len, int *pos) | 302 | static void aux_read(struct nand_chip *chip, u8 **buf, int len, int *pos) |
302 | { | 303 | { |
304 | struct mtd_info *mtd = nand_to_mtd(chip); | ||
305 | |||
303 | *pos += len; | 306 | *pos += len; |
304 | 307 | ||
305 | if (!*buf) { | 308 | if (!*buf) { |
306 | /* skip over "len" bytes */ | 309 | /* skip over "len" bytes */ |
307 | chip->cmdfunc(&chip->mtd, NAND_CMD_RNDOUT, *pos, -1); | 310 | chip->cmdfunc(mtd, NAND_CMD_RNDOUT, *pos, -1); |
308 | } else { | 311 | } else { |
309 | tango_read_buf(&chip->mtd, *buf, len); | 312 | tango_read_buf(mtd, *buf, len); |
310 | *buf += len; | 313 | *buf += len; |
311 | } | 314 | } |
312 | } | 315 | } |
313 | 316 | ||
314 | static void aux_write(struct nand_chip *chip, const u8 **buf, int len, int *pos) | 317 | static void aux_write(struct nand_chip *chip, const u8 **buf, int len, int *pos) |
315 | { | 318 | { |
319 | struct mtd_info *mtd = nand_to_mtd(chip); | ||
320 | |||
316 | *pos += len; | 321 | *pos += len; |
317 | 322 | ||
318 | if (!*buf) { | 323 | if (!*buf) { |
319 | /* skip over "len" bytes */ | 324 | /* skip over "len" bytes */ |
320 | chip->cmdfunc(&chip->mtd, NAND_CMD_SEQIN, *pos, -1); | 325 | chip->cmdfunc(mtd, NAND_CMD_SEQIN, *pos, -1); |
321 | } else { | 326 | } else { |
322 | tango_write_buf(&chip->mtd, *buf, len); | 327 | tango_write_buf(mtd, *buf, len); |
323 | *buf += len; | 328 | *buf += len; |
324 | } | 329 | } |
325 | } | 330 | } |
@@ -345,8 +350,9 @@ static void aux_write(struct nand_chip *chip, const u8 **buf, int len, int *pos) | |||
345 | */ | 350 | */ |
346 | static void raw_read(struct nand_chip *chip, u8 *buf, u8 *oob) | 351 | static void raw_read(struct nand_chip *chip, u8 *buf, u8 *oob) |
347 | { | 352 | { |
353 | struct mtd_info *mtd = nand_to_mtd(chip); | ||
348 | u8 *oob_orig = oob; | 354 | u8 *oob_orig = oob; |
349 | const int page_size = chip->mtd.writesize; | 355 | const int page_size = mtd->writesize; |
350 | const int ecc_size = chip->ecc.bytes; | 356 | const int ecc_size = chip->ecc.bytes; |
351 | const int pkt_size = chip->ecc.size; | 357 | const int pkt_size = chip->ecc.size; |
352 | int pos = 0; /* position within physical page */ | 358 | int pos = 0; /* position within physical page */ |
@@ -371,8 +377,9 @@ static void raw_read(struct nand_chip *chip, u8 *buf, u8 *oob) | |||
371 | 377 | ||
372 | static void raw_write(struct nand_chip *chip, const u8 *buf, const u8 *oob) | 378 | static void raw_write(struct nand_chip *chip, const u8 *buf, const u8 *oob) |
373 | { | 379 | { |
380 | struct mtd_info *mtd = nand_to_mtd(chip); | ||
374 | const u8 *oob_orig = oob; | 381 | const u8 *oob_orig = oob; |
375 | const int page_size = chip->mtd.writesize; | 382 | const int page_size = mtd->writesize; |
376 | const int ecc_size = chip->ecc.bytes; | 383 | const int ecc_size = chip->ecc.bytes; |
377 | const int pkt_size = chip->ecc.size; | 384 | const int pkt_size = chip->ecc.size; |
378 | int pos = 0; /* position within physical page */ | 385 | int pos = 0; /* position within physical page */ |
@@ -522,7 +529,7 @@ static int chip_init(struct device *dev, struct device_node *np) | |||
522 | 529 | ||
523 | chip = &tchip->nand_chip; | 530 | chip = &tchip->nand_chip; |
524 | ecc = &chip->ecc; | 531 | ecc = &chip->ecc; |
525 | mtd = &chip->mtd; | 532 | mtd = nand_to_mtd(chip); |
526 | 533 | ||
527 | chip->read_byte = tango_read_byte; | 534 | chip->read_byte = tango_read_byte; |
528 | chip->write_buf = tango_write_buf; | 535 | chip->write_buf = tango_write_buf; |
@@ -584,7 +591,7 @@ static int tango_nand_remove(struct platform_device *pdev) | |||
584 | 591 | ||
585 | for (cs = 0; cs < MAX_CS; ++cs) { | 592 | for (cs = 0; cs < MAX_CS; ++cs) { |
586 | if (nfc->chips[cs]) | 593 | if (nfc->chips[cs]) |
587 | nand_release(&nfc->chips[cs]->nand_chip.mtd); | 594 | nand_release(nand_to_mtd(&nfc->chips[cs]->nand_chip)); |
588 | } | 595 | } |
589 | 596 | ||
590 | return 0; | 597 | return 0; |