diff options
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 172 |
1 files changed, 109 insertions, 63 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 975b2ef611..baece61169 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -415,7 +415,7 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, | |||
415 | * Wait for the ready pin, after a command | 415 | * Wait for the ready pin, after a command |
416 | * The timeout is catched later. | 416 | * The timeout is catched later. |
417 | */ | 417 | */ |
418 | static void nand_wait_ready(struct mtd_info *mtd) | 418 | void nand_wait_ready(struct mtd_info *mtd) |
419 | { | 419 | { |
420 | struct nand_chip *chip = mtd->priv; | 420 | struct nand_chip *chip = mtd->priv; |
421 | unsigned long timeo = jiffies + 2; | 421 | unsigned long timeo = jiffies + 2; |
@@ -429,6 +429,7 @@ static void nand_wait_ready(struct mtd_info *mtd) | |||
429 | } while (time_before(jiffies, timeo)); | 429 | } while (time_before(jiffies, timeo)); |
430 | led_trigger_event(nand_led_trigger, LED_OFF); | 430 | led_trigger_event(nand_led_trigger, LED_OFF); |
431 | } | 431 | } |
432 | EXPORT_SYMBOL_GPL(nand_wait_ready); | ||
432 | 433 | ||
433 | /** | 434 | /** |
434 | * nand_command - [DEFAULT] Send command to NAND device | 435 | * nand_command - [DEFAULT] Send command to NAND device |
@@ -766,8 +767,8 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
766 | int eccbytes = chip->ecc.bytes; | 767 | int eccbytes = chip->ecc.bytes; |
767 | int eccsteps = chip->ecc.steps; | 768 | int eccsteps = chip->ecc.steps; |
768 | uint8_t *p = buf; | 769 | uint8_t *p = buf; |
769 | uint8_t *ecc_calc = chip->buffers.ecccalc; | 770 | uint8_t *ecc_calc = chip->buffers->ecccalc; |
770 | uint8_t *ecc_code = chip->buffers.ecccode; | 771 | uint8_t *ecc_code = chip->buffers->ecccode; |
771 | int *eccpos = chip->ecc.layout->eccpos; | 772 | int *eccpos = chip->ecc.layout->eccpos; |
772 | 773 | ||
773 | nand_read_page_raw(mtd, chip, buf); | 774 | nand_read_page_raw(mtd, chip, buf); |
@@ -808,8 +809,8 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
808 | int eccbytes = chip->ecc.bytes; | 809 | int eccbytes = chip->ecc.bytes; |
809 | int eccsteps = chip->ecc.steps; | 810 | int eccsteps = chip->ecc.steps; |
810 | uint8_t *p = buf; | 811 | uint8_t *p = buf; |
811 | uint8_t *ecc_calc = chip->buffers.ecccalc; | 812 | uint8_t *ecc_calc = chip->buffers->ecccalc; |
812 | uint8_t *ecc_code = chip->buffers.ecccode; | 813 | uint8_t *ecc_code = chip->buffers->ecccode; |
813 | int *eccpos = chip->ecc.layout->eccpos; | 814 | int *eccpos = chip->ecc.layout->eccpos; |
814 | 815 | ||
815 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { | 816 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { |
@@ -970,7 +971,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
970 | page = realpage & chip->pagemask; | 971 | page = realpage & chip->pagemask; |
971 | 972 | ||
972 | col = (int)(from & (mtd->writesize - 1)); | 973 | col = (int)(from & (mtd->writesize - 1)); |
973 | chip->oob_poi = chip->buffers.oobrbuf; | 974 | chip->oob_poi = chip->buffers->oobrbuf; |
974 | 975 | ||
975 | buf = ops->datbuf; | 976 | buf = ops->datbuf; |
976 | oob = ops->oobbuf; | 977 | oob = ops->oobbuf; |
@@ -981,7 +982,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
981 | 982 | ||
982 | /* Is the current page in the buffer ? */ | 983 | /* Is the current page in the buffer ? */ |
983 | if (realpage != chip->pagebuf || oob) { | 984 | if (realpage != chip->pagebuf || oob) { |
984 | bufpoi = aligned ? buf : chip->buffers.databuf; | 985 | bufpoi = aligned ? buf : chip->buffers->databuf; |
985 | 986 | ||
986 | if (likely(sndcmd)) { | 987 | if (likely(sndcmd)) { |
987 | chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); | 988 | chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); |
@@ -989,14 +990,17 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
989 | } | 990 | } |
990 | 991 | ||
991 | /* Now read the page into the buffer */ | 992 | /* Now read the page into the buffer */ |
992 | ret = chip->ecc.read_page(mtd, chip, bufpoi); | 993 | if (unlikely(ops->mode == MTD_OOB_RAW)) |
994 | ret = chip->ecc.read_page_raw(mtd, chip, bufpoi); | ||
995 | else | ||
996 | ret = chip->ecc.read_page(mtd, chip, bufpoi); | ||
993 | if (ret < 0) | 997 | if (ret < 0) |
994 | break; | 998 | break; |
995 | 999 | ||
996 | /* Transfer not aligned data */ | 1000 | /* Transfer not aligned data */ |
997 | if (!aligned) { | 1001 | if (!aligned) { |
998 | chip->pagebuf = realpage; | 1002 | chip->pagebuf = realpage; |
999 | memcpy(buf, chip->buffers.databuf + col, bytes); | 1003 | memcpy(buf, chip->buffers->databuf + col, bytes); |
1000 | } | 1004 | } |
1001 | 1005 | ||
1002 | buf += bytes; | 1006 | buf += bytes; |
@@ -1023,7 +1027,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1023 | nand_wait_ready(mtd); | 1027 | nand_wait_ready(mtd); |
1024 | } | 1028 | } |
1025 | } else { | 1029 | } else { |
1026 | memcpy(buf, chip->buffers.databuf + col, bytes); | 1030 | memcpy(buf, chip->buffers->databuf + col, bytes); |
1027 | buf += bytes; | 1031 | buf += bytes; |
1028 | } | 1032 | } |
1029 | 1033 | ||
@@ -1266,7 +1270,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1266 | realpage = (int)(from >> chip->page_shift); | 1270 | realpage = (int)(from >> chip->page_shift); |
1267 | page = realpage & chip->pagemask; | 1271 | page = realpage & chip->pagemask; |
1268 | 1272 | ||
1269 | chip->oob_poi = chip->buffers.oobrbuf; | 1273 | chip->oob_poi = chip->buffers->oobrbuf; |
1270 | 1274 | ||
1271 | while(1) { | 1275 | while(1) { |
1272 | sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); | 1276 | sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); |
@@ -1322,8 +1326,6 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1322 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, | 1326 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, |
1323 | struct mtd_oob_ops *ops) | 1327 | struct mtd_oob_ops *ops) |
1324 | { | 1328 | { |
1325 | int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip, | ||
1326 | uint8_t *buf) = NULL; | ||
1327 | struct nand_chip *chip = mtd->priv; | 1329 | struct nand_chip *chip = mtd->priv; |
1328 | int ret = -ENOTSUPP; | 1330 | int ret = -ENOTSUPP; |
1329 | 1331 | ||
@@ -1341,12 +1343,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, | |||
1341 | switch(ops->mode) { | 1343 | switch(ops->mode) { |
1342 | case MTD_OOB_PLACE: | 1344 | case MTD_OOB_PLACE: |
1343 | case MTD_OOB_AUTO: | 1345 | case MTD_OOB_AUTO: |
1344 | break; | ||
1345 | |||
1346 | case MTD_OOB_RAW: | 1346 | case MTD_OOB_RAW: |
1347 | /* Replace the read_page algorithm temporary */ | ||
1348 | read_page = chip->ecc.read_page; | ||
1349 | chip->ecc.read_page = nand_read_page_raw; | ||
1350 | break; | 1347 | break; |
1351 | 1348 | ||
1352 | default: | 1349 | default: |
@@ -1358,8 +1355,6 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, | |||
1358 | else | 1355 | else |
1359 | ret = nand_do_read_ops(mtd, from, ops); | 1356 | ret = nand_do_read_ops(mtd, from, ops); |
1360 | 1357 | ||
1361 | if (unlikely(ops->mode == MTD_OOB_RAW)) | ||
1362 | chip->ecc.read_page = read_page; | ||
1363 | out: | 1358 | out: |
1364 | nand_release_device(mtd); | 1359 | nand_release_device(mtd); |
1365 | return ret; | 1360 | return ret; |
@@ -1391,7 +1386,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1391 | int i, eccsize = chip->ecc.size; | 1386 | int i, eccsize = chip->ecc.size; |
1392 | int eccbytes = chip->ecc.bytes; | 1387 | int eccbytes = chip->ecc.bytes; |
1393 | int eccsteps = chip->ecc.steps; | 1388 | int eccsteps = chip->ecc.steps; |
1394 | uint8_t *ecc_calc = chip->buffers.ecccalc; | 1389 | uint8_t *ecc_calc = chip->buffers->ecccalc; |
1395 | const uint8_t *p = buf; | 1390 | const uint8_t *p = buf; |
1396 | int *eccpos = chip->ecc.layout->eccpos; | 1391 | int *eccpos = chip->ecc.layout->eccpos; |
1397 | 1392 | ||
@@ -1417,7 +1412,7 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1417 | int i, eccsize = chip->ecc.size; | 1412 | int i, eccsize = chip->ecc.size; |
1418 | int eccbytes = chip->ecc.bytes; | 1413 | int eccbytes = chip->ecc.bytes; |
1419 | int eccsteps = chip->ecc.steps; | 1414 | int eccsteps = chip->ecc.steps; |
1420 | uint8_t *ecc_calc = chip->buffers.ecccalc; | 1415 | uint8_t *ecc_calc = chip->buffers->ecccalc; |
1421 | const uint8_t *p = buf; | 1416 | const uint8_t *p = buf; |
1422 | int *eccpos = chip->ecc.layout->eccpos; | 1417 | int *eccpos = chip->ecc.layout->eccpos; |
1423 | 1418 | ||
@@ -1478,7 +1473,7 @@ static void nand_write_page_syndrome(struct mtd_info *mtd, | |||
1478 | } | 1473 | } |
1479 | 1474 | ||
1480 | /** | 1475 | /** |
1481 | * nand_write_page - [INTERNAL] write one page | 1476 | * nand_write_page - [REPLACEABLE] write one page |
1482 | * @mtd: MTD device structure | 1477 | * @mtd: MTD device structure |
1483 | * @chip: NAND chip descriptor | 1478 | * @chip: NAND chip descriptor |
1484 | * @buf: the data to write | 1479 | * @buf: the data to write |
@@ -1486,13 +1481,16 @@ static void nand_write_page_syndrome(struct mtd_info *mtd, | |||
1486 | * @cached: cached programming | 1481 | * @cached: cached programming |
1487 | */ | 1482 | */ |
1488 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, | 1483 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, |
1489 | const uint8_t *buf, int page, int cached) | 1484 | const uint8_t *buf, int page, int cached, int raw) |
1490 | { | 1485 | { |
1491 | int status; | 1486 | int status; |
1492 | 1487 | ||
1493 | chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); | 1488 | chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); |
1494 | 1489 | ||
1495 | chip->ecc.write_page(mtd, chip, buf); | 1490 | if (unlikely(raw)) |
1491 | chip->ecc.write_page_raw(mtd, chip, buf); | ||
1492 | else | ||
1493 | chip->ecc.write_page(mtd, chip, buf); | ||
1496 | 1494 | ||
1497 | /* | 1495 | /* |
1498 | * Cached progamming disabled for now, Not sure if its worth the | 1496 | * Cached progamming disabled for now, Not sure if its worth the |
@@ -1627,7 +1625,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
1627 | (chip->pagebuf << chip->page_shift) < (to + ops->len)) | 1625 | (chip->pagebuf << chip->page_shift) < (to + ops->len)) |
1628 | chip->pagebuf = -1; | 1626 | chip->pagebuf = -1; |
1629 | 1627 | ||
1630 | chip->oob_poi = chip->buffers.oobwbuf; | 1628 | chip->oob_poi = chip->buffers->oobwbuf; |
1631 | 1629 | ||
1632 | while(1) { | 1630 | while(1) { |
1633 | int cached = writelen > bytes && page != blockmask; | 1631 | int cached = writelen > bytes && page != blockmask; |
@@ -1635,7 +1633,8 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
1635 | if (unlikely(oob)) | 1633 | if (unlikely(oob)) |
1636 | oob = nand_fill_oob(chip, oob, ops); | 1634 | oob = nand_fill_oob(chip, oob, ops); |
1637 | 1635 | ||
1638 | ret = nand_write_page(mtd, chip, buf, page, cached); | 1636 | ret = chip->write_page(mtd, chip, buf, page, cached, |
1637 | (ops->mode == MTD_OOB_RAW)); | ||
1639 | if (ret) | 1638 | if (ret) |
1640 | break; | 1639 | break; |
1641 | 1640 | ||
@@ -1745,7 +1744,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
1745 | if (page == chip->pagebuf) | 1744 | if (page == chip->pagebuf) |
1746 | chip->pagebuf = -1; | 1745 | chip->pagebuf = -1; |
1747 | 1746 | ||
1748 | chip->oob_poi = chip->buffers.oobwbuf; | 1747 | chip->oob_poi = chip->buffers->oobwbuf; |
1749 | memset(chip->oob_poi, 0xff, mtd->oobsize); | 1748 | memset(chip->oob_poi, 0xff, mtd->oobsize); |
1750 | nand_fill_oob(chip, ops->oobbuf, ops); | 1749 | nand_fill_oob(chip, ops->oobbuf, ops); |
1751 | status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); | 1750 | status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); |
@@ -1768,8 +1767,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
1768 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, | 1767 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, |
1769 | struct mtd_oob_ops *ops) | 1768 | struct mtd_oob_ops *ops) |
1770 | { | 1769 | { |
1771 | void (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, | ||
1772 | const uint8_t *buf) = NULL; | ||
1773 | struct nand_chip *chip = mtd->priv; | 1770 | struct nand_chip *chip = mtd->priv; |
1774 | int ret = -ENOTSUPP; | 1771 | int ret = -ENOTSUPP; |
1775 | 1772 | ||
@@ -1787,12 +1784,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, | |||
1787 | switch(ops->mode) { | 1784 | switch(ops->mode) { |
1788 | case MTD_OOB_PLACE: | 1785 | case MTD_OOB_PLACE: |
1789 | case MTD_OOB_AUTO: | 1786 | case MTD_OOB_AUTO: |
1790 | break; | ||
1791 | |||
1792 | case MTD_OOB_RAW: | 1787 | case MTD_OOB_RAW: |
1793 | /* Replace the write_page algorithm temporary */ | ||
1794 | write_page = chip->ecc.write_page; | ||
1795 | chip->ecc.write_page = nand_write_page_raw; | ||
1796 | break; | 1788 | break; |
1797 | 1789 | ||
1798 | default: | 1790 | default: |
@@ -1804,8 +1796,6 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, | |||
1804 | else | 1796 | else |
1805 | ret = nand_do_write_ops(mtd, to, ops); | 1797 | ret = nand_do_write_ops(mtd, to, ops); |
1806 | 1798 | ||
1807 | if (unlikely(ops->mode == MTD_OOB_RAW)) | ||
1808 | chip->ecc.write_page = write_page; | ||
1809 | out: | 1799 | out: |
1810 | nand_release_device(mtd); | 1800 | nand_release_device(mtd); |
1811 | return ret; | 1801 | return ret; |
@@ -2288,40 +2278,22 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2288 | return type; | 2278 | return type; |
2289 | } | 2279 | } |
2290 | 2280 | ||
2291 | /* module_text_address() isn't exported, and it's mostly a pointless | ||
2292 | test if this is a module _anyway_ -- they'd have to try _really_ hard | ||
2293 | to call us from in-kernel code if the core NAND support is modular. */ | ||
2294 | #ifdef MODULE | ||
2295 | #define caller_is_module() (1) | ||
2296 | #else | ||
2297 | #define caller_is_module() \ | ||
2298 | module_text_address((unsigned long)__builtin_return_address(0)) | ||
2299 | #endif | ||
2300 | |||
2301 | /** | 2281 | /** |
2302 | * nand_scan - [NAND Interface] Scan for the NAND device | 2282 | * nand_scan_ident - [NAND Interface] Scan for the NAND device |
2303 | * @mtd: MTD device structure | 2283 | * @mtd: MTD device structure |
2304 | * @maxchips: Number of chips to scan for | 2284 | * @maxchips: Number of chips to scan for |
2305 | * | 2285 | * |
2306 | * This fills out all the uninitialized function pointers | 2286 | * This is the first phase of the normal nand_scan() function. It |
2307 | * with the defaults. | 2287 | * reads the flash ID and sets up MTD fields accordingly. |
2308 | * The flash ID is read and the mtd/chip structures are | ||
2309 | * filled with the appropriate values. | ||
2310 | * The mtd->owner field must be set to the module of the caller | ||
2311 | * | 2288 | * |
2289 | * The mtd->owner field must be set to the module of the caller. | ||
2312 | */ | 2290 | */ |
2313 | int nand_scan(struct mtd_info *mtd, int maxchips) | 2291 | int nand_scan_ident(struct mtd_info *mtd, int maxchips) |
2314 | { | 2292 | { |
2315 | int i, busw, nand_maf_id; | 2293 | int i, busw, nand_maf_id; |
2316 | struct nand_chip *chip = mtd->priv; | 2294 | struct nand_chip *chip = mtd->priv; |
2317 | struct nand_flash_dev *type; | 2295 | struct nand_flash_dev *type; |
2318 | 2296 | ||
2319 | /* Many callers got this wrong, so check for it for a while... */ | ||
2320 | if (!mtd->owner && caller_is_module()) { | ||
2321 | printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n"); | ||
2322 | BUG(); | ||
2323 | } | ||
2324 | |||
2325 | /* Get buswidth to select the correct functions */ | 2297 | /* Get buswidth to select the correct functions */ |
2326 | busw = chip->options & NAND_BUSWIDTH_16; | 2298 | busw = chip->options & NAND_BUSWIDTH_16; |
2327 | /* Set the default functions */ | 2299 | /* Set the default functions */ |
@@ -2353,8 +2325,31 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2353 | chip->numchips = i; | 2325 | chip->numchips = i; |
2354 | mtd->size = i * chip->chipsize; | 2326 | mtd->size = i * chip->chipsize; |
2355 | 2327 | ||
2328 | return 0; | ||
2329 | } | ||
2330 | |||
2331 | |||
2332 | /** | ||
2333 | * nand_scan_tail - [NAND Interface] Scan for the NAND device | ||
2334 | * @mtd: MTD device structure | ||
2335 | * @maxchips: Number of chips to scan for | ||
2336 | * | ||
2337 | * This is the second phase of the normal nand_scan() function. It | ||
2338 | * fills out all the uninitialized function pointers with the defaults | ||
2339 | * and scans for a bad block table if appropriate. | ||
2340 | */ | ||
2341 | int nand_scan_tail(struct mtd_info *mtd) | ||
2342 | { | ||
2343 | int i; | ||
2344 | struct nand_chip *chip = mtd->priv; | ||
2345 | |||
2346 | if (!(chip->options & NAND_OWN_BUFFERS)) | ||
2347 | chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL); | ||
2348 | if (!chip->buffers) | ||
2349 | return -ENOMEM; | ||
2350 | |||
2356 | /* Preset the internal oob write buffer */ | 2351 | /* Preset the internal oob write buffer */ |
2357 | memset(chip->buffers.oobwbuf, 0xff, mtd->oobsize); | 2352 | memset(chip->buffers->oobwbuf, 0xff, mtd->oobsize); |
2358 | 2353 | ||
2359 | /* | 2354 | /* |
2360 | * If no default placement scheme is given, select an appropriate one | 2355 | * If no default placement scheme is given, select an appropriate one |
@@ -2377,10 +2372,18 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2377 | } | 2372 | } |
2378 | } | 2373 | } |
2379 | 2374 | ||
2375 | if (!chip->write_page) | ||
2376 | chip->write_page = nand_write_page; | ||
2377 | |||
2380 | /* | 2378 | /* |
2381 | * check ECC mode, default to software if 3byte/512byte hardware ECC is | 2379 | * check ECC mode, default to software if 3byte/512byte hardware ECC is |
2382 | * selected and we have 256 byte pagesize fallback to software ECC | 2380 | * selected and we have 256 byte pagesize fallback to software ECC |
2383 | */ | 2381 | */ |
2382 | if (!chip->ecc.read_page_raw) | ||
2383 | chip->ecc.read_page_raw = nand_read_page_raw; | ||
2384 | if (!chip->ecc.write_page_raw) | ||
2385 | chip->ecc.write_page_raw = nand_write_page_raw; | ||
2386 | |||
2384 | switch (chip->ecc.mode) { | 2387 | switch (chip->ecc.mode) { |
2385 | case NAND_ECC_HW: | 2388 | case NAND_ECC_HW: |
2386 | /* Use standard hwecc read page function ? */ | 2389 | /* Use standard hwecc read page function ? */ |
@@ -2438,6 +2441,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2438 | chip->ecc.size = mtd->writesize; | 2441 | chip->ecc.size = mtd->writesize; |
2439 | chip->ecc.bytes = 0; | 2442 | chip->ecc.bytes = 0; |
2440 | break; | 2443 | break; |
2444 | |||
2441 | default: | 2445 | default: |
2442 | printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", | 2446 | printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", |
2443 | chip->ecc.mode); | 2447 | chip->ecc.mode); |
@@ -2503,6 +2507,44 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2503 | return chip->scan_bbt(mtd); | 2507 | return chip->scan_bbt(mtd); |
2504 | } | 2508 | } |
2505 | 2509 | ||
2510 | /* module_text_address() isn't exported, and it's mostly a pointless | ||
2511 | test if this is a module _anyway_ -- they'd have to try _really_ hard | ||
2512 | to call us from in-kernel code if the core NAND support is modular. */ | ||
2513 | #ifdef MODULE | ||
2514 | #define caller_is_module() (1) | ||
2515 | #else | ||
2516 | #define caller_is_module() \ | ||
2517 | module_text_address((unsigned long)__builtin_return_address(0)) | ||
2518 | #endif | ||
2519 | |||
2520 | /** | ||
2521 | * nand_scan - [NAND Interface] Scan for the NAND device | ||
2522 | * @mtd: MTD device structure | ||
2523 | * @maxchips: Number of chips to scan for | ||
2524 | * | ||
2525 | * This fills out all the uninitialized function pointers | ||
2526 | * with the defaults. | ||
2527 | * The flash ID is read and the mtd/chip structures are | ||
2528 | * filled with the appropriate values. | ||
2529 | * The mtd->owner field must be set to the module of the caller | ||
2530 | * | ||
2531 | */ | ||
2532 | int nand_scan(struct mtd_info *mtd, int maxchips) | ||
2533 | { | ||
2534 | int ret; | ||
2535 | |||
2536 | /* Many callers got this wrong, so check for it for a while... */ | ||
2537 | if (!mtd->owner && caller_is_module()) { | ||
2538 | printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n"); | ||
2539 | BUG(); | ||
2540 | } | ||
2541 | |||
2542 | ret = nand_scan_ident(mtd, maxchips); | ||
2543 | if (!ret) | ||
2544 | ret = nand_scan_tail(mtd); | ||
2545 | return ret; | ||
2546 | } | ||
2547 | |||
2506 | /** | 2548 | /** |
2507 | * nand_release - [NAND Interface] Free resources held by the NAND device | 2549 | * nand_release - [NAND Interface] Free resources held by the NAND device |
2508 | * @mtd: MTD device structure | 2550 | * @mtd: MTD device structure |
@@ -2520,9 +2562,13 @@ void nand_release(struct mtd_info *mtd) | |||
2520 | 2562 | ||
2521 | /* Free bad block table memory */ | 2563 | /* Free bad block table memory */ |
2522 | kfree(chip->bbt); | 2564 | kfree(chip->bbt); |
2565 | if (!(chip->options & NAND_OWN_BUFFERS)) | ||
2566 | kfree(chip->buffers); | ||
2523 | } | 2567 | } |
2524 | 2568 | ||
2525 | EXPORT_SYMBOL_GPL(nand_scan); | 2569 | EXPORT_SYMBOL_GPL(nand_scan); |
2570 | EXPORT_SYMBOL_GPL(nand_scan_ident); | ||
2571 | EXPORT_SYMBOL_GPL(nand_scan_tail); | ||
2526 | EXPORT_SYMBOL_GPL(nand_release); | 2572 | EXPORT_SYMBOL_GPL(nand_release); |
2527 | 2573 | ||
2528 | static int __init nand_base_init(void) | 2574 | static int __init nand_base_init(void) |