diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-13 22:31:43 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-13 22:31:43 -0500 |
commit | 82cb6acea4d10fa4080612c58deb63993f558e5a (patch) | |
tree | ba6f0b8281e37c7e1830ef2162d38d8a2bc2fbb7 /drivers/mtd/nand | |
parent | 0d522ee7499e4abe7189b2f1728e838959b8ddde (diff) | |
parent | 885d71e5838f68d5dbee92ab952cc90ad6c1dc6b (diff) |
Merge tag 'for-linus-20131112' of git://git.infradead.org/linux-mtd
Pull MTD changes from Brian Norris:
- Unify some compile-time differences so that we have fewer uses of
#ifdef CONFIG_OF in atmel_nand
- Other general cleanups (removing unused functions, options,
variables, fields; use correct interfaces)
- Fix BUG() for new odd-sized NAND, which report non-power-of-2
dimensions via ONFI
- Miscellaneous driver fixes (SPI NOR flash; BCM47xx NAND flash; etc.)
- Improve differentiation between SLC and MLC NAND -- this clarifies an
ABI issue regarding the MTD "type" (in sysfs and in the MEMGETINFO
ioctl), where the MTD_MLCNANDFLASH type was present but
inconsistently used
- Extend GPMI NAND to support multi-chip-select NAND for some platforms
- Many improvements to the OMAP2/3 NAND driver, including an expanded
DT binding to bring us closer to mainline support for some OMAP
systems
- Fix a deadlock in the error path of the Atmel NAND driver probe
- Correct the error codes from MTD mmap() to conform to POSIX and the
Linux Programmer's Manual. This is an acknowledged change in the MTD
ABI, but I can't imagine somebody relying on the non-standard -ENOSYS
error code specifically. Am I just being unimaginative? :)
- Fix a few important GPMI NAND bugs (one regression from 3.12 and one
long-standing race condition)
- More? Read the log!
* tag 'for-linus-20131112' of git://git.infradead.org/linux-mtd: (98 commits)
mtd: gpmi: fix the NULL pointer
mtd: gpmi: fix kernel BUG due to racing DMA operations
mtd: mtdchar: return expected errors on mmap() call
mtd: gpmi: only scan two chips for imx6
mtd: gpmi: Use devm_kzalloc()
mtd: atmel_nand: fix bug driver will in a dead lock if no nand detected
mtd: nand: use a local variable to simplify the nand_scan_tail
mtd: nand: remove deprecated IRQF_DISABLED
mtd: dataflash: Say if we find a device we don't support
mtd: nand: omap: fix error return code in omap_nand_probe()
mtd: nand_bbt: kill NAND_BBT_SCANALLPAGES
mtd: m25p80: fixup device removal failure path
mtd: mxc_nand: Include linux/of.h header
mtd: remove duplicated include from mtdcore.c
mtd: m25p80: add support for Macronix mx25l3255e
mtd: nand: omap: remove selection of BCH ecc-scheme via KConfig
mtd: nand: omap: updated devm_xx for all resource allocation and free calls
mtd: nand: omap: use drivers/mtd/nand/nand_bch.c wrapper for BCH ECC instead of lib/bch.c
mtd: nand: omap: clean-up ecc layout for BCH ecc schemes
mtd: nand: omap2: clean-up BCHx_HW and BCHx_SW ECC configurations in device_probe
...
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r-- | drivers/mtd/nand/Kconfig | 40 | ||||
-rw-r--r-- | drivers/mtd/nand/atmel_nand.c | 67 | ||||
-rw-r--r-- | drivers/mtd/nand/bcm47xxnflash/main.c | 38 | ||||
-rw-r--r-- | drivers/mtd/nand/denali.c | 4 | ||||
-rw-r--r-- | drivers/mtd/nand/denali_pci.c | 1 | ||||
-rw-r--r-- | drivers/mtd/nand/diskonchip.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/docg4.c | 16 | ||||
-rw-r--r-- | drivers/mtd/nand/fsl_elbc_nand.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/fsl_ifc_nand.c | 134 | ||||
-rw-r--r-- | drivers/mtd/nand/gpmi-nand/gpmi-lib.c | 13 | ||||
-rw-r--r-- | drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 66 | ||||
-rw-r--r-- | drivers/mtd/nand/gpmi-nand/gpmi-regs.h | 3 | ||||
-rw-r--r-- | drivers/mtd/nand/lpc32xx_mlc.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/lpc32xx_slc.c | 10 | ||||
-rw-r--r-- | drivers/mtd/nand/mxc_nand.c | 3 | ||||
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 305 | ||||
-rw-r--r-- | drivers/mtd/nand/nand_bbt.c | 38 | ||||
-rw-r--r-- | drivers/mtd/nand/nandsim.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/omap2.c | 642 | ||||
-rw-r--r-- | drivers/mtd/nand/pxa3xx_nand.c | 56 | ||||
-rw-r--r-- | drivers/mtd/nand/socrates_nand.c | 14 | ||||
-rw-r--r-- | drivers/mtd/nand/tmio_nand.c | 3 |
22 files changed, 690 insertions, 771 deletions
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index d88529841d3f..93ae6a6d94f7 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig | |||
@@ -96,43 +96,15 @@ config MTD_NAND_OMAP2 | |||
96 | 96 | ||
97 | config MTD_NAND_OMAP_BCH | 97 | config MTD_NAND_OMAP_BCH |
98 | depends on MTD_NAND && MTD_NAND_OMAP2 && ARCH_OMAP3 | 98 | depends on MTD_NAND && MTD_NAND_OMAP2 && ARCH_OMAP3 |
99 | tristate "Enable support for hardware BCH error correction" | 99 | tristate "Support hardware based BCH error correction" |
100 | default n | 100 | default n |
101 | select BCH | 101 | select BCH |
102 | select BCH_CONST_PARAMS | ||
103 | help | 102 | help |
104 | Support for hardware BCH error correction. | 103 | This config enables the ELM hardware engine, which can be used to |
105 | 104 | locate and correct errors when using BCH ECC scheme. This offloads | |
106 | choice | 105 | the cpu from doing ECC error searching and correction. However some |
107 | prompt "BCH error correction capability" | 106 | legacy OMAP families like OMAP2xxx, OMAP3xxx do not have ELM engine |
108 | depends on MTD_NAND_OMAP_BCH | 107 | so they should not enable this config symbol. |
109 | |||
110 | config MTD_NAND_OMAP_BCH8 | ||
111 | bool "8 bits / 512 bytes (recommended)" | ||
112 | help | ||
113 | Support correcting up to 8 bitflips per 512-byte block. | ||
114 | This will use 13 bytes of spare area per 512 bytes of page data. | ||
115 | This is the recommended mode, as 4-bit mode does not work | ||
116 | on some OMAP3 revisions, due to a hardware bug. | ||
117 | |||
118 | config MTD_NAND_OMAP_BCH4 | ||
119 | bool "4 bits / 512 bytes" | ||
120 | help | ||
121 | Support correcting up to 4 bitflips per 512-byte block. | ||
122 | This will use 7 bytes of spare area per 512 bytes of page data. | ||
123 | Note that this mode does not work on some OMAP3 revisions, due to a | ||
124 | hardware bug. Please check your OMAP datasheet before selecting this | ||
125 | mode. | ||
126 | |||
127 | endchoice | ||
128 | |||
129 | if MTD_NAND_OMAP_BCH | ||
130 | config BCH_CONST_M | ||
131 | default 13 | ||
132 | config BCH_CONST_T | ||
133 | default 4 if MTD_NAND_OMAP_BCH4 | ||
134 | default 8 if MTD_NAND_OMAP_BCH8 | ||
135 | endif | ||
136 | 108 | ||
137 | config MTD_NAND_IDS | 109 | config MTD_NAND_IDS |
138 | tristate | 110 | tristate |
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index bd1ce7d13702..d78a97d4153a 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c | |||
@@ -1062,56 +1062,28 @@ static void atmel_pmecc_core_init(struct mtd_info *mtd) | |||
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | /* | 1064 | /* |
1065 | * Get ECC requirement in ONFI parameters, returns -1 if ONFI | 1065 | * Get minimum ecc requirements from NAND. |
1066 | * parameters is not supported. | ||
1067 | * return 0 if success to get the ECC requirement. | ||
1068 | */ | ||
1069 | static int get_onfi_ecc_param(struct nand_chip *chip, | ||
1070 | int *ecc_bits, int *sector_size) | ||
1071 | { | ||
1072 | *ecc_bits = *sector_size = 0; | ||
1073 | |||
1074 | if (chip->onfi_params.ecc_bits == 0xff) | ||
1075 | /* TODO: the sector_size and ecc_bits need to be find in | ||
1076 | * extended ecc parameter, currently we don't support it. | ||
1077 | */ | ||
1078 | return -1; | ||
1079 | |||
1080 | *ecc_bits = chip->onfi_params.ecc_bits; | ||
1081 | |||
1082 | /* The default sector size (ecc codeword size) is 512 */ | ||
1083 | *sector_size = 512; | ||
1084 | |||
1085 | return 0; | ||
1086 | } | ||
1087 | |||
1088 | /* | ||
1089 | * Get ecc requirement from ONFI parameters ecc requirement. | ||
1090 | * If pmecc-cap, pmecc-sector-size in DTS are not specified, this function | 1066 | * If pmecc-cap, pmecc-sector-size in DTS are not specified, this function |
1091 | * will set them according to ONFI ecc requirement. Otherwise, use the | 1067 | * will set them according to minimum ecc requirement. Otherwise, use the |
1092 | * value in DTS file. | 1068 | * value in DTS file. |
1093 | * return 0 if success. otherwise return error code. | 1069 | * return 0 if success. otherwise return error code. |
1094 | */ | 1070 | */ |
1095 | static int pmecc_choose_ecc(struct atmel_nand_host *host, | 1071 | static int pmecc_choose_ecc(struct atmel_nand_host *host, |
1096 | int *cap, int *sector_size) | 1072 | int *cap, int *sector_size) |
1097 | { | 1073 | { |
1098 | /* Get ECC requirement from ONFI parameters */ | 1074 | /* Get minimum ECC requirements */ |
1099 | *cap = *sector_size = 0; | 1075 | if (host->nand_chip.ecc_strength_ds) { |
1100 | if (host->nand_chip.onfi_version) { | 1076 | *cap = host->nand_chip.ecc_strength_ds; |
1101 | if (!get_onfi_ecc_param(&host->nand_chip, cap, sector_size)) | 1077 | *sector_size = host->nand_chip.ecc_step_ds; |
1102 | dev_info(host->dev, "ONFI params, minimum required ECC: %d bits in %d bytes\n", | 1078 | dev_info(host->dev, "minimum ECC: %d bits in %d bytes\n", |
1103 | *cap, *sector_size); | 1079 | *cap, *sector_size); |
1104 | else | ||
1105 | dev_info(host->dev, "NAND chip ECC reqirement is in Extended ONFI parameter, we don't support yet.\n"); | ||
1106 | } else { | 1080 | } else { |
1107 | dev_info(host->dev, "NAND chip is not ONFI compliant, assume ecc_bits is 2 in 512 bytes"); | ||
1108 | } | ||
1109 | if (*cap == 0 && *sector_size == 0) { | ||
1110 | *cap = 2; | 1081 | *cap = 2; |
1111 | *sector_size = 512; | 1082 | *sector_size = 512; |
1083 | dev_info(host->dev, "can't detect min. ECC, assume 2 bits in 512 bytes\n"); | ||
1112 | } | 1084 | } |
1113 | 1085 | ||
1114 | /* If dts file doesn't specify then use the one in ONFI parameters */ | 1086 | /* If device tree doesn't specify, use NAND's minimum ECC parameters */ |
1115 | if (host->pmecc_corr_cap == 0) { | 1087 | if (host->pmecc_corr_cap == 0) { |
1116 | /* use the most fitable ecc bits (the near bigger one ) */ | 1088 | /* use the most fitable ecc bits (the near bigger one ) */ |
1117 | if (*cap <= 2) | 1089 | if (*cap <= 2) |
@@ -1449,7 +1421,6 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) | |||
1449 | ecc_writel(host->ecc, CR, ATMEL_ECC_RST); | 1421 | ecc_writel(host->ecc, CR, ATMEL_ECC_RST); |
1450 | } | 1422 | } |
1451 | 1423 | ||
1452 | #if defined(CONFIG_OF) | ||
1453 | static int atmel_of_init_port(struct atmel_nand_host *host, | 1424 | static int atmel_of_init_port(struct atmel_nand_host *host, |
1454 | struct device_node *np) | 1425 | struct device_node *np) |
1455 | { | 1426 | { |
@@ -1457,7 +1428,7 @@ static int atmel_of_init_port(struct atmel_nand_host *host, | |||
1457 | u32 offset[2]; | 1428 | u32 offset[2]; |
1458 | int ecc_mode; | 1429 | int ecc_mode; |
1459 | struct atmel_nand_data *board = &host->board; | 1430 | struct atmel_nand_data *board = &host->board; |
1460 | enum of_gpio_flags flags; | 1431 | enum of_gpio_flags flags = 0; |
1461 | 1432 | ||
1462 | if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) { | 1433 | if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) { |
1463 | if (val >= 32) { | 1434 | if (val >= 32) { |
@@ -1540,13 +1511,6 @@ static int atmel_of_init_port(struct atmel_nand_host *host, | |||
1540 | 1511 | ||
1541 | return 0; | 1512 | return 0; |
1542 | } | 1513 | } |
1543 | #else | ||
1544 | static int atmel_of_init_port(struct atmel_nand_host *host, | ||
1545 | struct device_node *np) | ||
1546 | { | ||
1547 | return -EINVAL; | ||
1548 | } | ||
1549 | #endif | ||
1550 | 1514 | ||
1551 | static int atmel_hw_nand_init_params(struct platform_device *pdev, | 1515 | static int atmel_hw_nand_init_params(struct platform_device *pdev, |
1552 | struct atmel_nand_host *host) | 1516 | struct atmel_nand_host *host) |
@@ -2019,7 +1983,8 @@ static int atmel_nand_probe(struct platform_device *pdev) | |||
2019 | mtd = &host->mtd; | 1983 | mtd = &host->mtd; |
2020 | nand_chip = &host->nand_chip; | 1984 | nand_chip = &host->nand_chip; |
2021 | host->dev = &pdev->dev; | 1985 | host->dev = &pdev->dev; |
2022 | if (pdev->dev.of_node) { | 1986 | if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { |
1987 | /* Only when CONFIG_OF is enabled of_node can be parsed */ | ||
2023 | res = atmel_of_init_port(host, pdev->dev.of_node); | 1988 | res = atmel_of_init_port(host, pdev->dev.of_node); |
2024 | if (res) | 1989 | if (res) |
2025 | goto err_nand_ioremap; | 1990 | goto err_nand_ioremap; |
@@ -2177,7 +2142,6 @@ err_no_card: | |||
2177 | if (host->dma_chan) | 2142 | if (host->dma_chan) |
2178 | dma_release_channel(host->dma_chan); | 2143 | dma_release_channel(host->dma_chan); |
2179 | err_nand_ioremap: | 2144 | err_nand_ioremap: |
2180 | platform_driver_unregister(&atmel_nand_nfc_driver); | ||
2181 | return res; | 2145 | return res; |
2182 | } | 2146 | } |
2183 | 2147 | ||
@@ -2207,14 +2171,12 @@ static int atmel_nand_remove(struct platform_device *pdev) | |||
2207 | return 0; | 2171 | return 0; |
2208 | } | 2172 | } |
2209 | 2173 | ||
2210 | #if defined(CONFIG_OF) | ||
2211 | static const struct of_device_id atmel_nand_dt_ids[] = { | 2174 | static const struct of_device_id atmel_nand_dt_ids[] = { |
2212 | { .compatible = "atmel,at91rm9200-nand" }, | 2175 | { .compatible = "atmel,at91rm9200-nand" }, |
2213 | { /* sentinel */ } | 2176 | { /* sentinel */ } |
2214 | }; | 2177 | }; |
2215 | 2178 | ||
2216 | MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids); | 2179 | MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids); |
2217 | #endif | ||
2218 | 2180 | ||
2219 | static int atmel_nand_nfc_probe(struct platform_device *pdev) | 2181 | static int atmel_nand_nfc_probe(struct platform_device *pdev) |
2220 | { | 2182 | { |
@@ -2253,12 +2215,11 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev) | |||
2253 | return 0; | 2215 | return 0; |
2254 | } | 2216 | } |
2255 | 2217 | ||
2256 | #if defined(CONFIG_OF) | 2218 | static const struct of_device_id atmel_nand_nfc_match[] = { |
2257 | static struct of_device_id atmel_nand_nfc_match[] = { | ||
2258 | { .compatible = "atmel,sama5d3-nfc" }, | 2219 | { .compatible = "atmel,sama5d3-nfc" }, |
2259 | { /* sentinel */ } | 2220 | { /* sentinel */ } |
2260 | }; | 2221 | }; |
2261 | #endif | 2222 | MODULE_DEVICE_TABLE(of, atmel_nand_nfc_match); |
2262 | 2223 | ||
2263 | static struct platform_driver atmel_nand_nfc_driver = { | 2224 | static struct platform_driver atmel_nand_nfc_driver = { |
2264 | .driver = { | 2225 | .driver = { |
diff --git a/drivers/mtd/nand/bcm47xxnflash/main.c b/drivers/mtd/nand/bcm47xxnflash/main.c index 7bae569fdc79..107445911315 100644 --- a/drivers/mtd/nand/bcm47xxnflash/main.c +++ b/drivers/mtd/nand/bcm47xxnflash/main.c | |||
@@ -29,11 +29,9 @@ static int bcm47xxnflash_probe(struct platform_device *pdev) | |||
29 | struct bcm47xxnflash *b47n; | 29 | struct bcm47xxnflash *b47n; |
30 | int err = 0; | 30 | int err = 0; |
31 | 31 | ||
32 | b47n = kzalloc(sizeof(*b47n), GFP_KERNEL); | 32 | b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL); |
33 | if (!b47n) { | 33 | if (!b47n) |
34 | err = -ENOMEM; | 34 | return -ENOMEM; |
35 | goto out; | ||
36 | } | ||
37 | 35 | ||
38 | b47n->nand_chip.priv = b47n; | 36 | b47n->nand_chip.priv = b47n; |
39 | b47n->mtd.owner = THIS_MODULE; | 37 | b47n->mtd.owner = THIS_MODULE; |
@@ -48,22 +46,16 @@ static int bcm47xxnflash_probe(struct platform_device *pdev) | |||
48 | } | 46 | } |
49 | if (err) { | 47 | if (err) { |
50 | pr_err("Initialization failed: %d\n", err); | 48 | pr_err("Initialization failed: %d\n", err); |
51 | goto err_init; | 49 | return err; |
52 | } | 50 | } |
53 | 51 | ||
54 | err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0); | 52 | err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0); |
55 | if (err) { | 53 | if (err) { |
56 | pr_err("Failed to register MTD device: %d\n", err); | 54 | pr_err("Failed to register MTD device: %d\n", err); |
57 | goto err_dev_reg; | 55 | return err; |
58 | } | 56 | } |
59 | 57 | ||
60 | return 0; | 58 | return 0; |
61 | |||
62 | err_dev_reg: | ||
63 | err_init: | ||
64 | kfree(b47n); | ||
65 | out: | ||
66 | return err; | ||
67 | } | 59 | } |
68 | 60 | ||
69 | static int bcm47xxnflash_remove(struct platform_device *pdev) | 61 | static int bcm47xxnflash_remove(struct platform_device *pdev) |
@@ -85,22 +77,4 @@ static struct platform_driver bcm47xxnflash_driver = { | |||
85 | }, | 77 | }, |
86 | }; | 78 | }; |
87 | 79 | ||
88 | static int __init bcm47xxnflash_init(void) | 80 | module_platform_driver(bcm47xxnflash_driver); |
89 | { | ||
90 | int err; | ||
91 | |||
92 | err = platform_driver_register(&bcm47xxnflash_driver); | ||
93 | if (err) | ||
94 | pr_err("Failed to register bcm47xx nand flash driver: %d\n", | ||
95 | err); | ||
96 | |||
97 | return err; | ||
98 | } | ||
99 | |||
100 | static void __exit bcm47xxnflash_exit(void) | ||
101 | { | ||
102 | platform_driver_unregister(&bcm47xxnflash_driver); | ||
103 | } | ||
104 | |||
105 | module_init(bcm47xxnflash_init); | ||
106 | module_exit(bcm47xxnflash_exit); | ||
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 2ed2bb33a6e7..370b9dd7a278 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c | |||
@@ -1394,7 +1394,7 @@ static struct nand_bbt_descr bbt_mirror_descr = { | |||
1394 | }; | 1394 | }; |
1395 | 1395 | ||
1396 | /* initialize driver data structures */ | 1396 | /* initialize driver data structures */ |
1397 | void denali_drv_init(struct denali_nand_info *denali) | 1397 | static void denali_drv_init(struct denali_nand_info *denali) |
1398 | { | 1398 | { |
1399 | denali->idx = 0; | 1399 | denali->idx = 0; |
1400 | 1400 | ||
@@ -1520,7 +1520,7 @@ int denali_init(struct denali_nand_info *denali) | |||
1520 | * so just let controller do 15bit ECC for MLC and 8bit ECC for | 1520 | * so just let controller do 15bit ECC for MLC and 8bit ECC for |
1521 | * SLC if possible. | 1521 | * SLC if possible. |
1522 | * */ | 1522 | * */ |
1523 | if (denali->nand.cellinfo & NAND_CI_CELLTYPE_MSK && | 1523 | if (!nand_is_slc(&denali->nand) && |
1524 | (denali->mtd.oobsize > (denali->bbtskipbytes + | 1524 | (denali->mtd.oobsize > (denali->bbtskipbytes + |
1525 | ECC_15BITS * (denali->mtd.writesize / | 1525 | ECC_15BITS * (denali->mtd.writesize / |
1526 | ECC_SECTOR_SIZE)))) { | 1526 | ECC_SECTOR_SIZE)))) { |
diff --git a/drivers/mtd/nand/denali_pci.c b/drivers/mtd/nand/denali_pci.c index e3e46623b2b4..033f177a6369 100644 --- a/drivers/mtd/nand/denali_pci.c +++ b/drivers/mtd/nand/denali_pci.c | |||
@@ -119,7 +119,6 @@ static void denali_pci_remove(struct pci_dev *dev) | |||
119 | iounmap(denali->flash_mem); | 119 | iounmap(denali->flash_mem); |
120 | pci_release_regions(dev); | 120 | pci_release_regions(dev); |
121 | pci_disable_device(dev); | 121 | pci_disable_device(dev); |
122 | pci_set_drvdata(dev, NULL); | ||
123 | kfree(denali); | 122 | kfree(denali); |
124 | } | 123 | } |
125 | 124 | ||
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c index eaa3c29ad860..b68a4959f700 100644 --- a/drivers/mtd/nand/diskonchip.c +++ b/drivers/mtd/nand/diskonchip.c | |||
@@ -38,7 +38,7 @@ | |||
38 | #define CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 0 | 38 | #define CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 0 |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | static unsigned long __initdata doc_locations[] = { | 41 | static unsigned long doc_locations[] __initdata = { |
42 | #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) | 42 | #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) |
43 | #ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH | 43 | #ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH |
44 | 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, | 44 | 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, |
diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c index 548db2389fab..bd1cb672034f 100644 --- a/drivers/mtd/nand/docg4.c +++ b/drivers/mtd/nand/docg4.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/mtd/nand.h> | 44 | #include <linux/mtd/nand.h> |
45 | #include <linux/bch.h> | 45 | #include <linux/bch.h> |
46 | #include <linux/bitrev.h> | 46 | #include <linux/bitrev.h> |
47 | #include <linux/jiffies.h> | ||
47 | 48 | ||
48 | /* | 49 | /* |
49 | * In "reliable mode" consecutive 2k pages are used in parallel (in some | 50 | * In "reliable mode" consecutive 2k pages are used in parallel (in some |
@@ -269,7 +270,7 @@ static int poll_status(struct docg4_priv *doc) | |||
269 | */ | 270 | */ |
270 | 271 | ||
271 | uint16_t flash_status; | 272 | uint16_t flash_status; |
272 | unsigned int timeo; | 273 | unsigned long timeo; |
273 | void __iomem *docptr = doc->virtadr; | 274 | void __iomem *docptr = doc->virtadr; |
274 | 275 | ||
275 | dev_dbg(doc->dev, "%s...\n", __func__); | 276 | dev_dbg(doc->dev, "%s...\n", __func__); |
@@ -277,22 +278,18 @@ static int poll_status(struct docg4_priv *doc) | |||
277 | /* hardware quirk requires reading twice initially */ | 278 | /* hardware quirk requires reading twice initially */ |
278 | flash_status = readw(docptr + DOC_FLASHCONTROL); | 279 | flash_status = readw(docptr + DOC_FLASHCONTROL); |
279 | 280 | ||
280 | timeo = 1000; | 281 | timeo = jiffies + msecs_to_jiffies(200); /* generous timeout */ |
281 | do { | 282 | do { |
282 | cpu_relax(); | 283 | cpu_relax(); |
283 | flash_status = readb(docptr + DOC_FLASHCONTROL); | 284 | flash_status = readb(docptr + DOC_FLASHCONTROL); |
284 | } while (!(flash_status & DOC_CTRL_FLASHREADY) && --timeo); | 285 | } while (!(flash_status & DOC_CTRL_FLASHREADY) && |
286 | time_before(jiffies, timeo)); | ||
285 | 287 | ||
286 | 288 | if (unlikely(!(flash_status & DOC_CTRL_FLASHREADY))) { | |
287 | if (!timeo) { | ||
288 | dev_err(doc->dev, "%s: timed out!\n", __func__); | 289 | dev_err(doc->dev, "%s: timed out!\n", __func__); |
289 | return NAND_STATUS_FAIL; | 290 | return NAND_STATUS_FAIL; |
290 | } | 291 | } |
291 | 292 | ||
292 | if (unlikely(timeo < 50)) | ||
293 | dev_warn(doc->dev, "%s: nearly timed out; %d remaining\n", | ||
294 | __func__, timeo); | ||
295 | |||
296 | return 0; | 293 | return 0; |
297 | } | 294 | } |
298 | 295 | ||
@@ -1239,7 +1236,6 @@ static void __init init_mtd_structs(struct mtd_info *mtd) | |||
1239 | nand->block_markbad = docg4_block_markbad; | 1236 | nand->block_markbad = docg4_block_markbad; |
1240 | nand->read_buf = docg4_read_buf; | 1237 | nand->read_buf = docg4_read_buf; |
1241 | nand->write_buf = docg4_write_buf16; | 1238 | nand->write_buf = docg4_write_buf16; |
1242 | nand->scan_bbt = nand_default_bbt; | ||
1243 | nand->erase_cmd = docg4_erase_block; | 1239 | nand->erase_cmd = docg4_erase_block; |
1244 | nand->ecc.read_page = docg4_read_page; | 1240 | nand->ecc.read_page = docg4_read_page; |
1245 | nand->ecc.write_page = docg4_write_page; | 1241 | nand->ecc.write_page = docg4_write_page; |
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index e59c8860f472..c966fc7474ce 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c | |||
@@ -651,8 +651,6 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd) | |||
651 | chip->page_shift); | 651 | chip->page_shift); |
652 | dev_dbg(priv->dev, "fsl_elbc_init: nand->phys_erase_shift = %d\n", | 652 | dev_dbg(priv->dev, "fsl_elbc_init: nand->phys_erase_shift = %d\n", |
653 | chip->phys_erase_shift); | 653 | chip->phys_erase_shift); |
654 | dev_dbg(priv->dev, "fsl_elbc_init: nand->ecclayout = %p\n", | ||
655 | chip->ecclayout); | ||
656 | dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.mode = %d\n", | 654 | dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.mode = %d\n", |
657 | chip->ecc.mode); | 655 | chip->ecc.mode); |
658 | dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.steps = %d\n", | 656 | dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.steps = %d\n", |
diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c index 2730c78d2bf8..43355779cff5 100644 --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c | |||
@@ -136,6 +136,69 @@ static struct nand_ecclayout oob_4096_ecc8 = { | |||
136 | .oobfree = { {2, 6}, {136, 82} }, | 136 | .oobfree = { {2, 6}, {136, 82} }, |
137 | }; | 137 | }; |
138 | 138 | ||
139 | /* 8192-byte page size with 4-bit ECC */ | ||
140 | static struct nand_ecclayout oob_8192_ecc4 = { | ||
141 | .eccbytes = 128, | ||
142 | .eccpos = { | ||
143 | 8, 9, 10, 11, 12, 13, 14, 15, | ||
144 | 16, 17, 18, 19, 20, 21, 22, 23, | ||
145 | 24, 25, 26, 27, 28, 29, 30, 31, | ||
146 | 32, 33, 34, 35, 36, 37, 38, 39, | ||
147 | 40, 41, 42, 43, 44, 45, 46, 47, | ||
148 | 48, 49, 50, 51, 52, 53, 54, 55, | ||
149 | 56, 57, 58, 59, 60, 61, 62, 63, | ||
150 | 64, 65, 66, 67, 68, 69, 70, 71, | ||
151 | 72, 73, 74, 75, 76, 77, 78, 79, | ||
152 | 80, 81, 82, 83, 84, 85, 86, 87, | ||
153 | 88, 89, 90, 91, 92, 93, 94, 95, | ||
154 | 96, 97, 98, 99, 100, 101, 102, 103, | ||
155 | 104, 105, 106, 107, 108, 109, 110, 111, | ||
156 | 112, 113, 114, 115, 116, 117, 118, 119, | ||
157 | 120, 121, 122, 123, 124, 125, 126, 127, | ||
158 | 128, 129, 130, 131, 132, 133, 134, 135, | ||
159 | }, | ||
160 | .oobfree = { {2, 6}, {136, 208} }, | ||
161 | }; | ||
162 | |||
163 | /* 8192-byte page size with 8-bit ECC -- requires 218-byte OOB */ | ||
164 | static struct nand_ecclayout oob_8192_ecc8 = { | ||
165 | .eccbytes = 256, | ||
166 | .eccpos = { | ||
167 | 8, 9, 10, 11, 12, 13, 14, 15, | ||
168 | 16, 17, 18, 19, 20, 21, 22, 23, | ||
169 | 24, 25, 26, 27, 28, 29, 30, 31, | ||
170 | 32, 33, 34, 35, 36, 37, 38, 39, | ||
171 | 40, 41, 42, 43, 44, 45, 46, 47, | ||
172 | 48, 49, 50, 51, 52, 53, 54, 55, | ||
173 | 56, 57, 58, 59, 60, 61, 62, 63, | ||
174 | 64, 65, 66, 67, 68, 69, 70, 71, | ||
175 | 72, 73, 74, 75, 76, 77, 78, 79, | ||
176 | 80, 81, 82, 83, 84, 85, 86, 87, | ||
177 | 88, 89, 90, 91, 92, 93, 94, 95, | ||
178 | 96, 97, 98, 99, 100, 101, 102, 103, | ||
179 | 104, 105, 106, 107, 108, 109, 110, 111, | ||
180 | 112, 113, 114, 115, 116, 117, 118, 119, | ||
181 | 120, 121, 122, 123, 124, 125, 126, 127, | ||
182 | 128, 129, 130, 131, 132, 133, 134, 135, | ||
183 | 136, 137, 138, 139, 140, 141, 142, 143, | ||
184 | 144, 145, 146, 147, 148, 149, 150, 151, | ||
185 | 152, 153, 154, 155, 156, 157, 158, 159, | ||
186 | 160, 161, 162, 163, 164, 165, 166, 167, | ||
187 | 168, 169, 170, 171, 172, 173, 174, 175, | ||
188 | 176, 177, 178, 179, 180, 181, 182, 183, | ||
189 | 184, 185, 186, 187, 188, 189, 190, 191, | ||
190 | 192, 193, 194, 195, 196, 197, 198, 199, | ||
191 | 200, 201, 202, 203, 204, 205, 206, 207, | ||
192 | 208, 209, 210, 211, 212, 213, 214, 215, | ||
193 | 216, 217, 218, 219, 220, 221, 222, 223, | ||
194 | 224, 225, 226, 227, 228, 229, 230, 231, | ||
195 | 232, 233, 234, 235, 236, 237, 238, 239, | ||
196 | 240, 241, 242, 243, 244, 245, 246, 247, | ||
197 | 248, 249, 250, 251, 252, 253, 254, 255, | ||
198 | 256, 257, 258, 259, 260, 261, 262, 263, | ||
199 | }, | ||
200 | .oobfree = { {2, 6}, {264, 80} }, | ||
201 | }; | ||
139 | 202 | ||
140 | /* | 203 | /* |
141 | * Generic flash bbt descriptors | 204 | * Generic flash bbt descriptors |
@@ -442,20 +505,29 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
442 | if (mtd->writesize > 512) { | 505 | if (mtd->writesize > 512) { |
443 | nand_fcr0 = | 506 | nand_fcr0 = |
444 | (NAND_CMD_SEQIN << IFC_NAND_FCR0_CMD0_SHIFT) | | 507 | (NAND_CMD_SEQIN << IFC_NAND_FCR0_CMD0_SHIFT) | |
445 | (NAND_CMD_PAGEPROG << IFC_NAND_FCR0_CMD1_SHIFT); | 508 | (NAND_CMD_STATUS << IFC_NAND_FCR0_CMD1_SHIFT) | |
509 | (NAND_CMD_PAGEPROG << IFC_NAND_FCR0_CMD2_SHIFT); | ||
446 | 510 | ||
447 | iowrite32be( | 511 | iowrite32be( |
448 | (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) | | 512 | (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) | |
449 | (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) | | 513 | (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) | |
450 | (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) | | 514 | (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) | |
451 | (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP3_SHIFT) | | 515 | (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP3_SHIFT) | |
452 | (IFC_FIR_OP_CW1 << IFC_NAND_FIR0_OP4_SHIFT), | 516 | (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP4_SHIFT), |
453 | &ifc->ifc_nand.nand_fir0); | 517 | &ifc->ifc_nand.nand_fir0); |
518 | iowrite32be( | ||
519 | (IFC_FIR_OP_CW1 << IFC_NAND_FIR1_OP5_SHIFT) | | ||
520 | (IFC_FIR_OP_RDSTAT << | ||
521 | IFC_NAND_FIR1_OP6_SHIFT) | | ||
522 | (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP7_SHIFT), | ||
523 | &ifc->ifc_nand.nand_fir1); | ||
454 | } else { | 524 | } else { |
455 | nand_fcr0 = ((NAND_CMD_PAGEPROG << | 525 | nand_fcr0 = ((NAND_CMD_PAGEPROG << |
456 | IFC_NAND_FCR0_CMD1_SHIFT) | | 526 | IFC_NAND_FCR0_CMD1_SHIFT) | |
457 | (NAND_CMD_SEQIN << | 527 | (NAND_CMD_SEQIN << |
458 | IFC_NAND_FCR0_CMD2_SHIFT)); | 528 | IFC_NAND_FCR0_CMD2_SHIFT) | |
529 | (NAND_CMD_STATUS << | ||
530 | IFC_NAND_FCR0_CMD3_SHIFT)); | ||
459 | 531 | ||
460 | iowrite32be( | 532 | iowrite32be( |
461 | (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) | | 533 | (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) | |
@@ -464,8 +536,13 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
464 | (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP3_SHIFT) | | 536 | (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP3_SHIFT) | |
465 | (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP4_SHIFT), | 537 | (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP4_SHIFT), |
466 | &ifc->ifc_nand.nand_fir0); | 538 | &ifc->ifc_nand.nand_fir0); |
467 | iowrite32be(IFC_FIR_OP_CW1 << IFC_NAND_FIR1_OP5_SHIFT, | 539 | iowrite32be( |
468 | &ifc->ifc_nand.nand_fir1); | 540 | (IFC_FIR_OP_CMD1 << IFC_NAND_FIR1_OP5_SHIFT) | |
541 | (IFC_FIR_OP_CW3 << IFC_NAND_FIR1_OP6_SHIFT) | | ||
542 | (IFC_FIR_OP_RDSTAT << | ||
543 | IFC_NAND_FIR1_OP7_SHIFT) | | ||
544 | (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP8_SHIFT), | ||
545 | &ifc->ifc_nand.nand_fir1); | ||
469 | 546 | ||
470 | if (column >= mtd->writesize) | 547 | if (column >= mtd->writesize) |
471 | nand_fcr0 |= | 548 | nand_fcr0 |= |
@@ -719,8 +796,6 @@ static int fsl_ifc_chip_init_tail(struct mtd_info *mtd) | |||
719 | chip->page_shift); | 796 | chip->page_shift); |
720 | dev_dbg(priv->dev, "%s: nand->phys_erase_shift = %d\n", __func__, | 797 | dev_dbg(priv->dev, "%s: nand->phys_erase_shift = %d\n", __func__, |
721 | chip->phys_erase_shift); | 798 | chip->phys_erase_shift); |
722 | dev_dbg(priv->dev, "%s: nand->ecclayout = %p\n", __func__, | ||
723 | chip->ecclayout); | ||
724 | dev_dbg(priv->dev, "%s: nand->ecc.mode = %d\n", __func__, | 799 | dev_dbg(priv->dev, "%s: nand->ecc.mode = %d\n", __func__, |
725 | chip->ecc.mode); | 800 | chip->ecc.mode); |
726 | dev_dbg(priv->dev, "%s: nand->ecc.steps = %d\n", __func__, | 801 | dev_dbg(priv->dev, "%s: nand->ecc.steps = %d\n", __func__, |
@@ -873,11 +948,25 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv) | |||
873 | } else { | 948 | } else { |
874 | layout = &oob_4096_ecc8; | 949 | layout = &oob_4096_ecc8; |
875 | chip->ecc.bytes = 16; | 950 | chip->ecc.bytes = 16; |
951 | chip->ecc.strength = 8; | ||
876 | } | 952 | } |
877 | 953 | ||
878 | priv->bufnum_mask = 1; | 954 | priv->bufnum_mask = 1; |
879 | break; | 955 | break; |
880 | 956 | ||
957 | case CSOR_NAND_PGS_8K: | ||
958 | if ((csor & CSOR_NAND_ECC_MODE_MASK) == | ||
959 | CSOR_NAND_ECC_MODE_4) { | ||
960 | layout = &oob_8192_ecc4; | ||
961 | } else { | ||
962 | layout = &oob_8192_ecc8; | ||
963 | chip->ecc.bytes = 16; | ||
964 | chip->ecc.strength = 8; | ||
965 | } | ||
966 | |||
967 | priv->bufnum_mask = 0; | ||
968 | break; | ||
969 | |||
881 | default: | 970 | default: |
882 | dev_err(priv->dev, "bad csor %#x: bad page size\n", csor); | 971 | dev_err(priv->dev, "bad csor %#x: bad page size\n", csor); |
883 | return -ENODEV; | 972 | return -ENODEV; |
@@ -908,7 +997,6 @@ static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv) | |||
908 | iounmap(priv->vbase); | 997 | iounmap(priv->vbase); |
909 | 998 | ||
910 | ifc_nand_ctrl->chips[priv->bank] = NULL; | 999 | ifc_nand_ctrl->chips[priv->bank] = NULL; |
911 | dev_set_drvdata(priv->dev, NULL); | ||
912 | 1000 | ||
913 | return 0; | 1001 | return 0; |
914 | } | 1002 | } |
@@ -1083,25 +1171,7 @@ static struct platform_driver fsl_ifc_nand_driver = { | |||
1083 | .remove = fsl_ifc_nand_remove, | 1171 | .remove = fsl_ifc_nand_remove, |
1084 | }; | 1172 | }; |
1085 | 1173 | ||
1086 | static int __init fsl_ifc_nand_init(void) | 1174 | module_platform_driver(fsl_ifc_nand_driver); |
1087 | { | ||
1088 | int ret; | ||
1089 | |||
1090 | ret = platform_driver_register(&fsl_ifc_nand_driver); | ||
1091 | if (ret) | ||
1092 | printk(KERN_ERR "fsl-ifc: Failed to register platform" | ||
1093 | "driver\n"); | ||
1094 | |||
1095 | return ret; | ||
1096 | } | ||
1097 | |||
1098 | static void __exit fsl_ifc_nand_exit(void) | ||
1099 | { | ||
1100 | platform_driver_unregister(&fsl_ifc_nand_driver); | ||
1101 | } | ||
1102 | |||
1103 | module_init(fsl_ifc_nand_init); | ||
1104 | module_exit(fsl_ifc_nand_exit); | ||
1105 | 1175 | ||
1106 | MODULE_LICENSE("GPL"); | 1176 | MODULE_LICENSE("GPL"); |
1107 | MODULE_AUTHOR("Freescale"); | 1177 | MODULE_AUTHOR("Freescale"); |
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c index 4f8857fa48a7..aaced29727fb 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c | |||
@@ -187,6 +187,12 @@ int gpmi_init(struct gpmi_nand_data *this) | |||
187 | /* Select BCH ECC. */ | 187 | /* Select BCH ECC. */ |
188 | writel(BM_GPMI_CTRL1_BCH_MODE, r->gpmi_regs + HW_GPMI_CTRL1_SET); | 188 | writel(BM_GPMI_CTRL1_BCH_MODE, r->gpmi_regs + HW_GPMI_CTRL1_SET); |
189 | 189 | ||
190 | /* | ||
191 | * Decouple the chip select from dma channel. We use dma0 for all | ||
192 | * the chips. | ||
193 | */ | ||
194 | writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET); | ||
195 | |||
190 | gpmi_disable_clk(this); | 196 | gpmi_disable_clk(this); |
191 | return 0; | 197 | return 0; |
192 | err_out: | 198 | err_out: |
@@ -1073,6 +1079,13 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip) | |||
1073 | mask = MX23_BM_GPMI_DEBUG_READY0 << chip; | 1079 | mask = MX23_BM_GPMI_DEBUG_READY0 << chip; |
1074 | reg = readl(r->gpmi_regs + HW_GPMI_DEBUG); | 1080 | reg = readl(r->gpmi_regs + HW_GPMI_DEBUG); |
1075 | } else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) { | 1081 | } else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) { |
1082 | /* | ||
1083 | * In the imx6, all the ready/busy pins are bound | ||
1084 | * together. So we only need to check chip 0. | ||
1085 | */ | ||
1086 | if (GPMI_IS_MX6Q(this)) | ||
1087 | chip = 0; | ||
1088 | |||
1076 | /* MX28 shares the same R/B register as MX6Q. */ | 1089 | /* MX28 shares the same R/B register as MX6Q. */ |
1077 | mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip); | 1090 | mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip); |
1078 | reg = readl(r->gpmi_regs + HW_GPMI_STAT); | 1091 | reg = readl(r->gpmi_regs + HW_GPMI_STAT); |
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index a9830ff8e3f3..dabbc14db563 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c | |||
@@ -45,7 +45,10 @@ static struct nand_bbt_descr gpmi_bbt_descr = { | |||
45 | .pattern = scan_ff_pattern | 45 | .pattern = scan_ff_pattern |
46 | }; | 46 | }; |
47 | 47 | ||
48 | /* We will use all the (page + OOB). */ | 48 | /* |
49 | * We may change the layout if we can get the ECC info from the datasheet, | ||
50 | * else we will use all the (page + OOB). | ||
51 | */ | ||
49 | static struct nand_ecclayout gpmi_hw_ecclayout = { | 52 | static struct nand_ecclayout gpmi_hw_ecclayout = { |
50 | .eccbytes = 0, | 53 | .eccbytes = 0, |
51 | .eccpos = { 0, }, | 54 | .eccpos = { 0, }, |
@@ -354,9 +357,8 @@ int common_nfc_set_geometry(struct gpmi_nand_data *this) | |||
354 | 357 | ||
355 | struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) | 358 | struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) |
356 | { | 359 | { |
357 | int chipnr = this->current_chip; | 360 | /* We use the DMA channel 0 to access all the nand chips. */ |
358 | 361 | return this->dma_chans[0]; | |
359 | return this->dma_chans[chipnr]; | ||
360 | } | 362 | } |
361 | 363 | ||
362 | /* Can we use the upper's buffer directly for DMA? */ | 364 | /* Can we use the upper's buffer directly for DMA? */ |
@@ -392,8 +394,6 @@ static void dma_irq_callback(void *param) | |||
392 | struct gpmi_nand_data *this = param; | 394 | struct gpmi_nand_data *this = param; |
393 | struct completion *dma_c = &this->dma_done; | 395 | struct completion *dma_c = &this->dma_done; |
394 | 396 | ||
395 | complete(dma_c); | ||
396 | |||
397 | switch (this->dma_type) { | 397 | switch (this->dma_type) { |
398 | case DMA_FOR_COMMAND: | 398 | case DMA_FOR_COMMAND: |
399 | dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE); | 399 | dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE); |
@@ -418,6 +418,8 @@ static void dma_irq_callback(void *param) | |||
418 | default: | 418 | default: |
419 | pr_err("in wrong DMA operation.\n"); | 419 | pr_err("in wrong DMA operation.\n"); |
420 | } | 420 | } |
421 | |||
422 | complete(dma_c); | ||
421 | } | 423 | } |
422 | 424 | ||
423 | int start_dma_without_bch_irq(struct gpmi_nand_data *this, | 425 | int start_dma_without_bch_irq(struct gpmi_nand_data *this, |
@@ -1263,14 +1265,22 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip, | |||
1263 | static int | 1265 | static int |
1264 | gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page) | 1266 | gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page) |
1265 | { | 1267 | { |
1266 | /* | 1268 | struct nand_oobfree *of = mtd->ecclayout->oobfree; |
1267 | * The BCH will use all the (page + oob). | 1269 | int status = 0; |
1268 | * Our gpmi_hw_ecclayout can only prohibit the JFFS2 to write the oob. | 1270 | |
1269 | * But it can not stop some ioctls such MEMWRITEOOB which uses | 1271 | /* Do we have available oob area? */ |
1270 | * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit | 1272 | if (!of->length) |
1271 | * these ioctls too. | 1273 | return -EPERM; |
1272 | */ | 1274 | |
1273 | return -EPERM; | 1275 | if (!nand_is_slc(chip)) |
1276 | return -EPERM; | ||
1277 | |||
1278 | chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of->offset, page); | ||
1279 | chip->write_buf(mtd, chip->oob_poi + of->offset, of->length); | ||
1280 | chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); | ||
1281 | |||
1282 | status = chip->waitfunc(mtd, chip); | ||
1283 | return status & NAND_STATUS_FAIL ? -EIO : 0; | ||
1274 | } | 1284 | } |
1275 | 1285 | ||
1276 | static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs) | 1286 | static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs) |
@@ -1568,8 +1578,6 @@ static int gpmi_set_geometry(struct gpmi_nand_data *this) | |||
1568 | 1578 | ||
1569 | static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) | 1579 | static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) |
1570 | { | 1580 | { |
1571 | int ret; | ||
1572 | |||
1573 | /* Set up swap_block_mark, must be set before the gpmi_set_geometry() */ | 1581 | /* Set up swap_block_mark, must be set before the gpmi_set_geometry() */ |
1574 | if (GPMI_IS_MX23(this)) | 1582 | if (GPMI_IS_MX23(this)) |
1575 | this->swap_block_mark = false; | 1583 | this->swap_block_mark = false; |
@@ -1577,12 +1585,8 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) | |||
1577 | this->swap_block_mark = true; | 1585 | this->swap_block_mark = true; |
1578 | 1586 | ||
1579 | /* Set up the medium geometry */ | 1587 | /* Set up the medium geometry */ |
1580 | ret = gpmi_set_geometry(this); | 1588 | return gpmi_set_geometry(this); |
1581 | if (ret) | ||
1582 | return ret; | ||
1583 | 1589 | ||
1584 | /* NAND boot init, depends on the gpmi_set_geometry(). */ | ||
1585 | return nand_boot_init(this); | ||
1586 | } | 1590 | } |
1587 | 1591 | ||
1588 | static void gpmi_nfc_exit(struct gpmi_nand_data *this) | 1592 | static void gpmi_nfc_exit(struct gpmi_nand_data *this) |
@@ -1664,7 +1668,7 @@ static int gpmi_nfc_init(struct gpmi_nand_data *this) | |||
1664 | if (ret) | 1668 | if (ret) |
1665 | goto err_out; | 1669 | goto err_out; |
1666 | 1670 | ||
1667 | ret = nand_scan_ident(mtd, 1, NULL); | 1671 | ret = nand_scan_ident(mtd, GPMI_IS_MX6Q(this) ? 2 : 1, NULL); |
1668 | if (ret) | 1672 | if (ret) |
1669 | goto err_out; | 1673 | goto err_out; |
1670 | 1674 | ||
@@ -1672,10 +1676,16 @@ static int gpmi_nfc_init(struct gpmi_nand_data *this) | |||
1672 | if (ret) | 1676 | if (ret) |
1673 | goto err_out; | 1677 | goto err_out; |
1674 | 1678 | ||
1679 | chip->options |= NAND_SKIP_BBTSCAN; | ||
1675 | ret = nand_scan_tail(mtd); | 1680 | ret = nand_scan_tail(mtd); |
1676 | if (ret) | 1681 | if (ret) |
1677 | goto err_out; | 1682 | goto err_out; |
1678 | 1683 | ||
1684 | ret = nand_boot_init(this); | ||
1685 | if (ret) | ||
1686 | goto err_out; | ||
1687 | chip->scan_bbt(mtd); | ||
1688 | |||
1679 | ppdata.of_node = this->pdev->dev.of_node; | 1689 | ppdata.of_node = this->pdev->dev.of_node; |
1680 | ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); | 1690 | ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); |
1681 | if (ret) | 1691 | if (ret) |
@@ -1691,19 +1701,19 @@ static const struct platform_device_id gpmi_ids[] = { | |||
1691 | { .name = "imx23-gpmi-nand", .driver_data = IS_MX23, }, | 1701 | { .name = "imx23-gpmi-nand", .driver_data = IS_MX23, }, |
1692 | { .name = "imx28-gpmi-nand", .driver_data = IS_MX28, }, | 1702 | { .name = "imx28-gpmi-nand", .driver_data = IS_MX28, }, |
1693 | { .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, }, | 1703 | { .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, }, |
1694 | {}, | 1704 | {} |
1695 | }; | 1705 | }; |
1696 | 1706 | ||
1697 | static const struct of_device_id gpmi_nand_id_table[] = { | 1707 | static const struct of_device_id gpmi_nand_id_table[] = { |
1698 | { | 1708 | { |
1699 | .compatible = "fsl,imx23-gpmi-nand", | 1709 | .compatible = "fsl,imx23-gpmi-nand", |
1700 | .data = (void *)&gpmi_ids[IS_MX23] | 1710 | .data = (void *)&gpmi_ids[IS_MX23], |
1701 | }, { | 1711 | }, { |
1702 | .compatible = "fsl,imx28-gpmi-nand", | 1712 | .compatible = "fsl,imx28-gpmi-nand", |
1703 | .data = (void *)&gpmi_ids[IS_MX28] | 1713 | .data = (void *)&gpmi_ids[IS_MX28], |
1704 | }, { | 1714 | }, { |
1705 | .compatible = "fsl,imx6q-gpmi-nand", | 1715 | .compatible = "fsl,imx6q-gpmi-nand", |
1706 | .data = (void *)&gpmi_ids[IS_MX6Q] | 1716 | .data = (void *)&gpmi_ids[IS_MX6Q], |
1707 | }, {} | 1717 | }, {} |
1708 | }; | 1718 | }; |
1709 | MODULE_DEVICE_TABLE(of, gpmi_nand_id_table); | 1719 | MODULE_DEVICE_TABLE(of, gpmi_nand_id_table); |
@@ -1722,7 +1732,7 @@ static int gpmi_nand_probe(struct platform_device *pdev) | |||
1722 | return -ENODEV; | 1732 | return -ENODEV; |
1723 | } | 1733 | } |
1724 | 1734 | ||
1725 | this = kzalloc(sizeof(*this), GFP_KERNEL); | 1735 | this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL); |
1726 | if (!this) { | 1736 | if (!this) { |
1727 | pr_err("Failed to allocate per-device memory\n"); | 1737 | pr_err("Failed to allocate per-device memory\n"); |
1728 | return -ENOMEM; | 1738 | return -ENOMEM; |
@@ -1752,7 +1762,6 @@ exit_nfc_init: | |||
1752 | release_resources(this); | 1762 | release_resources(this); |
1753 | exit_acquire_resources: | 1763 | exit_acquire_resources: |
1754 | dev_err(this->dev, "driver registration failed: %d\n", ret); | 1764 | dev_err(this->dev, "driver registration failed: %d\n", ret); |
1755 | kfree(this); | ||
1756 | 1765 | ||
1757 | return ret; | 1766 | return ret; |
1758 | } | 1767 | } |
@@ -1763,7 +1772,6 @@ static int gpmi_nand_remove(struct platform_device *pdev) | |||
1763 | 1772 | ||
1764 | gpmi_nfc_exit(this); | 1773 | gpmi_nfc_exit(this); |
1765 | release_resources(this); | 1774 | release_resources(this); |
1766 | kfree(this); | ||
1767 | return 0; | 1775 | return 0; |
1768 | } | 1776 | } |
1769 | 1777 | ||
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-regs.h b/drivers/mtd/nand/gpmi-nand/gpmi-regs.h index 53397cc290fc..82114cdc8330 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-regs.h +++ b/drivers/mtd/nand/gpmi-nand/gpmi-regs.h | |||
@@ -108,6 +108,9 @@ | |||
108 | #define HW_GPMI_CTRL1_CLR 0x00000068 | 108 | #define HW_GPMI_CTRL1_CLR 0x00000068 |
109 | #define HW_GPMI_CTRL1_TOG 0x0000006c | 109 | #define HW_GPMI_CTRL1_TOG 0x0000006c |
110 | 110 | ||
111 | #define BP_GPMI_CTRL1_DECOUPLE_CS 24 | ||
112 | #define BM_GPMI_CTRL1_DECOUPLE_CS (1 << BP_GPMI_CTRL1_DECOUPLE_CS) | ||
113 | |||
111 | #define BP_GPMI_CTRL1_WRN_DLY_SEL 22 | 114 | #define BP_GPMI_CTRL1_WRN_DLY_SEL 22 |
112 | #define BM_GPMI_CTRL1_WRN_DLY_SEL (0x3 << BP_GPMI_CTRL1_WRN_DLY_SEL) | 115 | #define BM_GPMI_CTRL1_WRN_DLY_SEL (0x3 << BP_GPMI_CTRL1_WRN_DLY_SEL) |
113 | #define BF_GPMI_CTRL1_WRN_DLY_SEL(v) \ | 116 | #define BF_GPMI_CTRL1_WRN_DLY_SEL(v) \ |
diff --git a/drivers/mtd/nand/lpc32xx_mlc.c b/drivers/mtd/nand/lpc32xx_mlc.c index f4dd2a887ea5..327d96c03505 100644 --- a/drivers/mtd/nand/lpc32xx_mlc.c +++ b/drivers/mtd/nand/lpc32xx_mlc.c | |||
@@ -905,7 +905,7 @@ static struct platform_driver lpc32xx_nand_driver = { | |||
905 | .driver = { | 905 | .driver = { |
906 | .name = DRV_NAME, | 906 | .name = DRV_NAME, |
907 | .owner = THIS_MODULE, | 907 | .owner = THIS_MODULE, |
908 | .of_match_table = of_match_ptr(lpc32xx_nand_match), | 908 | .of_match_table = lpc32xx_nand_match, |
909 | }, | 909 | }, |
910 | }; | 910 | }; |
911 | 911 | ||
diff --git a/drivers/mtd/nand/lpc32xx_slc.c b/drivers/mtd/nand/lpc32xx_slc.c index add75709d415..23e6974ccd20 100644 --- a/drivers/mtd/nand/lpc32xx_slc.c +++ b/drivers/mtd/nand/lpc32xx_slc.c | |||
@@ -893,7 +893,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) | |||
893 | 893 | ||
894 | /* Avoid extra scan if using BBT, setup BBT support */ | 894 | /* Avoid extra scan if using BBT, setup BBT support */ |
895 | if (host->ncfg->use_bbt) { | 895 | if (host->ncfg->use_bbt) { |
896 | chip->options |= NAND_SKIP_BBTSCAN; | ||
897 | chip->bbt_options |= NAND_BBT_USE_FLASH; | 896 | chip->bbt_options |= NAND_BBT_USE_FLASH; |
898 | 897 | ||
899 | /* | 898 | /* |
@@ -915,13 +914,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) | |||
915 | goto err_exit3; | 914 | goto err_exit3; |
916 | } | 915 | } |
917 | 916 | ||
918 | /* Standard layout in FLASH for bad block tables */ | ||
919 | if (host->ncfg->use_bbt) { | ||
920 | if (nand_default_bbt(mtd) < 0) | ||
921 | dev_err(&pdev->dev, | ||
922 | "Error initializing default bad block tables\n"); | ||
923 | } | ||
924 | |||
925 | mtd->name = "nxp_lpc3220_slc"; | 917 | mtd->name = "nxp_lpc3220_slc"; |
926 | ppdata.of_node = pdev->dev.of_node; | 918 | ppdata.of_node = pdev->dev.of_node; |
927 | res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts, | 919 | res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts, |
@@ -1023,7 +1015,7 @@ static struct platform_driver lpc32xx_nand_driver = { | |||
1023 | .driver = { | 1015 | .driver = { |
1024 | .name = LPC32XX_MODNAME, | 1016 | .name = LPC32XX_MODNAME, |
1025 | .owner = THIS_MODULE, | 1017 | .owner = THIS_MODULE, |
1026 | .of_match_table = of_match_ptr(lpc32xx_nand_match), | 1018 | .of_match_table = lpc32xx_nand_match, |
1027 | }, | 1019 | }, |
1028 | }; | 1020 | }; |
1029 | 1021 | ||
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index ce8242b6c3e7..4edea7f4462f 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/irq.h> | 33 | #include <linux/irq.h> |
34 | #include <linux/completion.h> | 34 | #include <linux/completion.h> |
35 | #include <linux/of.h> | ||
35 | #include <linux/of_device.h> | 36 | #include <linux/of_device.h> |
36 | #include <linux/of_mtd.h> | 37 | #include <linux/of_mtd.h> |
37 | 38 | ||
@@ -1507,7 +1508,7 @@ static int mxcnd_probe(struct platform_device *pdev) | |||
1507 | host->devtype_data->irq_control(host, 0); | 1508 | host->devtype_data->irq_control(host, 0); |
1508 | 1509 | ||
1509 | err = devm_request_irq(&pdev->dev, host->irq, mxc_nfc_irq, | 1510 | err = devm_request_irq(&pdev->dev, host->irq, mxc_nfc_irq, |
1510 | IRQF_DISABLED, DRIVER_NAME, host); | 1511 | 0, DRIVER_NAME, host); |
1511 | if (err) | 1512 | if (err) |
1512 | return err; | 1513 | return err; |
1513 | 1514 | ||
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index d340b2f198c6..bd39f7b67906 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -2912,12 +2912,13 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd, | |||
2912 | /* get the info we want. */ | 2912 | /* get the info we want. */ |
2913 | ecc = (struct onfi_ext_ecc_info *)cursor; | 2913 | ecc = (struct onfi_ext_ecc_info *)cursor; |
2914 | 2914 | ||
2915 | if (ecc->codeword_size) { | 2915 | if (!ecc->codeword_size) { |
2916 | chip->ecc_strength_ds = ecc->ecc_bits; | 2916 | pr_debug("Invalid codeword size\n"); |
2917 | chip->ecc_step_ds = 1 << ecc->codeword_size; | 2917 | goto ext_out; |
2918 | } | 2918 | } |
2919 | 2919 | ||
2920 | pr_info("ONFI extended param page detected.\n"); | 2920 | chip->ecc_strength_ds = ecc->ecc_bits; |
2921 | chip->ecc_step_ds = 1 << ecc->codeword_size; | ||
2921 | ret = 0; | 2922 | ret = 0; |
2922 | 2923 | ||
2923 | ext_out: | 2924 | ext_out: |
@@ -2935,29 +2936,34 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2935 | int i; | 2936 | int i; |
2936 | int val; | 2937 | int val; |
2937 | 2938 | ||
2938 | /* ONFI need to be probed in 8 bits mode, and 16 bits should be selected with NAND_BUSWIDTH_AUTO */ | ||
2939 | if (chip->options & NAND_BUSWIDTH_16) { | ||
2940 | pr_err("Trying ONFI probe in 16 bits mode, aborting !\n"); | ||
2941 | return 0; | ||
2942 | } | ||
2943 | /* Try ONFI for unknown chip or LP */ | 2939 | /* Try ONFI for unknown chip or LP */ |
2944 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); | 2940 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); |
2945 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || | 2941 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || |
2946 | chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') | 2942 | chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') |
2947 | return 0; | 2943 | return 0; |
2948 | 2944 | ||
2945 | /* | ||
2946 | * ONFI must be probed in 8-bit mode or with NAND_BUSWIDTH_AUTO, not | ||
2947 | * with NAND_BUSWIDTH_16 | ||
2948 | */ | ||
2949 | if (chip->options & NAND_BUSWIDTH_16) { | ||
2950 | pr_err("ONFI cannot be probed in 16-bit mode; aborting\n"); | ||
2951 | return 0; | ||
2952 | } | ||
2953 | |||
2949 | chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); | 2954 | chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); |
2950 | for (i = 0; i < 3; i++) { | 2955 | for (i = 0; i < 3; i++) { |
2951 | chip->read_buf(mtd, (uint8_t *)p, sizeof(*p)); | 2956 | chip->read_buf(mtd, (uint8_t *)p, sizeof(*p)); |
2952 | if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) == | 2957 | if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) == |
2953 | le16_to_cpu(p->crc)) { | 2958 | le16_to_cpu(p->crc)) { |
2954 | pr_info("ONFI param page %d valid\n", i); | ||
2955 | break; | 2959 | break; |
2956 | } | 2960 | } |
2957 | } | 2961 | } |
2958 | 2962 | ||
2959 | if (i == 3) | 2963 | if (i == 3) { |
2964 | pr_err("Could not find valid ONFI parameter page; aborting\n"); | ||
2960 | return 0; | 2965 | return 0; |
2966 | } | ||
2961 | 2967 | ||
2962 | /* Check version */ | 2968 | /* Check version */ |
2963 | val = le16_to_cpu(p->revision); | 2969 | val = le16_to_cpu(p->revision); |
@@ -2981,11 +2987,23 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2981 | sanitize_string(p->model, sizeof(p->model)); | 2987 | sanitize_string(p->model, sizeof(p->model)); |
2982 | if (!mtd->name) | 2988 | if (!mtd->name) |
2983 | mtd->name = p->model; | 2989 | mtd->name = p->model; |
2990 | |||
2984 | mtd->writesize = le32_to_cpu(p->byte_per_page); | 2991 | mtd->writesize = le32_to_cpu(p->byte_per_page); |
2985 | mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize; | 2992 | |
2993 | /* | ||
2994 | * pages_per_block and blocks_per_lun may not be a power-of-2 size | ||
2995 | * (don't ask me who thought of this...). MTD assumes that these | ||
2996 | * dimensions will be power-of-2, so just truncate the remaining area. | ||
2997 | */ | ||
2998 | mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); | ||
2999 | mtd->erasesize *= mtd->writesize; | ||
3000 | |||
2986 | mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); | 3001 | mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); |
2987 | chip->chipsize = le32_to_cpu(p->blocks_per_lun); | 3002 | |
3003 | /* See erasesize comment */ | ||
3004 | chip->chipsize = 1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1); | ||
2988 | chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; | 3005 | chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; |
3006 | chip->bits_per_cell = p->bits_per_cell; | ||
2989 | 3007 | ||
2990 | if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) | 3008 | if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) |
2991 | *busw = NAND_BUSWIDTH_16; | 3009 | *busw = NAND_BUSWIDTH_16; |
@@ -3009,10 +3027,11 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
3009 | 3027 | ||
3010 | /* The Extended Parameter Page is supported since ONFI 2.1. */ | 3028 | /* The Extended Parameter Page is supported since ONFI 2.1. */ |
3011 | if (nand_flash_detect_ext_param_page(mtd, chip, p)) | 3029 | if (nand_flash_detect_ext_param_page(mtd, chip, p)) |
3012 | pr_info("Failed to detect the extended param page.\n"); | 3030 | pr_warn("Failed to detect ONFI extended param page\n"); |
3031 | } else { | ||
3032 | pr_warn("Could not retrieve ONFI ECC requirements\n"); | ||
3013 | } | 3033 | } |
3014 | 3034 | ||
3015 | pr_info("ONFI flash detected\n"); | ||
3016 | return 1; | 3035 | return 1; |
3017 | } | 3036 | } |
3018 | 3037 | ||
@@ -3075,6 +3094,16 @@ static int nand_id_len(u8 *id_data, int arrlen) | |||
3075 | return arrlen; | 3094 | return arrlen; |
3076 | } | 3095 | } |
3077 | 3096 | ||
3097 | /* Extract the bits of per cell from the 3rd byte of the extended ID */ | ||
3098 | static int nand_get_bits_per_cell(u8 cellinfo) | ||
3099 | { | ||
3100 | int bits; | ||
3101 | |||
3102 | bits = cellinfo & NAND_CI_CELLTYPE_MSK; | ||
3103 | bits >>= NAND_CI_CELLTYPE_SHIFT; | ||
3104 | return bits + 1; | ||
3105 | } | ||
3106 | |||
3078 | /* | 3107 | /* |
3079 | * Many new NAND share similar device ID codes, which represent the size of the | 3108 | * Many new NAND share similar device ID codes, which represent the size of the |
3080 | * chip. The rest of the parameters must be decoded according to generic or | 3109 | * chip. The rest of the parameters must be decoded according to generic or |
@@ -3085,7 +3114,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | |||
3085 | { | 3114 | { |
3086 | int extid, id_len; | 3115 | int extid, id_len; |
3087 | /* The 3rd id byte holds MLC / multichip data */ | 3116 | /* The 3rd id byte holds MLC / multichip data */ |
3088 | chip->cellinfo = id_data[2]; | 3117 | chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); |
3089 | /* The 4th id byte is the important one */ | 3118 | /* The 4th id byte is the important one */ |
3090 | extid = id_data[3]; | 3119 | extid = id_data[3]; |
3091 | 3120 | ||
@@ -3101,8 +3130,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | |||
3101 | * ID to decide what to do. | 3130 | * ID to decide what to do. |
3102 | */ | 3131 | */ |
3103 | if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG && | 3132 | if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG && |
3104 | (chip->cellinfo & NAND_CI_CELLTYPE_MSK) && | 3133 | !nand_is_slc(chip) && id_data[5] != 0x00) { |
3105 | id_data[5] != 0x00) { | ||
3106 | /* Calc pagesize */ | 3134 | /* Calc pagesize */ |
3107 | mtd->writesize = 2048 << (extid & 0x03); | 3135 | mtd->writesize = 2048 << (extid & 0x03); |
3108 | extid >>= 2; | 3136 | extid >>= 2; |
@@ -3134,7 +3162,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | |||
3134 | (((extid >> 1) & 0x04) | (extid & 0x03)); | 3162 | (((extid >> 1) & 0x04) | (extid & 0x03)); |
3135 | *busw = 0; | 3163 | *busw = 0; |
3136 | } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && | 3164 | } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && |
3137 | (chip->cellinfo & NAND_CI_CELLTYPE_MSK)) { | 3165 | !nand_is_slc(chip)) { |
3138 | unsigned int tmp; | 3166 | unsigned int tmp; |
3139 | 3167 | ||
3140 | /* Calc pagesize */ | 3168 | /* Calc pagesize */ |
@@ -3197,7 +3225,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, | |||
3197 | * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC | 3225 | * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC |
3198 | */ | 3226 | */ |
3199 | if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA && | 3227 | if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA && |
3200 | !(chip->cellinfo & NAND_CI_CELLTYPE_MSK) && | 3228 | nand_is_slc(chip) && |
3201 | (id_data[5] & 0x7) == 0x6 /* 24nm */ && | 3229 | (id_data[5] & 0x7) == 0x6 /* 24nm */ && |
3202 | !(id_data[4] & 0x80) /* !BENAND */) { | 3230 | !(id_data[4] & 0x80) /* !BENAND */) { |
3203 | mtd->oobsize = 32 * mtd->writesize >> 9; | 3231 | mtd->oobsize = 32 * mtd->writesize >> 9; |
@@ -3222,6 +3250,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, | |||
3222 | mtd->oobsize = mtd->writesize / 32; | 3250 | mtd->oobsize = mtd->writesize / 32; |
3223 | *busw = type->options & NAND_BUSWIDTH_16; | 3251 | *busw = type->options & NAND_BUSWIDTH_16; |
3224 | 3252 | ||
3253 | /* All legacy ID NAND are small-page, SLC */ | ||
3254 | chip->bits_per_cell = 1; | ||
3255 | |||
3225 | /* | 3256 | /* |
3226 | * Check for Spansion/AMD ID + repeating 5th, 6th byte since | 3257 | * Check for Spansion/AMD ID + repeating 5th, 6th byte since |
3227 | * some Spansion chips have erasesize that conflicts with size | 3258 | * some Spansion chips have erasesize that conflicts with size |
@@ -3258,11 +3289,11 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, | |||
3258 | * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, | 3289 | * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, |
3259 | * AMD/Spansion, and Macronix. All others scan only the first page. | 3290 | * AMD/Spansion, and Macronix. All others scan only the first page. |
3260 | */ | 3291 | */ |
3261 | if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) && | 3292 | if (!nand_is_slc(chip) && |
3262 | (maf_id == NAND_MFR_SAMSUNG || | 3293 | (maf_id == NAND_MFR_SAMSUNG || |
3263 | maf_id == NAND_MFR_HYNIX)) | 3294 | maf_id == NAND_MFR_HYNIX)) |
3264 | chip->bbt_options |= NAND_BBT_SCANLASTPAGE; | 3295 | chip->bbt_options |= NAND_BBT_SCANLASTPAGE; |
3265 | else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) && | 3296 | else if ((nand_is_slc(chip) && |
3266 | (maf_id == NAND_MFR_SAMSUNG || | 3297 | (maf_id == NAND_MFR_SAMSUNG || |
3267 | maf_id == NAND_MFR_HYNIX || | 3298 | maf_id == NAND_MFR_HYNIX || |
3268 | maf_id == NAND_MFR_TOSHIBA || | 3299 | maf_id == NAND_MFR_TOSHIBA || |
@@ -3286,7 +3317,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, | |||
3286 | mtd->erasesize = type->erasesize; | 3317 | mtd->erasesize = type->erasesize; |
3287 | mtd->oobsize = type->oobsize; | 3318 | mtd->oobsize = type->oobsize; |
3288 | 3319 | ||
3289 | chip->cellinfo = id_data[2]; | 3320 | chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); |
3290 | chip->chipsize = (uint64_t)type->chipsize << 20; | 3321 | chip->chipsize = (uint64_t)type->chipsize << 20; |
3291 | chip->options |= type->options; | 3322 | chip->options |= type->options; |
3292 | chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); | 3323 | chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); |
@@ -3441,11 +3472,13 @@ ident_done: | |||
3441 | if (mtd->writesize > 512 && chip->cmdfunc == nand_command) | 3472 | if (mtd->writesize > 512 && chip->cmdfunc == nand_command) |
3442 | chip->cmdfunc = nand_command_lp; | 3473 | chip->cmdfunc = nand_command_lp; |
3443 | 3474 | ||
3444 | pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s)," | 3475 | pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s)\n", |
3445 | " %dMiB, page size: %d, OOB size: %d\n", | ||
3446 | *maf_id, *dev_id, nand_manuf_ids[maf_idx].name, | 3476 | *maf_id, *dev_id, nand_manuf_ids[maf_idx].name, |
3447 | chip->onfi_version ? chip->onfi_params.model : type->name, | 3477 | chip->onfi_version ? chip->onfi_params.model : type->name); |
3448 | (int)(chip->chipsize >> 20), mtd->writesize, mtd->oobsize); | 3478 | |
3479 | pr_info("NAND device: %dMiB, %s, page size: %d, OOB size: %d\n", | ||
3480 | (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", | ||
3481 | mtd->writesize, mtd->oobsize); | ||
3449 | 3482 | ||
3450 | return type; | 3483 | return type; |
3451 | } | 3484 | } |
@@ -3525,6 +3558,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3525 | { | 3558 | { |
3526 | int i; | 3559 | int i; |
3527 | struct nand_chip *chip = mtd->priv; | 3560 | struct nand_chip *chip = mtd->priv; |
3561 | struct nand_ecc_ctrl *ecc = &chip->ecc; | ||
3528 | 3562 | ||
3529 | /* New bad blocks should be marked in OOB, flash-based BBT, or both */ | 3563 | /* New bad blocks should be marked in OOB, flash-based BBT, or both */ |
3530 | BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) && | 3564 | BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) && |
@@ -3541,19 +3575,19 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3541 | /* | 3575 | /* |
3542 | * If no default placement scheme is given, select an appropriate one. | 3576 | * If no default placement scheme is given, select an appropriate one. |
3543 | */ | 3577 | */ |
3544 | if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) { | 3578 | if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) { |
3545 | switch (mtd->oobsize) { | 3579 | switch (mtd->oobsize) { |
3546 | case 8: | 3580 | case 8: |
3547 | chip->ecc.layout = &nand_oob_8; | 3581 | ecc->layout = &nand_oob_8; |
3548 | break; | 3582 | break; |
3549 | case 16: | 3583 | case 16: |
3550 | chip->ecc.layout = &nand_oob_16; | 3584 | ecc->layout = &nand_oob_16; |
3551 | break; | 3585 | break; |
3552 | case 64: | 3586 | case 64: |
3553 | chip->ecc.layout = &nand_oob_64; | 3587 | ecc->layout = &nand_oob_64; |
3554 | break; | 3588 | break; |
3555 | case 128: | 3589 | case 128: |
3556 | chip->ecc.layout = &nand_oob_128; | 3590 | ecc->layout = &nand_oob_128; |
3557 | break; | 3591 | break; |
3558 | default: | 3592 | default: |
3559 | pr_warn("No oob scheme defined for oobsize %d\n", | 3593 | pr_warn("No oob scheme defined for oobsize %d\n", |
@@ -3570,64 +3604,62 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3570 | * selected and we have 256 byte pagesize fallback to software ECC | 3604 | * selected and we have 256 byte pagesize fallback to software ECC |
3571 | */ | 3605 | */ |
3572 | 3606 | ||
3573 | switch (chip->ecc.mode) { | 3607 | switch (ecc->mode) { |
3574 | case NAND_ECC_HW_OOB_FIRST: | 3608 | case NAND_ECC_HW_OOB_FIRST: |
3575 | /* Similar to NAND_ECC_HW, but a separate read_page handle */ | 3609 | /* Similar to NAND_ECC_HW, but a separate read_page handle */ |
3576 | if (!chip->ecc.calculate || !chip->ecc.correct || | 3610 | if (!ecc->calculate || !ecc->correct || !ecc->hwctl) { |
3577 | !chip->ecc.hwctl) { | ||
3578 | pr_warn("No ECC functions supplied; " | 3611 | pr_warn("No ECC functions supplied; " |
3579 | "hardware ECC not possible\n"); | 3612 | "hardware ECC not possible\n"); |
3580 | BUG(); | 3613 | BUG(); |
3581 | } | 3614 | } |
3582 | if (!chip->ecc.read_page) | 3615 | if (!ecc->read_page) |
3583 | chip->ecc.read_page = nand_read_page_hwecc_oob_first; | 3616 | ecc->read_page = nand_read_page_hwecc_oob_first; |
3584 | 3617 | ||
3585 | case NAND_ECC_HW: | 3618 | case NAND_ECC_HW: |
3586 | /* Use standard hwecc read page function? */ | 3619 | /* Use standard hwecc read page function? */ |
3587 | if (!chip->ecc.read_page) | 3620 | if (!ecc->read_page) |
3588 | chip->ecc.read_page = nand_read_page_hwecc; | 3621 | ecc->read_page = nand_read_page_hwecc; |
3589 | if (!chip->ecc.write_page) | 3622 | if (!ecc->write_page) |
3590 | chip->ecc.write_page = nand_write_page_hwecc; | 3623 | ecc->write_page = nand_write_page_hwecc; |
3591 | if (!chip->ecc.read_page_raw) | 3624 | if (!ecc->read_page_raw) |
3592 | chip->ecc.read_page_raw = nand_read_page_raw; | 3625 | ecc->read_page_raw = nand_read_page_raw; |
3593 | if (!chip->ecc.write_page_raw) | 3626 | if (!ecc->write_page_raw) |
3594 | chip->ecc.write_page_raw = nand_write_page_raw; | 3627 | ecc->write_page_raw = nand_write_page_raw; |
3595 | if (!chip->ecc.read_oob) | 3628 | if (!ecc->read_oob) |
3596 | chip->ecc.read_oob = nand_read_oob_std; | 3629 | ecc->read_oob = nand_read_oob_std; |
3597 | if (!chip->ecc.write_oob) | 3630 | if (!ecc->write_oob) |
3598 | chip->ecc.write_oob = nand_write_oob_std; | 3631 | ecc->write_oob = nand_write_oob_std; |
3599 | if (!chip->ecc.read_subpage) | 3632 | if (!ecc->read_subpage) |
3600 | chip->ecc.read_subpage = nand_read_subpage; | 3633 | ecc->read_subpage = nand_read_subpage; |
3601 | if (!chip->ecc.write_subpage) | 3634 | if (!ecc->write_subpage) |
3602 | chip->ecc.write_subpage = nand_write_subpage_hwecc; | 3635 | ecc->write_subpage = nand_write_subpage_hwecc; |
3603 | 3636 | ||
3604 | case NAND_ECC_HW_SYNDROME: | 3637 | case NAND_ECC_HW_SYNDROME: |
3605 | if ((!chip->ecc.calculate || !chip->ecc.correct || | 3638 | if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) && |
3606 | !chip->ecc.hwctl) && | 3639 | (!ecc->read_page || |
3607 | (!chip->ecc.read_page || | 3640 | ecc->read_page == nand_read_page_hwecc || |
3608 | chip->ecc.read_page == nand_read_page_hwecc || | 3641 | !ecc->write_page || |
3609 | !chip->ecc.write_page || | 3642 | ecc->write_page == nand_write_page_hwecc)) { |
3610 | chip->ecc.write_page == nand_write_page_hwecc)) { | ||
3611 | pr_warn("No ECC functions supplied; " | 3643 | pr_warn("No ECC functions supplied; " |
3612 | "hardware ECC not possible\n"); | 3644 | "hardware ECC not possible\n"); |
3613 | BUG(); | 3645 | BUG(); |
3614 | } | 3646 | } |
3615 | /* Use standard syndrome read/write page function? */ | 3647 | /* Use standard syndrome read/write page function? */ |
3616 | if (!chip->ecc.read_page) | 3648 | if (!ecc->read_page) |
3617 | chip->ecc.read_page = nand_read_page_syndrome; | 3649 | ecc->read_page = nand_read_page_syndrome; |
3618 | if (!chip->ecc.write_page) | 3650 | if (!ecc->write_page) |
3619 | chip->ecc.write_page = nand_write_page_syndrome; | 3651 | ecc->write_page = nand_write_page_syndrome; |
3620 | if (!chip->ecc.read_page_raw) | 3652 | if (!ecc->read_page_raw) |
3621 | chip->ecc.read_page_raw = nand_read_page_raw_syndrome; | 3653 | ecc->read_page_raw = nand_read_page_raw_syndrome; |
3622 | if (!chip->ecc.write_page_raw) | 3654 | if (!ecc->write_page_raw) |
3623 | chip->ecc.write_page_raw = nand_write_page_raw_syndrome; | 3655 | ecc->write_page_raw = nand_write_page_raw_syndrome; |
3624 | if (!chip->ecc.read_oob) | 3656 | if (!ecc->read_oob) |
3625 | chip->ecc.read_oob = nand_read_oob_syndrome; | 3657 | ecc->read_oob = nand_read_oob_syndrome; |
3626 | if (!chip->ecc.write_oob) | 3658 | if (!ecc->write_oob) |
3627 | chip->ecc.write_oob = nand_write_oob_syndrome; | 3659 | ecc->write_oob = nand_write_oob_syndrome; |
3628 | 3660 | ||
3629 | if (mtd->writesize >= chip->ecc.size) { | 3661 | if (mtd->writesize >= ecc->size) { |
3630 | if (!chip->ecc.strength) { | 3662 | if (!ecc->strength) { |
3631 | pr_warn("Driver must set ecc.strength when using hardware ECC\n"); | 3663 | pr_warn("Driver must set ecc.strength when using hardware ECC\n"); |
3632 | BUG(); | 3664 | BUG(); |
3633 | } | 3665 | } |
@@ -3635,23 +3667,23 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3635 | } | 3667 | } |
3636 | pr_warn("%d byte HW ECC not possible on " | 3668 | pr_warn("%d byte HW ECC not possible on " |
3637 | "%d byte page size, fallback to SW ECC\n", | 3669 | "%d byte page size, fallback to SW ECC\n", |
3638 | chip->ecc.size, mtd->writesize); | 3670 | ecc->size, mtd->writesize); |
3639 | chip->ecc.mode = NAND_ECC_SOFT; | 3671 | ecc->mode = NAND_ECC_SOFT; |
3640 | 3672 | ||
3641 | case NAND_ECC_SOFT: | 3673 | case NAND_ECC_SOFT: |
3642 | chip->ecc.calculate = nand_calculate_ecc; | 3674 | ecc->calculate = nand_calculate_ecc; |
3643 | chip->ecc.correct = nand_correct_data; | 3675 | ecc->correct = nand_correct_data; |
3644 | chip->ecc.read_page = nand_read_page_swecc; | 3676 | ecc->read_page = nand_read_page_swecc; |
3645 | chip->ecc.read_subpage = nand_read_subpage; | 3677 | ecc->read_subpage = nand_read_subpage; |
3646 | chip->ecc.write_page = nand_write_page_swecc; | 3678 | ecc->write_page = nand_write_page_swecc; |
3647 | chip->ecc.read_page_raw = nand_read_page_raw; | 3679 | ecc->read_page_raw = nand_read_page_raw; |
3648 | chip->ecc.write_page_raw = nand_write_page_raw; | 3680 | ecc->write_page_raw = nand_write_page_raw; |
3649 | chip->ecc.read_oob = nand_read_oob_std; | 3681 | ecc->read_oob = nand_read_oob_std; |
3650 | chip->ecc.write_oob = nand_write_oob_std; | 3682 | ecc->write_oob = nand_write_oob_std; |
3651 | if (!chip->ecc.size) | 3683 | if (!ecc->size) |
3652 | chip->ecc.size = 256; | 3684 | ecc->size = 256; |
3653 | chip->ecc.bytes = 3; | 3685 | ecc->bytes = 3; |
3654 | chip->ecc.strength = 1; | 3686 | ecc->strength = 1; |
3655 | break; | 3687 | break; |
3656 | 3688 | ||
3657 | case NAND_ECC_SOFT_BCH: | 3689 | case NAND_ECC_SOFT_BCH: |
@@ -3659,88 +3691,83 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3659 | pr_warn("CONFIG_MTD_ECC_BCH not enabled\n"); | 3691 | pr_warn("CONFIG_MTD_ECC_BCH not enabled\n"); |
3660 | BUG(); | 3692 | BUG(); |
3661 | } | 3693 | } |
3662 | chip->ecc.calculate = nand_bch_calculate_ecc; | 3694 | ecc->calculate = nand_bch_calculate_ecc; |
3663 | chip->ecc.correct = nand_bch_correct_data; | 3695 | ecc->correct = nand_bch_correct_data; |
3664 | chip->ecc.read_page = nand_read_page_swecc; | 3696 | ecc->read_page = nand_read_page_swecc; |
3665 | chip->ecc.read_subpage = nand_read_subpage; | 3697 | ecc->read_subpage = nand_read_subpage; |
3666 | chip->ecc.write_page = nand_write_page_swecc; | 3698 | ecc->write_page = nand_write_page_swecc; |
3667 | chip->ecc.read_page_raw = nand_read_page_raw; | 3699 | ecc->read_page_raw = nand_read_page_raw; |
3668 | chip->ecc.write_page_raw = nand_write_page_raw; | 3700 | ecc->write_page_raw = nand_write_page_raw; |
3669 | chip->ecc.read_oob = nand_read_oob_std; | 3701 | ecc->read_oob = nand_read_oob_std; |
3670 | chip->ecc.write_oob = nand_write_oob_std; | 3702 | ecc->write_oob = nand_write_oob_std; |
3671 | /* | 3703 | /* |
3672 | * Board driver should supply ecc.size and ecc.bytes values to | 3704 | * Board driver should supply ecc.size and ecc.bytes values to |
3673 | * select how many bits are correctable; see nand_bch_init() | 3705 | * select how many bits are correctable; see nand_bch_init() |
3674 | * for details. Otherwise, default to 4 bits for large page | 3706 | * for details. Otherwise, default to 4 bits for large page |
3675 | * devices. | 3707 | * devices. |
3676 | */ | 3708 | */ |
3677 | if (!chip->ecc.size && (mtd->oobsize >= 64)) { | 3709 | if (!ecc->size && (mtd->oobsize >= 64)) { |
3678 | chip->ecc.size = 512; | 3710 | ecc->size = 512; |
3679 | chip->ecc.bytes = 7; | 3711 | ecc->bytes = 7; |
3680 | } | 3712 | } |
3681 | chip->ecc.priv = nand_bch_init(mtd, | 3713 | ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes, |
3682 | chip->ecc.size, | 3714 | &ecc->layout); |
3683 | chip->ecc.bytes, | 3715 | if (!ecc->priv) { |
3684 | &chip->ecc.layout); | ||
3685 | if (!chip->ecc.priv) { | ||
3686 | pr_warn("BCH ECC initialization failed!\n"); | 3716 | pr_warn("BCH ECC initialization failed!\n"); |
3687 | BUG(); | 3717 | BUG(); |
3688 | } | 3718 | } |
3689 | chip->ecc.strength = | 3719 | ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size); |
3690 | chip->ecc.bytes * 8 / fls(8 * chip->ecc.size); | ||
3691 | break; | 3720 | break; |
3692 | 3721 | ||
3693 | case NAND_ECC_NONE: | 3722 | case NAND_ECC_NONE: |
3694 | pr_warn("NAND_ECC_NONE selected by board driver. " | 3723 | pr_warn("NAND_ECC_NONE selected by board driver. " |
3695 | "This is not recommended!\n"); | 3724 | "This is not recommended!\n"); |
3696 | chip->ecc.read_page = nand_read_page_raw; | 3725 | ecc->read_page = nand_read_page_raw; |
3697 | chip->ecc.write_page = nand_write_page_raw; | 3726 | ecc->write_page = nand_write_page_raw; |
3698 | chip->ecc.read_oob = nand_read_oob_std; | 3727 | ecc->read_oob = nand_read_oob_std; |
3699 | chip->ecc.read_page_raw = nand_read_page_raw; | 3728 | ecc->read_page_raw = nand_read_page_raw; |
3700 | chip->ecc.write_page_raw = nand_write_page_raw; | 3729 | ecc->write_page_raw = nand_write_page_raw; |
3701 | chip->ecc.write_oob = nand_write_oob_std; | 3730 | ecc->write_oob = nand_write_oob_std; |
3702 | chip->ecc.size = mtd->writesize; | 3731 | ecc->size = mtd->writesize; |
3703 | chip->ecc.bytes = 0; | 3732 | ecc->bytes = 0; |
3704 | chip->ecc.strength = 0; | 3733 | ecc->strength = 0; |
3705 | break; | 3734 | break; |
3706 | 3735 | ||
3707 | default: | 3736 | default: |
3708 | pr_warn("Invalid NAND_ECC_MODE %d\n", chip->ecc.mode); | 3737 | pr_warn("Invalid NAND_ECC_MODE %d\n", ecc->mode); |
3709 | BUG(); | 3738 | BUG(); |
3710 | } | 3739 | } |
3711 | 3740 | ||
3712 | /* For many systems, the standard OOB write also works for raw */ | 3741 | /* For many systems, the standard OOB write also works for raw */ |
3713 | if (!chip->ecc.read_oob_raw) | 3742 | if (!ecc->read_oob_raw) |
3714 | chip->ecc.read_oob_raw = chip->ecc.read_oob; | 3743 | ecc->read_oob_raw = ecc->read_oob; |
3715 | if (!chip->ecc.write_oob_raw) | 3744 | if (!ecc->write_oob_raw) |
3716 | chip->ecc.write_oob_raw = chip->ecc.write_oob; | 3745 | ecc->write_oob_raw = ecc->write_oob; |
3717 | 3746 | ||
3718 | /* | 3747 | /* |
3719 | * The number of bytes available for a client to place data into | 3748 | * The number of bytes available for a client to place data into |
3720 | * the out of band area. | 3749 | * the out of band area. |
3721 | */ | 3750 | */ |
3722 | chip->ecc.layout->oobavail = 0; | 3751 | ecc->layout->oobavail = 0; |
3723 | for (i = 0; chip->ecc.layout->oobfree[i].length | 3752 | for (i = 0; ecc->layout->oobfree[i].length |
3724 | && i < ARRAY_SIZE(chip->ecc.layout->oobfree); i++) | 3753 | && i < ARRAY_SIZE(ecc->layout->oobfree); i++) |
3725 | chip->ecc.layout->oobavail += | 3754 | ecc->layout->oobavail += ecc->layout->oobfree[i].length; |
3726 | chip->ecc.layout->oobfree[i].length; | 3755 | mtd->oobavail = ecc->layout->oobavail; |
3727 | mtd->oobavail = chip->ecc.layout->oobavail; | ||
3728 | 3756 | ||
3729 | /* | 3757 | /* |
3730 | * Set the number of read / write steps for one page depending on ECC | 3758 | * Set the number of read / write steps for one page depending on ECC |
3731 | * mode. | 3759 | * mode. |
3732 | */ | 3760 | */ |
3733 | chip->ecc.steps = mtd->writesize / chip->ecc.size; | 3761 | ecc->steps = mtd->writesize / ecc->size; |
3734 | if (chip->ecc.steps * chip->ecc.size != mtd->writesize) { | 3762 | if (ecc->steps * ecc->size != mtd->writesize) { |
3735 | pr_warn("Invalid ECC parameters\n"); | 3763 | pr_warn("Invalid ECC parameters\n"); |
3736 | BUG(); | 3764 | BUG(); |
3737 | } | 3765 | } |
3738 | chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; | 3766 | ecc->total = ecc->steps * ecc->bytes; |
3739 | 3767 | ||
3740 | /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ | 3768 | /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ |
3741 | if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && | 3769 | if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) { |
3742 | !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) { | 3770 | switch (ecc->steps) { |
3743 | switch (chip->ecc.steps) { | ||
3744 | case 2: | 3771 | case 2: |
3745 | mtd->subpage_sft = 1; | 3772 | mtd->subpage_sft = 1; |
3746 | break; | 3773 | break; |
@@ -3760,11 +3787,11 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3760 | chip->pagebuf = -1; | 3787 | chip->pagebuf = -1; |
3761 | 3788 | ||
3762 | /* Large page NAND with SOFT_ECC should support subpage reads */ | 3789 | /* Large page NAND with SOFT_ECC should support subpage reads */ |
3763 | if ((chip->ecc.mode == NAND_ECC_SOFT) && (chip->page_shift > 9)) | 3790 | if ((ecc->mode == NAND_ECC_SOFT) && (chip->page_shift > 9)) |
3764 | chip->options |= NAND_SUBPAGE_READ; | 3791 | chip->options |= NAND_SUBPAGE_READ; |
3765 | 3792 | ||
3766 | /* Fill in remaining MTD driver data */ | 3793 | /* Fill in remaining MTD driver data */ |
3767 | mtd->type = MTD_NANDFLASH; | 3794 | mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; |
3768 | mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : | 3795 | mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : |
3769 | MTD_CAP_NANDFLASH; | 3796 | MTD_CAP_NANDFLASH; |
3770 | mtd->_erase = nand_erase; | 3797 | mtd->_erase = nand_erase; |
@@ -3785,9 +3812,9 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3785 | mtd->writebufsize = mtd->writesize; | 3812 | mtd->writebufsize = mtd->writesize; |
3786 | 3813 | ||
3787 | /* propagate ecc info to mtd_info */ | 3814 | /* propagate ecc info to mtd_info */ |
3788 | mtd->ecclayout = chip->ecc.layout; | 3815 | mtd->ecclayout = ecc->layout; |
3789 | mtd->ecc_strength = chip->ecc.strength; | 3816 | mtd->ecc_strength = ecc->strength; |
3790 | mtd->ecc_step_size = chip->ecc.size; | 3817 | mtd->ecc_step_size = ecc->size; |
3791 | /* | 3818 | /* |
3792 | * Initialize bitflip_threshold to its default prior scan_bbt() call. | 3819 | * Initialize bitflip_threshold to its default prior scan_bbt() call. |
3793 | * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be | 3820 | * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be |
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index bc06196d5739..c0615d1526f9 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c | |||
@@ -412,25 +412,6 @@ static void read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, | |||
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | /* Scan a given block full */ | ||
416 | static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, | ||
417 | loff_t offs, uint8_t *buf, size_t readlen, | ||
418 | int scanlen, int numpages) | ||
419 | { | ||
420 | int ret, j; | ||
421 | |||
422 | ret = scan_read_oob(mtd, buf, offs, readlen); | ||
423 | /* Ignore ECC errors when checking for BBM */ | ||
424 | if (ret && !mtd_is_bitflip_or_eccerr(ret)) | ||
425 | return ret; | ||
426 | |||
427 | for (j = 0; j < numpages; j++, buf += scanlen) { | ||
428 | if (check_pattern(buf, scanlen, mtd->writesize, bd)) | ||
429 | return 1; | ||
430 | } | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | /* Scan a given block partially */ | 415 | /* Scan a given block partially */ |
435 | static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, | 416 | static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, |
436 | loff_t offs, uint8_t *buf, int numpages) | 417 | loff_t offs, uint8_t *buf, int numpages) |
@@ -477,24 +458,17 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
477 | struct nand_bbt_descr *bd, int chip) | 458 | struct nand_bbt_descr *bd, int chip) |
478 | { | 459 | { |
479 | struct nand_chip *this = mtd->priv; | 460 | struct nand_chip *this = mtd->priv; |
480 | int i, numblocks, numpages, scanlen; | 461 | int i, numblocks, numpages; |
481 | int startblock; | 462 | int startblock; |
482 | loff_t from; | 463 | loff_t from; |
483 | size_t readlen; | ||
484 | 464 | ||
485 | pr_info("Scanning device for bad blocks\n"); | 465 | pr_info("Scanning device for bad blocks\n"); |
486 | 466 | ||
487 | if (bd->options & NAND_BBT_SCANALLPAGES) | 467 | if (bd->options & NAND_BBT_SCAN2NDPAGE) |
488 | numpages = 1 << (this->bbt_erase_shift - this->page_shift); | ||
489 | else if (bd->options & NAND_BBT_SCAN2NDPAGE) | ||
490 | numpages = 2; | 468 | numpages = 2; |
491 | else | 469 | else |
492 | numpages = 1; | 470 | numpages = 1; |
493 | 471 | ||
494 | /* We need only read few bytes from the OOB area */ | ||
495 | scanlen = 0; | ||
496 | readlen = bd->len; | ||
497 | |||
498 | if (chip == -1) { | 472 | if (chip == -1) { |
499 | numblocks = mtd->size >> this->bbt_erase_shift; | 473 | numblocks = mtd->size >> this->bbt_erase_shift; |
500 | startblock = 0; | 474 | startblock = 0; |
@@ -519,12 +493,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
519 | 493 | ||
520 | BUG_ON(bd->options & NAND_BBT_NO_OOB); | 494 | BUG_ON(bd->options & NAND_BBT_NO_OOB); |
521 | 495 | ||
522 | if (bd->options & NAND_BBT_SCANALLPAGES) | 496 | ret = scan_block_fast(mtd, bd, from, buf, numpages); |
523 | ret = scan_block_full(mtd, bd, from, buf, readlen, | ||
524 | scanlen, numpages); | ||
525 | else | ||
526 | ret = scan_block_fast(mtd, bd, from, buf, numpages); | ||
527 | |||
528 | if (ret < 0) | 497 | if (ret < 0) |
529 | return ret; | 498 | return ret; |
530 | 499 | ||
@@ -1392,4 +1361,3 @@ int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs) | |||
1392 | } | 1361 | } |
1393 | 1362 | ||
1394 | EXPORT_SYMBOL(nand_scan_bbt); | 1363 | EXPORT_SYMBOL(nand_scan_bbt); |
1395 | EXPORT_SYMBOL(nand_default_bbt); | ||
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index d1c7de92cfdf..42e8a770e631 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c | |||
@@ -2372,7 +2372,7 @@ static int __init ns_init_module(void) | |||
2372 | if ((retval = init_nandsim(nsmtd)) != 0) | 2372 | if ((retval = init_nandsim(nsmtd)) != 0) |
2373 | goto err_exit; | 2373 | goto err_exit; |
2374 | 2374 | ||
2375 | if ((retval = nand_default_bbt(nsmtd)) != 0) | 2375 | if ((retval = chip->scan_bbt(nsmtd)) != 0) |
2376 | goto err_exit; | 2376 | goto err_exit; |
2377 | 2377 | ||
2378 | if ((retval = parse_badblocks(nand, nsmtd)) != 0) | 2378 | if ((retval = parse_badblocks(nand, nsmtd)) != 0) |
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index 4ecf0e5fd484..f77725009907 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c | |||
@@ -25,10 +25,8 @@ | |||
25 | #include <linux/of.h> | 25 | #include <linux/of.h> |
26 | #include <linux/of_device.h> | 26 | #include <linux/of_device.h> |
27 | 27 | ||
28 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | 28 | #include <linux/mtd/nand_bch.h> |
29 | #include <linux/bch.h> | ||
30 | #include <linux/platform_data/elm.h> | 29 | #include <linux/platform_data/elm.h> |
31 | #endif | ||
32 | 30 | ||
33 | #include <linux/platform_data/mtd-nand-omap2.h> | 31 | #include <linux/platform_data/mtd-nand-omap2.h> |
34 | 32 | ||
@@ -141,6 +139,8 @@ | |||
141 | #define BCH_ECC_SIZE0 0x0 /* ecc_size0 = 0, no oob protection */ | 139 | #define BCH_ECC_SIZE0 0x0 /* ecc_size0 = 0, no oob protection */ |
142 | #define BCH_ECC_SIZE1 0x20 /* ecc_size1 = 32 */ | 140 | #define BCH_ECC_SIZE1 0x20 /* ecc_size1 = 32 */ |
143 | 141 | ||
142 | #define BADBLOCK_MARKER_LENGTH 2 | ||
143 | |||
144 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | 144 | #ifdef CONFIG_MTD_NAND_OMAP_BCH |
145 | static u_char bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2, 0xbe, 0xcc, | 145 | static u_char bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2, 0xbe, 0xcc, |
146 | 0xac, 0x6b, 0xff, 0x99, 0x7b}; | 146 | 0xac, 0x6b, 0xff, 0x99, 0x7b}; |
@@ -149,17 +149,6 @@ static u_char bch4_vector[] = {0x00, 0x6b, 0x31, 0xdd, 0x41, 0xbc, 0x10}; | |||
149 | 149 | ||
150 | /* oob info generated runtime depending on ecc algorithm and layout selected */ | 150 | /* oob info generated runtime depending on ecc algorithm and layout selected */ |
151 | static struct nand_ecclayout omap_oobinfo; | 151 | static struct nand_ecclayout omap_oobinfo; |
152 | /* Define some generic bad / good block scan pattern which are used | ||
153 | * while scanning a device for factory marked good / bad blocks | ||
154 | */ | ||
155 | static uint8_t scan_ff_pattern[] = { 0xff }; | ||
156 | static struct nand_bbt_descr bb_descrip_flashbased = { | ||
157 | .options = NAND_BBT_SCANALLPAGES, | ||
158 | .offs = 0, | ||
159 | .len = 1, | ||
160 | .pattern = scan_ff_pattern, | ||
161 | }; | ||
162 | |||
163 | 152 | ||
164 | struct omap_nand_info { | 153 | struct omap_nand_info { |
165 | struct nand_hw_control controller; | 154 | struct nand_hw_control controller; |
@@ -182,14 +171,10 @@ struct omap_nand_info { | |||
182 | u_char *buf; | 171 | u_char *buf; |
183 | int buf_len; | 172 | int buf_len; |
184 | struct gpmc_nand_regs reg; | 173 | struct gpmc_nand_regs reg; |
185 | 174 | /* fields specific for BCHx_HW ECC scheme */ | |
186 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | ||
187 | struct bch_control *bch; | ||
188 | struct nand_ecclayout ecclayout; | ||
189 | bool is_elm_used; | 175 | bool is_elm_used; |
190 | struct device *elm_dev; | 176 | struct device *elm_dev; |
191 | struct device_node *of_node; | 177 | struct device_node *of_node; |
192 | #endif | ||
193 | }; | 178 | }; |
194 | 179 | ||
195 | /** | 180 | /** |
@@ -1058,8 +1043,7 @@ static int omap_dev_ready(struct mtd_info *mtd) | |||
1058 | } | 1043 | } |
1059 | } | 1044 | } |
1060 | 1045 | ||
1061 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | 1046 | #if defined(CONFIG_MTD_NAND_ECC_BCH) || defined(CONFIG_MTD_NAND_OMAP_BCH) |
1062 | |||
1063 | /** | 1047 | /** |
1064 | * omap3_enable_hwecc_bch - Program OMAP3 GPMC to perform BCH ECC correction | 1048 | * omap3_enable_hwecc_bch - Program OMAP3 GPMC to perform BCH ECC correction |
1065 | * @mtd: MTD device structure | 1049 | * @mtd: MTD device structure |
@@ -1140,7 +1124,9 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode) | |||
1140 | /* Clear ecc and enable bits */ | 1124 | /* Clear ecc and enable bits */ |
1141 | writel(ECCCLEAR | ECC1, info->reg.gpmc_ecc_control); | 1125 | writel(ECCCLEAR | ECC1, info->reg.gpmc_ecc_control); |
1142 | } | 1126 | } |
1127 | #endif | ||
1143 | 1128 | ||
1129 | #ifdef CONFIG_MTD_NAND_ECC_BCH | ||
1144 | /** | 1130 | /** |
1145 | * omap3_calculate_ecc_bch4 - Generate 7 bytes of ECC bytes | 1131 | * omap3_calculate_ecc_bch4 - Generate 7 bytes of ECC bytes |
1146 | * @mtd: MTD device structure | 1132 | * @mtd: MTD device structure |
@@ -1225,7 +1211,9 @@ static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat, | |||
1225 | 1211 | ||
1226 | return 0; | 1212 | return 0; |
1227 | } | 1213 | } |
1214 | #endif /* CONFIG_MTD_NAND_ECC_BCH */ | ||
1228 | 1215 | ||
1216 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | ||
1229 | /** | 1217 | /** |
1230 | * omap3_calculate_ecc_bch - Generate bytes of ECC bytes | 1218 | * omap3_calculate_ecc_bch - Generate bytes of ECC bytes |
1231 | * @mtd: MTD device structure | 1219 | * @mtd: MTD device structure |
@@ -1519,38 +1507,6 @@ static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data, | |||
1519 | } | 1507 | } |
1520 | 1508 | ||
1521 | /** | 1509 | /** |
1522 | * omap3_correct_data_bch - Decode received data and correct errors | ||
1523 | * @mtd: MTD device structure | ||
1524 | * @data: page data | ||
1525 | * @read_ecc: ecc read from nand flash | ||
1526 | * @calc_ecc: ecc read from HW ECC registers | ||
1527 | */ | ||
1528 | static int omap3_correct_data_bch(struct mtd_info *mtd, u_char *data, | ||
1529 | u_char *read_ecc, u_char *calc_ecc) | ||
1530 | { | ||
1531 | int i, count; | ||
1532 | /* cannot correct more than 8 errors */ | ||
1533 | unsigned int errloc[8]; | ||
1534 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, | ||
1535 | mtd); | ||
1536 | |||
1537 | count = decode_bch(info->bch, NULL, 512, read_ecc, calc_ecc, NULL, | ||
1538 | errloc); | ||
1539 | if (count > 0) { | ||
1540 | /* correct errors */ | ||
1541 | for (i = 0; i < count; i++) { | ||
1542 | /* correct data only, not ecc bytes */ | ||
1543 | if (errloc[i] < 8*512) | ||
1544 | data[errloc[i]/8] ^= 1 << (errloc[i] & 7); | ||
1545 | pr_debug("corrected bitflip %u\n", errloc[i]); | ||
1546 | } | ||
1547 | } else if (count < 0) { | ||
1548 | pr_err("ecc unrecoverable error\n"); | ||
1549 | } | ||
1550 | return count; | ||
1551 | } | ||
1552 | |||
1553 | /** | ||
1554 | * omap_write_page_bch - BCH ecc based write page function for entire page | 1510 | * omap_write_page_bch - BCH ecc based write page function for entire page |
1555 | * @mtd: mtd info structure | 1511 | * @mtd: mtd info structure |
1556 | * @chip: nand chip info structure | 1512 | * @chip: nand chip info structure |
@@ -1637,197 +1593,46 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip, | |||
1637 | } | 1593 | } |
1638 | 1594 | ||
1639 | /** | 1595 | /** |
1640 | * omap3_free_bch - Release BCH ecc resources | 1596 | * is_elm_present - checks for presence of ELM module by scanning DT nodes |
1641 | * @mtd: MTD device structure | 1597 | * @omap_nand_info: NAND device structure containing platform data |
1642 | */ | 1598 | * @bch_type: 0x0=BCH4, 0x1=BCH8, 0x2=BCH16 |
1643 | static void omap3_free_bch(struct mtd_info *mtd) | ||
1644 | { | ||
1645 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, | ||
1646 | mtd); | ||
1647 | if (info->bch) { | ||
1648 | free_bch(info->bch); | ||
1649 | info->bch = NULL; | ||
1650 | } | ||
1651 | } | ||
1652 | |||
1653 | /** | ||
1654 | * omap3_init_bch - Initialize BCH ECC | ||
1655 | * @mtd: MTD device structure | ||
1656 | * @ecc_opt: OMAP ECC mode (OMAP_ECC_BCH4_CODE_HW or OMAP_ECC_BCH8_CODE_HW) | ||
1657 | */ | ||
1658 | static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt) | ||
1659 | { | ||
1660 | int max_errors; | ||
1661 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, | ||
1662 | mtd); | ||
1663 | #ifdef CONFIG_MTD_NAND_OMAP_BCH8 | ||
1664 | const int hw_errors = BCH8_MAX_ERROR; | ||
1665 | #else | ||
1666 | const int hw_errors = BCH4_MAX_ERROR; | ||
1667 | #endif | ||
1668 | enum bch_ecc bch_type; | ||
1669 | const __be32 *parp; | ||
1670 | int lenp; | ||
1671 | struct device_node *elm_node; | ||
1672 | |||
1673 | info->bch = NULL; | ||
1674 | |||
1675 | max_errors = (ecc_opt == OMAP_ECC_BCH8_CODE_HW) ? | ||
1676 | BCH8_MAX_ERROR : BCH4_MAX_ERROR; | ||
1677 | if (max_errors != hw_errors) { | ||
1678 | pr_err("cannot configure %d-bit BCH ecc, only %d-bit supported", | ||
1679 | max_errors, hw_errors); | ||
1680 | goto fail; | ||
1681 | } | ||
1682 | |||
1683 | info->nand.ecc.size = 512; | ||
1684 | info->nand.ecc.hwctl = omap3_enable_hwecc_bch; | ||
1685 | info->nand.ecc.mode = NAND_ECC_HW; | ||
1686 | info->nand.ecc.strength = max_errors; | ||
1687 | |||
1688 | if (hw_errors == BCH8_MAX_ERROR) | ||
1689 | bch_type = BCH8_ECC; | ||
1690 | else | ||
1691 | bch_type = BCH4_ECC; | ||
1692 | |||
1693 | /* Detect availability of ELM module */ | ||
1694 | parp = of_get_property(info->of_node, "elm_id", &lenp); | ||
1695 | if ((parp == NULL) && (lenp != (sizeof(void *) * 2))) { | ||
1696 | pr_err("Missing elm_id property, fall back to Software BCH\n"); | ||
1697 | info->is_elm_used = false; | ||
1698 | } else { | ||
1699 | struct platform_device *pdev; | ||
1700 | |||
1701 | elm_node = of_find_node_by_phandle(be32_to_cpup(parp)); | ||
1702 | pdev = of_find_device_by_node(elm_node); | ||
1703 | info->elm_dev = &pdev->dev; | ||
1704 | |||
1705 | if (elm_config(info->elm_dev, bch_type) == 0) | ||
1706 | info->is_elm_used = true; | ||
1707 | } | ||
1708 | |||
1709 | if (info->is_elm_used && (mtd->writesize <= 4096)) { | ||
1710 | |||
1711 | if (hw_errors == BCH8_MAX_ERROR) | ||
1712 | info->nand.ecc.bytes = BCH8_SIZE; | ||
1713 | else | ||
1714 | info->nand.ecc.bytes = BCH4_SIZE; | ||
1715 | |||
1716 | info->nand.ecc.correct = omap_elm_correct_data; | ||
1717 | info->nand.ecc.calculate = omap3_calculate_ecc_bch; | ||
1718 | info->nand.ecc.read_page = omap_read_page_bch; | ||
1719 | info->nand.ecc.write_page = omap_write_page_bch; | ||
1720 | } else { | ||
1721 | /* | ||
1722 | * software bch library is only used to detect and | ||
1723 | * locate errors | ||
1724 | */ | ||
1725 | info->bch = init_bch(13, max_errors, | ||
1726 | 0x201b /* hw polynomial */); | ||
1727 | if (!info->bch) | ||
1728 | goto fail; | ||
1729 | |||
1730 | info->nand.ecc.correct = omap3_correct_data_bch; | ||
1731 | |||
1732 | /* | ||
1733 | * The number of corrected errors in an ecc block that will | ||
1734 | * trigger block scrubbing defaults to the ecc strength (4 or 8) | ||
1735 | * Set mtd->bitflip_threshold here to define a custom threshold. | ||
1736 | */ | ||
1737 | |||
1738 | if (max_errors == 8) { | ||
1739 | info->nand.ecc.bytes = 13; | ||
1740 | info->nand.ecc.calculate = omap3_calculate_ecc_bch8; | ||
1741 | } else { | ||
1742 | info->nand.ecc.bytes = 7; | ||
1743 | info->nand.ecc.calculate = omap3_calculate_ecc_bch4; | ||
1744 | } | ||
1745 | } | ||
1746 | |||
1747 | pr_info("enabling NAND BCH ecc with %d-bit correction\n", max_errors); | ||
1748 | return 0; | ||
1749 | fail: | ||
1750 | omap3_free_bch(mtd); | ||
1751 | return -1; | ||
1752 | } | ||
1753 | |||
1754 | /** | ||
1755 | * omap3_init_bch_tail - Build an oob layout for BCH ECC correction. | ||
1756 | * @mtd: MTD device structure | ||
1757 | */ | 1599 | */ |
1758 | static int omap3_init_bch_tail(struct mtd_info *mtd) | 1600 | static int is_elm_present(struct omap_nand_info *info, |
1601 | struct device_node *elm_node, enum bch_ecc bch_type) | ||
1759 | { | 1602 | { |
1760 | int i, steps, offset; | 1603 | struct platform_device *pdev; |
1761 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, | 1604 | info->is_elm_used = false; |
1762 | mtd); | 1605 | /* check whether elm-id is passed via DT */ |
1763 | struct nand_ecclayout *layout = &info->ecclayout; | 1606 | if (!elm_node) { |
1764 | 1607 | pr_err("nand: error: ELM DT node not found\n"); | |
1765 | /* build oob layout */ | 1608 | return -ENODEV; |
1766 | steps = mtd->writesize/info->nand.ecc.size; | ||
1767 | layout->eccbytes = steps*info->nand.ecc.bytes; | ||
1768 | |||
1769 | /* do not bother creating special oob layouts for small page devices */ | ||
1770 | if (mtd->oobsize < 64) { | ||
1771 | pr_err("BCH ecc is not supported on small page devices\n"); | ||
1772 | goto fail; | ||
1773 | } | 1609 | } |
1774 | 1610 | pdev = of_find_device_by_node(elm_node); | |
1775 | /* reserve 2 bytes for bad block marker */ | 1611 | /* check whether ELM device is registered */ |
1776 | if (layout->eccbytes+2 > mtd->oobsize) { | 1612 | if (!pdev) { |
1777 | pr_err("no oob layout available for oobsize %d eccbytes %u\n", | 1613 | pr_err("nand: error: ELM device not found\n"); |
1778 | mtd->oobsize, layout->eccbytes); | 1614 | return -ENODEV; |
1779 | goto fail; | ||
1780 | } | 1615 | } |
1781 | 1616 | /* ELM module available, now configure it */ | |
1782 | /* ECC layout compatible with RBL for BCH8 */ | 1617 | info->elm_dev = &pdev->dev; |
1783 | if (info->is_elm_used && (info->nand.ecc.bytes == BCH8_SIZE)) | 1618 | if (elm_config(info->elm_dev, bch_type)) |
1784 | offset = 2; | 1619 | return -ENODEV; |
1785 | else | 1620 | info->is_elm_used = true; |
1786 | offset = mtd->oobsize - layout->eccbytes; | ||
1787 | |||
1788 | /* put ecc bytes at oob tail */ | ||
1789 | for (i = 0; i < layout->eccbytes; i++) | ||
1790 | layout->eccpos[i] = offset + i; | ||
1791 | |||
1792 | if (info->is_elm_used && (info->nand.ecc.bytes == BCH8_SIZE)) | ||
1793 | layout->oobfree[0].offset = 2 + layout->eccbytes * steps; | ||
1794 | else | ||
1795 | layout->oobfree[0].offset = 2; | ||
1796 | |||
1797 | layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes; | ||
1798 | info->nand.ecc.layout = layout; | ||
1799 | |||
1800 | if (!(info->nand.options & NAND_BUSWIDTH_16)) | ||
1801 | info->nand.badblock_pattern = &bb_descrip_flashbased; | ||
1802 | return 0; | 1621 | return 0; |
1803 | fail: | ||
1804 | omap3_free_bch(mtd); | ||
1805 | return -1; | ||
1806 | } | ||
1807 | |||
1808 | #else | ||
1809 | static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt) | ||
1810 | { | ||
1811 | pr_err("CONFIG_MTD_NAND_OMAP_BCH is not enabled\n"); | ||
1812 | return -1; | ||
1813 | } | ||
1814 | static int omap3_init_bch_tail(struct mtd_info *mtd) | ||
1815 | { | ||
1816 | return -1; | ||
1817 | } | ||
1818 | static void omap3_free_bch(struct mtd_info *mtd) | ||
1819 | { | ||
1820 | } | 1622 | } |
1821 | #endif /* CONFIG_MTD_NAND_OMAP_BCH */ | 1623 | #endif /* CONFIG_MTD_NAND_ECC_BCH */ |
1822 | 1624 | ||
1823 | static int omap_nand_probe(struct platform_device *pdev) | 1625 | static int omap_nand_probe(struct platform_device *pdev) |
1824 | { | 1626 | { |
1825 | struct omap_nand_info *info; | 1627 | struct omap_nand_info *info; |
1826 | struct omap_nand_platform_data *pdata; | 1628 | struct omap_nand_platform_data *pdata; |
1629 | struct mtd_info *mtd; | ||
1630 | struct nand_chip *nand_chip; | ||
1631 | struct nand_ecclayout *ecclayout; | ||
1827 | int err; | 1632 | int err; |
1828 | int i, offset; | 1633 | int i; |
1829 | dma_cap_mask_t mask; | 1634 | dma_cap_mask_t mask; |
1830 | unsigned sig; | 1635 | unsigned sig; |
1831 | struct resource *res; | 1636 | struct resource *res; |
1832 | struct mtd_part_parser_data ppdata = {}; | 1637 | struct mtd_part_parser_data ppdata = {}; |
1833 | 1638 | ||
@@ -1837,7 +1642,8 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1837 | return -ENODEV; | 1642 | return -ENODEV; |
1838 | } | 1643 | } |
1839 | 1644 | ||
1840 | info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL); | 1645 | info = devm_kzalloc(&pdev->dev, sizeof(struct omap_nand_info), |
1646 | GFP_KERNEL); | ||
1841 | if (!info) | 1647 | if (!info) |
1842 | return -ENOMEM; | 1648 | return -ENOMEM; |
1843 | 1649 | ||
@@ -1846,47 +1652,45 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1846 | spin_lock_init(&info->controller.lock); | 1652 | spin_lock_init(&info->controller.lock); |
1847 | init_waitqueue_head(&info->controller.wq); | 1653 | init_waitqueue_head(&info->controller.wq); |
1848 | 1654 | ||
1849 | info->pdev = pdev; | 1655 | info->pdev = pdev; |
1850 | |||
1851 | info->gpmc_cs = pdata->cs; | 1656 | info->gpmc_cs = pdata->cs; |
1852 | info->reg = pdata->reg; | 1657 | info->reg = pdata->reg; |
1853 | |||
1854 | info->mtd.priv = &info->nand; | ||
1855 | info->mtd.name = dev_name(&pdev->dev); | ||
1856 | info->mtd.owner = THIS_MODULE; | ||
1857 | |||
1858 | info->nand.options = pdata->devsize; | ||
1859 | info->nand.options |= NAND_SKIP_BBTSCAN; | ||
1860 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | ||
1861 | info->of_node = pdata->of_node; | 1658 | info->of_node = pdata->of_node; |
1862 | #endif | 1659 | mtd = &info->mtd; |
1660 | mtd->priv = &info->nand; | ||
1661 | mtd->name = dev_name(&pdev->dev); | ||
1662 | mtd->owner = THIS_MODULE; | ||
1663 | nand_chip = &info->nand; | ||
1664 | nand_chip->ecc.priv = NULL; | ||
1665 | nand_chip->options |= NAND_SKIP_BBTSCAN; | ||
1863 | 1666 | ||
1864 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1667 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1865 | if (res == NULL) { | 1668 | if (res == NULL) { |
1866 | err = -EINVAL; | 1669 | err = -EINVAL; |
1867 | dev_err(&pdev->dev, "error getting memory resource\n"); | 1670 | dev_err(&pdev->dev, "error getting memory resource\n"); |
1868 | goto out_free_info; | 1671 | goto return_error; |
1869 | } | 1672 | } |
1870 | 1673 | ||
1871 | info->phys_base = res->start; | 1674 | info->phys_base = res->start; |
1872 | info->mem_size = resource_size(res); | 1675 | info->mem_size = resource_size(res); |
1873 | 1676 | ||
1874 | if (!request_mem_region(info->phys_base, info->mem_size, | 1677 | if (!devm_request_mem_region(&pdev->dev, info->phys_base, |
1875 | pdev->dev.driver->name)) { | 1678 | info->mem_size, pdev->dev.driver->name)) { |
1876 | err = -EBUSY; | 1679 | err = -EBUSY; |
1877 | goto out_free_info; | 1680 | goto return_error; |
1878 | } | 1681 | } |
1879 | 1682 | ||
1880 | info->nand.IO_ADDR_R = ioremap(info->phys_base, info->mem_size); | 1683 | nand_chip->IO_ADDR_R = devm_ioremap(&pdev->dev, info->phys_base, |
1881 | if (!info->nand.IO_ADDR_R) { | 1684 | info->mem_size); |
1685 | if (!nand_chip->IO_ADDR_R) { | ||
1882 | err = -ENOMEM; | 1686 | err = -ENOMEM; |
1883 | goto out_release_mem_region; | 1687 | goto return_error; |
1884 | } | 1688 | } |
1885 | 1689 | ||
1886 | info->nand.controller = &info->controller; | 1690 | nand_chip->controller = &info->controller; |
1887 | 1691 | ||
1888 | info->nand.IO_ADDR_W = info->nand.IO_ADDR_R; | 1692 | nand_chip->IO_ADDR_W = nand_chip->IO_ADDR_R; |
1889 | info->nand.cmd_ctrl = omap_hwcontrol; | 1693 | nand_chip->cmd_ctrl = omap_hwcontrol; |
1890 | 1694 | ||
1891 | /* | 1695 | /* |
1892 | * If RDY/BSY line is connected to OMAP then use the omap ready | 1696 | * If RDY/BSY line is connected to OMAP then use the omap ready |
@@ -1896,26 +1700,42 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1896 | * device and read status register until you get a failure or success | 1700 | * device and read status register until you get a failure or success |
1897 | */ | 1701 | */ |
1898 | if (pdata->dev_ready) { | 1702 | if (pdata->dev_ready) { |
1899 | info->nand.dev_ready = omap_dev_ready; | 1703 | nand_chip->dev_ready = omap_dev_ready; |
1900 | info->nand.chip_delay = 0; | 1704 | nand_chip->chip_delay = 0; |
1901 | } else { | 1705 | } else { |
1902 | info->nand.waitfunc = omap_wait; | 1706 | nand_chip->waitfunc = omap_wait; |
1903 | info->nand.chip_delay = 50; | 1707 | nand_chip->chip_delay = 50; |
1904 | } | 1708 | } |
1905 | 1709 | ||
1710 | /* scan NAND device connected to chip controller */ | ||
1711 | nand_chip->options |= pdata->devsize & NAND_BUSWIDTH_16; | ||
1712 | if (nand_scan_ident(mtd, 1, NULL)) { | ||
1713 | pr_err("nand device scan failed, may be bus-width mismatch\n"); | ||
1714 | err = -ENXIO; | ||
1715 | goto return_error; | ||
1716 | } | ||
1717 | |||
1718 | /* check for small page devices */ | ||
1719 | if ((mtd->oobsize < 64) && (pdata->ecc_opt != OMAP_ECC_HAM1_CODE_HW)) { | ||
1720 | pr_err("small page devices are not supported\n"); | ||
1721 | err = -EINVAL; | ||
1722 | goto return_error; | ||
1723 | } | ||
1724 | |||
1725 | /* re-populate low-level callbacks based on xfer modes */ | ||
1906 | switch (pdata->xfer_type) { | 1726 | switch (pdata->xfer_type) { |
1907 | case NAND_OMAP_PREFETCH_POLLED: | 1727 | case NAND_OMAP_PREFETCH_POLLED: |
1908 | info->nand.read_buf = omap_read_buf_pref; | 1728 | nand_chip->read_buf = omap_read_buf_pref; |
1909 | info->nand.write_buf = omap_write_buf_pref; | 1729 | nand_chip->write_buf = omap_write_buf_pref; |
1910 | break; | 1730 | break; |
1911 | 1731 | ||
1912 | case NAND_OMAP_POLLED: | 1732 | case NAND_OMAP_POLLED: |
1913 | if (info->nand.options & NAND_BUSWIDTH_16) { | 1733 | if (nand_chip->options & NAND_BUSWIDTH_16) { |
1914 | info->nand.read_buf = omap_read_buf16; | 1734 | nand_chip->read_buf = omap_read_buf16; |
1915 | info->nand.write_buf = omap_write_buf16; | 1735 | nand_chip->write_buf = omap_write_buf16; |
1916 | } else { | 1736 | } else { |
1917 | info->nand.read_buf = omap_read_buf8; | 1737 | nand_chip->read_buf = omap_read_buf8; |
1918 | info->nand.write_buf = omap_write_buf8; | 1738 | nand_chip->write_buf = omap_write_buf8; |
1919 | } | 1739 | } |
1920 | break; | 1740 | break; |
1921 | 1741 | ||
@@ -1927,7 +1747,7 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1927 | if (!info->dma) { | 1747 | if (!info->dma) { |
1928 | dev_err(&pdev->dev, "DMA engine request failed\n"); | 1748 | dev_err(&pdev->dev, "DMA engine request failed\n"); |
1929 | err = -ENXIO; | 1749 | err = -ENXIO; |
1930 | goto out_release_mem_region; | 1750 | goto return_error; |
1931 | } else { | 1751 | } else { |
1932 | struct dma_slave_config cfg; | 1752 | struct dma_slave_config cfg; |
1933 | 1753 | ||
@@ -1942,10 +1762,10 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1942 | if (err) { | 1762 | if (err) { |
1943 | dev_err(&pdev->dev, "DMA engine slave config failed: %d\n", | 1763 | dev_err(&pdev->dev, "DMA engine slave config failed: %d\n", |
1944 | err); | 1764 | err); |
1945 | goto out_release_mem_region; | 1765 | goto return_error; |
1946 | } | 1766 | } |
1947 | info->nand.read_buf = omap_read_buf_dma_pref; | 1767 | nand_chip->read_buf = omap_read_buf_dma_pref; |
1948 | info->nand.write_buf = omap_write_buf_dma_pref; | 1768 | nand_chip->write_buf = omap_write_buf_dma_pref; |
1949 | } | 1769 | } |
1950 | break; | 1770 | break; |
1951 | 1771 | ||
@@ -1954,34 +1774,36 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1954 | if (info->gpmc_irq_fifo <= 0) { | 1774 | if (info->gpmc_irq_fifo <= 0) { |
1955 | dev_err(&pdev->dev, "error getting fifo irq\n"); | 1775 | dev_err(&pdev->dev, "error getting fifo irq\n"); |
1956 | err = -ENODEV; | 1776 | err = -ENODEV; |
1957 | goto out_release_mem_region; | 1777 | goto return_error; |
1958 | } | 1778 | } |
1959 | err = request_irq(info->gpmc_irq_fifo, omap_nand_irq, | 1779 | err = devm_request_irq(&pdev->dev, info->gpmc_irq_fifo, |
1960 | IRQF_SHARED, "gpmc-nand-fifo", info); | 1780 | omap_nand_irq, IRQF_SHARED, |
1781 | "gpmc-nand-fifo", info); | ||
1961 | if (err) { | 1782 | if (err) { |
1962 | dev_err(&pdev->dev, "requesting irq(%d) error:%d", | 1783 | dev_err(&pdev->dev, "requesting irq(%d) error:%d", |
1963 | info->gpmc_irq_fifo, err); | 1784 | info->gpmc_irq_fifo, err); |
1964 | info->gpmc_irq_fifo = 0; | 1785 | info->gpmc_irq_fifo = 0; |
1965 | goto out_release_mem_region; | 1786 | goto return_error; |
1966 | } | 1787 | } |
1967 | 1788 | ||
1968 | info->gpmc_irq_count = platform_get_irq(pdev, 1); | 1789 | info->gpmc_irq_count = platform_get_irq(pdev, 1); |
1969 | if (info->gpmc_irq_count <= 0) { | 1790 | if (info->gpmc_irq_count <= 0) { |
1970 | dev_err(&pdev->dev, "error getting count irq\n"); | 1791 | dev_err(&pdev->dev, "error getting count irq\n"); |
1971 | err = -ENODEV; | 1792 | err = -ENODEV; |
1972 | goto out_release_mem_region; | 1793 | goto return_error; |
1973 | } | 1794 | } |
1974 | err = request_irq(info->gpmc_irq_count, omap_nand_irq, | 1795 | err = devm_request_irq(&pdev->dev, info->gpmc_irq_count, |
1975 | IRQF_SHARED, "gpmc-nand-count", info); | 1796 | omap_nand_irq, IRQF_SHARED, |
1797 | "gpmc-nand-count", info); | ||
1976 | if (err) { | 1798 | if (err) { |
1977 | dev_err(&pdev->dev, "requesting irq(%d) error:%d", | 1799 | dev_err(&pdev->dev, "requesting irq(%d) error:%d", |
1978 | info->gpmc_irq_count, err); | 1800 | info->gpmc_irq_count, err); |
1979 | info->gpmc_irq_count = 0; | 1801 | info->gpmc_irq_count = 0; |
1980 | goto out_release_mem_region; | 1802 | goto return_error; |
1981 | } | 1803 | } |
1982 | 1804 | ||
1983 | info->nand.read_buf = omap_read_buf_irq_pref; | 1805 | nand_chip->read_buf = omap_read_buf_irq_pref; |
1984 | info->nand.write_buf = omap_write_buf_irq_pref; | 1806 | nand_chip->write_buf = omap_write_buf_irq_pref; |
1985 | 1807 | ||
1986 | break; | 1808 | break; |
1987 | 1809 | ||
@@ -1989,117 +1811,223 @@ static int omap_nand_probe(struct platform_device *pdev) | |||
1989 | dev_err(&pdev->dev, | 1811 | dev_err(&pdev->dev, |
1990 | "xfer_type(%d) not supported!\n", pdata->xfer_type); | 1812 | "xfer_type(%d) not supported!\n", pdata->xfer_type); |
1991 | err = -EINVAL; | 1813 | err = -EINVAL; |
1992 | goto out_release_mem_region; | 1814 | goto return_error; |
1993 | } | 1815 | } |
1994 | 1816 | ||
1995 | /* select the ecc type */ | 1817 | /* populate MTD interface based on ECC scheme */ |
1996 | if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_DEFAULT) | 1818 | nand_chip->ecc.layout = &omap_oobinfo; |
1997 | info->nand.ecc.mode = NAND_ECC_SOFT; | 1819 | ecclayout = &omap_oobinfo; |
1998 | else if ((pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW) || | 1820 | switch (pdata->ecc_opt) { |
1999 | (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)) { | 1821 | case OMAP_ECC_HAM1_CODE_HW: |
2000 | info->nand.ecc.bytes = 3; | 1822 | pr_info("nand: using OMAP_ECC_HAM1_CODE_HW\n"); |
2001 | info->nand.ecc.size = 512; | 1823 | nand_chip->ecc.mode = NAND_ECC_HW; |
2002 | info->nand.ecc.strength = 1; | 1824 | nand_chip->ecc.bytes = 3; |
2003 | info->nand.ecc.calculate = omap_calculate_ecc; | 1825 | nand_chip->ecc.size = 512; |
2004 | info->nand.ecc.hwctl = omap_enable_hwecc; | 1826 | nand_chip->ecc.strength = 1; |
2005 | info->nand.ecc.correct = omap_correct_data; | 1827 | nand_chip->ecc.calculate = omap_calculate_ecc; |
2006 | info->nand.ecc.mode = NAND_ECC_HW; | 1828 | nand_chip->ecc.hwctl = omap_enable_hwecc; |
2007 | } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) || | 1829 | nand_chip->ecc.correct = omap_correct_data; |
2008 | (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) { | 1830 | /* define ECC layout */ |
2009 | err = omap3_init_bch(&info->mtd, pdata->ecc_opt); | 1831 | ecclayout->eccbytes = nand_chip->ecc.bytes * |
2010 | if (err) { | 1832 | (mtd->writesize / |
1833 | nand_chip->ecc.size); | ||
1834 | if (nand_chip->options & NAND_BUSWIDTH_16) | ||
1835 | ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; | ||
1836 | else | ||
1837 | ecclayout->eccpos[0] = 1; | ||
1838 | ecclayout->oobfree->offset = ecclayout->eccpos[0] + | ||
1839 | ecclayout->eccbytes; | ||
1840 | break; | ||
1841 | |||
1842 | case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW: | ||
1843 | #ifdef CONFIG_MTD_NAND_ECC_BCH | ||
1844 | pr_info("nand: using OMAP_ECC_BCH4_CODE_HW_DETECTION_SW\n"); | ||
1845 | nand_chip->ecc.mode = NAND_ECC_HW; | ||
1846 | nand_chip->ecc.size = 512; | ||
1847 | nand_chip->ecc.bytes = 7; | ||
1848 | nand_chip->ecc.strength = 4; | ||
1849 | nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; | ||
1850 | nand_chip->ecc.correct = nand_bch_correct_data; | ||
1851 | nand_chip->ecc.calculate = omap3_calculate_ecc_bch4; | ||
1852 | /* define ECC layout */ | ||
1853 | ecclayout->eccbytes = nand_chip->ecc.bytes * | ||
1854 | (mtd->writesize / | ||
1855 | nand_chip->ecc.size); | ||
1856 | ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; | ||
1857 | ecclayout->oobfree->offset = ecclayout->eccpos[0] + | ||
1858 | ecclayout->eccbytes; | ||
1859 | /* software bch library is used for locating errors */ | ||
1860 | nand_chip->ecc.priv = nand_bch_init(mtd, | ||
1861 | nand_chip->ecc.size, | ||
1862 | nand_chip->ecc.bytes, | ||
1863 | &nand_chip->ecc.layout); | ||
1864 | if (!nand_chip->ecc.priv) { | ||
1865 | pr_err("nand: error: unable to use s/w BCH library\n"); | ||
2011 | err = -EINVAL; | 1866 | err = -EINVAL; |
2012 | goto out_release_mem_region; | ||
2013 | } | 1867 | } |
2014 | } | 1868 | break; |
1869 | #else | ||
1870 | pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n"); | ||
1871 | err = -EINVAL; | ||
1872 | goto return_error; | ||
1873 | #endif | ||
2015 | 1874 | ||
2016 | /* DIP switches on some boards change between 8 and 16 bit | 1875 | case OMAP_ECC_BCH4_CODE_HW: |
2017 | * bus widths for flash. Try the other width if the first try fails. | 1876 | #ifdef CONFIG_MTD_NAND_OMAP_BCH |
2018 | */ | 1877 | pr_info("nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme\n"); |
2019 | if (nand_scan_ident(&info->mtd, 1, NULL)) { | 1878 | nand_chip->ecc.mode = NAND_ECC_HW; |
2020 | info->nand.options ^= NAND_BUSWIDTH_16; | 1879 | nand_chip->ecc.size = 512; |
2021 | if (nand_scan_ident(&info->mtd, 1, NULL)) { | 1880 | /* 14th bit is kept reserved for ROM-code compatibility */ |
2022 | err = -ENXIO; | 1881 | nand_chip->ecc.bytes = 7 + 1; |
2023 | goto out_release_mem_region; | 1882 | nand_chip->ecc.strength = 4; |
1883 | nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; | ||
1884 | nand_chip->ecc.correct = omap_elm_correct_data; | ||
1885 | nand_chip->ecc.calculate = omap3_calculate_ecc_bch; | ||
1886 | nand_chip->ecc.read_page = omap_read_page_bch; | ||
1887 | nand_chip->ecc.write_page = omap_write_page_bch; | ||
1888 | /* define ECC layout */ | ||
1889 | ecclayout->eccbytes = nand_chip->ecc.bytes * | ||
1890 | (mtd->writesize / | ||
1891 | nand_chip->ecc.size); | ||
1892 | ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; | ||
1893 | ecclayout->oobfree->offset = ecclayout->eccpos[0] + | ||
1894 | ecclayout->eccbytes; | ||
1895 | /* This ECC scheme requires ELM H/W block */ | ||
1896 | if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) { | ||
1897 | pr_err("nand: error: could not initialize ELM\n"); | ||
1898 | err = -ENODEV; | ||
1899 | goto return_error; | ||
2024 | } | 1900 | } |
2025 | } | 1901 | break; |
2026 | 1902 | #else | |
2027 | /* rom code layout */ | 1903 | pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); |
2028 | if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE) { | 1904 | err = -EINVAL; |
1905 | goto return_error; | ||
1906 | #endif | ||
2029 | 1907 | ||
2030 | if (info->nand.options & NAND_BUSWIDTH_16) | 1908 | case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW: |
2031 | offset = 2; | 1909 | #ifdef CONFIG_MTD_NAND_ECC_BCH |
2032 | else { | 1910 | pr_info("nand: using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n"); |
2033 | offset = 1; | 1911 | nand_chip->ecc.mode = NAND_ECC_HW; |
2034 | info->nand.badblock_pattern = &bb_descrip_flashbased; | 1912 | nand_chip->ecc.size = 512; |
2035 | } | 1913 | nand_chip->ecc.bytes = 13; |
2036 | omap_oobinfo.eccbytes = 3 * (info->mtd.oobsize/16); | 1914 | nand_chip->ecc.strength = 8; |
2037 | for (i = 0; i < omap_oobinfo.eccbytes; i++) | 1915 | nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; |
2038 | omap_oobinfo.eccpos[i] = i+offset; | 1916 | nand_chip->ecc.correct = nand_bch_correct_data; |
2039 | 1917 | nand_chip->ecc.calculate = omap3_calculate_ecc_bch8; | |
2040 | omap_oobinfo.oobfree->offset = offset + omap_oobinfo.eccbytes; | 1918 | /* define ECC layout */ |
2041 | omap_oobinfo.oobfree->length = info->mtd.oobsize - | 1919 | ecclayout->eccbytes = nand_chip->ecc.bytes * |
2042 | (offset + omap_oobinfo.eccbytes); | 1920 | (mtd->writesize / |
2043 | 1921 | nand_chip->ecc.size); | |
2044 | info->nand.ecc.layout = &omap_oobinfo; | 1922 | ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; |
2045 | } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) || | 1923 | ecclayout->oobfree->offset = ecclayout->eccpos[0] + |
2046 | (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) { | 1924 | ecclayout->eccbytes; |
2047 | /* build OOB layout for BCH ECC correction */ | 1925 | /* software bch library is used for locating errors */ |
2048 | err = omap3_init_bch_tail(&info->mtd); | 1926 | nand_chip->ecc.priv = nand_bch_init(mtd, |
2049 | if (err) { | 1927 | nand_chip->ecc.size, |
1928 | nand_chip->ecc.bytes, | ||
1929 | &nand_chip->ecc.layout); | ||
1930 | if (!nand_chip->ecc.priv) { | ||
1931 | pr_err("nand: error: unable to use s/w BCH library\n"); | ||
2050 | err = -EINVAL; | 1932 | err = -EINVAL; |
2051 | goto out_release_mem_region; | 1933 | goto return_error; |
1934 | } | ||
1935 | break; | ||
1936 | #else | ||
1937 | pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n"); | ||
1938 | err = -EINVAL; | ||
1939 | goto return_error; | ||
1940 | #endif | ||
1941 | |||
1942 | case OMAP_ECC_BCH8_CODE_HW: | ||
1943 | #ifdef CONFIG_MTD_NAND_OMAP_BCH | ||
1944 | pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n"); | ||
1945 | nand_chip->ecc.mode = NAND_ECC_HW; | ||
1946 | nand_chip->ecc.size = 512; | ||
1947 | /* 14th bit is kept reserved for ROM-code compatibility */ | ||
1948 | nand_chip->ecc.bytes = 13 + 1; | ||
1949 | nand_chip->ecc.strength = 8; | ||
1950 | nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; | ||
1951 | nand_chip->ecc.correct = omap_elm_correct_data; | ||
1952 | nand_chip->ecc.calculate = omap3_calculate_ecc_bch; | ||
1953 | nand_chip->ecc.read_page = omap_read_page_bch; | ||
1954 | nand_chip->ecc.write_page = omap_write_page_bch; | ||
1955 | /* This ECC scheme requires ELM H/W block */ | ||
1956 | err = is_elm_present(info, pdata->elm_of_node, BCH8_ECC); | ||
1957 | if (err < 0) { | ||
1958 | pr_err("nand: error: could not initialize ELM\n"); | ||
1959 | goto return_error; | ||
2052 | } | 1960 | } |
1961 | /* define ECC layout */ | ||
1962 | ecclayout->eccbytes = nand_chip->ecc.bytes * | ||
1963 | (mtd->writesize / | ||
1964 | nand_chip->ecc.size); | ||
1965 | ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; | ||
1966 | ecclayout->oobfree->offset = ecclayout->eccpos[0] + | ||
1967 | ecclayout->eccbytes; | ||
1968 | break; | ||
1969 | #else | ||
1970 | pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); | ||
1971 | err = -EINVAL; | ||
1972 | goto return_error; | ||
1973 | #endif | ||
1974 | |||
1975 | default: | ||
1976 | pr_err("nand: error: invalid or unsupported ECC scheme\n"); | ||
1977 | err = -EINVAL; | ||
1978 | goto return_error; | ||
1979 | } | ||
1980 | |||
1981 | /* populate remaining ECC layout data */ | ||
1982 | ecclayout->oobfree->length = mtd->oobsize - (BADBLOCK_MARKER_LENGTH + | ||
1983 | ecclayout->eccbytes); | ||
1984 | for (i = 1; i < ecclayout->eccbytes; i++) | ||
1985 | ecclayout->eccpos[i] = ecclayout->eccpos[0] + i; | ||
1986 | /* check if NAND device's OOB is enough to store ECC signatures */ | ||
1987 | if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) { | ||
1988 | pr_err("not enough OOB bytes required = %d, available=%d\n", | ||
1989 | ecclayout->eccbytes, mtd->oobsize); | ||
1990 | err = -EINVAL; | ||
1991 | goto return_error; | ||
2053 | } | 1992 | } |
2054 | 1993 | ||
2055 | /* second phase scan */ | 1994 | /* second phase scan */ |
2056 | if (nand_scan_tail(&info->mtd)) { | 1995 | if (nand_scan_tail(mtd)) { |
2057 | err = -ENXIO; | 1996 | err = -ENXIO; |
2058 | goto out_release_mem_region; | 1997 | goto return_error; |
2059 | } | 1998 | } |
2060 | 1999 | ||
2061 | ppdata.of_node = pdata->of_node; | 2000 | ppdata.of_node = pdata->of_node; |
2062 | mtd_device_parse_register(&info->mtd, NULL, &ppdata, pdata->parts, | 2001 | mtd_device_parse_register(mtd, NULL, &ppdata, pdata->parts, |
2063 | pdata->nr_parts); | 2002 | pdata->nr_parts); |
2064 | 2003 | ||
2065 | platform_set_drvdata(pdev, &info->mtd); | 2004 | platform_set_drvdata(pdev, mtd); |
2066 | 2005 | ||
2067 | return 0; | 2006 | return 0; |
2068 | 2007 | ||
2069 | out_release_mem_region: | 2008 | return_error: |
2070 | if (info->dma) | 2009 | if (info->dma) |
2071 | dma_release_channel(info->dma); | 2010 | dma_release_channel(info->dma); |
2072 | if (info->gpmc_irq_count > 0) | 2011 | if (nand_chip->ecc.priv) { |
2073 | free_irq(info->gpmc_irq_count, info); | 2012 | nand_bch_free(nand_chip->ecc.priv); |
2074 | if (info->gpmc_irq_fifo > 0) | 2013 | nand_chip->ecc.priv = NULL; |
2075 | free_irq(info->gpmc_irq_fifo, info); | 2014 | } |
2076 | release_mem_region(info->phys_base, info->mem_size); | ||
2077 | out_free_info: | ||
2078 | kfree(info); | ||
2079 | |||
2080 | return err; | 2015 | return err; |
2081 | } | 2016 | } |
2082 | 2017 | ||
2083 | static int omap_nand_remove(struct platform_device *pdev) | 2018 | static int omap_nand_remove(struct platform_device *pdev) |
2084 | { | 2019 | { |
2085 | struct mtd_info *mtd = platform_get_drvdata(pdev); | 2020 | struct mtd_info *mtd = platform_get_drvdata(pdev); |
2021 | struct nand_chip *nand_chip = mtd->priv; | ||
2086 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, | 2022 | struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, |
2087 | mtd); | 2023 | mtd); |
2088 | omap3_free_bch(&info->mtd); | 2024 | if (nand_chip->ecc.priv) { |
2089 | 2025 | nand_bch_free(nand_chip->ecc.priv); | |
2026 | nand_chip->ecc.priv = NULL; | ||
2027 | } | ||
2090 | if (info->dma) | 2028 | if (info->dma) |
2091 | dma_release_channel(info->dma); | 2029 | dma_release_channel(info->dma); |
2092 | 2030 | nand_release(mtd); | |
2093 | if (info->gpmc_irq_count > 0) | ||
2094 | free_irq(info->gpmc_irq_count, info); | ||
2095 | if (info->gpmc_irq_fifo > 0) | ||
2096 | free_irq(info->gpmc_irq_fifo, info); | ||
2097 | |||
2098 | /* Release NAND device, its internal structures and partitions */ | ||
2099 | nand_release(&info->mtd); | ||
2100 | iounmap(info->nand.IO_ADDR_R); | ||
2101 | release_mem_region(info->phys_base, info->mem_size); | ||
2102 | kfree(info); | ||
2103 | return 0; | 2031 | return 0; |
2104 | } | 2032 | } |
2105 | 2033 | ||
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index c28d4e29af1a..4cabdc9fda90 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c | |||
@@ -39,6 +39,13 @@ | |||
39 | #define NAND_STOP_DELAY (2 * HZ/50) | 39 | #define NAND_STOP_DELAY (2 * HZ/50) |
40 | #define PAGE_CHUNK_SIZE (2048) | 40 | #define PAGE_CHUNK_SIZE (2048) |
41 | 41 | ||
42 | /* | ||
43 | * Define a buffer size for the initial command that detects the flash device: | ||
44 | * STATUS, READID and PARAM. The largest of these is the PARAM command, | ||
45 | * needing 256 bytes. | ||
46 | */ | ||
47 | #define INIT_BUFFER_SIZE 256 | ||
48 | |||
42 | /* registers and bit definitions */ | 49 | /* registers and bit definitions */ |
43 | #define NDCR (0x00) /* Control register */ | 50 | #define NDCR (0x00) /* Control register */ |
44 | #define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */ | 51 | #define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */ |
@@ -164,6 +171,7 @@ struct pxa3xx_nand_info { | |||
164 | 171 | ||
165 | unsigned int buf_start; | 172 | unsigned int buf_start; |
166 | unsigned int buf_count; | 173 | unsigned int buf_count; |
174 | unsigned int buf_size; | ||
167 | 175 | ||
168 | /* DMA information */ | 176 | /* DMA information */ |
169 | int drcmr_dat; | 177 | int drcmr_dat; |
@@ -540,7 +548,6 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, | |||
540 | info->oob_size = 0; | 548 | info->oob_size = 0; |
541 | info->use_ecc = 0; | 549 | info->use_ecc = 0; |
542 | info->use_spare = 1; | 550 | info->use_spare = 1; |
543 | info->use_dma = (use_dma) ? 1 : 0; | ||
544 | info->is_ready = 0; | 551 | info->is_ready = 0; |
545 | info->retcode = ERR_NONE; | 552 | info->retcode = ERR_NONE; |
546 | if (info->cs != 0) | 553 | if (info->cs != 0) |
@@ -912,26 +919,20 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) | |||
912 | return 0; | 919 | return 0; |
913 | } | 920 | } |
914 | 921 | ||
915 | /* the maximum possible buffer size for large page with OOB data | ||
916 | * is: 2048 + 64 = 2112 bytes, allocate a page here for both the | ||
917 | * data buffer and the DMA descriptor | ||
918 | */ | ||
919 | #define MAX_BUFF_SIZE PAGE_SIZE | ||
920 | |||
921 | #ifdef ARCH_HAS_DMA | 922 | #ifdef ARCH_HAS_DMA |
922 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) | 923 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) |
923 | { | 924 | { |
924 | struct platform_device *pdev = info->pdev; | 925 | struct platform_device *pdev = info->pdev; |
925 | int data_desc_offset = MAX_BUFF_SIZE - sizeof(struct pxa_dma_desc); | 926 | int data_desc_offset = info->buf_size - sizeof(struct pxa_dma_desc); |
926 | 927 | ||
927 | if (use_dma == 0) { | 928 | if (use_dma == 0) { |
928 | info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL); | 929 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); |
929 | if (info->data_buff == NULL) | 930 | if (info->data_buff == NULL) |
930 | return -ENOMEM; | 931 | return -ENOMEM; |
931 | return 0; | 932 | return 0; |
932 | } | 933 | } |
933 | 934 | ||
934 | info->data_buff = dma_alloc_coherent(&pdev->dev, MAX_BUFF_SIZE, | 935 | info->data_buff = dma_alloc_coherent(&pdev->dev, info->buf_size, |
935 | &info->data_buff_phys, GFP_KERNEL); | 936 | &info->data_buff_phys, GFP_KERNEL); |
936 | if (info->data_buff == NULL) { | 937 | if (info->data_buff == NULL) { |
937 | dev_err(&pdev->dev, "failed to allocate dma buffer\n"); | 938 | dev_err(&pdev->dev, "failed to allocate dma buffer\n"); |
@@ -945,11 +946,16 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) | |||
945 | pxa3xx_nand_data_dma_irq, info); | 946 | pxa3xx_nand_data_dma_irq, info); |
946 | if (info->data_dma_ch < 0) { | 947 | if (info->data_dma_ch < 0) { |
947 | dev_err(&pdev->dev, "failed to request data dma\n"); | 948 | dev_err(&pdev->dev, "failed to request data dma\n"); |
948 | dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE, | 949 | dma_free_coherent(&pdev->dev, info->buf_size, |
949 | info->data_buff, info->data_buff_phys); | 950 | info->data_buff, info->data_buff_phys); |
950 | return info->data_dma_ch; | 951 | return info->data_dma_ch; |
951 | } | 952 | } |
952 | 953 | ||
954 | /* | ||
955 | * Now that DMA buffers are allocated we turn on | ||
956 | * DMA proper for I/O operations. | ||
957 | */ | ||
958 | info->use_dma = 1; | ||
953 | return 0; | 959 | return 0; |
954 | } | 960 | } |
955 | 961 | ||
@@ -958,7 +964,7 @@ static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) | |||
958 | struct platform_device *pdev = info->pdev; | 964 | struct platform_device *pdev = info->pdev; |
959 | if (use_dma) { | 965 | if (use_dma) { |
960 | pxa_free_dma(info->data_dma_ch); | 966 | pxa_free_dma(info->data_dma_ch); |
961 | dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE, | 967 | dma_free_coherent(&pdev->dev, info->buf_size, |
962 | info->data_buff, info->data_buff_phys); | 968 | info->data_buff, info->data_buff_phys); |
963 | } else { | 969 | } else { |
964 | kfree(info->data_buff); | 970 | kfree(info->data_buff); |
@@ -967,7 +973,7 @@ static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) | |||
967 | #else | 973 | #else |
968 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) | 974 | static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) |
969 | { | 975 | { |
970 | info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL); | 976 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); |
971 | if (info->data_buff == NULL) | 977 | if (info->data_buff == NULL) |
972 | return -ENOMEM; | 978 | return -ENOMEM; |
973 | return 0; | 979 | return 0; |
@@ -1081,7 +1087,16 @@ KEEP_CONFIG: | |||
1081 | else | 1087 | else |
1082 | host->col_addr_cycles = 1; | 1088 | host->col_addr_cycles = 1; |
1083 | 1089 | ||
1090 | /* release the initial buffer */ | ||
1091 | kfree(info->data_buff); | ||
1092 | |||
1093 | /* allocate the real data + oob buffer */ | ||
1094 | info->buf_size = mtd->writesize + mtd->oobsize; | ||
1095 | ret = pxa3xx_nand_init_buff(info); | ||
1096 | if (ret) | ||
1097 | return ret; | ||
1084 | info->oob_buff = info->data_buff + mtd->writesize; | 1098 | info->oob_buff = info->data_buff + mtd->writesize; |
1099 | |||
1085 | if ((mtd->size >> chip->page_shift) > 65536) | 1100 | if ((mtd->size >> chip->page_shift) > 65536) |
1086 | host->row_addr_cycles = 3; | 1101 | host->row_addr_cycles = 3; |
1087 | else | 1102 | else |
@@ -1187,15 +1202,18 @@ static int alloc_nand_resource(struct platform_device *pdev) | |||
1187 | } | 1202 | } |
1188 | info->mmio_phys = r->start; | 1203 | info->mmio_phys = r->start; |
1189 | 1204 | ||
1190 | ret = pxa3xx_nand_init_buff(info); | 1205 | /* Allocate a buffer to allow flash detection */ |
1191 | if (ret) | 1206 | info->buf_size = INIT_BUFFER_SIZE; |
1207 | info->data_buff = kmalloc(info->buf_size, GFP_KERNEL); | ||
1208 | if (info->data_buff == NULL) { | ||
1209 | ret = -ENOMEM; | ||
1192 | goto fail_disable_clk; | 1210 | goto fail_disable_clk; |
1211 | } | ||
1193 | 1212 | ||
1194 | /* initialize all interrupts to be disabled */ | 1213 | /* initialize all interrupts to be disabled */ |
1195 | disable_int(info, NDSR_MASK); | 1214 | disable_int(info, NDSR_MASK); |
1196 | 1215 | ||
1197 | ret = request_irq(irq, pxa3xx_nand_irq, IRQF_DISABLED, | 1216 | ret = request_irq(irq, pxa3xx_nand_irq, 0, pdev->name, info); |
1198 | pdev->name, info); | ||
1199 | if (ret < 0) { | 1217 | if (ret < 0) { |
1200 | dev_err(&pdev->dev, "failed to request IRQ\n"); | 1218 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
1201 | goto fail_free_buf; | 1219 | goto fail_free_buf; |
@@ -1207,7 +1225,7 @@ static int alloc_nand_resource(struct platform_device *pdev) | |||
1207 | 1225 | ||
1208 | fail_free_buf: | 1226 | fail_free_buf: |
1209 | free_irq(irq, info); | 1227 | free_irq(irq, info); |
1210 | pxa3xx_nand_free_buff(info); | 1228 | kfree(info->data_buff); |
1211 | fail_disable_clk: | 1229 | fail_disable_clk: |
1212 | clk_disable_unprepare(info->clk); | 1230 | clk_disable_unprepare(info->clk); |
1213 | return ret; | 1231 | return ret; |
@@ -1412,7 +1430,7 @@ static int pxa3xx_nand_resume(struct platform_device *pdev) | |||
1412 | static struct platform_driver pxa3xx_nand_driver = { | 1430 | static struct platform_driver pxa3xx_nand_driver = { |
1413 | .driver = { | 1431 | .driver = { |
1414 | .name = "pxa3xx-nand", | 1432 | .name = "pxa3xx-nand", |
1415 | .of_match_table = of_match_ptr(pxa3xx_nand_dt_ids), | 1433 | .of_match_table = pxa3xx_nand_dt_ids, |
1416 | }, | 1434 | }, |
1417 | .probe = pxa3xx_nand_probe, | 1435 | .probe = pxa3xx_nand_probe, |
1418 | .remove = pxa3xx_nand_remove, | 1436 | .remove = pxa3xx_nand_remove, |
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c index 49bd9155cb19..fe8058a45054 100644 --- a/drivers/mtd/nand/socrates_nand.c +++ b/drivers/mtd/nand/socrates_nand.c | |||
@@ -150,17 +150,13 @@ static int socrates_nand_probe(struct platform_device *ofdev) | |||
150 | struct mtd_part_parser_data ppdata; | 150 | struct mtd_part_parser_data ppdata; |
151 | 151 | ||
152 | /* Allocate memory for the device structure (and zero it) */ | 152 | /* Allocate memory for the device structure (and zero it) */ |
153 | host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL); | 153 | host = devm_kzalloc(&ofdev->dev, sizeof(*host), GFP_KERNEL); |
154 | if (!host) { | 154 | if (!host) |
155 | printk(KERN_ERR | ||
156 | "socrates_nand: failed to allocate device structure.\n"); | ||
157 | return -ENOMEM; | 155 | return -ENOMEM; |
158 | } | ||
159 | 156 | ||
160 | host->io_base = of_iomap(ofdev->dev.of_node, 0); | 157 | host->io_base = of_iomap(ofdev->dev.of_node, 0); |
161 | if (host->io_base == NULL) { | 158 | if (host->io_base == NULL) { |
162 | printk(KERN_ERR "socrates_nand: ioremap failed\n"); | 159 | dev_err(&ofdev->dev, "ioremap failed\n"); |
163 | kfree(host); | ||
164 | return -EIO; | 160 | return -EIO; |
165 | } | 161 | } |
166 | 162 | ||
@@ -212,9 +208,7 @@ static int socrates_nand_probe(struct platform_device *ofdev) | |||
212 | nand_release(mtd); | 208 | nand_release(mtd); |
213 | 209 | ||
214 | out: | 210 | out: |
215 | dev_set_drvdata(&ofdev->dev, NULL); | ||
216 | iounmap(host->io_base); | 211 | iounmap(host->io_base); |
217 | kfree(host); | ||
218 | return res; | 212 | return res; |
219 | } | 213 | } |
220 | 214 | ||
@@ -228,9 +222,7 @@ static int socrates_nand_remove(struct platform_device *ofdev) | |||
228 | 222 | ||
229 | nand_release(mtd); | 223 | nand_release(mtd); |
230 | 224 | ||
231 | dev_set_drvdata(&ofdev->dev, NULL); | ||
232 | iounmap(host->io_base); | 225 | iounmap(host->io_base); |
233 | kfree(host); | ||
234 | 226 | ||
235 | return 0; | 227 | return 0; |
236 | } | 228 | } |
diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c index 396530d87ecf..a3747c914d57 100644 --- a/drivers/mtd/nand/tmio_nand.c +++ b/drivers/mtd/nand/tmio_nand.c | |||
@@ -428,8 +428,7 @@ static int tmio_probe(struct platform_device *dev) | |||
428 | /* 15 us command delay time */ | 428 | /* 15 us command delay time */ |
429 | nand_chip->chip_delay = 15; | 429 | nand_chip->chip_delay = 15; |
430 | 430 | ||
431 | retval = request_irq(irq, &tmio_irq, | 431 | retval = request_irq(irq, &tmio_irq, 0, dev_name(&dev->dev), tmio); |
432 | IRQF_DISABLED, dev_name(&dev->dev), tmio); | ||
433 | if (retval) { | 432 | if (retval) { |
434 | dev_err(&dev->dev, "request_irq error %d\n", retval); | 433 | dev_err(&dev->dev, "request_irq error %d\n", retval); |
435 | goto err_irq; | 434 | goto err_irq; |