Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus-20161216' of git://git.infradead.org/linux-mtd

Pull MTD updates from Brian Norris:
"Nothing enormous here, though notably we have some of the first work
of a few new maintainers. I think for now I'll still be sending pull
requests, but that's open to change in the future. Summary:

Core:

- dynamic BDI object allocation (resolves some problems when built as
a module)
- cleanups in the ooblayout handling

NAND:

- new tango NAND controller driver
- new ox820 NAND controller driver
- addition of a new full-ID entry in the nand_ids table
- rework of the s3c240 driver to support DT
- extension of the nand_sdr_timings to expose tCCS, tPROG and tR
- addition of a new flag to ask the core to wait for tCCS when
sending a RNDIN/RNDOUT command
- addition of a new flag to ask the core to let the controller driver
send the READ/PROGPAGE command

Minor fixes/cleanup/cosmetic changes:

- properly support 512 ECC step size in the sunxi driver
- improve the error messages in the PXA probe path
- fix module autoload in the omap2 driver
- cleanup of several nand drivers to return nand_scan{_tail}() error
code instead of returning -EIO
- various cleanups in the denali driver
- fix an error check in nandsim

SPI NOR:

- new flash IDs
- wait for Spansion flash to be ready after quad-enable
- error handling fixes for Candence QSPI
- constify some structures in Freescale QSPI driver"

* tag 'for-linus-20161216' of git://git.infradead.org/linux-mtd: (71 commits)
mtd: Allocate bdi objects dynamically
mtd: nand: tango: Add standard legalese header
mtd: maps: add missing iounmap() in error path
mtd: spi-nor: constify fsl_qspi_devtype_data
mtd: spi-nor: Add support for mr25h40
mtd: spi-nor: Add support for N25Q016A
mtd: spi-nor: Add at25df321 spi-nor flash support
mtd: spi-nor: Fix some error codes in cqspi_setup_flash()
mtd: spi-nor: Off by one in cqspi_setup_flash()
mtd: spi-nor: add support for s25fl208k
mtd: spi-nor: fix flags for s25fl128s
mtd: spi-nor: fix spansion quad enable
mtd: spi-nor: add Macronix mx25u25635f to list of known devices.
mtd: mtdswap: fix spelling mistake "erassure" -> "erasure"
mtd: bcm47xxpart: fix parsing first block after aligned TRX
mtd: nand: tango: Use nand_to_mtd() instead of directly accessing chip->mtd
mtd: remove unneeded initializer in mtd_ooblayout_count_bytes()
mtd: use min_t() to refactor mtd_ooblayout_{get, set}_bytes()
mtd: remove unneeded initializer in mtd_ooblayout_{get, set}_bytes()
mtd: nand: nandsim: fix error check
...

+1555 -351
+41
Documentation/devicetree/bindings/mtd/oxnas-nand.txt
··· 1 + * Oxford Semiconductor OXNAS NAND Controller 2 + 3 + Please refer to nand.txt for generic information regarding MTD NAND bindings. 4 + 5 + Required properties: 6 + - compatible: "oxsemi,ox820-nand" 7 + - reg: Base address and length for NAND mapped memory. 8 + 9 + Optional Properties: 10 + - clocks: phandle to the NAND gate clock if needed. 11 + - resets: phandle to the NAND reset control if needed. 12 + 13 + Example: 14 + 15 + nandc: nand-controller@41000000 { 16 + compatible = "oxsemi,ox820-nand"; 17 + reg = <0x41000000 0x100000>; 18 + clocks = <&stdclk CLK_820_NAND>; 19 + resets = <&reset RESET_NAND>; 20 + #address-cells = <1>; 21 + #size-cells = <0>; 22 + 23 + nand@0 { 24 + reg = <0>; 25 + #address-cells = <1>; 26 + #size-cells = <1>; 27 + nand-ecc-mode = "soft"; 28 + nand-ecc-algo = "hamming"; 29 + 30 + partition@0 { 31 + label = "boot"; 32 + reg = <0x00000000 0x00e00000>; 33 + read-only; 34 + }; 35 + 36 + partition@e00000 { 37 + label = "ubi"; 38 + reg = <0x00e00000 0x07200000>; 39 + }; 40 + }; 41 + };
+56
Documentation/devicetree/bindings/mtd/samsung-s3c2410.txt
··· 1 + * Samsung S3C2410 and compatible NAND flash controller 2 + 3 + Required properties: 4 + - compatible : The possible values are: 5 + "samsung,s3c2410-nand" 6 + "samsung,s3c2412-nand" 7 + "samsung,s3c2440-nand" 8 + - reg : register's location and length. 9 + - #address-cells, #size-cells : see nand.txt 10 + - clocks : phandle to the nand controller clock 11 + - clock-names : must contain "nand" 12 + 13 + Optional child nodes: 14 + Child nodes representing the available nand chips. 15 + 16 + Optional child properties: 17 + - nand-ecc-mode : see nand.txt 18 + - nand-on-flash-bbt : see nand.txt 19 + 20 + Each child device node may optionally contain a 'partitions' sub-node, 21 + which further contains sub-nodes describing the flash partition mapping. 22 + See partition.txt for more detail. 23 + 24 + Example: 25 + 26 + nand-controller@4e000000 { 27 + compatible = "samsung,s3c2440-nand"; 28 + reg = <0x4e000000 0x40>; 29 + 30 + #address-cells = <1>; 31 + #size-cells = <0>; 32 + 33 + clocks = <&clocks HCLK_NAND>; 34 + clock-names = "nand"; 35 + 36 + nand { 37 + nand-ecc-mode = "soft"; 38 + nand-on-flash-bbt; 39 + 40 + partitions { 41 + compatible = "fixed-partitions"; 42 + #address-cells = <1>; 43 + #size-cells = <1>; 44 + 45 + partition@0 { 46 + label = "u-boot"; 47 + reg = <0 0x040000>; 48 + }; 49 + 50 + partition@40000 { 51 + label = "kernel"; 52 + reg = <0x040000 0x500000>; 53 + }; 54 + }; 55 + }; 56 + };
+38
Documentation/devicetree/bindings/mtd/tango-nand.txt
··· 1 + Sigma Designs Tango4 NAND Flash Controller (NFC) 2 + 3 + Required properties: 4 + 5 + - compatible: "sigma,smp8758-nand" 6 + - reg: address/size of nfc_reg, nfc_mem, and pbus_reg 7 + - dmas: reference to the DMA channel used by the controller 8 + - dma-names: "nfc_sbox" 9 + - clocks: reference to the system clock 10 + - #address-cells: <1> 11 + - #size-cells: <0> 12 + 13 + Children nodes represent the available NAND chips. 14 + See Documentation/devicetree/bindings/mtd/nand.txt for generic bindings. 15 + 16 + Example: 17 + 18 + nandc: nand-controller@2c000 { 19 + compatible = "sigma,smp8758-nand"; 20 + reg = <0x2c000 0x30 0x2d000 0x800 0x20000 0x1000>; 21 + dmas = <&dma0 3>; 22 + dma-names = "nfc_sbox"; 23 + clocks = <&clkgen SYS_CLK>; 24 + #address-cells = <1>; 25 + #size-cells = <0>; 26 + 27 + nand@0 { 28 + reg = <0>; /* CS0 */ 29 + nand-ecc-strength = <14>; 30 + nand-ecc-step-size = <1024>; 31 + }; 32 + 33 + nand@1 { 34 + reg = <1>; /* CS1 */ 35 + nand-ecc-strength = <14>; 36 + nand-ecc-step-size = <1024>; 37 + }; 38 + };
+1
arch/arm/mach-s3c24xx/common-smdk.c
··· 171 171 .twrph1 = 20, 172 172 .nr_sets = ARRAY_SIZE(smdk_nand_sets), 173 173 .sets = smdk_nand_sets, 174 + .ecc_mode = NAND_ECC_SOFT, 174 175 }; 175 176 176 177 /* devices we initialise */
+1
arch/arm/mach-s3c24xx/mach-anubis.c
··· 223 223 .nr_sets = ARRAY_SIZE(anubis_nand_sets), 224 224 .sets = anubis_nand_sets, 225 225 .select_chip = anubis_nand_select, 226 + .ecc_mode = NAND_ECC_SOFT, 226 227 }; 227 228 228 229 /* IDE channels */
+1
arch/arm/mach-s3c24xx/mach-at2440evb.c
··· 114 114 .twrph1 = 40, 115 115 .nr_sets = ARRAY_SIZE(at2440evb_nand_sets), 116 116 .sets = at2440evb_nand_sets, 117 + .ecc_mode = NAND_ECC_SOFT, 117 118 }; 118 119 119 120 /* DM9000AEP 10/100 ethernet controller */
+1
arch/arm/mach-s3c24xx/mach-bast.c
··· 299 299 .nr_sets = ARRAY_SIZE(bast_nand_sets), 300 300 .sets = bast_nand_sets, 301 301 .select_chip = bast_nand_select, 302 + .ecc_mode = NAND_ECC_SOFT, 302 303 }; 303 304 304 305 /* DM9000 */
+1
arch/arm/mach-s3c24xx/mach-gta02.c
··· 443 443 .twrph1 = 15, 444 444 .nr_sets = ARRAY_SIZE(gta02_nand_sets), 445 445 .sets = gta02_nand_sets, 446 + .ecc_mode = NAND_ECC_SOFT, 446 447 }; 447 448 448 449
+1
arch/arm/mach-s3c24xx/mach-jive.c
··· 232 232 .twrph1 = 40, 233 233 .sets = jive_nand_sets, 234 234 .nr_sets = ARRAY_SIZE(jive_nand_sets), 235 + .ecc_mode = NAND_ECC_SOFT, 235 236 }; 236 237 237 238 static int __init jive_mtdset(char *options)
+1
arch/arm/mach-s3c24xx/mach-mini2440.c
··· 287 287 .nr_sets = ARRAY_SIZE(mini2440_nand_sets), 288 288 .sets = mini2440_nand_sets, 289 289 .ignore_unset_ecc = 1, 290 + .ecc_mode = NAND_ECC_SOFT, 290 291 }; 291 292 292 293 /* DM9000AEP 10/100 ethernet controller */
+1
arch/arm/mach-s3c24xx/mach-osiris.c
··· 238 238 .nr_sets = ARRAY_SIZE(osiris_nand_sets), 239 239 .sets = osiris_nand_sets, 240 240 .select_chip = osiris_nand_select, 241 + .ecc_mode = NAND_ECC_SOFT, 241 242 }; 242 243 243 244 /* PCMCIA control and configuration */
+1
arch/arm/mach-s3c24xx/mach-qt2410.c
··· 284 284 .twrph1 = 20, 285 285 .nr_sets = ARRAY_SIZE(qt2410_nand_sets), 286 286 .sets = qt2410_nand_sets, 287 + .ecc_mode = NAND_ECC_SOFT, 287 288 }; 288 289 289 290 /* UDC */
+1
arch/arm/mach-s3c24xx/mach-rx1950.c
··· 611 611 .twrph1 = 15, 612 612 .nr_sets = ARRAY_SIZE(rx1950_nand_sets), 613 613 .sets = rx1950_nand_sets, 614 + .ecc_mode = NAND_ECC_SOFT, 614 615 }; 615 616 616 617 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = {
+1
arch/arm/mach-s3c24xx/mach-rx3715.c
··· 164 164 .twrph1 = 15, 165 165 .nr_sets = ARRAY_SIZE(rx3715_nand_sets), 166 166 .sets = rx3715_nand_sets, 167 + .ecc_mode = NAND_ECC_SOFT, 167 168 }; 168 169 169 170 static struct platform_device *rx3715_devices[] __initdata = {
+1
arch/arm/mach-s3c24xx/mach-vstms.c
··· 117 117 .twrph1 = 20, 118 118 .nr_sets = ARRAY_SIZE(vstms_nand_sets), 119 119 .sets = vstms_nand_sets, 120 + .ecc_mode = NAND_ECC_SOFT, 120 121 }; 121 122 122 123 static struct platform_device *vstms_devices[] __initdata = {
+1
arch/arm/mach-s3c64xx/mach-hmt.c
··· 204 204 .twrph1 = 40, 205 205 .nr_sets = ARRAY_SIZE(hmt_nand_sets), 206 206 .sets = hmt_nand_sets, 207 + .ecc_mode = NAND_ECC_SOFT, 207 208 }; 208 209 209 210 static struct gpio_led hmt_leds[] = {
+1
arch/arm/mach-s3c64xx/mach-mini6410.c
··· 142 142 .twrph1 = 40, 143 143 .nr_sets = ARRAY_SIZE(mini6410_nand_sets), 144 144 .sets = mini6410_nand_sets, 145 + .ecc_mode = NAND_ECC_SOFT, 145 146 }; 146 147 147 148 static struct s3c_fb_pd_win mini6410_lcd_type0_fb_win = {
+1
arch/arm/mach-s3c64xx/mach-real6410.c
··· 194 194 .twrph1 = 40, 195 195 .nr_sets = ARRAY_SIZE(real6410_nand_sets), 196 196 .sets = real6410_nand_sets, 197 + .ecc_mode = NAND_ECC_SOFT, 197 198 }; 198 199 199 200 static struct platform_device *real6410_devices[] __initdata = {
+4 -6
drivers/mtd/bcm47xxpart.c
··· 229 229 230 230 last_trx_part = curr_part - 1; 231 231 232 - /* 233 - * We have whole TRX scanned, skip to the next part. Use 234 - * roundown (not roundup), as the loop will increase 235 - * offset in next step. 236 - */ 237 - offset = rounddown(offset + trx->length, blocksize); 232 + /* Jump to the end of TRX */ 233 + offset = roundup(offset + trx->length, blocksize); 234 + /* Next loop iteration will increase the offset */ 235 + offset -= blocksize; 238 236 continue; 239 237 } 240 238
+19 -5
drivers/mtd/devices/bcm47xxsflash.c
··· 296 296 dev_err(dev, "can't request region for resource %pR\n", res); 297 297 return -EBUSY; 298 298 } 299 - b47s->window = ioremap_cache(res->start, resource_size(res)); 300 - if (!b47s->window) { 301 - dev_err(dev, "ioremap failed for resource %pR\n", res); 302 - return -ENOMEM; 303 - } 304 299 305 300 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); 306 301 b47s->cc_read = bcm47xxsflash_bcma_cc_read; 307 302 b47s->cc_write = bcm47xxsflash_bcma_cc_write; 303 + 304 + /* 305 + * On old MIPS devices cache was magically invalidated when needed, 306 + * allowing us to use cached access and gain some performance. Trying 307 + * the same on ARM based BCM53573 results in flash corruptions, we need 308 + * to use uncached access for it. 309 + * 310 + * It may be arch specific, but right now there is only 1 ARM SoC using 311 + * this driver, so let's follow Broadcom's reference code and check 312 + * ChipCommon revision. 313 + */ 314 + if (b47s->bcma_cc->core->id.rev == 54) 315 + b47s->window = ioremap_nocache(res->start, resource_size(res)); 316 + else 317 + b47s->window = ioremap_cache(res->start, resource_size(res)); 318 + if (!b47s->window) { 319 + dev_err(dev, "ioremap failed for resource %pR\n", res); 320 + return -ENOMEM; 321 + } 308 322 309 323 switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) { 310 324 case BCMA_CC_FLASHT_STSER:
+7 -1
drivers/mtd/maps/sc520cdp.c
··· 227 227 228 228 static int __init init_sc520cdp(void) 229 229 { 230 - int i, devices_found = 0; 230 + int i, j, devices_found = 0; 231 231 232 232 #ifdef REPROGRAM_PAR 233 233 /* reprogram PAR registers so flash appears at the desired addresses */ ··· 243 243 244 244 if (!sc520cdp_map[i].virt) { 245 245 printk("Failed to ioremap_nocache\n"); 246 + for (j = 0; j < i; j++) { 247 + if (mymtd[j]) { 248 + map_destroy(mymtd[j]); 249 + iounmap(sc520cdp_map[j].virt); 250 + } 251 + } 246 252 return -EIO; 247 253 } 248 254
+25 -19
drivers/mtd/mtdcore.c
··· 46 46 47 47 #include "mtdcore.h" 48 48 49 - static struct backing_dev_info mtd_bdi = { 50 - }; 49 + static struct backing_dev_info *mtd_bdi; 51 50 52 51 #ifdef CONFIG_PM_SLEEP 53 52 ··· 499 500 if (WARN_ONCE(mtd->backing_dev_info, "MTD already registered\n")) 500 501 return -EEXIST; 501 502 502 - mtd->backing_dev_info = &mtd_bdi; 503 + mtd->backing_dev_info = mtd_bdi; 503 504 504 505 BUG_ON(mtd->writesize == 0); 505 506 mutex_lock(&mtd_table_mutex); ··· 1273 1274 int section, 1274 1275 struct mtd_oob_region *oobregion)) 1275 1276 { 1276 - struct mtd_oob_region oobregion = { }; 1277 - int section = 0, ret; 1277 + struct mtd_oob_region oobregion; 1278 + int section, ret; 1278 1279 1279 1280 ret = mtd_ooblayout_find_region(mtd, start, &section, 1280 1281 &oobregion, iter); ··· 1282 1283 while (!ret) { 1283 1284 int cnt; 1284 1285 1285 - cnt = oobregion.length > nbytes ? nbytes : oobregion.length; 1286 + cnt = min_t(int, nbytes, oobregion.length); 1286 1287 memcpy(buf, oobbuf + oobregion.offset, cnt); 1287 1288 buf += cnt; 1288 1289 nbytes -= cnt; ··· 1316 1317 int section, 1317 1318 struct mtd_oob_region *oobregion)) 1318 1319 { 1319 - struct mtd_oob_region oobregion = { }; 1320 - int section = 0, ret; 1320 + struct mtd_oob_region oobregion; 1321 + int section, ret; 1321 1322 1322 1323 ret = mtd_ooblayout_find_region(mtd, start, &section, 1323 1324 &oobregion, iter); ··· 1325 1326 while (!ret) { 1326 1327 int cnt; 1327 1328 1328 - cnt = oobregion.length > nbytes ? nbytes : oobregion.length; 1329 + cnt = min_t(int, nbytes, oobregion.length); 1329 1330 memcpy(oobbuf + oobregion.offset, buf, cnt); 1330 1331 buf += cnt; 1331 1332 nbytes -= cnt; ··· 1353 1354 int section, 1354 1355 struct mtd_oob_region *oobregion)) 1355 1356 { 1356 - struct mtd_oob_region oobregion = { }; 1357 + struct mtd_oob_region oobregion; 1357 1358 int section = 0, ret, nbytes = 0; 1358 1359 1359 1360 while (1) { ··· 1770 1771 /*====================================================================*/ 1771 1772 /* Init code */ 1772 1773 1773 - static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name) 1774 + static struct backing_dev_info * __init mtd_bdi_init(char *name) 1774 1775 { 1776 + struct backing_dev_info *bdi; 1775 1777 int ret; 1776 1778 1777 - ret = bdi_init(bdi); 1778 - if (!ret) 1779 - ret = bdi_register(bdi, NULL, "%s", name); 1779 + bdi = kzalloc(sizeof(*bdi), GFP_KERNEL); 1780 + if (!bdi) 1781 + return ERR_PTR(-ENOMEM); 1780 1782 1783 + ret = bdi_setup_and_register(bdi, name); 1781 1784 if (ret) 1782 - bdi_destroy(bdi); 1785 + kfree(bdi); 1783 1786 1784 - return ret; 1787 + return ret ? ERR_PTR(ret) : bdi; 1785 1788 } 1786 1789 1787 1790 static struct proc_dir_entry *proc_mtd; ··· 1796 1795 if (ret) 1797 1796 goto err_reg; 1798 1797 1799 - ret = mtd_bdi_init(&mtd_bdi, "mtd"); 1800 - if (ret) 1798 + mtd_bdi = mtd_bdi_init("mtd"); 1799 + if (IS_ERR(mtd_bdi)) { 1800 + ret = PTR_ERR(mtd_bdi); 1801 1801 goto err_bdi; 1802 + } 1802 1803 1803 1804 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); 1804 1805 ··· 1813 1810 out_procfs: 1814 1811 if (proc_mtd) 1815 1812 remove_proc_entry("mtd", NULL); 1813 + bdi_destroy(mtd_bdi); 1814 + kfree(mtd_bdi); 1816 1815 err_bdi: 1817 1816 class_unregister(&mtd_class); 1818 1817 err_reg: ··· 1828 1823 if (proc_mtd) 1829 1824 remove_proc_entry("mtd", NULL); 1830 1825 class_unregister(&mtd_class); 1831 - bdi_destroy(&mtd_bdi); 1826 + bdi_destroy(mtd_bdi); 1827 + kfree(mtd_bdi); 1832 1828 idr_destroy(&mtd_idr); 1833 1829 } 1834 1830
+1 -1
drivers/mtd/mtdswap.c
··· 587 587 ret = wait_event_interruptible(wq, erase.state == MTD_ERASE_DONE || 588 588 erase.state == MTD_ERASE_FAILED); 589 589 if (ret) { 590 - dev_err(d->dev, "Interrupted erase block %#llx erassure on %s", 590 + dev_err(d->dev, "Interrupted erase block %#llx erasure on %s\n", 591 591 erase.addr, mtd->name); 592 592 return -EINTR; 593 593 }
+12 -9
drivers/mtd/nand/Kconfig
··· 179 179 help 180 180 Enable debugging of the S3C NAND driver 181 181 182 - config MTD_NAND_S3C2410_HWECC 183 - bool "Samsung S3C NAND Hardware ECC" 184 - depends on MTD_NAND_S3C2410 185 - help 186 - Enable the use of the controller's internal ECC generator when 187 - using NAND. Early versions of the chips have had problems with 188 - incorrect ECC generation, and if using these, the default of 189 - software ECC is preferable. 190 - 191 182 config MTD_NAND_NDFC 192 183 tristate "NDFC NanD Flash Controller" 193 184 depends on 4xx ··· 195 204 selected to save power. This will mean there is a small delay 196 205 when the is NAND chip selected or released, but will save 197 206 approximately 5mA of power when there is nothing happening. 207 + 208 + config MTD_NAND_TANGO 209 + tristate "NAND Flash support for Tango chips" 210 + depends on ARCH_TANGO || COMPILE_TEST 211 + depends on HAS_DMA 212 + help 213 + Enables the NAND Flash controller on Tango chips. 198 214 199 215 config MTD_NAND_DISKONCHIP 200 216 tristate "DiskOnChip 2000, Millennium and Millennium Plus (NAND reimplementation)" ··· 423 425 424 426 No board specific support is done by this driver, each board 425 427 must advertise a platform_device for the driver to attach. 428 + 429 + config MTD_NAND_OXNAS 430 + tristate "NAND Flash support for Oxford Semiconductor SoC" 431 + help 432 + This enables the NAND flash controller on Oxford Semiconductor SoCs. 426 433 427 434 config MTD_NAND_FSL_ELBC 428 435 tristate "NAND support for Freescale eLBC controllers"
+2
drivers/mtd/nand/Makefile
··· 16 16 obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o 17 17 obj-$(CONFIG_MTD_NAND_BF5XX) += bf5xx_nand.o 18 18 obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o 19 + obj-$(CONFIG_MTD_NAND_TANGO) += tango_nand.o 19 20 obj-$(CONFIG_MTD_NAND_DAVINCI) += davinci_nand.o 20 21 obj-$(CONFIG_MTD_NAND_DISKONCHIP) += diskonchip.o 21 22 obj-$(CONFIG_MTD_NAND_DOCG4) += docg4.o ··· 36 35 obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 37 36 obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 38 37 obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o 38 + obj-$(CONFIG_MTD_NAND_OXNAS) += oxnas_nand.o 39 39 obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o 40 40 obj-$(CONFIG_MTD_NAND_FSL_IFC) += fsl_ifc_nand.o 41 41 obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o
+2 -3
drivers/mtd/nand/ams-delta.c
··· 234 234 goto out_gpio; 235 235 236 236 /* Scan to find existence of the device */ 237 - if (nand_scan(ams_delta_mtd, 1)) { 238 - err = -ENXIO; 237 + err = nand_scan(ams_delta_mtd, 1); 238 + if (err) 239 239 goto out_mtd; 240 - } 241 240 242 241 /* Register the partitions */ 243 242 mtd_device_register(ams_delta_mtd, partition_info,
+4 -6
drivers/mtd/nand/atmel_nand.c
··· 2267 2267 dev_info(host->dev, "No DMA support for NAND access.\n"); 2268 2268 2269 2269 /* first scan to find the device and get the page size */ 2270 - if (nand_scan_ident(mtd, 1, NULL)) { 2271 - res = -ENXIO; 2270 + res = nand_scan_ident(mtd, 1, NULL); 2271 + if (res) 2272 2272 goto err_scan_ident; 2273 - } 2274 2273 2275 2274 if (host->board.on_flash_bbt || on_flash_bbt) 2276 2275 nand_chip->bbt_options |= NAND_BBT_USE_FLASH; ··· 2303 2304 } 2304 2305 2305 2306 /* second phase scan */ 2306 - if (nand_scan_tail(mtd)) { 2307 - res = -ENXIO; 2307 + res = nand_scan_tail(mtd); 2308 + if (res) 2308 2309 goto err_scan_tail; 2309 - } 2310 2310 2311 2311 mtd->name = "atmel_nand"; 2312 2312 res = mtd_device_register(mtd, host->board.parts,
+6 -4
drivers/mtd/nand/brcmnand/brcmnand.c
··· 2209 2209 nand_writereg(ctrl, cfg_offs, 2210 2210 nand_readreg(ctrl, cfg_offs) & ~CFG_BUS_WIDTH); 2211 2211 2212 - if (nand_scan_ident(mtd, 1, NULL)) 2213 - return -ENXIO; 2212 + ret = nand_scan_ident(mtd, 1, NULL); 2213 + if (ret) 2214 + return ret; 2214 2215 2215 2216 chip->options |= NAND_NO_SUBPAGE_WRITE; 2216 2217 /* ··· 2235 2234 if (ret) 2236 2235 return ret; 2237 2236 2238 - if (nand_scan_tail(mtd)) 2239 - return -ENXIO; 2237 + ret = nand_scan_tail(mtd); 2238 + if (ret) 2239 + return ret; 2240 2240 2241 2241 return mtd_device_register(mtd, NULL, 0); 2242 2242 }
+2 -3
drivers/mtd/nand/cafe_nand.c
··· 725 725 usedma = 0; 726 726 727 727 /* Scan to find existence of the device */ 728 - if (nand_scan_ident(mtd, 2, NULL)) { 729 - err = -ENXIO; 728 + err = nand_scan_ident(mtd, 2, NULL); 729 + if (err) 730 730 goto out_irq; 731 - } 732 731 733 732 cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev, 734 733 2112 + sizeof(struct nand_buffers) +
+2 -2
drivers/mtd/nand/cmx270_nand.c
··· 195 195 this->write_buf = cmx270_write_buf; 196 196 197 197 /* Scan to find existence of the device */ 198 - if (nand_scan (cmx270_nand_mtd, 1)) { 198 + ret = nand_scan(cmx270_nand_mtd, 1); 199 + if (ret) { 199 200 pr_notice("No NAND device\n"); 200 - ret = -ENXIO; 201 201 goto err_scan; 202 202 } 203 203
+2 -3
drivers/mtd/nand/cs553x_nand.c
··· 242 242 } 243 243 244 244 /* Scan to find existence of the device */ 245 - if (nand_scan(new_mtd, 1)) { 246 - err = -ENXIO; 245 + err = nand_scan(new_mtd, 1); 246 + if (err) 247 247 goto out_free; 248 - } 249 248 250 249 cs553x_mtd[cs] = new_mtd; 251 250 goto out;
+21 -80
drivers/mtd/nand/denali.c
··· 21 21 #include <linux/dma-mapping.h> 22 22 #include <linux/wait.h> 23 23 #include <linux/mutex.h> 24 - #include <linux/slab.h> 25 24 #include <linux/mtd/mtd.h> 26 25 #include <linux/module.h> 27 26 ··· 181 182 { 182 183 int i; 183 184 184 - dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 185 - __FILE__, __LINE__, __func__); 186 - 187 185 for (i = 0; i < denali->max_banks; i++) 188 186 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT, 189 187 denali->flash_reg + INTR_STATUS(i)); ··· 229 233 uint16_t en_lo, en_hi; 230 234 uint16_t acc_clks; 231 235 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt; 232 - 233 - dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 234 - __FILE__, __LINE__, __func__); 235 236 236 237 en_lo = CEIL_DIV(Trp[mode], CLK_X); 237 238 en_hi = CEIL_DIV(Treh[mode], CLK_X); ··· 396 403 break; 397 404 default: 398 405 dev_warn(denali->dev, 399 - "Spectra: Unknown Hynix NAND (Device ID: 0x%x).\n" 406 + "Unknown Hynix NAND (Device ID: 0x%x).\n" 400 407 "Will use default parameter values instead.\n", 401 408 device_id); 402 409 } ··· 467 474 denali->max_banks = 1 << (features & FEATURES__N_BANKS); 468 475 } 469 476 470 - static void detect_partition_feature(struct denali_nand_info *denali) 471 - { 472 - /* 473 - * For MRST platform, denali->fwblks represent the 474 - * number of blocks firmware is taken, 475 - * FW is in protect partition and MTD driver has no 476 - * permission to access it. So let driver know how many 477 - * blocks it can't touch. 478 - */ 479 - if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) { 480 - if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) & 481 - PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) { 482 - denali->fwblks = 483 - ((ioread32(denali->flash_reg + MIN_MAX_BANK(1)) & 484 - MIN_MAX_BANK__MIN_VALUE) * 485 - denali->blksperchip) 486 - + 487 - (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) & 488 - MIN_BLK_ADDR__VALUE); 489 - } else { 490 - denali->fwblks = SPECTRA_START_BLOCK; 491 - } 492 - } else { 493 - denali->fwblks = SPECTRA_START_BLOCK; 494 - } 495 - } 496 - 497 477 static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) 498 478 { 499 479 uint16_t status = PASS; 500 480 uint32_t id_bytes[8], addr; 501 481 uint8_t maf_id, device_id; 502 482 int i; 503 - 504 - dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 505 - __FILE__, __LINE__, __func__); 506 483 507 484 /* 508 485 * Use read id method to get device ID and other params. ··· 515 552 516 553 find_valid_banks(denali); 517 554 518 - detect_partition_feature(denali); 519 - 520 555 /* 521 556 * If the user specified to override the default timings 522 557 * with a specific ONFI mode, we apply those changes here. ··· 528 567 static void denali_set_intr_modes(struct denali_nand_info *denali, 529 568 uint16_t INT_ENABLE) 530 569 { 531 - dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 532 - __FILE__, __LINE__, __func__); 533 - 534 570 if (INT_ENABLE) 535 571 iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE); 536 572 else ··· 563 605 static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali) 564 606 { 565 607 denali_set_intr_modes(denali, false); 566 - free_irq(irqnum, denali); 567 608 } 568 609 569 610 static void denali_irq_enable(struct denali_nand_info *denali, ··· 1394 1437 /* initialize driver data structures */ 1395 1438 static void denali_drv_init(struct denali_nand_info *denali) 1396 1439 { 1397 - denali->idx = 0; 1398 - 1399 - /* setup interrupt handler */ 1400 1440 /* 1401 1441 * the completion object will be used to notify 1402 1442 * the callee that the interrupt is done ··· 1439 1485 denali_hw_init(denali); 1440 1486 denali_drv_init(denali); 1441 1487 1442 - /* 1443 - * denali_isr register is done after all the hardware 1444 - * initilization is finished 1445 - */ 1446 - if (request_irq(denali->irq, denali_isr, IRQF_SHARED, 1447 - DENALI_NAND_NAME, denali)) { 1448 - pr_err("Spectra: Unable to allocate IRQ\n"); 1449 - return -ENODEV; 1488 + /* Request IRQ after all the hardware initialization is finished */ 1489 + ret = devm_request_irq(denali->dev, denali->irq, denali_isr, 1490 + IRQF_SHARED, DENALI_NAND_NAME, denali); 1491 + if (ret) { 1492 + dev_err(denali->dev, "Unable to request IRQ\n"); 1493 + return ret; 1450 1494 } 1451 1495 1452 1496 /* now that our ISR is registered, we can enable interrupts */ ··· 1462 1510 * this is the first stage in a two step process to register 1463 1511 * with the nand subsystem 1464 1512 */ 1465 - if (nand_scan_ident(mtd, denali->max_banks, NULL)) { 1466 - ret = -ENXIO; 1513 + ret = nand_scan_ident(mtd, denali->max_banks, NULL); 1514 + if (ret) 1467 1515 goto failed_req_irq; 1468 - } 1469 1516 1470 1517 /* allocate the right size buffer now */ 1471 1518 devm_kfree(denali->dev, denali->buf.buf); ··· 1479 1528 /* Is 32-bit DMA supported? */ 1480 1529 ret = dma_set_mask(denali->dev, DMA_BIT_MASK(32)); 1481 1530 if (ret) { 1482 - pr_err("Spectra: no usable DMA configuration\n"); 1531 + dev_err(denali->dev, "No usable DMA configuration\n"); 1483 1532 goto failed_req_irq; 1484 1533 } 1485 1534 ··· 1487 1536 mtd->writesize + mtd->oobsize, 1488 1537 DMA_BIDIRECTIONAL); 1489 1538 if (dma_mapping_error(denali->dev, denali->buf.dma_buf)) { 1490 - dev_err(denali->dev, "Spectra: failed to map DMA buffer\n"); 1539 + dev_err(denali->dev, "Failed to map DMA buffer\n"); 1491 1540 ret = -EIO; 1492 1541 goto failed_req_irq; 1493 1542 } ··· 1498 1547 * the real pagesize and anything necessery 1499 1548 */ 1500 1549 denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED); 1501 - denali->nand.chipsize <<= (denali->devnum - 1); 1502 - denali->nand.page_shift += (denali->devnum - 1); 1550 + denali->nand.chipsize <<= denali->devnum - 1; 1551 + denali->nand.page_shift += denali->devnum - 1; 1503 1552 denali->nand.pagemask = (denali->nand.chipsize >> 1504 1553 denali->nand.page_shift) - 1; 1505 - denali->nand.bbt_erase_shift += (denali->devnum - 1); 1554 + denali->nand.bbt_erase_shift += denali->devnum - 1; 1506 1555 denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift; 1507 - denali->nand.chip_shift += (denali->devnum - 1); 1508 - mtd->writesize <<= (denali->devnum - 1); 1509 - mtd->oobsize <<= (denali->devnum - 1); 1510 - mtd->erasesize <<= (denali->devnum - 1); 1556 + denali->nand.chip_shift += denali->devnum - 1; 1557 + mtd->writesize <<= denali->devnum - 1; 1558 + mtd->oobsize <<= denali->devnum - 1; 1559 + mtd->erasesize <<= denali->devnum - 1; 1511 1560 mtd->size = denali->nand.numchips * denali->nand.chipsize; 1512 1561 denali->bbtskipbytes *= denali->devnum; 1513 1562 ··· 1557 1606 denali->nand.ecc.bytes *= denali->devnum; 1558 1607 denali->nand.ecc.strength *= denali->devnum; 1559 1608 1560 - /* 1561 - * Let driver know the total blocks number and how many blocks 1562 - * contained by each nand chip. blksperchip will help driver to 1563 - * know how many blocks is taken by FW. 1564 - */ 1565 - denali->totalblks = mtd->size >> denali->nand.phys_erase_shift; 1566 - denali->blksperchip = denali->totalblks / denali->nand.numchips; 1567 - 1568 1609 /* override the default read operations */ 1569 1610 denali->nand.ecc.size = ECC_SECTOR_SIZE * denali->devnum; 1570 1611 denali->nand.ecc.read_page = denali_read_page; ··· 1567 1624 denali->nand.ecc.write_oob = denali_write_oob; 1568 1625 denali->nand.erase = denali_erase; 1569 1626 1570 - if (nand_scan_tail(mtd)) { 1571 - ret = -ENXIO; 1627 + ret = nand_scan_tail(mtd); 1628 + if (ret) 1572 1629 goto failed_req_irq; 1573 - } 1574 1630 1575 1631 ret = mtd_device_register(mtd, NULL, 0); 1576 1632 if (ret) { 1577 - dev_err(denali->dev, "Spectra: Failed to register MTD: %d\n", 1578 - ret); 1633 + dev_err(denali->dev, "Failed to register MTD: %d\n", ret); 1579 1634 goto failed_req_irq; 1580 1635 } 1581 1636 return 0;
-12
drivers/mtd/nand/denali.h
··· 383 383 #define CLK_X 5 384 384 #define CLK_MULTI 4 385 385 386 - /* spectraswconfig.h */ 387 - #define CMD_DMA 0 388 - 389 - #define SPECTRA_PARTITION_ID 0 390 - /**** Block Table and Reserved Block Parameters *****/ 391 - #define SPECTRA_START_BLOCK 3 392 - #define NUM_FREE_BLOCKS_GATE 30 393 - 394 386 /* KBV - Updated to LNW scratch register address */ 395 387 #define SCRATCH_REG_ADDR CONFIG_MTD_NAND_DENALI_SCRATCH_REG_ADDR 396 388 #define SCRATCH_REG_SIZE 64 ··· 459 467 spinlock_t irq_lock; 460 468 uint32_t irq_status; 461 469 int irq_debug_array[32]; 462 - int idx; 463 470 int irq; 464 471 465 472 uint32_t devnum; /* represent how many nands connected */ 466 - uint32_t fwblks; /* represent how many blocks FW used */ 467 - uint32_t totalblks; 468 - uint32_t blksperchip; 469 473 uint32_t bbtskipbytes; 470 474 uint32_t max_banks; 471 475 };
+1 -2
drivers/mtd/nand/denali_dt.c
··· 21 21 #include <linux/platform_device.h> 22 22 #include <linux/of.h> 23 23 #include <linux/of_device.h> 24 - #include <linux/slab.h> 25 24 26 25 #include "denali.h" 27 26 ··· 109 110 struct denali_dt *dt = platform_get_drvdata(ofdev); 110 111 111 112 denali_remove(&dt->denali); 112 - clk_disable(dt->clk); 113 + clk_disable_unprepare(dt->clk); 113 114 114 115 return 0; 115 116 }
-1
drivers/mtd/nand/denali_pci.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 16 #include <linux/pci.h> 17 - #include <linux/slab.h> 18 17 19 18 #include "denali.h" 20 19
+4 -5
drivers/mtd/nand/fsmc_nand.c
··· 926 926 /* 927 927 * Scan to find existence of the device 928 928 */ 929 - if (nand_scan_ident(mtd, 1, NULL)) { 930 - ret = -ENXIO; 929 + ret = nand_scan_ident(mtd, 1, NULL); 930 + if (ret) { 931 931 dev_err(&pdev->dev, "No NAND Device found!\n"); 932 932 goto err_scan_ident; 933 933 } ··· 992 992 } 993 993 994 994 /* Second stage of scan to fill MTD data-structures */ 995 - if (nand_scan_tail(mtd)) { 996 - ret = -ENXIO; 995 + ret = nand_scan_tail(mtd); 996 + if (ret) 997 997 goto err_probe; 998 - } 999 998 1000 999 /* 1001 1000 * The partition information can is accessed by (in the same precedence)
+2 -3
drivers/mtd/nand/gpio.c
··· 286 286 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 287 287 gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); 288 288 289 - if (nand_scan(mtd, 1)) { 290 - ret = -ENXIO; 289 + ret = nand_scan(mtd, 1); 290 + if (ret) 291 291 goto err_wp; 292 - } 293 292 294 293 if (gpiomtd->plat.adjust_parts) 295 294 gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size);
+1 -3
drivers/mtd/nand/hisi504_nand.c
··· 774 774 } 775 775 776 776 ret = nand_scan_ident(mtd, max_chips, NULL); 777 - if (ret) { 778 - ret = -ENODEV; 777 + if (ret) 779 778 goto err_res; 780 - } 781 779 782 780 host->buffer = dmam_alloc_coherent(dev, mtd->writesize + mtd->oobsize, 783 781 &host->dma_buffer, GFP_KERNEL);
+4 -6
drivers/mtd/nand/lpc32xx_mlc.c
··· 747 747 * Scan to find existance of the device and 748 748 * Get the type of NAND device SMALL block or LARGE block 749 749 */ 750 - if (nand_scan_ident(mtd, 1, NULL)) { 751 - res = -ENXIO; 750 + res = nand_scan_ident(mtd, 1, NULL); 751 + if (res) 752 752 goto err_exit3; 753 - } 754 753 755 754 host->dma_buf = devm_kzalloc(&pdev->dev, mtd->writesize, GFP_KERNEL); 756 755 if (!host->dma_buf) { ··· 792 793 * Fills out all the uninitialized function pointers with the defaults 793 794 * And scans for a bad block table if appropriate. 794 795 */ 795 - if (nand_scan_tail(mtd)) { 796 - res = -ENXIO; 796 + res = nand_scan_tail(mtd); 797 + if (res) 797 798 goto err_exit4; 798 - } 799 799 800 800 mtd->name = DRV_NAME; 801 801
+4 -6
drivers/mtd/nand/lpc32xx_slc.c
··· 894 894 } 895 895 896 896 /* Find NAND device */ 897 - if (nand_scan_ident(mtd, 1, NULL)) { 898 - res = -ENXIO; 897 + res = nand_scan_ident(mtd, 1, NULL); 898 + if (res) 899 899 goto err_exit3; 900 - } 901 900 902 901 /* OOB and ECC CPU and DMA work areas */ 903 902 host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE); ··· 928 929 /* 929 930 * Fills out all the uninitialized function pointers with the defaults 930 931 */ 931 - if (nand_scan_tail(mtd)) { 932 - res = -ENXIO; 932 + res = nand_scan_tail(mtd); 933 + if (res) 933 934 goto err_exit3; 934 - } 935 935 936 936 mtd->name = "nxp_lpc3220_slc"; 937 937 res = mtd_device_register(mtd, host->ncfg->parts,
+2 -2
drivers/mtd/nand/mpc5121_nfc.c
··· 777 777 } 778 778 779 779 /* Detect NAND chips */ 780 - if (nand_scan(mtd, be32_to_cpup(chips_no))) { 780 + retval = nand_scan(mtd, be32_to_cpup(chips_no)); 781 + if (retval) { 781 782 dev_err(dev, "NAND Flash not found !\n"); 782 - retval = -ENXIO; 783 783 goto error; 784 784 } 785 785
+2 -2
drivers/mtd/nand/mtk_nand.c
··· 1297 1297 1298 1298 ret = nand_scan_ident(mtd, nsels, NULL); 1299 1299 if (ret) 1300 - return -ENODEV; 1300 + return ret; 1301 1301 1302 1302 /* store bbt magic in page, cause OOB is not protected */ 1303 1303 if (nand->bbt_options & NAND_BBT_USE_FLASH) ··· 1323 1323 1324 1324 ret = nand_scan_tail(mtd); 1325 1325 if (ret) 1326 - return -ENODEV; 1326 + return ret; 1327 1327 1328 1328 ret = mtd_device_parse_register(mtd, NULL, NULL, NULL, 0); 1329 1329 if (ret) {
+4 -6
drivers/mtd/nand/mxc_nand.c
··· 1747 1747 } 1748 1748 1749 1749 /* first scan to find the device and get the page size */ 1750 - if (nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL)) { 1751 - err = -ENXIO; 1750 + err = nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL); 1751 + if (err) 1752 1752 goto escan; 1753 - } 1754 1753 1755 1754 switch (this->ecc.mode) { 1756 1755 case NAND_ECC_HW: ··· 1807 1808 } 1808 1809 1809 1810 /* second phase scan */ 1810 - if (nand_scan_tail(mtd)) { 1811 - err = -ENXIO; 1811 + err = nand_scan_tail(mtd); 1812 + if (err) 1812 1813 goto escan; 1813 - } 1814 1814 1815 1815 /* Register the partitions */ 1816 1816 mtd_device_parse_register(mtd, part_probes,
+66 -18
drivers/mtd/nand/nand_base.c
··· 709 709 nand_wait_ready(mtd); 710 710 } 711 711 712 + static void nand_ccs_delay(struct nand_chip *chip) 713 + { 714 + /* 715 + * The controller already takes care of waiting for tCCS when the RNDIN 716 + * or RNDOUT command is sent, return directly. 717 + */ 718 + if (!(chip->options & NAND_WAIT_TCCS)) 719 + return; 720 + 721 + /* 722 + * Wait tCCS_min if it is correctly defined, otherwise wait 500ns 723 + * (which should be safe for all NANDs). 724 + */ 725 + if (chip->data_interface && chip->data_interface->timings.sdr.tCCS_min) 726 + ndelay(chip->data_interface->timings.sdr.tCCS_min / 1000); 727 + else 728 + ndelay(500); 729 + } 730 + 712 731 /** 713 732 * nand_command_lp - [DEFAULT] Send command to NAND large page device 714 733 * @mtd: MTD device structure ··· 792 773 case NAND_CMD_ERASE1: 793 774 case NAND_CMD_ERASE2: 794 775 case NAND_CMD_SEQIN: 795 - case NAND_CMD_RNDIN: 796 776 case NAND_CMD_STATUS: 777 + return; 778 + 779 + case NAND_CMD_RNDIN: 780 + nand_ccs_delay(chip); 797 781 return; 798 782 799 783 case NAND_CMD_RESET: ··· 817 795 NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); 818 796 chip->cmd_ctrl(mtd, NAND_CMD_NONE, 819 797 NAND_NCE | NAND_CTRL_CHANGE); 798 + 799 + nand_ccs_delay(chip); 820 800 return; 821 801 822 802 case NAND_CMD_READ0: ··· 1970 1946 __func__, buf); 1971 1947 1972 1948 read_retry: 1973 - chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); 1949 + if (nand_standard_page_accessors(&chip->ecc)) 1950 + chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); 1974 1951 1975 1952 /* 1976 1953 * Now read the page into the buffer. Absent an error, ··· 2659 2634 else 2660 2635 subpage = 0; 2661 2636 2662 - chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 2637 + if (nand_standard_page_accessors(&chip->ecc)) 2638 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 2663 2639 2664 2640 if (unlikely(raw)) 2665 2641 status = chip->ecc.write_page_raw(mtd, chip, buf, ··· 2683 2657 2684 2658 if (!cached || !NAND_HAS_CACHEPROG(chip)) { 2685 2659 2686 - chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 2660 + if (nand_standard_page_accessors(&chip->ecc)) 2661 + chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 2687 2662 status = chip->waitfunc(mtd, chip); 2688 2663 /* 2689 2664 * See if operation failed and additional status checks are ··· 4012 3985 /* 4013 3986 * Get the flash and manufacturer id and lookup if the type is supported. 4014 3987 */ 4015 - static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, 4016 - struct nand_chip *chip, 4017 - int *maf_id, int *dev_id, 4018 - struct nand_flash_dev *type) 3988 + static int nand_get_flash_type(struct mtd_info *mtd, struct nand_chip *chip, 3989 + int *maf_id, int *dev_id, 3990 + struct nand_flash_dev *type) 4019 3991 { 4020 3992 int busw; 4021 3993 int i, maf_idx; ··· 4052 4026 if (id_data[0] != *maf_id || id_data[1] != *dev_id) { 4053 4027 pr_info("second ID read did not match %02x,%02x against %02x,%02x\n", 4054 4028 *maf_id, *dev_id, id_data[0], id_data[1]); 4055 - return ERR_PTR(-ENODEV); 4029 + return -ENODEV; 4056 4030 } 4057 4031 4058 4032 if (!type) ··· 4079 4053 } 4080 4054 4081 4055 if (!type->name) 4082 - return ERR_PTR(-ENODEV); 4056 + return -ENODEV; 4083 4057 4084 4058 if (!mtd->name) 4085 4059 mtd->name = type->name; ··· 4124 4098 pr_warn("bus width %d instead %d bit\n", 4125 4099 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8, 4126 4100 busw ? 16 : 8); 4127 - return ERR_PTR(-EINVAL); 4101 + return -EINVAL; 4128 4102 } 4129 4103 4130 4104 nand_decode_bbm_options(mtd, chip, id_data); ··· 4166 4140 pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n", 4167 4141 (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", 4168 4142 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); 4169 - return type; 4143 + return 0; 4170 4144 } 4171 4145 4172 4146 static const char * const nand_ecc_modes[] = { ··· 4332 4306 { 4333 4307 int i, nand_maf_id, nand_dev_id; 4334 4308 struct nand_chip *chip = mtd_to_nand(mtd); 4335 - struct nand_flash_dev *type; 4336 4309 int ret; 4337 4310 4338 4311 ret = nand_dt_init(chip); ··· 4354 4329 nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); 4355 4330 4356 4331 /* Read the flash type */ 4357 - type = nand_get_flash_type(mtd, chip, &nand_maf_id, 4358 - &nand_dev_id, table); 4359 - 4360 - if (IS_ERR(type)) { 4332 + ret = nand_get_flash_type(mtd, chip, &nand_maf_id, &nand_dev_id, table); 4333 + if (ret) { 4361 4334 if (!(chip->options & NAND_SCAN_SILENT_NODEV)) 4362 4335 pr_warn("No NAND device found\n"); 4363 4336 chip->select_chip(mtd, -1); 4364 - return PTR_ERR(type); 4337 + return ret; 4365 4338 } 4366 4339 4367 4340 /* Initialize the ->data_interface field. */ ··· 4538 4515 return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds; 4539 4516 } 4540 4517 4518 + static bool invalid_ecc_page_accessors(struct nand_chip *chip) 4519 + { 4520 + struct nand_ecc_ctrl *ecc = &chip->ecc; 4521 + 4522 + if (nand_standard_page_accessors(ecc)) 4523 + return false; 4524 + 4525 + /* 4526 + * NAND_ECC_CUSTOM_PAGE_ACCESS flag is set, make sure the NAND 4527 + * controller driver implements all the page accessors because 4528 + * default helpers are not suitable when the core does not 4529 + * send the READ0/PAGEPROG commands. 4530 + */ 4531 + return (!ecc->read_page || !ecc->write_page || 4532 + !ecc->read_page_raw || !ecc->write_page_raw || 4533 + (NAND_HAS_SUBPAGE_READ(chip) && !ecc->read_subpage) || 4534 + (NAND_HAS_SUBPAGE_WRITE(chip) && !ecc->write_subpage && 4535 + ecc->hwctl && ecc->calculate)); 4536 + } 4537 + 4541 4538 /** 4542 4539 * nand_scan_tail - [NAND Interface] Scan for the NAND device 4543 4540 * @mtd: MTD device structure ··· 4577 4534 if (WARN_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) && 4578 4535 !(chip->bbt_options & NAND_BBT_USE_FLASH))) 4579 4536 return -EINVAL; 4537 + 4538 + if (invalid_ecc_page_accessors(chip)) { 4539 + pr_err("Invalid ECC page accessors setup\n"); 4540 + return -EINVAL; 4541 + } 4580 4542 4581 4543 if (!(chip->options & NAND_OWN_BUFFERS)) { 4582 4544 nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
+3
drivers/mtd/nand/nand_ids.c
··· 36 36 {"TC58NVG2S0F 4G 3.3V 8-bit", 37 37 { .id = {0x98, 0xdc, 0x90, 0x26, 0x76, 0x15, 0x01, 0x08} }, 38 38 SZ_4K, SZ_512, SZ_256K, 0, 8, 224, NAND_ECC_INFO(4, SZ_512) }, 39 + {"TC58NVG2S0H 4G 3.3V 8-bit", 40 + { .id = {0x98, 0xdc, 0x90, 0x26, 0x76, 0x16, 0x08, 0x00} }, 41 + SZ_4K, SZ_512, SZ_256K, 0, 8, 256, NAND_ECC_INFO(8, SZ_512) }, 39 42 {"TC58NVG3S0F 8G 3.3V 8-bit", 40 43 { .id = {0x98, 0xd3, 0x90, 0x26, 0x76, 0x15, 0x02, 0x08} }, 41 44 SZ_4K, SZ_1K, SZ_256K, 0, 8, 232, NAND_ECC_INFO(4, SZ_512) },
+25 -1
drivers/mtd/nand/nand_timings.c
··· 18 18 { 19 19 .type = NAND_SDR_IFACE, 20 20 .timings.sdr = { 21 + .tCCS_min = 500000, 22 + .tR_max = 200000000, 21 23 .tADL_min = 400000, 22 24 .tALH_min = 20000, 23 25 .tALS_min = 50000, ··· 60 58 { 61 59 .type = NAND_SDR_IFACE, 62 60 .timings.sdr = { 61 + .tCCS_min = 500000, 62 + .tR_max = 200000000, 63 63 .tADL_min = 400000, 64 64 .tALH_min = 10000, 65 65 .tALS_min = 25000, ··· 102 98 { 103 99 .type = NAND_SDR_IFACE, 104 100 .timings.sdr = { 101 + .tCCS_min = 500000, 102 + .tR_max = 200000000, 105 103 .tADL_min = 400000, 106 104 .tALH_min = 10000, 107 105 .tALS_min = 15000, ··· 144 138 { 145 139 .type = NAND_SDR_IFACE, 146 140 .timings.sdr = { 141 + .tCCS_min = 500000, 142 + .tR_max = 200000000, 147 143 .tADL_min = 400000, 148 144 .tALH_min = 5000, 149 145 .tALS_min = 10000, ··· 186 178 { 187 179 .type = NAND_SDR_IFACE, 188 180 .timings.sdr = { 181 + .tCCS_min = 500000, 182 + .tR_max = 200000000, 189 183 .tADL_min = 400000, 190 184 .tALH_min = 5000, 191 185 .tALS_min = 10000, ··· 228 218 { 229 219 .type = NAND_SDR_IFACE, 230 220 .timings.sdr = { 221 + .tCCS_min = 500000, 222 + .tR_max = 200000000, 231 223 .tADL_min = 400000, 232 224 .tALH_min = 5000, 233 225 .tALS_min = 10000, ··· 302 290 *iface = onfi_sdr_timings[timing_mode]; 303 291 304 292 /* 305 - * TODO: initialize timings that cannot be deduced from timing mode: 293 + * Initialize timings that cannot be deduced from timing mode: 306 294 * tR, tPROG, tCCS, ... 307 295 * These information are part of the ONFI parameter page. 308 296 */ 297 + if (chip->onfi_version) { 298 + struct nand_onfi_params *params = &chip->onfi_params; 299 + struct nand_sdr_timings *timings = &iface->timings.sdr; 300 + 301 + /* microseconds -> picoseconds */ 302 + timings->tPROG_max = 1000000UL * le16_to_cpu(params->t_prog); 303 + timings->tBERS_max = 1000000UL * le16_to_cpu(params->t_bers); 304 + timings->tR_max = 1000000UL * le16_to_cpu(params->t_r); 305 + 306 + /* nanoseconds -> picoseconds */ 307 + timings->tCCS_min = 1000UL * le16_to_cpu(params->t_ccs); 308 + } 309 309 310 310 return 0; 311 311 }
+5 -14
drivers/mtd/nand/nandsim.c
··· 525 525 { 526 526 struct nandsim_debug_info *dbg = &dev->dbg; 527 527 struct dentry *dent; 528 - int err; 529 528 530 529 if (!IS_ENABLED(CONFIG_DEBUG_FS)) 531 530 return 0; 532 531 533 532 dent = debugfs_create_dir("nandsim", NULL); 534 - if (IS_ERR_OR_NULL(dent)) { 535 - int err = dent ? -ENODEV : PTR_ERR(dent); 536 - 537 - NS_ERR("cannot create \"nandsim\" debugfs directory, err %d\n", 538 - err); 539 - return err; 533 + if (!dent) { 534 + NS_ERR("cannot create \"nandsim\" debugfs directory\n"); 535 + return -ENODEV; 540 536 } 541 537 dbg->dfs_root = dent; 542 538 543 539 dent = debugfs_create_file("wear_report", S_IRUSR, 544 540 dbg->dfs_root, dev, &dfs_fops); 545 - if (IS_ERR_OR_NULL(dent)) 541 + if (!dent) 546 542 goto out_remove; 547 543 dbg->dfs_wear_report = dent; 548 544 ··· 546 550 547 551 out_remove: 548 552 debugfs_remove_recursive(dbg->dfs_root); 549 - err = dent ? PTR_ERR(dent) : -ENODEV; 550 - return err; 553 + return -ENODEV; 551 554 } 552 555 553 556 /** ··· 2308 2313 retval = nand_scan_ident(nsmtd, 1, NULL); 2309 2314 if (retval) { 2310 2315 NS_ERR("cannot scan NAND Simulator device\n"); 2311 - if (retval > 0) 2312 - retval = -ENXIO; 2313 2316 goto error; 2314 2317 } 2315 2318 ··· 2343 2350 retval = nand_scan_tail(nsmtd); 2344 2351 if (retval) { 2345 2352 NS_ERR("can't register NAND Simulator\n"); 2346 - if (retval > 0) 2347 - retval = -ENXIO; 2348 2353 goto error; 2349 2354 } 2350 2355
+5 -5
drivers/mtd/nand/omap2.c
··· 1895 1895 1896 1896 /* scan NAND device connected to chip controller */ 1897 1897 nand_chip->options |= info->devsize & NAND_BUSWIDTH_16; 1898 - if (nand_scan_ident(mtd, 1, NULL)) { 1898 + err = nand_scan_ident(mtd, 1, NULL); 1899 + if (err) { 1899 1900 dev_err(&info->pdev->dev, 1900 1901 "scan failed, may be bus-width mismatch\n"); 1901 - err = -ENXIO; 1902 1902 goto return_error; 1903 1903 } 1904 1904 ··· 2154 2154 2155 2155 scan_tail: 2156 2156 /* second phase scan */ 2157 - if (nand_scan_tail(mtd)) { 2158 - err = -ENXIO; 2157 + err = nand_scan_tail(mtd); 2158 + if (err) 2159 2159 goto return_error; 2160 - } 2161 2160 2162 2161 if (dev->of_node) 2163 2162 mtd_device_register(mtd, NULL, 0); ··· 2196 2197 { .compatible = "ti,omap2-nand", }, 2197 2198 {}, 2198 2199 }; 2200 + MODULE_DEVICE_TABLE(of, omap_nand_ids); 2199 2201 2200 2202 static struct platform_driver omap_nand_driver = { 2201 2203 .probe = omap_nand_probe,
+2 -3
drivers/mtd/nand/orion_nand.c
··· 155 155 clk_put(clk); 156 156 } 157 157 158 - if (nand_scan(mtd, 1)) { 159 - ret = -ENXIO; 158 + ret = nand_scan(mtd, 1); 159 + if (ret) 160 160 goto no_dev; 161 - } 162 161 163 162 mtd->name = "orion_nand"; 164 163 ret = mtd_device_register(mtd, board->parts, board->nr_parts);
+195
drivers/mtd/nand/oxnas_nand.c
··· 1 + /* 2 + * Oxford Semiconductor OXNAS NAND driver 3 + 4 + * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com> 5 + * Heavily based on plat_nand.c : 6 + * Author: Vitaly Wool <vitalywool@gmail.com> 7 + * Copyright (C) 2013 Ma Haijun <mahaijuns@gmail.com> 8 + * Copyright (C) 2012 John Crispin <blogic@openwrt.org> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + */ 15 + 16 + #include <linux/err.h> 17 + #include <linux/io.h> 18 + #include <linux/module.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/slab.h> 21 + #include <linux/clk.h> 22 + #include <linux/reset.h> 23 + #include <linux/mtd/mtd.h> 24 + #include <linux/mtd/nand.h> 25 + #include <linux/mtd/partitions.h> 26 + #include <linux/of.h> 27 + 28 + /* Nand commands */ 29 + #define OXNAS_NAND_CMD_ALE BIT(18) 30 + #define OXNAS_NAND_CMD_CLE BIT(19) 31 + 32 + #define OXNAS_NAND_MAX_CHIPS 1 33 + 34 + struct oxnas_nand_ctrl { 35 + struct nand_hw_control base; 36 + void __iomem *io_base; 37 + struct clk *clk; 38 + struct nand_chip *chips[OXNAS_NAND_MAX_CHIPS]; 39 + }; 40 + 41 + static uint8_t oxnas_nand_read_byte(struct mtd_info *mtd) 42 + { 43 + struct nand_chip *chip = mtd_to_nand(mtd); 44 + struct oxnas_nand_ctrl *oxnas = nand_get_controller_data(chip); 45 + 46 + return readb(oxnas->io_base); 47 + } 48 + 49 + static void oxnas_nand_read_buf(struct mtd_info *mtd, u8 *buf, int len) 50 + { 51 + struct nand_chip *chip = mtd_to_nand(mtd); 52 + struct oxnas_nand_ctrl *oxnas = nand_get_controller_data(chip); 53 + 54 + ioread8_rep(oxnas->io_base, buf, len); 55 + } 56 + 57 + static void oxnas_nand_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 58 + { 59 + struct nand_chip *chip = mtd_to_nand(mtd); 60 + struct oxnas_nand_ctrl *oxnas = nand_get_controller_data(chip); 61 + 62 + iowrite8_rep(oxnas->io_base, buf, len); 63 + } 64 + 65 + /* Single CS command control */ 66 + static void oxnas_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 67 + unsigned int ctrl) 68 + { 69 + struct nand_chip *chip = mtd_to_nand(mtd); 70 + struct oxnas_nand_ctrl *oxnas = nand_get_controller_data(chip); 71 + 72 + if (ctrl & NAND_CLE) 73 + writeb(cmd, oxnas->io_base + OXNAS_NAND_CMD_CLE); 74 + else if (ctrl & NAND_ALE) 75 + writeb(cmd, oxnas->io_base + OXNAS_NAND_CMD_ALE); 76 + } 77 + 78 + /* 79 + * Probe for the NAND device. 80 + */ 81 + static int oxnas_nand_probe(struct platform_device *pdev) 82 + { 83 + struct device_node *np = pdev->dev.of_node; 84 + struct device_node *nand_np; 85 + struct oxnas_nand_ctrl *oxnas; 86 + struct nand_chip *chip; 87 + struct mtd_info *mtd; 88 + struct resource *res; 89 + int nchips = 0; 90 + int count = 0; 91 + int err = 0; 92 + 93 + /* Allocate memory for the device structure (and zero it) */ 94 + oxnas = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip), 95 + GFP_KERNEL); 96 + if (!oxnas) 97 + return -ENOMEM; 98 + 99 + nand_hw_control_init(&oxnas->base); 100 + 101 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 102 + oxnas->io_base = devm_ioremap_resource(&pdev->dev, res); 103 + if (IS_ERR(oxnas->io_base)) 104 + return PTR_ERR(oxnas->io_base); 105 + 106 + oxnas->clk = devm_clk_get(&pdev->dev, NULL); 107 + if (IS_ERR(oxnas->clk)) 108 + oxnas->clk = NULL; 109 + 110 + /* Only a single chip node is supported */ 111 + count = of_get_child_count(np); 112 + if (count > 1) 113 + return -EINVAL; 114 + 115 + clk_prepare_enable(oxnas->clk); 116 + device_reset_optional(&pdev->dev); 117 + 118 + for_each_child_of_node(np, nand_np) { 119 + chip = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip), 120 + GFP_KERNEL); 121 + if (!chip) 122 + return -ENOMEM; 123 + 124 + chip->controller = &oxnas->base; 125 + 126 + nand_set_flash_node(chip, nand_np); 127 + nand_set_controller_data(chip, oxnas); 128 + 129 + mtd = nand_to_mtd(chip); 130 + mtd->dev.parent = &pdev->dev; 131 + mtd->priv = chip; 132 + 133 + chip->cmd_ctrl = oxnas_nand_cmd_ctrl; 134 + chip->read_buf = oxnas_nand_read_buf; 135 + chip->read_byte = oxnas_nand_read_byte; 136 + chip->write_buf = oxnas_nand_write_buf; 137 + chip->chip_delay = 30; 138 + 139 + /* Scan to find existence of the device */ 140 + err = nand_scan(mtd, 1); 141 + if (err) 142 + return err; 143 + 144 + err = mtd_device_register(mtd, NULL, 0); 145 + if (err) { 146 + nand_release(mtd); 147 + return err; 148 + } 149 + 150 + oxnas->chips[nchips] = chip; 151 + ++nchips; 152 + } 153 + 154 + /* Exit if no chips found */ 155 + if (!nchips) 156 + return -ENODEV; 157 + 158 + platform_set_drvdata(pdev, oxnas); 159 + 160 + return 0; 161 + } 162 + 163 + static int oxnas_nand_remove(struct platform_device *pdev) 164 + { 165 + struct oxnas_nand_ctrl *oxnas = platform_get_drvdata(pdev); 166 + 167 + if (oxnas->chips[0]) 168 + nand_release(nand_to_mtd(oxnas->chips[0])); 169 + 170 + clk_disable_unprepare(oxnas->clk); 171 + 172 + return 0; 173 + } 174 + 175 + static const struct of_device_id oxnas_nand_match[] = { 176 + { .compatible = "oxsemi,ox820-nand" }, 177 + {}, 178 + }; 179 + MODULE_DEVICE_TABLE(of, oxnas_nand_match); 180 + 181 + static struct platform_driver oxnas_nand_driver = { 182 + .probe = oxnas_nand_probe, 183 + .remove = oxnas_nand_remove, 184 + .driver = { 185 + .name = "oxnas_nand", 186 + .of_match_table = oxnas_nand_match, 187 + }, 188 + }; 189 + 190 + module_platform_driver(oxnas_nand_driver); 191 + 192 + MODULE_LICENSE("GPL"); 193 + MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); 194 + MODULE_DESCRIPTION("Oxnas NAND driver"); 195 + MODULE_ALIAS("platform:oxnas_nand");
+2 -3
drivers/mtd/nand/pasemi_nand.c
··· 156 156 chip->bbt_options = NAND_BBT_USE_FLASH; 157 157 158 158 /* Scan to find existence of the device */ 159 - if (nand_scan(pasemi_nand_mtd, 1)) { 160 - err = -ENXIO; 159 + err = nand_scan(pasemi_nand_mtd, 1); 160 + if (err) 161 161 goto out_lpc; 162 - } 163 162 164 163 if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) { 165 164 dev_err(dev, "Unable to register MTD device\n");
+2 -3
drivers/mtd/nand/plat_nand.c
··· 86 86 } 87 87 88 88 /* Scan to find existence of the device */ 89 - if (nand_scan(mtd, pdata->chip.nr_chips)) { 90 - err = -ENXIO; 89 + err = nand_scan(mtd, pdata->chip.nr_chips); 90 + if (err) 91 91 goto out; 92 - } 93 92 94 93 part_types = pdata->chip.part_probe_types; 95 94
+13 -9
drivers/mtd/nand/pxa3xx_nand.c
··· 1680 1680 chip->ecc.strength = pdata->ecc_strength; 1681 1681 chip->ecc.size = pdata->ecc_step_size; 1682 1682 1683 - if (nand_scan_ident(mtd, 1, NULL)) 1684 - return -ENODEV; 1683 + ret = nand_scan_ident(mtd, 1, NULL); 1684 + if (ret) 1685 + return ret; 1685 1686 1686 1687 if (!pdata->keep_config) { 1687 1688 ret = pxa3xx_nand_init(host); ··· 1775 1774 int ret, irq, cs; 1776 1775 1777 1776 pdata = dev_get_platdata(&pdev->dev); 1778 - if (pdata->num_cs <= 0) 1777 + if (pdata->num_cs <= 0) { 1778 + dev_err(&pdev->dev, "invalid number of chip selects\n"); 1779 1779 return -ENODEV; 1780 + } 1781 + 1780 1782 info = devm_kzalloc(&pdev->dev, 1781 1783 sizeof(*info) + sizeof(*host) * pdata->num_cs, 1782 1784 GFP_KERNEL); ··· 1817 1813 nand_hw_control_init(chip->controller); 1818 1814 info->clk = devm_clk_get(&pdev->dev, NULL); 1819 1815 if (IS_ERR(info->clk)) { 1820 - dev_err(&pdev->dev, "failed to get nand clock\n"); 1821 - return PTR_ERR(info->clk); 1816 + ret = PTR_ERR(info->clk); 1817 + dev_err(&pdev->dev, "failed to get nand clock: %d\n", ret); 1818 + return ret; 1822 1819 } 1823 1820 ret = clk_prepare_enable(info->clk); 1824 1821 if (ret < 0) ··· 1847 1842 info->mmio_base = devm_ioremap_resource(&pdev->dev, r); 1848 1843 if (IS_ERR(info->mmio_base)) { 1849 1844 ret = PTR_ERR(info->mmio_base); 1845 + dev_err(&pdev->dev, "failed to map register space: %d\n", ret); 1850 1846 goto fail_disable_clk; 1851 1847 } 1852 1848 info->mmio_phys = r->start; ··· 1867 1861 pxa3xx_nand_irq_thread, IRQF_ONESHOT, 1868 1862 pdev->name, info); 1869 1863 if (ret < 0) { 1870 - dev_err(&pdev->dev, "failed to request IRQ\n"); 1864 + dev_err(&pdev->dev, "failed to request IRQ: %d\n", ret); 1871 1865 goto fail_free_buf; 1872 1866 } 1873 1867 ··· 1966 1960 } 1967 1961 1968 1962 ret = alloc_nand_resource(pdev); 1969 - if (ret) { 1970 - dev_err(&pdev->dev, "alloc nand resource failed\n"); 1963 + if (ret) 1971 1964 return ret; 1972 - } 1973 1965 1974 1966 info = platform_get_drvdata(pdev); 1975 1967 probe_success = 0;
+209 -77
drivers/mtd/nand/s3c2410.c
··· 39 39 #include <linux/slab.h> 40 40 #include <linux/clk.h> 41 41 #include <linux/cpufreq.h> 42 + #include <linux/of.h> 43 + #include <linux/of_device.h> 42 44 43 45 #include <linux/mtd/mtd.h> 44 46 #include <linux/mtd/nand.h> ··· 185 183 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ 186 184 struct notifier_block freq_transition; 187 185 #endif 186 + }; 187 + 188 + struct s3c24XX_nand_devtype_data { 189 + enum s3c_cpu_type type; 190 + }; 191 + 192 + static const struct s3c24XX_nand_devtype_data s3c2410_nand_devtype_data = { 193 + .type = TYPE_S3C2410, 194 + }; 195 + 196 + static const struct s3c24XX_nand_devtype_data s3c2412_nand_devtype_data = { 197 + .type = TYPE_S3C2412, 198 + }; 199 + 200 + static const struct s3c24XX_nand_devtype_data s3c2440_nand_devtype_data = { 201 + .type = TYPE_S3C2440, 188 202 }; 189 203 190 204 /* conversion functions */ ··· 515 497 516 498 /* ECC handling functions */ 517 499 518 - #ifdef CONFIG_MTD_NAND_S3C2410_HWECC 519 500 static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, 520 501 u_char *read_ecc, u_char *calc_ecc) 521 502 { ··· 666 649 667 650 return 0; 668 651 } 669 - #endif 670 652 671 653 /* over-ride the standard functions for a little more speed. We can 672 654 * use read/write block to move the data buffers to/from the controller ··· 812 796 return -ENODEV; 813 797 } 814 798 799 + static int s3c2410_nand_setup_data_interface(struct mtd_info *mtd, 800 + const struct nand_data_interface *conf, 801 + bool check_only) 802 + { 803 + struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 804 + struct s3c2410_platform_nand *pdata = info->platform; 805 + const struct nand_sdr_timings *timings; 806 + int tacls; 807 + 808 + timings = nand_get_sdr_timings(conf); 809 + if (IS_ERR(timings)) 810 + return -ENOTSUPP; 811 + 812 + tacls = timings->tCLS_min - timings->tWP_min; 813 + if (tacls < 0) 814 + tacls = 0; 815 + 816 + pdata->tacls = DIV_ROUND_UP(tacls, 1000); 817 + pdata->twrph0 = DIV_ROUND_UP(timings->tWP_min, 1000); 818 + pdata->twrph1 = DIV_ROUND_UP(timings->tCLH_min, 1000); 819 + 820 + return s3c2410_nand_setrate(info); 821 + } 822 + 815 823 /** 816 824 * s3c2410_nand_init_chip - initialise a single instance of an chip 817 825 * @info: The base NAND controller the chip is on. ··· 850 810 struct s3c2410_nand_mtd *nmtd, 851 811 struct s3c2410_nand_set *set) 852 812 { 813 + struct device_node *np = info->device->of_node; 853 814 struct nand_chip *chip = &nmtd->chip; 854 815 void __iomem *regs = info->regs; 816 + 817 + nand_set_flash_node(chip, set->of_node); 855 818 856 819 chip->write_buf = s3c2410_nand_write_buf; 857 820 chip->read_buf = s3c2410_nand_read_buf; ··· 863 820 nand_set_controller_data(chip, nmtd); 864 821 chip->options = set->options; 865 822 chip->controller = &info->controller; 823 + 824 + /* 825 + * let's keep behavior unchanged for legacy boards booting via pdata and 826 + * auto-detect timings only when booting with a device tree. 827 + */ 828 + if (np) 829 + chip->setup_data_interface = s3c2410_nand_setup_data_interface; 866 830 867 831 switch (info->cpu_type) { 868 832 case TYPE_S3C2410: ··· 908 858 nmtd->info = info; 909 859 nmtd->set = set; 910 860 911 - #ifdef CONFIG_MTD_NAND_S3C2410_HWECC 912 - chip->ecc.calculate = s3c2410_nand_calculate_ecc; 913 - chip->ecc.correct = s3c2410_nand_correct_data; 914 - chip->ecc.mode = NAND_ECC_HW; 915 - chip->ecc.strength = 1; 861 + chip->ecc.mode = info->platform->ecc_mode; 916 862 917 - switch (info->cpu_type) { 918 - case TYPE_S3C2410: 919 - chip->ecc.hwctl = s3c2410_nand_enable_hwecc; 920 - chip->ecc.calculate = s3c2410_nand_calculate_ecc; 921 - break; 922 - 923 - case TYPE_S3C2412: 924 - chip->ecc.hwctl = s3c2412_nand_enable_hwecc; 925 - chip->ecc.calculate = s3c2412_nand_calculate_ecc; 926 - break; 927 - 928 - case TYPE_S3C2440: 929 - chip->ecc.hwctl = s3c2440_nand_enable_hwecc; 930 - chip->ecc.calculate = s3c2440_nand_calculate_ecc; 931 - break; 932 - } 933 - #else 934 - chip->ecc.mode = NAND_ECC_SOFT; 935 - chip->ecc.algo = NAND_ECC_HAMMING; 936 - #endif 937 - 938 - if (set->disable_ecc) 939 - chip->ecc.mode = NAND_ECC_NONE; 940 - 941 - switch (chip->ecc.mode) { 942 - case NAND_ECC_NONE: 943 - dev_info(info->device, "NAND ECC disabled\n"); 944 - break; 945 - case NAND_ECC_SOFT: 946 - dev_info(info->device, "NAND soft ECC\n"); 947 - break; 948 - case NAND_ECC_HW: 949 - dev_info(info->device, "NAND hardware ECC\n"); 950 - break; 951 - default: 952 - dev_info(info->device, "NAND ECC UNKNOWN\n"); 953 - break; 954 - } 955 - 956 - /* If you use u-boot BBT creation code, specifying this flag will 957 - * let the kernel fish out the BBT from the NAND, and also skip the 958 - * full NAND scan that can take 1/2s or so. Little things... */ 959 - if (set->flash_bbt) { 863 + /* 864 + * If you use u-boot BBT creation code, specifying this flag will 865 + * let the kernel fish out the BBT from the NAND. 866 + */ 867 + if (set->flash_bbt) 960 868 chip->bbt_options |= NAND_BBT_USE_FLASH; 961 - chip->options |= NAND_SKIP_BBTSCAN; 962 - } 963 869 } 964 870 965 871 /** ··· 929 923 * 930 924 * The internal state is currently limited to the ECC state information. 931 925 */ 932 - static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info, 933 - struct s3c2410_nand_mtd *nmtd) 926 + static int s3c2410_nand_update_chip(struct s3c2410_nand_info *info, 927 + struct s3c2410_nand_mtd *nmtd) 934 928 { 935 929 struct nand_chip *chip = &nmtd->chip; 936 930 937 - dev_dbg(info->device, "chip %p => page shift %d\n", 938 - chip, chip->page_shift); 931 + switch (chip->ecc.mode) { 939 932 940 - if (chip->ecc.mode != NAND_ECC_HW) 941 - return; 933 + case NAND_ECC_NONE: 934 + dev_info(info->device, "ECC disabled\n"); 935 + break; 936 + 937 + case NAND_ECC_SOFT: 938 + /* 939 + * This driver expects Hamming based ECC when ecc_mode is set 940 + * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to 941 + * avoid adding an extra ecc_algo field to 942 + * s3c2410_platform_nand. 943 + */ 944 + chip->ecc.algo = NAND_ECC_HAMMING; 945 + dev_info(info->device, "soft ECC\n"); 946 + break; 947 + 948 + case NAND_ECC_HW: 949 + chip->ecc.calculate = s3c2410_nand_calculate_ecc; 950 + chip->ecc.correct = s3c2410_nand_correct_data; 951 + chip->ecc.strength = 1; 952 + 953 + switch (info->cpu_type) { 954 + case TYPE_S3C2410: 955 + chip->ecc.hwctl = s3c2410_nand_enable_hwecc; 956 + chip->ecc.calculate = s3c2410_nand_calculate_ecc; 957 + break; 958 + 959 + case TYPE_S3C2412: 960 + chip->ecc.hwctl = s3c2412_nand_enable_hwecc; 961 + chip->ecc.calculate = s3c2412_nand_calculate_ecc; 962 + break; 963 + 964 + case TYPE_S3C2440: 965 + chip->ecc.hwctl = s3c2440_nand_enable_hwecc; 966 + chip->ecc.calculate = s3c2440_nand_calculate_ecc; 967 + break; 968 + } 969 + 970 + dev_dbg(info->device, "chip %p => page shift %d\n", 971 + chip, chip->page_shift); 942 972 943 973 /* change the behaviour depending on whether we are using 944 974 * the large or small page nand device */ 975 + if (chip->page_shift > 10) { 976 + chip->ecc.size = 256; 977 + chip->ecc.bytes = 3; 978 + } else { 979 + chip->ecc.size = 512; 980 + chip->ecc.bytes = 3; 981 + mtd_set_ooblayout(nand_to_mtd(chip), 982 + &s3c2410_ooblayout_ops); 983 + } 945 984 946 - if (chip->page_shift > 10) { 947 - chip->ecc.size = 256; 948 - chip->ecc.bytes = 3; 949 - } else { 950 - chip->ecc.size = 512; 951 - chip->ecc.bytes = 3; 952 - mtd_set_ooblayout(nand_to_mtd(chip), &s3c2410_ooblayout_ops); 985 + dev_info(info->device, "hardware ECC\n"); 986 + break; 987 + 988 + default: 989 + dev_err(info->device, "invalid ECC mode!\n"); 990 + return -EINVAL; 953 991 } 992 + 993 + if (chip->bbt_options & NAND_BBT_USE_FLASH) 994 + chip->options |= NAND_SKIP_BBTSCAN; 995 + 996 + return 0; 997 + } 998 + 999 + static const struct of_device_id s3c24xx_nand_dt_ids[] = { 1000 + { 1001 + .compatible = "samsung,s3c2410-nand", 1002 + .data = &s3c2410_nand_devtype_data, 1003 + }, { 1004 + /* also compatible with s3c6400 */ 1005 + .compatible = "samsung,s3c2412-nand", 1006 + .data = &s3c2412_nand_devtype_data, 1007 + }, { 1008 + .compatible = "samsung,s3c2440-nand", 1009 + .data = &s3c2440_nand_devtype_data, 1010 + }, 1011 + { /* sentinel */ } 1012 + }; 1013 + MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids); 1014 + 1015 + static int s3c24xx_nand_probe_dt(struct platform_device *pdev) 1016 + { 1017 + const struct s3c24XX_nand_devtype_data *devtype_data; 1018 + struct s3c2410_platform_nand *pdata; 1019 + struct s3c2410_nand_info *info = platform_get_drvdata(pdev); 1020 + struct device_node *np = pdev->dev.of_node, *child; 1021 + struct s3c2410_nand_set *sets; 1022 + 1023 + devtype_data = of_device_get_match_data(&pdev->dev); 1024 + if (!devtype_data) 1025 + return -ENODEV; 1026 + 1027 + info->cpu_type = devtype_data->type; 1028 + 1029 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1030 + if (!pdata) 1031 + return -ENOMEM; 1032 + 1033 + pdev->dev.platform_data = pdata; 1034 + 1035 + pdata->nr_sets = of_get_child_count(np); 1036 + if (!pdata->nr_sets) 1037 + return 0; 1038 + 1039 + sets = devm_kzalloc(&pdev->dev, sizeof(*sets) * pdata->nr_sets, 1040 + GFP_KERNEL); 1041 + if (!sets) 1042 + return -ENOMEM; 1043 + 1044 + pdata->sets = sets; 1045 + 1046 + for_each_available_child_of_node(np, child) { 1047 + sets->name = (char *)child->name; 1048 + sets->of_node = child; 1049 + sets->nr_chips = 1; 1050 + 1051 + of_node_get(child); 1052 + 1053 + sets++; 1054 + } 1055 + 1056 + return 0; 1057 + } 1058 + 1059 + static int s3c24xx_nand_probe_pdata(struct platform_device *pdev) 1060 + { 1061 + struct s3c2410_nand_info *info = platform_get_drvdata(pdev); 1062 + 1063 + info->cpu_type = platform_get_device_id(pdev)->driver_data; 1064 + 1065 + return 0; 954 1066 } 955 1067 956 1068 /* s3c24xx_nand_probe ··· 1080 956 */ 1081 957 static int s3c24xx_nand_probe(struct platform_device *pdev) 1082 958 { 1083 - struct s3c2410_platform_nand *plat = to_nand_plat(pdev); 1084 - enum s3c_cpu_type cpu_type; 959 + struct s3c2410_platform_nand *plat; 1085 960 struct s3c2410_nand_info *info; 1086 961 struct s3c2410_nand_mtd *nmtd; 1087 962 struct s3c2410_nand_set *sets; ··· 1089 966 int size; 1090 967 int nr_sets; 1091 968 int setno; 1092 - 1093 - cpu_type = platform_get_device_id(pdev)->driver_data; 1094 969 1095 970 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 1096 971 if (info == NULL) { ··· 1111 990 1112 991 s3c2410_nand_clk_set_state(info, CLOCK_ENABLE); 1113 992 993 + if (pdev->dev.of_node) 994 + err = s3c24xx_nand_probe_dt(pdev); 995 + else 996 + err = s3c24xx_nand_probe_pdata(pdev); 997 + 998 + if (err) 999 + goto exit_error; 1000 + 1001 + plat = to_nand_plat(pdev); 1002 + 1114 1003 /* allocate and map the resource */ 1115 1004 1116 1005 /* currently we assume we have the one resource */ ··· 1129 998 1130 999 info->device = &pdev->dev; 1131 1000 info->platform = plat; 1132 - info->cpu_type = cpu_type; 1133 1001 1134 1002 info->regs = devm_ioremap_resource(&pdev->dev, res); 1135 1003 if (IS_ERR(info->regs)) { ··· 1137 1007 } 1138 1008 1139 1009 dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs); 1140 - 1141 - /* initialise the hardware */ 1142 - 1143 - err = s3c2410_nand_inithw(info); 1144 - if (err != 0) 1145 - goto exit_error; 1146 1010 1147 1011 sets = (plat != NULL) ? plat->sets : NULL; 1148 1012 nr_sets = (plat != NULL) ? plat->nr_sets : 1; ··· 1170 1046 NULL); 1171 1047 1172 1048 if (nmtd->scan_res == 0) { 1173 - s3c2410_nand_update_chip(info, nmtd); 1049 + err = s3c2410_nand_update_chip(info, nmtd); 1050 + if (err < 0) 1051 + goto exit_error; 1174 1052 nand_scan_tail(mtd); 1175 1053 s3c2410_nand_add_partition(info, nmtd, sets); 1176 1054 } ··· 1180 1054 if (sets != NULL) 1181 1055 sets++; 1182 1056 } 1057 + 1058 + /* initialise the hardware */ 1059 + err = s3c2410_nand_inithw(info); 1060 + if (err != 0) 1061 + goto exit_error; 1183 1062 1184 1063 err = s3c2410_nand_cpufreq_register(info); 1185 1064 if (err < 0) { ··· 1286 1155 .id_table = s3c24xx_driver_ids, 1287 1156 .driver = { 1288 1157 .name = "s3c24xx-nand", 1158 + .of_match_table = s3c24xx_nand_dt_ids, 1289 1159 }, 1290 1160 }; 1291 1161
+2 -10
drivers/mtd/nand/socrates_nand.c
··· 187 187 188 188 dev_set_drvdata(&ofdev->dev, host); 189 189 190 - /* first scan to find the device and get the page size */ 191 - if (nand_scan_ident(mtd, 1, NULL)) { 192 - res = -ENXIO; 190 + res = nand_scan(mtd, 1); 191 + if (res) 193 192 goto out; 194 - } 195 - 196 - /* second phase scan */ 197 - if (nand_scan_tail(mtd)) { 198 - res = -ENXIO; 199 - goto out; 200 - } 201 193 202 194 res = mtd_device_register(mtd, NULL, 0); 203 195 if (!res)
+4
drivers/mtd/nand/sunxi_nand.c
··· 145 145 #define NFC_ECC_PIPELINE BIT(3) 146 146 #define NFC_ECC_EXCEPTION BIT(4) 147 147 #define NFC_ECC_BLOCK_SIZE_MSK BIT(5) 148 + #define NFC_ECC_BLOCK_512 BIT(5) 148 149 #define NFC_RANDOM_EN BIT(9) 149 150 #define NFC_RANDOM_DIRECTION BIT(10) 150 151 #define NFC_ECC_MODE_MSK GENMASK(15, 12) ··· 817 816 NFC_ECC_BLOCK_SIZE_MSK); 818 817 ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(data->mode) | NFC_ECC_EXCEPTION | 819 818 NFC_ECC_PIPELINE; 819 + 820 + if (nand->ecc.size == 512) 821 + ecc_ctl |= NFC_ECC_BLOCK_512; 820 822 821 823 writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); 822 824 }
+676
drivers/mtd/nand/tango_nand.c
··· 1 + /* 2 + * Copyright (C) 2016 Sigma Designs 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * version 2 as published by the Free Software Foundation. 7 + */ 8 + 9 + #include <linux/io.h> 10 + #include <linux/of.h> 11 + #include <linux/clk.h> 12 + #include <linux/iopoll.h> 13 + #include <linux/module.h> 14 + #include <linux/mtd/nand.h> 15 + #include <linux/dmaengine.h> 16 + #include <linux/dma-mapping.h> 17 + #include <linux/platform_device.h> 18 + 19 + /* Offsets relative to chip->base */ 20 + #define PBUS_CMD 0 21 + #define PBUS_ADDR 4 22 + #define PBUS_DATA 8 23 + 24 + /* Offsets relative to reg_base */ 25 + #define NFC_STATUS 0x00 26 + #define NFC_FLASH_CMD 0x04 27 + #define NFC_DEVICE_CFG 0x08 28 + #define NFC_TIMING1 0x0c 29 + #define NFC_TIMING2 0x10 30 + #define NFC_XFER_CFG 0x14 31 + #define NFC_PKT_0_CFG 0x18 32 + #define NFC_PKT_N_CFG 0x1c 33 + #define NFC_BB_CFG 0x20 34 + #define NFC_ADDR_PAGE 0x24 35 + #define NFC_ADDR_OFFSET 0x28 36 + #define NFC_XFER_STATUS 0x2c 37 + 38 + /* NFC_STATUS values */ 39 + #define CMD_READY BIT(31) 40 + 41 + /* NFC_FLASH_CMD values */ 42 + #define NFC_READ 1 43 + #define NFC_WRITE 2 44 + 45 + /* NFC_XFER_STATUS values */ 46 + #define PAGE_IS_EMPTY BIT(16) 47 + 48 + /* Offsets relative to mem_base */ 49 + #define METADATA 0x000 50 + #define ERROR_REPORT 0x1c0 51 + 52 + /* 53 + * Error reports are split in two bytes: 54 + * byte 0 for the first packet in the page (PKT_0) 55 + * byte 1 for other packets in the page (PKT_N, for N > 0) 56 + * ERR_COUNT_PKT_N is the max error count over all but the first packet. 57 + */ 58 + #define DECODE_OK_PKT_0(v) ((v) & BIT(7)) 59 + #define DECODE_OK_PKT_N(v) ((v) & BIT(15)) 60 + #define ERR_COUNT_PKT_0(v) (((v) >> 0) & 0x3f) 61 + #define ERR_COUNT_PKT_N(v) (((v) >> 8) & 0x3f) 62 + 63 + /* Offsets relative to pbus_base */ 64 + #define PBUS_CS_CTRL 0x83c 65 + #define PBUS_PAD_MODE 0x8f0 66 + 67 + /* PBUS_CS_CTRL values */ 68 + #define PBUS_IORDY BIT(31) 69 + 70 + /* 71 + * PBUS_PAD_MODE values 72 + * In raw mode, the driver communicates directly with the NAND chips. 73 + * In NFC mode, the NAND Flash controller manages the communication. 74 + * We use NFC mode for read and write; raw mode for everything else. 75 + */ 76 + #define MODE_RAW 0 77 + #define MODE_NFC BIT(31) 78 + 79 + #define METADATA_SIZE 4 80 + #define BBM_SIZE 6 81 + #define FIELD_ORDER 15 82 + 83 + #define MAX_CS 4 84 + 85 + struct tango_nfc { 86 + struct nand_hw_control hw; 87 + void __iomem *reg_base; 88 + void __iomem *mem_base; 89 + void __iomem *pbus_base; 90 + struct tango_chip *chips[MAX_CS]; 91 + struct dma_chan *chan; 92 + int freq_kHz; 93 + }; 94 + 95 + #define to_tango_nfc(ptr) container_of(ptr, struct tango_nfc, hw) 96 + 97 + struct tango_chip { 98 + struct nand_chip nand_chip; 99 + void __iomem *base; 100 + u32 timing1; 101 + u32 timing2; 102 + u32 xfer_cfg; 103 + u32 pkt_0_cfg; 104 + u32 pkt_n_cfg; 105 + u32 bb_cfg; 106 + }; 107 + 108 + #define to_tango_chip(ptr) container_of(ptr, struct tango_chip, nand_chip) 109 + 110 + #define XFER_CFG(cs, page_count, steps, metadata_size) \ 111 + ((cs) << 24 | (page_count) << 16 | (steps) << 8 | (metadata_size)) 112 + 113 + #define PKT_CFG(size, strength) ((size) << 16 | (strength)) 114 + 115 + #define BB_CFG(bb_offset, bb_size) ((bb_offset) << 16 | (bb_size)) 116 + 117 + #define TIMING(t0, t1, t2, t3) ((t0) << 24 | (t1) << 16 | (t2) << 8 | (t3)) 118 + 119 + static void tango_cmd_ctrl(struct mtd_info *mtd, int dat, unsigned int ctrl) 120 + { 121 + struct tango_chip *tchip = to_tango_chip(mtd_to_nand(mtd)); 122 + 123 + if (ctrl & NAND_CLE) 124 + writeb_relaxed(dat, tchip->base + PBUS_CMD); 125 + 126 + if (ctrl & NAND_ALE) 127 + writeb_relaxed(dat, tchip->base + PBUS_ADDR); 128 + } 129 + 130 + static int tango_dev_ready(struct mtd_info *mtd) 131 + { 132 + struct nand_chip *chip = mtd_to_nand(mtd); 133 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 134 + 135 + return readl_relaxed(nfc->pbus_base + PBUS_CS_CTRL) & PBUS_IORDY; 136 + } 137 + 138 + static u8 tango_read_byte(struct mtd_info *mtd) 139 + { 140 + struct tango_chip *tchip = to_tango_chip(mtd_to_nand(mtd)); 141 + 142 + return readb_relaxed(tchip->base + PBUS_DATA); 143 + } 144 + 145 + static void tango_read_buf(struct mtd_info *mtd, u8 *buf, int len) 146 + { 147 + struct tango_chip *tchip = to_tango_chip(mtd_to_nand(mtd)); 148 + 149 + ioread8_rep(tchip->base + PBUS_DATA, buf, len); 150 + } 151 + 152 + static void tango_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 153 + { 154 + struct tango_chip *tchip = to_tango_chip(mtd_to_nand(mtd)); 155 + 156 + iowrite8_rep(tchip->base + PBUS_DATA, buf, len); 157 + } 158 + 159 + static void tango_select_chip(struct mtd_info *mtd, int idx) 160 + { 161 + struct nand_chip *chip = mtd_to_nand(mtd); 162 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 163 + struct tango_chip *tchip = to_tango_chip(chip); 164 + 165 + if (idx < 0) 166 + return; /* No "chip unselect" function */ 167 + 168 + writel_relaxed(tchip->timing1, nfc->reg_base + NFC_TIMING1); 169 + writel_relaxed(tchip->timing2, nfc->reg_base + NFC_TIMING2); 170 + writel_relaxed(tchip->xfer_cfg, nfc->reg_base + NFC_XFER_CFG); 171 + writel_relaxed(tchip->pkt_0_cfg, nfc->reg_base + NFC_PKT_0_CFG); 172 + writel_relaxed(tchip->pkt_n_cfg, nfc->reg_base + NFC_PKT_N_CFG); 173 + writel_relaxed(tchip->bb_cfg, nfc->reg_base + NFC_BB_CFG); 174 + } 175 + 176 + /* 177 + * The controller does not check for bitflips in erased pages, 178 + * therefore software must check instead. 179 + */ 180 + static int check_erased_page(struct nand_chip *chip, u8 *buf) 181 + { 182 + struct mtd_info *mtd = nand_to_mtd(chip); 183 + u8 *meta = chip->oob_poi + BBM_SIZE; 184 + u8 *ecc = chip->oob_poi + BBM_SIZE + METADATA_SIZE; 185 + const int ecc_size = chip->ecc.bytes; 186 + const int pkt_size = chip->ecc.size; 187 + int i, res, meta_len, bitflips = 0; 188 + 189 + for (i = 0; i < chip->ecc.steps; ++i) { 190 + meta_len = i ? 0 : METADATA_SIZE; 191 + res = nand_check_erased_ecc_chunk(buf, pkt_size, ecc, ecc_size, 192 + meta, meta_len, 193 + chip->ecc.strength); 194 + if (res < 0) 195 + mtd->ecc_stats.failed++; 196 + 197 + bitflips = max(res, bitflips); 198 + buf += pkt_size; 199 + ecc += ecc_size; 200 + } 201 + 202 + return bitflips; 203 + } 204 + 205 + static int decode_error_report(struct tango_nfc *nfc) 206 + { 207 + u32 status, res; 208 + 209 + status = readl_relaxed(nfc->reg_base + NFC_XFER_STATUS); 210 + if (status & PAGE_IS_EMPTY) 211 + return 0; 212 + 213 + res = readl_relaxed(nfc->mem_base + ERROR_REPORT); 214 + 215 + if (DECODE_OK_PKT_0(res) && DECODE_OK_PKT_N(res)) 216 + return max(ERR_COUNT_PKT_0(res), ERR_COUNT_PKT_N(res)); 217 + 218 + return -EBADMSG; 219 + } 220 + 221 + static void tango_dma_callback(void *arg) 222 + { 223 + complete(arg); 224 + } 225 + 226 + static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, 227 + int len, int page) 228 + { 229 + void __iomem *addr = nfc->reg_base + NFC_STATUS; 230 + struct dma_chan *chan = nfc->chan; 231 + struct dma_async_tx_descriptor *desc; 232 + struct scatterlist sg; 233 + struct completion tx_done; 234 + int err = -EIO; 235 + u32 res, val; 236 + 237 + sg_init_one(&sg, buf, len); 238 + if (dma_map_sg(chan->device->dev, &sg, 1, dir) != 1) 239 + return -EIO; 240 + 241 + desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir, DMA_PREP_INTERRUPT); 242 + if (!desc) 243 + goto dma_unmap; 244 + 245 + desc->callback = tango_dma_callback; 246 + desc->callback_param = &tx_done; 247 + init_completion(&tx_done); 248 + 249 + writel_relaxed(MODE_NFC, nfc->pbus_base + PBUS_PAD_MODE); 250 + 251 + writel_relaxed(page, nfc->reg_base + NFC_ADDR_PAGE); 252 + writel_relaxed(0, nfc->reg_base + NFC_ADDR_OFFSET); 253 + writel_relaxed(cmd, nfc->reg_base + NFC_FLASH_CMD); 254 + 255 + dmaengine_submit(desc); 256 + dma_async_issue_pending(chan); 257 + 258 + res = wait_for_completion_timeout(&tx_done, HZ); 259 + if (res > 0) 260 + err = readl_poll_timeout(addr, val, val & CMD_READY, 0, 1000); 261 + 262 + writel_relaxed(MODE_RAW, nfc->pbus_base + PBUS_PAD_MODE); 263 + 264 + dma_unmap: 265 + dma_unmap_sg(chan->device->dev, &sg, 1, dir); 266 + 267 + return err; 268 + } 269 + 270 + static int tango_read_page(struct mtd_info *mtd, struct nand_chip *chip, 271 + u8 *buf, int oob_required, int page) 272 + { 273 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 274 + int err, res, len = mtd->writesize; 275 + 276 + if (oob_required) 277 + chip->ecc.read_oob(mtd, chip, page); 278 + 279 + err = do_dma(nfc, DMA_FROM_DEVICE, NFC_READ, buf, len, page); 280 + if (err) 281 + return err; 282 + 283 + res = decode_error_report(nfc); 284 + if (res < 0) { 285 + chip->ecc.read_oob_raw(mtd, chip, page); 286 + res = check_erased_page(chip, buf); 287 + } 288 + 289 + return res; 290 + } 291 + 292 + static int tango_write_page(struct mtd_info *mtd, struct nand_chip *chip, 293 + const u8 *buf, int oob_required, int page) 294 + { 295 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 296 + int err, len = mtd->writesize; 297 + 298 + /* Calling tango_write_oob() would send PAGEPROG twice */ 299 + if (oob_required) 300 + return -ENOTSUPP; 301 + 302 + writel_relaxed(0xffffffff, nfc->mem_base + METADATA); 303 + err = do_dma(nfc, DMA_TO_DEVICE, NFC_WRITE, buf, len, page); 304 + if (err) 305 + return err; 306 + 307 + return 0; 308 + } 309 + 310 + static void aux_read(struct nand_chip *chip, u8 **buf, int len, int *pos) 311 + { 312 + struct mtd_info *mtd = nand_to_mtd(chip); 313 + 314 + *pos += len; 315 + 316 + if (!*buf) { 317 + /* skip over "len" bytes */ 318 + chip->cmdfunc(mtd, NAND_CMD_RNDOUT, *pos, -1); 319 + } else { 320 + tango_read_buf(mtd, *buf, len); 321 + *buf += len; 322 + } 323 + } 324 + 325 + static void aux_write(struct nand_chip *chip, const u8 **buf, int len, int *pos) 326 + { 327 + struct mtd_info *mtd = nand_to_mtd(chip); 328 + 329 + *pos += len; 330 + 331 + if (!*buf) { 332 + /* skip over "len" bytes */ 333 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, *pos, -1); 334 + } else { 335 + tango_write_buf(mtd, *buf, len); 336 + *buf += len; 337 + } 338 + } 339 + 340 + /* 341 + * Physical page layout (not drawn to scale) 342 + * 343 + * NB: Bad Block Marker area splits PKT_N in two (N1, N2). 344 + * 345 + * +---+-----------------+-------+-----+-----------+-----+----+-------+ 346 + * | M | PKT_0 | ECC_0 | ... | N1 | BBM | N2 | ECC_N | 347 + * +---+-----------------+-------+-----+-----------+-----+----+-------+ 348 + * 349 + * Logical page layout: 350 + * 351 + * +-----+---+-------+-----+-------+ 352 + * oob = | BBM | M | ECC_0 | ... | ECC_N | 353 + * +-----+---+-------+-----+-------+ 354 + * 355 + * +-----------------+-----+-----------------+ 356 + * buf = | PKT_0 | ... | PKT_N | 357 + * +-----------------+-----+-----------------+ 358 + */ 359 + static void raw_read(struct nand_chip *chip, u8 *buf, u8 *oob) 360 + { 361 + struct mtd_info *mtd = nand_to_mtd(chip); 362 + u8 *oob_orig = oob; 363 + const int page_size = mtd->writesize; 364 + const int ecc_size = chip->ecc.bytes; 365 + const int pkt_size = chip->ecc.size; 366 + int pos = 0; /* position within physical page */ 367 + int rem = page_size; /* bytes remaining until BBM area */ 368 + 369 + if (oob) 370 + oob += BBM_SIZE; 371 + 372 + aux_read(chip, &oob, METADATA_SIZE, &pos); 373 + 374 + while (rem > pkt_size) { 375 + aux_read(chip, &buf, pkt_size, &pos); 376 + aux_read(chip, &oob, ecc_size, &pos); 377 + rem = page_size - pos; 378 + } 379 + 380 + aux_read(chip, &buf, rem, &pos); 381 + aux_read(chip, &oob_orig, BBM_SIZE, &pos); 382 + aux_read(chip, &buf, pkt_size - rem, &pos); 383 + aux_read(chip, &oob, ecc_size, &pos); 384 + } 385 + 386 + static void raw_write(struct nand_chip *chip, const u8 *buf, const u8 *oob) 387 + { 388 + struct mtd_info *mtd = nand_to_mtd(chip); 389 + const u8 *oob_orig = oob; 390 + const int page_size = mtd->writesize; 391 + const int ecc_size = chip->ecc.bytes; 392 + const int pkt_size = chip->ecc.size; 393 + int pos = 0; /* position within physical page */ 394 + int rem = page_size; /* bytes remaining until BBM area */ 395 + 396 + if (oob) 397 + oob += BBM_SIZE; 398 + 399 + aux_write(chip, &oob, METADATA_SIZE, &pos); 400 + 401 + while (rem > pkt_size) { 402 + aux_write(chip, &buf, pkt_size, &pos); 403 + aux_write(chip, &oob, ecc_size, &pos); 404 + rem = page_size - pos; 405 + } 406 + 407 + aux_write(chip, &buf, rem, &pos); 408 + aux_write(chip, &oob_orig, BBM_SIZE, &pos); 409 + aux_write(chip, &buf, pkt_size - rem, &pos); 410 + aux_write(chip, &oob, ecc_size, &pos); 411 + } 412 + 413 + static int tango_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 414 + u8 *buf, int oob_required, int page) 415 + { 416 + chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page); 417 + raw_read(chip, buf, chip->oob_poi); 418 + return 0; 419 + } 420 + 421 + static int tango_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 422 + const u8 *buf, int oob_required, int page) 423 + { 424 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page); 425 + raw_write(chip, buf, chip->oob_poi); 426 + chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 427 + return 0; 428 + } 429 + 430 + static int tango_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 431 + int page) 432 + { 433 + chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page); 434 + raw_read(chip, NULL, chip->oob_poi); 435 + return 0; 436 + } 437 + 438 + static int tango_write_oob(struct mtd_info *mtd, struct nand_chip *chip, 439 + int page) 440 + { 441 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page); 442 + raw_write(chip, NULL, chip->oob_poi); 443 + chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 444 + chip->waitfunc(mtd, chip); 445 + return 0; 446 + } 447 + 448 + static int oob_ecc(struct mtd_info *mtd, int idx, struct mtd_oob_region *res) 449 + { 450 + struct nand_chip *chip = mtd_to_nand(mtd); 451 + struct nand_ecc_ctrl *ecc = &chip->ecc; 452 + 453 + if (idx >= ecc->steps) 454 + return -ERANGE; 455 + 456 + res->offset = BBM_SIZE + METADATA_SIZE + ecc->bytes * idx; 457 + res->length = ecc->bytes; 458 + 459 + return 0; 460 + } 461 + 462 + static int oob_free(struct mtd_info *mtd, int idx, struct mtd_oob_region *res) 463 + { 464 + return -ERANGE; /* no free space in spare area */ 465 + } 466 + 467 + static const struct mtd_ooblayout_ops tango_nand_ooblayout_ops = { 468 + .ecc = oob_ecc, 469 + .free = oob_free, 470 + }; 471 + 472 + static u32 to_ticks(int kHz, int ps) 473 + { 474 + return DIV_ROUND_UP_ULL((u64)kHz * ps, NSEC_PER_SEC); 475 + } 476 + 477 + static int tango_set_timings(struct mtd_info *mtd, 478 + const struct nand_data_interface *conf, 479 + bool check_only) 480 + { 481 + const struct nand_sdr_timings *sdr = nand_get_sdr_timings(conf); 482 + struct nand_chip *chip = mtd_to_nand(mtd); 483 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 484 + struct tango_chip *tchip = to_tango_chip(chip); 485 + u32 Trdy, Textw, Twc, Twpw, Tacc, Thold, Trpw, Textr; 486 + int kHz = nfc->freq_kHz; 487 + 488 + if (IS_ERR(sdr)) 489 + return PTR_ERR(sdr); 490 + 491 + if (check_only) 492 + return 0; 493 + 494 + Trdy = to_ticks(kHz, sdr->tCEA_max - sdr->tREA_max); 495 + Textw = to_ticks(kHz, sdr->tWB_max); 496 + Twc = to_ticks(kHz, sdr->tWC_min); 497 + Twpw = to_ticks(kHz, sdr->tWC_min - sdr->tWP_min); 498 + 499 + Tacc = to_ticks(kHz, sdr->tREA_max); 500 + Thold = to_ticks(kHz, sdr->tREH_min); 501 + Trpw = to_ticks(kHz, sdr->tRC_min - sdr->tREH_min); 502 + Textr = to_ticks(kHz, sdr->tRHZ_max); 503 + 504 + tchip->timing1 = TIMING(Trdy, Textw, Twc, Twpw); 505 + tchip->timing2 = TIMING(Tacc, Thold, Trpw, Textr); 506 + 507 + return 0; 508 + } 509 + 510 + static int chip_init(struct device *dev, struct device_node *np) 511 + { 512 + u32 cs; 513 + int err, res; 514 + struct mtd_info *mtd; 515 + struct nand_chip *chip; 516 + struct tango_chip *tchip; 517 + struct nand_ecc_ctrl *ecc; 518 + struct tango_nfc *nfc = dev_get_drvdata(dev); 519 + 520 + tchip = devm_kzalloc(dev, sizeof(*tchip), GFP_KERNEL); 521 + if (!tchip) 522 + return -ENOMEM; 523 + 524 + res = of_property_count_u32_elems(np, "reg"); 525 + if (res < 0) 526 + return res; 527 + 528 + if (res != 1) 529 + return -ENOTSUPP; /* Multi-CS chips are not supported */ 530 + 531 + err = of_property_read_u32_index(np, "reg", 0, &cs); 532 + if (err) 533 + return err; 534 + 535 + if (cs >= MAX_CS) 536 + return -EINVAL; 537 + 538 + chip = &tchip->nand_chip; 539 + ecc = &chip->ecc; 540 + mtd = nand_to_mtd(chip); 541 + 542 + chip->read_byte = tango_read_byte; 543 + chip->write_buf = tango_write_buf; 544 + chip->read_buf = tango_read_buf; 545 + chip->select_chip = tango_select_chip; 546 + chip->cmd_ctrl = tango_cmd_ctrl; 547 + chip->dev_ready = tango_dev_ready; 548 + chip->setup_data_interface = tango_set_timings; 549 + chip->options = NAND_USE_BOUNCE_BUFFER | 550 + NAND_NO_SUBPAGE_WRITE | 551 + NAND_WAIT_TCCS; 552 + chip->controller = &nfc->hw; 553 + tchip->base = nfc->pbus_base + (cs * 256); 554 + 555 + nand_set_flash_node(chip, np); 556 + mtd_set_ooblayout(mtd, &tango_nand_ooblayout_ops); 557 + mtd->dev.parent = dev; 558 + 559 + err = nand_scan_ident(mtd, 1, NULL); 560 + if (err) 561 + return err; 562 + 563 + ecc->mode = NAND_ECC_HW; 564 + ecc->algo = NAND_ECC_BCH; 565 + ecc->bytes = DIV_ROUND_UP(ecc->strength * FIELD_ORDER, BITS_PER_BYTE); 566 + 567 + ecc->read_page_raw = tango_read_page_raw; 568 + ecc->write_page_raw = tango_write_page_raw; 569 + ecc->read_page = tango_read_page; 570 + ecc->write_page = tango_write_page; 571 + ecc->read_oob = tango_read_oob; 572 + ecc->write_oob = tango_write_oob; 573 + ecc->options = NAND_ECC_CUSTOM_PAGE_ACCESS; 574 + 575 + err = nand_scan_tail(mtd); 576 + if (err) 577 + return err; 578 + 579 + tchip->xfer_cfg = XFER_CFG(cs, 1, ecc->steps, METADATA_SIZE); 580 + tchip->pkt_0_cfg = PKT_CFG(ecc->size + METADATA_SIZE, ecc->strength); 581 + tchip->pkt_n_cfg = PKT_CFG(ecc->size, ecc->strength); 582 + tchip->bb_cfg = BB_CFG(mtd->writesize, BBM_SIZE); 583 + 584 + err = mtd_device_register(mtd, NULL, 0); 585 + if (err) 586 + return err; 587 + 588 + nfc->chips[cs] = tchip; 589 + 590 + return 0; 591 + } 592 + 593 + static int tango_nand_remove(struct platform_device *pdev) 594 + { 595 + int cs; 596 + struct tango_nfc *nfc = platform_get_drvdata(pdev); 597 + 598 + dma_release_channel(nfc->chan); 599 + 600 + for (cs = 0; cs < MAX_CS; ++cs) { 601 + if (nfc->chips[cs]) 602 + nand_release(nand_to_mtd(&nfc->chips[cs]->nand_chip)); 603 + } 604 + 605 + return 0; 606 + } 607 + 608 + static int tango_nand_probe(struct platform_device *pdev) 609 + { 610 + int err; 611 + struct clk *clk; 612 + struct resource *res; 613 + struct tango_nfc *nfc; 614 + struct device_node *np; 615 + 616 + nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL); 617 + if (!nfc) 618 + return -ENOMEM; 619 + 620 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 621 + nfc->reg_base = devm_ioremap_resource(&pdev->dev, res); 622 + if (IS_ERR(nfc->reg_base)) 623 + return PTR_ERR(nfc->reg_base); 624 + 625 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 626 + nfc->mem_base = devm_ioremap_resource(&pdev->dev, res); 627 + if (IS_ERR(nfc->mem_base)) 628 + return PTR_ERR(nfc->mem_base); 629 + 630 + res = platform_get_resource(pdev, IORESOURCE_MEM, 2); 631 + nfc->pbus_base = devm_ioremap_resource(&pdev->dev, res); 632 + if (IS_ERR(nfc->pbus_base)) 633 + return PTR_ERR(nfc->pbus_base); 634 + 635 + clk = clk_get(&pdev->dev, NULL); 636 + if (IS_ERR(clk)) 637 + return PTR_ERR(clk); 638 + 639 + nfc->chan = dma_request_chan(&pdev->dev, "nfc_sbox"); 640 + if (IS_ERR(nfc->chan)) 641 + return PTR_ERR(nfc->chan); 642 + 643 + platform_set_drvdata(pdev, nfc); 644 + nand_hw_control_init(&nfc->hw); 645 + nfc->freq_kHz = clk_get_rate(clk) / 1000; 646 + 647 + for_each_child_of_node(pdev->dev.of_node, np) { 648 + err = chip_init(&pdev->dev, np); 649 + if (err) { 650 + tango_nand_remove(pdev); 651 + return err; 652 + } 653 + } 654 + 655 + return 0; 656 + } 657 + 658 + static const struct of_device_id tango_nand_ids[] = { 659 + { .compatible = "sigma,smp8758-nand" }, 660 + { /* sentinel */ } 661 + }; 662 + 663 + static struct platform_driver tango_nand_driver = { 664 + .probe = tango_nand_probe, 665 + .remove = tango_nand_remove, 666 + .driver = { 667 + .name = "tango-nand", 668 + .of_match_table = tango_nand_ids, 669 + }, 670 + }; 671 + 672 + module_platform_driver(tango_nand_driver); 673 + 674 + MODULE_LICENSE("GPL"); 675 + MODULE_AUTHOR("Sigma Designs"); 676 + MODULE_DESCRIPTION("Tango4 NAND Flash controller driver");
+3 -3
drivers/mtd/nand/tmio_nand.c
··· 435 435 nand_chip->waitfunc = tmio_nand_wait; 436 436 437 437 /* Scan to find existence of the device */ 438 - if (nand_scan(mtd, 1)) { 439 - retval = -ENODEV; 438 + retval = nand_scan(mtd, 1); 439 + if (retval) 440 440 goto err_irq; 441 - } 441 + 442 442 /* Register the partitions */ 443 443 retval = mtd_device_parse_register(mtd, NULL, NULL, 444 444 data ? data->partition : NULL,
+4 -6
drivers/mtd/nand/vf610_nfc.c
··· 717 717 vf610_nfc_preinit_controller(nfc); 718 718 719 719 /* first scan to find the device and get the page size */ 720 - if (nand_scan_ident(mtd, 1, NULL)) { 721 - err = -ENXIO; 720 + err = nand_scan_ident(mtd, 1, NULL); 721 + if (err) 722 722 goto error; 723 - } 724 723 725 724 vf610_nfc_init_controller(nfc); 726 725 ··· 774 775 } 775 776 776 777 /* second phase scan */ 777 - if (nand_scan_tail(mtd)) { 778 - err = -ENXIO; 778 + err = nand_scan_tail(mtd); 779 + if (err) 779 780 goto error; 780 - } 781 781 782 782 platform_set_drvdata(pdev, mtd); 783 783
+4 -2
drivers/mtd/spi-nor/cadence-quadspi.c
··· 1077 1077 1078 1078 /* Get flash device data */ 1079 1079 for_each_available_child_of_node(dev->of_node, np) { 1080 - if (of_property_read_u32(np, "reg", &cs)) { 1080 + ret = of_property_read_u32(np, "reg", &cs); 1081 + if (ret) { 1081 1082 dev_err(dev, "Couldn't determine chip select.\n"); 1082 1083 goto err; 1083 1084 } 1084 1085 1085 - if (cs > CQSPI_MAX_CHIPSELECT) { 1086 + if (cs >= CQSPI_MAX_CHIPSELECT) { 1087 + ret = -EINVAL; 1086 1088 dev_err(dev, "Chip select %d out of range.\n", cs); 1087 1089 goto err; 1088 1090 }
+4 -4
drivers/mtd/spi-nor/fsl-quadspi.c
··· 224 224 int driver_data; 225 225 }; 226 226 227 - static struct fsl_qspi_devtype_data vybrid_data = { 227 + static const struct fsl_qspi_devtype_data vybrid_data = { 228 228 .devtype = FSL_QUADSPI_VYBRID, 229 229 .rxfifo = 128, 230 230 .txfifo = 64, ··· 232 232 .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN, 233 233 }; 234 234 235 - static struct fsl_qspi_devtype_data imx6sx_data = { 235 + static const struct fsl_qspi_devtype_data imx6sx_data = { 236 236 .devtype = FSL_QUADSPI_IMX6SX, 237 237 .rxfifo = 128, 238 238 .txfifo = 512, ··· 241 241 | QUADSPI_QUIRK_TKT245618, 242 242 }; 243 243 244 - static struct fsl_qspi_devtype_data imx7d_data = { 244 + static const struct fsl_qspi_devtype_data imx7d_data = { 245 245 .devtype = FSL_QUADSPI_IMX7D, 246 246 .rxfifo = 512, 247 247 .txfifo = 512, ··· 250 250 | QUADSPI_QUIRK_4X_INT_CLK, 251 251 }; 252 252 253 - static struct fsl_qspi_devtype_data imx6ul_data = { 253 + static const struct fsl_qspi_devtype_data imx6ul_data = { 254 254 .devtype = FSL_QUADSPI_IMX6UL, 255 255 .rxfifo = 128, 256 256 .txfifo = 512,
+13 -1
drivers/mtd/spi-nor/spi-nor.c
··· 799 799 { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) }, 800 800 801 801 { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K) }, 802 + { "at25df321", INFO(0x1f4700, 0, 64 * 1024, 64, SECT_4K) }, 802 803 { "at25df321a", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) }, 803 804 { "at25df641", INFO(0x1f4800, 0, 64 * 1024, 128, SECT_4K) }, 804 805 ··· 826 825 /* Everspin */ 827 826 { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 828 827 { "mr25h10", CAT25_INFO(128 * 1024, 1, 256, 3, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 828 + { "mr25h40", CAT25_INFO(512 * 1024, 1, 256, 3, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, 829 829 830 830 /* Fujitsu */ 831 831 { "mb85rs1mt", INFO(0x047f27, 0, 128 * 1024, 1, SPI_NOR_NO_ERASE) }, ··· 874 872 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, 875 873 { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) }, 876 874 { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) }, 875 + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K) }, 877 876 { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) }, 878 877 { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) }, 879 878 { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) }, 880 879 881 880 /* Micron */ 881 + { "n25q016a", INFO(0x20bb15, 0, 64 * 1024, 32, SECT_4K | SPI_NOR_QUAD_READ) }, 882 882 { "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, SPI_NOR_QUAD_READ) }, 883 883 { "n25q032a", INFO(0x20bb16, 0, 64 * 1024, 64, SPI_NOR_QUAD_READ) }, 884 884 { "n25q064", INFO(0x20ba17, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_QUAD_READ) }, ··· 909 905 { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) }, 910 906 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, 911 907 { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, 912 - { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SECT_4K | SPI_NOR_QUAD_READ) }, 908 + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 913 909 { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 914 910 { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 915 911 { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) }, ··· 925 921 { "s25fl132k", INFO(0x014016, 0, 64 * 1024, 64, SECT_4K) }, 926 922 { "s25fl164k", INFO(0x014017, 0, 64 * 1024, 128, SECT_4K) }, 927 923 { "s25fl204k", INFO(0x014013, 0, 64 * 1024, 8, SECT_4K | SPI_NOR_DUAL_READ) }, 924 + { "s25fl208k", INFO(0x014014, 0, 64 * 1024, 16, SECT_4K | SPI_NOR_DUAL_READ) }, 928 925 929 926 /* SST -- large erase sizes are "overlays", "sectors" are 4K */ 930 927 { "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024, 8, SECT_4K | SST_WRITE) }, ··· 1258 1253 dev_err(nor->dev, 1259 1254 "error while writing configuration register\n"); 1260 1255 return -EINVAL; 1256 + } 1257 + 1258 + ret = spi_nor_wait_till_ready(nor); 1259 + if (ret) { 1260 + dev_err(nor->dev, 1261 + "timeout while writing configuration register\n"); 1262 + return ret; 1261 1263 } 1262 1264 1263 1265 /* read back and check it */
+30
include/linux/mtd/nand.h
··· 142 142 */ 143 143 #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0) 144 144 #define NAND_ECC_MAXIMIZE BIT(1) 145 + /* 146 + * If your controller already sends the required NAND commands when 147 + * reading or writing a page, then the framework is not supposed to 148 + * send READ0 and SEQIN/PAGEPROG respectively. 149 + */ 150 + #define NAND_ECC_CUSTOM_PAGE_ACCESS BIT(2) 145 151 146 152 /* Bit mask for flags passed to do_nand_read_ecc */ 147 153 #define NAND_GET_DEVICE 0x80 ··· 192 186 /* Macros to identify the above */ 193 187 #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG)) 194 188 #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ)) 189 + #define NAND_HAS_SUBPAGE_WRITE(chip) !((chip)->options & NAND_NO_SUBPAGE_WRITE) 195 190 196 191 /* Non chip related options */ 197 192 /* This option skips the bbt scan during initialization. */ ··· 216 209 * kmap'ed, vmalloc'ed highmem buffers being passed from upper layers 217 210 */ 218 211 #define NAND_USE_BOUNCE_BUFFER 0x00100000 212 + 213 + /* 214 + * In case your controller is implementing ->cmd_ctrl() and is relying on the 215 + * default ->cmdfunc() implementation, you may want to let the core handle the 216 + * tCCS delay which is required when a column change (RNDIN or RNDOUT) is 217 + * requested. 218 + * If your controller already takes care of this delay, you don't need to set 219 + * this flag. 220 + */ 221 + #define NAND_WAIT_TCCS 0x00200000 219 222 220 223 /* Options set by nand scan */ 221 224 /* Nand scan has allocated controller struct */ ··· 575 558 int page); 576 559 }; 577 560 561 + static inline int nand_standard_page_accessors(struct nand_ecc_ctrl *ecc) 562 + { 563 + return !(ecc->options & NAND_ECC_CUSTOM_PAGE_ACCESS); 564 + } 565 + 578 566 /** 579 567 * struct nand_buffers - buffer structure for read/write 580 568 * @ecccalc: buffer pointer for calculated ECC, size is oobsize. ··· 606 584 * 607 585 * All these timings are expressed in picoseconds. 608 586 * 587 + * @tBERS_max: Block erase time 588 + * @tCCS_min: Change column setup time 589 + * @tPROG_max: Page program time 590 + * @tR_max: Page read time 609 591 * @tALH_min: ALE hold time 610 592 * @tADL_min: ALE to data loading time 611 593 * @tALS_min: ALE setup time ··· 647 621 * @tWW_min: WP# transition to WE# low 648 622 */ 649 623 struct nand_sdr_timings { 624 + u32 tBERS_max; 625 + u32 tCCS_min; 626 + u32 tPROG_max; 627 + u32 tR_max; 650 628 u32 tALH_min; 651 629 u32 tADL_min; 652 630 u32 tALS_min;
+5 -2
include/linux/platform_data/mtd-nand-s3c2410.h
··· 12 12 #ifndef __MTD_NAND_S3C2410_H 13 13 #define __MTD_NAND_S3C2410_H 14 14 15 + #include <linux/mtd/nand.h> 16 + 15 17 /** 16 18 * struct s3c2410_nand_set - define a set of one or more nand chips 17 - * @disable_ecc: Entirely disable ECC - Dangerous 18 19 * @flash_bbt: Openmoko u-boot can create a Bad Block Table 19 20 * Setting this flag will allow the kernel to 20 21 * look for it at boot time and also skip the NAND ··· 32 31 * a warning at boot time. 33 32 */ 34 33 struct s3c2410_nand_set { 35 - unsigned int disable_ecc:1; 36 34 unsigned int flash_bbt:1; 37 35 38 36 unsigned int options; ··· 40 40 char *name; 41 41 int *nr_map; 42 42 struct mtd_partition *partitions; 43 + struct device_node *of_node; 43 44 }; 44 45 45 46 struct s3c2410_platform_nand { ··· 51 50 int twrph1; /* time for release CLE/ALE from nWE/nOE inactive */ 52 51 53 52 unsigned int ignore_unset_ecc:1; 53 + 54 + nand_ecc_modes_t ecc_mode; 54 55 55 56 int nr_sets; 56 57 struct s3c2410_nand_set *sets;