diff options
author | David Woodhouse <dwmw2@infradead.org> | 2006-09-25 12:06:53 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2006-09-25 12:06:53 -0400 |
commit | 3b85c3211ebde263a86c8cd3c7277fdd2e440310 (patch) | |
tree | 31c837ab0ce86eb4ade51836a624bbeadb60204f | |
parent | 4b648b0253c0976e944ea07e38a2d53ad4d0b30e (diff) |
[MTD NAND] Split nand_scan() into two parts; allow board driver to intervene
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 90 | ||||
-rw-r--r-- | include/linux/mtd/nand.h | 5 |
2 files changed, 70 insertions, 25 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 8da8862d0548..492ff9d1a35c 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -2289,40 +2289,22 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2289 | return type; | 2289 | return type; |
2290 | } | 2290 | } |
2291 | 2291 | ||
2292 | /* module_text_address() isn't exported, and it's mostly a pointless | ||
2293 | test if this is a module _anyway_ -- they'd have to try _really_ hard | ||
2294 | to call us from in-kernel code if the core NAND support is modular. */ | ||
2295 | #ifdef MODULE | ||
2296 | #define caller_is_module() (1) | ||
2297 | #else | ||
2298 | #define caller_is_module() \ | ||
2299 | module_text_address((unsigned long)__builtin_return_address(0)) | ||
2300 | #endif | ||
2301 | |||
2302 | /** | 2292 | /** |
2303 | * nand_scan - [NAND Interface] Scan for the NAND device | 2293 | * nand_scan_ident - [NAND Interface] Scan for the NAND device |
2304 | * @mtd: MTD device structure | 2294 | * @mtd: MTD device structure |
2305 | * @maxchips: Number of chips to scan for | 2295 | * @maxchips: Number of chips to scan for |
2306 | * | 2296 | * |
2307 | * This fills out all the uninitialized function pointers | 2297 | * This is the first phase of the normal nand_scan() function. It |
2308 | * with the defaults. | 2298 | * reads the flash ID and sets up MTD fields accordingly. |
2309 | * The flash ID is read and the mtd/chip structures are | ||
2310 | * filled with the appropriate values. | ||
2311 | * The mtd->owner field must be set to the module of the caller | ||
2312 | * | 2299 | * |
2300 | * The mtd->owner field must be set to the module of the caller. | ||
2313 | */ | 2301 | */ |
2314 | int nand_scan(struct mtd_info *mtd, int maxchips) | 2302 | int nand_scan_ident(struct mtd_info *mtd, int maxchips) |
2315 | { | 2303 | { |
2316 | int i, busw, nand_maf_id; | 2304 | int i, busw, nand_maf_id; |
2317 | struct nand_chip *chip = mtd->priv; | 2305 | struct nand_chip *chip = mtd->priv; |
2318 | struct nand_flash_dev *type; | 2306 | struct nand_flash_dev *type; |
2319 | 2307 | ||
2320 | /* Many callers got this wrong, so check for it for a while... */ | ||
2321 | if (!mtd->owner && caller_is_module()) { | ||
2322 | printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n"); | ||
2323 | BUG(); | ||
2324 | } | ||
2325 | |||
2326 | /* Get buswidth to select the correct functions */ | 2308 | /* Get buswidth to select the correct functions */ |
2327 | busw = chip->options & NAND_BUSWIDTH_16; | 2309 | busw = chip->options & NAND_BUSWIDTH_16; |
2328 | /* Set the default functions */ | 2310 | /* Set the default functions */ |
@@ -2354,6 +2336,24 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2354 | chip->numchips = i; | 2336 | chip->numchips = i; |
2355 | mtd->size = i * chip->chipsize; | 2337 | mtd->size = i * chip->chipsize; |
2356 | 2338 | ||
2339 | return 0; | ||
2340 | } | ||
2341 | |||
2342 | |||
2343 | /** | ||
2344 | * nand_scan_tail - [NAND Interface] Scan for the NAND device | ||
2345 | * @mtd: MTD device structure | ||
2346 | * @maxchips: Number of chips to scan for | ||
2347 | * | ||
2348 | * This is the second phase of the normal nand_scan() function. It | ||
2349 | * fills out all the uninitialized function pointers with the defaults | ||
2350 | * and scans for a bad block table if appropriate. | ||
2351 | */ | ||
2352 | int nand_scan_tail(struct mtd_info *mtd) | ||
2353 | { | ||
2354 | int i; | ||
2355 | struct nand_chip *chip = mtd->priv; | ||
2356 | |||
2357 | /* Preset the internal oob write buffer */ | 2357 | /* Preset the internal oob write buffer */ |
2358 | memset(chip->buffers.oobwbuf, 0xff, mtd->oobsize); | 2358 | memset(chip->buffers.oobwbuf, 0xff, mtd->oobsize); |
2359 | 2359 | ||
@@ -2504,6 +2504,44 @@ int nand_scan(struct mtd_info *mtd, int maxchips) | |||
2504 | return chip->scan_bbt(mtd); | 2504 | return chip->scan_bbt(mtd); |
2505 | } | 2505 | } |
2506 | 2506 | ||
2507 | /* module_text_address() isn't exported, and it's mostly a pointless | ||
2508 | test if this is a module _anyway_ -- they'd have to try _really_ hard | ||
2509 | to call us from in-kernel code if the core NAND support is modular. */ | ||
2510 | #ifdef MODULE | ||
2511 | #define caller_is_module() (1) | ||
2512 | #else | ||
2513 | #define caller_is_module() \ | ||
2514 | module_text_address((unsigned long)__builtin_return_address(0)) | ||
2515 | #endif | ||
2516 | |||
2517 | /** | ||
2518 | * nand_scan - [NAND Interface] Scan for the NAND device | ||
2519 | * @mtd: MTD device structure | ||
2520 | * @maxchips: Number of chips to scan for | ||
2521 | * | ||
2522 | * This fills out all the uninitialized function pointers | ||
2523 | * with the defaults. | ||
2524 | * The flash ID is read and the mtd/chip structures are | ||
2525 | * filled with the appropriate values. | ||
2526 | * The mtd->owner field must be set to the module of the caller | ||
2527 | * | ||
2528 | */ | ||
2529 | int nand_scan(struct mtd_info *mtd, int maxchips) | ||
2530 | { | ||
2531 | int ret; | ||
2532 | |||
2533 | /* Many callers got this wrong, so check for it for a while... */ | ||
2534 | if (!mtd->owner && caller_is_module()) { | ||
2535 | printk(KERN_CRIT "nand_scan() called with NULL mtd->owner!\n"); | ||
2536 | BUG(); | ||
2537 | } | ||
2538 | |||
2539 | ret = nand_scan_ident(mtd, maxchips); | ||
2540 | if (!ret) | ||
2541 | ret = nand_scan_tail(mtd); | ||
2542 | return ret; | ||
2543 | } | ||
2544 | |||
2507 | /** | 2545 | /** |
2508 | * nand_release - [NAND Interface] Free resources held by the NAND device | 2546 | * nand_release - [NAND Interface] Free resources held by the NAND device |
2509 | * @mtd: MTD device structure | 2547 | * @mtd: MTD device structure |
@@ -2524,6 +2562,8 @@ void nand_release(struct mtd_info *mtd) | |||
2524 | } | 2562 | } |
2525 | 2563 | ||
2526 | EXPORT_SYMBOL_GPL(nand_scan); | 2564 | EXPORT_SYMBOL_GPL(nand_scan); |
2565 | EXPORT_SYMBOL_GPL(nand_scan_ident); | ||
2566 | EXPORT_SYMBOL_GPL(nand_scan_tail); | ||
2527 | EXPORT_SYMBOL_GPL(nand_release); | 2567 | EXPORT_SYMBOL_GPL(nand_release); |
2528 | 2568 | ||
2529 | static int __init nand_base_init(void) | 2569 | static int __init nand_base_init(void) |
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 0b4cd2fa64aa..88d690d79d77 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h | |||
@@ -27,6 +27,11 @@ | |||
27 | struct mtd_info; | 27 | struct mtd_info; |
28 | /* Scan and identify a NAND device */ | 28 | /* Scan and identify a NAND device */ |
29 | extern int nand_scan (struct mtd_info *mtd, int max_chips); | 29 | extern int nand_scan (struct mtd_info *mtd, int max_chips); |
30 | /* Separate phases of nand_scan(), allowing board driver to intervene | ||
31 | * and override command or ECC setup according to flash type */ | ||
32 | extern int nand_scan_ident(struct mtd_info *mtd, int max_chips); | ||
33 | extern int nand_scan_tail(struct mtd_info *mtd); | ||
34 | |||
30 | /* Free resources held by the NAND device */ | 35 | /* Free resources held by the NAND device */ |
31 | extern void nand_release (struct mtd_info *mtd); | 36 | extern void nand_release (struct mtd_info *mtd); |
32 | 37 | ||