aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorArchit Taneja <architt@codeaurora.org>2016-02-03 03:59:49 -0500
committerBrian Norris <computersforpeace@gmail.com>2016-03-10 13:52:21 -0500
commit9f3e04297b08212ef43fce4f167e01f40a98d243 (patch)
tree2ab5f381b077246a8ed4a752269742a7e36cec03 /drivers/mtd
parent9648388fc7737365be7a8092e77df78ccc2cd1a4 (diff)
mtd: nand: don't select chip in nand_chip's block_bad op
One of the arguments passed to struct nand_chip's block_bad op is 'getchip', which, if true, is supposed to get and select the nand device, and later unselect and release the device. This op is intended to be replaceable by drivers. The drivers shouldn't be responsible for selecting/unselecting chip. Like other ops, the chip should already be selected before the block_bad op is called. Remove the getchip argument from the block_bad op and nand_block_checkbad. Move the chip selection to nand_block_isbad, since it is the only caller to nand_block_checkbad which requires chip selection. Modify nand_block_bad (the default function for the op) such that it doesn't select the chip. Remove the getchip argument from the bad_block funcs in cafe_nand, diskonchip and docg4 drivers. Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Archit Taneja <architt@codeaurora.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/cafe_nand.c2
-rw-r--r--drivers/mtd/nand/diskonchip.c2
-rw-r--r--drivers/mtd/nand/docg4.c2
-rw-r--r--drivers/mtd/nand/nand_base.c41
4 files changed, 22 insertions, 25 deletions
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index aa1a616b9fb6..e553aff68987 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -537,7 +537,7 @@ static int cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
537 return 0; 537 return 0;
538} 538}
539 539
540static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 540static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs)
541{ 541{
542 return 0; 542 return 0;
543} 543}
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index f170f3c31b34..547c1002941d 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -794,7 +794,7 @@ static int doc200x_dev_ready(struct mtd_info *mtd)
794 } 794 }
795} 795}
796 796
797static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 797static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs)
798{ 798{
799 /* This is our last resort if we couldn't find or create a BBT. Just 799 /* This is our last resort if we couldn't find or create a BBT. Just
800 pretend all blocks are good. */ 800 pretend all blocks are good. */
diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c
index fb46fd7e056b..d86a60e1bbcb 100644
--- a/drivers/mtd/nand/docg4.c
+++ b/drivers/mtd/nand/docg4.c
@@ -1120,7 +1120,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs)
1120 return ret; 1120 return ret;
1121} 1121}
1122 1122
1123static int docg4_block_neverbad(struct mtd_info *mtd, loff_t ofs, int getchip) 1123static int docg4_block_neverbad(struct mtd_info *mtd, loff_t ofs)
1124{ 1124{
1125 /* only called when module_param ignore_badblocks is set */ 1125 /* only called when module_param ignore_badblocks is set */
1126 return 0; 1126 return 0;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 191e4f75a513..d49b01df3513 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -317,9 +317,9 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
317 * 317 *
318 * Check, if the block is bad. 318 * Check, if the block is bad.
319 */ 319 */
320static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 320static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
321{ 321{
322 int page, chipnr, res = 0, i = 0; 322 int page, res = 0, i = 0;
323 struct nand_chip *chip = mtd_to_nand(mtd); 323 struct nand_chip *chip = mtd_to_nand(mtd);
324 u16 bad; 324 u16 bad;
325 325
@@ -328,15 +328,6 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
328 328
329 page = (int)(ofs >> chip->page_shift) & chip->pagemask; 329 page = (int)(ofs >> chip->page_shift) & chip->pagemask;
330 330
331 if (getchip) {
332 chipnr = (int)(ofs >> chip->chip_shift);
333
334 nand_get_device(mtd, FL_READING);
335
336 /* Select the NAND device */
337 chip->select_chip(mtd, chipnr);
338 }
339
340 do { 331 do {
341 if (chip->options & NAND_BUSWIDTH_16) { 332 if (chip->options & NAND_BUSWIDTH_16) {
342 chip->cmdfunc(mtd, NAND_CMD_READOOB, 333 chip->cmdfunc(mtd, NAND_CMD_READOOB,
@@ -361,11 +352,6 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
361 i++; 352 i++;
362 } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); 353 } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE));
363 354
364 if (getchip) {
365 chip->select_chip(mtd, -1);
366 nand_release_device(mtd);
367 }
368
369 return res; 355 return res;
370} 356}
371 357
@@ -503,19 +489,17 @@ static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
503 * nand_block_checkbad - [GENERIC] Check if a block is marked bad 489 * nand_block_checkbad - [GENERIC] Check if a block is marked bad
504 * @mtd: MTD device structure 490 * @mtd: MTD device structure
505 * @ofs: offset from device start 491 * @ofs: offset from device start
506 * @getchip: 0, if the chip is already selected
507 * @allowbbt: 1, if its allowed to access the bbt area 492 * @allowbbt: 1, if its allowed to access the bbt area
508 * 493 *
509 * Check, if the block is bad. Either by reading the bad block table or 494 * Check, if the block is bad. Either by reading the bad block table or
510 * calling of the scan function. 495 * calling of the scan function.
511 */ 496 */
512static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, 497static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt)
513 int allowbbt)
514{ 498{
515 struct nand_chip *chip = mtd_to_nand(mtd); 499 struct nand_chip *chip = mtd_to_nand(mtd);
516 500
517 if (!chip->bbt) 501 if (!chip->bbt)
518 return chip->block_bad(mtd, ofs, getchip); 502 return chip->block_bad(mtd, ofs);
519 503
520 /* Return info from the table */ 504 /* Return info from the table */
521 return nand_isbad_bbt(mtd, ofs, allowbbt); 505 return nand_isbad_bbt(mtd, ofs, allowbbt);
@@ -2949,7 +2933,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2949 while (len) { 2933 while (len) {
2950 /* Check if we have a bad block, we do not erase bad blocks! */ 2934 /* Check if we have a bad block, we do not erase bad blocks! */
2951 if (nand_block_checkbad(mtd, ((loff_t) page) << 2935 if (nand_block_checkbad(mtd, ((loff_t) page) <<
2952 chip->page_shift, 0, allowbbt)) { 2936 chip->page_shift, allowbbt)) {
2953 pr_warn("%s: attempt to erase a bad block at page 0x%08x\n", 2937 pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
2954 __func__, page); 2938 __func__, page);
2955 instr->state = MTD_ERASE_FAILED; 2939 instr->state = MTD_ERASE_FAILED;
@@ -3036,7 +3020,20 @@ static void nand_sync(struct mtd_info *mtd)
3036 */ 3020 */
3037static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) 3021static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
3038{ 3022{
3039 return nand_block_checkbad(mtd, offs, 1, 0); 3023 struct nand_chip *chip = mtd_to_nand(mtd);
3024 int chipnr = (int)(offs >> chip->chip_shift);
3025 int ret;
3026
3027 /* Select the NAND device */
3028 nand_get_device(mtd, FL_READING);
3029 chip->select_chip(mtd, chipnr);
3030
3031 ret = nand_block_checkbad(mtd, offs, 0);
3032
3033 chip->select_chip(mtd, -1);
3034 nand_release_device(mtd);
3035
3036 return ret;
3040} 3037}
3041 3038
3042/** 3039/**