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

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

Pull mtd updates from David Woodhouse:
- factor out common code from MTD tests
- nand-gpio cleanup and portability to non-ARM
- m25p80 support for 4-byte addressing chips, other new chips
- pxa3xx cleanup and support for new platforms
- remove obsolete alauda, octagon-5066 drivers
- erase/write support for bcm47xxsflash
- improve detection of ECC requirements for NAND, controller setup
- NFC acceleration support for atmel-nand, read/write via SRAM
- etc

* tag 'for-linus-20130909' of git://git.infradead.org/linux-mtd: (184 commits)
mtd: chips: Add support for PMC SPI Flash chips in m25p80.c
mtd: ofpart: use for_each_child_of_node() macro
mtd: mtdswap: replace strict_strtoul() with kstrtoul()
mtd cs553x_nand: use kzalloc() instead of memset
mtd: atmel_nand: fix error return code in atmel_nand_probe()
mtd: bcm47xxsflash: writing support
mtd: bcm47xxsflash: implement erasing support
mtd: bcm47xxsflash: convert to module_platform_driver instead of init/exit
mtd: bcm47xxsflash: convert kzalloc to avoid invalid access
mtd: remove alauda driver
mtd: nand: mxc_nand: mark 'const' properly
mtd: maps: cfi_flagadm: add missing __iomem annotation
mtd: spear_smi: add missing __iomem annotation
mtd: r852: Staticize local symbols
mtd: nandsim: Staticize local symbols
mtd: impa7: add missing __iomem annotation
mtd: sm_ftl: Staticize local symbols
mtd: m25p80: add support for mr25h10
mtd: m25p80: make CONFIG_M25PXX_USE_FAST_READ safe to enable
mtd: m25p80: Pass flags through CAT25_INFO macro
...

+2734 -3203
+14 -3
Documentation/ABI/testing/sysfs-class-mtd
··· 128 128 Contact: linux-mtd@lists.infradead.org 129 129 Description: 130 130 Maximum number of bit errors that the device is capable of 131 - correcting within each region covering an ecc step. This will 132 - always be a non-negative integer. Note that some devices will 133 - have multiple ecc steps within each writesize region. 131 + correcting within each region covering an ECC step (see 132 + ecc_step_size). This will always be a non-negative integer. 134 133 135 134 In the case of devices lacking any ECC capability, it is 0. 136 135 ··· 172 173 This is generally applicable only to NAND flash devices with ECC 173 174 capability. It is ignored on devices lacking ECC capability; 174 175 i.e., devices for which ecc_strength is zero. 176 + 177 + What: /sys/class/mtd/mtdX/ecc_step_size 178 + Date: May 2013 179 + KernelVersion: 3.10 180 + Contact: linux-mtd@lists.infradead.org 181 + Description: 182 + The size of a single region covered by ECC, known as the ECC 183 + step. Devices may have several equally sized ECC steps within 184 + each writesize region. 185 + 186 + It will always be a non-negative integer. In the case of 187 + devices lacking any ECC capability, it is 0.
-2
Documentation/DocBook/mtdnand.tmpl
··· 1224 1224 #define NAND_BBT_CREATE 0x00000200 1225 1225 /* Search good / bad pattern through all pages of a block */ 1226 1226 #define NAND_BBT_SCANALLPAGES 0x00000400 1227 - /* Scan block empty during good / bad block scan */ 1228 - #define NAND_BBT_SCANEMPTY 0x00000800 1229 1227 /* Write bbt if neccecary */ 1230 1228 #define NAND_BBT_WRITE 0x00001000 1231 1229 /* Read and write back block contents when writing bbt */
+28
Documentation/devicetree/bindings/mtd/atmel-nand.txt
··· 15 15 optional gpio and may be set to 0 if not present. 16 16 17 17 Optional properties: 18 + - atmel,nand-has-dma : boolean to support dma transfer for nand read/write. 18 19 - nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default. 19 20 Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first", 20 21 "soft_bch". ··· 30 29 sector size 1024. 31 30 - nand-bus-width : 8 or 16 bus width if not present 8 32 31 - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false 32 + - Nand Flash Controller(NFC) is a slave driver under Atmel nand flash 33 + - Required properties: 34 + - compatible : "atmel,sama5d3-nfc". 35 + - reg : should specify the address and size used for NFC command registers, 36 + NFC registers and NFC Sram. NFC Sram address and size can be absent 37 + if don't want to use it. 38 + - Optional properties: 39 + - atmel,write-by-sram: boolean to enable NFC write by sram. 33 40 34 41 Examples: 35 42 nand0: nand@40000000,0 { ··· 84 75 >; 85 76 partition@0 { 86 77 ... 78 + }; 79 + }; 80 + 81 + /* for NFC supported chips */ 82 + nand0: nand@40000000 { 83 + compatible = "atmel,at91rm9200-nand"; 84 + #address-cells = <1>; 85 + #size-cells = <1>; 86 + ranges; 87 + ... 88 + nfc@70000000 { 89 + compatible = "atmel,sama5d3-nfc"; 90 + #address-cells = <1>; 91 + #size-cells = <1>; 92 + reg = < 93 + 0x70000000 0x10000000 /* NFC Command Registers */ 94 + 0xffffc000 0x00000070 /* NFC HSMC regs */ 95 + 0x00200000 0x00100000 /* NFC SRAM banks */ 96 + >; 87 97 }; 88 98 };
+24 -1
Documentation/devicetree/bindings/mtd/fsmc-nand.txt
··· 1 - * FSMC NAND 1 + ST Microelectronics Flexible Static Memory Controller (FSMC) 2 + NAND Interface 2 3 3 4 Required properties: 4 5 - compatible : "st,spear600-fsmc-nand", "stericsson,fsmc-nand" ··· 10 9 - bank-width : Width (in bytes) of the device. If not present, the width 11 10 defaults to 1 byte 12 11 - nand-skip-bbtscan: Indicates the the BBT scanning should be skipped 12 + - timings: array of 6 bytes for NAND timings. The meanings of these bytes 13 + are: 14 + byte 0 TCLR : CLE to RE delay in number of AHB clock cycles, only 4 bits 15 + are valid. Zero means one clockcycle, 15 means 16 clock 16 + cycles. 17 + byte 1 TAR : ALE to RE delay, 4 bits are valid. Same format as TCLR. 18 + byte 2 THIZ : number of HCLK clock cycles during which the data bus is 19 + kept in Hi-Z (tristate) after the start of a write access. 20 + Only valid for write transactions. Zero means zero cycles, 21 + 255 means 255 cycles. 22 + byte 3 THOLD : number of HCLK clock cycles to hold the address (and data 23 + when writing) after the command deassertation. Zero means 24 + one cycle, 255 means 256 cycles. 25 + byte 4 TWAIT : number of HCLK clock cycles to assert the command to the 26 + NAND flash in response to SMWAITn. Zero means 1 cycle, 27 + 255 means 256 cycles. 28 + byte 5 TSET : number of HCLK clock cycles to assert the address before the 29 + command is asserted. Zero means one cycle, 255 means 256 30 + cycles. 31 + - bank: default NAND bank to use (0-3 are valid, 0 is the default). 13 32 14 33 Example: 15 34 ··· 45 24 46 25 bank-width = <1>; 47 26 nand-skip-bbtscan; 27 + timings = /bits/ 8 <0 0 0 2 3 0>; 28 + bank = <1>; 48 29 49 30 partition@0 { 50 31 ...
+1
Documentation/devicetree/bindings/mtd/partition.txt
··· 4 4 on platforms which have strong conventions about which portions of a flash are 5 5 used for what purposes, but which don't use an on-flash partition table such 6 6 as RedBoot. 7 + NOTE: if the sub-node has a compatible string, then it is not a partition. 7 8 8 9 #address-cells & #size-cells must both be present in the mtd device. There are 9 10 two valid values for both:
+3
arch/avr32/mach-at32ap/at32ap700x.c
··· 1983 1983 ARRAY_SIZE(smc_cs3_resource))) 1984 1984 goto fail; 1985 1985 1986 + /* For at32ap7000, we use the reset workaround for nand driver */ 1987 + data->need_reset_workaround = true; 1988 + 1986 1989 if (platform_device_add_data(pdev, data, 1987 1990 sizeof(struct atmel_nand_data))) 1988 1991 goto fail;
+11
arch/mips/bcm63xx/nvram.c
··· 35 35 u32 checksum_high; 36 36 }; 37 37 38 + #define BCM63XX_DEFAULT_PSI_SIZE 64 39 + 38 40 static struct bcm963xx_nvram nvram; 39 41 static int mac_addr_used; 40 42 ··· 116 114 return 0; 117 115 } 118 116 EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address); 117 + 118 + int bcm63xx_nvram_get_psi_size(void) 119 + { 120 + if (nvram.psi_size > 0) 121 + return nvram.psi_size; 122 + 123 + return BCM63XX_DEFAULT_PSI_SIZE; 124 + } 125 + EXPORT_SYMBOL(bcm63xx_nvram_get_psi_size);
+2
arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
··· 30 30 */ 31 31 int bcm63xx_nvram_get_mac_address(u8 *mac); 32 32 33 + int bcm63xx_nvram_get_psi_size(void); 34 + 33 35 #endif /* BCM63XX_NVRAM_H */
+6 -3
drivers/mtd/bcm63xxpart.c
··· 4 4 * Copyright © 2006-2008 Florian Fainelli <florian@openwrt.org> 5 5 * Mike Albon <malbon@openwrt.org> 6 6 * Copyright © 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net> 7 - * Copyright © 2011-2012 Jonas Gorski <jonas.gorski@gmail.com> 7 + * Copyright © 2011-2013 Jonas Gorski <jonas.gorski@gmail.com> 8 8 * 9 9 * This program is free software; you can redistribute it and/or modify 10 10 * it under the terms of the GNU General Public License as published by ··· 27 27 #include <linux/crc32.h> 28 28 #include <linux/module.h> 29 29 #include <linux/kernel.h> 30 + #include <linux/sizes.h> 30 31 #include <linux/slab.h> 31 32 #include <linux/vmalloc.h> 32 33 #include <linux/mtd/mtd.h> 33 34 #include <linux/mtd/partitions.h> 34 35 36 + #include <asm/mach-bcm63xx/bcm63xx_nvram.h> 35 37 #include <asm/mach-bcm63xx/bcm963xx_tag.h> 36 38 #include <asm/mach-bcm63xx/board_bcm963xx.h> 37 39 38 40 #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ 39 41 40 - #define BCM63XX_CFE_BLOCK_SIZE 0x10000 /* always at least 64KiB */ 42 + #define BCM63XX_CFE_BLOCK_SIZE SZ_64K /* always at least 64KiB */ 41 43 42 44 #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0 43 45 ··· 92 90 BCM63XX_CFE_BLOCK_SIZE); 93 91 94 92 cfelen = cfe_erasesize; 95 - nvramlen = cfe_erasesize; 93 + nvramlen = bcm63xx_nvram_get_psi_size() * SZ_1K; 94 + nvramlen = roundup(nvramlen, cfe_erasesize); 96 95 97 96 /* Allocate memory for buffer */ 98 97 buf = vmalloc(sizeof(struct bcm_tag));
+2 -2
drivers/mtd/chips/cfi_cmdset_0002.c
··· 1571 1571 xip_enable(map, chip, adr); 1572 1572 /* FIXME - should have reset delay before continuing */ 1573 1573 1574 - printk(KERN_WARNING "MTD %s(): software timeout\n", 1575 - __func__ ); 1574 + printk(KERN_WARNING "MTD %s(): software timeout, address:0x%.8lx.\n", 1575 + __func__, adr); 1576 1576 1577 1577 ret = -EIO; 1578 1578 op_done:
+1 -3
drivers/mtd/chips/gen_probe.c
··· 211 211 212 212 probe_function = __symbol_get(probename); 213 213 if (!probe_function) { 214 - char modname[sizeof("cfi_cmdset_%4.4X")]; 215 - sprintf(modname, "cfi_cmdset_%4.4X", type); 216 - request_module(modname); 214 + request_module("cfi_cmdset_%4.4X", type); 217 215 probe_function = __symbol_get(probename); 218 216 } 219 217
+7 -6
drivers/mtd/chips/jedec_probe.c
··· 120 120 #define PM49FL008 0x006A 121 121 122 122 /* Sharp */ 123 - #define LH28F640BF 0x00b0 123 + #define LH28F640BF 0x00B0 124 124 125 125 /* ST - www.st.com */ 126 126 #define M29F800AB 0x0058 ··· 1299 1299 .mfr_id = CFI_MFR_SHARP, 1300 1300 .dev_id = LH28F640BF, 1301 1301 .name = "LH28F640BF", 1302 - .devtypes = CFI_DEVICETYPE_X8, 1302 + .devtypes = CFI_DEVICETYPE_X16, 1303 1303 .uaddr = MTD_UADDR_UNNECESSARY, 1304 - .dev_size = SIZE_4MiB, 1305 - .cmd_set = P_ID_INTEL_STD, 1306 - .nr_regions = 1, 1304 + .dev_size = SIZE_8MiB, 1305 + .cmd_set = P_ID_INTEL_EXT, 1306 + .nr_regions = 2, 1307 1307 .regions = { 1308 - ERASEINFO(0x40000,16), 1308 + ERASEINFO(0x10000, 127), 1309 + ERASEINFO(0x02000, 8), 1309 1310 } 1310 1311 }, { 1311 1312 .mfr_id = CFI_MFR_SST,
-55
drivers/mtd/devices/Kconfig
··· 224 224 default 4 225 225 endif 226 226 227 - config MTD_DOCPROBE 228 - tristate 229 - select MTD_DOCECC 230 - 231 - config MTD_DOCECC 232 - tristate 233 - 234 - config MTD_DOCPROBE_ADVANCED 235 - bool "Advanced detection options for DiskOnChip" 236 - depends on MTD_DOCPROBE 237 - help 238 - This option allows you to specify nonstandard address at which to 239 - probe for a DiskOnChip, or to change the detection options. You 240 - are unlikely to need any of this unless you are using LinuxBIOS. 241 - Say 'N'. 242 - 243 - config MTD_DOCPROBE_ADDRESS 244 - hex "Physical address of DiskOnChip" if MTD_DOCPROBE_ADVANCED 245 - depends on MTD_DOCPROBE 246 - default "0x0" 247 - ---help--- 248 - By default, the probe for DiskOnChip devices will look for a 249 - DiskOnChip at every multiple of 0x2000 between 0xC8000 and 0xEE000. 250 - This option allows you to specify a single address at which to probe 251 - for the device, which is useful if you have other devices in that 252 - range which get upset when they are probed. 253 - 254 - (Note that on PowerPC, the normal probe will only check at 255 - 0xE4000000.) 256 - 257 - Normally, you should leave this set to zero, to allow the probe at 258 - the normal addresses. 259 - 260 - config MTD_DOCPROBE_HIGH 261 - bool "Probe high addresses" 262 - depends on MTD_DOCPROBE_ADVANCED 263 - help 264 - By default, the probe for DiskOnChip devices will look for a 265 - DiskOnChip at every multiple of 0x2000 between 0xC8000 and 0xEE000. 266 - This option changes to make it probe between 0xFFFC8000 and 267 - 0xFFFEE000. Unless you are using LinuxBIOS, this is unlikely to be 268 - useful to you. Say 'N'. 269 - 270 - config MTD_DOCPROBE_55AA 271 - bool "Probe for 0x55 0xAA BIOS Extension Signature" 272 - depends on MTD_DOCPROBE_ADVANCED 273 - help 274 - Check for the 0x55 0xAA signature of a DiskOnChip, and do not 275 - continue with probing if it is absent. The signature will always be 276 - present for a DiskOnChip 2000 or a normal DiskOnChip Millennium. 277 - Only if you have overwritten the first block of a DiskOnChip 278 - Millennium will it be absent. Enable this option if you are using 279 - LinuxBIOS or if you need to recover a DiskOnChip Millennium on which 280 - you have managed to wipe the first block. 281 - 282 227 endmenu
+240 -37
drivers/mtd/devices/bcm47xxsflash.c
··· 1 1 #include <linux/kernel.h> 2 2 #include <linux/module.h> 3 3 #include <linux/slab.h> 4 + #include <linux/delay.h> 4 5 #include <linux/mtd/mtd.h> 5 6 #include <linux/platform_device.h> 6 7 #include <linux/bcma/bcma.h> ··· 12 11 MODULE_DESCRIPTION("Serial flash driver for BCMA bus"); 13 12 14 13 static const char * const probes[] = { "bcm47xxpart", NULL }; 14 + 15 + /************************************************** 16 + * Various helpers 17 + **************************************************/ 18 + 19 + static void bcm47xxsflash_cmd(struct bcm47xxsflash *b47s, u32 opcode) 20 + { 21 + int i; 22 + 23 + b47s->cc_write(b47s, BCMA_CC_FLASHCTL, BCMA_CC_FLASHCTL_START | opcode); 24 + for (i = 0; i < 1000; i++) { 25 + if (!(b47s->cc_read(b47s, BCMA_CC_FLASHCTL) & 26 + BCMA_CC_FLASHCTL_BUSY)) 27 + return; 28 + cpu_relax(); 29 + } 30 + pr_err("Control command failed (timeout)!\n"); 31 + } 32 + 33 + static int bcm47xxsflash_poll(struct bcm47xxsflash *b47s, int timeout) 34 + { 35 + unsigned long deadline = jiffies + timeout; 36 + 37 + do { 38 + switch (b47s->type) { 39 + case BCM47XXSFLASH_TYPE_ST: 40 + bcm47xxsflash_cmd(b47s, OPCODE_ST_RDSR); 41 + if (!(b47s->cc_read(b47s, BCMA_CC_FLASHDATA) & 42 + SR_ST_WIP)) 43 + return 0; 44 + break; 45 + case BCM47XXSFLASH_TYPE_ATMEL: 46 + bcm47xxsflash_cmd(b47s, OPCODE_AT_STATUS); 47 + if (b47s->cc_read(b47s, BCMA_CC_FLASHDATA) & 48 + SR_AT_READY) 49 + return 0; 50 + break; 51 + } 52 + 53 + cpu_relax(); 54 + udelay(1); 55 + } while (!time_after_eq(jiffies, deadline)); 56 + 57 + pr_err("Timeout waiting for flash to be ready!\n"); 58 + 59 + return -EBUSY; 60 + } 61 + 62 + /************************************************** 63 + * MTD ops 64 + **************************************************/ 65 + 66 + static int bcm47xxsflash_erase(struct mtd_info *mtd, struct erase_info *erase) 67 + { 68 + struct bcm47xxsflash *b47s = mtd->priv; 69 + int err; 70 + 71 + switch (b47s->type) { 72 + case BCM47XXSFLASH_TYPE_ST: 73 + bcm47xxsflash_cmd(b47s, OPCODE_ST_WREN); 74 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, erase->addr); 75 + /* Newer flashes have "sub-sectors" which can be erased 76 + * independently with a new command: ST_SSE. The ST_SE command 77 + * erases 64KB just as before. 78 + */ 79 + if (b47s->blocksize < (64 * 1024)) 80 + bcm47xxsflash_cmd(b47s, OPCODE_ST_SSE); 81 + else 82 + bcm47xxsflash_cmd(b47s, OPCODE_ST_SE); 83 + break; 84 + case BCM47XXSFLASH_TYPE_ATMEL: 85 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, erase->addr << 1); 86 + bcm47xxsflash_cmd(b47s, OPCODE_AT_PAGE_ERASE); 87 + break; 88 + } 89 + 90 + err = bcm47xxsflash_poll(b47s, HZ); 91 + if (err) 92 + erase->state = MTD_ERASE_FAILED; 93 + else 94 + erase->state = MTD_ERASE_DONE; 95 + 96 + if (erase->callback) 97 + erase->callback(erase); 98 + 99 + return err; 100 + } 15 101 16 102 static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, 17 103 size_t *retlen, u_char *buf) ··· 116 28 return len; 117 29 } 118 30 31 + static int bcm47xxsflash_write_st(struct mtd_info *mtd, u32 offset, size_t len, 32 + const u_char *buf) 33 + { 34 + struct bcm47xxsflash *b47s = mtd->priv; 35 + int written = 0; 36 + 37 + /* Enable writes */ 38 + bcm47xxsflash_cmd(b47s, OPCODE_ST_WREN); 39 + 40 + /* Write first byte */ 41 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, offset); 42 + b47s->cc_write(b47s, BCMA_CC_FLASHDATA, *buf++); 43 + 44 + /* Program page */ 45 + if (b47s->bcma_cc->core->id.rev < 20) { 46 + bcm47xxsflash_cmd(b47s, OPCODE_ST_PP); 47 + return 1; /* 1B written */ 48 + } 49 + 50 + /* Program page and set CSA (on newer chips we can continue writing) */ 51 + bcm47xxsflash_cmd(b47s, OPCODE_ST_CSA | OPCODE_ST_PP); 52 + offset++; 53 + len--; 54 + written++; 55 + 56 + while (len > 0) { 57 + /* Page boundary, another function call is needed */ 58 + if ((offset & 0xFF) == 0) 59 + break; 60 + 61 + bcm47xxsflash_cmd(b47s, OPCODE_ST_CSA | *buf++); 62 + offset++; 63 + len--; 64 + written++; 65 + } 66 + 67 + /* All done, drop CSA & poll */ 68 + b47s->cc_write(b47s, BCMA_CC_FLASHCTL, 0); 69 + udelay(1); 70 + if (bcm47xxsflash_poll(b47s, HZ / 10)) 71 + pr_err("Flash rejected dropping CSA\n"); 72 + 73 + return written; 74 + } 75 + 76 + static int bcm47xxsflash_write_at(struct mtd_info *mtd, u32 offset, size_t len, 77 + const u_char *buf) 78 + { 79 + struct bcm47xxsflash *b47s = mtd->priv; 80 + u32 mask = b47s->blocksize - 1; 81 + u32 page = (offset & ~mask) << 1; 82 + u32 byte = offset & mask; 83 + int written = 0; 84 + 85 + /* If we don't overwrite whole page, read it to the buffer first */ 86 + if (byte || (len < b47s->blocksize)) { 87 + int err; 88 + 89 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, page); 90 + bcm47xxsflash_cmd(b47s, OPCODE_AT_BUF1_LOAD); 91 + /* 250 us for AT45DB321B */ 92 + err = bcm47xxsflash_poll(b47s, HZ / 1000); 93 + if (err) { 94 + pr_err("Timeout reading page 0x%X info buffer\n", page); 95 + return err; 96 + } 97 + } 98 + 99 + /* Change buffer content with our data */ 100 + while (len > 0) { 101 + /* Page boundary, another function call is needed */ 102 + if (byte == b47s->blocksize) 103 + break; 104 + 105 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, byte++); 106 + b47s->cc_write(b47s, BCMA_CC_FLASHDATA, *buf++); 107 + bcm47xxsflash_cmd(b47s, OPCODE_AT_BUF1_WRITE); 108 + len--; 109 + written++; 110 + } 111 + 112 + /* Program page with the buffer content */ 113 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, page); 114 + bcm47xxsflash_cmd(b47s, OPCODE_AT_BUF1_PROGRAM); 115 + 116 + return written; 117 + } 118 + 119 + static int bcm47xxsflash_write(struct mtd_info *mtd, loff_t to, size_t len, 120 + size_t *retlen, const u_char *buf) 121 + { 122 + struct bcm47xxsflash *b47s = mtd->priv; 123 + int written; 124 + 125 + /* Writing functions can return without writing all passed data, for 126 + * example when the hardware is too old or when we git page boundary. 127 + */ 128 + while (len > 0) { 129 + switch (b47s->type) { 130 + case BCM47XXSFLASH_TYPE_ST: 131 + written = bcm47xxsflash_write_st(mtd, to, len, buf); 132 + break; 133 + case BCM47XXSFLASH_TYPE_ATMEL: 134 + written = bcm47xxsflash_write_at(mtd, to, len, buf); 135 + break; 136 + default: 137 + BUG_ON(1); 138 + } 139 + if (written < 0) { 140 + pr_err("Error writing at offset 0x%llX\n", to); 141 + return written; 142 + } 143 + to += (loff_t)written; 144 + len -= written; 145 + *retlen += written; 146 + buf += written; 147 + } 148 + 149 + return 0; 150 + } 151 + 119 152 static void bcm47xxsflash_fill_mtd(struct bcm47xxsflash *b47s) 120 153 { 121 154 struct mtd_info *mtd = &b47s->mtd; ··· 244 35 mtd->priv = b47s; 245 36 mtd->name = "bcm47xxsflash"; 246 37 mtd->owner = THIS_MODULE; 247 - mtd->type = MTD_ROM; 248 - mtd->size = b47s->size; 249 - mtd->_read = bcm47xxsflash_read; 250 38 251 - /* TODO: implement writing support and verify/change following code */ 252 - mtd->flags = MTD_CAP_ROM; 253 - mtd->writebufsize = mtd->writesize = 1; 39 + mtd->type = MTD_NORFLASH; 40 + mtd->flags = MTD_CAP_NORFLASH; 41 + mtd->size = b47s->size; 42 + mtd->erasesize = b47s->blocksize; 43 + mtd->writesize = 1; 44 + mtd->writebufsize = 1; 45 + 46 + mtd->_erase = bcm47xxsflash_erase; 47 + mtd->_read = bcm47xxsflash_read; 48 + mtd->_write = bcm47xxsflash_write; 254 49 } 255 50 256 51 /************************************************** 257 52 * BCMA 258 53 **************************************************/ 54 + 55 + static int bcm47xxsflash_bcma_cc_read(struct bcm47xxsflash *b47s, u16 offset) 56 + { 57 + return bcma_cc_read32(b47s->bcma_cc, offset); 58 + } 59 + 60 + static void bcm47xxsflash_bcma_cc_write(struct bcm47xxsflash *b47s, u16 offset, 61 + u32 value) 62 + { 63 + bcma_cc_write32(b47s->bcma_cc, offset, value); 64 + } 259 65 260 66 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) 261 67 { ··· 278 54 struct bcm47xxsflash *b47s; 279 55 int err; 280 56 281 - b47s = kzalloc(sizeof(*b47s), GFP_KERNEL); 282 - if (!b47s) { 283 - err = -ENOMEM; 284 - goto out; 285 - } 57 + b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL); 58 + if (!b47s) 59 + return -ENOMEM; 286 60 sflash->priv = b47s; 287 61 288 62 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); 63 + b47s->cc_read = bcm47xxsflash_bcma_cc_read; 64 + b47s->cc_write = bcm47xxsflash_bcma_cc_write; 289 65 290 66 switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) { 291 67 case BCMA_CC_FLASHT_STSER: ··· 305 81 err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); 306 82 if (err) { 307 83 pr_err("Failed to register MTD device: %d\n", err); 308 - goto err_dev_reg; 84 + return err; 309 85 } 310 86 311 - return 0; 87 + if (bcm47xxsflash_poll(b47s, HZ / 10)) 88 + pr_warn("Serial flash busy\n"); 312 89 313 - err_dev_reg: 314 - kfree(&b47s->mtd); 315 - out: 316 - return err; 90 + return 0; 317 91 } 318 92 319 93 static int bcm47xxsflash_bcma_remove(struct platform_device *pdev) ··· 320 98 struct bcm47xxsflash *b47s = sflash->priv; 321 99 322 100 mtd_device_unregister(&b47s->mtd); 323 - kfree(b47s); 324 101 325 102 return 0; 326 103 } ··· 337 116 * Init 338 117 **************************************************/ 339 118 340 - static int __init bcm47xxsflash_init(void) 341 - { 342 - int err; 343 - 344 - err = platform_driver_register(&bcma_sflash_driver); 345 - if (err) 346 - pr_err("Failed to register BCMA serial flash driver: %d\n", 347 - err); 348 - 349 - return err; 350 - } 351 - 352 - static void __exit bcm47xxsflash_exit(void) 353 - { 354 - platform_driver_unregister(&bcma_sflash_driver); 355 - } 356 - 357 - module_init(bcm47xxsflash_init); 358 - module_exit(bcm47xxsflash_exit); 119 + module_platform_driver(bcma_sflash_driver);
+2
drivers/mtd/devices/bcm47xxsflash.h
··· 60 60 61 61 struct bcm47xxsflash { 62 62 struct bcma_drv_cc *bcma_cc; 63 + int (*cc_read)(struct bcm47xxsflash *b47s, u16 offset); 64 + void (*cc_write)(struct bcm47xxsflash *b47s, u16 offset, u32 value); 63 65 64 66 enum bcm47xxsflash_type type; 65 67
+31 -27
drivers/mtd/devices/block2mtd.c
··· 6 6 * 7 7 * Licence: GPL 8 8 */ 9 + 10 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 + 9 12 #include <linux/module.h> 10 13 #include <linux/fs.h> 11 14 #include <linux/blkdev.h> ··· 20 17 #include <linux/mutex.h> 21 18 #include <linux/mount.h> 22 19 #include <linux/slab.h> 23 - 24 - #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) 25 - #define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args) 26 - 27 20 28 21 /* Info for the block device */ 29 22 struct block2mtd_dev { ··· 83 84 err = _block2mtd_erase(dev, from, len); 84 85 mutex_unlock(&dev->write_mutex); 85 86 if (err) { 86 - ERROR("erase failed err = %d", err); 87 + pr_err("erase failed err = %d\n", err); 87 88 instr->state = MTD_ERASE_FAILED; 88 89 } else 89 90 instr->state = MTD_ERASE_DONE; ··· 238 239 #endif 239 240 240 241 if (IS_ERR(bdev)) { 241 - ERROR("error: cannot open device %s", devname); 242 + pr_err("error: cannot open device %s\n", devname); 242 243 goto devinit_err; 243 244 } 244 245 dev->blkdev = bdev; 245 246 246 247 if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { 247 - ERROR("attempting to use an MTD device as a block device"); 248 + pr_err("attempting to use an MTD device as a block device\n"); 248 249 goto devinit_err; 249 250 } 250 251 ··· 276 277 goto devinit_err; 277 278 } 278 279 list_add(&dev->list, &blkmtd_device_list); 279 - INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index, 280 - dev->mtd.name + strlen("block2mtd: "), 281 - dev->mtd.erasesize >> 10, dev->mtd.erasesize); 280 + pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 281 + dev->mtd.index, 282 + dev->mtd.name + strlen("block2mtd: "), 283 + dev->mtd.erasesize >> 10, dev->mtd.erasesize); 282 284 return dev; 283 285 284 286 devinit_err: ··· 339 339 } 340 340 341 341 342 - #define parse_err(fmt, args...) do { \ 343 - ERROR(fmt, ## args); \ 344 - return 0; \ 345 - } while (0) 346 - 347 342 #ifndef MODULE 348 343 static int block2mtd_init_called = 0; 349 344 static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */ 350 345 #endif 351 - 352 346 353 347 static int block2mtd_setup2(const char *val) 354 348 { ··· 353 359 size_t erase_size = PAGE_SIZE; 354 360 int i, ret; 355 361 356 - if (strnlen(val, sizeof(buf)) >= sizeof(buf)) 357 - parse_err("parameter too long"); 362 + if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 363 + pr_err("parameter too long\n"); 364 + return 0; 365 + } 358 366 359 367 strcpy(str, val); 360 368 kill_final_newline(str); ··· 364 368 for (i = 0; i < 2; i++) 365 369 token[i] = strsep(&str, ","); 366 370 367 - if (str) 368 - parse_err("too many arguments"); 371 + if (str) { 372 + pr_err("too many arguments\n"); 373 + return 0; 374 + } 369 375 370 - if (!token[0]) 371 - parse_err("no argument"); 376 + if (!token[0]) { 377 + pr_err("no argument\n"); 378 + return 0; 379 + } 372 380 373 381 name = token[0]; 374 - if (strlen(name) + 1 > 80) 375 - parse_err("device name too long"); 382 + if (strlen(name) + 1 > 80) { 383 + pr_err("device name too long\n"); 384 + return 0; 385 + } 376 386 377 387 if (token[1]) { 378 388 ret = parse_num(&erase_size, token[1]); 379 389 if (ret) { 380 - parse_err("illegal erase size"); 390 + pr_err("illegal erase size\n"); 391 + return 0; 381 392 } 382 393 } 383 394 ··· 447 444 struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list); 448 445 block2mtd_sync(&dev->mtd); 449 446 mtd_device_unregister(&dev->mtd); 450 - INFO("mtd%d: [%s] removed", dev->mtd.index, 451 - dev->mtd.name + strlen("block2mtd: ")); 447 + pr_info("mtd%d: [%s] removed\n", 448 + dev->mtd.index, 449 + dev->mtd.name + strlen("block2mtd: ")); 452 450 list_del(&dev->list); 453 451 block2mtd_free_device(dev); 454 452 }
+120 -9
drivers/mtd/devices/elm.c
··· 20 20 #include <linux/interrupt.h> 21 21 #include <linux/io.h> 22 22 #include <linux/of.h> 23 + #include <linux/sched.h> 23 24 #include <linux/pm_runtime.h> 24 25 #include <linux/platform_data/elm.h> 25 26 27 + #define ELM_SYSCONFIG 0x010 26 28 #define ELM_IRQSTATUS 0x018 27 29 #define ELM_IRQENABLE 0x01c 28 30 #define ELM_LOCATION_CONFIG 0x020 29 31 #define ELM_PAGE_CTRL 0x080 30 32 #define ELM_SYNDROME_FRAGMENT_0 0x400 33 + #define ELM_SYNDROME_FRAGMENT_1 0x404 34 + #define ELM_SYNDROME_FRAGMENT_2 0x408 35 + #define ELM_SYNDROME_FRAGMENT_3 0x40c 36 + #define ELM_SYNDROME_FRAGMENT_4 0x410 37 + #define ELM_SYNDROME_FRAGMENT_5 0x414 31 38 #define ELM_SYNDROME_FRAGMENT_6 0x418 32 39 #define ELM_LOCATION_STATUS 0x800 33 40 #define ELM_ERROR_LOCATION_0 0x880 ··· 63 56 #define SYNDROME_FRAGMENT_REG_SIZE 0x40 64 57 #define ERROR_LOCATION_SIZE 0x100 65 58 59 + struct elm_registers { 60 + u32 elm_irqenable; 61 + u32 elm_sysconfig; 62 + u32 elm_location_config; 63 + u32 elm_page_ctrl; 64 + u32 elm_syndrome_fragment_6[ERROR_VECTOR_MAX]; 65 + u32 elm_syndrome_fragment_5[ERROR_VECTOR_MAX]; 66 + u32 elm_syndrome_fragment_4[ERROR_VECTOR_MAX]; 67 + u32 elm_syndrome_fragment_3[ERROR_VECTOR_MAX]; 68 + u32 elm_syndrome_fragment_2[ERROR_VECTOR_MAX]; 69 + u32 elm_syndrome_fragment_1[ERROR_VECTOR_MAX]; 70 + u32 elm_syndrome_fragment_0[ERROR_VECTOR_MAX]; 71 + }; 72 + 66 73 struct elm_info { 67 74 struct device *dev; 68 75 void __iomem *elm_base; 69 76 struct completion elm_completion; 70 77 struct list_head list; 71 78 enum bch_ecc bch_type; 79 + struct elm_registers elm_regs; 72 80 }; 73 81 74 82 static LIST_HEAD(elm_devices); ··· 368 346 } 369 347 370 348 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 371 - if (!res) { 372 - dev_err(&pdev->dev, "no memory resource defined\n"); 373 - return -ENODEV; 374 - } 375 - 376 - info->elm_base = devm_request_and_ioremap(&pdev->dev, res); 377 - if (!info->elm_base) 378 - return -EADDRNOTAVAIL; 349 + info->elm_base = devm_ioremap_resource(&pdev->dev, res); 350 + if (IS_ERR(info->elm_base)) 351 + return PTR_ERR(info->elm_base); 379 352 380 353 ret = devm_request_irq(&pdev->dev, irq->start, elm_isr, 0, 381 354 pdev->name, info); ··· 398 381 { 399 382 pm_runtime_put_sync(&pdev->dev); 400 383 pm_runtime_disable(&pdev->dev); 401 - platform_set_drvdata(pdev, NULL); 402 384 return 0; 403 385 } 386 + 387 + /** 388 + * elm_context_save 389 + * saves ELM configurations to preserve them across Hardware powered-down 390 + */ 391 + static int elm_context_save(struct elm_info *info) 392 + { 393 + struct elm_registers *regs = &info->elm_regs; 394 + enum bch_ecc bch_type = info->bch_type; 395 + u32 offset = 0, i; 396 + 397 + regs->elm_irqenable = elm_read_reg(info, ELM_IRQENABLE); 398 + regs->elm_sysconfig = elm_read_reg(info, ELM_SYSCONFIG); 399 + regs->elm_location_config = elm_read_reg(info, ELM_LOCATION_CONFIG); 400 + regs->elm_page_ctrl = elm_read_reg(info, ELM_PAGE_CTRL); 401 + for (i = 0; i < ERROR_VECTOR_MAX; i++) { 402 + offset = i * SYNDROME_FRAGMENT_REG_SIZE; 403 + switch (bch_type) { 404 + case BCH8_ECC: 405 + regs->elm_syndrome_fragment_3[i] = elm_read_reg(info, 406 + ELM_SYNDROME_FRAGMENT_3 + offset); 407 + regs->elm_syndrome_fragment_2[i] = elm_read_reg(info, 408 + ELM_SYNDROME_FRAGMENT_2 + offset); 409 + case BCH4_ECC: 410 + regs->elm_syndrome_fragment_1[i] = elm_read_reg(info, 411 + ELM_SYNDROME_FRAGMENT_1 + offset); 412 + regs->elm_syndrome_fragment_0[i] = elm_read_reg(info, 413 + ELM_SYNDROME_FRAGMENT_0 + offset); 414 + default: 415 + return -EINVAL; 416 + } 417 + /* ELM SYNDROME_VALID bit in SYNDROME_FRAGMENT_6[] needs 418 + * to be saved for all BCH schemes*/ 419 + regs->elm_syndrome_fragment_6[i] = elm_read_reg(info, 420 + ELM_SYNDROME_FRAGMENT_6 + offset); 421 + } 422 + return 0; 423 + } 424 + 425 + /** 426 + * elm_context_restore 427 + * writes configurations saved duing power-down back into ELM registers 428 + */ 429 + static int elm_context_restore(struct elm_info *info) 430 + { 431 + struct elm_registers *regs = &info->elm_regs; 432 + enum bch_ecc bch_type = info->bch_type; 433 + u32 offset = 0, i; 434 + 435 + elm_write_reg(info, ELM_IRQENABLE, regs->elm_irqenable); 436 + elm_write_reg(info, ELM_SYSCONFIG, regs->elm_sysconfig); 437 + elm_write_reg(info, ELM_LOCATION_CONFIG, regs->elm_location_config); 438 + elm_write_reg(info, ELM_PAGE_CTRL, regs->elm_page_ctrl); 439 + for (i = 0; i < ERROR_VECTOR_MAX; i++) { 440 + offset = i * SYNDROME_FRAGMENT_REG_SIZE; 441 + switch (bch_type) { 442 + case BCH8_ECC: 443 + elm_write_reg(info, ELM_SYNDROME_FRAGMENT_3 + offset, 444 + regs->elm_syndrome_fragment_3[i]); 445 + elm_write_reg(info, ELM_SYNDROME_FRAGMENT_2 + offset, 446 + regs->elm_syndrome_fragment_2[i]); 447 + case BCH4_ECC: 448 + elm_write_reg(info, ELM_SYNDROME_FRAGMENT_1 + offset, 449 + regs->elm_syndrome_fragment_1[i]); 450 + elm_write_reg(info, ELM_SYNDROME_FRAGMENT_0 + offset, 451 + regs->elm_syndrome_fragment_0[i]); 452 + default: 453 + return -EINVAL; 454 + } 455 + /* ELM_SYNDROME_VALID bit to be set in last to trigger FSM */ 456 + elm_write_reg(info, ELM_SYNDROME_FRAGMENT_6 + offset, 457 + regs->elm_syndrome_fragment_6[i] & 458 + ELM_SYNDROME_VALID); 459 + } 460 + return 0; 461 + } 462 + 463 + static int elm_suspend(struct device *dev) 464 + { 465 + struct elm_info *info = dev_get_drvdata(dev); 466 + elm_context_save(info); 467 + pm_runtime_put_sync(dev); 468 + return 0; 469 + } 470 + 471 + static int elm_resume(struct device *dev) 472 + { 473 + struct elm_info *info = dev_get_drvdata(dev); 474 + pm_runtime_get_sync(dev); 475 + elm_context_restore(info); 476 + return 0; 477 + } 478 + 479 + static SIMPLE_DEV_PM_OPS(elm_pm_ops, elm_suspend, elm_resume); 404 480 405 481 #ifdef CONFIG_OF 406 482 static const struct of_device_id elm_of_match[] = { ··· 508 398 .name = "elm", 509 399 .owner = THIS_MODULE, 510 400 .of_match_table = of_match_ptr(elm_of_match), 401 + .pm = &elm_pm_ops, 511 402 }, 512 403 .probe = elm_probe, 513 404 .remove = elm_remove,
+60 -21
drivers/mtd/devices/m25p80.c
··· 43 43 #define OPCODE_FAST_READ 0x0b /* Read data bytes (high frequency) */ 44 44 #define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */ 45 45 #define OPCODE_BE_4K 0x20 /* Erase 4KiB block */ 46 + #define OPCODE_BE_4K_PMC 0xd7 /* Erase 4KiB block on PMC chips */ 46 47 #define OPCODE_BE_32K 0x52 /* Erase 32KiB block */ 47 48 #define OPCODE_CHIP_ERASE 0xc7 /* Erase whole flash chip */ 48 49 #define OPCODE_SE 0xd8 /* Sector erase (usually 64KiB) */ 49 50 #define OPCODE_RDID 0x9f /* Read JEDEC ID */ 51 + 52 + /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */ 53 + #define OPCODE_NORM_READ_4B 0x13 /* Read data bytes (low frequency) */ 54 + #define OPCODE_FAST_READ_4B 0x0c /* Read data bytes (high frequency) */ 55 + #define OPCODE_PP_4B 0x12 /* Page program (up to 256 bytes) */ 56 + #define OPCODE_SE_4B 0xdc /* Sector erase (usually 64KiB) */ 50 57 51 58 /* Used for SST flashes only. */ 52 59 #define OPCODE_BP 0x02 /* Byte program */ 53 60 #define OPCODE_WRDI 0x04 /* Write disable */ 54 61 #define OPCODE_AAI_WP 0xad /* Auto address increment word program */ 55 62 56 - /* Used for Macronix flashes only. */ 63 + /* Used for Macronix and Winbond flashes. */ 57 64 #define OPCODE_EN4B 0xb7 /* Enter 4-byte mode */ 58 65 #define OPCODE_EX4B 0xe9 /* Exit 4-byte mode */ 59 66 ··· 91 84 u16 page_size; 92 85 u16 addr_width; 93 86 u8 erase_opcode; 87 + u8 read_opcode; 88 + u8 program_opcode; 94 89 u8 *command; 95 90 bool fast_read; 96 91 }; ··· 170 161 { 171 162 switch (JEDEC_MFR(jedec_id)) { 172 163 case CFI_MFR_MACRONIX: 164 + case CFI_MFR_ST: /* Micron, actually */ 173 165 case 0xEF /* winbond */: 174 166 flash->command[0] = enable ? OPCODE_EN4B : OPCODE_EX4B; 175 167 return spi_write(flash->spi, flash->command, 1); ··· 381 371 */ 382 372 383 373 /* Set up the write data buffer. */ 384 - opcode = flash->fast_read ? OPCODE_FAST_READ : OPCODE_NORM_READ; 374 + opcode = flash->read_opcode; 385 375 flash->command[0] = opcode; 386 376 m25p_addr2cmd(flash, from, flash->command); 387 377 ··· 432 422 write_enable(flash); 433 423 434 424 /* Set up the opcode in the write buffer. */ 435 - flash->command[0] = OPCODE_PP; 425 + flash->command[0] = flash->program_opcode; 436 426 m25p_addr2cmd(flash, to, flash->command); 437 427 438 428 page_offset = to & (flash->page_size - 1); ··· 692 682 #define SECT_4K 0x01 /* OPCODE_BE_4K works uniformly */ 693 683 #define M25P_NO_ERASE 0x02 /* No erase command needed */ 694 684 #define SST_WRITE 0x04 /* use SST byte programming */ 685 + #define M25P_NO_FR 0x08 /* Can't do fastread */ 686 + #define SECT_4K_PMC 0x10 /* OPCODE_BE_4K_PMC works uniformly */ 695 687 }; 696 688 697 689 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ ··· 706 694 .flags = (_flags), \ 707 695 }) 708 696 709 - #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width) \ 697 + #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width, _flags) \ 710 698 ((kernel_ulong_t)&(struct flash_info) { \ 711 699 .sector_size = (_sector_size), \ 712 700 .n_sectors = (_n_sectors), \ 713 701 .page_size = (_page_size), \ 714 702 .addr_width = (_addr_width), \ 715 - .flags = M25P_NO_ERASE, \ 703 + .flags = (_flags), \ 716 704 }) 717 705 718 706 /* NOTE: double check command sets and memory organization when you add ··· 744 732 { "en25qh256", INFO(0x1c7019, 0, 64 * 1024, 512, 0) }, 745 733 746 734 /* Everspin */ 747 - { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2) }, 735 + { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, M25P_NO_ERASE | M25P_NO_FR) }, 736 + { "mr25h10", CAT25_INFO(128 * 1024, 1, 256, 3, M25P_NO_ERASE | M25P_NO_FR) }, 748 737 749 738 /* GigaDevice */ 750 739 { "gd25q32", INFO(0xc84016, 0, 64 * 1024, 64, SECT_4K) }, ··· 774 761 { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, 0) }, 775 762 { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, 0) }, 776 763 { "n25q256a", INFO(0x20ba19, 0, 64 * 1024, 512, SECT_4K) }, 764 + 765 + /* PMC */ 766 + { "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) }, 767 + { "pm25lv010", INFO(0, 0, 32 * 1024, 4, SECT_4K_PMC) }, 768 + { "pm25lq032", INFO(0x7f9d46, 0, 64 * 1024, 64, SECT_4K) }, 777 769 778 770 /* Spansion -- single (large) sector size only, at least 779 771 * for the chips listed here (without boot sectors). ··· 858 840 { "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64, SECT_4K) }, 859 841 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 860 842 { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, 843 + { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) }, 861 844 { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) }, 862 845 { "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) }, 863 846 { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) }, 864 847 { "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, SECT_4K) }, 865 848 866 849 /* Catalyst / On Semiconductor -- non-JEDEC */ 867 - { "cat25c11", CAT25_INFO( 16, 8, 16, 1) }, 868 - { "cat25c03", CAT25_INFO( 32, 8, 16, 2) }, 869 - { "cat25c09", CAT25_INFO( 128, 8, 32, 2) }, 870 - { "cat25c17", CAT25_INFO( 256, 8, 32, 2) }, 871 - { "cat25128", CAT25_INFO(2048, 8, 64, 2) }, 850 + { "cat25c11", CAT25_INFO( 16, 8, 16, 1, M25P_NO_ERASE | M25P_NO_FR) }, 851 + { "cat25c03", CAT25_INFO( 32, 8, 16, 2, M25P_NO_ERASE | M25P_NO_FR) }, 852 + { "cat25c09", CAT25_INFO( 128, 8, 32, 2, M25P_NO_ERASE | M25P_NO_FR) }, 853 + { "cat25c17", CAT25_INFO( 256, 8, 32, 2, M25P_NO_ERASE | M25P_NO_FR) }, 854 + { "cat25128", CAT25_INFO(2048, 8, 64, 2, M25P_NO_ERASE | M25P_NO_FR) }, 872 855 { }, 873 856 }; 874 857 MODULE_DEVICE_TABLE(spi, m25p_ids); ··· 939 920 * a chip ID, try the JEDEC id commands; they'll work for most 940 921 * newer chips, even if we don't recognize the particular chip. 941 922 */ 942 - data = spi->dev.platform_data; 923 + data = dev_get_platdata(&spi->dev); 943 924 if (data && data->type) { 944 925 const struct spi_device_id *plat_id; 945 926 ··· 991 972 992 973 flash->spi = spi; 993 974 mutex_init(&flash->lock); 994 - dev_set_drvdata(&spi->dev, flash); 975 + spi_set_drvdata(spi, flash); 995 976 996 977 /* 997 978 * Atmel, SST and Intel/Numonyx serial flash tend to power ··· 1033 1014 if (info->flags & SECT_4K) { 1034 1015 flash->erase_opcode = OPCODE_BE_4K; 1035 1016 flash->mtd.erasesize = 4096; 1017 + } else if (info->flags & SECT_4K_PMC) { 1018 + flash->erase_opcode = OPCODE_BE_4K_PMC; 1019 + flash->mtd.erasesize = 4096; 1036 1020 } else { 1037 1021 flash->erase_opcode = OPCODE_SE; 1038 1022 flash->mtd.erasesize = info->sector_size; ··· 1050 1028 flash->mtd.writebufsize = flash->page_size; 1051 1029 1052 1030 flash->fast_read = false; 1053 - #ifdef CONFIG_OF 1054 1031 if (np && of_property_read_bool(np, "m25p,fast-read")) 1055 1032 flash->fast_read = true; 1056 - #endif 1057 1033 1058 1034 #ifdef CONFIG_M25PXX_USE_FAST_READ 1059 1035 flash->fast_read = true; 1060 1036 #endif 1037 + if (info->flags & M25P_NO_FR) 1038 + flash->fast_read = false; 1039 + 1040 + /* Default commands */ 1041 + if (flash->fast_read) 1042 + flash->read_opcode = OPCODE_FAST_READ; 1043 + else 1044 + flash->read_opcode = OPCODE_NORM_READ; 1045 + 1046 + flash->program_opcode = OPCODE_PP; 1061 1047 1062 1048 if (info->addr_width) 1063 1049 flash->addr_width = info->addr_width; 1064 - else { 1050 + else if (flash->mtd.size > 0x1000000) { 1065 1051 /* enable 4-byte addressing if the device exceeds 16MiB */ 1066 - if (flash->mtd.size > 0x1000000) { 1067 - flash->addr_width = 4; 1068 - set_4byte(flash, info->jedec_id, 1); 1052 + flash->addr_width = 4; 1053 + if (JEDEC_MFR(info->jedec_id) == CFI_MFR_AMD) { 1054 + /* Dedicated 4-byte command set */ 1055 + flash->read_opcode = flash->fast_read ? 1056 + OPCODE_FAST_READ_4B : 1057 + OPCODE_NORM_READ_4B; 1058 + flash->program_opcode = OPCODE_PP_4B; 1059 + /* No small sector erase for 4-byte command set */ 1060 + flash->erase_opcode = OPCODE_SE_4B; 1061 + flash->mtd.erasesize = info->sector_size; 1069 1062 } else 1070 - flash->addr_width = 3; 1063 + set_4byte(flash, info->jedec_id, 1); 1064 + } else { 1065 + flash->addr_width = 3; 1071 1066 } 1072 1067 1073 1068 dev_info(&spi->dev, "%s (%lld Kbytes)\n", id->name, ··· 1119 1080 1120 1081 static int m25p_remove(struct spi_device *spi) 1121 1082 { 1122 - struct m25p *flash = dev_get_drvdata(&spi->dev); 1083 + struct m25p *flash = spi_get_drvdata(spi); 1123 1084 int status; 1124 1085 1125 1086 /* Clean up MTD stuff. */
+5 -5
drivers/mtd/devices/mtd_dataflash.c
··· 622 622 struct dataflash *priv; 623 623 struct mtd_info *device; 624 624 struct mtd_part_parser_data ppdata; 625 - struct flash_platform_data *pdata = spi->dev.platform_data; 625 + struct flash_platform_data *pdata = dev_get_platdata(&spi->dev); 626 626 char *otp_tag = ""; 627 627 int err = 0; 628 628 ··· 661 661 dev_info(&spi->dev, "%s (%lld KBytes) pagesize %d bytes%s\n", 662 662 name, (long long)((device->size + 1023) >> 10), 663 663 pagesize, otp_tag); 664 - dev_set_drvdata(&spi->dev, priv); 664 + spi_set_drvdata(spi, priv); 665 665 666 666 ppdata.of_node = spi->dev.of_node; 667 667 err = mtd_device_parse_register(device, NULL, &ppdata, ··· 671 671 if (!err) 672 672 return 0; 673 673 674 - dev_set_drvdata(&spi->dev, NULL); 674 + spi_set_drvdata(spi, NULL); 675 675 kfree(priv); 676 676 return err; 677 677 } ··· 895 895 896 896 static int dataflash_remove(struct spi_device *spi) 897 897 { 898 - struct dataflash *flash = dev_get_drvdata(&spi->dev); 898 + struct dataflash *flash = spi_get_drvdata(spi); 899 899 int status; 900 900 901 901 pr_debug("%s: remove\n", dev_name(&spi->dev)); 902 902 903 903 status = mtd_device_unregister(&flash->mtd); 904 904 if (status == 0) { 905 - dev_set_drvdata(&spi->dev, NULL); 905 + spi_set_drvdata(spi, NULL); 906 906 kfree(flash); 907 907 } 908 908 return status;
+7 -12
drivers/mtd/devices/spear_smi.c
··· 550 550 { 551 551 struct spear_snor_flash *flash = get_flash_data(mtd); 552 552 struct spear_smi *dev = mtd->priv; 553 - void *src; 553 + void __iomem *src; 554 554 u32 ctrlreg1, val; 555 555 int ret; 556 556 ··· 583 583 584 584 writel(val, dev->io_base + SMI_CR1); 585 585 586 - memcpy_fromio(buf, (u8 *)src, len); 586 + memcpy_fromio(buf, src, len); 587 587 588 588 /* restore ctrl reg1 */ 589 589 writel(ctrlreg1, dev->io_base + SMI_CR1); ··· 596 596 } 597 597 598 598 static inline int spear_smi_cpy_toio(struct spear_smi *dev, u32 bank, 599 - void *dest, const void *src, size_t len) 599 + void __iomem *dest, const void *src, size_t len) 600 600 { 601 601 int ret; 602 602 u32 ctrlreg1; ··· 643 643 { 644 644 struct spear_snor_flash *flash = get_flash_data(mtd); 645 645 struct spear_smi *dev = mtd->priv; 646 - void *dest; 646 + void __iomem *dest; 647 647 u32 page_offset, page_size; 648 648 int ret; 649 649 ··· 995 995 ret = spear_smi_setup_banks(pdev, i, pdata->np[i]); 996 996 if (ret) { 997 997 dev_err(&dev->pdev->dev, "bank setup failed\n"); 998 - goto err_bank_setup; 998 + goto err_irq; 999 999 } 1000 1000 } 1001 1001 1002 1002 return 0; 1003 1003 1004 - err_bank_setup: 1005 - platform_set_drvdata(pdev, NULL); 1006 1004 err_irq: 1007 1005 clk_disable_unprepare(dev->clk); 1008 1006 err: ··· 1038 1040 } 1039 1041 1040 1042 clk_disable_unprepare(dev->clk); 1041 - platform_set_drvdata(pdev, NULL); 1042 1043 1043 1044 return 0; 1044 1045 } 1045 1046 1046 - #ifdef CONFIG_PM 1047 + #ifdef CONFIG_PM_SLEEP 1047 1048 static int spear_smi_suspend(struct device *dev) 1048 1049 { 1049 1050 struct spear_smi *sdev = dev_get_drvdata(dev); ··· 1065 1068 spear_smi_hw_init(sdev); 1066 1069 return ret; 1067 1070 } 1071 + #endif 1068 1072 1069 1073 static SIMPLE_DEV_PM_OPS(spear_smi_pm_ops, spear_smi_suspend, spear_smi_resume); 1070 - #endif 1071 1074 1072 1075 #ifdef CONFIG_OF 1073 1076 static const struct of_device_id spear_smi_id_table[] = { ··· 1083 1086 .bus = &platform_bus_type, 1084 1087 .owner = THIS_MODULE, 1085 1088 .of_match_table = of_match_ptr(spear_smi_id_table), 1086 - #ifdef CONFIG_PM 1087 1089 .pm = &spear_smi_pm_ops, 1088 - #endif 1089 1090 }, 1090 1091 .probe = spear_smi_probe, 1091 1092 .remove = spear_smi_remove,
+4 -4
drivers/mtd/devices/sst25l.c
··· 370 370 371 371 flash->spi = spi; 372 372 mutex_init(&flash->lock); 373 - dev_set_drvdata(&spi->dev, flash); 373 + spi_set_drvdata(spi, flash); 374 374 375 - data = spi->dev.platform_data; 375 + data = dev_get_platdata(&spi->dev); 376 376 if (data && data->name) 377 377 flash->mtd.name = data->name; 378 378 else ··· 404 404 data ? data->nr_parts : 0); 405 405 if (ret) { 406 406 kfree(flash); 407 - dev_set_drvdata(&spi->dev, NULL); 407 + spi_set_drvdata(spi, NULL); 408 408 return -ENODEV; 409 409 } 410 410 ··· 413 413 414 414 static int sst25l_remove(struct spi_device *spi) 415 415 { 416 - struct sst25l_flash *flash = dev_get_drvdata(&spi->dev); 416 + struct sst25l_flash *flash = spi_get_drvdata(spi); 417 417 int ret; 418 418 419 419 ret = mtd_device_unregister(&flash->mtd);
-18
drivers/mtd/maps/Kconfig
··· 157 157 help 158 158 This provides a driver for the NOR flash attached to a PXA2xx chip. 159 159 160 - config MTD_OCTAGON 161 - tristate "JEDEC Flash device mapped on Octagon 5066 SBC" 162 - depends on X86 && MTD_JEDEC && MTD_COMPLEX_MAPPINGS 163 - help 164 - This provides a 'mapping' driver which supports the way in which 165 - the flash chips are connected in the Octagon-5066 Single Board 166 - Computer. More information on the board is available at 167 - <http://www.octagonsystems.com/products/5066.aspx>. 168 - 169 - config MTD_VMAX 170 - tristate "JEDEC Flash device mapped on Tempustech VMAX SBC301" 171 - depends on X86 && MTD_JEDEC && MTD_COMPLEX_MAPPINGS 172 - help 173 - This provides a 'mapping' driver which supports the way in which 174 - the flash chips are connected in the Tempustech VMAX SBC301 Single 175 - Board Computer. More information on the board is available at 176 - <http://www.tempustech.com/>. 177 - 178 160 config MTD_SCx200_DOCFLASH 179 161 tristate "Flash device mapped with DOCCS on NatSemi SCx200" 180 162 depends on SCx200 && MTD_CFI
-2
drivers/mtd/maps/Makefile
··· 16 16 obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o 17 17 obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 18 18 obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o 19 - obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 20 19 obj-$(CONFIG_MTD_PHYSMAP) += physmap.o 21 20 obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o 22 21 obj-$(CONFIG_MTD_PISMO) += pismo.o ··· 27 28 obj-$(CONFIG_MTD_NETSC520) += netsc520.o 28 29 obj-$(CONFIG_MTD_TS5500) += ts5500_flash.o 29 30 obj-$(CONFIG_MTD_SUN_UFLASH) += sun_uflash.o 30 - obj-$(CONFIG_MTD_VMAX) += vmax301.o 31 31 obj-$(CONFIG_MTD_SCx200_DOCFLASH)+= scx200_docflash.o 32 32 obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 33 33 obj-$(CONFIG_MTD_PCI) += pci.o
+1 -1
drivers/mtd/maps/bfin-async-flash.c
··· 128 128 static int bfin_flash_probe(struct platform_device *pdev) 129 129 { 130 130 int ret; 131 - struct physmap_flash_data *pdata = pdev->dev.platform_data; 131 + struct physmap_flash_data *pdata = dev_get_platdata(&pdev->dev); 132 132 struct resource *memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); 133 133 struct resource *flash_ambctl = platform_get_resource(pdev, IORESOURCE_MEM, 1); 134 134 struct async_state *state;
+5 -5
drivers/mtd/maps/cfi_flagadm.c
··· 55 55 #define FLASH_PARTITION3_SIZE 0x001C0000 56 56 57 57 58 - struct map_info flagadm_map = { 58 + static struct map_info flagadm_map = { 59 59 .name = "FlagaDM flash device", 60 60 .size = FLASH_SIZE, 61 61 .bankwidth = 2, 62 62 }; 63 63 64 - struct mtd_partition flagadm_parts[] = { 64 + static struct mtd_partition flagadm_parts[] = { 65 65 { 66 66 .name = "Bootloader", 67 67 .offset = FLASH_PARTITION0_ADDR, ··· 112 112 return 0; 113 113 } 114 114 115 - iounmap((void *)flagadm_map.virt); 115 + iounmap((void __iomem *)flagadm_map.virt); 116 116 return -ENXIO; 117 117 } 118 118 ··· 123 123 map_destroy(mymtd); 124 124 } 125 125 if (flagadm_map.virt) { 126 - iounmap((void *)flagadm_map.virt); 127 - flagadm_map.virt = 0; 126 + iounmap((void __iomem *)flagadm_map.virt); 127 + flagadm_map.virt = NULL; 128 128 } 129 129 } 130 130
+1 -1
drivers/mtd/maps/gpio-addr-flash.c
··· 196 196 struct resource *gpios; 197 197 struct async_state *state; 198 198 199 - pdata = pdev->dev.platform_data; 199 + pdata = dev_get_platdata(&pdev->dev); 200 200 memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); 201 201 gpios = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 202 202
+5 -5
drivers/mtd/maps/impa7.c
··· 79 79 } 80 80 simple_map_init(&impa7_map[i]); 81 81 82 - impa7_mtd[i] = 0; 82 + impa7_mtd[i] = NULL; 83 83 type = rom_probe_types; 84 84 for(; !impa7_mtd[i] && *type; type++) { 85 85 impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]); ··· 91 91 mtd_device_parse_register(impa7_mtd[i], NULL, NULL, 92 92 partitions, 93 93 ARRAY_SIZE(partitions)); 94 + } else { 95 + iounmap((void __iomem *)impa7_map[i].virt); 94 96 } 95 - else 96 - iounmap((void *)impa7_map[i].virt); 97 97 } 98 98 return devicesfound == 0 ? -ENXIO : 0; 99 99 } ··· 105 105 if (impa7_mtd[i]) { 106 106 mtd_device_unregister(impa7_mtd[i]); 107 107 map_destroy(impa7_mtd[i]); 108 - iounmap((void *)impa7_map[i].virt); 109 - impa7_map[i].virt = 0; 108 + iounmap((void __iomem *)impa7_map[i].virt); 109 + impa7_map[i].virt = NULL; 110 110 } 111 111 } 112 112 }
+2 -4
drivers/mtd/maps/ixp4xx.c
··· 152 152 153 153 static int ixp4xx_flash_remove(struct platform_device *dev) 154 154 { 155 - struct flash_platform_data *plat = dev->dev.platform_data; 155 + struct flash_platform_data *plat = dev_get_platdata(&dev->dev); 156 156 struct ixp4xx_flash_info *info = platform_get_drvdata(dev); 157 - 158 - platform_set_drvdata(dev, NULL); 159 157 160 158 if(!info) 161 159 return 0; ··· 178 180 179 181 static int ixp4xx_flash_probe(struct platform_device *dev) 180 182 { 181 - struct flash_platform_data *plat = dev->dev.platform_data; 183 + struct flash_platform_data *plat = dev_get_platdata(&dev->dev); 182 184 struct ixp4xx_flash_info *info; 183 185 struct mtd_part_parser_data ppdata = { 184 186 .origin = dev->resource->start,
+2 -3
drivers/mtd/maps/latch-addr-flash.c
··· 102 102 info = platform_get_drvdata(dev); 103 103 if (info == NULL) 104 104 return 0; 105 - platform_set_drvdata(dev, NULL); 106 105 107 - latch_addr_data = dev->dev.platform_data; 106 + latch_addr_data = dev_get_platdata(&dev->dev); 108 107 109 108 if (info->mtd != NULL) { 110 109 mtd_device_unregister(info->mtd); ··· 134 135 int chipsel; 135 136 int err; 136 137 137 - latch_addr_data = dev->dev.platform_data; 138 + latch_addr_data = dev_get_platdata(&dev->dev); 138 139 if (latch_addr_data == NULL) 139 140 return -ENODEV; 140 141
-246
drivers/mtd/maps/octagon-5066.c
··· 1 - /* ###################################################################### 2 - 3 - Octagon 5066 MTD Driver. 4 - 5 - The Octagon 5066 is a SBC based on AMD's 586-WB running at 133 MHZ. It 6 - comes with a builtin AMD 29F016 flash chip and a socketed EEPROM that 7 - is replacable by flash. Both units are mapped through a multiplexer 8 - into a 32k memory window at 0xe8000. The control register for the 9 - multiplexing unit is located at IO 0x208 with a bit map of 10 - 0-5 Page Selection in 32k increments 11 - 6-7 Device selection: 12 - 00 SSD off 13 - 01 SSD 0 (Socket) 14 - 10 SSD 1 (Flash chip) 15 - 11 undefined 16 - 17 - On each SSD, the first 128k is reserved for use by the bios 18 - (actually it IS the bios..) This only matters if you are booting off the 19 - flash, you must not put a file system starting there. 20 - 21 - The driver tries to do a detection algorithm to guess what sort of devices 22 - are plugged into the sockets. 23 - 24 - ##################################################################### */ 25 - 26 - #include <linux/module.h> 27 - #include <linux/ioport.h> 28 - #include <linux/init.h> 29 - #include <asm/io.h> 30 - 31 - #include <linux/mtd/map.h> 32 - #include <linux/mtd/mtd.h> 33 - 34 - #define WINDOW_START 0xe8000 35 - #define WINDOW_LENGTH 0x8000 36 - #define WINDOW_SHIFT 27 37 - #define WINDOW_MASK 0x7FFF 38 - #define PAGE_IO 0x208 39 - 40 - static volatile char page_n_dev = 0; 41 - static unsigned long iomapadr; 42 - static DEFINE_SPINLOCK(oct5066_spin); 43 - 44 - /* 45 - * We use map_priv_1 to identify which device we are. 46 - */ 47 - 48 - static void __oct5066_page(struct map_info *map, __u8 byte) 49 - { 50 - outb(byte,PAGE_IO); 51 - page_n_dev = byte; 52 - } 53 - 54 - static inline void oct5066_page(struct map_info *map, unsigned long ofs) 55 - { 56 - __u8 byte = map->map_priv_1 | (ofs >> WINDOW_SHIFT); 57 - 58 - if (page_n_dev != byte) 59 - __oct5066_page(map, byte); 60 - } 61 - 62 - 63 - static map_word oct5066_read8(struct map_info *map, unsigned long ofs) 64 - { 65 - map_word ret; 66 - spin_lock(&oct5066_spin); 67 - oct5066_page(map, ofs); 68 - ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK)); 69 - spin_unlock(&oct5066_spin); 70 - return ret; 71 - } 72 - 73 - static void oct5066_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 74 - { 75 - while(len) { 76 - unsigned long thislen = len; 77 - if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) 78 - thislen = WINDOW_LENGTH-(from & WINDOW_MASK); 79 - 80 - spin_lock(&oct5066_spin); 81 - oct5066_page(map, from); 82 - memcpy_fromio(to, iomapadr + from, thislen); 83 - spin_unlock(&oct5066_spin); 84 - to += thislen; 85 - from += thislen; 86 - len -= thislen; 87 - } 88 - } 89 - 90 - static void oct5066_write8(struct map_info *map, map_word d, unsigned long adr) 91 - { 92 - spin_lock(&oct5066_spin); 93 - oct5066_page(map, adr); 94 - writeb(d.x[0], iomapadr + (adr & WINDOW_MASK)); 95 - spin_unlock(&oct5066_spin); 96 - } 97 - 98 - static void oct5066_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 99 - { 100 - while(len) { 101 - unsigned long thislen = len; 102 - if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) 103 - thislen = WINDOW_LENGTH-(to & WINDOW_MASK); 104 - 105 - spin_lock(&oct5066_spin); 106 - oct5066_page(map, to); 107 - memcpy_toio(iomapadr + to, from, thislen); 108 - spin_unlock(&oct5066_spin); 109 - to += thislen; 110 - from += thislen; 111 - len -= thislen; 112 - } 113 - } 114 - 115 - static struct map_info oct5066_map[2] = { 116 - { 117 - .name = "Octagon 5066 Socket", 118 - .phys = NO_XIP, 119 - .size = 512 * 1024, 120 - .bankwidth = 1, 121 - .read = oct5066_read8, 122 - .copy_from = oct5066_copy_from, 123 - .write = oct5066_write8, 124 - .copy_to = oct5066_copy_to, 125 - .map_priv_1 = 1<<6 126 - }, 127 - { 128 - .name = "Octagon 5066 Internal Flash", 129 - .phys = NO_XIP, 130 - .size = 2 * 1024 * 1024, 131 - .bankwidth = 1, 132 - .read = oct5066_read8, 133 - .copy_from = oct5066_copy_from, 134 - .write = oct5066_write8, 135 - .copy_to = oct5066_copy_to, 136 - .map_priv_1 = 2<<6 137 - } 138 - }; 139 - 140 - static struct mtd_info *oct5066_mtd[2] = {NULL, NULL}; 141 - 142 - // OctProbe - Sense if this is an octagon card 143 - // --------------------------------------------------------------------- 144 - /* Perform a simple validity test, we map the window select SSD0 and 145 - change pages while monitoring the window. A change in the window, 146 - controlled by the PAGE_IO port is a functioning 5066 board. This will 147 - fail if the thing in the socket is set to a uniform value. */ 148 - static int __init OctProbe(void) 149 - { 150 - unsigned int Base = (1 << 6); 151 - unsigned long I; 152 - unsigned long Values[10]; 153 - for (I = 0; I != 20; I++) 154 - { 155 - outb(Base + (I%10),PAGE_IO); 156 - if (I < 10) 157 - { 158 - // Record the value and check for uniqueness 159 - Values[I%10] = readl(iomapadr); 160 - if (I > 0 && Values[I%10] == Values[0]) 161 - return -EAGAIN; 162 - } 163 - else 164 - { 165 - // Make sure we get the same values on the second pass 166 - if (Values[I%10] != readl(iomapadr)) 167 - return -EAGAIN; 168 - } 169 - } 170 - return 0; 171 - } 172 - 173 - void cleanup_oct5066(void) 174 - { 175 - int i; 176 - for (i=0; i<2; i++) { 177 - if (oct5066_mtd[i]) { 178 - mtd_device_unregister(oct5066_mtd[i]); 179 - map_destroy(oct5066_mtd[i]); 180 - } 181 - } 182 - iounmap((void *)iomapadr); 183 - release_region(PAGE_IO, 1); 184 - } 185 - 186 - static int __init init_oct5066(void) 187 - { 188 - int i; 189 - int ret = 0; 190 - 191 - // Do an autoprobe sequence 192 - if (!request_region(PAGE_IO,1,"Octagon SSD")) { 193 - printk(KERN_NOTICE "5066: Page Register in Use\n"); 194 - return -EAGAIN; 195 - } 196 - iomapadr = (unsigned long)ioremap(WINDOW_START, WINDOW_LENGTH); 197 - if (!iomapadr) { 198 - printk(KERN_NOTICE "Failed to ioremap memory region\n"); 199 - ret = -EIO; 200 - goto out_rel; 201 - } 202 - if (OctProbe() != 0) { 203 - printk(KERN_NOTICE "5066: Octagon Probe Failed, is this an Octagon 5066 SBC?\n"); 204 - iounmap((void *)iomapadr); 205 - ret = -EAGAIN; 206 - goto out_unmap; 207 - } 208 - 209 - // Print out our little header.. 210 - printk("Octagon 5066 SSD IO:0x%x MEM:0x%x-0x%x\n",PAGE_IO,WINDOW_START, 211 - WINDOW_START+WINDOW_LENGTH); 212 - 213 - for (i=0; i<2; i++) { 214 - oct5066_mtd[i] = do_map_probe("cfi_probe", &oct5066_map[i]); 215 - if (!oct5066_mtd[i]) 216 - oct5066_mtd[i] = do_map_probe("jedec", &oct5066_map[i]); 217 - if (!oct5066_mtd[i]) 218 - oct5066_mtd[i] = do_map_probe("map_ram", &oct5066_map[i]); 219 - if (!oct5066_mtd[i]) 220 - oct5066_mtd[i] = do_map_probe("map_rom", &oct5066_map[i]); 221 - if (oct5066_mtd[i]) { 222 - oct5066_mtd[i]->owner = THIS_MODULE; 223 - mtd_device_register(oct5066_mtd[i], NULL, 0); 224 - } 225 - } 226 - 227 - if (!oct5066_mtd[0] && !oct5066_mtd[1]) { 228 - cleanup_oct5066(); 229 - return -ENXIO; 230 - } 231 - 232 - return 0; 233 - 234 - out_unmap: 235 - iounmap((void *)iomapadr); 236 - out_rel: 237 - release_region(PAGE_IO, 1); 238 - return ret; 239 - } 240 - 241 - module_init(init_oct5066); 242 - module_exit(cleanup_oct5066); 243 - 244 - MODULE_LICENSE("GPL"); 245 - MODULE_AUTHOR("Jason Gunthorpe <jgg@deltatee.com>, David Woodhouse <dwmw2@infradead.org>"); 246 - MODULE_DESCRIPTION("MTD map driver for Octagon 5066 Single Board Computer");
+3 -4
drivers/mtd/maps/physmap.c
··· 40 40 info = platform_get_drvdata(dev); 41 41 if (info == NULL) 42 42 return 0; 43 - platform_set_drvdata(dev, NULL); 44 43 45 - physmap_data = dev->dev.platform_data; 44 + physmap_data = dev_get_platdata(&dev->dev); 46 45 47 46 if (info->cmtd) { 48 47 mtd_device_unregister(info->cmtd); ··· 68 69 unsigned long flags; 69 70 70 71 pdev = (struct platform_device *)map->map_priv_1; 71 - physmap_data = pdev->dev.platform_data; 72 + physmap_data = dev_get_platdata(&pdev->dev); 72 73 73 74 if (!physmap_data->set_vpp) 74 75 return; ··· 102 103 int i; 103 104 int devices_found = 0; 104 105 105 - physmap_data = dev->dev.platform_data; 106 + physmap_data = dev_get_platdata(&dev->dev); 106 107 if (physmap_data == NULL) 107 108 return -ENODEV; 108 109
+2 -4
drivers/mtd/maps/plat-ram.c
··· 84 84 { 85 85 struct platram_info *info = to_platram_info(pdev); 86 86 87 - platform_set_drvdata(pdev, NULL); 88 - 89 87 dev_dbg(&pdev->dev, "removing device\n"); 90 88 91 89 if (info == NULL) ··· 128 130 129 131 dev_dbg(&pdev->dev, "probe entered\n"); 130 132 131 - if (pdev->dev.platform_data == NULL) { 133 + if (dev_get_platdata(&pdev->dev) == NULL) { 132 134 dev_err(&pdev->dev, "no platform data supplied\n"); 133 135 err = -ENOENT; 134 136 goto exit_error; 135 137 } 136 138 137 - pdata = pdev->dev.platform_data; 139 + pdata = dev_get_platdata(&pdev->dev); 138 140 139 141 info = kzalloc(sizeof(*info), GFP_KERNEL); 140 142 if (info == NULL) {
+1 -3
drivers/mtd/maps/pxa2xx-flash.c
··· 49 49 50 50 static int pxa2xx_flash_probe(struct platform_device *pdev) 51 51 { 52 - struct flash_platform_data *flash = pdev->dev.platform_data; 52 + struct flash_platform_data *flash = dev_get_platdata(&pdev->dev); 53 53 struct pxa2xx_flash_info *info; 54 54 struct resource *res; 55 55 ··· 106 106 static int pxa2xx_flash_remove(struct platform_device *dev) 107 107 { 108 108 struct pxa2xx_flash_info *info = platform_get_drvdata(dev); 109 - 110 - platform_set_drvdata(dev, NULL); 111 109 112 110 mtd_device_unregister(info->mtd); 113 111
+2 -3
drivers/mtd/maps/rbtx4939-flash.c
··· 34 34 info = platform_get_drvdata(dev); 35 35 if (!info) 36 36 return 0; 37 - platform_set_drvdata(dev, NULL); 38 37 39 38 if (info->mtd) { 40 - struct rbtx4939_flash_data *pdata = dev->dev.platform_data; 39 + struct rbtx4939_flash_data *pdata = dev_get_platdata(&dev->dev); 41 40 42 41 mtd_device_unregister(info->mtd); 43 42 map_destroy(info->mtd); ··· 56 57 int err = 0; 57 58 unsigned long size; 58 59 59 - pdata = dev->dev.platform_data; 60 + pdata = dev_get_platdata(&dev->dev); 60 61 if (!pdata) 61 62 return -ENODEV; 62 63
+2 -3
drivers/mtd/maps/sa1100-flash.c
··· 248 248 249 249 static int sa1100_mtd_probe(struct platform_device *pdev) 250 250 { 251 - struct flash_platform_data *plat = pdev->dev.platform_data; 251 + struct flash_platform_data *plat = dev_get_platdata(&pdev->dev); 252 252 struct sa_info *info; 253 253 int err; 254 254 ··· 277 277 static int __exit sa1100_mtd_remove(struct platform_device *pdev) 278 278 { 279 279 struct sa_info *info = platform_get_drvdata(pdev); 280 - struct flash_platform_data *plat = pdev->dev.platform_data; 280 + struct flash_platform_data *plat = dev_get_platdata(&pdev->dev); 281 281 282 - platform_set_drvdata(pdev, NULL); 283 282 sa1100_destroy(info, plat); 284 283 285 284 return 0;
-196
drivers/mtd/maps/vmax301.c
··· 1 - /* ###################################################################### 2 - 3 - Tempustech VMAX SBC301 MTD Driver. 4 - 5 - The VMAx 301 is a SBC based on . It 6 - comes with three builtin AMD 29F016B flash chips and a socket for SRAM or 7 - more flash. Each unit has it's own 8k mapping into a settable region 8 - (0xD8000). There are two 8k mappings for each MTD, the first is always set 9 - to the lower 8k of the device the second is paged. Writing a 16 bit page 10 - value to anywhere in the first 8k will cause the second 8k to page around. 11 - 12 - To boot the device a bios extension must be installed into the first 8k 13 - of flash that is smart enough to copy itself down, page in the rest of 14 - itself and begin executing. 15 - 16 - ##################################################################### */ 17 - 18 - #include <linux/module.h> 19 - #include <linux/ioport.h> 20 - #include <linux/init.h> 21 - #include <linux/spinlock.h> 22 - #include <asm/io.h> 23 - 24 - #include <linux/mtd/map.h> 25 - #include <linux/mtd/mtd.h> 26 - 27 - 28 - #define WINDOW_START 0xd8000 29 - #define WINDOW_LENGTH 0x2000 30 - #define WINDOW_SHIFT 25 31 - #define WINDOW_MASK 0x1FFF 32 - 33 - /* Actually we could use two spinlocks, but we'd have to have 34 - more private space in the struct map_info. We lose a little 35 - performance like this, but we'd probably lose more by having 36 - the extra indirection from having one of the map->map_priv 37 - fields pointing to yet another private struct. 38 - */ 39 - static DEFINE_SPINLOCK(vmax301_spin); 40 - 41 - static void __vmax301_page(struct map_info *map, unsigned long page) 42 - { 43 - writew(page, map->map_priv_2 - WINDOW_LENGTH); 44 - map->map_priv_1 = page; 45 - } 46 - 47 - static inline void vmax301_page(struct map_info *map, 48 - unsigned long ofs) 49 - { 50 - unsigned long page = (ofs >> WINDOW_SHIFT); 51 - if (map->map_priv_1 != page) 52 - __vmax301_page(map, page); 53 - } 54 - 55 - static map_word vmax301_read8(struct map_info *map, unsigned long ofs) 56 - { 57 - map_word ret; 58 - spin_lock(&vmax301_spin); 59 - vmax301_page(map, ofs); 60 - ret.x[0] = readb(map->map_priv_2 + (ofs & WINDOW_MASK)); 61 - spin_unlock(&vmax301_spin); 62 - return ret; 63 - } 64 - 65 - static void vmax301_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 66 - { 67 - while(len) { 68 - unsigned long thislen = len; 69 - if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) 70 - thislen = WINDOW_LENGTH-(from & WINDOW_MASK); 71 - spin_lock(&vmax301_spin); 72 - vmax301_page(map, from); 73 - memcpy_fromio(to, map->map_priv_2 + from, thislen); 74 - spin_unlock(&vmax301_spin); 75 - to += thislen; 76 - from += thislen; 77 - len -= thislen; 78 - } 79 - } 80 - 81 - static void vmax301_write8(struct map_info *map, map_word d, unsigned long adr) 82 - { 83 - spin_lock(&vmax301_spin); 84 - vmax301_page(map, adr); 85 - writeb(d.x[0], map->map_priv_2 + (adr & WINDOW_MASK)); 86 - spin_unlock(&vmax301_spin); 87 - } 88 - 89 - static void vmax301_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 90 - { 91 - while(len) { 92 - unsigned long thislen = len; 93 - if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) 94 - thislen = WINDOW_LENGTH-(to & WINDOW_MASK); 95 - 96 - spin_lock(&vmax301_spin); 97 - vmax301_page(map, to); 98 - memcpy_toio(map->map_priv_2 + to, from, thislen); 99 - spin_unlock(&vmax301_spin); 100 - to += thislen; 101 - from += thislen; 102 - len -= thislen; 103 - } 104 - } 105 - 106 - static struct map_info vmax_map[2] = { 107 - { 108 - .name = "VMAX301 Internal Flash", 109 - .phys = NO_XIP, 110 - .size = 3*2*1024*1024, 111 - .bankwidth = 1, 112 - .read = vmax301_read8, 113 - .copy_from = vmax301_copy_from, 114 - .write = vmax301_write8, 115 - .copy_to = vmax301_copy_to, 116 - .map_priv_1 = WINDOW_START + WINDOW_LENGTH, 117 - .map_priv_2 = 0xFFFFFFFF 118 - }, 119 - { 120 - .name = "VMAX301 Socket", 121 - .phys = NO_XIP, 122 - .size = 0, 123 - .bankwidth = 1, 124 - .read = vmax301_read8, 125 - .copy_from = vmax301_copy_from, 126 - .write = vmax301_write8, 127 - .copy_to = vmax301_copy_to, 128 - .map_priv_1 = WINDOW_START + (3*WINDOW_LENGTH), 129 - .map_priv_2 = 0xFFFFFFFF 130 - } 131 - }; 132 - 133 - static struct mtd_info *vmax_mtd[2] = {NULL, NULL}; 134 - 135 - static void __exit cleanup_vmax301(void) 136 - { 137 - int i; 138 - 139 - for (i=0; i<2; i++) { 140 - if (vmax_mtd[i]) { 141 - mtd_device_unregister(vmax_mtd[i]); 142 - map_destroy(vmax_mtd[i]); 143 - } 144 - } 145 - iounmap((void *)vmax_map[0].map_priv_1 - WINDOW_START); 146 - } 147 - 148 - static int __init init_vmax301(void) 149 - { 150 - int i; 151 - unsigned long iomapadr; 152 - // Print out our little header.. 153 - printk("Tempustech VMAX 301 MEM:0x%x-0x%x\n",WINDOW_START, 154 - WINDOW_START+4*WINDOW_LENGTH); 155 - 156 - iomapadr = (unsigned long)ioremap(WINDOW_START, WINDOW_LENGTH*4); 157 - if (!iomapadr) { 158 - printk("Failed to ioremap memory region\n"); 159 - return -EIO; 160 - } 161 - /* Put the address in the map's private data area. 162 - We store the actual MTD IO address rather than the 163 - address of the first half, because it's used more 164 - often. 165 - */ 166 - vmax_map[0].map_priv_2 = iomapadr + WINDOW_START; 167 - vmax_map[1].map_priv_2 = iomapadr + (3*WINDOW_START); 168 - 169 - for (i=0; i<2; i++) { 170 - vmax_mtd[i] = do_map_probe("cfi_probe", &vmax_map[i]); 171 - if (!vmax_mtd[i]) 172 - vmax_mtd[i] = do_map_probe("jedec", &vmax_map[i]); 173 - if (!vmax_mtd[i]) 174 - vmax_mtd[i] = do_map_probe("map_ram", &vmax_map[i]); 175 - if (!vmax_mtd[i]) 176 - vmax_mtd[i] = do_map_probe("map_rom", &vmax_map[i]); 177 - if (vmax_mtd[i]) { 178 - vmax_mtd[i]->owner = THIS_MODULE; 179 - mtd_device_register(vmax_mtd[i], NULL, 0); 180 - } 181 - } 182 - 183 - if (!vmax_mtd[0] && !vmax_mtd[1]) { 184 - iounmap((void *)iomapadr); 185 - return -ENXIO; 186 - } 187 - 188 - return 0; 189 - } 190 - 191 - module_init(init_vmax301); 192 - module_exit(cleanup_vmax301); 193 - 194 - MODULE_LICENSE("GPL"); 195 - MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 196 - MODULE_DESCRIPTION("MTD map driver for Tempustech VMAX SBC301 board");
+11
drivers/mtd/mtdcore.c
··· 285 285 mtd_bitflip_threshold_show, 286 286 mtd_bitflip_threshold_store); 287 287 288 + static ssize_t mtd_ecc_step_size_show(struct device *dev, 289 + struct device_attribute *attr, char *buf) 290 + { 291 + struct mtd_info *mtd = dev_get_drvdata(dev); 292 + 293 + return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_step_size); 294 + 295 + } 296 + static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL); 297 + 288 298 static struct attribute *mtd_attrs[] = { 289 299 &dev_attr_type.attr, 290 300 &dev_attr_flags.attr, ··· 306 296 &dev_attr_numeraseregions.attr, 307 297 &dev_attr_name.attr, 308 298 &dev_attr_ecc_strength.attr, 299 + &dev_attr_ecc_step_size.attr, 309 300 &dev_attr_bitflip_threshold.attr, 310 301 NULL, 311 302 };
+1
drivers/mtd/mtdpart.c
··· 516 516 } 517 517 518 518 slave->mtd.ecclayout = master->ecclayout; 519 + slave->mtd.ecc_step_size = master->ecc_step_size; 519 520 slave->mtd.ecc_strength = master->ecc_strength; 520 521 slave->mtd.bitflip_threshold = master->bitflip_threshold; 521 522
+1 -1
drivers/mtd/mtdswap.c
··· 1425 1425 return; 1426 1426 1427 1427 while ((this_opt = strsep(&parts, ",")) != NULL) { 1428 - if (strict_strtoul(this_opt, 0, &part) < 0) 1428 + if (kstrtoul(this_opt, 0, &part) < 0) 1429 1429 return; 1430 1430 1431 1431 if (mtd->index == part)
+3 -9
drivers/mtd/nand/Kconfig
··· 43 43 44 44 config MTD_NAND_DENALI 45 45 tristate "Support Denali NAND controller" 46 + depends on HAS_DMA 46 47 help 47 48 Enable support for the Denali NAND controller. This should be 48 49 combined with either the PCI or platform drivers to provide device ··· 76 75 77 76 config MTD_NAND_GPIO 78 77 tristate "GPIO NAND Flash driver" 79 - depends on GPIOLIB && ARM 78 + depends on GPIOLIB 80 79 help 81 80 This enables a GPIO based NAND flash driver. 82 81 ··· 355 354 356 355 config MTD_NAND_PXA3xx 357 356 tristate "Support for NAND flash devices on PXA3xx" 358 - depends on PXA3xx || ARCH_MMP 357 + depends on PXA3xx || ARCH_MMP || PLAT_ORION 359 358 help 360 359 This enables the driver for the NAND flash device found on 361 360 PXA3xx processors ··· 432 431 This implements a generic NAND driver for on-SOC platform 433 432 devices. You will need to provide platform-specific functions 434 433 via platform_data. 435 - 436 - config MTD_ALAUDA 437 - tristate "MTD driver for Olympus MAUSB-10 and Fujifilm DPC-R1" 438 - depends on USB 439 - help 440 - These two (and possibly other) Alauda-based cardreaders for 441 - SmartMedia and xD allow raw flash access. 442 434 443 435 config MTD_NAND_ORION 444 436 tristate "NAND Flash support for Marvell Orion SoC"
-1
drivers/mtd/nand/Makefile
··· 31 31 obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o 32 32 obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o 33 33 obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 34 - obj-$(CONFIG_MTD_ALAUDA) += alauda.o 35 34 obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 36 35 obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o 37 36 obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o
-723
drivers/mtd/nand/alauda.c
··· 1 - /* 2 - * MTD driver for Alauda chips 3 - * 4 - * Copyright (C) 2007 Joern Engel <joern@logfs.org> 5 - * 6 - * Based on drivers/usb/usb-skeleton.c which is: 7 - * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 8 - * and on drivers/usb/storage/alauda.c, which is: 9 - * (c) 2005 Daniel Drake <dsd@gentoo.org> 10 - * 11 - * Idea and initial work by Arnd Bergmann <arnd@arndb.de> 12 - */ 13 - #include <linux/kernel.h> 14 - #include <linux/errno.h> 15 - #include <linux/init.h> 16 - #include <linux/slab.h> 17 - #include <linux/module.h> 18 - #include <linux/kref.h> 19 - #include <linux/usb.h> 20 - #include <linux/mutex.h> 21 - #include <linux/mtd/mtd.h> 22 - #include <linux/mtd/nand_ecc.h> 23 - 24 - /* Control commands */ 25 - #define ALAUDA_GET_XD_MEDIA_STATUS 0x08 26 - #define ALAUDA_ACK_XD_MEDIA_CHANGE 0x0a 27 - #define ALAUDA_GET_XD_MEDIA_SIG 0x86 28 - 29 - /* Common prefix */ 30 - #define ALAUDA_BULK_CMD 0x40 31 - 32 - /* The two ports */ 33 - #define ALAUDA_PORT_XD 0x00 34 - #define ALAUDA_PORT_SM 0x01 35 - 36 - /* Bulk commands */ 37 - #define ALAUDA_BULK_READ_PAGE 0x84 38 - #define ALAUDA_BULK_READ_OOB 0x85 /* don't use, there's a chip bug */ 39 - #define ALAUDA_BULK_READ_BLOCK 0x94 40 - #define ALAUDA_BULK_ERASE_BLOCK 0xa3 41 - #define ALAUDA_BULK_WRITE_PAGE 0xa4 42 - #define ALAUDA_BULK_WRITE_BLOCK 0xb4 43 - #define ALAUDA_BULK_RESET_MEDIA 0xe0 44 - 45 - /* Address shifting */ 46 - #define PBA_LO(pba) ((pba & 0xF) << 5) 47 - #define PBA_HI(pba) (pba >> 3) 48 - #define PBA_ZONE(pba) (pba >> 11) 49 - 50 - #define TIMEOUT HZ 51 - 52 - static const struct usb_device_id alauda_table[] = { 53 - { USB_DEVICE(0x0584, 0x0008) }, /* Fujifilm DPC-R1 */ 54 - { USB_DEVICE(0x07b4, 0x010a) }, /* Olympus MAUSB-10 */ 55 - { } 56 - }; 57 - MODULE_DEVICE_TABLE(usb, alauda_table); 58 - 59 - struct alauda_card { 60 - u8 id; /* id byte */ 61 - u8 chipshift; /* 1<<chipshift total size */ 62 - u8 pageshift; /* 1<<pageshift page size */ 63 - u8 blockshift; /* 1<<blockshift block size */ 64 - }; 65 - 66 - struct alauda { 67 - struct usb_device *dev; 68 - struct usb_interface *interface; 69 - struct mtd_info *mtd; 70 - struct alauda_card *card; 71 - struct mutex card_mutex; 72 - u32 pagemask; 73 - u32 bytemask; 74 - u32 blockmask; 75 - unsigned int write_out; 76 - unsigned int bulk_in; 77 - unsigned int bulk_out; 78 - u8 port; 79 - struct kref kref; 80 - }; 81 - 82 - static struct alauda_card alauda_card_ids[] = { 83 - /* NAND flash */ 84 - { 0x6e, 20, 8, 12}, /* 1 MB */ 85 - { 0xe8, 20, 8, 12}, /* 1 MB */ 86 - { 0xec, 20, 8, 12}, /* 1 MB */ 87 - { 0x64, 21, 8, 12}, /* 2 MB */ 88 - { 0xea, 21, 8, 12}, /* 2 MB */ 89 - { 0x6b, 22, 9, 13}, /* 4 MB */ 90 - { 0xe3, 22, 9, 13}, /* 4 MB */ 91 - { 0xe5, 22, 9, 13}, /* 4 MB */ 92 - { 0xe6, 23, 9, 13}, /* 8 MB */ 93 - { 0x73, 24, 9, 14}, /* 16 MB */ 94 - { 0x75, 25, 9, 14}, /* 32 MB */ 95 - { 0x76, 26, 9, 14}, /* 64 MB */ 96 - { 0x79, 27, 9, 14}, /* 128 MB */ 97 - { 0x71, 28, 9, 14}, /* 256 MB */ 98 - 99 - /* MASK ROM */ 100 - { 0x5d, 21, 9, 13}, /* 2 MB */ 101 - { 0xd5, 22, 9, 13}, /* 4 MB */ 102 - { 0xd6, 23, 9, 13}, /* 8 MB */ 103 - { 0x57, 24, 9, 13}, /* 16 MB */ 104 - { 0x58, 25, 9, 13}, /* 32 MB */ 105 - { } 106 - }; 107 - 108 - static struct alauda_card *get_card(u8 id) 109 - { 110 - struct alauda_card *card; 111 - 112 - for (card = alauda_card_ids; card->id; card++) 113 - if (card->id == id) 114 - return card; 115 - return NULL; 116 - } 117 - 118 - static void alauda_delete(struct kref *kref) 119 - { 120 - struct alauda *al = container_of(kref, struct alauda, kref); 121 - 122 - if (al->mtd) { 123 - mtd_device_unregister(al->mtd); 124 - kfree(al->mtd); 125 - } 126 - usb_put_dev(al->dev); 127 - kfree(al); 128 - } 129 - 130 - static int alauda_get_media_status(struct alauda *al, void *buf) 131 - { 132 - int ret; 133 - 134 - mutex_lock(&al->card_mutex); 135 - ret = usb_control_msg(al->dev, usb_rcvctrlpipe(al->dev, 0), 136 - ALAUDA_GET_XD_MEDIA_STATUS, 0xc0, 0, 1, buf, 2, HZ); 137 - mutex_unlock(&al->card_mutex); 138 - return ret; 139 - } 140 - 141 - static int alauda_ack_media(struct alauda *al) 142 - { 143 - int ret; 144 - 145 - mutex_lock(&al->card_mutex); 146 - ret = usb_control_msg(al->dev, usb_sndctrlpipe(al->dev, 0), 147 - ALAUDA_ACK_XD_MEDIA_CHANGE, 0x40, 0, 1, NULL, 0, HZ); 148 - mutex_unlock(&al->card_mutex); 149 - return ret; 150 - } 151 - 152 - static int alauda_get_media_signatures(struct alauda *al, void *buf) 153 - { 154 - int ret; 155 - 156 - mutex_lock(&al->card_mutex); 157 - ret = usb_control_msg(al->dev, usb_rcvctrlpipe(al->dev, 0), 158 - ALAUDA_GET_XD_MEDIA_SIG, 0xc0, 0, 0, buf, 4, HZ); 159 - mutex_unlock(&al->card_mutex); 160 - return ret; 161 - } 162 - 163 - static void alauda_reset(struct alauda *al) 164 - { 165 - u8 command[] = { 166 - ALAUDA_BULK_CMD, ALAUDA_BULK_RESET_MEDIA, 0, 0, 167 - 0, 0, 0, 0, al->port 168 - }; 169 - mutex_lock(&al->card_mutex); 170 - usb_bulk_msg(al->dev, al->bulk_out, command, 9, NULL, HZ); 171 - mutex_unlock(&al->card_mutex); 172 - } 173 - 174 - static void correct_data(void *buf, void *read_ecc, 175 - int *corrected, int *uncorrected) 176 - { 177 - u8 calc_ecc[3]; 178 - int err; 179 - 180 - nand_calculate_ecc(NULL, buf, calc_ecc); 181 - err = nand_correct_data(NULL, buf, read_ecc, calc_ecc); 182 - if (err) { 183 - if (err > 0) 184 - (*corrected)++; 185 - else 186 - (*uncorrected)++; 187 - } 188 - } 189 - 190 - struct alauda_sg_request { 191 - struct urb *urb[3]; 192 - struct completion comp; 193 - }; 194 - 195 - static void alauda_complete(struct urb *urb) 196 - { 197 - struct completion *comp = urb->context; 198 - 199 - if (comp) 200 - complete(comp); 201 - } 202 - 203 - static int __alauda_read_page(struct mtd_info *mtd, loff_t from, void *buf, 204 - void *oob) 205 - { 206 - struct alauda_sg_request sg; 207 - struct alauda *al = mtd->priv; 208 - u32 pba = from >> al->card->blockshift; 209 - u32 page = (from >> al->card->pageshift) & al->pagemask; 210 - u8 command[] = { 211 - ALAUDA_BULK_CMD, ALAUDA_BULK_READ_PAGE, PBA_HI(pba), 212 - PBA_ZONE(pba), 0, PBA_LO(pba) + page, 1, 0, al->port 213 - }; 214 - int i, err; 215 - 216 - for (i=0; i<3; i++) 217 - sg.urb[i] = NULL; 218 - 219 - err = -ENOMEM; 220 - for (i=0; i<3; i++) { 221 - sg.urb[i] = usb_alloc_urb(0, GFP_NOIO); 222 - if (!sg.urb[i]) 223 - goto out; 224 - } 225 - init_completion(&sg.comp); 226 - usb_fill_bulk_urb(sg.urb[0], al->dev, al->bulk_out, command, 9, 227 - alauda_complete, NULL); 228 - usb_fill_bulk_urb(sg.urb[1], al->dev, al->bulk_in, buf, mtd->writesize, 229 - alauda_complete, NULL); 230 - usb_fill_bulk_urb(sg.urb[2], al->dev, al->bulk_in, oob, 16, 231 - alauda_complete, &sg.comp); 232 - 233 - mutex_lock(&al->card_mutex); 234 - for (i=0; i<3; i++) { 235 - err = usb_submit_urb(sg.urb[i], GFP_NOIO); 236 - if (err) 237 - goto cancel; 238 - } 239 - if (!wait_for_completion_timeout(&sg.comp, TIMEOUT)) { 240 - err = -ETIMEDOUT; 241 - cancel: 242 - for (i=0; i<3; i++) { 243 - usb_kill_urb(sg.urb[i]); 244 - } 245 - } 246 - mutex_unlock(&al->card_mutex); 247 - 248 - out: 249 - usb_free_urb(sg.urb[0]); 250 - usb_free_urb(sg.urb[1]); 251 - usb_free_urb(sg.urb[2]); 252 - return err; 253 - } 254 - 255 - static int alauda_read_page(struct mtd_info *mtd, loff_t from, 256 - void *buf, u8 *oob, int *corrected, int *uncorrected) 257 - { 258 - int err; 259 - 260 - err = __alauda_read_page(mtd, from, buf, oob); 261 - if (err) 262 - return err; 263 - correct_data(buf, oob+13, corrected, uncorrected); 264 - correct_data(buf+256, oob+8, corrected, uncorrected); 265 - return 0; 266 - } 267 - 268 - static int alauda_write_page(struct mtd_info *mtd, loff_t to, void *buf, 269 - void *oob) 270 - { 271 - struct alauda_sg_request sg; 272 - struct alauda *al = mtd->priv; 273 - u32 pba = to >> al->card->blockshift; 274 - u32 page = (to >> al->card->pageshift) & al->pagemask; 275 - u8 command[] = { 276 - ALAUDA_BULK_CMD, ALAUDA_BULK_WRITE_PAGE, PBA_HI(pba), 277 - PBA_ZONE(pba), 0, PBA_LO(pba) + page, 32, 0, al->port 278 - }; 279 - int i, err; 280 - 281 - for (i=0; i<3; i++) 282 - sg.urb[i] = NULL; 283 - 284 - err = -ENOMEM; 285 - for (i=0; i<3; i++) { 286 - sg.urb[i] = usb_alloc_urb(0, GFP_NOIO); 287 - if (!sg.urb[i]) 288 - goto out; 289 - } 290 - init_completion(&sg.comp); 291 - usb_fill_bulk_urb(sg.urb[0], al->dev, al->bulk_out, command, 9, 292 - alauda_complete, NULL); 293 - usb_fill_bulk_urb(sg.urb[1], al->dev, al->write_out, buf,mtd->writesize, 294 - alauda_complete, NULL); 295 - usb_fill_bulk_urb(sg.urb[2], al->dev, al->write_out, oob, 16, 296 - alauda_complete, &sg.comp); 297 - 298 - mutex_lock(&al->card_mutex); 299 - for (i=0; i<3; i++) { 300 - err = usb_submit_urb(sg.urb[i], GFP_NOIO); 301 - if (err) 302 - goto cancel; 303 - } 304 - if (!wait_for_completion_timeout(&sg.comp, TIMEOUT)) { 305 - err = -ETIMEDOUT; 306 - cancel: 307 - for (i=0; i<3; i++) { 308 - usb_kill_urb(sg.urb[i]); 309 - } 310 - } 311 - mutex_unlock(&al->card_mutex); 312 - 313 - out: 314 - usb_free_urb(sg.urb[0]); 315 - usb_free_urb(sg.urb[1]); 316 - usb_free_urb(sg.urb[2]); 317 - return err; 318 - } 319 - 320 - static int alauda_erase_block(struct mtd_info *mtd, loff_t ofs) 321 - { 322 - struct alauda_sg_request sg; 323 - struct alauda *al = mtd->priv; 324 - u32 pba = ofs >> al->card->blockshift; 325 - u8 command[] = { 326 - ALAUDA_BULK_CMD, ALAUDA_BULK_ERASE_BLOCK, PBA_HI(pba), 327 - PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, al->port 328 - }; 329 - u8 buf[2]; 330 - int i, err; 331 - 332 - for (i=0; i<2; i++) 333 - sg.urb[i] = NULL; 334 - 335 - err = -ENOMEM; 336 - for (i=0; i<2; i++) { 337 - sg.urb[i] = usb_alloc_urb(0, GFP_NOIO); 338 - if (!sg.urb[i]) 339 - goto out; 340 - } 341 - init_completion(&sg.comp); 342 - usb_fill_bulk_urb(sg.urb[0], al->dev, al->bulk_out, command, 9, 343 - alauda_complete, NULL); 344 - usb_fill_bulk_urb(sg.urb[1], al->dev, al->bulk_in, buf, 2, 345 - alauda_complete, &sg.comp); 346 - 347 - mutex_lock(&al->card_mutex); 348 - for (i=0; i<2; i++) { 349 - err = usb_submit_urb(sg.urb[i], GFP_NOIO); 350 - if (err) 351 - goto cancel; 352 - } 353 - if (!wait_for_completion_timeout(&sg.comp, TIMEOUT)) { 354 - err = -ETIMEDOUT; 355 - cancel: 356 - for (i=0; i<2; i++) { 357 - usb_kill_urb(sg.urb[i]); 358 - } 359 - } 360 - mutex_unlock(&al->card_mutex); 361 - 362 - out: 363 - usb_free_urb(sg.urb[0]); 364 - usb_free_urb(sg.urb[1]); 365 - return err; 366 - } 367 - 368 - static int alauda_read_oob(struct mtd_info *mtd, loff_t from, void *oob) 369 - { 370 - static u8 ignore_buf[512]; /* write only */ 371 - 372 - return __alauda_read_page(mtd, from, ignore_buf, oob); 373 - } 374 - 375 - static int alauda_isbad(struct mtd_info *mtd, loff_t ofs) 376 - { 377 - u8 oob[16]; 378 - int err; 379 - 380 - err = alauda_read_oob(mtd, ofs, oob); 381 - if (err) 382 - return err; 383 - 384 - /* A block is marked bad if two or more bits are zero */ 385 - return hweight8(oob[5]) >= 7 ? 0 : 1; 386 - } 387 - 388 - static int alauda_bounce_read(struct mtd_info *mtd, loff_t from, size_t len, 389 - size_t *retlen, u_char *buf) 390 - { 391 - struct alauda *al = mtd->priv; 392 - void *bounce_buf; 393 - int err, corrected=0, uncorrected=0; 394 - 395 - bounce_buf = kmalloc(mtd->writesize, GFP_KERNEL); 396 - if (!bounce_buf) 397 - return -ENOMEM; 398 - 399 - *retlen = len; 400 - while (len) { 401 - u8 oob[16]; 402 - size_t byte = from & al->bytemask; 403 - size_t cplen = min(len, mtd->writesize - byte); 404 - 405 - err = alauda_read_page(mtd, from, bounce_buf, oob, 406 - &corrected, &uncorrected); 407 - if (err) 408 - goto out; 409 - 410 - memcpy(buf, bounce_buf + byte, cplen); 411 - buf += cplen; 412 - from += cplen; 413 - len -= cplen; 414 - } 415 - err = 0; 416 - if (corrected) 417 - err = 1; /* return max_bitflips per ecc step */ 418 - if (uncorrected) 419 - err = -EBADMSG; 420 - out: 421 - kfree(bounce_buf); 422 - return err; 423 - } 424 - 425 - static int alauda_read(struct mtd_info *mtd, loff_t from, size_t len, 426 - size_t *retlen, u_char *buf) 427 - { 428 - struct alauda *al = mtd->priv; 429 - int err, corrected=0, uncorrected=0; 430 - 431 - if ((from & al->bytemask) || (len & al->bytemask)) 432 - return alauda_bounce_read(mtd, from, len, retlen, buf); 433 - 434 - *retlen = len; 435 - while (len) { 436 - u8 oob[16]; 437 - 438 - err = alauda_read_page(mtd, from, buf, oob, 439 - &corrected, &uncorrected); 440 - if (err) 441 - return err; 442 - 443 - buf += mtd->writesize; 444 - from += mtd->writesize; 445 - len -= mtd->writesize; 446 - } 447 - err = 0; 448 - if (corrected) 449 - err = 1; /* return max_bitflips per ecc step */ 450 - if (uncorrected) 451 - err = -EBADMSG; 452 - return err; 453 - } 454 - 455 - static int alauda_write(struct mtd_info *mtd, loff_t to, size_t len, 456 - size_t *retlen, const u_char *buf) 457 - { 458 - struct alauda *al = mtd->priv; 459 - int err; 460 - 461 - if ((to & al->bytemask) || (len & al->bytemask)) 462 - return -EINVAL; 463 - 464 - *retlen = len; 465 - while (len) { 466 - u32 page = (to >> al->card->pageshift) & al->pagemask; 467 - u8 oob[16] = { 'h', 'e', 'l', 'l', 'o', 0xff, 0xff, 0xff, 468 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 469 - 470 - /* don't write to bad blocks */ 471 - if (page == 0) { 472 - err = alauda_isbad(mtd, to); 473 - if (err) { 474 - return -EIO; 475 - } 476 - } 477 - nand_calculate_ecc(mtd, buf, &oob[13]); 478 - nand_calculate_ecc(mtd, buf+256, &oob[8]); 479 - 480 - err = alauda_write_page(mtd, to, (void*)buf, oob); 481 - if (err) 482 - return err; 483 - 484 - buf += mtd->writesize; 485 - to += mtd->writesize; 486 - len -= mtd->writesize; 487 - } 488 - return 0; 489 - } 490 - 491 - static int __alauda_erase(struct mtd_info *mtd, struct erase_info *instr) 492 - { 493 - struct alauda *al = mtd->priv; 494 - u32 ofs = instr->addr; 495 - u32 len = instr->len; 496 - int err; 497 - 498 - if ((ofs & al->blockmask) || (len & al->blockmask)) 499 - return -EINVAL; 500 - 501 - while (len) { 502 - /* don't erase bad blocks */ 503 - err = alauda_isbad(mtd, ofs); 504 - if (err > 0) 505 - err = -EIO; 506 - if (err < 0) 507 - return err; 508 - 509 - err = alauda_erase_block(mtd, ofs); 510 - if (err < 0) 511 - return err; 512 - 513 - ofs += mtd->erasesize; 514 - len -= mtd->erasesize; 515 - } 516 - return 0; 517 - } 518 - 519 - static int alauda_erase(struct mtd_info *mtd, struct erase_info *instr) 520 - { 521 - int err; 522 - 523 - err = __alauda_erase(mtd, instr); 524 - instr->state = err ? MTD_ERASE_FAILED : MTD_ERASE_DONE; 525 - mtd_erase_callback(instr); 526 - return err; 527 - } 528 - 529 - static int alauda_init_media(struct alauda *al) 530 - { 531 - u8 buf[4], *b0=buf, *b1=buf+1; 532 - struct alauda_card *card; 533 - struct mtd_info *mtd; 534 - int err; 535 - 536 - mtd = kzalloc(sizeof(*mtd), GFP_KERNEL); 537 - if (!mtd) 538 - return -ENOMEM; 539 - 540 - for (;;) { 541 - err = alauda_get_media_status(al, buf); 542 - if (err < 0) 543 - goto error; 544 - if (*b0 & 0x10) 545 - break; 546 - msleep(20); 547 - } 548 - 549 - err = alauda_ack_media(al); 550 - if (err) 551 - goto error; 552 - 553 - msleep(10); 554 - 555 - err = alauda_get_media_status(al, buf); 556 - if (err < 0) 557 - goto error; 558 - 559 - if (*b0 != 0x14) { 560 - /* media not ready */ 561 - err = -EIO; 562 - goto error; 563 - } 564 - err = alauda_get_media_signatures(al, buf); 565 - if (err < 0) 566 - goto error; 567 - 568 - card = get_card(*b1); 569 - if (!card) { 570 - printk(KERN_ERR"Alauda: unknown card id %02x\n", *b1); 571 - err = -EIO; 572 - goto error; 573 - } 574 - printk(KERN_INFO"pagesize=%x\nerasesize=%x\nsize=%xMiB\n", 575 - 1<<card->pageshift, 1<<card->blockshift, 576 - 1<<(card->chipshift-20)); 577 - al->card = card; 578 - al->pagemask = (1 << (card->blockshift - card->pageshift)) - 1; 579 - al->bytemask = (1 << card->pageshift) - 1; 580 - al->blockmask = (1 << card->blockshift) - 1; 581 - 582 - mtd->name = "alauda"; 583 - mtd->size = 1<<card->chipshift; 584 - mtd->erasesize = 1<<card->blockshift; 585 - mtd->writesize = 1<<card->pageshift; 586 - mtd->type = MTD_NANDFLASH; 587 - mtd->flags = MTD_CAP_NANDFLASH; 588 - mtd->_read = alauda_read; 589 - mtd->_write = alauda_write; 590 - mtd->_erase = alauda_erase; 591 - mtd->_block_isbad = alauda_isbad; 592 - mtd->priv = al; 593 - mtd->owner = THIS_MODULE; 594 - mtd->ecc_strength = 1; 595 - 596 - err = mtd_device_register(mtd, NULL, 0); 597 - if (err) { 598 - err = -ENFILE; 599 - goto error; 600 - } 601 - 602 - al->mtd = mtd; 603 - alauda_reset(al); /* no clue whether this is necessary */ 604 - return 0; 605 - error: 606 - kfree(mtd); 607 - return err; 608 - } 609 - 610 - static int alauda_check_media(struct alauda *al) 611 - { 612 - u8 buf[2], *b0 = buf, *b1 = buf+1; 613 - int err; 614 - 615 - err = alauda_get_media_status(al, buf); 616 - if (err < 0) 617 - return err; 618 - 619 - if ((*b1 & 0x01) == 0) { 620 - /* door open */ 621 - return -EIO; 622 - } 623 - if ((*b0 & 0x80) || ((*b0 & 0x1F) == 0x10)) { 624 - /* no media ? */ 625 - return -EIO; 626 - } 627 - if (*b0 & 0x08) { 628 - /* media change ? */ 629 - return alauda_init_media(al); 630 - } 631 - return 0; 632 - } 633 - 634 - static int alauda_probe(struct usb_interface *interface, 635 - const struct usb_device_id *id) 636 - { 637 - struct alauda *al; 638 - struct usb_host_interface *iface; 639 - struct usb_endpoint_descriptor *ep, 640 - *ep_in=NULL, *ep_out=NULL, *ep_wr=NULL; 641 - int i, err = -ENOMEM; 642 - 643 - al = kzalloc(2*sizeof(*al), GFP_KERNEL); 644 - if (!al) 645 - goto error; 646 - 647 - kref_init(&al->kref); 648 - usb_set_intfdata(interface, al); 649 - 650 - al->dev = usb_get_dev(interface_to_usbdev(interface)); 651 - al->interface = interface; 652 - 653 - iface = interface->cur_altsetting; 654 - for (i = 0; i < iface->desc.bNumEndpoints; ++i) { 655 - ep = &iface->endpoint[i].desc; 656 - 657 - if (usb_endpoint_is_bulk_in(ep)) { 658 - ep_in = ep; 659 - } else if (usb_endpoint_is_bulk_out(ep)) { 660 - if (i==0) 661 - ep_wr = ep; 662 - else 663 - ep_out = ep; 664 - } 665 - } 666 - err = -EIO; 667 - if (!ep_wr || !ep_in || !ep_out) 668 - goto error; 669 - 670 - al->write_out = usb_sndbulkpipe(al->dev, 671 - usb_endpoint_num(ep_wr)); 672 - al->bulk_in = usb_rcvbulkpipe(al->dev, 673 - usb_endpoint_num(ep_in)); 674 - al->bulk_out = usb_sndbulkpipe(al->dev, 675 - usb_endpoint_num(ep_out)); 676 - 677 - /* second device is identical up to now */ 678 - memcpy(al+1, al, sizeof(*al)); 679 - 680 - mutex_init(&al[0].card_mutex); 681 - mutex_init(&al[1].card_mutex); 682 - 683 - al[0].port = ALAUDA_PORT_XD; 684 - al[1].port = ALAUDA_PORT_SM; 685 - 686 - dev_info(&interface->dev, "alauda probed\n"); 687 - alauda_check_media(al); 688 - alauda_check_media(al+1); 689 - 690 - return 0; 691 - 692 - error: 693 - if (al) 694 - kref_put(&al->kref, alauda_delete); 695 - return err; 696 - } 697 - 698 - static void alauda_disconnect(struct usb_interface *interface) 699 - { 700 - struct alauda *al; 701 - 702 - al = usb_get_intfdata(interface); 703 - usb_set_intfdata(interface, NULL); 704 - 705 - /* FIXME: prevent more I/O from starting */ 706 - 707 - /* decrement our usage count */ 708 - if (al) 709 - kref_put(&al->kref, alauda_delete); 710 - 711 - dev_info(&interface->dev, "alauda gone"); 712 - } 713 - 714 - static struct usb_driver alauda_driver = { 715 - .name = "alauda", 716 - .probe = alauda_probe, 717 - .disconnect = alauda_disconnect, 718 - .id_table = alauda_table, 719 - }; 720 - 721 - module_usb_driver(alauda_driver); 722 - 723 - MODULE_LICENSE("GPL");
-1
drivers/mtd/nand/ams-delta.c
··· 258 258 out_mtd: 259 259 gpio_free_array(_mandatory_gpio, ARRAY_SIZE(_mandatory_gpio)); 260 260 out_gpio: 261 - platform_set_drvdata(pdev, NULL); 262 261 gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB); 263 262 iounmap(io_base); 264 263 out_free:
+731 -190
drivers/mtd/nand/atmel_nand.c
··· 18 18 * Add Programmable Multibit ECC support for various AT91 SoC 19 19 * © Copyright 2012 ATMEL, Hong Xu 20 20 * 21 + * Add Nand Flash Controller support for SAMA5 SoC 22 + * © Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com) 23 + * 21 24 * This program is free software; you can redistribute it and/or modify 22 25 * it under the terms of the GNU General Public License version 2 as 23 26 * published by the Free Software Foundation. ··· 40 37 #include <linux/mtd/nand.h> 41 38 #include <linux/mtd/partitions.h> 42 39 40 + #include <linux/delay.h> 43 41 #include <linux/dmaengine.h> 44 42 #include <linux/gpio.h> 43 + #include <linux/interrupt.h> 45 44 #include <linux/io.h> 46 45 #include <linux/platform_data/atmel.h> 47 - #include <linux/pinctrl/consumer.h> 48 - 49 - #include <mach/cpu.h> 50 46 51 47 static int use_dma = 1; 52 48 module_param(use_dma, int, 0); ··· 60 58 __raw_writel((value), add + ATMEL_ECC_##reg) 61 59 62 60 #include "atmel_nand_ecc.h" /* Hardware ECC registers */ 61 + #include "atmel_nand_nfc.h" /* Nand Flash Controller definition */ 63 62 64 63 /* oob layout for large page size 65 64 * bad block info is on bytes 0 and 1 ··· 88 85 }, 89 86 }; 90 87 88 + struct atmel_nfc { 89 + void __iomem *base_cmd_regs; 90 + void __iomem *hsmc_regs; 91 + void __iomem *sram_bank0; 92 + dma_addr_t sram_bank0_phys; 93 + bool use_nfc_sram; 94 + bool write_by_sram; 95 + 96 + bool is_initialized; 97 + struct completion comp_nfc; 98 + 99 + /* Point to the sram bank which include readed data via NFC */ 100 + void __iomem *data_in_sram; 101 + bool will_write_sram; 102 + }; 103 + static struct atmel_nfc nand_nfc; 104 + 91 105 struct atmel_nand_host { 92 106 struct nand_chip nand_chip; 93 107 struct mtd_info mtd; ··· 116 96 117 97 struct completion comp; 118 98 struct dma_chan *dma_chan; 99 + 100 + struct atmel_nfc *nfc; 119 101 120 102 bool has_pmecc; 121 103 u8 pmecc_corr_cap; ··· 149 127 }; 150 128 151 129 static struct nand_ecclayout atmel_pmecc_oobinfo; 152 - 153 - static int cpu_has_dma(void) 154 - { 155 - return cpu_is_at91sam9rl() || cpu_is_at91sam9g45(); 156 - } 157 130 158 131 /* 159 132 * Enable NAND. ··· 203 186 !!host->board.rdy_pin_active_low; 204 187 } 205 188 189 + /* Set up for hardware ready pin and enable pin. */ 190 + static int atmel_nand_set_enable_ready_pins(struct mtd_info *mtd) 191 + { 192 + struct nand_chip *chip = mtd->priv; 193 + struct atmel_nand_host *host = chip->priv; 194 + int res = 0; 195 + 196 + if (gpio_is_valid(host->board.rdy_pin)) { 197 + res = devm_gpio_request(host->dev, 198 + host->board.rdy_pin, "nand_rdy"); 199 + if (res < 0) { 200 + dev_err(host->dev, 201 + "can't request rdy gpio %d\n", 202 + host->board.rdy_pin); 203 + return res; 204 + } 205 + 206 + res = gpio_direction_input(host->board.rdy_pin); 207 + if (res < 0) { 208 + dev_err(host->dev, 209 + "can't request input direction rdy gpio %d\n", 210 + host->board.rdy_pin); 211 + return res; 212 + } 213 + 214 + chip->dev_ready = atmel_nand_device_ready; 215 + } 216 + 217 + if (gpio_is_valid(host->board.enable_pin)) { 218 + res = devm_gpio_request(host->dev, 219 + host->board.enable_pin, "nand_enable"); 220 + if (res < 0) { 221 + dev_err(host->dev, 222 + "can't request enable gpio %d\n", 223 + host->board.enable_pin); 224 + return res; 225 + } 226 + 227 + res = gpio_direction_output(host->board.enable_pin, 1); 228 + if (res < 0) { 229 + dev_err(host->dev, 230 + "can't request output direction enable gpio %d\n", 231 + host->board.enable_pin); 232 + return res; 233 + } 234 + } 235 + 236 + return res; 237 + } 238 + 239 + static void memcpy32_fromio(void *trg, const void __iomem *src, size_t size) 240 + { 241 + int i; 242 + u32 *t = trg; 243 + const __iomem u32 *s = src; 244 + 245 + for (i = 0; i < (size >> 2); i++) 246 + *t++ = readl_relaxed(s++); 247 + } 248 + 249 + static void memcpy32_toio(void __iomem *trg, const void *src, int size) 250 + { 251 + int i; 252 + u32 __iomem *t = trg; 253 + const u32 *s = src; 254 + 255 + for (i = 0; i < (size >> 2); i++) 256 + writel_relaxed(*s++, t++); 257 + } 258 + 206 259 /* 207 260 * Minimal-overhead PIO for data access. 208 261 */ 209 262 static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len) 210 263 { 211 264 struct nand_chip *nand_chip = mtd->priv; 265 + struct atmel_nand_host *host = nand_chip->priv; 212 266 213 - __raw_readsb(nand_chip->IO_ADDR_R, buf, len); 267 + if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) { 268 + memcpy32_fromio(buf, host->nfc->data_in_sram, len); 269 + host->nfc->data_in_sram += len; 270 + } else { 271 + __raw_readsb(nand_chip->IO_ADDR_R, buf, len); 272 + } 214 273 } 215 274 216 275 static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len) 217 276 { 218 277 struct nand_chip *nand_chip = mtd->priv; 278 + struct atmel_nand_host *host = nand_chip->priv; 219 279 220 - __raw_readsw(nand_chip->IO_ADDR_R, buf, len / 2); 280 + if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) { 281 + memcpy32_fromio(buf, host->nfc->data_in_sram, len); 282 + host->nfc->data_in_sram += len; 283 + } else { 284 + __raw_readsw(nand_chip->IO_ADDR_R, buf, len / 2); 285 + } 221 286 } 222 287 223 288 static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len) ··· 321 222 complete(completion); 322 223 } 323 224 225 + static int nfc_set_sram_bank(struct atmel_nand_host *host, unsigned int bank) 226 + { 227 + /* NFC only has two banks. Must be 0 or 1 */ 228 + if (bank > 1) 229 + return -EINVAL; 230 + 231 + if (bank) { 232 + /* Only for a 2k-page or lower flash, NFC can handle 2 banks */ 233 + if (host->mtd.writesize > 2048) 234 + return -EINVAL; 235 + nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1); 236 + } else { 237 + nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK0); 238 + } 239 + 240 + return 0; 241 + } 242 + 243 + static uint nfc_get_sram_off(struct atmel_nand_host *host) 244 + { 245 + if (nfc_readl(host->nfc->hsmc_regs, BANK) & ATMEL_HSMC_NFC_BANK1) 246 + return NFC_SRAM_BANK1_OFFSET; 247 + else 248 + return 0; 249 + } 250 + 251 + static dma_addr_t nfc_sram_phys(struct atmel_nand_host *host) 252 + { 253 + if (nfc_readl(host->nfc->hsmc_regs, BANK) & ATMEL_HSMC_NFC_BANK1) 254 + return host->nfc->sram_bank0_phys + NFC_SRAM_BANK1_OFFSET; 255 + else 256 + return host->nfc->sram_bank0_phys; 257 + } 258 + 324 259 static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len, 325 260 int is_read) 326 261 { ··· 368 235 void *p = buf; 369 236 int err = -EIO; 370 237 enum dma_data_direction dir = is_read ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 238 + struct atmel_nfc *nfc = host->nfc; 371 239 372 240 if (buf >= high_memory) 373 241 goto err_buf; ··· 385 251 } 386 252 387 253 if (is_read) { 388 - dma_src_addr = host->io_phys; 254 + if (nfc && nfc->data_in_sram) 255 + dma_src_addr = nfc_sram_phys(host) + (nfc->data_in_sram 256 + - (nfc->sram_bank0 + nfc_get_sram_off(host))); 257 + else 258 + dma_src_addr = host->io_phys; 259 + 389 260 dma_dst_addr = phys_addr; 390 261 } else { 391 262 dma_src_addr = phys_addr; 392 - dma_dst_addr = host->io_phys; 263 + 264 + if (nfc && nfc->write_by_sram) 265 + dma_dst_addr = nfc_sram_phys(host); 266 + else 267 + dma_dst_addr = host->io_phys; 393 268 } 394 269 395 270 tx = dma_dev->device_prep_dma_memcpy(host->dma_chan, dma_dst_addr, ··· 420 277 421 278 dma_async_issue_pending(host->dma_chan); 422 279 wait_for_completion(&host->comp); 280 + 281 + if (is_read && nfc && nfc->data_in_sram) 282 + /* After read data from SRAM, need to increase the position */ 283 + nfc->data_in_sram += len; 423 284 424 285 err = 0; 425 286 ··· 513 366 table_size * sizeof(int16_t); 514 367 } 515 368 516 - static void pmecc_data_free(struct atmel_nand_host *host) 517 - { 518 - kfree(host->pmecc_partial_syn); 519 - kfree(host->pmecc_si); 520 - kfree(host->pmecc_lmu); 521 - kfree(host->pmecc_smu); 522 - kfree(host->pmecc_mu); 523 - kfree(host->pmecc_dmu); 524 - kfree(host->pmecc_delta); 525 - } 526 - 527 369 static int pmecc_data_alloc(struct atmel_nand_host *host) 528 370 { 529 371 const int cap = host->pmecc_corr_cap; 372 + int size; 530 373 531 - host->pmecc_partial_syn = kzalloc((2 * cap + 1) * sizeof(int16_t), 532 - GFP_KERNEL); 533 - host->pmecc_si = kzalloc((2 * cap + 1) * sizeof(int16_t), GFP_KERNEL); 534 - host->pmecc_lmu = kzalloc((cap + 1) * sizeof(int16_t), GFP_KERNEL); 535 - host->pmecc_smu = kzalloc((cap + 2) * (2 * cap + 1) * sizeof(int16_t), 536 - GFP_KERNEL); 537 - host->pmecc_mu = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL); 538 - host->pmecc_dmu = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL); 539 - host->pmecc_delta = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL); 374 + size = (2 * cap + 1) * sizeof(int16_t); 375 + host->pmecc_partial_syn = devm_kzalloc(host->dev, size, GFP_KERNEL); 376 + host->pmecc_si = devm_kzalloc(host->dev, size, GFP_KERNEL); 377 + host->pmecc_lmu = devm_kzalloc(host->dev, 378 + (cap + 1) * sizeof(int16_t), GFP_KERNEL); 379 + host->pmecc_smu = devm_kzalloc(host->dev, 380 + (cap + 2) * size, GFP_KERNEL); 540 381 541 - if (host->pmecc_partial_syn && 542 - host->pmecc_si && 543 - host->pmecc_lmu && 544 - host->pmecc_smu && 545 - host->pmecc_mu && 546 - host->pmecc_dmu && 547 - host->pmecc_delta) 548 - return 0; 382 + size = (cap + 1) * sizeof(int); 383 + host->pmecc_mu = devm_kzalloc(host->dev, size, GFP_KERNEL); 384 + host->pmecc_dmu = devm_kzalloc(host->dev, size, GFP_KERNEL); 385 + host->pmecc_delta = devm_kzalloc(host->dev, size, GFP_KERNEL); 549 386 550 - /* error happened */ 551 - pmecc_data_free(host); 552 - return -ENOMEM; 387 + if (!host->pmecc_partial_syn || 388 + !host->pmecc_si || 389 + !host->pmecc_lmu || 390 + !host->pmecc_smu || 391 + !host->pmecc_mu || 392 + !host->pmecc_dmu || 393 + !host->pmecc_delta) 394 + return -ENOMEM; 395 + 396 + return 0; 553 397 } 554 398 555 399 static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector) ··· 901 763 return total_err; 902 764 } 903 765 766 + static void pmecc_enable(struct atmel_nand_host *host, int ecc_op) 767 + { 768 + u32 val; 769 + 770 + if (ecc_op != NAND_ECC_READ && ecc_op != NAND_ECC_WRITE) { 771 + dev_err(host->dev, "atmel_nand: wrong pmecc operation type!"); 772 + return; 773 + } 774 + 775 + pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST); 776 + pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE); 777 + val = pmecc_readl_relaxed(host->ecc, CFG); 778 + 779 + if (ecc_op == NAND_ECC_READ) 780 + pmecc_writel(host->ecc, CFG, (val & ~PMECC_CFG_WRITE_OP) 781 + | PMECC_CFG_AUTO_ENABLE); 782 + else 783 + pmecc_writel(host->ecc, CFG, (val | PMECC_CFG_WRITE_OP) 784 + & ~PMECC_CFG_AUTO_ENABLE); 785 + 786 + pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE); 787 + pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DATA); 788 + } 789 + 904 790 static int atmel_nand_pmecc_read_page(struct mtd_info *mtd, 905 791 struct nand_chip *chip, uint8_t *buf, int oob_required, int page) 906 792 { ··· 936 774 unsigned long end_time; 937 775 int bitflips = 0; 938 776 939 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST); 940 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE); 941 - pmecc_writel(host->ecc, CFG, (pmecc_readl_relaxed(host->ecc, CFG) 942 - & ~PMECC_CFG_WRITE_OP) | PMECC_CFG_AUTO_ENABLE); 943 - 944 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE); 945 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DATA); 777 + if (!host->nfc || !host->nfc->use_nfc_sram) 778 + pmecc_enable(host, NAND_ECC_READ); 946 779 947 780 chip->read_buf(mtd, buf, eccsize); 948 781 chip->read_buf(mtd, oob, mtd->oobsize); ··· 970 813 int i, j; 971 814 unsigned long end_time; 972 815 973 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST); 974 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE); 975 - 976 - pmecc_writel(host->ecc, CFG, (pmecc_readl_relaxed(host->ecc, CFG) | 977 - PMECC_CFG_WRITE_OP) & ~PMECC_CFG_AUTO_ENABLE); 978 - 979 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE); 980 - pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DATA); 981 - 982 - chip->write_buf(mtd, (u8 *)buf, mtd->writesize); 816 + if (!host->nfc || !host->nfc->write_by_sram) { 817 + pmecc_enable(host, NAND_ECC_WRITE); 818 + chip->write_buf(mtd, (u8 *)buf, mtd->writesize); 819 + } 983 820 984 821 end_time = jiffies + msecs_to_jiffies(PMECC_MAX_TIMEOUT_MS); 985 822 while ((pmecc_readl_relaxed(host->ecc, SR) & PMECC_SR_BUSY)) { ··· 1118 967 host->pmecc_corr_cap = 2; 1119 968 else if (*cap <= 4) 1120 969 host->pmecc_corr_cap = 4; 1121 - else if (*cap < 8) 970 + else if (*cap <= 8) 1122 971 host->pmecc_corr_cap = 8; 1123 - else if (*cap < 12) 972 + else if (*cap <= 12) 1124 973 host->pmecc_corr_cap = 12; 1125 - else if (*cap < 24) 974 + else if (*cap <= 24) 1126 975 host->pmecc_corr_cap = 24; 1127 976 else 1128 977 return -EINVAL; ··· 1153 1002 return err_no; 1154 1003 } 1155 1004 1156 - if (cap != host->pmecc_corr_cap || 1005 + if (cap > host->pmecc_corr_cap || 1157 1006 sector_size != host->pmecc_sector_size) 1158 1007 dev_info(host->dev, "WARNING: Be Caution! Using different PMECC parameters from Nand ONFI ECC reqirement.\n"); 1159 1008 ··· 1174 1023 return 0; 1175 1024 } 1176 1025 1177 - host->ecc = ioremap(regs->start, resource_size(regs)); 1178 - if (host->ecc == NULL) { 1026 + host->ecc = devm_ioremap_resource(&pdev->dev, regs); 1027 + if (IS_ERR(host->ecc)) { 1179 1028 dev_err(host->dev, "ioremap failed\n"); 1180 - err_no = -EIO; 1181 - goto err_pmecc_ioremap; 1029 + err_no = PTR_ERR(host->ecc); 1030 + goto err; 1182 1031 } 1183 1032 1184 1033 regs_pmerr = platform_get_resource(pdev, IORESOURCE_MEM, 2); 1185 - regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3); 1186 - if (regs_pmerr && regs_rom) { 1187 - host->pmerrloc_base = ioremap(regs_pmerr->start, 1188 - resource_size(regs_pmerr)); 1189 - host->pmecc_rom_base = ioremap(regs_rom->start, 1190 - resource_size(regs_rom)); 1034 + host->pmerrloc_base = devm_ioremap_resource(&pdev->dev, regs_pmerr); 1035 + if (IS_ERR(host->pmerrloc_base)) { 1036 + dev_err(host->dev, 1037 + "Can not get I/O resource for PMECC ERRLOC controller!\n"); 1038 + err_no = PTR_ERR(host->pmerrloc_base); 1039 + goto err; 1191 1040 } 1192 1041 1193 - if (!host->pmerrloc_base || !host->pmecc_rom_base) { 1194 - dev_err(host->dev, 1195 - "Can not get I/O resource for PMECC ERRLOC controller or ROM!\n"); 1196 - err_no = -EIO; 1197 - goto err_pmloc_ioremap; 1042 + regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3); 1043 + host->pmecc_rom_base = devm_ioremap_resource(&pdev->dev, regs_rom); 1044 + if (IS_ERR(host->pmecc_rom_base)) { 1045 + dev_err(host->dev, "Can not get I/O resource for ROM!\n"); 1046 + err_no = PTR_ERR(host->pmecc_rom_base); 1047 + goto err; 1198 1048 } 1199 1049 1200 1050 /* ECC is calculated for the whole page (1 step) */ ··· 1204 1052 /* set ECC page size and oob layout */ 1205 1053 switch (mtd->writesize) { 1206 1054 case 2048: 1207 - host->pmecc_degree = PMECC_GF_DIMENSION_13; 1055 + host->pmecc_degree = (sector_size == 512) ? 1056 + PMECC_GF_DIMENSION_13 : PMECC_GF_DIMENSION_14; 1208 1057 host->pmecc_cw_len = (1 << host->pmecc_degree) - 1; 1209 1058 host->pmecc_sector_number = mtd->writesize / sector_size; 1210 1059 host->pmecc_bytes_per_sector = pmecc_get_ecc_bytes( ··· 1221 1068 if (nand_chip->ecc.bytes > mtd->oobsize - 2) { 1222 1069 dev_err(host->dev, "No room for ECC bytes\n"); 1223 1070 err_no = -EINVAL; 1224 - goto err_no_ecc_room; 1071 + goto err; 1225 1072 } 1226 1073 pmecc_config_ecc_layout(&atmel_pmecc_oobinfo, 1227 1074 mtd->oobsize, ··· 1246 1093 if (err_no) { 1247 1094 dev_err(host->dev, 1248 1095 "Cannot allocate memory for PMECC computation!\n"); 1249 - goto err_pmecc_data_alloc; 1096 + goto err; 1250 1097 } 1251 1098 1252 1099 nand_chip->ecc.read_page = atmel_nand_pmecc_read_page; ··· 1256 1103 1257 1104 return 0; 1258 1105 1259 - err_pmecc_data_alloc: 1260 - err_no_ecc_room: 1261 - err_pmloc_ioremap: 1262 - iounmap(host->ecc); 1263 - if (host->pmerrloc_base) 1264 - iounmap(host->pmerrloc_base); 1265 - if (host->pmecc_rom_base) 1266 - iounmap(host->pmecc_rom_base); 1267 - err_pmecc_ioremap: 1106 + err: 1268 1107 return err_no; 1269 1108 } 1270 1109 ··· 1319 1174 * Workaround: Reset the parity registers before reading the 1320 1175 * actual data. 1321 1176 */ 1322 - if (cpu_is_at32ap7000()) { 1323 - struct atmel_nand_host *host = chip->priv; 1177 + struct atmel_nand_host *host = chip->priv; 1178 + if (host->board.need_reset_workaround) 1324 1179 ecc_writel(host->ecc, CR, ATMEL_ECC_RST); 1325 - } 1326 1180 1327 1181 /* read the page */ 1328 1182 chip->read_buf(mtd, p, eccsize); ··· 1442 1298 */ 1443 1299 static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) 1444 1300 { 1445 - if (cpu_is_at32ap7000()) { 1446 - struct nand_chip *nand_chip = mtd->priv; 1447 - struct atmel_nand_host *host = nand_chip->priv; 1301 + struct nand_chip *nand_chip = mtd->priv; 1302 + struct atmel_nand_host *host = nand_chip->priv; 1303 + 1304 + if (host->board.need_reset_workaround) 1448 1305 ecc_writel(host->ecc, CR, ATMEL_ECC_RST); 1449 - } 1450 1306 } 1451 1307 1452 1308 #if defined(CONFIG_OF) ··· 1481 1337 1482 1338 board->on_flash_bbt = of_get_nand_on_flash_bbt(np); 1483 1339 1340 + board->has_dma = of_property_read_bool(np, "atmel,nand-has-dma"); 1341 + 1484 1342 if (of_get_nand_bus_width(np) == 16) 1485 1343 board->bus_width_16 = 1; 1486 1344 ··· 1493 1347 board->det_pin = of_get_gpio(np, 2); 1494 1348 1495 1349 host->has_pmecc = of_property_read_bool(np, "atmel,has-pmecc"); 1350 + 1351 + /* load the nfc driver if there is */ 1352 + of_platform_populate(np, NULL, NULL, host->dev); 1496 1353 1497 1354 if (!(board->ecc_mode == NAND_ECC_HW) || !host->has_pmecc) 1498 1355 return 0; /* Not using PMECC */ ··· 1563 1414 return 0; 1564 1415 } 1565 1416 1566 - host->ecc = ioremap(regs->start, resource_size(regs)); 1567 - if (host->ecc == NULL) { 1417 + host->ecc = devm_ioremap_resource(&pdev->dev, regs); 1418 + if (IS_ERR(host->ecc)) { 1568 1419 dev_err(host->dev, "ioremap failed\n"); 1569 - return -EIO; 1420 + return PTR_ERR(host->ecc); 1570 1421 } 1571 1422 1572 1423 /* ECC is calculated for the whole page (1 step) */ ··· 1608 1459 return 0; 1609 1460 } 1610 1461 1462 + /* SMC interrupt service routine */ 1463 + static irqreturn_t hsmc_interrupt(int irq, void *dev_id) 1464 + { 1465 + struct atmel_nand_host *host = dev_id; 1466 + u32 status, mask, pending; 1467 + irqreturn_t ret = IRQ_HANDLED; 1468 + 1469 + status = nfc_readl(host->nfc->hsmc_regs, SR); 1470 + mask = nfc_readl(host->nfc->hsmc_regs, IMR); 1471 + pending = status & mask; 1472 + 1473 + if (pending & NFC_SR_XFR_DONE) { 1474 + complete(&host->nfc->comp_nfc); 1475 + nfc_writel(host->nfc->hsmc_regs, IDR, NFC_SR_XFR_DONE); 1476 + } else if (pending & NFC_SR_RB_EDGE) { 1477 + complete(&host->nfc->comp_nfc); 1478 + nfc_writel(host->nfc->hsmc_regs, IDR, NFC_SR_RB_EDGE); 1479 + } else if (pending & NFC_SR_CMD_DONE) { 1480 + complete(&host->nfc->comp_nfc); 1481 + nfc_writel(host->nfc->hsmc_regs, IDR, NFC_SR_CMD_DONE); 1482 + } else { 1483 + ret = IRQ_NONE; 1484 + } 1485 + 1486 + return ret; 1487 + } 1488 + 1489 + /* NFC(Nand Flash Controller) related functions */ 1490 + static int nfc_wait_interrupt(struct atmel_nand_host *host, u32 flag) 1491 + { 1492 + unsigned long timeout; 1493 + init_completion(&host->nfc->comp_nfc); 1494 + 1495 + /* Enable interrupt that need to wait for */ 1496 + nfc_writel(host->nfc->hsmc_regs, IER, flag); 1497 + 1498 + timeout = wait_for_completion_timeout(&host->nfc->comp_nfc, 1499 + msecs_to_jiffies(NFC_TIME_OUT_MS)); 1500 + if (timeout) 1501 + return 0; 1502 + 1503 + /* Time out to wait for the interrupt */ 1504 + dev_err(host->dev, "Time out to wait for interrupt: 0x%08x\n", flag); 1505 + return -ETIMEDOUT; 1506 + } 1507 + 1508 + static int nfc_send_command(struct atmel_nand_host *host, 1509 + unsigned int cmd, unsigned int addr, unsigned char cycle0) 1510 + { 1511 + unsigned long timeout; 1512 + dev_dbg(host->dev, 1513 + "nfc_cmd: 0x%08x, addr1234: 0x%08x, cycle0: 0x%02x\n", 1514 + cmd, addr, cycle0); 1515 + 1516 + timeout = jiffies + msecs_to_jiffies(NFC_TIME_OUT_MS); 1517 + while (nfc_cmd_readl(NFCADDR_CMD_NFCBUSY, host->nfc->base_cmd_regs) 1518 + & NFCADDR_CMD_NFCBUSY) { 1519 + if (time_after(jiffies, timeout)) { 1520 + dev_err(host->dev, 1521 + "Time out to wait CMD_NFCBUSY ready!\n"); 1522 + return -ETIMEDOUT; 1523 + } 1524 + } 1525 + nfc_writel(host->nfc->hsmc_regs, CYCLE0, cycle0); 1526 + nfc_cmd_addr1234_writel(cmd, addr, host->nfc->base_cmd_regs); 1527 + return nfc_wait_interrupt(host, NFC_SR_CMD_DONE); 1528 + } 1529 + 1530 + static int nfc_device_ready(struct mtd_info *mtd) 1531 + { 1532 + struct nand_chip *nand_chip = mtd->priv; 1533 + struct atmel_nand_host *host = nand_chip->priv; 1534 + if (!nfc_wait_interrupt(host, NFC_SR_RB_EDGE)) 1535 + return 1; 1536 + return 0; 1537 + } 1538 + 1539 + static void nfc_select_chip(struct mtd_info *mtd, int chip) 1540 + { 1541 + struct nand_chip *nand_chip = mtd->priv; 1542 + struct atmel_nand_host *host = nand_chip->priv; 1543 + 1544 + if (chip == -1) 1545 + nfc_writel(host->nfc->hsmc_regs, CTRL, NFC_CTRL_DISABLE); 1546 + else 1547 + nfc_writel(host->nfc->hsmc_regs, CTRL, NFC_CTRL_ENABLE); 1548 + } 1549 + 1550 + static int nfc_make_addr(struct mtd_info *mtd, int column, int page_addr, 1551 + unsigned int *addr1234, unsigned int *cycle0) 1552 + { 1553 + struct nand_chip *chip = mtd->priv; 1554 + 1555 + int acycle = 0; 1556 + unsigned char addr_bytes[8]; 1557 + int index = 0, bit_shift; 1558 + 1559 + BUG_ON(addr1234 == NULL || cycle0 == NULL); 1560 + 1561 + *cycle0 = 0; 1562 + *addr1234 = 0; 1563 + 1564 + if (column != -1) { 1565 + if (chip->options & NAND_BUSWIDTH_16) 1566 + column >>= 1; 1567 + addr_bytes[acycle++] = column & 0xff; 1568 + if (mtd->writesize > 512) 1569 + addr_bytes[acycle++] = (column >> 8) & 0xff; 1570 + } 1571 + 1572 + if (page_addr != -1) { 1573 + addr_bytes[acycle++] = page_addr & 0xff; 1574 + addr_bytes[acycle++] = (page_addr >> 8) & 0xff; 1575 + if (chip->chipsize > (128 << 20)) 1576 + addr_bytes[acycle++] = (page_addr >> 16) & 0xff; 1577 + } 1578 + 1579 + if (acycle > 4) 1580 + *cycle0 = addr_bytes[index++]; 1581 + 1582 + for (bit_shift = 0; index < acycle; bit_shift += 8) 1583 + *addr1234 += addr_bytes[index++] << bit_shift; 1584 + 1585 + /* return acycle in cmd register */ 1586 + return acycle << NFCADDR_CMD_ACYCLE_BIT_POS; 1587 + } 1588 + 1589 + static void nfc_nand_command(struct mtd_info *mtd, unsigned int command, 1590 + int column, int page_addr) 1591 + { 1592 + struct nand_chip *chip = mtd->priv; 1593 + struct atmel_nand_host *host = chip->priv; 1594 + unsigned long timeout; 1595 + unsigned int nfc_addr_cmd = 0; 1596 + 1597 + unsigned int cmd1 = command << NFCADDR_CMD_CMD1_BIT_POS; 1598 + 1599 + /* Set default settings: no cmd2, no addr cycle. read from nand */ 1600 + unsigned int cmd2 = 0; 1601 + unsigned int vcmd2 = 0; 1602 + int acycle = NFCADDR_CMD_ACYCLE_NONE; 1603 + int csid = NFCADDR_CMD_CSID_3; 1604 + int dataen = NFCADDR_CMD_DATADIS; 1605 + int nfcwr = NFCADDR_CMD_NFCRD; 1606 + unsigned int addr1234 = 0; 1607 + unsigned int cycle0 = 0; 1608 + bool do_addr = true; 1609 + host->nfc->data_in_sram = NULL; 1610 + 1611 + dev_dbg(host->dev, "%s: cmd = 0x%02x, col = 0x%08x, page = 0x%08x\n", 1612 + __func__, command, column, page_addr); 1613 + 1614 + switch (command) { 1615 + case NAND_CMD_RESET: 1616 + nfc_addr_cmd = cmd1 | acycle | csid | dataen | nfcwr; 1617 + nfc_send_command(host, nfc_addr_cmd, addr1234, cycle0); 1618 + udelay(chip->chip_delay); 1619 + 1620 + nfc_nand_command(mtd, NAND_CMD_STATUS, -1, -1); 1621 + timeout = jiffies + msecs_to_jiffies(NFC_TIME_OUT_MS); 1622 + while (!(chip->read_byte(mtd) & NAND_STATUS_READY)) { 1623 + if (time_after(jiffies, timeout)) { 1624 + dev_err(host->dev, 1625 + "Time out to wait status ready!\n"); 1626 + break; 1627 + } 1628 + } 1629 + return; 1630 + case NAND_CMD_STATUS: 1631 + do_addr = false; 1632 + break; 1633 + case NAND_CMD_PARAM: 1634 + case NAND_CMD_READID: 1635 + do_addr = false; 1636 + acycle = NFCADDR_CMD_ACYCLE_1; 1637 + if (column != -1) 1638 + addr1234 = column; 1639 + break; 1640 + case NAND_CMD_RNDOUT: 1641 + cmd2 = NAND_CMD_RNDOUTSTART << NFCADDR_CMD_CMD2_BIT_POS; 1642 + vcmd2 = NFCADDR_CMD_VCMD2; 1643 + break; 1644 + case NAND_CMD_READ0: 1645 + case NAND_CMD_READOOB: 1646 + if (command == NAND_CMD_READOOB) { 1647 + column += mtd->writesize; 1648 + command = NAND_CMD_READ0; /* only READ0 is valid */ 1649 + cmd1 = command << NFCADDR_CMD_CMD1_BIT_POS; 1650 + } 1651 + if (host->nfc->use_nfc_sram) { 1652 + /* Enable Data transfer to sram */ 1653 + dataen = NFCADDR_CMD_DATAEN; 1654 + 1655 + /* Need enable PMECC now, since NFC will transfer 1656 + * data in bus after sending nfc read command. 1657 + */ 1658 + if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc) 1659 + pmecc_enable(host, NAND_ECC_READ); 1660 + } 1661 + 1662 + cmd2 = NAND_CMD_READSTART << NFCADDR_CMD_CMD2_BIT_POS; 1663 + vcmd2 = NFCADDR_CMD_VCMD2; 1664 + break; 1665 + /* For prgramming command, the cmd need set to write enable */ 1666 + case NAND_CMD_PAGEPROG: 1667 + case NAND_CMD_SEQIN: 1668 + case NAND_CMD_RNDIN: 1669 + nfcwr = NFCADDR_CMD_NFCWR; 1670 + if (host->nfc->will_write_sram && command == NAND_CMD_SEQIN) 1671 + dataen = NFCADDR_CMD_DATAEN; 1672 + break; 1673 + default: 1674 + break; 1675 + } 1676 + 1677 + if (do_addr) 1678 + acycle = nfc_make_addr(mtd, column, page_addr, &addr1234, 1679 + &cycle0); 1680 + 1681 + nfc_addr_cmd = cmd1 | cmd2 | vcmd2 | acycle | csid | dataen | nfcwr; 1682 + nfc_send_command(host, nfc_addr_cmd, addr1234, cycle0); 1683 + 1684 + if (dataen == NFCADDR_CMD_DATAEN) 1685 + if (nfc_wait_interrupt(host, NFC_SR_XFR_DONE)) 1686 + dev_err(host->dev, "something wrong, No XFR_DONE interrupt comes.\n"); 1687 + 1688 + /* 1689 + * Program and erase have their own busy handlers status, sequential 1690 + * in, and deplete1 need no delay. 1691 + */ 1692 + switch (command) { 1693 + case NAND_CMD_CACHEDPROG: 1694 + case NAND_CMD_PAGEPROG: 1695 + case NAND_CMD_ERASE1: 1696 + case NAND_CMD_ERASE2: 1697 + case NAND_CMD_RNDIN: 1698 + case NAND_CMD_STATUS: 1699 + case NAND_CMD_RNDOUT: 1700 + case NAND_CMD_SEQIN: 1701 + case NAND_CMD_READID: 1702 + return; 1703 + 1704 + case NAND_CMD_READ0: 1705 + if (dataen == NFCADDR_CMD_DATAEN) { 1706 + host->nfc->data_in_sram = host->nfc->sram_bank0 + 1707 + nfc_get_sram_off(host); 1708 + return; 1709 + } 1710 + /* fall through */ 1711 + default: 1712 + nfc_wait_interrupt(host, NFC_SR_RB_EDGE); 1713 + } 1714 + } 1715 + 1716 + static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1717 + uint32_t offset, int data_len, const uint8_t *buf, 1718 + int oob_required, int page, int cached, int raw) 1719 + { 1720 + int cfg, len; 1721 + int status = 0; 1722 + struct atmel_nand_host *host = chip->priv; 1723 + void __iomem *sram = host->nfc->sram_bank0 + nfc_get_sram_off(host); 1724 + 1725 + /* Subpage write is not supported */ 1726 + if (offset || (data_len < mtd->writesize)) 1727 + return -EINVAL; 1728 + 1729 + cfg = nfc_readl(host->nfc->hsmc_regs, CFG); 1730 + len = mtd->writesize; 1731 + 1732 + if (unlikely(raw)) { 1733 + len += mtd->oobsize; 1734 + nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE); 1735 + } else 1736 + nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE); 1737 + 1738 + /* Copy page data to sram that will write to nand via NFC */ 1739 + if (use_dma) { 1740 + if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0) 1741 + /* Fall back to use cpu copy */ 1742 + memcpy32_toio(sram, buf, len); 1743 + } else { 1744 + memcpy32_toio(sram, buf, len); 1745 + } 1746 + 1747 + if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc) 1748 + /* 1749 + * When use NFC sram, need set up PMECC before send 1750 + * NAND_CMD_SEQIN command. Since when the nand command 1751 + * is sent, nfc will do transfer from sram and nand. 1752 + */ 1753 + pmecc_enable(host, NAND_ECC_WRITE); 1754 + 1755 + host->nfc->will_write_sram = true; 1756 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 1757 + host->nfc->will_write_sram = false; 1758 + 1759 + if (likely(!raw)) 1760 + /* Need to write ecc into oob */ 1761 + status = chip->ecc.write_page(mtd, chip, buf, oob_required); 1762 + 1763 + if (status < 0) 1764 + return status; 1765 + 1766 + chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 1767 + status = chip->waitfunc(mtd, chip); 1768 + 1769 + if ((status & NAND_STATUS_FAIL) && (chip->errstat)) 1770 + status = chip->errstat(mtd, chip, FL_WRITING, status, page); 1771 + 1772 + if (status & NAND_STATUS_FAIL) 1773 + return -EIO; 1774 + 1775 + return 0; 1776 + } 1777 + 1778 + static int nfc_sram_init(struct mtd_info *mtd) 1779 + { 1780 + struct nand_chip *chip = mtd->priv; 1781 + struct atmel_nand_host *host = chip->priv; 1782 + int res = 0; 1783 + 1784 + /* Initialize the NFC CFG register */ 1785 + unsigned int cfg_nfc = 0; 1786 + 1787 + /* set page size and oob layout */ 1788 + switch (mtd->writesize) { 1789 + case 512: 1790 + cfg_nfc = NFC_CFG_PAGESIZE_512; 1791 + break; 1792 + case 1024: 1793 + cfg_nfc = NFC_CFG_PAGESIZE_1024; 1794 + break; 1795 + case 2048: 1796 + cfg_nfc = NFC_CFG_PAGESIZE_2048; 1797 + break; 1798 + case 4096: 1799 + cfg_nfc = NFC_CFG_PAGESIZE_4096; 1800 + break; 1801 + case 8192: 1802 + cfg_nfc = NFC_CFG_PAGESIZE_8192; 1803 + break; 1804 + default: 1805 + dev_err(host->dev, "Unsupported page size for NFC.\n"); 1806 + res = -ENXIO; 1807 + return res; 1808 + } 1809 + 1810 + /* oob bytes size = (NFCSPARESIZE + 1) * 4 1811 + * Max support spare size is 512 bytes. */ 1812 + cfg_nfc |= (((mtd->oobsize / 4) - 1) << NFC_CFG_NFC_SPARESIZE_BIT_POS 1813 + & NFC_CFG_NFC_SPARESIZE); 1814 + /* default set a max timeout */ 1815 + cfg_nfc |= NFC_CFG_RSPARE | 1816 + NFC_CFG_NFC_DTOCYC | NFC_CFG_NFC_DTOMUL; 1817 + 1818 + nfc_writel(host->nfc->hsmc_regs, CFG, cfg_nfc); 1819 + 1820 + host->nfc->will_write_sram = false; 1821 + nfc_set_sram_bank(host, 0); 1822 + 1823 + /* Use Write page with NFC SRAM only for PMECC or ECC NONE. */ 1824 + if (host->nfc->write_by_sram) { 1825 + if ((chip->ecc.mode == NAND_ECC_HW && host->has_pmecc) || 1826 + chip->ecc.mode == NAND_ECC_NONE) 1827 + chip->write_page = nfc_sram_write_page; 1828 + else 1829 + host->nfc->write_by_sram = false; 1830 + } 1831 + 1832 + dev_info(host->dev, "Using NFC Sram read %s\n", 1833 + host->nfc->write_by_sram ? "and write" : ""); 1834 + return 0; 1835 + } 1836 + 1837 + static struct platform_driver atmel_nand_nfc_driver; 1611 1838 /* 1612 1839 * Probe for the NAND device. 1613 1840 */ ··· 1994 1469 struct nand_chip *nand_chip; 1995 1470 struct resource *mem; 1996 1471 struct mtd_part_parser_data ppdata = {}; 1997 - int res; 1998 - struct pinctrl *pinctrl; 1999 - 2000 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2001 - if (!mem) { 2002 - printk(KERN_ERR "atmel_nand: can't get I/O resource mem\n"); 2003 - return -ENXIO; 2004 - } 1472 + int res, irq; 2005 1473 2006 1474 /* Allocate memory for the device structure (and zero it) */ 2007 - host = kzalloc(sizeof(struct atmel_nand_host), GFP_KERNEL); 1475 + host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); 2008 1476 if (!host) { 2009 1477 printk(KERN_ERR "atmel_nand: failed to allocate device structure.\n"); 2010 1478 return -ENOMEM; 2011 1479 } 2012 1480 2013 - host->io_phys = (dma_addr_t)mem->start; 1481 + res = platform_driver_register(&atmel_nand_nfc_driver); 1482 + if (res) 1483 + dev_err(&pdev->dev, "atmel_nand: can't register NFC driver\n"); 2014 1484 2015 - host->io_base = ioremap(mem->start, resource_size(mem)); 2016 - if (host->io_base == NULL) { 2017 - printk(KERN_ERR "atmel_nand: ioremap failed\n"); 2018 - res = -EIO; 1485 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1486 + host->io_base = devm_ioremap_resource(&pdev->dev, mem); 1487 + if (IS_ERR(host->io_base)) { 1488 + dev_err(&pdev->dev, "atmel_nand: ioremap resource failed\n"); 1489 + res = PTR_ERR(host->io_base); 2019 1490 goto err_nand_ioremap; 2020 1491 } 1492 + host->io_phys = (dma_addr_t)mem->start; 2021 1493 2022 1494 mtd = &host->mtd; 2023 1495 nand_chip = &host->nand_chip; ··· 2022 1500 if (pdev->dev.of_node) { 2023 1501 res = atmel_of_init_port(host, pdev->dev.of_node); 2024 1502 if (res) 2025 - goto err_ecc_ioremap; 1503 + goto err_nand_ioremap; 2026 1504 } else { 2027 - memcpy(&host->board, pdev->dev.platform_data, 1505 + memcpy(&host->board, dev_get_platdata(&pdev->dev), 2028 1506 sizeof(struct atmel_nand_data)); 2029 1507 } 2030 1508 ··· 2035 1513 /* Set address of NAND IO lines */ 2036 1514 nand_chip->IO_ADDR_R = host->io_base; 2037 1515 nand_chip->IO_ADDR_W = host->io_base; 2038 - nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl; 2039 1516 2040 - pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 2041 - if (IS_ERR(pinctrl)) { 2042 - dev_err(host->dev, "Failed to request pinctrl\n"); 2043 - res = PTR_ERR(pinctrl); 2044 - goto err_ecc_ioremap; 2045 - } 1517 + if (nand_nfc.is_initialized) { 1518 + /* NFC driver is probed and initialized */ 1519 + host->nfc = &nand_nfc; 2046 1520 2047 - if (gpio_is_valid(host->board.rdy_pin)) { 2048 - res = gpio_request(host->board.rdy_pin, "nand_rdy"); 2049 - if (res < 0) { 2050 - dev_err(&pdev->dev, 2051 - "can't request rdy gpio %d\n", 2052 - host->board.rdy_pin); 2053 - goto err_ecc_ioremap; 1521 + nand_chip->select_chip = nfc_select_chip; 1522 + nand_chip->dev_ready = nfc_device_ready; 1523 + nand_chip->cmdfunc = nfc_nand_command; 1524 + 1525 + /* Initialize the interrupt for NFC */ 1526 + irq = platform_get_irq(pdev, 0); 1527 + if (irq < 0) { 1528 + dev_err(host->dev, "Cannot get HSMC irq!\n"); 1529 + res = irq; 1530 + goto err_nand_ioremap; 2054 1531 } 2055 1532 2056 - res = gpio_direction_input(host->board.rdy_pin); 2057 - if (res < 0) { 2058 - dev_err(&pdev->dev, 2059 - "can't request input direction rdy gpio %d\n", 2060 - host->board.rdy_pin); 2061 - goto err_ecc_ioremap; 1533 + res = devm_request_irq(&pdev->dev, irq, hsmc_interrupt, 1534 + 0, "hsmc", host); 1535 + if (res) { 1536 + dev_err(&pdev->dev, "Unable to request HSMC irq %d\n", 1537 + irq); 1538 + goto err_nand_ioremap; 2062 1539 } 1540 + } else { 1541 + res = atmel_nand_set_enable_ready_pins(mtd); 1542 + if (res) 1543 + goto err_nand_ioremap; 2063 1544 2064 - nand_chip->dev_ready = atmel_nand_device_ready; 2065 - } 2066 - 2067 - if (gpio_is_valid(host->board.enable_pin)) { 2068 - res = gpio_request(host->board.enable_pin, "nand_enable"); 2069 - if (res < 0) { 2070 - dev_err(&pdev->dev, 2071 - "can't request enable gpio %d\n", 2072 - host->board.enable_pin); 2073 - goto err_ecc_ioremap; 2074 - } 2075 - 2076 - res = gpio_direction_output(host->board.enable_pin, 1); 2077 - if (res < 0) { 2078 - dev_err(&pdev->dev, 2079 - "can't request output direction enable gpio %d\n", 2080 - host->board.enable_pin); 2081 - goto err_ecc_ioremap; 2082 - } 1545 + nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl; 2083 1546 } 2084 1547 2085 1548 nand_chip->ecc.mode = host->board.ecc_mode; ··· 2080 1573 atmel_nand_enable(host); 2081 1574 2082 1575 if (gpio_is_valid(host->board.det_pin)) { 2083 - res = gpio_request(host->board.det_pin, "nand_det"); 1576 + res = devm_gpio_request(&pdev->dev, 1577 + host->board.det_pin, "nand_det"); 2084 1578 if (res < 0) { 2085 1579 dev_err(&pdev->dev, 2086 1580 "can't request det gpio %d\n", ··· 2109 1601 nand_chip->bbt_options |= NAND_BBT_USE_FLASH; 2110 1602 } 2111 1603 2112 - if (!cpu_has_dma()) 1604 + if (!host->board.has_dma) 2113 1605 use_dma = 0; 2114 1606 2115 1607 if (use_dma) { ··· 2145 1637 goto err_hw_ecc; 2146 1638 } 2147 1639 1640 + /* initialize the nfc configuration register */ 1641 + if (host->nfc && host->nfc->use_nfc_sram) { 1642 + res = nfc_sram_init(mtd); 1643 + if (res) { 1644 + host->nfc->use_nfc_sram = false; 1645 + dev_err(host->dev, "Disable use nfc sram for data transfer.\n"); 1646 + } 1647 + } 1648 + 2148 1649 /* second phase scan */ 2149 1650 if (nand_scan_tail(mtd)) { 2150 1651 res = -ENXIO; ··· 2168 1651 return res; 2169 1652 2170 1653 err_scan_tail: 2171 - if (host->has_pmecc && host->nand_chip.ecc.mode == NAND_ECC_HW) { 1654 + if (host->has_pmecc && host->nand_chip.ecc.mode == NAND_ECC_HW) 2172 1655 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE); 2173 - pmecc_data_free(host); 2174 - } 2175 - if (host->ecc) 2176 - iounmap(host->ecc); 2177 - if (host->pmerrloc_base) 2178 - iounmap(host->pmerrloc_base); 2179 - if (host->pmecc_rom_base) 2180 - iounmap(host->pmecc_rom_base); 2181 1656 err_hw_ecc: 2182 1657 err_scan_ident: 2183 1658 err_no_card: 2184 1659 atmel_nand_disable(host); 2185 - platform_set_drvdata(pdev, NULL); 2186 1660 if (host->dma_chan) 2187 1661 dma_release_channel(host->dma_chan); 2188 - err_ecc_ioremap: 2189 - iounmap(host->io_base); 2190 1662 err_nand_ioremap: 2191 - kfree(host); 1663 + platform_driver_unregister(&atmel_nand_nfc_driver); 2192 1664 return res; 2193 1665 } 2194 1666 ··· 2197 1691 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE); 2198 1692 pmerrloc_writel(host->pmerrloc_base, ELDIS, 2199 1693 PMERRLOC_DISABLE); 2200 - pmecc_data_free(host); 2201 1694 } 2202 - 2203 - if (gpio_is_valid(host->board.det_pin)) 2204 - gpio_free(host->board.det_pin); 2205 - 2206 - if (gpio_is_valid(host->board.enable_pin)) 2207 - gpio_free(host->board.enable_pin); 2208 - 2209 - if (gpio_is_valid(host->board.rdy_pin)) 2210 - gpio_free(host->board.rdy_pin); 2211 - 2212 - if (host->ecc) 2213 - iounmap(host->ecc); 2214 - if (host->pmecc_rom_base) 2215 - iounmap(host->pmecc_rom_base); 2216 - if (host->pmerrloc_base) 2217 - iounmap(host->pmerrloc_base); 2218 1695 2219 1696 if (host->dma_chan) 2220 1697 dma_release_channel(host->dma_chan); 2221 1698 2222 - iounmap(host->io_base); 2223 - kfree(host); 1699 + platform_driver_unregister(&atmel_nand_nfc_driver); 2224 1700 2225 1701 return 0; 2226 1702 } ··· 2215 1727 2216 1728 MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids); 2217 1729 #endif 1730 + 1731 + static int atmel_nand_nfc_probe(struct platform_device *pdev) 1732 + { 1733 + struct atmel_nfc *nfc = &nand_nfc; 1734 + struct resource *nfc_cmd_regs, *nfc_hsmc_regs, *nfc_sram; 1735 + 1736 + nfc_cmd_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1737 + nfc->base_cmd_regs = devm_ioremap_resource(&pdev->dev, nfc_cmd_regs); 1738 + if (IS_ERR(nfc->base_cmd_regs)) 1739 + return PTR_ERR(nfc->base_cmd_regs); 1740 + 1741 + nfc_hsmc_regs = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1742 + nfc->hsmc_regs = devm_ioremap_resource(&pdev->dev, nfc_hsmc_regs); 1743 + if (IS_ERR(nfc->hsmc_regs)) 1744 + return PTR_ERR(nfc->hsmc_regs); 1745 + 1746 + nfc_sram = platform_get_resource(pdev, IORESOURCE_MEM, 2); 1747 + if (nfc_sram) { 1748 + nfc->sram_bank0 = devm_ioremap_resource(&pdev->dev, nfc_sram); 1749 + if (IS_ERR(nfc->sram_bank0)) { 1750 + dev_warn(&pdev->dev, "Fail to ioremap the NFC sram with error: %ld. So disable NFC sram.\n", 1751 + PTR_ERR(nfc->sram_bank0)); 1752 + } else { 1753 + nfc->use_nfc_sram = true; 1754 + nfc->sram_bank0_phys = (dma_addr_t)nfc_sram->start; 1755 + 1756 + if (pdev->dev.of_node) 1757 + nfc->write_by_sram = of_property_read_bool( 1758 + pdev->dev.of_node, 1759 + "atmel,write-by-sram"); 1760 + } 1761 + } 1762 + 1763 + nfc->is_initialized = true; 1764 + dev_info(&pdev->dev, "NFC is probed.\n"); 1765 + return 0; 1766 + } 1767 + 1768 + #if defined(CONFIG_OF) 1769 + static struct of_device_id atmel_nand_nfc_match[] = { 1770 + { .compatible = "atmel,sama5d3-nfc" }, 1771 + { /* sentinel */ } 1772 + }; 1773 + #endif 1774 + 1775 + static struct platform_driver atmel_nand_nfc_driver = { 1776 + .driver = { 1777 + .name = "atmel_nand_nfc", 1778 + .owner = THIS_MODULE, 1779 + .of_match_table = of_match_ptr(atmel_nand_nfc_match), 1780 + }, 1781 + .probe = atmel_nand_nfc_probe, 1782 + }; 2218 1783 2219 1784 static struct platform_driver atmel_nand_driver = { 2220 1785 .remove = __exit_p(atmel_nand_remove),
+98
drivers/mtd/nand/atmel_nand_nfc.h
··· 1 + /* 2 + * Atmel Nand Flash Controller (NFC) - System peripherals regsters. 3 + * Based on SAMA5D3 datasheet. 4 + * 5 + * © Copyright 2013 Atmel Corporation. 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + */ 12 + 13 + #ifndef ATMEL_NAND_NFC_H 14 + #define ATMEL_NAND_NFC_H 15 + 16 + /* 17 + * HSMC NFC registers 18 + */ 19 + #define ATMEL_HSMC_NFC_CFG 0x00 /* NFC Configuration Register */ 20 + #define NFC_CFG_PAGESIZE (7 << 0) 21 + #define NFC_CFG_PAGESIZE_512 (0 << 0) 22 + #define NFC_CFG_PAGESIZE_1024 (1 << 0) 23 + #define NFC_CFG_PAGESIZE_2048 (2 << 0) 24 + #define NFC_CFG_PAGESIZE_4096 (3 << 0) 25 + #define NFC_CFG_PAGESIZE_8192 (4 << 0) 26 + #define NFC_CFG_WSPARE (1 << 8) 27 + #define NFC_CFG_RSPARE (1 << 9) 28 + #define NFC_CFG_NFC_DTOCYC (0xf << 16) 29 + #define NFC_CFG_NFC_DTOMUL (0x7 << 20) 30 + #define NFC_CFG_NFC_SPARESIZE (0x7f << 24) 31 + #define NFC_CFG_NFC_SPARESIZE_BIT_POS 24 32 + 33 + #define ATMEL_HSMC_NFC_CTRL 0x04 /* NFC Control Register */ 34 + #define NFC_CTRL_ENABLE (1 << 0) 35 + #define NFC_CTRL_DISABLE (1 << 1) 36 + 37 + #define ATMEL_HSMC_NFC_SR 0x08 /* NFC Status Register */ 38 + #define NFC_SR_XFR_DONE (1 << 16) 39 + #define NFC_SR_CMD_DONE (1 << 17) 40 + #define NFC_SR_RB_EDGE (1 << 24) 41 + 42 + #define ATMEL_HSMC_NFC_IER 0x0c 43 + #define ATMEL_HSMC_NFC_IDR 0x10 44 + #define ATMEL_HSMC_NFC_IMR 0x14 45 + #define ATMEL_HSMC_NFC_CYCLE0 0x18 /* NFC Address Cycle Zero */ 46 + #define ATMEL_HSMC_NFC_ADDR_CYCLE0 (0xff) 47 + 48 + #define ATMEL_HSMC_NFC_BANK 0x1c /* NFC Bank Register */ 49 + #define ATMEL_HSMC_NFC_BANK0 (0 << 0) 50 + #define ATMEL_HSMC_NFC_BANK1 (1 << 0) 51 + 52 + #define nfc_writel(addr, reg, value) \ 53 + writel((value), (addr) + ATMEL_HSMC_NFC_##reg) 54 + 55 + #define nfc_readl(addr, reg) \ 56 + readl_relaxed((addr) + ATMEL_HSMC_NFC_##reg) 57 + 58 + /* 59 + * NFC Address Command definitions 60 + */ 61 + #define NFCADDR_CMD_CMD1 (0xff << 2) /* Command for Cycle 1 */ 62 + #define NFCADDR_CMD_CMD1_BIT_POS 2 63 + #define NFCADDR_CMD_CMD2 (0xff << 10) /* Command for Cycle 2 */ 64 + #define NFCADDR_CMD_CMD2_BIT_POS 10 65 + #define NFCADDR_CMD_VCMD2 (0x1 << 18) /* Valid Cycle 2 Command */ 66 + #define NFCADDR_CMD_ACYCLE (0x7 << 19) /* Number of Address required */ 67 + #define NFCADDR_CMD_ACYCLE_NONE (0x0 << 19) 68 + #define NFCADDR_CMD_ACYCLE_1 (0x1 << 19) 69 + #define NFCADDR_CMD_ACYCLE_2 (0x2 << 19) 70 + #define NFCADDR_CMD_ACYCLE_3 (0x3 << 19) 71 + #define NFCADDR_CMD_ACYCLE_4 (0x4 << 19) 72 + #define NFCADDR_CMD_ACYCLE_5 (0x5 << 19) 73 + #define NFCADDR_CMD_ACYCLE_BIT_POS 19 74 + #define NFCADDR_CMD_CSID (0x7 << 22) /* Chip Select Identifier */ 75 + #define NFCADDR_CMD_CSID_0 (0x0 << 22) 76 + #define NFCADDR_CMD_CSID_1 (0x1 << 22) 77 + #define NFCADDR_CMD_CSID_2 (0x2 << 22) 78 + #define NFCADDR_CMD_CSID_3 (0x3 << 22) 79 + #define NFCADDR_CMD_CSID_4 (0x4 << 22) 80 + #define NFCADDR_CMD_CSID_5 (0x5 << 22) 81 + #define NFCADDR_CMD_CSID_6 (0x6 << 22) 82 + #define NFCADDR_CMD_CSID_7 (0x7 << 22) 83 + #define NFCADDR_CMD_DATAEN (0x1 << 25) /* Data Transfer Enable */ 84 + #define NFCADDR_CMD_DATADIS (0x0 << 25) /* Data Transfer Disable */ 85 + #define NFCADDR_CMD_NFCRD (0x0 << 26) /* NFC Read Enable */ 86 + #define NFCADDR_CMD_NFCWR (0x1 << 26) /* NFC Write Enable */ 87 + #define NFCADDR_CMD_NFCBUSY (0x1 << 27) /* NFC Busy */ 88 + 89 + #define nfc_cmd_addr1234_writel(cmd, addr1234, nfc_base) \ 90 + writel((addr1234), (cmd) + nfc_base) 91 + 92 + #define nfc_cmd_readl(bitstatus, nfc_base) \ 93 + readl_relaxed((bitstatus) + nfc_base) 94 + 95 + #define NFC_TIME_OUT_MS 100 96 + #define NFC_SRAM_BANK1_OFFSET 0x1200 97 + 98 + #endif
+1 -1
drivers/mtd/nand/au1550nd.c
··· 411 411 struct resource *r; 412 412 int ret, cs; 413 413 414 - pd = pdev->dev.platform_data; 414 + pd = dev_get_platdata(&pdev->dev); 415 415 if (!pd) { 416 416 dev_err(&pdev->dev, "missing platform data\n"); 417 417 return -ENODEV;
+1 -4
drivers/mtd/nand/bf5xx_nand.c
··· 171 171 172 172 static struct bf5xx_nand_platform *to_nand_plat(struct platform_device *pdev) 173 173 { 174 - return pdev->dev.platform_data; 174 + return dev_get_platdata(&pdev->dev); 175 175 } 176 176 177 177 /* ··· 671 671 { 672 672 struct bf5xx_nand_info *info = to_nand_info(pdev); 673 673 674 - platform_set_drvdata(pdev, NULL); 675 - 676 674 /* first thing we need to do is release all our mtds 677 675 * and their partitions, then go through freeing the 678 676 * resources used ··· 830 832 out_err_nand_scan: 831 833 bf5xx_nand_dma_remove(info); 832 834 out_err_hw_init: 833 - platform_set_drvdata(pdev, NULL); 834 835 kfree(info); 835 836 out_err_kzalloc: 836 837 peripheral_free_list(bfin_nfc_pin_req);
+1 -5
drivers/mtd/nand/cs553x_nand.c
··· 197 197 } 198 198 199 199 /* Allocate memory for MTD device structure and private data */ 200 - new_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 200 + new_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 201 201 if (!new_mtd) { 202 202 printk(KERN_WARNING "Unable to allocate CS553X NAND MTD device structure.\n"); 203 203 err = -ENOMEM; ··· 206 206 207 207 /* Get pointer to private data */ 208 208 this = (struct nand_chip *)(&new_mtd[1]); 209 - 210 - /* Initialize structures */ 211 - memset(new_mtd, 0, sizeof(struct mtd_info)); 212 - memset(this, 0, sizeof(struct nand_chip)); 213 209 214 210 /* Link the private data with the MTD structure */ 215 211 new_mtd->priv = this;
+11 -8
drivers/mtd/nand/davinci_nand.c
··· 530 530 static struct davinci_nand_pdata 531 531 *nand_davinci_get_pdata(struct platform_device *pdev) 532 532 { 533 - if (!pdev->dev.platform_data && pdev->dev.of_node) { 533 + if (!dev_get_platdata(&pdev->dev) && pdev->dev.of_node) { 534 534 struct davinci_nand_pdata *pdata; 535 535 const char *mode; 536 536 u32 prop; ··· 575 575 pdata->bbt_options = NAND_BBT_USE_FLASH; 576 576 } 577 577 578 - return pdev->dev.platform_data; 578 + return dev_get_platdata(&pdev->dev); 579 579 } 580 580 #else 581 581 static struct davinci_nand_pdata 582 582 *nand_davinci_get_pdata(struct platform_device *pdev) 583 583 { 584 - return pdev->dev.platform_data; 584 + return dev_get_platdata(&pdev->dev); 585 585 } 586 586 #endif 587 587 ··· 623 623 goto err_nomem; 624 624 } 625 625 626 - vaddr = devm_request_and_ioremap(&pdev->dev, res1); 627 - base = devm_request_and_ioremap(&pdev->dev, res2); 628 - if (!vaddr || !base) { 629 - dev_err(&pdev->dev, "ioremap failed\n"); 630 - ret = -EADDRNOTAVAIL; 626 + vaddr = devm_ioremap_resource(&pdev->dev, res1); 627 + if (IS_ERR(vaddr)) { 628 + ret = PTR_ERR(vaddr); 629 + goto err_ioremap; 630 + } 631 + base = devm_ioremap_resource(&pdev->dev, res2); 632 + if (IS_ERR(base)) { 633 + ret = PTR_ERR(base); 631 634 goto err_ioremap; 632 635 } 633 636
+1 -1
drivers/mtd/nand/denali.c
··· 1520 1520 * so just let controller do 15bit ECC for MLC and 8bit ECC for 1521 1521 * SLC if possible. 1522 1522 * */ 1523 - if (denali->nand.cellinfo & 0xc && 1523 + if (denali->nand.cellinfo & NAND_CI_CELLTYPE_MSK && 1524 1524 (denali->mtd.oobsize > (denali->bbtskipbytes + 1525 1525 ECC_15BITS * (denali->mtd.writesize / 1526 1526 ECC_SECTOR_SIZE)))) {
+2 -2
drivers/mtd/nand/diskonchip.c
··· 46 46 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, 47 47 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000, 48 48 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000, 49 - #else /* CONFIG_MTD_DOCPROBE_HIGH */ 49 + #else 50 50 0xc8000, 0xca000, 0xcc000, 0xce000, 51 51 0xd0000, 0xd2000, 0xd4000, 0xd6000, 52 52 0xd8000, 0xda000, 0xdc000, 0xde000, 53 53 0xe0000, 0xe2000, 0xe4000, 0xe6000, 54 54 0xe8000, 0xea000, 0xec000, 0xee000, 55 - #endif /* CONFIG_MTD_DOCPROBE_HIGH */ 55 + #endif 56 56 #endif 57 57 0xffffffff }; 58 58
-8
drivers/mtd/nand/docg4.c
··· 1093 1093 struct nand_chip *nand = mtd->priv; 1094 1094 struct docg4_priv *doc = nand->priv; 1095 1095 struct nand_bbt_descr *bbtd = nand->badblock_pattern; 1096 - int block = (int)(ofs >> nand->bbt_erase_shift); 1097 1096 int page = (int)(ofs >> nand->page_shift); 1098 1097 uint32_t g4_addr = mtd_to_docg4_address(page, 0); 1099 1098 ··· 1107 1108 if (buf == NULL) 1108 1109 return -ENOMEM; 1109 1110 1110 - /* update bbt in memory */ 1111 - nand->bbt[block / 4] |= 0x01 << ((block & 0x03) * 2); 1112 - 1113 1111 /* write bit-wise negation of pattern to oob buffer */ 1114 1112 memset(nand->oob_poi, 0xff, mtd->oobsize); 1115 1113 for (i = 0; i < bbtd->len; i++) ··· 1116 1120 write_page_prologue(mtd, g4_addr); 1117 1121 docg4_write_page(mtd, nand, buf, 1); 1118 1122 ret = pageprog(mtd); 1119 - if (!ret) 1120 - mtd->ecc_stats.badblocks++; 1121 1123 1122 1124 kfree(buf); 1123 1125 ··· 1362 1368 struct nand_chip *nand = mtd->priv; 1363 1369 struct docg4_priv *doc = nand->priv; 1364 1370 nand_release(mtd); /* deletes partitions and mtd devices */ 1365 - platform_set_drvdata(pdev, NULL); 1366 1371 free_bch(doc->bch); 1367 1372 kfree(mtd); 1368 1373 } ··· 1373 1380 { 1374 1381 struct docg4_priv *doc = platform_get_drvdata(pdev); 1375 1382 nand_release(doc->mtd); 1376 - platform_set_drvdata(pdev, NULL); 1377 1383 free_bch(doc->bch); 1378 1384 kfree(doc->mtd); 1379 1385 iounmap(doc->virtadr);
+1 -2
drivers/mtd/nand/fsl_ifc_nand.c
··· 823 823 824 824 /* set up nand options */ 825 825 chip->bbt_options = NAND_BBT_USE_FLASH; 826 - 826 + chip->options = NAND_NO_SUBPAGE_WRITE; 827 827 828 828 if (ioread32be(&ifc->cspr_cs[priv->bank].cspr) & CSPR_PORT_SIZE_16) { 829 829 chip->read_byte = fsl_ifc_read_byte16; ··· 908 908 909 909 ifc_nand_ctrl->chips[priv->bank] = NULL; 910 910 dev_set_drvdata(priv->dev, NULL); 911 - kfree(priv); 912 911 913 912 return 0; 914 913 }
+20 -18
drivers/mtd/nand/fsmc_nand.c
··· 889 889 if (of_get_property(np, "nand-skip-bbtscan", NULL)) 890 890 pdata->options = NAND_SKIP_BBTSCAN; 891 891 892 + pdata->nand_timings = devm_kzalloc(&pdev->dev, 893 + sizeof(*pdata->nand_timings), GFP_KERNEL); 894 + if (!pdata->nand_timings) { 895 + dev_err(&pdev->dev, "no memory for nand_timing\n"); 896 + return -ENOMEM; 897 + } 898 + of_property_read_u8_array(np, "timings", (u8 *)pdata->nand_timings, 899 + sizeof(*pdata->nand_timings)); 900 + 901 + /* Set default NAND bank to 0 */ 902 + pdata->bank = 0; 903 + if (!of_property_read_u32(np, "bank", &val)) { 904 + if (val > 3) { 905 + dev_err(&pdev->dev, "invalid bank %u\n", val); 906 + return -EINVAL; 907 + } 908 + pdata->bank = val; 909 + } 892 910 return 0; 893 911 } 894 912 #else ··· 958 940 } 959 941 960 942 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); 961 - if (!res) 962 - return -EINVAL; 963 - 964 943 host->data_va = devm_ioremap_resource(&pdev->dev, res); 965 944 if (IS_ERR(host->data_va)) 966 945 return PTR_ERR(host->data_va); ··· 965 950 host->data_pa = (dma_addr_t)res->start; 966 951 967 952 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_addr"); 968 - if (!res) 969 - return -EINVAL; 970 - 971 953 host->addr_va = devm_ioremap_resource(&pdev->dev, res); 972 954 if (IS_ERR(host->addr_va)) 973 955 return PTR_ERR(host->addr_va); 974 956 975 957 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cmd"); 976 - if (!res) 977 - return -EINVAL; 978 - 979 958 host->cmd_va = devm_ioremap_resource(&pdev->dev, res); 980 959 if (IS_ERR(host->cmd_va)) 981 960 return PTR_ERR(host->cmd_va); 982 961 983 962 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs"); 984 - if (!res) 985 - return -EINVAL; 986 - 987 963 host->regs_va = devm_ioremap_resource(&pdev->dev, res); 988 964 if (IS_ERR(host->regs_va)) 989 965 return PTR_ERR(host->regs_va); ··· 1180 1174 { 1181 1175 struct fsmc_nand_data *host = platform_get_drvdata(pdev); 1182 1176 1183 - platform_set_drvdata(pdev, NULL); 1184 - 1185 1177 if (host) { 1186 1178 nand_release(&host->mtd); 1187 1179 ··· 1194 1190 return 0; 1195 1191 } 1196 1192 1197 - #ifdef CONFIG_PM 1193 + #ifdef CONFIG_PM_SLEEP 1198 1194 static int fsmc_nand_suspend(struct device *dev) 1199 1195 { 1200 1196 struct fsmc_nand_data *host = dev_get_drvdata(dev); ··· 1214 1210 } 1215 1211 return 0; 1216 1212 } 1213 + #endif 1217 1214 1218 1215 static SIMPLE_DEV_PM_OPS(fsmc_nand_pm_ops, fsmc_nand_suspend, fsmc_nand_resume); 1219 - #endif 1220 1216 1221 1217 #ifdef CONFIG_OF 1222 1218 static const struct of_device_id fsmc_nand_id_table[] = { ··· 1233 1229 .owner = THIS_MODULE, 1234 1230 .name = "fsmc-nand", 1235 1231 .of_match_table = of_match_ptr(fsmc_nand_id_table), 1236 - #ifdef CONFIG_PM 1237 1232 .pm = &fsmc_nand_pm_ops, 1238 - #endif 1239 1233 }, 1240 1234 }; 1241 1235
+62 -171
drivers/mtd/nand/gpio.c
··· 17 17 */ 18 18 19 19 #include <linux/kernel.h> 20 + #include <linux/err.h> 20 21 #include <linux/init.h> 21 22 #include <linux/slab.h> 22 23 #include <linux/module.h> ··· 87 86 gpio_nand_dosync(gpiomtd); 88 87 } 89 88 90 - static void gpio_nand_writebuf(struct mtd_info *mtd, const u_char *buf, int len) 91 - { 92 - struct nand_chip *this = mtd->priv; 93 - 94 - iowrite8_rep(this->IO_ADDR_W, buf, len); 95 - } 96 - 97 - static void gpio_nand_readbuf(struct mtd_info *mtd, u_char *buf, int len) 98 - { 99 - struct nand_chip *this = mtd->priv; 100 - 101 - ioread8_rep(this->IO_ADDR_R, buf, len); 102 - } 103 - 104 - static void gpio_nand_writebuf16(struct mtd_info *mtd, const u_char *buf, 105 - int len) 106 - { 107 - struct nand_chip *this = mtd->priv; 108 - 109 - if (IS_ALIGNED((unsigned long)buf, 2)) { 110 - iowrite16_rep(this->IO_ADDR_W, buf, len>>1); 111 - } else { 112 - int i; 113 - unsigned short *ptr = (unsigned short *)buf; 114 - 115 - for (i = 0; i < len; i += 2, ptr++) 116 - writew(*ptr, this->IO_ADDR_W); 117 - } 118 - } 119 - 120 - static void gpio_nand_readbuf16(struct mtd_info *mtd, u_char *buf, int len) 121 - { 122 - struct nand_chip *this = mtd->priv; 123 - 124 - if (IS_ALIGNED((unsigned long)buf, 2)) { 125 - ioread16_rep(this->IO_ADDR_R, buf, len>>1); 126 - } else { 127 - int i; 128 - unsigned short *ptr = (unsigned short *)buf; 129 - 130 - for (i = 0; i < len; i += 2, ptr++) 131 - *ptr = readw(this->IO_ADDR_R); 132 - } 133 - } 134 - 135 89 static int gpio_nand_devready(struct mtd_info *mtd) 136 90 { 137 91 struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); 138 92 139 - if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) 140 - return gpio_get_value(gpiomtd->plat.gpio_rdy); 141 - 142 - return 1; 93 + return gpio_get_value(gpiomtd->plat.gpio_rdy); 143 94 } 144 95 145 96 #ifdef CONFIG_OF ··· 105 152 struct gpio_nand_platdata *plat) 106 153 { 107 154 u32 val; 155 + 156 + if (!dev->of_node) 157 + return -ENODEV; 108 158 109 159 if (!of_property_read_u32(dev->of_node, "bank-width", &val)) { 110 160 if (val == 2) { ··· 167 211 if (!ret) 168 212 return ret; 169 213 170 - if (dev->platform_data) { 171 - memcpy(plat, dev->platform_data, sizeof(*plat)); 214 + if (dev_get_platdata(dev)) { 215 + memcpy(plat, dev_get_platdata(dev), sizeof(*plat)); 172 216 return 0; 173 217 } 174 218 ··· 186 230 return platform_get_resource(pdev, IORESOURCE_MEM, 1); 187 231 } 188 232 189 - static int gpio_nand_remove(struct platform_device *dev) 233 + static int gpio_nand_remove(struct platform_device *pdev) 190 234 { 191 - struct gpiomtd *gpiomtd = platform_get_drvdata(dev); 192 - struct resource *res; 235 + struct gpiomtd *gpiomtd = platform_get_drvdata(pdev); 193 236 194 237 nand_release(&gpiomtd->mtd_info); 195 - 196 - res = gpio_nand_get_io_sync(dev); 197 - iounmap(gpiomtd->io_sync); 198 - if (res) 199 - release_mem_region(res->start, resource_size(res)); 200 - 201 - res = platform_get_resource(dev, IORESOURCE_MEM, 0); 202 - iounmap(gpiomtd->nand_chip.IO_ADDR_R); 203 - release_mem_region(res->start, resource_size(res)); 204 238 205 239 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 206 240 gpio_set_value(gpiomtd->plat.gpio_nwp, 0); 207 241 gpio_set_value(gpiomtd->plat.gpio_nce, 1); 208 242 209 - gpio_free(gpiomtd->plat.gpio_cle); 210 - gpio_free(gpiomtd->plat.gpio_ale); 211 - gpio_free(gpiomtd->plat.gpio_nce); 212 - if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 213 - gpio_free(gpiomtd->plat.gpio_nwp); 214 - if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) 215 - gpio_free(gpiomtd->plat.gpio_rdy); 216 - 217 243 return 0; 218 244 } 219 245 220 - static void __iomem *request_and_remap(struct resource *res, size_t size, 221 - const char *name, int *err) 222 - { 223 - void __iomem *ptr; 224 - 225 - if (!request_mem_region(res->start, resource_size(res), name)) { 226 - *err = -EBUSY; 227 - return NULL; 228 - } 229 - 230 - ptr = ioremap(res->start, size); 231 - if (!ptr) { 232 - release_mem_region(res->start, resource_size(res)); 233 - *err = -ENOMEM; 234 - } 235 - return ptr; 236 - } 237 - 238 - static int gpio_nand_probe(struct platform_device *dev) 246 + static int gpio_nand_probe(struct platform_device *pdev) 239 247 { 240 248 struct gpiomtd *gpiomtd; 241 - struct nand_chip *this; 242 - struct resource *res0, *res1; 249 + struct nand_chip *chip; 250 + struct resource *res; 243 251 struct mtd_part_parser_data ppdata = {}; 244 252 int ret = 0; 245 253 246 - if (!dev->dev.of_node && !dev->dev.platform_data) 254 + if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev)) 247 255 return -EINVAL; 248 256 249 - res0 = platform_get_resource(dev, IORESOURCE_MEM, 0); 250 - if (!res0) 251 - return -EINVAL; 252 - 253 - gpiomtd = devm_kzalloc(&dev->dev, sizeof(*gpiomtd), GFP_KERNEL); 254 - if (gpiomtd == NULL) { 255 - dev_err(&dev->dev, "failed to create NAND MTD\n"); 257 + gpiomtd = devm_kzalloc(&pdev->dev, sizeof(*gpiomtd), GFP_KERNEL); 258 + if (!gpiomtd) { 259 + dev_err(&pdev->dev, "failed to create NAND MTD\n"); 256 260 return -ENOMEM; 257 261 } 258 262 259 - this = &gpiomtd->nand_chip; 260 - this->IO_ADDR_R = request_and_remap(res0, 2, "NAND", &ret); 261 - if (!this->IO_ADDR_R) { 262 - dev_err(&dev->dev, "unable to map NAND\n"); 263 - goto err_map; 263 + chip = &gpiomtd->nand_chip; 264 + 265 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 266 + chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res); 267 + if (IS_ERR(chip->IO_ADDR_R)) 268 + return PTR_ERR(chip->IO_ADDR_R); 269 + 270 + res = gpio_nand_get_io_sync(pdev); 271 + if (res) { 272 + gpiomtd->io_sync = devm_ioremap_resource(&pdev->dev, res); 273 + if (IS_ERR(gpiomtd->io_sync)) 274 + return PTR_ERR(gpiomtd->io_sync); 264 275 } 265 276 266 - res1 = gpio_nand_get_io_sync(dev); 267 - if (res1) { 268 - gpiomtd->io_sync = request_and_remap(res1, 4, "NAND sync", &ret); 269 - if (!gpiomtd->io_sync) { 270 - dev_err(&dev->dev, "unable to map sync NAND\n"); 271 - goto err_sync; 272 - } 273 - } 274 - 275 - ret = gpio_nand_get_config(&dev->dev, &gpiomtd->plat); 277 + ret = gpio_nand_get_config(&pdev->dev, &gpiomtd->plat); 276 278 if (ret) 277 - goto err_nce; 279 + return ret; 278 280 279 - ret = gpio_request(gpiomtd->plat.gpio_nce, "NAND NCE"); 281 + ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nce, "NAND NCE"); 280 282 if (ret) 281 - goto err_nce; 283 + return ret; 282 284 gpio_direction_output(gpiomtd->plat.gpio_nce, 1); 285 + 283 286 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) { 284 - ret = gpio_request(gpiomtd->plat.gpio_nwp, "NAND NWP"); 287 + ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nwp, 288 + "NAND NWP"); 285 289 if (ret) 286 - goto err_nwp; 287 - gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); 290 + return ret; 288 291 } 289 - ret = gpio_request(gpiomtd->plat.gpio_ale, "NAND ALE"); 292 + 293 + ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_ale, "NAND ALE"); 290 294 if (ret) 291 - goto err_ale; 295 + return ret; 292 296 gpio_direction_output(gpiomtd->plat.gpio_ale, 0); 293 - ret = gpio_request(gpiomtd->plat.gpio_cle, "NAND CLE"); 297 + 298 + ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_cle, "NAND CLE"); 294 299 if (ret) 295 - goto err_cle; 300 + return ret; 296 301 gpio_direction_output(gpiomtd->plat.gpio_cle, 0); 302 + 297 303 if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) { 298 - ret = gpio_request(gpiomtd->plat.gpio_rdy, "NAND RDY"); 304 + ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_rdy, 305 + "NAND RDY"); 299 306 if (ret) 300 - goto err_rdy; 307 + return ret; 301 308 gpio_direction_input(gpiomtd->plat.gpio_rdy); 309 + chip->dev_ready = gpio_nand_devready; 302 310 } 303 311 312 + chip->IO_ADDR_W = chip->IO_ADDR_R; 313 + chip->ecc.mode = NAND_ECC_SOFT; 314 + chip->options = gpiomtd->plat.options; 315 + chip->chip_delay = gpiomtd->plat.chip_delay; 316 + chip->cmd_ctrl = gpio_nand_cmd_ctrl; 304 317 305 - this->IO_ADDR_W = this->IO_ADDR_R; 306 - this->ecc.mode = NAND_ECC_SOFT; 307 - this->options = gpiomtd->plat.options; 308 - this->chip_delay = gpiomtd->plat.chip_delay; 318 + gpiomtd->mtd_info.priv = chip; 319 + gpiomtd->mtd_info.owner = THIS_MODULE; 309 320 310 - /* install our routines */ 311 - this->cmd_ctrl = gpio_nand_cmd_ctrl; 312 - this->dev_ready = gpio_nand_devready; 321 + platform_set_drvdata(pdev, gpiomtd); 313 322 314 - if (this->options & NAND_BUSWIDTH_16) { 315 - this->read_buf = gpio_nand_readbuf16; 316 - this->write_buf = gpio_nand_writebuf16; 317 - } else { 318 - this->read_buf = gpio_nand_readbuf; 319 - this->write_buf = gpio_nand_writebuf; 320 - } 321 - 322 - /* set the mtd private data for the nand driver */ 323 - gpiomtd->mtd_info.priv = this; 324 - gpiomtd->mtd_info.owner = THIS_MODULE; 323 + if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 324 + gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); 325 325 326 326 if (nand_scan(&gpiomtd->mtd_info, 1)) { 327 - dev_err(&dev->dev, "no nand chips found?\n"); 328 327 ret = -ENXIO; 329 328 goto err_wp; 330 329 } ··· 288 377 gpiomtd->plat.adjust_parts(&gpiomtd->plat, 289 378 gpiomtd->mtd_info.size); 290 379 291 - ppdata.of_node = dev->dev.of_node; 380 + ppdata.of_node = pdev->dev.of_node; 292 381 ret = mtd_device_parse_register(&gpiomtd->mtd_info, NULL, &ppdata, 293 382 gpiomtd->plat.parts, 294 383 gpiomtd->plat.num_parts); 295 - if (ret) 296 - goto err_wp; 297 - platform_set_drvdata(dev, gpiomtd); 298 - 299 - return 0; 384 + if (!ret) 385 + return 0; 300 386 301 387 err_wp: 302 388 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 303 389 gpio_set_value(gpiomtd->plat.gpio_nwp, 0); 304 - if (gpio_is_valid(gpiomtd->plat.gpio_rdy)) 305 - gpio_free(gpiomtd->plat.gpio_rdy); 306 - err_rdy: 307 - gpio_free(gpiomtd->plat.gpio_cle); 308 - err_cle: 309 - gpio_free(gpiomtd->plat.gpio_ale); 310 - err_ale: 311 - if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 312 - gpio_free(gpiomtd->plat.gpio_nwp); 313 - err_nwp: 314 - gpio_free(gpiomtd->plat.gpio_nce); 315 - err_nce: 316 - iounmap(gpiomtd->io_sync); 317 - if (res1) 318 - release_mem_region(res1->start, resource_size(res1)); 319 - err_sync: 320 - iounmap(gpiomtd->nand_chip.IO_ADDR_R); 321 - release_mem_region(res0->start, resource_size(res0)); 322 - err_map: 390 + 323 391 return ret; 324 392 } 325 393 ··· 307 417 .remove = gpio_nand_remove, 308 418 .driver = { 309 419 .name = "gpio-nand", 420 + .owner = THIS_MODULE, 310 421 .of_match_table = of_match_ptr(gpio_nand_id_table), 311 422 }, 312 423 };
+192 -76
drivers/mtd/nand/gpmi-nand/gpmi-nand.c
··· 26 26 #include <linux/interrupt.h> 27 27 #include <linux/module.h> 28 28 #include <linux/mtd/partitions.h> 29 - #include <linux/pinctrl/consumer.h> 30 29 #include <linux/of.h> 31 30 #include <linux/of_device.h> 32 31 #include <linux/of_mtd.h> ··· 111 112 return true; 112 113 } 113 114 114 - int common_nfc_set_geometry(struct gpmi_nand_data *this) 115 + /* 116 + * If we can get the ECC information from the nand chip, we do not 117 + * need to calculate them ourselves. 118 + * 119 + * We may have available oob space in this case. 120 + */ 121 + static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this) 122 + { 123 + struct bch_geometry *geo = &this->bch_geometry; 124 + struct mtd_info *mtd = &this->mtd; 125 + struct nand_chip *chip = mtd->priv; 126 + struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree; 127 + unsigned int block_mark_bit_offset; 128 + 129 + if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) 130 + return false; 131 + 132 + switch (chip->ecc_step_ds) { 133 + case SZ_512: 134 + geo->gf_len = 13; 135 + break; 136 + case SZ_1K: 137 + geo->gf_len = 14; 138 + break; 139 + default: 140 + dev_err(this->dev, 141 + "unsupported nand chip. ecc bits : %d, ecc size : %d\n", 142 + chip->ecc_strength_ds, chip->ecc_step_ds); 143 + return false; 144 + } 145 + geo->ecc_chunk_size = chip->ecc_step_ds; 146 + geo->ecc_strength = round_up(chip->ecc_strength_ds, 2); 147 + if (!gpmi_check_ecc(this)) 148 + return false; 149 + 150 + /* Keep the C >= O */ 151 + if (geo->ecc_chunk_size < mtd->oobsize) { 152 + dev_err(this->dev, 153 + "unsupported nand chip. ecc size: %d, oob size : %d\n", 154 + chip->ecc_step_ds, mtd->oobsize); 155 + return false; 156 + } 157 + 158 + /* The default value, see comment in the legacy_set_geometry(). */ 159 + geo->metadata_size = 10; 160 + 161 + geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size; 162 + 163 + /* 164 + * Now, the NAND chip with 2K page(data chunk is 512byte) shows below: 165 + * 166 + * | P | 167 + * |<----------------------------------------------------->| 168 + * | | 169 + * | (Block Mark) | 170 + * | P' | | | | 171 + * |<-------------------------------------------->| D | | O' | 172 + * | |<---->| |<--->| 173 + * V V V V V 174 + * +---+----------+-+----------+-+----------+-+----------+-+-----+ 175 + * | M | data |E| data |E| data |E| data |E| | 176 + * +---+----------+-+----------+-+----------+-+----------+-+-----+ 177 + * ^ ^ 178 + * | O | 179 + * |<------------>| 180 + * | | 181 + * 182 + * P : the page size for BCH module. 183 + * E : The ECC strength. 184 + * G : the length of Galois Field. 185 + * N : The chunk count of per page. 186 + * M : the metasize of per page. 187 + * C : the ecc chunk size, aka the "data" above. 188 + * P': the nand chip's page size. 189 + * O : the nand chip's oob size. 190 + * O': the free oob. 191 + * 192 + * The formula for P is : 193 + * 194 + * E * G * N 195 + * P = ------------ + P' + M 196 + * 8 197 + * 198 + * The position of block mark moves forward in the ECC-based view 199 + * of page, and the delta is: 200 + * 201 + * E * G * (N - 1) 202 + * D = (---------------- + M) 203 + * 8 204 + * 205 + * Please see the comment in legacy_set_geometry(). 206 + * With the condition C >= O , we still can get same result. 207 + * So the bit position of the physical block mark within the ECC-based 208 + * view of the page is : 209 + * (P' - D) * 8 210 + */ 211 + geo->page_size = mtd->writesize + geo->metadata_size + 212 + (geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) / 8; 213 + 214 + /* The available oob size we have. */ 215 + if (geo->page_size < mtd->writesize + mtd->oobsize) { 216 + of->offset = geo->page_size - mtd->writesize; 217 + of->length = mtd->oobsize - of->offset; 218 + } 219 + 220 + geo->payload_size = mtd->writesize; 221 + 222 + geo->auxiliary_status_offset = ALIGN(geo->metadata_size, 4); 223 + geo->auxiliary_size = ALIGN(geo->metadata_size, 4) 224 + + ALIGN(geo->ecc_chunk_count, 4); 225 + 226 + if (!this->swap_block_mark) 227 + return true; 228 + 229 + /* For bit swap. */ 230 + block_mark_bit_offset = mtd->writesize * 8 - 231 + (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1) 232 + + geo->metadata_size * 8); 233 + 234 + geo->block_mark_byte_offset = block_mark_bit_offset / 8; 235 + geo->block_mark_bit_offset = block_mark_bit_offset % 8; 236 + return true; 237 + } 238 + 239 + static int legacy_set_geometry(struct gpmi_nand_data *this) 115 240 { 116 241 struct bch_geometry *geo = &this->bch_geometry; 117 242 struct mtd_info *mtd = &this->mtd; ··· 345 222 geo->block_mark_byte_offset = block_mark_bit_offset / 8; 346 223 geo->block_mark_bit_offset = block_mark_bit_offset % 8; 347 224 return 0; 225 + } 226 + 227 + int common_nfc_set_geometry(struct gpmi_nand_data *this) 228 + { 229 + return set_geometry_by_ecc_info(this) ? 0 : legacy_set_geometry(this); 348 230 } 349 231 350 232 struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) ··· 483 355 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name); 484 356 if (!r) { 485 357 pr_err("Can't get resource for %s\n", res_name); 486 - return -ENXIO; 358 + return -ENODEV; 487 359 } 488 360 489 361 p = ioremap(r->start, resource_size(r)); ··· 524 396 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name); 525 397 if (!r) { 526 398 pr_err("Can't get resource for %s\n", res_name); 527 - return -ENXIO; 399 + return -ENODEV; 528 400 } 529 401 530 402 err = request_irq(r->start, irq_h, 0, res_name, this); ··· 601 473 struct resources *r = &this->resources; 602 474 char **extra_clks = NULL; 603 475 struct clk *clk; 604 - int i; 476 + int err, i; 605 477 606 478 /* The main clock is stored in the first. */ 607 479 r->clock[0] = clk_get(this->dev, "gpmi_io"); 608 - if (IS_ERR(r->clock[0])) 480 + if (IS_ERR(r->clock[0])) { 481 + err = PTR_ERR(r->clock[0]); 609 482 goto err_clock; 483 + } 610 484 611 485 /* Get extra clocks */ 612 486 if (GPMI_IS_MX6Q(this)) ··· 621 491 break; 622 492 623 493 clk = clk_get(this->dev, extra_clks[i - 1]); 624 - if (IS_ERR(clk)) 494 + if (IS_ERR(clk)) { 495 + err = PTR_ERR(clk); 625 496 goto err_clock; 497 + } 626 498 627 499 r->clock[i] = clk; 628 500 } ··· 643 511 err_clock: 644 512 dev_dbg(this->dev, "failed in finding the clocks.\n"); 645 513 gpmi_put_clks(this); 646 - return -ENOMEM; 514 + return err; 647 515 } 648 516 649 517 static int acquire_resources(struct gpmi_nand_data *this) 650 518 { 651 - struct pinctrl *pinctrl; 652 519 int ret; 653 520 654 521 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME); ··· 666 535 if (ret) 667 536 goto exit_dma_channels; 668 537 669 - pinctrl = devm_pinctrl_get_select_default(&this->pdev->dev); 670 - if (IS_ERR(pinctrl)) { 671 - ret = PTR_ERR(pinctrl); 672 - goto exit_pin; 673 - } 674 - 675 538 ret = gpmi_get_clks(this); 676 539 if (ret) 677 540 goto exit_clock; 678 541 return 0; 679 542 680 543 exit_clock: 681 - exit_pin: 682 544 release_dma_channels(this); 683 545 exit_dma_channels: 684 546 release_bch_irq(this); ··· 1277 1153 { 1278 1154 struct nand_chip *chip = mtd->priv; 1279 1155 struct gpmi_nand_data *this = chip->priv; 1280 - int block, ret = 0; 1156 + int ret = 0; 1281 1157 uint8_t *block_mark; 1282 1158 int column, page, status, chipnr; 1283 1159 1284 - /* Get block number */ 1285 - block = (int)(ofs >> chip->bbt_erase_shift); 1286 - if (chip->bbt) 1287 - chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 1160 + chipnr = (int)(ofs >> chip->chip_shift); 1161 + chip->select_chip(mtd, chipnr); 1288 1162 1289 - /* Do we have a flash based bad block table ? */ 1290 - if (chip->bbt_options & NAND_BBT_USE_FLASH) 1291 - ret = nand_update_bbt(mtd, ofs); 1292 - else { 1293 - chipnr = (int)(ofs >> chip->chip_shift); 1294 - chip->select_chip(mtd, chipnr); 1163 + column = this->swap_block_mark ? mtd->writesize : 0; 1295 1164 1296 - column = this->swap_block_mark ? mtd->writesize : 0; 1165 + /* Write the block mark. */ 1166 + block_mark = this->data_buffer_dma; 1167 + block_mark[0] = 0; /* bad block marker */ 1297 1168 1298 - /* Write the block mark. */ 1299 - block_mark = this->data_buffer_dma; 1300 - block_mark[0] = 0; /* bad block marker */ 1169 + /* Shift to get page */ 1170 + page = (int)(ofs >> chip->page_shift); 1301 1171 1302 - /* Shift to get page */ 1303 - page = (int)(ofs >> chip->page_shift); 1172 + chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page); 1173 + chip->write_buf(mtd, block_mark, 1); 1174 + chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 1304 1175 1305 - chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page); 1306 - chip->write_buf(mtd, block_mark, 1); 1307 - chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 1176 + status = chip->waitfunc(mtd, chip); 1177 + if (status & NAND_STATUS_FAIL) 1178 + ret = -EIO; 1308 1179 1309 - status = chip->waitfunc(mtd, chip); 1310 - if (status & NAND_STATUS_FAIL) 1311 - ret = -EIO; 1312 - 1313 - chip->select_chip(mtd, -1); 1314 - } 1315 - if (!ret) 1316 - mtd->ecc_stats.badblocks++; 1180 + chip->select_chip(mtd, -1); 1317 1181 1318 1182 return ret; 1319 1183 } ··· 1581 1469 if (ret) 1582 1470 return ret; 1583 1471 1584 - /* Adjust the ECC strength according to the chip. */ 1585 - this->nand.ecc.strength = this->bch_geometry.ecc_strength; 1586 - this->mtd.ecc_strength = this->bch_geometry.ecc_strength; 1587 - this->mtd.bitflip_threshold = this->bch_geometry.ecc_strength; 1588 - 1589 1472 /* NAND boot init, depends on the gpmi_set_geometry(). */ 1590 1473 return nand_boot_init(this); 1591 1474 } 1592 1475 1593 - static int gpmi_scan_bbt(struct mtd_info *mtd) 1476 + static void gpmi_nfc_exit(struct gpmi_nand_data *this) 1594 1477 { 1478 + nand_release(&this->mtd); 1479 + gpmi_free_dma_buffer(this); 1480 + } 1481 + 1482 + static int gpmi_init_last(struct gpmi_nand_data *this) 1483 + { 1484 + struct mtd_info *mtd = &this->mtd; 1595 1485 struct nand_chip *chip = mtd->priv; 1596 - struct gpmi_nand_data *this = chip->priv; 1486 + struct nand_ecc_ctrl *ecc = &chip->ecc; 1487 + struct bch_geometry *bch_geo = &this->bch_geometry; 1597 1488 int ret; 1598 1489 1599 1490 /* Prepare for the BBT scan. */ 1600 1491 ret = gpmi_pre_bbt_scan(this); 1601 1492 if (ret) 1602 1493 return ret; 1494 + 1495 + /* Init the nand_ecc_ctrl{} */ 1496 + ecc->read_page = gpmi_ecc_read_page; 1497 + ecc->write_page = gpmi_ecc_write_page; 1498 + ecc->read_oob = gpmi_ecc_read_oob; 1499 + ecc->write_oob = gpmi_ecc_write_oob; 1500 + ecc->mode = NAND_ECC_HW; 1501 + ecc->size = bch_geo->ecc_chunk_size; 1502 + ecc->strength = bch_geo->ecc_strength; 1503 + ecc->layout = &gpmi_hw_ecclayout; 1603 1504 1604 1505 /* 1605 1506 * Can we enable the extra features? such as EDO or Sync mode. ··· 1622 1497 */ 1623 1498 gpmi_extra_init(this); 1624 1499 1625 - /* use the default BBT implementation */ 1626 - return nand_default_bbt(mtd); 1627 - } 1628 - 1629 - static void gpmi_nfc_exit(struct gpmi_nand_data *this) 1630 - { 1631 - nand_release(&this->mtd); 1632 - gpmi_free_dma_buffer(this); 1500 + return 0; 1633 1501 } 1634 1502 1635 1503 static int gpmi_nfc_init(struct gpmi_nand_data *this) ··· 1648 1530 chip->read_byte = gpmi_read_byte; 1649 1531 chip->read_buf = gpmi_read_buf; 1650 1532 chip->write_buf = gpmi_write_buf; 1651 - chip->ecc.read_page = gpmi_ecc_read_page; 1652 - chip->ecc.write_page = gpmi_ecc_write_page; 1653 - chip->ecc.read_oob = gpmi_ecc_read_oob; 1654 - chip->ecc.write_oob = gpmi_ecc_write_oob; 1655 - chip->scan_bbt = gpmi_scan_bbt; 1656 1533 chip->badblock_pattern = &gpmi_bbt_descr; 1657 1534 chip->block_markbad = gpmi_block_markbad; 1658 1535 chip->options |= NAND_NO_SUBPAGE_WRITE; 1659 - chip->ecc.mode = NAND_ECC_HW; 1660 - chip->ecc.size = 1; 1661 - chip->ecc.strength = 8; 1662 - chip->ecc.layout = &gpmi_hw_ecclayout; 1663 1536 if (of_get_nand_on_flash_bbt(this->dev->of_node)) 1664 1537 chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB; 1665 1538 1666 - /* Allocate a temporary DMA buffer for reading ID in the nand_scan() */ 1539 + /* 1540 + * Allocate a temporary DMA buffer for reading ID in the 1541 + * nand_scan_ident(). 1542 + */ 1667 1543 this->bch_geometry.payload_size = 1024; 1668 1544 this->bch_geometry.auxiliary_size = 128; 1669 1545 ret = gpmi_alloc_dma_buffer(this); 1670 1546 if (ret) 1671 1547 goto err_out; 1672 1548 1673 - ret = nand_scan(mtd, 1); 1674 - if (ret) { 1675 - pr_err("Chip scan failed\n"); 1549 + ret = nand_scan_ident(mtd, 1, NULL); 1550 + if (ret) 1676 1551 goto err_out; 1677 - } 1552 + 1553 + ret = gpmi_init_last(this); 1554 + if (ret) 1555 + goto err_out; 1556 + 1557 + ret = nand_scan_tail(mtd); 1558 + if (ret) 1559 + goto err_out; 1678 1560 1679 1561 ppdata.of_node = this->pdev->dev.of_node; 1680 1562 ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); ··· 1719 1601 pdev->id_entry = of_id->data; 1720 1602 } else { 1721 1603 pr_err("Failed to find the right device id.\n"); 1722 - return -ENOMEM; 1604 + return -ENODEV; 1723 1605 } 1724 1606 1725 1607 this = kzalloc(sizeof(*this), GFP_KERNEL); ··· 1751 1633 exit_nfc_init: 1752 1634 release_resources(this); 1753 1635 exit_acquire_resources: 1754 - platform_set_drvdata(pdev, NULL); 1755 1636 dev_err(this->dev, "driver registration failed: %d\n", ret); 1756 1637 kfree(this); 1757 1638 ··· 1763 1646 1764 1647 gpmi_nfc_exit(this); 1765 1648 release_resources(this); 1766 - platform_set_drvdata(pdev, NULL); 1767 1649 kfree(this); 1768 1650 return 0; 1769 1651 }
+2 -4
drivers/mtd/nand/jz4740_nand.c
··· 411 411 struct jz_nand *nand; 412 412 struct nand_chip *chip; 413 413 struct mtd_info *mtd; 414 - struct jz_nand_platform_data *pdata = pdev->dev.platform_data; 414 + struct jz_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 415 415 size_t chipnr, bank_idx; 416 416 uint8_t nand_maf_id = 0, nand_dev_id = 0; 417 417 ··· 538 538 err_gpio_busy: 539 539 if (pdata && gpio_is_valid(pdata->busy_gpio)) 540 540 gpio_free(pdata->busy_gpio); 541 - platform_set_drvdata(pdev, NULL); 542 541 err_iounmap_mmio: 543 542 jz_nand_iounmap_resource(nand->mem, nand->base); 544 543 err_free: ··· 548 549 static int jz_nand_remove(struct platform_device *pdev) 549 550 { 550 551 struct jz_nand *nand = platform_get_drvdata(pdev); 551 - struct jz_nand_platform_data *pdata = pdev->dev.platform_data; 552 + struct jz_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 552 553 size_t i; 553 554 554 555 nand_release(&nand->mtd); ··· 569 570 570 571 jz_nand_iounmap_resource(nand->mem, nand->base); 571 572 572 - platform_set_drvdata(pdev, NULL); 573 573 kfree(nand); 574 574 575 575 return 0;
+1 -3
drivers/mtd/nand/lpc32xx_mlc.c
··· 696 696 } 697 697 lpc32xx_wp_disable(host); 698 698 699 - host->pdata = pdev->dev.platform_data; 699 + host->pdata = dev_get_platdata(&pdev->dev); 700 700 701 701 nand_chip->priv = host; /* link the private data structures */ 702 702 mtd->priv = nand_chip; ··· 828 828 err_exit2: 829 829 clk_disable(host->clk); 830 830 clk_put(host->clk); 831 - platform_set_drvdata(pdev, NULL); 832 831 err_exit1: 833 832 lpc32xx_wp_enable(host); 834 833 gpio_free(host->ncfg->wp_gpio); ··· 850 851 851 852 clk_disable(host->clk); 852 853 clk_put(host->clk); 853 - platform_set_drvdata(pdev, NULL); 854 854 855 855 lpc32xx_wp_enable(host); 856 856 gpio_free(host->ncfg->wp_gpio);
+1 -3
drivers/mtd/nand/lpc32xx_slc.c
··· 798 798 } 799 799 lpc32xx_wp_disable(host); 800 800 801 - host->pdata = pdev->dev.platform_data; 801 + host->pdata = dev_get_platdata(&pdev->dev); 802 802 803 803 mtd = &host->mtd; 804 804 chip = &host->nand_chip; ··· 936 936 err_exit2: 937 937 clk_disable(host->clk); 938 938 clk_put(host->clk); 939 - platform_set_drvdata(pdev, NULL); 940 939 err_exit1: 941 940 lpc32xx_wp_enable(host); 942 941 gpio_free(host->ncfg->wp_gpio); ··· 962 963 963 964 clk_disable(host->clk); 964 965 clk_put(host->clk); 965 - platform_set_drvdata(pdev, NULL); 966 966 lpc32xx_wp_enable(host); 967 967 gpio_free(host->ncfg->wp_gpio); 968 968
+3 -9
drivers/mtd/nand/mxc_nand.c
··· 266 266 } 267 267 }; 268 268 269 - static const char const *part_probes[] = { 269 + static const char * const part_probes[] = { 270 270 "cmdlinepart", "RedBoot", "ofpart", NULL }; 271 271 272 272 static void memcpy32_fromio(void *trg, const void __iomem *src, size_t size) ··· 1432 1432 1433 1433 err = mxcnd_probe_dt(host); 1434 1434 if (err > 0) { 1435 - struct mxc_nand_platform_data *pdata = pdev->dev.platform_data; 1435 + struct mxc_nand_platform_data *pdata = 1436 + dev_get_platdata(&pdev->dev); 1436 1437 if (pdata) { 1437 1438 host->pdata = *pdata; 1438 1439 host->devtype_data = (struct mxc_nand_devtype_data *) ··· 1447 1446 1448 1447 if (host->devtype_data->needs_ip) { 1449 1448 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1450 - if (!res) 1451 - return -ENODEV; 1452 1449 host->regs_ip = devm_ioremap_resource(&pdev->dev, res); 1453 1450 if (IS_ERR(host->regs_ip)) 1454 1451 return PTR_ERR(host->regs_ip); ··· 1455 1456 } else { 1456 1457 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1457 1458 } 1458 - 1459 - if (!res) 1460 - return -ENODEV; 1461 1459 1462 1460 host->base = devm_ioremap_resource(&pdev->dev, res); 1463 1461 if (IS_ERR(host->base)) ··· 1573 1577 static int mxcnd_remove(struct platform_device *pdev) 1574 1578 { 1575 1579 struct mxc_nand_host *host = platform_get_drvdata(pdev); 1576 - 1577 - platform_set_drvdata(pdev, NULL); 1578 1580 1579 1581 nand_release(&host->mtd); 1580 1582
+207 -91
drivers/mtd/nand/nand_base.c
··· 108 108 int ret = 0; 109 109 110 110 /* Start address must align on block boundary */ 111 - if (ofs & ((1 << chip->phys_erase_shift) - 1)) { 111 + if (ofs & ((1ULL << chip->phys_erase_shift) - 1)) { 112 112 pr_debug("%s: unaligned address\n", __func__); 113 113 ret = -EINVAL; 114 114 } 115 115 116 116 /* Length must align on block boundary */ 117 - if (len & ((1 << chip->phys_erase_shift) - 1)) { 117 + if (len & ((1ULL << chip->phys_erase_shift) - 1)) { 118 118 pr_debug("%s: length not block aligned\n", __func__); 119 119 ret = -EINVAL; 120 120 } ··· 211 211 */ 212 212 static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 213 213 { 214 - int i; 215 214 struct nand_chip *chip = mtd->priv; 216 215 217 - for (i = 0; i < len; i++) 218 - writeb(buf[i], chip->IO_ADDR_W); 216 + iowrite8_rep(chip->IO_ADDR_W, buf, len); 219 217 } 220 218 221 219 /** ··· 226 228 */ 227 229 static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 228 230 { 229 - int i; 230 231 struct nand_chip *chip = mtd->priv; 231 232 232 - for (i = 0; i < len; i++) 233 - buf[i] = readb(chip->IO_ADDR_R); 233 + ioread8_rep(chip->IO_ADDR_R, buf, len); 234 234 } 235 235 236 236 /** ··· 241 245 */ 242 246 static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 243 247 { 244 - int i; 245 248 struct nand_chip *chip = mtd->priv; 246 249 u16 *p = (u16 *) buf; 247 - len >>= 1; 248 250 249 - for (i = 0; i < len; i++) 250 - writew(p[i], chip->IO_ADDR_W); 251 - 251 + iowrite16_rep(chip->IO_ADDR_W, p, len >> 1); 252 252 } 253 253 254 254 /** ··· 257 265 */ 258 266 static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) 259 267 { 260 - int i; 261 268 struct nand_chip *chip = mtd->priv; 262 269 u16 *p = (u16 *) buf; 263 - len >>= 1; 264 270 265 - for (i = 0; i < len; i++) 266 - p[i] = readw(chip->IO_ADDR_R); 271 + ioread16_rep(chip->IO_ADDR_R, p, len >> 1); 267 272 } 268 273 269 274 /** ··· 324 335 } 325 336 326 337 /** 327 - * nand_default_block_markbad - [DEFAULT] mark a block bad 338 + * nand_default_block_markbad - [DEFAULT] mark a block bad via bad block marker 328 339 * @mtd: MTD device structure 329 340 * @ofs: offset from device start 330 341 * 331 342 * This is the default implementation, which can be overridden by a hardware 332 - * specific driver. We try operations in the following order, according to our 333 - * bbt_options (NAND_BBT_NO_OOB_BBM and NAND_BBT_USE_FLASH): 334 - * (1) erase the affected block, to allow OOB marker to be written cleanly 335 - * (2) update in-memory BBT 336 - * (3) write bad block marker to OOB area of affected block 337 - * (4) update flash-based BBT 338 - * Note that we retain the first error encountered in (3) or (4), finish the 339 - * procedures, and dump the error in the end. 340 - */ 343 + * specific driver. It provides the details for writing a bad block marker to a 344 + * block. 345 + */ 341 346 static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) 342 347 { 343 348 struct nand_chip *chip = mtd->priv; 349 + struct mtd_oob_ops ops; 344 350 uint8_t buf[2] = { 0, 0 }; 345 - int block, res, ret = 0, i = 0; 346 - int write_oob = !(chip->bbt_options & NAND_BBT_NO_OOB_BBM); 351 + int ret = 0, res, i = 0; 347 352 348 - if (write_oob) { 353 + ops.datbuf = NULL; 354 + ops.oobbuf = buf; 355 + ops.ooboffs = chip->badblockpos; 356 + if (chip->options & NAND_BUSWIDTH_16) { 357 + ops.ooboffs &= ~0x01; 358 + ops.len = ops.ooblen = 2; 359 + } else { 360 + ops.len = ops.ooblen = 1; 361 + } 362 + ops.mode = MTD_OPS_PLACE_OOB; 363 + 364 + /* Write to first/last page(s) if necessary */ 365 + if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) 366 + ofs += mtd->erasesize - mtd->writesize; 367 + do { 368 + res = nand_do_write_oob(mtd, ofs, &ops); 369 + if (!ret) 370 + ret = res; 371 + 372 + i++; 373 + ofs += mtd->writesize; 374 + } while ((chip->bbt_options & NAND_BBT_SCAN2NDPAGE) && i < 2); 375 + 376 + return ret; 377 + } 378 + 379 + /** 380 + * nand_block_markbad_lowlevel - mark a block bad 381 + * @mtd: MTD device structure 382 + * @ofs: offset from device start 383 + * 384 + * This function performs the generic NAND bad block marking steps (i.e., bad 385 + * block table(s) and/or marker(s)). We only allow the hardware driver to 386 + * specify how to write bad block markers to OOB (chip->block_markbad). 387 + * 388 + * We try operations in the following order: 389 + * (1) erase the affected block, to allow OOB marker to be written cleanly 390 + * (2) write bad block marker to OOB area of affected block (unless flag 391 + * NAND_BBT_NO_OOB_BBM is present) 392 + * (3) update the BBT 393 + * Note that we retain the first error encountered in (2) or (3), finish the 394 + * procedures, and dump the error in the end. 395 + */ 396 + static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs) 397 + { 398 + struct nand_chip *chip = mtd->priv; 399 + int res, ret = 0; 400 + 401 + if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) { 349 402 struct erase_info einfo; 350 403 351 404 /* Attempt erase before marking OOB */ 352 405 memset(&einfo, 0, sizeof(einfo)); 353 406 einfo.mtd = mtd; 354 407 einfo.addr = ofs; 355 - einfo.len = 1 << chip->phys_erase_shift; 408 + einfo.len = 1ULL << chip->phys_erase_shift; 356 409 nand_erase_nand(mtd, &einfo, 0); 357 - } 358 410 359 - /* Get block number */ 360 - block = (int)(ofs >> chip->bbt_erase_shift); 361 - /* Mark block bad in memory-based BBT */ 362 - if (chip->bbt) 363 - chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 364 - 365 - /* Write bad block marker to OOB */ 366 - if (write_oob) { 367 - struct mtd_oob_ops ops; 368 - loff_t wr_ofs = ofs; 369 - 411 + /* Write bad block marker to OOB */ 370 412 nand_get_device(mtd, FL_WRITING); 371 - 372 - ops.datbuf = NULL; 373 - ops.oobbuf = buf; 374 - ops.ooboffs = chip->badblockpos; 375 - if (chip->options & NAND_BUSWIDTH_16) { 376 - ops.ooboffs &= ~0x01; 377 - ops.len = ops.ooblen = 2; 378 - } else { 379 - ops.len = ops.ooblen = 1; 380 - } 381 - ops.mode = MTD_OPS_PLACE_OOB; 382 - 383 - /* Write to first/last page(s) if necessary */ 384 - if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) 385 - wr_ofs += mtd->erasesize - mtd->writesize; 386 - do { 387 - res = nand_do_write_oob(mtd, wr_ofs, &ops); 388 - if (!ret) 389 - ret = res; 390 - 391 - i++; 392 - wr_ofs += mtd->writesize; 393 - } while ((chip->bbt_options & NAND_BBT_SCAN2NDPAGE) && i < 2); 394 - 413 + ret = chip->block_markbad(mtd, ofs); 395 414 nand_release_device(mtd); 396 415 } 397 416 398 - /* Update flash-based bad block table */ 399 - if (chip->bbt_options & NAND_BBT_USE_FLASH) { 400 - res = nand_update_bbt(mtd, ofs); 417 + /* Mark block bad in BBT */ 418 + if (chip->bbt) { 419 + res = nand_markbad_bbt(mtd, ofs); 401 420 if (!ret) 402 421 ret = res; 403 422 } ··· 1980 1983 * nand_write_subpage_hwecc - [REPLACABLE] hardware ECC based subpage write 1981 1984 * @mtd: mtd info structure 1982 1985 * @chip: nand chip info structure 1983 - * @column: column address of subpage within the page 1986 + * @offset: column address of subpage within the page 1984 1987 * @data_len: data length 1988 + * @buf: data buffer 1985 1989 * @oob_required: must write chip->oob_poi to OOB 1986 1990 */ 1987 1991 static int nand_write_subpage_hwecc(struct mtd_info *mtd, 1988 1992 struct nand_chip *chip, uint32_t offset, 1989 - uint32_t data_len, const uint8_t *data_buf, 1993 + uint32_t data_len, const uint8_t *buf, 1990 1994 int oob_required) 1991 1995 { 1992 1996 uint8_t *oob_buf = chip->oob_poi; ··· 2006 2008 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); 2007 2009 2008 2010 /* write data (untouched subpages already masked by 0xFF) */ 2009 - chip->write_buf(mtd, data_buf, ecc_size); 2011 + chip->write_buf(mtd, buf, ecc_size); 2010 2012 2011 2013 /* mask ECC of un-touched subpages by padding 0xFF */ 2012 2014 if ((step < start_step) || (step > end_step)) 2013 2015 memset(ecc_calc, 0xff, ecc_bytes); 2014 2016 else 2015 - chip->ecc.calculate(mtd, data_buf, ecc_calc); 2017 + chip->ecc.calculate(mtd, buf, ecc_calc); 2016 2018 2017 2019 /* mask OOB of un-touched subpages by padding 0xFF */ 2018 2020 /* if oob_required, preserve OOB metadata of written subpage */ 2019 2021 if (!oob_required || (step < start_step) || (step > end_step)) 2020 2022 memset(oob_buf, 0xff, oob_bytes); 2021 2023 2022 - data_buf += ecc_size; 2024 + buf += ecc_size; 2023 2025 ecc_calc += ecc_bytes; 2024 2026 oob_buf += oob_bytes; 2025 2027 } ··· 2631 2633 } 2632 2634 2633 2635 /* Increment page address and decrement length */ 2634 - len -= (1 << chip->phys_erase_shift); 2636 + len -= (1ULL << chip->phys_erase_shift); 2635 2637 page += pages_per_block; 2636 2638 2637 2639 /* Check, if we cross a chip boundary */ ··· 2692 2694 */ 2693 2695 static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) 2694 2696 { 2695 - struct nand_chip *chip = mtd->priv; 2696 2697 int ret; 2697 2698 2698 2699 ret = nand_block_isbad(mtd, ofs); ··· 2702 2705 return ret; 2703 2706 } 2704 2707 2705 - return chip->block_markbad(mtd, ofs); 2708 + return nand_block_markbad_lowlevel(mtd, ofs); 2706 2709 } 2707 2710 2708 2711 /** ··· 2717 2720 { 2718 2721 int status; 2719 2722 2720 - if (!chip->onfi_version) 2723 + if (!chip->onfi_version || 2724 + !(le16_to_cpu(chip->onfi_params.opt_cmd) 2725 + & ONFI_OPT_CMD_SET_GET_FEATURES)) 2721 2726 return -EINVAL; 2722 2727 2723 2728 chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, addr, -1); ··· 2740 2741 static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, 2741 2742 int addr, uint8_t *subfeature_param) 2742 2743 { 2743 - if (!chip->onfi_version) 2744 + if (!chip->onfi_version || 2745 + !(le16_to_cpu(chip->onfi_params.opt_cmd) 2746 + & ONFI_OPT_CMD_SET_GET_FEATURES)) 2744 2747 return -EINVAL; 2745 2748 2746 2749 /* clear the sub feature parameters */ ··· 2794 2793 2795 2794 if (!chip->select_chip) 2796 2795 chip->select_chip = nand_select_chip; 2797 - if (!chip->read_byte) 2796 + 2797 + /* set for ONFI nand */ 2798 + if (!chip->onfi_set_features) 2799 + chip->onfi_set_features = nand_onfi_set_features; 2800 + if (!chip->onfi_get_features) 2801 + chip->onfi_get_features = nand_onfi_get_features; 2802 + 2803 + /* If called twice, pointers that depend on busw may need to be reset */ 2804 + if (!chip->read_byte || chip->read_byte == nand_read_byte) 2798 2805 chip->read_byte = busw ? nand_read_byte16 : nand_read_byte; 2799 2806 if (!chip->read_word) 2800 2807 chip->read_word = nand_read_word; ··· 2810 2801 chip->block_bad = nand_block_bad; 2811 2802 if (!chip->block_markbad) 2812 2803 chip->block_markbad = nand_default_block_markbad; 2813 - if (!chip->write_buf) 2804 + if (!chip->write_buf || chip->write_buf == nand_write_buf) 2814 2805 chip->write_buf = busw ? nand_write_buf16 : nand_write_buf; 2815 - if (!chip->read_buf) 2806 + if (!chip->read_buf || chip->read_buf == nand_read_buf) 2816 2807 chip->read_buf = busw ? nand_read_buf16 : nand_read_buf; 2817 2808 if (!chip->scan_bbt) 2818 2809 chip->scan_bbt = nand_default_bbt; ··· 2853 2844 } 2854 2845 2855 2846 return crc; 2847 + } 2848 + 2849 + /* Parse the Extended Parameter Page. */ 2850 + static int nand_flash_detect_ext_param_page(struct mtd_info *mtd, 2851 + struct nand_chip *chip, struct nand_onfi_params *p) 2852 + { 2853 + struct onfi_ext_param_page *ep; 2854 + struct onfi_ext_section *s; 2855 + struct onfi_ext_ecc_info *ecc; 2856 + uint8_t *cursor; 2857 + int ret = -EINVAL; 2858 + int len; 2859 + int i; 2860 + 2861 + len = le16_to_cpu(p->ext_param_page_length) * 16; 2862 + ep = kmalloc(len, GFP_KERNEL); 2863 + if (!ep) { 2864 + ret = -ENOMEM; 2865 + goto ext_out; 2866 + } 2867 + 2868 + /* Send our own NAND_CMD_PARAM. */ 2869 + chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); 2870 + 2871 + /* Use the Change Read Column command to skip the ONFI param pages. */ 2872 + chip->cmdfunc(mtd, NAND_CMD_RNDOUT, 2873 + sizeof(*p) * p->num_of_param_pages , -1); 2874 + 2875 + /* Read out the Extended Parameter Page. */ 2876 + chip->read_buf(mtd, (uint8_t *)ep, len); 2877 + if ((onfi_crc16(ONFI_CRC_BASE, ((uint8_t *)ep) + 2, len - 2) 2878 + != le16_to_cpu(ep->crc))) { 2879 + pr_debug("fail in the CRC.\n"); 2880 + goto ext_out; 2881 + } 2882 + 2883 + /* 2884 + * Check the signature. 2885 + * Do not strictly follow the ONFI spec, maybe changed in future. 2886 + */ 2887 + if (strncmp(ep->sig, "EPPS", 4)) { 2888 + pr_debug("The signature is invalid.\n"); 2889 + goto ext_out; 2890 + } 2891 + 2892 + /* find the ECC section. */ 2893 + cursor = (uint8_t *)(ep + 1); 2894 + for (i = 0; i < ONFI_EXT_SECTION_MAX; i++) { 2895 + s = ep->sections + i; 2896 + if (s->type == ONFI_SECTION_TYPE_2) 2897 + break; 2898 + cursor += s->length * 16; 2899 + } 2900 + if (i == ONFI_EXT_SECTION_MAX) { 2901 + pr_debug("We can not find the ECC section.\n"); 2902 + goto ext_out; 2903 + } 2904 + 2905 + /* get the info we want. */ 2906 + ecc = (struct onfi_ext_ecc_info *)cursor; 2907 + 2908 + if (ecc->codeword_size) { 2909 + chip->ecc_strength_ds = ecc->ecc_bits; 2910 + chip->ecc_step_ds = 1 << ecc->codeword_size; 2911 + } 2912 + 2913 + pr_info("ONFI extended param page detected.\n"); 2914 + return 0; 2915 + 2916 + ext_out: 2917 + kfree(ep); 2918 + return ret; 2856 2919 } 2857 2920 2858 2921 /* ··· 2988 2907 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); 2989 2908 chip->chipsize = le32_to_cpu(p->blocks_per_lun); 2990 2909 chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; 2991 - *busw = 0; 2992 - if (le16_to_cpu(p->features) & 1) 2910 + 2911 + if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) 2993 2912 *busw = NAND_BUSWIDTH_16; 2913 + else 2914 + *busw = 0; 2915 + 2916 + if (p->ecc_bits != 0xff) { 2917 + chip->ecc_strength_ds = p->ecc_bits; 2918 + chip->ecc_step_ds = 512; 2919 + } else if (chip->onfi_version >= 21 && 2920 + (onfi_feature(chip) & ONFI_FEATURE_EXT_PARAM_PAGE)) { 2921 + 2922 + /* 2923 + * The nand_flash_detect_ext_param_page() uses the 2924 + * Change Read Column command which maybe not supported 2925 + * by the chip->cmdfunc. So try to update the chip->cmdfunc 2926 + * now. We do not replace user supplied command function. 2927 + */ 2928 + if (mtd->writesize > 512 && chip->cmdfunc == nand_command) 2929 + chip->cmdfunc = nand_command_lp; 2930 + 2931 + /* The Extended Parameter Page is supported since ONFI 2.1. */ 2932 + if (nand_flash_detect_ext_param_page(mtd, chip, p)) 2933 + pr_info("Failed to detect the extended param page.\n"); 2934 + } 2994 2935 2995 2936 pr_info("ONFI flash detected\n"); 2996 2937 return 1; ··· 3189 3086 extid >>= 2; 3190 3087 /* Get buswidth information */ 3191 3088 *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; 3089 + 3090 + /* 3091 + * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per 3092 + * 512B page. For Toshiba SLC, we decode the 5th/6th byte as 3093 + * follows: 3094 + * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, 3095 + * 110b -> 24nm 3096 + * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC 3097 + */ 3098 + if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA && 3099 + !(chip->cellinfo & NAND_CI_CELLTYPE_MSK) && 3100 + (id_data[5] & 0x7) == 0x6 /* 24nm */ && 3101 + !(id_data[4] & 0x80) /* !BENAND */) { 3102 + mtd->oobsize = 32 * mtd->writesize >> 9; 3103 + } 3104 + 3192 3105 } 3193 3106 } 3194 3107 ··· 3291 3172 chip->cellinfo = id_data[2]; 3292 3173 chip->chipsize = (uint64_t)type->chipsize << 20; 3293 3174 chip->options |= type->options; 3175 + chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); 3176 + chip->ecc_step_ds = NAND_ECC_STEP(type); 3294 3177 3295 3178 *busw = type->options & NAND_BUSWIDTH_16; 3296 3179 ··· 3567 3446 if (!chip->write_page) 3568 3447 chip->write_page = nand_write_page; 3569 3448 3570 - /* set for ONFI nand */ 3571 - if (!chip->onfi_set_features) 3572 - chip->onfi_set_features = nand_onfi_set_features; 3573 - if (!chip->onfi_get_features) 3574 - chip->onfi_get_features = nand_onfi_get_features; 3575 - 3576 3449 /* 3577 3450 * Check ECC mode, default to software if 3byte/512byte hardware ECC is 3578 3451 * selected and we have 256 byte pagesize fallback to software ECC ··· 3789 3674 /* propagate ecc info to mtd_info */ 3790 3675 mtd->ecclayout = chip->ecc.layout; 3791 3676 mtd->ecc_strength = chip->ecc.strength; 3677 + mtd->ecc_step_size = chip->ecc.size; 3792 3678 /* 3793 3679 * Initialize bitflip_threshold to its default prior scan_bbt() call. 3794 3680 * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be
+103 -91
drivers/mtd/nand/nand_bbt.c
··· 71 71 #include <linux/export.h> 72 72 #include <linux/string.h> 73 73 74 + #define BBT_BLOCK_GOOD 0x00 75 + #define BBT_BLOCK_WORN 0x01 76 + #define BBT_BLOCK_RESERVED 0x02 77 + #define BBT_BLOCK_FACTORY_BAD 0x03 78 + 79 + #define BBT_ENTRY_MASK 0x03 80 + #define BBT_ENTRY_SHIFT 2 81 + 82 + static int nand_update_bbt(struct mtd_info *mtd, loff_t offs); 83 + 84 + static inline uint8_t bbt_get_entry(struct nand_chip *chip, int block) 85 + { 86 + uint8_t entry = chip->bbt[block >> BBT_ENTRY_SHIFT]; 87 + entry >>= (block & BBT_ENTRY_MASK) * 2; 88 + return entry & BBT_ENTRY_MASK; 89 + } 90 + 91 + static inline void bbt_mark_entry(struct nand_chip *chip, int block, 92 + uint8_t mark) 93 + { 94 + uint8_t msk = (mark & BBT_ENTRY_MASK) << ((block & BBT_ENTRY_MASK) * 2); 95 + chip->bbt[block >> BBT_ENTRY_SHIFT] |= msk; 96 + } 97 + 74 98 static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) 75 99 { 76 100 if (memcmp(buf, td->pattern, td->len)) ··· 110 86 * @td: search pattern descriptor 111 87 * 112 88 * Check for a pattern at the given place. Used to search bad block tables and 113 - * good / bad block identifiers. If the SCAN_EMPTY option is set then check, if 114 - * all bytes except the pattern area contain 0xff. 89 + * good / bad block identifiers. 115 90 */ 116 91 static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 117 92 { 118 - int end = 0; 119 - uint8_t *p = buf; 120 - 121 93 if (td->options & NAND_BBT_NO_OOB) 122 94 return check_pattern_no_oob(buf, td); 123 95 124 - end = paglen + td->offs; 125 - if (td->options & NAND_BBT_SCANEMPTY) 126 - if (memchr_inv(p, 0xff, end)) 127 - return -1; 128 - p += end; 129 - 130 96 /* Compare the pattern */ 131 - if (memcmp(p, td->pattern, td->len)) 97 + if (memcmp(buf + paglen + td->offs, td->pattern, td->len)) 132 98 return -1; 133 99 134 - if (td->options & NAND_BBT_SCANEMPTY) { 135 - p += td->len; 136 - end += td->len; 137 - if (memchr_inv(p, 0xff, len - end)) 138 - return -1; 139 - } 140 100 return 0; 141 101 } 142 102 ··· 167 159 * @page: the starting page 168 160 * @num: the number of bbt descriptors to read 169 161 * @td: the bbt describtion table 170 - * @offs: offset in the memory table 162 + * @offs: block number offset in the table 171 163 * 172 164 * Read the bad block table starting from page. 173 165 */ ··· 217 209 /* Analyse data */ 218 210 for (i = 0; i < len; i++) { 219 211 uint8_t dat = buf[i]; 220 - for (j = 0; j < 8; j += bits, act += 2) { 212 + for (j = 0; j < 8; j += bits, act++) { 221 213 uint8_t tmp = (dat >> j) & msk; 222 214 if (tmp == msk) 223 215 continue; 224 216 if (reserved_block_code && (tmp == reserved_block_code)) { 225 217 pr_info("nand_read_bbt: reserved block at 0x%012llx\n", 226 - (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); 227 - this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06); 218 + (loff_t)(offs + act) << 219 + this->bbt_erase_shift); 220 + bbt_mark_entry(this, offs + act, 221 + BBT_BLOCK_RESERVED); 228 222 mtd->ecc_stats.bbtblocks++; 229 223 continue; 230 224 } ··· 235 225 * move this message to pr_debug. 236 226 */ 237 227 pr_info("nand_read_bbt: bad block at 0x%012llx\n", 238 - (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); 228 + (loff_t)(offs + act) << 229 + this->bbt_erase_shift); 239 230 /* Factory marked bad or worn out? */ 240 231 if (tmp == 0) 241 - this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06); 232 + bbt_mark_entry(this, offs + act, 233 + BBT_BLOCK_FACTORY_BAD); 242 234 else 243 - this->bbt[offs + (act >> 3)] |= 0x1 << (act & 0x06); 235 + bbt_mark_entry(this, offs + act, 236 + BBT_BLOCK_WORN); 244 237 mtd->ecc_stats.badblocks++; 245 238 } 246 239 } ··· 278 265 td, offs); 279 266 if (res) 280 267 return res; 281 - offs += this->chipsize >> (this->bbt_erase_shift + 2); 268 + offs += this->chipsize >> this->bbt_erase_shift; 282 269 } 283 270 } else { 284 271 res = read_bbt(mtd, buf, td->pages[0], ··· 491 478 else 492 479 numpages = 1; 493 480 494 - if (!(bd->options & NAND_BBT_SCANEMPTY)) { 495 - /* We need only read few bytes from the OOB area */ 496 - scanlen = 0; 497 - readlen = bd->len; 498 - } else { 499 - /* Full page content should be read */ 500 - scanlen = mtd->writesize + mtd->oobsize; 501 - readlen = numpages * mtd->writesize; 502 - } 481 + /* We need only read few bytes from the OOB area */ 482 + scanlen = 0; 483 + readlen = bd->len; 503 484 504 485 if (chip == -1) { 505 - /* 506 - * Note that numblocks is 2 * (real numblocks) here, see i+=2 507 - * below as it makes shifting and masking less painful 508 - */ 509 - numblocks = mtd->size >> (this->bbt_erase_shift - 1); 486 + numblocks = mtd->size >> this->bbt_erase_shift; 510 487 startblock = 0; 511 488 from = 0; 512 489 } else { ··· 505 502 chip + 1, this->numchips); 506 503 return -EINVAL; 507 504 } 508 - numblocks = this->chipsize >> (this->bbt_erase_shift - 1); 505 + numblocks = this->chipsize >> this->bbt_erase_shift; 509 506 startblock = chip * numblocks; 510 507 numblocks += startblock; 511 - from = (loff_t)startblock << (this->bbt_erase_shift - 1); 508 + from = (loff_t)startblock << this->bbt_erase_shift; 512 509 } 513 510 514 511 if (this->bbt_options & NAND_BBT_SCANLASTPAGE) 515 512 from += mtd->erasesize - (mtd->writesize * numpages); 516 513 517 - for (i = startblock; i < numblocks;) { 514 + for (i = startblock; i < numblocks; i++) { 518 515 int ret; 519 516 520 517 BUG_ON(bd->options & NAND_BBT_NO_OOB); ··· 529 526 return ret; 530 527 531 528 if (ret) { 532 - this->bbt[i >> 3] |= 0x03 << (i & 0x6); 529 + bbt_mark_entry(this, i, BBT_BLOCK_FACTORY_BAD); 533 530 pr_warn("Bad eraseblock %d at 0x%012llx\n", 534 - i >> 1, (unsigned long long)from); 531 + i, (unsigned long long)from); 535 532 mtd->ecc_stats.badblocks++; 536 533 } 537 534 538 - i += 2; 539 535 from += (1 << this->bbt_erase_shift); 540 536 } 541 537 return 0; ··· 657 655 { 658 656 struct nand_chip *this = mtd->priv; 659 657 struct erase_info einfo; 660 - int i, j, res, chip = 0; 658 + int i, res, chip = 0; 661 659 int bits, startblock, dir, page, offs, numblocks, sft, sftmsk; 662 - int nrchips, bbtoffs, pageoffs, ooboffs; 660 + int nrchips, pageoffs, ooboffs; 663 661 uint8_t msk[4]; 664 662 uint8_t rcode = td->reserved_block_code; 665 663 size_t retlen, len = 0; ··· 715 713 for (i = 0; i < td->maxblocks; i++) { 716 714 int block = startblock + dir * i; 717 715 /* Check, if the block is bad */ 718 - switch ((this->bbt[block >> 2] >> 719 - (2 * (block & 0x03))) & 0x03) { 720 - case 0x01: 721 - case 0x03: 716 + switch (bbt_get_entry(this, block)) { 717 + case BBT_BLOCK_WORN: 718 + case BBT_BLOCK_FACTORY_BAD: 722 719 continue; 723 720 } 724 721 page = block << ··· 748 747 break; 749 748 default: return -EINVAL; 750 749 } 751 - 752 - bbtoffs = chip * (numblocks >> 2); 753 750 754 751 to = ((loff_t)page) << this->page_shift; 755 752 ··· 813 814 buf[ooboffs + td->veroffs] = td->version[chip]; 814 815 815 816 /* Walk through the memory table */ 816 - for (i = 0; i < numblocks;) { 817 + for (i = 0; i < numblocks; i++) { 817 818 uint8_t dat; 818 - dat = this->bbt[bbtoffs + (i >> 2)]; 819 - for (j = 0; j < 4; j++, i++) { 820 - int sftcnt = (i << (3 - sft)) & sftmsk; 821 - /* Do not store the reserved bbt blocks! */ 822 - buf[offs + (i >> sft)] &= 823 - ~(msk[dat & 0x03] << sftcnt); 824 - dat >>= 2; 825 - } 819 + int sftcnt = (i << (3 - sft)) & sftmsk; 820 + dat = bbt_get_entry(this, chip * numblocks + i); 821 + /* Do not store the reserved bbt blocks! */ 822 + buf[offs + (i >> sft)] &= ~(msk[dat] << sftcnt); 826 823 } 827 824 828 825 memset(&einfo, 0, sizeof(einfo)); ··· 860 865 { 861 866 struct nand_chip *this = mtd->priv; 862 867 863 - bd->options &= ~NAND_BBT_SCANEMPTY; 864 868 return create_bbt(mtd, this->buffers->databuf, bd, -1); 865 869 } 866 870 ··· 1003 1009 { 1004 1010 struct nand_chip *this = mtd->priv; 1005 1011 int i, j, chips, block, nrblocks, update; 1006 - uint8_t oldval, newval; 1012 + uint8_t oldval; 1007 1013 1008 1014 /* Do we have a bbt per chip? */ 1009 1015 if (td->options & NAND_BBT_PERCHIP) { ··· 1020 1026 if (td->pages[i] == -1) 1021 1027 continue; 1022 1028 block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift); 1023 - block <<= 1; 1024 - oldval = this->bbt[(block >> 3)]; 1025 - newval = oldval | (0x2 << (block & 0x06)); 1026 - this->bbt[(block >> 3)] = newval; 1027 - if ((oldval != newval) && td->reserved_block_code) 1028 - nand_update_bbt(mtd, (loff_t)block << (this->bbt_erase_shift - 1)); 1029 + oldval = bbt_get_entry(this, block); 1030 + bbt_mark_entry(this, block, BBT_BLOCK_RESERVED); 1031 + if ((oldval != BBT_BLOCK_RESERVED) && 1032 + td->reserved_block_code) 1033 + nand_update_bbt(mtd, (loff_t)block << 1034 + this->bbt_erase_shift); 1029 1035 continue; 1030 1036 } 1031 1037 update = 0; ··· 1033 1039 block = ((i + 1) * nrblocks) - td->maxblocks; 1034 1040 else 1035 1041 block = i * nrblocks; 1036 - block <<= 1; 1037 1042 for (j = 0; j < td->maxblocks; j++) { 1038 - oldval = this->bbt[(block >> 3)]; 1039 - newval = oldval | (0x2 << (block & 0x06)); 1040 - this->bbt[(block >> 3)] = newval; 1041 - if (oldval != newval) 1043 + oldval = bbt_get_entry(this, block); 1044 + bbt_mark_entry(this, block, BBT_BLOCK_RESERVED); 1045 + if (oldval != BBT_BLOCK_RESERVED) 1042 1046 update = 1; 1043 - block += 2; 1047 + block++; 1044 1048 } 1045 1049 /* 1046 1050 * If we want reserved blocks to be recorded to flash, and some ··· 1046 1054 * bbts. This should only happen once. 1047 1055 */ 1048 1056 if (update && td->reserved_block_code) 1049 - nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1)); 1057 + nand_update_bbt(mtd, (loff_t)(block - 1) << 1058 + this->bbt_erase_shift); 1050 1059 } 1051 1060 } 1052 1061 ··· 1173 1180 } 1174 1181 1175 1182 /** 1176 - * nand_update_bbt - [NAND Interface] update bad block table(s) 1183 + * nand_update_bbt - update bad block table(s) 1177 1184 * @mtd: MTD device structure 1178 1185 * @offs: the offset of the newly marked block 1179 1186 * 1180 1187 * The function updates the bad block table(s). 1181 1188 */ 1182 - int nand_update_bbt(struct mtd_info *mtd, loff_t offs) 1189 + static int nand_update_bbt(struct mtd_info *mtd, loff_t offs) 1183 1190 { 1184 1191 struct nand_chip *this = mtd->priv; 1185 1192 int len, res = 0; ··· 1349 1356 int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) 1350 1357 { 1351 1358 struct nand_chip *this = mtd->priv; 1352 - int block; 1353 - uint8_t res; 1359 + int block, res; 1354 1360 1355 - /* Get block number * 2 */ 1356 - block = (int)(offs >> (this->bbt_erase_shift - 1)); 1357 - res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; 1361 + block = (int)(offs >> this->bbt_erase_shift); 1362 + res = bbt_get_entry(this, block); 1358 1363 1359 1364 pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: " 1360 1365 "(block %d) 0x%02x\n", 1361 - (unsigned int)offs, block >> 1, res); 1366 + (unsigned int)offs, block, res); 1362 1367 1363 - switch ((int)res) { 1364 - case 0x00: 1368 + switch (res) { 1369 + case BBT_BLOCK_GOOD: 1365 1370 return 0; 1366 - case 0x01: 1371 + case BBT_BLOCK_WORN: 1367 1372 return 1; 1368 - case 0x02: 1373 + case BBT_BLOCK_RESERVED: 1369 1374 return allowbbt ? 0 : 1; 1370 1375 } 1371 1376 return 1; 1372 1377 } 1373 1378 1379 + /** 1380 + * nand_markbad_bbt - [NAND Interface] Mark a block bad in the BBT 1381 + * @mtd: MTD device structure 1382 + * @offs: offset of the bad block 1383 + */ 1384 + int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs) 1385 + { 1386 + struct nand_chip *this = mtd->priv; 1387 + int block, ret = 0; 1388 + 1389 + block = (int)(offs >> this->bbt_erase_shift); 1390 + 1391 + /* Mark bad block in memory */ 1392 + bbt_mark_entry(this, block, BBT_BLOCK_WORN); 1393 + 1394 + /* Update flash-based bad block table */ 1395 + if (this->bbt_options & NAND_BBT_USE_FLASH) 1396 + ret = nand_update_bbt(mtd, offs); 1397 + 1398 + return ret; 1399 + } 1400 + 1374 1401 EXPORT_SYMBOL(nand_scan_bbt); 1375 1402 EXPORT_SYMBOL(nand_default_bbt); 1376 - EXPORT_SYMBOL_GPL(nand_update_bbt);
+4 -4
drivers/mtd/nand/nand_ids.c
··· 33 33 */ 34 34 {"TC58NVG2S0F 4G 3.3V 8-bit", 35 35 { .id = {0x98, 0xdc, 0x90, 0x26, 0x76, 0x15, 0x01, 0x08} }, 36 - SZ_4K, SZ_512, SZ_256K, 0, 8, 224}, 36 + SZ_4K, SZ_512, SZ_256K, 0, 8, 224, NAND_ECC_INFO(4, SZ_512) }, 37 37 {"TC58NVG3S0F 8G 3.3V 8-bit", 38 38 { .id = {0x98, 0xd3, 0x90, 0x26, 0x76, 0x15, 0x02, 0x08} }, 39 - SZ_4K, SZ_1K, SZ_256K, 0, 8, 232}, 39 + SZ_4K, SZ_1K, SZ_256K, 0, 8, 232, NAND_ECC_INFO(4, SZ_512) }, 40 40 {"TC58NVG5D2 32G 3.3V 8-bit", 41 41 { .id = {0x98, 0xd7, 0x94, 0x32, 0x76, 0x56, 0x09, 0x00} }, 42 - SZ_8K, SZ_4K, SZ_1M, 0, 8, 640}, 42 + SZ_8K, SZ_4K, SZ_1M, 0, 8, 640, NAND_ECC_INFO(40, SZ_1K) }, 43 43 {"TC58NVG6D2 64G 3.3V 8-bit", 44 44 { .id = {0x98, 0xde, 0x94, 0x82, 0x76, 0x56, 0x04, 0x20} }, 45 - SZ_8K, SZ_8K, SZ_2M, 0, 8, 640}, 45 + SZ_8K, SZ_8K, SZ_2M, 0, 8, 640, NAND_ECC_INFO(40, SZ_1K) }, 46 46 47 47 LEGACY_ID_NAND("NAND 4MiB 5V 8-bit", 0x6B, 4, SZ_8K, SP_OPTIONS), 48 48 LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit", 0xE3, 4, SZ_8K, SP_OPTIONS),
+15 -24
drivers/mtd/nand/nandsim.c
··· 205 205 206 206 /* Calculate the page offset in flash RAM image by (row, column) address */ 207 207 #define NS_RAW_OFFSET(ns) \ 208 - (((ns)->regs.row << (ns)->geom.pgshift) + ((ns)->regs.row * (ns)->geom.oobsz) + (ns)->regs.column) 208 + (((ns)->regs.row * (ns)->geom.pgszoob) + (ns)->regs.column) 209 209 210 210 /* Calculate the OOB offset in flash RAM image by (row, column) address */ 211 211 #define NS_RAW_OFFSET_OOB(ns) (NS_RAW_OFFSET(ns) + ns->geom.pgsz) ··· 336 336 uint pgsec; /* number of pages per sector */ 337 337 uint secshift; /* bits number in sector size */ 338 338 uint pgshift; /* bits number in page size */ 339 - uint oobshift; /* bits number in OOB size */ 340 339 uint pgaddrbytes; /* bytes per page address */ 341 340 uint secaddrbytes; /* bytes per sector address */ 342 341 uint idbytes; /* the number ID bytes that this chip outputs */ ··· 362 363 363 364 /* Fields needed when using a cache file */ 364 365 struct file *cfile; /* Open file */ 365 - unsigned char *pages_written; /* Which pages have been written */ 366 + unsigned long *pages_written; /* Which pages have been written */ 366 367 void *file_buf; 367 368 struct page *held_pages[NS_MAX_HELD_PAGES]; 368 369 int held_cnt; ··· 585 586 err = -EINVAL; 586 587 goto err_close; 587 588 } 588 - ns->pages_written = vzalloc(ns->geom.pgnum); 589 + ns->pages_written = vzalloc(BITS_TO_LONGS(ns->geom.pgnum) * 590 + sizeof(unsigned long)); 589 591 if (!ns->pages_written) { 590 592 NS_ERR("alloc_device: unable to allocate pages written array\n"); 591 593 err = -ENOMEM; ··· 653 653 654 654 static char *get_partition_name(int i) 655 655 { 656 - char buf[64]; 657 - sprintf(buf, "NAND simulator partition %d", i); 658 - return kstrdup(buf, GFP_KERNEL); 656 + return kasprintf(GFP_KERNEL, "NAND simulator partition %d", i); 659 657 } 660 658 661 659 /* ··· 688 690 ns->geom.totszoob = ns->geom.totsz + (uint64_t)ns->geom.pgnum * ns->geom.oobsz; 689 691 ns->geom.secshift = ffs(ns->geom.secsz) - 1; 690 692 ns->geom.pgshift = chip->page_shift; 691 - ns->geom.oobshift = ffs(ns->geom.oobsz) - 1; 692 693 ns->geom.pgsec = ns->geom.secsz / ns->geom.pgsz; 693 694 ns->geom.secszoob = ns->geom.secsz + ns->geom.oobsz * ns->geom.pgsec; 694 695 ns->options = 0; ··· 758 761 ns->nbparts += 1; 759 762 } 760 763 761 - /* Detect how many ID bytes the NAND chip outputs */ 762 - for (i = 0; nand_flash_ids[i].name != NULL; i++) { 763 - if (second_id_byte != nand_flash_ids[i].dev_id) 764 - continue; 765 - } 766 - 767 764 if (ns->busw == 16) 768 765 NS_WARN("16-bit flashes support wasn't tested\n"); 769 766 ··· 771 780 printk("bus width: %u\n", ns->busw); 772 781 printk("bits in sector size: %u\n", ns->geom.secshift); 773 782 printk("bits in page size: %u\n", ns->geom.pgshift); 774 - printk("bits in OOB size: %u\n", ns->geom.oobshift); 783 + printk("bits in OOB size: %u\n", ffs(ns->geom.oobsz) - 1); 775 784 printk("flash size with OOB: %llu KiB\n", 776 785 (unsigned long long)ns->geom.totszoob >> 10); 777 786 printk("page address bytes: %u\n", ns->geom.pgaddrbytes); ··· 1433 1442 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off; 1434 1443 } 1435 1444 1436 - int do_read_error(struct nandsim *ns, int num) 1445 + static int do_read_error(struct nandsim *ns, int num) 1437 1446 { 1438 1447 unsigned int page_no = ns->regs.row; 1439 1448 ··· 1445 1454 return 0; 1446 1455 } 1447 1456 1448 - void do_bit_flips(struct nandsim *ns, int num) 1457 + static void do_bit_flips(struct nandsim *ns, int num) 1449 1458 { 1450 1459 if (bitflips && prandom_u32() < (1 << 22)) { 1451 1460 int flips = 1; ··· 1470 1479 union ns_mem *mypage; 1471 1480 1472 1481 if (ns->cfile) { 1473 - if (!ns->pages_written[ns->regs.row]) { 1482 + if (!test_bit(ns->regs.row, ns->pages_written)) { 1474 1483 NS_DBG("read_page: page %d not written\n", ns->regs.row); 1475 1484 memset(ns->buf.byte, 0xFF, num); 1476 1485 } else { ··· 1481 1490 ns->regs.row, ns->regs.column + ns->regs.off); 1482 1491 if (do_read_error(ns, num)) 1483 1492 return; 1484 - pos = (loff_t)ns->regs.row * ns->geom.pgszoob + ns->regs.column + ns->regs.off; 1493 + pos = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; 1485 1494 tx = read_file(ns, ns->cfile, ns->buf.byte, num, pos); 1486 1495 if (tx != num) { 1487 1496 NS_ERR("read_page: read error for page %d ret %ld\n", ns->regs.row, (long)tx); ··· 1516 1525 1517 1526 if (ns->cfile) { 1518 1527 for (i = 0; i < ns->geom.pgsec; i++) 1519 - if (ns->pages_written[ns->regs.row + i]) { 1528 + if (__test_and_clear_bit(ns->regs.row + i, 1529 + ns->pages_written)) { 1520 1530 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row + i); 1521 - ns->pages_written[ns->regs.row + i] = 0; 1522 1531 } 1523 1532 return; 1524 1533 } ··· 1550 1559 1551 1560 NS_DBG("prog_page: writing page %d\n", ns->regs.row); 1552 1561 pg_off = ns->file_buf + ns->regs.column + ns->regs.off; 1553 - off = (loff_t)ns->regs.row * ns->geom.pgszoob + ns->regs.column + ns->regs.off; 1554 - if (!ns->pages_written[ns->regs.row]) { 1562 + off = (loff_t)NS_RAW_OFFSET(ns) + ns->regs.off; 1563 + if (!test_bit(ns->regs.row, ns->pages_written)) { 1555 1564 all = 1; 1556 1565 memset(ns->file_buf, 0xff, ns->geom.pgszoob); 1557 1566 } else { ··· 1571 1580 NS_ERR("prog_page: write error for page %d ret %ld\n", ns->regs.row, (long)tx); 1572 1581 return -1; 1573 1582 } 1574 - ns->pages_written[ns->regs.row] = 1; 1583 + __set_bit(ns->regs.row, ns->pages_written); 1575 1584 } else { 1576 1585 tx = write_file(ns, ns->cfile, pg_off, num, off); 1577 1586 if (tx != num) {
-2
drivers/mtd/nand/nuc900_nand.c
··· 324 324 325 325 kfree(nuc900_nand); 326 326 327 - platform_set_drvdata(pdev, NULL); 328 - 329 327 return 0; 330 328 } 331 329
+2 -3
drivers/mtd/nand/omap2.c
··· 154 154 */ 155 155 static uint8_t scan_ff_pattern[] = { 0xff }; 156 156 static struct nand_bbt_descr bb_descrip_flashbased = { 157 - .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES, 157 + .options = NAND_BBT_SCANALLPAGES, 158 158 .offs = 0, 159 159 .len = 1, 160 160 .pattern = scan_ff_pattern, ··· 1831 1831 struct resource *res; 1832 1832 struct mtd_part_parser_data ppdata = {}; 1833 1833 1834 - pdata = pdev->dev.platform_data; 1834 + pdata = dev_get_platdata(&pdev->dev); 1835 1835 if (pdata == NULL) { 1836 1836 dev_err(&pdev->dev, "platform data missing\n"); 1837 1837 return -ENODEV; ··· 2087 2087 mtd); 2088 2088 omap3_free_bch(&info->mtd); 2089 2089 2090 - platform_set_drvdata(pdev, NULL); 2091 2090 if (info->dma) 2092 2091 dma_release_channel(info->dma); 2093 2092
+3 -3
drivers/mtd/nand/orion_nand.c
··· 130 130 if (!of_property_read_u32(pdev->dev.of_node, 131 131 "chip-delay", &val)) 132 132 board->chip_delay = (u8)val; 133 - } else 134 - board = pdev->dev.platform_data; 133 + } else { 134 + board = dev_get_platdata(&pdev->dev); 135 + } 135 136 136 137 mtd->priv = nc; 137 138 mtd->owner = THIS_MODULE; ··· 187 186 clk_disable_unprepare(clk); 188 187 clk_put(clk); 189 188 } 190 - platform_set_drvdata(pdev, NULL); 191 189 iounmap(io_base); 192 190 no_res: 193 191 kfree(nc);
+2 -3
drivers/mtd/nand/plat_nand.c
··· 30 30 */ 31 31 static int plat_nand_probe(struct platform_device *pdev) 32 32 { 33 - struct platform_nand_data *pdata = pdev->dev.platform_data; 33 + struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); 34 34 struct mtd_part_parser_data ppdata; 35 35 struct plat_nand_data *data; 36 36 struct resource *res; ··· 122 122 out: 123 123 if (pdata->ctrl.remove) 124 124 pdata->ctrl.remove(pdev); 125 - platform_set_drvdata(pdev, NULL); 126 125 iounmap(data->io_base); 127 126 out_release_io: 128 127 release_mem_region(res->start, resource_size(res)); ··· 136 137 static int plat_nand_remove(struct platform_device *pdev) 137 138 { 138 139 struct plat_nand_data *data = platform_get_drvdata(pdev); 139 - struct platform_nand_data *pdata = pdev->dev.platform_data; 140 + struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); 140 141 struct resource *res; 141 142 142 143 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+221 -163
drivers/mtd/nand/pxa3xx_nand.c
··· 25 25 #include <linux/of.h> 26 26 #include <linux/of_device.h> 27 27 28 + #if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP) 29 + #define ARCH_HAS_DMA 30 + #endif 31 + 32 + #ifdef ARCH_HAS_DMA 28 33 #include <mach/dma.h> 34 + #endif 35 + 29 36 #include <linux/platform_data/mtd-nand-pxa3xx.h> 30 37 31 38 #define CHIP_DELAY_TIMEOUT (2 * HZ/10) ··· 87 80 #define NDSR_RDDREQ (0x1 << 1) 88 81 #define NDSR_WRCMDREQ (0x1) 89 82 83 + #define NDCB0_LEN_OVRD (0x1 << 28) 90 84 #define NDCB0_ST_ROW_EN (0x1 << 26) 91 85 #define NDCB0_AUTO_RS (0x1 << 25) 92 86 #define NDCB0_CSEL (0x1 << 24) ··· 131 123 STATE_READY, 132 124 }; 133 125 126 + enum pxa3xx_nand_variant { 127 + PXA3XX_NAND_VARIANT_PXA, 128 + PXA3XX_NAND_VARIANT_ARMADA370, 129 + }; 130 + 134 131 struct pxa3xx_nand_host { 135 132 struct nand_chip chip; 136 - struct pxa3xx_nand_cmdset *cmdset; 137 133 struct mtd_info *mtd; 138 134 void *info_data; 139 135 ··· 151 139 unsigned int row_addr_cycles; 152 140 size_t read_id_bytes; 153 141 154 - /* cached register value */ 155 - uint32_t reg_ndcr; 156 - uint32_t ndtr0cs0; 157 - uint32_t ndtr1cs0; 158 142 }; 159 143 160 144 struct pxa3xx_nand_info { ··· 179 171 struct pxa3xx_nand_host *host[NUM_CHIP_SELECT]; 180 172 unsigned int state; 181 173 174 + /* 175 + * This driver supports NFCv1 (as found in PXA SoC) 176 + * and NFCv2 (as found in Armada 370/XP SoC). 177 + */ 178 + enum pxa3xx_nand_variant variant; 179 + 182 180 int cs; 183 181 int use_ecc; /* use HW ECC ? */ 184 182 int use_dma; /* use DMA ? */ 183 + int use_spare; /* use spare ? */ 185 184 int is_ready; 186 185 187 186 unsigned int page_size; /* page size of attached chip */ ··· 196 181 unsigned int oob_size; 197 182 int retcode; 198 183 184 + /* cached register value */ 185 + uint32_t reg_ndcr; 186 + uint32_t ndtr0cs0; 187 + uint32_t ndtr1cs0; 188 + 199 189 /* generated NDCBx register values */ 200 190 uint32_t ndcb0; 201 191 uint32_t ndcb1; 202 192 uint32_t ndcb2; 193 + uint32_t ndcb3; 203 194 }; 204 195 205 196 static bool use_dma = 1; 206 197 module_param(use_dma, bool, 0444); 207 198 MODULE_PARM_DESC(use_dma, "enable DMA for data transferring to/from NAND HW"); 208 - 209 - /* 210 - * Default NAND flash controller configuration setup by the 211 - * bootloader. This configuration is used only when pdata->keep_config is set 212 - */ 213 - static struct pxa3xx_nand_cmdset default_cmdset = { 214 - .read1 = 0x3000, 215 - .read2 = 0x0050, 216 - .program = 0x1080, 217 - .read_status = 0x0070, 218 - .read_id = 0x0090, 219 - .erase = 0xD060, 220 - .reset = 0x00FF, 221 - .lock = 0x002A, 222 - .unlock = 0x2423, 223 - .lock_status = 0x007A, 224 - }; 225 199 226 200 static struct pxa3xx_nand_timing timing[] = { 227 201 { 40, 80, 60, 100, 80, 100, 90000, 400, 40, }, ··· 233 229 234 230 /* Define a default flash type setting serve as flash detecting only */ 235 231 #define DEFAULT_FLASH_TYPE (&builtin_flash_types[0]) 236 - 237 - const char *mtd_names[] = {"pxa3xx_nand-0", "pxa3xx_nand-1", NULL}; 238 232 239 233 #define NDTR0_tCH(c) (min((c), 7) << 19) 240 234 #define NDTR0_tCS(c) (min((c), 7) << 16) ··· 266 264 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | 267 265 NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); 268 266 269 - host->ndtr0cs0 = ndtr0; 270 - host->ndtr1cs0 = ndtr1; 267 + info->ndtr0cs0 = ndtr0; 268 + info->ndtr1cs0 = ndtr1; 271 269 nand_writel(info, NDTR0CS0, ndtr0); 272 270 nand_writel(info, NDTR1CS0, ndtr1); 273 271 } ··· 275 273 static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info) 276 274 { 277 275 struct pxa3xx_nand_host *host = info->host[info->cs]; 278 - int oob_enable = host->reg_ndcr & NDCR_SPARE_EN; 276 + int oob_enable = info->reg_ndcr & NDCR_SPARE_EN; 279 277 280 278 info->data_size = host->page_size; 281 279 if (!oob_enable) { ··· 301 299 */ 302 300 static void pxa3xx_nand_start(struct pxa3xx_nand_info *info) 303 301 { 304 - struct pxa3xx_nand_host *host = info->host[info->cs]; 305 302 uint32_t ndcr; 306 303 307 - ndcr = host->reg_ndcr; 308 - ndcr |= info->use_ecc ? NDCR_ECC_EN : 0; 309 - ndcr |= info->use_dma ? NDCR_DMA_EN : 0; 304 + ndcr = info->reg_ndcr; 305 + 306 + if (info->use_ecc) 307 + ndcr |= NDCR_ECC_EN; 308 + else 309 + ndcr &= ~NDCR_ECC_EN; 310 + 311 + if (info->use_dma) 312 + ndcr |= NDCR_DMA_EN; 313 + else 314 + ndcr &= ~NDCR_DMA_EN; 315 + 316 + if (info->use_spare) 317 + ndcr |= NDCR_SPARE_EN; 318 + else 319 + ndcr &= ~NDCR_SPARE_EN; 320 + 310 321 ndcr |= NDCR_ND_RUN; 311 322 312 323 /* clear status bits and run */ ··· 348 333 nand_writel(info, NDSR, NDSR_MASK); 349 334 } 350 335 351 - static void enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask) 336 + static void __maybe_unused 337 + enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask) 352 338 { 353 339 uint32_t ndcr; 354 340 ··· 389 373 } 390 374 } 391 375 376 + #ifdef ARCH_HAS_DMA 392 377 static void start_data_dma(struct pxa3xx_nand_info *info) 393 378 { 394 379 struct pxa_dma_desc *desc = info->data_desc; ··· 436 419 enable_int(info, NDCR_INT_MASK); 437 420 nand_writel(info, NDSR, NDSR_WRDREQ | NDSR_RDDREQ); 438 421 } 422 + #else 423 + static void start_data_dma(struct pxa3xx_nand_info *info) 424 + {} 425 + #endif 439 426 440 427 static irqreturn_t pxa3xx_nand_irq(int irq, void *devid) 441 428 { ··· 488 467 nand_writel(info, NDSR, NDSR_WRCMDREQ); 489 468 status &= ~NDSR_WRCMDREQ; 490 469 info->state = STATE_CMD_HANDLE; 470 + 471 + /* 472 + * Command buffer registers NDCB{0-2} (and optionally NDCB3) 473 + * must be loaded by writing directly either 12 or 16 474 + * bytes directly to NDCB0, four bytes at a time. 475 + * 476 + * Direct write access to NDCB1, NDCB2 and NDCB3 is ignored 477 + * but each NDCBx register can be read. 478 + */ 491 479 nand_writel(info, NDCB0, info->ndcb0); 492 480 nand_writel(info, NDCB0, info->ndcb1); 493 481 nand_writel(info, NDCB0, info->ndcb2); 482 + 483 + /* NDCB3 register is available in NFCv2 (Armada 370/XP SoC) */ 484 + if (info->variant == PXA3XX_NAND_VARIANT_ARMADA370) 485 + nand_writel(info, NDCB0, info->ndcb3); 494 486 } 495 487 496 488 /* clear NDSR to let the controller exit the IRQ */ ··· 525 491 static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, 526 492 uint16_t column, int page_addr) 527 493 { 528 - uint16_t cmd; 529 494 int addr_cycle, exec_cmd; 530 495 struct pxa3xx_nand_host *host; 531 496 struct mtd_info *mtd; ··· 539 506 info->buf_count = 0; 540 507 info->oob_size = 0; 541 508 info->use_ecc = 0; 509 + info->use_spare = 1; 510 + info->use_dma = (use_dma) ? 1 : 0; 542 511 info->is_ready = 0; 543 512 info->retcode = ERR_NONE; 544 513 if (info->cs != 0) ··· 555 520 case NAND_CMD_READOOB: 556 521 pxa3xx_set_datasize(info); 557 522 break; 523 + case NAND_CMD_PARAM: 524 + info->use_spare = 0; 525 + break; 558 526 case NAND_CMD_SEQIN: 559 527 exec_cmd = 0; 560 528 break; 561 529 default: 562 530 info->ndcb1 = 0; 563 531 info->ndcb2 = 0; 532 + info->ndcb3 = 0; 564 533 break; 565 534 } 566 535 ··· 574 535 switch (command) { 575 536 case NAND_CMD_READOOB: 576 537 case NAND_CMD_READ0: 577 - cmd = host->cmdset->read1; 578 - if (command == NAND_CMD_READOOB) 579 - info->buf_start = mtd->writesize + column; 580 - else 581 - info->buf_start = column; 538 + info->buf_start = column; 539 + info->ndcb0 |= NDCB0_CMD_TYPE(0) 540 + | addr_cycle 541 + | NAND_CMD_READ0; 582 542 583 - if (unlikely(host->page_size < PAGE_CHUNK_SIZE)) 584 - info->ndcb0 |= NDCB0_CMD_TYPE(0) 585 - | addr_cycle 586 - | (cmd & NDCB0_CMD1_MASK); 587 - else 588 - info->ndcb0 |= NDCB0_CMD_TYPE(0) 589 - | NDCB0_DBC 590 - | addr_cycle 591 - | cmd; 543 + if (command == NAND_CMD_READOOB) 544 + info->buf_start += mtd->writesize; 545 + 546 + /* Second command setting for large pages */ 547 + if (host->page_size >= PAGE_CHUNK_SIZE) 548 + info->ndcb0 |= NDCB0_DBC | (NAND_CMD_READSTART << 8); 592 549 593 550 case NAND_CMD_SEQIN: 594 551 /* small page addr setting */ ··· 615 580 break; 616 581 } 617 582 618 - cmd = host->cmdset->program; 619 583 info->ndcb0 |= NDCB0_CMD_TYPE(0x1) 620 584 | NDCB0_AUTO_RS 621 585 | NDCB0_ST_ROW_EN 622 586 | NDCB0_DBC 623 - | cmd 587 + | (NAND_CMD_PAGEPROG << 8) 588 + | NAND_CMD_SEQIN 624 589 | addr_cycle; 625 590 break; 626 591 592 + case NAND_CMD_PARAM: 593 + info->buf_count = 256; 594 + info->ndcb0 |= NDCB0_CMD_TYPE(0) 595 + | NDCB0_ADDR_CYC(1) 596 + | NDCB0_LEN_OVRD 597 + | command; 598 + info->ndcb1 = (column & 0xFF); 599 + info->ndcb3 = 256; 600 + info->data_size = 256; 601 + break; 602 + 627 603 case NAND_CMD_READID: 628 - cmd = host->cmdset->read_id; 629 604 info->buf_count = host->read_id_bytes; 630 605 info->ndcb0 |= NDCB0_CMD_TYPE(3) 631 606 | NDCB0_ADDR_CYC(1) 632 - | cmd; 607 + | command; 608 + info->ndcb1 = (column & 0xFF); 633 609 634 610 info->data_size = 8; 635 611 break; 636 612 case NAND_CMD_STATUS: 637 - cmd = host->cmdset->read_status; 638 613 info->buf_count = 1; 639 614 info->ndcb0 |= NDCB0_CMD_TYPE(4) 640 615 | NDCB0_ADDR_CYC(1) 641 - | cmd; 616 + | command; 642 617 643 618 info->data_size = 8; 644 619 break; 645 620 646 621 case NAND_CMD_ERASE1: 647 - cmd = host->cmdset->erase; 648 622 info->ndcb0 |= NDCB0_CMD_TYPE(2) 649 623 | NDCB0_AUTO_RS 650 624 | NDCB0_ADDR_CYC(3) 651 625 | NDCB0_DBC 652 - | cmd; 626 + | (NAND_CMD_ERASE2 << 8) 627 + | NAND_CMD_ERASE1; 653 628 info->ndcb1 = page_addr; 654 629 info->ndcb2 = 0; 655 630 656 631 break; 657 632 case NAND_CMD_RESET: 658 - cmd = host->cmdset->reset; 659 633 info->ndcb0 |= NDCB0_CMD_TYPE(5) 660 - | cmd; 634 + | command; 661 635 662 636 break; 663 637 ··· 696 652 * "byte" address into a "word" address appropriate 697 653 * for indexing a word-oriented device 698 654 */ 699 - if (host->reg_ndcr & NDCR_DWIDTH_M) 655 + if (info->reg_ndcr & NDCR_DWIDTH_M) 700 656 column /= 2; 701 657 702 658 /* ··· 706 662 */ 707 663 if (info->cs != host->cs) { 708 664 info->cs = host->cs; 709 - nand_writel(info, NDTR0CS0, host->ndtr0cs0); 710 - nand_writel(info, NDTR1CS0, host->ndtr1cs0); 665 + nand_writel(info, NDTR0CS0, info->ndtr0cs0); 666 + nand_writel(info, NDTR1CS0, info->ndtr1cs0); 711 667 } 712 668 713 669 info->state = STATE_PREPARED; ··· 847 803 const struct pxa3xx_nand_flash *f) 848 804 { 849 805 struct platform_device *pdev = info->pdev; 850 - struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; 806 + struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 851 807 struct pxa3xx_nand_host *host = info->host[info->cs]; 852 808 uint32_t ndcr = 0x0; /* enable all interrupts */ 853 809 ··· 862 818 } 863 819 864 820 /* calculate flash information */ 865 - host->cmdset = &default_cmdset; 866 821 host->page_size = f->page_size; 867 822 host->read_id_bytes = (f->page_size == 2048) ? 4 : 2; 868 823 ··· 883 840 ndcr |= NDCR_RD_ID_CNT(host->read_id_bytes); 884 841 ndcr |= NDCR_SPARE_EN; /* enable spare by default */ 885 842 886 - host->reg_ndcr = ndcr; 843 + info->reg_ndcr = ndcr; 887 844 888 845 pxa3xx_nand_set_timing(host, f->timing); 889 846 return 0; ··· 906 863 host->read_id_bytes = 2; 907 864 } 908 865 909 - host->reg_ndcr = ndcr & ~NDCR_INT_MASK; 910 - host->cmdset = &default_cmdset; 911 - 912 - host->ndtr0cs0 = nand_readl(info, NDTR0CS0); 913 - host->ndtr1cs0 = nand_readl(info, NDTR1CS0); 914 - 866 + info->reg_ndcr = ndcr & ~NDCR_INT_MASK; 867 + info->ndtr0cs0 = nand_readl(info, NDTR0CS0); 868 + info->ndtr1cs0 = nand_readl(info, NDTR1CS0); 915 869 return 0; 916 870 } 917 871 ··· 918 878 */ 919 879 #define MAX_BUFF_SIZE PAGE_SIZE 920 880 881 + #ifdef ARCH_HAS_DMA 921 882 static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) 922 883 { 923 884 struct platform_device *pdev = info->pdev; ··· 953 912 return 0; 954 913 } 955 914 915 + static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) 916 + { 917 + struct platform_device *pdev = info->pdev; 918 + if (use_dma) { 919 + pxa_free_dma(info->data_dma_ch); 920 + dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE, 921 + info->data_buff, info->data_buff_phys); 922 + } else { 923 + kfree(info->data_buff); 924 + } 925 + } 926 + #else 927 + static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) 928 + { 929 + info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL); 930 + if (info->data_buff == NULL) 931 + return -ENOMEM; 932 + return 0; 933 + } 934 + 935 + static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info) 936 + { 937 + kfree(info->data_buff); 938 + } 939 + #endif 940 + 956 941 static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info) 957 942 { 958 943 struct mtd_info *mtd; ··· 1001 934 struct pxa3xx_nand_host *host = mtd->priv; 1002 935 struct pxa3xx_nand_info *info = host->info_data; 1003 936 struct platform_device *pdev = info->pdev; 1004 - struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; 937 + struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 1005 938 struct nand_flash_dev pxa3xx_flash_ids[2], *def = NULL; 1006 939 const struct pxa3xx_nand_flash *f = NULL; 1007 940 struct nand_chip *chip = mtd->priv; ··· 1070 1003 chip->ecc.size = host->page_size; 1071 1004 chip->ecc.strength = 1; 1072 1005 1073 - if (host->reg_ndcr & NDCR_DWIDTH_M) 1006 + if (info->reg_ndcr & NDCR_DWIDTH_M) 1074 1007 chip->options |= NAND_BUSWIDTH_16; 1075 1008 1076 1009 if (nand_scan_ident(mtd, 1, def)) ··· 1086 1019 host->row_addr_cycles = 3; 1087 1020 else 1088 1021 host->row_addr_cycles = 2; 1089 - 1090 - mtd->name = mtd_names[0]; 1091 1022 return nand_scan_tail(mtd); 1092 1023 } 1093 1024 ··· 1099 1034 struct resource *r; 1100 1035 int ret, irq, cs; 1101 1036 1102 - pdata = pdev->dev.platform_data; 1103 - info = kzalloc(sizeof(*info) + (sizeof(*mtd) + 1104 - sizeof(*host)) * pdata->num_cs, GFP_KERNEL); 1105 - if (!info) { 1106 - dev_err(&pdev->dev, "failed to allocate memory\n"); 1037 + pdata = dev_get_platdata(&pdev->dev); 1038 + info = devm_kzalloc(&pdev->dev, sizeof(*info) + (sizeof(*mtd) + 1039 + sizeof(*host)) * pdata->num_cs, GFP_KERNEL); 1040 + if (!info) 1107 1041 return -ENOMEM; 1108 - } 1109 1042 1110 1043 info->pdev = pdev; 1111 1044 for (cs = 0; cs < pdata->num_cs; cs++) { ··· 1132 1069 1133 1070 spin_lock_init(&chip->controller->lock); 1134 1071 init_waitqueue_head(&chip->controller->wq); 1135 - info->clk = clk_get(&pdev->dev, NULL); 1072 + info->clk = devm_clk_get(&pdev->dev, NULL); 1136 1073 if (IS_ERR(info->clk)) { 1137 1074 dev_err(&pdev->dev, "failed to get nand clock\n"); 1138 - ret = PTR_ERR(info->clk); 1139 - goto fail_free_mtd; 1075 + return PTR_ERR(info->clk); 1140 1076 } 1141 - clk_enable(info->clk); 1077 + ret = clk_prepare_enable(info->clk); 1078 + if (ret < 0) 1079 + return ret; 1142 1080 1143 - /* 1144 - * This is a dirty hack to make this driver work from devicetree 1145 - * bindings. It can be removed once we have a prober DMA controller 1146 - * framework for DT. 1147 - */ 1148 - if (pdev->dev.of_node && cpu_is_pxa3xx()) { 1149 - info->drcmr_dat = 97; 1150 - info->drcmr_cmd = 99; 1151 - } else { 1152 - r = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1153 - if (r == NULL) { 1154 - dev_err(&pdev->dev, "no resource defined for data DMA\n"); 1155 - ret = -ENXIO; 1156 - goto fail_put_clk; 1157 - } 1158 - info->drcmr_dat = r->start; 1081 + if (use_dma) { 1082 + /* 1083 + * This is a dirty hack to make this driver work from 1084 + * devicetree bindings. It can be removed once we have 1085 + * a prober DMA controller framework for DT. 1086 + */ 1087 + if (pdev->dev.of_node && 1088 + of_machine_is_compatible("marvell,pxa3xx")) { 1089 + info->drcmr_dat = 97; 1090 + info->drcmr_cmd = 99; 1091 + } else { 1092 + r = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1093 + if (r == NULL) { 1094 + dev_err(&pdev->dev, 1095 + "no resource defined for data DMA\n"); 1096 + ret = -ENXIO; 1097 + goto fail_disable_clk; 1098 + } 1099 + info->drcmr_dat = r->start; 1159 1100 1160 - r = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1161 - if (r == NULL) { 1162 - dev_err(&pdev->dev, "no resource defined for command DMA\n"); 1163 - ret = -ENXIO; 1164 - goto fail_put_clk; 1101 + r = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1102 + if (r == NULL) { 1103 + dev_err(&pdev->dev, 1104 + "no resource defined for cmd DMA\n"); 1105 + ret = -ENXIO; 1106 + goto fail_disable_clk; 1107 + } 1108 + info->drcmr_cmd = r->start; 1165 1109 } 1166 - info->drcmr_cmd = r->start; 1167 1110 } 1168 1111 1169 1112 irq = platform_get_irq(pdev, 0); 1170 1113 if (irq < 0) { 1171 1114 dev_err(&pdev->dev, "no IRQ resource defined\n"); 1172 1115 ret = -ENXIO; 1173 - goto fail_put_clk; 1116 + goto fail_disable_clk; 1174 1117 } 1175 1118 1176 1119 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1177 - if (r == NULL) { 1178 - dev_err(&pdev->dev, "no IO memory resource defined\n"); 1179 - ret = -ENODEV; 1180 - goto fail_put_clk; 1181 - } 1182 - 1183 - r = request_mem_region(r->start, resource_size(r), pdev->name); 1184 - if (r == NULL) { 1185 - dev_err(&pdev->dev, "failed to request memory resource\n"); 1186 - ret = -EBUSY; 1187 - goto fail_put_clk; 1188 - } 1189 - 1190 - info->mmio_base = ioremap(r->start, resource_size(r)); 1191 - if (info->mmio_base == NULL) { 1192 - dev_err(&pdev->dev, "ioremap() failed\n"); 1193 - ret = -ENODEV; 1194 - goto fail_free_res; 1120 + info->mmio_base = devm_ioremap_resource(&pdev->dev, r); 1121 + if (IS_ERR(info->mmio_base)) { 1122 + ret = PTR_ERR(info->mmio_base); 1123 + goto fail_disable_clk; 1195 1124 } 1196 1125 info->mmio_phys = r->start; 1197 1126 1198 1127 ret = pxa3xx_nand_init_buff(info); 1199 1128 if (ret) 1200 - goto fail_free_io; 1129 + goto fail_disable_clk; 1201 1130 1202 1131 /* initialize all interrupts to be disabled */ 1203 1132 disable_int(info, NDSR_MASK); ··· 1207 1152 1208 1153 fail_free_buf: 1209 1154 free_irq(irq, info); 1210 - if (use_dma) { 1211 - pxa_free_dma(info->data_dma_ch); 1212 - dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE, 1213 - info->data_buff, info->data_buff_phys); 1214 - } else 1215 - kfree(info->data_buff); 1216 - fail_free_io: 1217 - iounmap(info->mmio_base); 1218 - fail_free_res: 1219 - release_mem_region(r->start, resource_size(r)); 1220 - fail_put_clk: 1221 - clk_disable(info->clk); 1222 - clk_put(info->clk); 1223 - fail_free_mtd: 1224 - kfree(info); 1155 + pxa3xx_nand_free_buff(info); 1156 + fail_disable_clk: 1157 + clk_disable_unprepare(info->clk); 1225 1158 return ret; 1226 1159 } 1227 1160 ··· 1217 1174 { 1218 1175 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); 1219 1176 struct pxa3xx_nand_platform_data *pdata; 1220 - struct resource *r; 1221 1177 int irq, cs; 1222 1178 1223 1179 if (!info) 1224 1180 return 0; 1225 1181 1226 - pdata = pdev->dev.platform_data; 1227 - platform_set_drvdata(pdev, NULL); 1182 + pdata = dev_get_platdata(&pdev->dev); 1228 1183 1229 1184 irq = platform_get_irq(pdev, 0); 1230 1185 if (irq >= 0) 1231 1186 free_irq(irq, info); 1232 - if (use_dma) { 1233 - pxa_free_dma(info->data_dma_ch); 1234 - dma_free_writecombine(&pdev->dev, MAX_BUFF_SIZE, 1235 - info->data_buff, info->data_buff_phys); 1236 - } else 1237 - kfree(info->data_buff); 1187 + pxa3xx_nand_free_buff(info); 1238 1188 1239 - iounmap(info->mmio_base); 1240 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1241 - release_mem_region(r->start, resource_size(r)); 1242 - 1243 - clk_disable(info->clk); 1244 - clk_put(info->clk); 1189 + clk_disable_unprepare(info->clk); 1245 1190 1246 1191 for (cs = 0; cs < pdata->num_cs; cs++) 1247 1192 nand_release(info->host[cs]->mtd); 1248 - kfree(info); 1249 1193 return 0; 1250 1194 } 1251 1195 1252 1196 #ifdef CONFIG_OF 1253 1197 static struct of_device_id pxa3xx_nand_dt_ids[] = { 1254 - { .compatible = "marvell,pxa3xx-nand" }, 1198 + { 1199 + .compatible = "marvell,pxa3xx-nand", 1200 + .data = (void *)PXA3XX_NAND_VARIANT_PXA, 1201 + }, 1202 + { 1203 + .compatible = "marvell,armada370-nand", 1204 + .data = (void *)PXA3XX_NAND_VARIANT_ARMADA370, 1205 + }, 1255 1206 {} 1256 1207 }; 1257 - MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids); 1208 + MODULE_DEVICE_TABLE(of, pxa3xx_nand_dt_ids); 1209 + 1210 + static enum pxa3xx_nand_variant 1211 + pxa3xx_nand_get_variant(struct platform_device *pdev) 1212 + { 1213 + const struct of_device_id *of_id = 1214 + of_match_device(pxa3xx_nand_dt_ids, &pdev->dev); 1215 + if (!of_id) 1216 + return PXA3XX_NAND_VARIANT_PXA; 1217 + return (enum pxa3xx_nand_variant)of_id->data; 1218 + } 1258 1219 1259 1220 static int pxa3xx_nand_probe_dt(struct platform_device *pdev) 1260 1221 { ··· 1298 1251 struct pxa3xx_nand_info *info; 1299 1252 int ret, cs, probe_success; 1300 1253 1254 + #ifndef ARCH_HAS_DMA 1255 + if (use_dma) { 1256 + use_dma = 0; 1257 + dev_warn(&pdev->dev, 1258 + "This platform can't do DMA on this device\n"); 1259 + } 1260 + #endif 1301 1261 ret = pxa3xx_nand_probe_dt(pdev); 1302 1262 if (ret) 1303 1263 return ret; 1304 1264 1305 - pdata = pdev->dev.platform_data; 1265 + pdata = dev_get_platdata(&pdev->dev); 1306 1266 if (!pdata) { 1307 1267 dev_err(&pdev->dev, "no platform data defined\n"); 1308 1268 return -ENODEV; ··· 1322 1268 } 1323 1269 1324 1270 info = platform_get_drvdata(pdev); 1271 + info->variant = pxa3xx_nand_get_variant(pdev); 1325 1272 probe_success = 0; 1326 1273 for (cs = 0; cs < pdata->num_cs; cs++) { 1274 + struct mtd_info *mtd = info->host[cs]->mtd; 1275 + 1276 + mtd->name = pdev->name; 1327 1277 info->cs = cs; 1328 - ret = pxa3xx_nand_scan(info->host[cs]->mtd); 1278 + ret = pxa3xx_nand_scan(mtd); 1329 1279 if (ret) { 1330 1280 dev_warn(&pdev->dev, "failed to scan nand at cs %d\n", 1331 1281 cs); ··· 1337 1279 } 1338 1280 1339 1281 ppdata.of_node = pdev->dev.of_node; 1340 - ret = mtd_device_parse_register(info->host[cs]->mtd, NULL, 1282 + ret = mtd_device_parse_register(mtd, NULL, 1341 1283 &ppdata, pdata->parts[cs], 1342 1284 pdata->nr_parts[cs]); 1343 1285 if (!ret) ··· 1360 1302 struct mtd_info *mtd; 1361 1303 int cs; 1362 1304 1363 - pdata = pdev->dev.platform_data; 1305 + pdata = dev_get_platdata(&pdev->dev); 1364 1306 if (info->state) { 1365 1307 dev_err(&pdev->dev, "driver busy, state = %d\n", info->state); 1366 1308 return -EAGAIN; ··· 1381 1323 struct mtd_info *mtd; 1382 1324 int cs; 1383 1325 1384 - pdata = pdev->dev.platform_data; 1326 + pdata = dev_get_platdata(&pdev->dev); 1385 1327 /* We don't want to handle interrupt without calling mtd routine */ 1386 1328 disable_int(info, NDCR_INT_MASK); 1387 1329
+23 -26
drivers/mtd/nand/r852.c
··· 229 229 /* 230 230 * Program data lines of the nand chip to send data to it 231 231 */ 232 - void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 232 + static void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 233 233 { 234 234 struct r852_device *dev = r852_get_dev(mtd); 235 235 uint32_t reg; ··· 261 261 /* 262 262 * Read data lines of the nand chip to retrieve data 263 263 */ 264 - void r852_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 264 + static void r852_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 265 265 { 266 266 struct r852_device *dev = r852_get_dev(mtd); 267 267 uint32_t reg; ··· 312 312 /* 313 313 * Control several chip lines & send commands 314 314 */ 315 - void r852_cmdctl(struct mtd_info *mtd, int dat, unsigned int ctrl) 315 + static void r852_cmdctl(struct mtd_info *mtd, int dat, unsigned int ctrl) 316 316 { 317 317 struct r852_device *dev = r852_get_dev(mtd); 318 318 ··· 357 357 * Wait till card is ready. 358 358 * based on nand_wait, but returns errors on DMA error 359 359 */ 360 - int r852_wait(struct mtd_info *mtd, struct nand_chip *chip) 360 + static int r852_wait(struct mtd_info *mtd, struct nand_chip *chip) 361 361 { 362 362 struct r852_device *dev = chip->priv; 363 363 ··· 386 386 * Check if card is ready 387 387 */ 388 388 389 - int r852_ready(struct mtd_info *mtd) 389 + static int r852_ready(struct mtd_info *mtd) 390 390 { 391 391 struct r852_device *dev = r852_get_dev(mtd); 392 392 return !(r852_read_reg(dev, R852_CARD_STA) & R852_CARD_STA_BUSY); ··· 397 397 * Set ECC engine mode 398 398 */ 399 399 400 - void r852_ecc_hwctl(struct mtd_info *mtd, int mode) 400 + static void r852_ecc_hwctl(struct mtd_info *mtd, int mode) 401 401 { 402 402 struct r852_device *dev = r852_get_dev(mtd); 403 403 ··· 429 429 * Calculate ECC, only used for writes 430 430 */ 431 431 432 - int r852_ecc_calculate(struct mtd_info *mtd, const uint8_t *dat, 432 + static int r852_ecc_calculate(struct mtd_info *mtd, const uint8_t *dat, 433 433 uint8_t *ecc_code) 434 434 { 435 435 struct r852_device *dev = r852_get_dev(mtd); ··· 461 461 * Correct the data using ECC, hw did almost everything for us 462 462 */ 463 463 464 - int r852_ecc_correct(struct mtd_info *mtd, uint8_t *dat, 464 + static int r852_ecc_correct(struct mtd_info *mtd, uint8_t *dat, 465 465 uint8_t *read_ecc, uint8_t *calc_ecc) 466 466 { 467 467 uint16_t ecc_reg; ··· 529 529 * Start the nand engine 530 530 */ 531 531 532 - void r852_engine_enable(struct r852_device *dev) 532 + static void r852_engine_enable(struct r852_device *dev) 533 533 { 534 534 if (r852_read_reg_dword(dev, R852_HW) & R852_HW_UNKNOWN) { 535 535 r852_write_reg(dev, R852_CTL, R852_CTL_RESET | R852_CTL_ON); ··· 547 547 * Stop the nand engine 548 548 */ 549 549 550 - void r852_engine_disable(struct r852_device *dev) 550 + static void r852_engine_disable(struct r852_device *dev) 551 551 { 552 552 r852_write_reg_dword(dev, R852_HW, 0); 553 553 r852_write_reg(dev, R852_CTL, R852_CTL_RESET); ··· 557 557 * Test if card is present 558 558 */ 559 559 560 - void r852_card_update_present(struct r852_device *dev) 560 + static void r852_card_update_present(struct r852_device *dev) 561 561 { 562 562 unsigned long flags; 563 563 uint8_t reg; ··· 572 572 * Update card detection IRQ state according to current card state 573 573 * which is read in r852_card_update_present 574 574 */ 575 - void r852_update_card_detect(struct r852_device *dev) 575 + static void r852_update_card_detect(struct r852_device *dev) 576 576 { 577 577 int card_detect_reg = r852_read_reg(dev, R852_CARD_IRQ_ENABLE); 578 578 dev->card_unstable = 0; ··· 586 586 r852_write_reg(dev, R852_CARD_IRQ_ENABLE, card_detect_reg); 587 587 } 588 588 589 - ssize_t r852_media_type_show(struct device *sys_dev, 590 - struct device_attribute *attr, char *buf) 589 + static ssize_t r852_media_type_show(struct device *sys_dev, 590 + struct device_attribute *attr, char *buf) 591 591 { 592 592 struct mtd_info *mtd = container_of(sys_dev, struct mtd_info, dev); 593 593 struct r852_device *dev = r852_get_dev(mtd); ··· 597 597 return strlen(data); 598 598 } 599 599 600 - DEVICE_ATTR(media_type, S_IRUGO, r852_media_type_show, NULL); 600 + static DEVICE_ATTR(media_type, S_IRUGO, r852_media_type_show, NULL); 601 601 602 602 603 603 /* Detect properties of card in slot */ 604 - void r852_update_media_status(struct r852_device *dev) 604 + static void r852_update_media_status(struct r852_device *dev) 605 605 { 606 606 uint8_t reg; 607 607 unsigned long flags; ··· 630 630 * Register the nand device 631 631 * Called when the card is detected 632 632 */ 633 - int r852_register_nand_device(struct r852_device *dev) 633 + static int r852_register_nand_device(struct r852_device *dev) 634 634 { 635 635 dev->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL); 636 636 ··· 668 668 * Unregister the card 669 669 */ 670 670 671 - void r852_unregister_nand_device(struct r852_device *dev) 671 + static void r852_unregister_nand_device(struct r852_device *dev) 672 672 { 673 673 if (!dev->card_registred) 674 674 return; ··· 682 682 } 683 683 684 684 /* Card state updater */ 685 - void r852_card_detect_work(struct work_struct *work) 685 + static void r852_card_detect_work(struct work_struct *work) 686 686 { 687 687 struct r852_device *dev = 688 688 container_of(work, struct r852_device, card_detect_work.work); ··· 821 821 return ret; 822 822 } 823 823 824 - int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) 824 + static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) 825 825 { 826 826 int error; 827 827 struct nand_chip *chip; ··· 961 961 return error; 962 962 } 963 963 964 - void r852_remove(struct pci_dev *pci_dev) 964 + static void r852_remove(struct pci_dev *pci_dev) 965 965 { 966 966 struct r852_device *dev = pci_get_drvdata(pci_dev); 967 967 ··· 992 992 pci_disable_device(pci_dev); 993 993 } 994 994 995 - void r852_shutdown(struct pci_dev *pci_dev) 995 + static void r852_shutdown(struct pci_dev *pci_dev) 996 996 { 997 997 struct r852_device *dev = pci_get_drvdata(pci_dev); 998 998 ··· 1002 1002 pci_disable_device(pci_dev); 1003 1003 } 1004 1004 1005 - #ifdef CONFIG_PM 1005 + #ifdef CONFIG_PM_SLEEP 1006 1006 static int r852_suspend(struct device *device) 1007 1007 { 1008 1008 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device)); ··· 1055 1055 r852_update_card_detect(dev); 1056 1056 return 0; 1057 1057 } 1058 - #else 1059 - #define r852_suspend NULL 1060 - #define r852_resume NULL 1061 1058 #endif 1062 1059 1063 1060 static const struct pci_device_id r852_pci_id_tbl[] = {
+1 -3
drivers/mtd/nand/s3c2410.c
··· 150 150 151 151 static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev) 152 152 { 153 - return dev->dev.platform_data; 153 + return dev_get_platdata(&dev->dev); 154 154 } 155 155 156 156 static inline int allow_clk_suspend(struct s3c2410_nand_info *info) ··· 696 696 static int s3c24xx_nand_remove(struct platform_device *pdev) 697 697 { 698 698 struct s3c2410_nand_info *info = to_nand_info(pdev); 699 - 700 - platform_set_drvdata(pdev, NULL); 701 699 702 700 if (info == NULL) 703 701 return 0;
+2 -2
drivers/mtd/nand/sh_flctl.c
··· 137 137 dma_cap_mask_t mask; 138 138 struct dma_slave_config cfg; 139 139 struct platform_device *pdev = flctl->pdev; 140 - struct sh_flctl_platform_data *pdata = pdev->dev.platform_data; 140 + struct sh_flctl_platform_data *pdata = dev_get_platdata(&pdev->dev); 141 141 int ret; 142 142 143 143 if (!pdata) ··· 1131 1131 if (pdev->dev.of_node) 1132 1132 pdata = flctl_parse_dt(&pdev->dev); 1133 1133 else 1134 - pdata = pdev->dev.platform_data; 1134 + pdata = dev_get_platdata(&pdev->dev); 1135 1135 1136 1136 if (!pdata) { 1137 1137 dev_err(&pdev->dev, "no setup data defined\n");
+1 -4
drivers/mtd/nand/sharpsl.c
··· 112 112 struct resource *r; 113 113 int err = 0; 114 114 struct sharpsl_nand *sharpsl; 115 - struct sharpsl_nand_platform_data *data = pdev->dev.platform_data; 115 + struct sharpsl_nand_platform_data *data = dev_get_platdata(&pdev->dev); 116 116 117 117 if (!data) { 118 118 dev_err(&pdev->dev, "no platform data!\n"); ··· 194 194 nand_release(&sharpsl->mtd); 195 195 196 196 err_scan: 197 - platform_set_drvdata(pdev, NULL); 198 197 iounmap(sharpsl->io); 199 198 err_ioremap: 200 199 err_get_res: ··· 210 211 211 212 /* Release resources, unregister device */ 212 213 nand_release(&sharpsl->mtd); 213 - 214 - platform_set_drvdata(pdev, NULL); 215 214 216 215 iounmap(sharpsl->io); 217 216
+4 -5
drivers/mtd/nand/sm_common.c
··· 42 42 { 43 43 struct mtd_oob_ops ops; 44 44 struct sm_oob oob; 45 - int ret, error = 0; 45 + int ret; 46 46 47 47 memset(&oob, -1, SM_OOB_SIZE); 48 48 oob.block_status = 0x0F; ··· 61 61 printk(KERN_NOTICE 62 62 "sm_common: can't mark sector at %i as bad\n", 63 63 (int)ofs); 64 - error = -EIO; 65 - } else 66 - mtd->ecc_stats.badblocks++; 64 + return -EIO; 65 + } 67 66 68 - return error; 67 + return 0; 69 68 } 70 69 71 70 static struct nand_flash_dev nand_smartmedia_flash_ids[] = {
+1 -1
drivers/mtd/nand/tmio_nand.c
··· 357 357 358 358 static int tmio_probe(struct platform_device *dev) 359 359 { 360 - struct tmio_nand_data *data = dev->dev.platform_data; 360 + struct tmio_nand_data *data = dev_get_platdata(&dev->dev); 361 361 struct resource *fcr = platform_get_resource(dev, 362 362 IORESOURCE_MEM, 0); 363 363 struct resource *ccr = platform_get_resource(dev,
+5 -8
drivers/mtd/nand/txx9ndfmc.c
··· 87 87 static void __iomem *ndregaddr(struct platform_device *dev, unsigned int reg) 88 88 { 89 89 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev); 90 - struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 90 + struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev); 91 91 92 92 return drvdata->base + (reg << plat->shift); 93 93 } ··· 138 138 struct nand_chip *chip = mtd->priv; 139 139 struct txx9ndfmc_priv *txx9_priv = chip->priv; 140 140 struct platform_device *dev = txx9_priv->dev; 141 - struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 141 + struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev); 142 142 143 143 if (ctrl & NAND_CTRL_CHANGE) { 144 144 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR); ··· 225 225 226 226 static void txx9ndfmc_initialize(struct platform_device *dev) 227 227 { 228 - struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 228 + struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev); 229 229 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev); 230 230 int tmout = 100; 231 231 ··· 274 274 275 275 static int __init txx9ndfmc_probe(struct platform_device *dev) 276 276 { 277 - struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 277 + struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev); 278 278 int hold, spw; 279 279 int i; 280 280 struct txx9ndfmc_drvdata *drvdata; 281 281 unsigned long gbusclk = plat->gbus_clock; 282 282 struct resource *res; 283 283 284 - res = platform_get_resource(dev, IORESOURCE_MEM, 0); 285 - if (!res) 286 - return -ENODEV; 287 284 drvdata = devm_kzalloc(&dev->dev, sizeof(*drvdata), GFP_KERNEL); 288 285 if (!drvdata) 289 286 return -ENOMEM; 287 + res = platform_get_resource(dev, IORESOURCE_MEM, 0); 290 288 drvdata->base = devm_ioremap_resource(&dev->dev, res); 291 289 if (IS_ERR(drvdata->base)) 292 290 return PTR_ERR(drvdata->base); ··· 385 387 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev); 386 388 int i; 387 389 388 - platform_set_drvdata(dev, NULL); 389 390 if (!drvdata) 390 391 return 0; 391 392 for (i = 0; i < MAX_TXX9NDFMC_DEV; i++) {
+14 -4
drivers/mtd/ofpart.c
··· 20 20 #include <linux/slab.h> 21 21 #include <linux/mtd/partitions.h> 22 22 23 + static bool node_has_compatible(struct device_node *pp) 24 + { 25 + return of_get_property(pp, "compatible", NULL); 26 + } 27 + 23 28 static int parse_ofpart_partitions(struct mtd_info *master, 24 29 struct mtd_partition **pparts, 25 30 struct mtd_part_parser_data *data) ··· 43 38 return 0; 44 39 45 40 /* First count the subnodes */ 46 - pp = NULL; 47 41 nr_parts = 0; 48 - while ((pp = of_get_next_child(node, pp))) 42 + for_each_child_of_node(node, pp) { 43 + if (node_has_compatible(pp)) 44 + continue; 45 + 49 46 nr_parts++; 47 + } 50 48 51 49 if (nr_parts == 0) 52 50 return 0; ··· 58 50 if (!*pparts) 59 51 return -ENOMEM; 60 52 61 - pp = NULL; 62 53 i = 0; 63 - while ((pp = of_get_next_child(node, pp))) { 54 + for_each_child_of_node(node, pp) { 64 55 const __be32 *reg; 65 56 int len; 66 57 int a_cells, s_cells; 58 + 59 + if (node_has_compatible(pp)) 60 + continue; 67 61 68 62 reg = of_get_property(pp, "reg", &len); 69 63 if (!reg) {
+1 -3
drivers/mtd/onenand/generic.c
··· 38 38 static int generic_onenand_probe(struct platform_device *pdev) 39 39 { 40 40 struct onenand_info *info; 41 - struct onenand_platform_data *pdata = pdev->dev.platform_data; 41 + struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev); 42 42 struct resource *res = pdev->resource; 43 43 unsigned long size = resource_size(res); 44 44 int err; ··· 93 93 struct onenand_info *info = platform_get_drvdata(pdev); 94 94 struct resource *res = pdev->resource; 95 95 unsigned long size = resource_size(res); 96 - 97 - platform_set_drvdata(pdev, NULL); 98 96 99 97 if (info) { 100 98 onenand_release(&info->mtd);
+1 -2
drivers/mtd/onenand/omap2.c
··· 639 639 struct resource *res; 640 640 struct mtd_part_parser_data ppdata = {}; 641 641 642 - pdata = pdev->dev.platform_data; 642 + pdata = dev_get_platdata(&pdev->dev); 643 643 if (pdata == NULL) { 644 644 dev_err(&pdev->dev, "platform data missing\n"); 645 645 return -ENODEV; ··· 810 810 if (c->dma_channel != -1) 811 811 omap_free_dma(c->dma_channel); 812 812 omap2_onenand_shutdown(pdev); 813 - platform_set_drvdata(pdev, NULL); 814 813 if (c->gpio_irq) { 815 814 free_irq(gpio_to_irq(c->gpio_irq), c); 816 815 gpio_free(c->gpio_irq);
-1
drivers/mtd/onenand/onenand_bbt.c
··· 133 133 { 134 134 struct onenand_chip *this = mtd->priv; 135 135 136 - bd->options &= ~NAND_BBT_SCANEMPTY; 137 136 return create_bbt(mtd, this->page_buf, bd, -1); 138 137 } 139 138
+1 -2
drivers/mtd/onenand/samsung.c
··· 867 867 struct resource *r; 868 868 int size, err; 869 869 870 - pdata = pdev->dev.platform_data; 870 + pdata = dev_get_platdata(&pdev->dev); 871 871 /* No need to check pdata. the platform data is optional */ 872 872 873 873 size = sizeof(struct mtd_info) + sizeof(struct onenand_chip); ··· 1073 1073 release_mem_region(onenand->base_res->start, 1074 1074 resource_size(onenand->base_res)); 1075 1075 1076 - platform_set_drvdata(pdev, NULL); 1077 1076 kfree(onenand->oob_buf); 1078 1077 kfree(onenand->page_buf); 1079 1078 kfree(onenand);
+13 -13
drivers/mtd/sm_ftl.c
··· 22 22 23 23 24 24 25 - struct workqueue_struct *cache_flush_workqueue; 25 + static struct workqueue_struct *cache_flush_workqueue; 26 26 27 27 static int cache_timeout = 1000; 28 28 module_param(cache_timeout, int, S_IRUGO); ··· 41 41 int len; 42 42 }; 43 43 44 - ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr, 44 + static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr, 45 45 char *buf) 46 46 { 47 47 struct sm_sysfs_attribute *sm_attr = ··· 54 54 55 55 #define NUM_ATTRIBUTES 1 56 56 #define SM_CIS_VENDOR_OFFSET 0x59 57 - struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl) 57 + static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl) 58 58 { 59 59 struct attribute_group *attr_group; 60 60 struct attribute **attributes; ··· 107 107 return NULL; 108 108 } 109 109 110 - void sm_delete_sysfs_attributes(struct sm_ftl *ftl) 110 + static void sm_delete_sysfs_attributes(struct sm_ftl *ftl) 111 111 { 112 112 struct attribute **attributes = ftl->disk_attributes->attrs; 113 113 int i; ··· 571 571 }; 572 572 /* Find out media parameters. 573 573 * This ideally has to be based on nand id, but for now device size is enough */ 574 - int sm_get_media_info(struct sm_ftl *ftl, struct mtd_info *mtd) 574 + static int sm_get_media_info(struct sm_ftl *ftl, struct mtd_info *mtd) 575 575 { 576 576 int i; 577 577 int size_in_megs = mtd->size / (1024 * 1024); ··· 878 878 } 879 879 880 880 /* Get and automatically initialize an FTL mapping for one zone */ 881 - struct ftl_zone *sm_get_zone(struct sm_ftl *ftl, int zone_num) 881 + static struct ftl_zone *sm_get_zone(struct sm_ftl *ftl, int zone_num) 882 882 { 883 883 struct ftl_zone *zone; 884 884 int error; ··· 899 899 /* ----------------- cache handling ------------------------------------------*/ 900 900 901 901 /* Initialize the one block cache */ 902 - void sm_cache_init(struct sm_ftl *ftl) 902 + static void sm_cache_init(struct sm_ftl *ftl) 903 903 { 904 904 ftl->cache_data_invalid_bitmap = 0xFFFFFFFF; 905 905 ftl->cache_clean = 1; ··· 909 909 } 910 910 911 911 /* Put sector in one block cache */ 912 - void sm_cache_put(struct sm_ftl *ftl, char *buffer, int boffset) 912 + static void sm_cache_put(struct sm_ftl *ftl, char *buffer, int boffset) 913 913 { 914 914 memcpy(ftl->cache_data + boffset, buffer, SM_SECTOR_SIZE); 915 915 clear_bit(boffset / SM_SECTOR_SIZE, &ftl->cache_data_invalid_bitmap); ··· 917 917 } 918 918 919 919 /* Read a sector from the cache */ 920 - int sm_cache_get(struct sm_ftl *ftl, char *buffer, int boffset) 920 + static int sm_cache_get(struct sm_ftl *ftl, char *buffer, int boffset) 921 921 { 922 922 if (test_bit(boffset / SM_SECTOR_SIZE, 923 923 &ftl->cache_data_invalid_bitmap)) ··· 928 928 } 929 929 930 930 /* Write the cache to hardware */ 931 - int sm_cache_flush(struct sm_ftl *ftl) 931 + static int sm_cache_flush(struct sm_ftl *ftl) 932 932 { 933 933 struct ftl_zone *zone; 934 934 ··· 1274 1274 static __init int sm_module_init(void) 1275 1275 { 1276 1276 int error = 0; 1277 - cache_flush_workqueue = create_freezable_workqueue("smflush"); 1278 1277 1279 - if (IS_ERR(cache_flush_workqueue)) 1280 - return PTR_ERR(cache_flush_workqueue); 1278 + cache_flush_workqueue = create_freezable_workqueue("smflush"); 1279 + if (!cache_flush_workqueue) 1280 + return -ENOMEM; 1281 1281 1282 1282 error = register_mtd_blktrans(&sm_ftl_ops); 1283 1283 if (error)
+9
drivers/mtd/tests/Makefile
··· 7 7 obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o 8 8 obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o 9 9 obj-$(CONFIG_MTD_TESTS) += mtd_nandbiterrs.o 10 + 11 + mtd_oobtest-objs := oobtest.o mtd_test.o 12 + mtd_pagetest-objs := pagetest.o mtd_test.o 13 + mtd_readtest-objs := readtest.o mtd_test.o 14 + mtd_speedtest-objs := speedtest.o mtd_test.o 15 + mtd_stresstest-objs := stresstest.o mtd_test.o 16 + mtd_subpagetest-objs := subpagetest.o mtd_test.o 17 + mtd_torturetest-objs := torturetest.o mtd_test.o 18 + mtd_nandbiterrs-objs := nandbiterrs.o mtd_test.o
+4 -37
drivers/mtd/tests/mtd_nandbiterrs.c drivers/mtd/tests/nandbiterrs.c
··· 49 49 #include <linux/err.h> 50 50 #include <linux/mtd/nand.h> 51 51 #include <linux/slab.h> 52 + #include "mtd_test.h" 52 53 53 54 static int dev; 54 55 module_param(dev, int, S_IRUGO); ··· 99 98 return c; 100 99 } 101 100 102 - static int erase_block(void) 103 - { 104 - int err; 105 - struct erase_info ei; 106 - loff_t addr = eraseblock * mtd->erasesize; 107 - 108 - pr_info("erase_block\n"); 109 - 110 - memset(&ei, 0, sizeof(struct erase_info)); 111 - ei.mtd = mtd; 112 - ei.addr = addr; 113 - ei.len = mtd->erasesize; 114 - 115 - err = mtd_erase(mtd, &ei); 116 - if (err || ei.state == MTD_ERASE_FAILED) { 117 - pr_err("error %d while erasing\n", err); 118 - if (!err) 119 - err = -EIO; 120 - return err; 121 - } 122 - 123 - return 0; 124 - } 125 - 126 101 /* Writes wbuffer to page */ 127 102 static int write_page(int log) 128 103 { 129 - int err = 0; 130 - size_t written; 131 - 132 104 if (log) 133 105 pr_info("write_page\n"); 134 106 135 - err = mtd_write(mtd, offset, mtd->writesize, &written, wbuffer); 136 - if (err || written != mtd->writesize) { 137 - pr_err("error: write failed at %#llx\n", (long long)offset); 138 - if (!err) 139 - err = -EIO; 140 - } 141 - 142 - return err; 107 + return mtdtest_write(mtd, offset, mtd->writesize, wbuffer); 143 108 } 144 109 145 110 /* Re-writes the data area while leaving the OOB alone. */ ··· 382 415 goto exit_rbuffer; 383 416 } 384 417 385 - err = erase_block(); 418 + err = mtdtest_erase_eraseblock(mtd, eraseblock); 386 419 if (err) 387 420 goto exit_error; 388 421 ··· 395 428 goto exit_error; 396 429 397 430 /* We leave the block un-erased in case of test failure. */ 398 - err = erase_block(); 431 + err = mtdtest_erase_eraseblock(mtd, eraseblock); 399 432 if (err) 400 433 goto exit_error; 401 434
+14 -88
drivers/mtd/tests/mtd_oobtest.c drivers/mtd/tests/oobtest.c
··· 31 31 #include <linux/sched.h> 32 32 #include <linux/random.h> 33 33 34 + #include "mtd_test.h" 35 + 34 36 static int dev = -EINVAL; 35 37 module_param(dev, int, S_IRUGO); 36 38 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 50 48 static int use_len_max; 51 49 static int vary_offset; 52 50 static struct rnd_state rnd_state; 53 - 54 - static int erase_eraseblock(int ebnum) 55 - { 56 - int err; 57 - struct erase_info ei; 58 - loff_t addr = ebnum * mtd->erasesize; 59 - 60 - memset(&ei, 0, sizeof(struct erase_info)); 61 - ei.mtd = mtd; 62 - ei.addr = addr; 63 - ei.len = mtd->erasesize; 64 - 65 - err = mtd_erase(mtd, &ei); 66 - if (err) { 67 - pr_err("error %d while erasing EB %d\n", err, ebnum); 68 - return err; 69 - } 70 - 71 - if (ei.state == MTD_ERASE_FAILED) { 72 - pr_err("some erase error occurred at EB %d\n", ebnum); 73 - return -EIO; 74 - } 75 - 76 - return 0; 77 - } 78 - 79 - static int erase_whole_device(void) 80 - { 81 - int err; 82 - unsigned int i; 83 - 84 - pr_info("erasing whole device\n"); 85 - for (i = 0; i < ebcnt; ++i) { 86 - if (bbt[i]) 87 - continue; 88 - err = erase_eraseblock(i); 89 - if (err) 90 - return err; 91 - cond_resched(); 92 - } 93 - pr_info("erased %u eraseblocks\n", i); 94 - return 0; 95 - } 96 51 97 52 static void do_vary_offset(void) 98 53 { ··· 263 304 return 0; 264 305 } 265 306 266 - static int is_block_bad(int ebnum) 267 - { 268 - int ret; 269 - loff_t addr = ebnum * mtd->erasesize; 270 - 271 - ret = mtd_block_isbad(mtd, addr); 272 - if (ret) 273 - pr_info("block %d is bad\n", ebnum); 274 - return ret; 275 - } 276 - 277 - static int scan_for_bad_eraseblocks(void) 278 - { 279 - int i, bad = 0; 280 - 281 - bbt = kmalloc(ebcnt, GFP_KERNEL); 282 - if (!bbt) { 283 - pr_err("error: cannot allocate memory\n"); 284 - return -ENOMEM; 285 - } 286 - 287 - pr_info("scanning for bad eraseblocks\n"); 288 - for (i = 0; i < ebcnt; ++i) { 289 - bbt[i] = is_block_bad(i) ? 1 : 0; 290 - if (bbt[i]) 291 - bad += 1; 292 - cond_resched(); 293 - } 294 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 295 - return 0; 296 - } 297 - 298 307 static int __init mtd_oobtest_init(void) 299 308 { 300 309 int err = 0; ··· 307 380 308 381 err = -ENOMEM; 309 382 readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); 310 - if (!readbuf) { 311 - pr_err("error: cannot allocate memory\n"); 383 + if (!readbuf) 312 384 goto out; 313 - } 314 385 writebuf = kmalloc(mtd->erasesize, GFP_KERNEL); 315 - if (!writebuf) { 316 - pr_err("error: cannot allocate memory\n"); 386 + if (!writebuf) 317 387 goto out; 318 - } 388 + bbt = kzalloc(ebcnt, GFP_KERNEL); 389 + if (!bbt) 390 + goto out; 319 391 320 - err = scan_for_bad_eraseblocks(); 392 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 321 393 if (err) 322 394 goto out; 323 395 ··· 328 402 /* First test: write all OOB, read it back and verify */ 329 403 pr_info("test 1 of 5\n"); 330 404 331 - err = erase_whole_device(); 405 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 332 406 if (err) 333 407 goto out; 334 408 ··· 348 422 */ 349 423 pr_info("test 2 of 5\n"); 350 424 351 - err = erase_whole_device(); 425 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 352 426 if (err) 353 427 goto out; 354 428 ··· 378 452 */ 379 453 pr_info("test 3 of 5\n"); 380 454 381 - err = erase_whole_device(); 455 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 382 456 if (err) 383 457 goto out; 384 458 ··· 411 485 /* Fourth test: try to write off end of device */ 412 486 pr_info("test 4 of 5\n"); 413 487 414 - err = erase_whole_device(); 488 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 415 489 if (err) 416 490 goto out; 417 491 ··· 503 577 errcnt += 1; 504 578 } 505 579 506 - err = erase_eraseblock(ebcnt - 1); 580 + err = mtdtest_erase_eraseblock(mtd, ebcnt - 1); 507 581 if (err) 508 582 goto out; 509 583 ··· 552 626 pr_info("test 5 of 5\n"); 553 627 554 628 /* Erase all eraseblocks */ 555 - err = erase_whole_device(); 629 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 556 630 if (err) 557 631 goto out; 558 632
+60 -211
drivers/mtd/tests/mtd_pagetest.c drivers/mtd/tests/pagetest.c
··· 31 31 #include <linux/sched.h> 32 32 #include <linux/random.h> 33 33 34 + #include "mtd_test.h" 35 + 34 36 static int dev = -EINVAL; 35 37 module_param(dev, int, S_IRUGO); 36 38 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 50 48 static int errcnt; 51 49 static struct rnd_state rnd_state; 52 50 53 - static int erase_eraseblock(int ebnum) 54 - { 55 - int err; 56 - struct erase_info ei; 57 - loff_t addr = ebnum * mtd->erasesize; 58 - 59 - memset(&ei, 0, sizeof(struct erase_info)); 60 - ei.mtd = mtd; 61 - ei.addr = addr; 62 - ei.len = mtd->erasesize; 63 - 64 - err = mtd_erase(mtd, &ei); 65 - if (err) { 66 - pr_err("error %d while erasing EB %d\n", err, ebnum); 67 - return err; 68 - } 69 - 70 - if (ei.state == MTD_ERASE_FAILED) { 71 - pr_err("some erase error occurred at EB %d\n", 72 - ebnum); 73 - return -EIO; 74 - } 75 - 76 - return 0; 77 - } 78 - 79 51 static int write_eraseblock(int ebnum) 80 52 { 81 - int err = 0; 82 - size_t written; 83 53 loff_t addr = ebnum * mtd->erasesize; 84 54 85 55 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize); 86 56 cond_resched(); 87 - err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf); 88 - if (err || written != mtd->erasesize) 89 - pr_err("error: write failed at %#llx\n", 90 - (long long)addr); 91 - 92 - return err; 57 + return mtdtest_write(mtd, addr, mtd->erasesize, writebuf); 93 58 } 94 59 95 60 static int verify_eraseblock(int ebnum) 96 61 { 97 62 uint32_t j; 98 - size_t read; 99 63 int err = 0, i; 100 64 loff_t addr0, addrn; 101 65 loff_t addr = ebnum * mtd->erasesize; ··· 77 109 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize); 78 110 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { 79 111 /* Do a read to set the internal dataRAMs to different data */ 80 - err = mtd_read(mtd, addr0, bufsize, &read, twopages); 81 - if (mtd_is_bitflip(err)) 82 - err = 0; 83 - if (err || read != bufsize) { 84 - pr_err("error: read failed at %#llx\n", 85 - (long long)addr0); 112 + err = mtdtest_read(mtd, addr0, bufsize, twopages); 113 + if (err) 86 114 return err; 87 - } 88 - err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); 89 - if (mtd_is_bitflip(err)) 90 - err = 0; 91 - if (err || read != bufsize) { 92 - pr_err("error: read failed at %#llx\n", 93 - (long long)(addrn - bufsize)); 115 + err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages); 116 + if (err) 94 117 return err; 95 - } 96 118 memset(twopages, 0, bufsize); 97 - err = mtd_read(mtd, addr, bufsize, &read, twopages); 98 - if (mtd_is_bitflip(err)) 99 - err = 0; 100 - if (err || read != bufsize) { 101 - pr_err("error: read failed at %#llx\n", 102 - (long long)addr); 119 + err = mtdtest_read(mtd, addr, bufsize, twopages); 120 + if (err) 103 121 break; 104 - } 105 122 if (memcmp(twopages, writebuf + (j * pgsize), bufsize)) { 106 123 pr_err("error: verify failed at %#llx\n", 107 124 (long long)addr); ··· 98 145 struct rnd_state old_state = rnd_state; 99 146 100 147 /* Do a read to set the internal dataRAMs to different data */ 101 - err = mtd_read(mtd, addr0, bufsize, &read, twopages); 102 - if (mtd_is_bitflip(err)) 103 - err = 0; 104 - if (err || read != bufsize) { 105 - pr_err("error: read failed at %#llx\n", 106 - (long long)addr0); 148 + err = mtdtest_read(mtd, addr0, bufsize, twopages); 149 + if (err) 107 150 return err; 108 - } 109 - err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); 110 - if (mtd_is_bitflip(err)) 111 - err = 0; 112 - if (err || read != bufsize) { 113 - pr_err("error: read failed at %#llx\n", 114 - (long long)(addrn - bufsize)); 151 + err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages); 152 + if (err) 115 153 return err; 116 - } 117 154 memset(twopages, 0, bufsize); 118 - err = mtd_read(mtd, addr, bufsize, &read, twopages); 119 - if (mtd_is_bitflip(err)) 120 - err = 0; 121 - if (err || read != bufsize) { 122 - pr_err("error: read failed at %#llx\n", 123 - (long long)addr); 155 + err = mtdtest_read(mtd, addr, bufsize, twopages); 156 + if (err) 124 157 return err; 125 - } 126 158 memcpy(boundary, writebuf + mtd->erasesize - pgsize, pgsize); 127 159 prandom_bytes_state(&rnd_state, boundary + pgsize, pgsize); 128 160 if (memcmp(twopages, boundary, bufsize)) { ··· 122 184 123 185 static int crosstest(void) 124 186 { 125 - size_t read; 126 187 int err = 0, i; 127 188 loff_t addr, addr0, addrn; 128 189 unsigned char *pp1, *pp2, *pp3, *pp4; 129 190 130 191 pr_info("crosstest\n"); 131 192 pp1 = kmalloc(pgsize * 4, GFP_KERNEL); 132 - if (!pp1) { 133 - pr_err("error: cannot allocate memory\n"); 193 + if (!pp1) 134 194 return -ENOMEM; 135 - } 136 195 pp2 = pp1 + pgsize; 137 196 pp3 = pp2 + pgsize; 138 197 pp4 = pp3 + pgsize; ··· 145 210 146 211 /* Read 2nd-to-last page to pp1 */ 147 212 addr = addrn - pgsize - pgsize; 148 - err = mtd_read(mtd, addr, pgsize, &read, pp1); 149 - if (mtd_is_bitflip(err)) 150 - err = 0; 151 - if (err || read != pgsize) { 152 - pr_err("error: read failed at %#llx\n", 153 - (long long)addr); 213 + err = mtdtest_read(mtd, addr, pgsize, pp1); 214 + if (err) { 154 215 kfree(pp1); 155 216 return err; 156 217 } 157 218 158 219 /* Read 3rd-to-last page to pp1 */ 159 220 addr = addrn - pgsize - pgsize - pgsize; 160 - err = mtd_read(mtd, addr, pgsize, &read, pp1); 161 - if (mtd_is_bitflip(err)) 162 - err = 0; 163 - if (err || read != pgsize) { 164 - pr_err("error: read failed at %#llx\n", 165 - (long long)addr); 221 + err = mtdtest_read(mtd, addr, pgsize, pp1); 222 + if (err) { 166 223 kfree(pp1); 167 224 return err; 168 225 } ··· 162 235 /* Read first page to pp2 */ 163 236 addr = addr0; 164 237 pr_info("reading page at %#llx\n", (long long)addr); 165 - err = mtd_read(mtd, addr, pgsize, &read, pp2); 166 - if (mtd_is_bitflip(err)) 167 - err = 0; 168 - if (err || read != pgsize) { 169 - pr_err("error: read failed at %#llx\n", 170 - (long long)addr); 238 + err = mtdtest_read(mtd, addr, pgsize, pp2); 239 + if (err) { 171 240 kfree(pp1); 172 241 return err; 173 242 } ··· 171 248 /* Read last page to pp3 */ 172 249 addr = addrn - pgsize; 173 250 pr_info("reading page at %#llx\n", (long long)addr); 174 - err = mtd_read(mtd, addr, pgsize, &read, pp3); 175 - if (mtd_is_bitflip(err)) 176 - err = 0; 177 - if (err || read != pgsize) { 178 - pr_err("error: read failed at %#llx\n", 179 - (long long)addr); 251 + err = mtdtest_read(mtd, addr, pgsize, pp3); 252 + if (err) { 180 253 kfree(pp1); 181 254 return err; 182 255 } ··· 180 261 /* Read first page again to pp4 */ 181 262 addr = addr0; 182 263 pr_info("reading page at %#llx\n", (long long)addr); 183 - err = mtd_read(mtd, addr, pgsize, &read, pp4); 184 - if (mtd_is_bitflip(err)) 185 - err = 0; 186 - if (err || read != pgsize) { 187 - pr_err("error: read failed at %#llx\n", 188 - (long long)addr); 264 + err = mtdtest_read(mtd, addr, pgsize, pp4); 265 + if (err) { 189 266 kfree(pp1); 190 267 return err; 191 268 } ··· 200 285 201 286 static int erasecrosstest(void) 202 287 { 203 - size_t read, written; 204 288 int err = 0, i, ebnum, ebnum2; 205 289 loff_t addr0; 206 290 char *readbuf = twopages; ··· 218 304 ebnum2 -= 1; 219 305 220 306 pr_info("erasing block %d\n", ebnum); 221 - err = erase_eraseblock(ebnum); 307 + err = mtdtest_erase_eraseblock(mtd, ebnum); 222 308 if (err) 223 309 return err; 224 310 225 311 pr_info("writing 1st page of block %d\n", ebnum); 226 312 prandom_bytes_state(&rnd_state, writebuf, pgsize); 227 313 strcpy(writebuf, "There is no data like this!"); 228 - err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 229 - if (err || written != pgsize) { 230 - pr_info("error: write failed at %#llx\n", 231 - (long long)addr0); 232 - return err ? err : -1; 233 - } 314 + err = mtdtest_write(mtd, addr0, pgsize, writebuf); 315 + if (err) 316 + return err; 234 317 235 318 pr_info("reading 1st page of block %d\n", ebnum); 236 319 memset(readbuf, 0, pgsize); 237 - err = mtd_read(mtd, addr0, pgsize, &read, readbuf); 238 - if (mtd_is_bitflip(err)) 239 - err = 0; 240 - if (err || read != pgsize) { 241 - pr_err("error: read failed at %#llx\n", 242 - (long long)addr0); 243 - return err ? err : -1; 244 - } 320 + err = mtdtest_read(mtd, addr0, pgsize, readbuf); 321 + if (err) 322 + return err; 245 323 246 324 pr_info("verifying 1st page of block %d\n", ebnum); 247 325 if (memcmp(writebuf, readbuf, pgsize)) { ··· 243 337 } 244 338 245 339 pr_info("erasing block %d\n", ebnum); 246 - err = erase_eraseblock(ebnum); 340 + err = mtdtest_erase_eraseblock(mtd, ebnum); 247 341 if (err) 248 342 return err; 249 343 250 344 pr_info("writing 1st page of block %d\n", ebnum); 251 345 prandom_bytes_state(&rnd_state, writebuf, pgsize); 252 346 strcpy(writebuf, "There is no data like this!"); 253 - err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 254 - if (err || written != pgsize) { 255 - pr_err("error: write failed at %#llx\n", 256 - (long long)addr0); 257 - return err ? err : -1; 258 - } 347 + err = mtdtest_write(mtd, addr0, pgsize, writebuf); 348 + if (err) 349 + return err; 259 350 260 351 pr_info("erasing block %d\n", ebnum2); 261 - err = erase_eraseblock(ebnum2); 352 + err = mtdtest_erase_eraseblock(mtd, ebnum2); 262 353 if (err) 263 354 return err; 264 355 265 356 pr_info("reading 1st page of block %d\n", ebnum); 266 357 memset(readbuf, 0, pgsize); 267 - err = mtd_read(mtd, addr0, pgsize, &read, readbuf); 268 - if (mtd_is_bitflip(err)) 269 - err = 0; 270 - if (err || read != pgsize) { 271 - pr_err("error: read failed at %#llx\n", 272 - (long long)addr0); 273 - return err ? err : -1; 274 - } 358 + err = mtdtest_read(mtd, addr0, pgsize, readbuf); 359 + if (err) 360 + return err; 275 361 276 362 pr_info("verifying 1st page of block %d\n", ebnum); 277 363 if (memcmp(writebuf, readbuf, pgsize)) { ··· 279 381 280 382 static int erasetest(void) 281 383 { 282 - size_t read, written; 283 384 int err = 0, i, ebnum, ok = 1; 284 385 loff_t addr0; 285 386 ··· 292 395 } 293 396 294 397 pr_info("erasing block %d\n", ebnum); 295 - err = erase_eraseblock(ebnum); 398 + err = mtdtest_erase_eraseblock(mtd, ebnum); 296 399 if (err) 297 400 return err; 298 401 299 402 pr_info("writing 1st page of block %d\n", ebnum); 300 403 prandom_bytes_state(&rnd_state, writebuf, pgsize); 301 - err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 302 - if (err || written != pgsize) { 303 - pr_err("error: write failed at %#llx\n", 304 - (long long)addr0); 305 - return err ? err : -1; 306 - } 404 + err = mtdtest_write(mtd, addr0, pgsize, writebuf); 405 + if (err) 406 + return err; 307 407 308 408 pr_info("erasing block %d\n", ebnum); 309 - err = erase_eraseblock(ebnum); 409 + err = mtdtest_erase_eraseblock(mtd, ebnum); 310 410 if (err) 311 411 return err; 312 412 313 413 pr_info("reading 1st page of block %d\n", ebnum); 314 - err = mtd_read(mtd, addr0, pgsize, &read, twopages); 315 - if (mtd_is_bitflip(err)) 316 - err = 0; 317 - if (err || read != pgsize) { 318 - pr_err("error: read failed at %#llx\n", 319 - (long long)addr0); 320 - return err ? err : -1; 321 - } 414 + err = mtdtest_read(mtd, addr0, pgsize, twopages); 415 + if (err) 416 + return err; 322 417 323 418 pr_info("verifying 1st page of block %d is all 0xff\n", 324 419 ebnum); ··· 327 438 pr_info("erasetest ok\n"); 328 439 329 440 return err; 330 - } 331 - 332 - static int is_block_bad(int ebnum) 333 - { 334 - loff_t addr = ebnum * mtd->erasesize; 335 - int ret; 336 - 337 - ret = mtd_block_isbad(mtd, addr); 338 - if (ret) 339 - pr_info("block %d is bad\n", ebnum); 340 - return ret; 341 - } 342 - 343 - static int scan_for_bad_eraseblocks(void) 344 - { 345 - int i, bad = 0; 346 - 347 - bbt = kzalloc(ebcnt, GFP_KERNEL); 348 - if (!bbt) { 349 - pr_err("error: cannot allocate memory\n"); 350 - return -ENOMEM; 351 - } 352 - 353 - pr_info("scanning for bad eraseblocks\n"); 354 - for (i = 0; i < ebcnt; ++i) { 355 - bbt[i] = is_block_bad(i) ? 1 : 0; 356 - if (bbt[i]) 357 - bad += 1; 358 - cond_resched(); 359 - } 360 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 361 - return 0; 362 441 } 363 442 364 443 static int __init mtd_pagetest_init(void) ··· 373 516 err = -ENOMEM; 374 517 bufsize = pgsize * 2; 375 518 writebuf = kmalloc(mtd->erasesize, GFP_KERNEL); 376 - if (!writebuf) { 377 - pr_err("error: cannot allocate memory\n"); 519 + if (!writebuf) 378 520 goto out; 379 - } 380 521 twopages = kmalloc(bufsize, GFP_KERNEL); 381 - if (!twopages) { 382 - pr_err("error: cannot allocate memory\n"); 522 + if (!twopages) 383 523 goto out; 384 - } 385 524 boundary = kmalloc(bufsize, GFP_KERNEL); 386 - if (!boundary) { 387 - pr_err("error: cannot allocate memory\n"); 525 + if (!boundary) 388 526 goto out; 389 - } 390 527 391 - err = scan_for_bad_eraseblocks(); 528 + bbt = kzalloc(ebcnt, GFP_KERNEL); 529 + if (!bbt) 530 + goto out; 531 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 392 532 if (err) 393 533 goto out; 394 534 395 535 /* Erase all eraseblocks */ 396 536 pr_info("erasing whole device\n"); 397 - for (i = 0; i < ebcnt; ++i) { 398 - if (bbt[i]) 399 - continue; 400 - err = erase_eraseblock(i); 401 - if (err) 402 - goto out; 403 - cond_resched(); 404 - } 405 - pr_info("erased %u eraseblocks\n", i); 537 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 538 + if (err) 539 + goto out; 540 + pr_info("erased %u eraseblocks\n", ebcnt); 406 541 407 542 /* Write all eraseblocks */ 408 543 prandom_seed_state(&rnd_state, 1);
+10 -51
drivers/mtd/tests/mtd_readtest.c drivers/mtd/tests/readtest.c
··· 29 29 #include <linux/slab.h> 30 30 #include <linux/sched.h> 31 31 32 + #include "mtd_test.h" 33 + 32 34 static int dev = -EINVAL; 33 35 module_param(dev, int, S_IRUGO); 34 36 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 46 44 47 45 static int read_eraseblock_by_page(int ebnum) 48 46 { 49 - size_t read; 50 47 int i, ret, err = 0; 51 48 loff_t addr = ebnum * mtd->erasesize; 52 49 void *buf = iobuf; ··· 53 52 54 53 for (i = 0; i < pgcnt; i++) { 55 54 memset(buf, 0 , pgsize); 56 - ret = mtd_read(mtd, addr, pgsize, &read, buf); 57 - if (ret == -EUCLEAN) 58 - ret = 0; 59 - if (ret || read != pgsize) { 60 - pr_err("error: read failed at %#llx\n", 61 - (long long)addr); 55 + ret = mtdtest_read(mtd, addr, pgsize, buf); 56 + if (ret) { 62 57 if (!err) 63 58 err = ret; 64 - if (!err) 65 - err = -EINVAL; 66 59 } 67 60 if (mtd->oobsize) { 68 61 struct mtd_oob_ops ops; ··· 122 127 } 123 128 } 124 129 125 - static int is_block_bad(int ebnum) 126 - { 127 - loff_t addr = ebnum * mtd->erasesize; 128 - int ret; 129 - 130 - ret = mtd_block_isbad(mtd, addr); 131 - if (ret) 132 - pr_info("block %d is bad\n", ebnum); 133 - return ret; 134 - } 135 - 136 - static int scan_for_bad_eraseblocks(void) 137 - { 138 - int i, bad = 0; 139 - 140 - bbt = kzalloc(ebcnt, GFP_KERNEL); 141 - if (!bbt) { 142 - pr_err("error: cannot allocate memory\n"); 143 - return -ENOMEM; 144 - } 145 - 146 - if (!mtd_can_have_bb(mtd)) 147 - return 0; 148 - 149 - pr_info("scanning for bad eraseblocks\n"); 150 - for (i = 0; i < ebcnt; ++i) { 151 - bbt[i] = is_block_bad(i) ? 1 : 0; 152 - if (bbt[i]) 153 - bad += 1; 154 - cond_resched(); 155 - } 156 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 157 - return 0; 158 - } 159 - 160 130 static int __init mtd_readtest_init(void) 161 131 { 162 132 uint64_t tmp; ··· 164 204 165 205 err = -ENOMEM; 166 206 iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); 167 - if (!iobuf) { 168 - pr_err("error: cannot allocate memory\n"); 207 + if (!iobuf) 169 208 goto out; 170 - } 171 209 iobuf1 = kmalloc(mtd->erasesize, GFP_KERNEL); 172 - if (!iobuf1) { 173 - pr_err("error: cannot allocate memory\n"); 210 + if (!iobuf1) 174 211 goto out; 175 - } 176 212 177 - err = scan_for_bad_eraseblocks(); 213 + bbt = kzalloc(ebcnt, GFP_KERNEL); 214 + if (!bbt) 215 + goto out; 216 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 178 217 if (err) 179 218 goto out; 180 219
+33 -177
drivers/mtd/tests/mtd_speedtest.c drivers/mtd/tests/speedtest.c
··· 30 30 #include <linux/sched.h> 31 31 #include <linux/random.h> 32 32 33 + #include "mtd_test.h" 34 + 33 35 static int dev = -EINVAL; 34 36 module_param(dev, int, S_IRUGO); 35 37 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 50 48 static int pgcnt; 51 49 static int goodebcnt; 52 50 static struct timeval start, finish; 53 - 54 - 55 - static int erase_eraseblock(int ebnum) 56 - { 57 - int err; 58 - struct erase_info ei; 59 - loff_t addr = ebnum * mtd->erasesize; 60 - 61 - memset(&ei, 0, sizeof(struct erase_info)); 62 - ei.mtd = mtd; 63 - ei.addr = addr; 64 - ei.len = mtd->erasesize; 65 - 66 - err = mtd_erase(mtd, &ei); 67 - if (err) { 68 - pr_err("error %d while erasing EB %d\n", err, ebnum); 69 - return err; 70 - } 71 - 72 - if (ei.state == MTD_ERASE_FAILED) { 73 - pr_err("some erase error occurred at EB %d\n", 74 - ebnum); 75 - return -EIO; 76 - } 77 - 78 - return 0; 79 - } 80 51 81 52 static int multiblock_erase(int ebnum, int blocks) 82 53 { ··· 78 103 return 0; 79 104 } 80 105 81 - static int erase_whole_device(void) 82 - { 83 - int err; 84 - unsigned int i; 85 - 86 - for (i = 0; i < ebcnt; ++i) { 87 - if (bbt[i]) 88 - continue; 89 - err = erase_eraseblock(i); 90 - if (err) 91 - return err; 92 - cond_resched(); 93 - } 94 - return 0; 95 - } 96 - 97 106 static int write_eraseblock(int ebnum) 98 107 { 99 - size_t written; 100 - int err = 0; 101 108 loff_t addr = ebnum * mtd->erasesize; 102 109 103 - err = mtd_write(mtd, addr, mtd->erasesize, &written, iobuf); 104 - if (err || written != mtd->erasesize) { 105 - pr_err("error: write failed at %#llx\n", addr); 106 - if (!err) 107 - err = -EINVAL; 108 - } 109 - 110 - return err; 110 + return mtdtest_write(mtd, addr, mtd->erasesize, iobuf); 111 111 } 112 112 113 113 static int write_eraseblock_by_page(int ebnum) 114 114 { 115 - size_t written; 116 115 int i, err = 0; 117 116 loff_t addr = ebnum * mtd->erasesize; 118 117 void *buf = iobuf; 119 118 120 119 for (i = 0; i < pgcnt; i++) { 121 - err = mtd_write(mtd, addr, pgsize, &written, buf); 122 - if (err || written != pgsize) { 123 - pr_err("error: write failed at %#llx\n", 124 - addr); 125 - if (!err) 126 - err = -EINVAL; 120 + err = mtdtest_write(mtd, addr, pgsize, buf); 121 + if (err) 127 122 break; 128 - } 129 123 addr += pgsize; 130 124 buf += pgsize; 131 125 } ··· 104 160 105 161 static int write_eraseblock_by_2pages(int ebnum) 106 162 { 107 - size_t written, sz = pgsize * 2; 163 + size_t sz = pgsize * 2; 108 164 int i, n = pgcnt / 2, err = 0; 109 165 loff_t addr = ebnum * mtd->erasesize; 110 166 void *buf = iobuf; 111 167 112 168 for (i = 0; i < n; i++) { 113 - err = mtd_write(mtd, addr, sz, &written, buf); 114 - if (err || written != sz) { 115 - pr_err("error: write failed at %#llx\n", 116 - addr); 117 - if (!err) 118 - err = -EINVAL; 169 + err = mtdtest_write(mtd, addr, sz, buf); 170 + if (err) 119 171 return err; 120 - } 121 172 addr += sz; 122 173 buf += sz; 123 174 } 124 - if (pgcnt % 2) { 125 - err = mtd_write(mtd, addr, pgsize, &written, buf); 126 - if (err || written != pgsize) { 127 - pr_err("error: write failed at %#llx\n", 128 - addr); 129 - if (!err) 130 - err = -EINVAL; 131 - } 132 - } 175 + if (pgcnt % 2) 176 + err = mtdtest_write(mtd, addr, pgsize, buf); 133 177 134 178 return err; 135 179 } 136 180 137 181 static int read_eraseblock(int ebnum) 138 182 { 139 - size_t read; 140 - int err = 0; 141 183 loff_t addr = ebnum * mtd->erasesize; 142 184 143 - err = mtd_read(mtd, addr, mtd->erasesize, &read, iobuf); 144 - /* Ignore corrected ECC errors */ 145 - if (mtd_is_bitflip(err)) 146 - err = 0; 147 - if (err || read != mtd->erasesize) { 148 - pr_err("error: read failed at %#llx\n", addr); 149 - if (!err) 150 - err = -EINVAL; 151 - } 152 - 153 - return err; 185 + return mtdtest_read(mtd, addr, mtd->erasesize, iobuf); 154 186 } 155 187 156 188 static int read_eraseblock_by_page(int ebnum) 157 189 { 158 - size_t read; 159 190 int i, err = 0; 160 191 loff_t addr = ebnum * mtd->erasesize; 161 192 void *buf = iobuf; 162 193 163 194 for (i = 0; i < pgcnt; i++) { 164 - err = mtd_read(mtd, addr, pgsize, &read, buf); 165 - /* Ignore corrected ECC errors */ 166 - if (mtd_is_bitflip(err)) 167 - err = 0; 168 - if (err || read != pgsize) { 169 - pr_err("error: read failed at %#llx\n", 170 - addr); 171 - if (!err) 172 - err = -EINVAL; 195 + err = mtdtest_read(mtd, addr, pgsize, buf); 196 + if (err) 173 197 break; 174 - } 175 198 addr += pgsize; 176 199 buf += pgsize; 177 200 } ··· 148 237 149 238 static int read_eraseblock_by_2pages(int ebnum) 150 239 { 151 - size_t read, sz = pgsize * 2; 240 + size_t sz = pgsize * 2; 152 241 int i, n = pgcnt / 2, err = 0; 153 242 loff_t addr = ebnum * mtd->erasesize; 154 243 void *buf = iobuf; 155 244 156 245 for (i = 0; i < n; i++) { 157 - err = mtd_read(mtd, addr, sz, &read, buf); 158 - /* Ignore corrected ECC errors */ 159 - if (mtd_is_bitflip(err)) 160 - err = 0; 161 - if (err || read != sz) { 162 - pr_err("error: read failed at %#llx\n", 163 - addr); 164 - if (!err) 165 - err = -EINVAL; 246 + err = mtdtest_read(mtd, addr, sz, buf); 247 + if (err) 166 248 return err; 167 - } 168 249 addr += sz; 169 250 buf += sz; 170 251 } 171 - if (pgcnt % 2) { 172 - err = mtd_read(mtd, addr, pgsize, &read, buf); 173 - /* Ignore corrected ECC errors */ 174 - if (mtd_is_bitflip(err)) 175 - err = 0; 176 - if (err || read != pgsize) { 177 - pr_err("error: read failed at %#llx\n", 178 - addr); 179 - if (!err) 180 - err = -EINVAL; 181 - } 182 - } 252 + if (pgcnt % 2) 253 + err = mtdtest_read(mtd, addr, pgsize, buf); 183 254 184 255 return err; 185 - } 186 - 187 - static int is_block_bad(int ebnum) 188 - { 189 - loff_t addr = ebnum * mtd->erasesize; 190 - int ret; 191 - 192 - ret = mtd_block_isbad(mtd, addr); 193 - if (ret) 194 - pr_info("block %d is bad\n", ebnum); 195 - return ret; 196 256 } 197 257 198 258 static inline void start_timing(void) ··· 188 306 k = goodebcnt * (mtd->erasesize / 1024) * 1000; 189 307 do_div(k, ms); 190 308 return k; 191 - } 192 - 193 - static int scan_for_bad_eraseblocks(void) 194 - { 195 - int i, bad = 0; 196 - 197 - bbt = kzalloc(ebcnt, GFP_KERNEL); 198 - if (!bbt) { 199 - pr_err("error: cannot allocate memory\n"); 200 - return -ENOMEM; 201 - } 202 - 203 - if (!mtd_can_have_bb(mtd)) 204 - goto out; 205 - 206 - pr_info("scanning for bad eraseblocks\n"); 207 - for (i = 0; i < ebcnt; ++i) { 208 - bbt[i] = is_block_bad(i) ? 1 : 0; 209 - if (bbt[i]) 210 - bad += 1; 211 - cond_resched(); 212 - } 213 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 214 - out: 215 - goodebcnt = ebcnt - bad; 216 - return 0; 217 309 } 218 310 219 311 static int __init mtd_speedtest_init(void) ··· 240 384 241 385 err = -ENOMEM; 242 386 iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); 243 - if (!iobuf) { 244 - pr_err("error: cannot allocate memory\n"); 387 + if (!iobuf) 245 388 goto out; 246 - } 247 389 248 390 prandom_bytes(iobuf, mtd->erasesize); 249 391 250 - err = scan_for_bad_eraseblocks(); 392 + bbt = kzalloc(ebcnt, GFP_KERNEL); 393 + if (!bbt) 394 + goto out; 395 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 251 396 if (err) 252 397 goto out; 398 + for (i = 0; i < ebcnt; i++) { 399 + if (!bbt[i]) 400 + goodebcnt++; 401 + } 253 402 254 - err = erase_whole_device(); 403 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 255 404 if (err) 256 405 goto out; 257 406 ··· 290 429 speed = calc_speed(); 291 430 pr_info("eraseblock read speed is %ld KiB/s\n", speed); 292 431 293 - err = erase_whole_device(); 432 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 294 433 if (err) 295 434 goto out; 296 435 ··· 324 463 speed = calc_speed(); 325 464 pr_info("page read speed is %ld KiB/s\n", speed); 326 465 327 - err = erase_whole_device(); 466 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 328 467 if (err) 329 468 goto out; 330 469 ··· 361 500 /* Erase all eraseblocks */ 362 501 pr_info("Testing erase speed\n"); 363 502 start_timing(); 364 - for (i = 0; i < ebcnt; ++i) { 365 - if (bbt[i]) 366 - continue; 367 - err = erase_eraseblock(i); 368 - if (err) 369 - goto out; 370 - cond_resched(); 371 - } 503 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 504 + if (err) 505 + goto out; 372 506 stop_timing(); 373 507 speed = calc_speed(); 374 508 pr_info("erase speed is %ld KiB/s\n", speed);
+13 -88
drivers/mtd/tests/mtd_stresstest.c drivers/mtd/tests/stresstest.c
··· 31 31 #include <linux/vmalloc.h> 32 32 #include <linux/random.h> 33 33 34 + #include "mtd_test.h" 35 + 34 36 static int dev = -EINVAL; 35 37 module_param(dev, int, S_IRUGO); 36 38 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 83 81 return len; 84 82 } 85 83 86 - static int erase_eraseblock(int ebnum) 87 - { 88 - int err; 89 - struct erase_info ei; 90 - loff_t addr = ebnum * mtd->erasesize; 91 - 92 - memset(&ei, 0, sizeof(struct erase_info)); 93 - ei.mtd = mtd; 94 - ei.addr = addr; 95 - ei.len = mtd->erasesize; 96 - 97 - err = mtd_erase(mtd, &ei); 98 - if (unlikely(err)) { 99 - pr_err("error %d while erasing EB %d\n", err, ebnum); 100 - return err; 101 - } 102 - 103 - if (unlikely(ei.state == MTD_ERASE_FAILED)) { 104 - pr_err("some erase error occurred at EB %d\n", 105 - ebnum); 106 - return -EIO; 107 - } 108 - 109 - return 0; 110 - } 111 - 112 - static int is_block_bad(int ebnum) 113 - { 114 - loff_t addr = ebnum * mtd->erasesize; 115 - int ret; 116 - 117 - ret = mtd_block_isbad(mtd, addr); 118 - if (ret) 119 - pr_info("block %d is bad\n", ebnum); 120 - return ret; 121 - } 122 - 123 84 static int do_read(void) 124 85 { 125 - size_t read; 126 86 int eb = rand_eb(); 127 87 int offs = rand_offs(); 128 - int len = rand_len(offs), err; 88 + int len = rand_len(offs); 129 89 loff_t addr; 130 90 131 91 if (bbt[eb + 1]) { ··· 97 133 len = mtd->erasesize - offs; 98 134 } 99 135 addr = eb * mtd->erasesize + offs; 100 - err = mtd_read(mtd, addr, len, &read, readbuf); 101 - if (mtd_is_bitflip(err)) 102 - err = 0; 103 - if (unlikely(err || read != len)) { 104 - pr_err("error: read failed at 0x%llx\n", 105 - (long long)addr); 106 - if (!err) 107 - err = -EINVAL; 108 - return err; 109 - } 110 - return 0; 136 + return mtdtest_read(mtd, addr, len, readbuf); 111 137 } 112 138 113 139 static int do_write(void) 114 140 { 115 141 int eb = rand_eb(), offs, err, len; 116 - size_t written; 117 142 loff_t addr; 118 143 119 144 offs = offsets[eb]; 120 145 if (offs >= mtd->erasesize) { 121 - err = erase_eraseblock(eb); 146 + err = mtdtest_erase_eraseblock(mtd, eb); 122 147 if (err) 123 148 return err; 124 149 offs = offsets[eb] = 0; ··· 118 165 if (bbt[eb + 1]) 119 166 len = mtd->erasesize - offs; 120 167 else { 121 - err = erase_eraseblock(eb + 1); 168 + err = mtdtest_erase_eraseblock(mtd, eb + 1); 122 169 if (err) 123 170 return err; 124 171 offsets[eb + 1] = 0; 125 172 } 126 173 } 127 174 addr = eb * mtd->erasesize + offs; 128 - err = mtd_write(mtd, addr, len, &written, writebuf); 129 - if (unlikely(err || written != len)) { 130 - pr_err("error: write failed at 0x%llx\n", 131 - (long long)addr); 132 - if (!err) 133 - err = -EINVAL; 175 + err = mtdtest_write(mtd, addr, len, writebuf); 176 + if (unlikely(err)) 134 177 return err; 135 - } 136 178 offs += len; 137 179 while (offs > mtd->erasesize) { 138 180 offsets[eb++] = mtd->erasesize; ··· 143 195 return do_read(); 144 196 else 145 197 return do_write(); 146 - } 147 - 148 - static int scan_for_bad_eraseblocks(void) 149 - { 150 - int i, bad = 0; 151 - 152 - bbt = kzalloc(ebcnt, GFP_KERNEL); 153 - if (!bbt) { 154 - pr_err("error: cannot allocate memory\n"); 155 - return -ENOMEM; 156 - } 157 - 158 - if (!mtd_can_have_bb(mtd)) 159 - return 0; 160 - 161 - pr_info("scanning for bad eraseblocks\n"); 162 - for (i = 0; i < ebcnt; ++i) { 163 - bbt[i] = is_block_bad(i) ? 1 : 0; 164 - if (bbt[i]) 165 - bad += 1; 166 - cond_resched(); 167 - } 168 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 169 - return 0; 170 198 } 171 199 172 200 static int __init mtd_stresstest_init(void) ··· 200 276 readbuf = vmalloc(bufsize); 201 277 writebuf = vmalloc(bufsize); 202 278 offsets = kmalloc(ebcnt * sizeof(int), GFP_KERNEL); 203 - if (!readbuf || !writebuf || !offsets) { 204 - pr_err("error: cannot allocate memory\n"); 279 + if (!readbuf || !writebuf || !offsets) 205 280 goto out; 206 - } 207 281 for (i = 0; i < ebcnt; i++) 208 282 offsets[i] = mtd->erasesize; 209 283 prandom_bytes(writebuf, bufsize); 210 284 211 - err = scan_for_bad_eraseblocks(); 285 + bbt = kzalloc(ebcnt, GFP_KERNEL); 286 + if (!bbt) 287 + goto out; 288 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 212 289 if (err) 213 290 goto out; 214 291
+11 -86
drivers/mtd/tests/mtd_subpagetest.c drivers/mtd/tests/subpagetest.c
··· 30 30 #include <linux/sched.h> 31 31 #include <linux/random.h> 32 32 33 + #include "mtd_test.h" 34 + 33 35 static int dev = -EINVAL; 34 36 module_param(dev, int, S_IRUGO); 35 37 MODULE_PARM_DESC(dev, "MTD device number to use"); ··· 51 49 static inline void clear_data(unsigned char *buf, size_t len) 52 50 { 53 51 memset(buf, 0, len); 54 - } 55 - 56 - static int erase_eraseblock(int ebnum) 57 - { 58 - int err; 59 - struct erase_info ei; 60 - loff_t addr = ebnum * mtd->erasesize; 61 - 62 - memset(&ei, 0, sizeof(struct erase_info)); 63 - ei.mtd = mtd; 64 - ei.addr = addr; 65 - ei.len = mtd->erasesize; 66 - 67 - err = mtd_erase(mtd, &ei); 68 - if (err) { 69 - pr_err("error %d while erasing EB %d\n", err, ebnum); 70 - return err; 71 - } 72 - 73 - if (ei.state == MTD_ERASE_FAILED) { 74 - pr_err("some erase error occurred at EB %d\n", 75 - ebnum); 76 - return -EIO; 77 - } 78 - 79 - return 0; 80 - } 81 - 82 - static int erase_whole_device(void) 83 - { 84 - int err; 85 - unsigned int i; 86 - 87 - pr_info("erasing whole device\n"); 88 - for (i = 0; i < ebcnt; ++i) { 89 - if (bbt[i]) 90 - continue; 91 - err = erase_eraseblock(i); 92 - if (err) 93 - return err; 94 - cond_resched(); 95 - } 96 - pr_info("erased %u eraseblocks\n", i); 97 - return 0; 98 52 } 99 53 100 54 static int write_eraseblock(int ebnum) ··· 275 317 return 0; 276 318 } 277 319 278 - static int is_block_bad(int ebnum) 279 - { 280 - loff_t addr = ebnum * mtd->erasesize; 281 - int ret; 282 - 283 - ret = mtd_block_isbad(mtd, addr); 284 - if (ret) 285 - pr_info("block %d is bad\n", ebnum); 286 - return ret; 287 - } 288 - 289 - static int scan_for_bad_eraseblocks(void) 290 - { 291 - int i, bad = 0; 292 - 293 - bbt = kzalloc(ebcnt, GFP_KERNEL); 294 - if (!bbt) { 295 - pr_err("error: cannot allocate memory\n"); 296 - return -ENOMEM; 297 - } 298 - 299 - pr_info("scanning for bad eraseblocks\n"); 300 - for (i = 0; i < ebcnt; ++i) { 301 - bbt[i] = is_block_bad(i) ? 1 : 0; 302 - if (bbt[i]) 303 - bad += 1; 304 - cond_resched(); 305 - } 306 - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 307 - return 0; 308 - } 309 - 310 320 static int __init mtd_subpagetest_init(void) 311 321 { 312 322 int err = 0; ··· 319 393 err = -ENOMEM; 320 394 bufsize = subpgsize * 32; 321 395 writebuf = kmalloc(bufsize, GFP_KERNEL); 322 - if (!writebuf) { 323 - pr_info("error: cannot allocate memory\n"); 396 + if (!writebuf) 324 397 goto out; 325 - } 326 398 readbuf = kmalloc(bufsize, GFP_KERNEL); 327 - if (!readbuf) { 328 - pr_info("error: cannot allocate memory\n"); 399 + if (!readbuf) 329 400 goto out; 330 - } 401 + bbt = kzalloc(ebcnt, GFP_KERNEL); 402 + if (!bbt) 403 + goto out; 331 404 332 - err = scan_for_bad_eraseblocks(); 405 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); 333 406 if (err) 334 407 goto out; 335 408 336 - err = erase_whole_device(); 409 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 337 410 if (err) 338 411 goto out; 339 412 ··· 364 439 } 365 440 pr_info("verified %u eraseblocks\n", i); 366 441 367 - err = erase_whole_device(); 442 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 368 443 if (err) 369 444 goto out; 370 445 ··· 402 477 } 403 478 pr_info("verified %u eraseblocks\n", i); 404 479 405 - err = erase_whole_device(); 480 + err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); 406 481 if (err) 407 482 goto out; 408 483
+114
drivers/mtd/tests/mtd_test.c
··· 1 + #define pr_fmt(fmt) "mtd_test: " fmt 2 + 3 + #include <linux/init.h> 4 + #include <linux/module.h> 5 + #include <linux/sched.h> 6 + #include <linux/printk.h> 7 + 8 + #include "mtd_test.h" 9 + 10 + int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum) 11 + { 12 + int err; 13 + struct erase_info ei; 14 + loff_t addr = ebnum * mtd->erasesize; 15 + 16 + memset(&ei, 0, sizeof(struct erase_info)); 17 + ei.mtd = mtd; 18 + ei.addr = addr; 19 + ei.len = mtd->erasesize; 20 + 21 + err = mtd_erase(mtd, &ei); 22 + if (err) { 23 + pr_info("error %d while erasing EB %d\n", err, ebnum); 24 + return err; 25 + } 26 + 27 + if (ei.state == MTD_ERASE_FAILED) { 28 + pr_info("some erase error occurred at EB %d\n", ebnum); 29 + return -EIO; 30 + } 31 + return 0; 32 + } 33 + 34 + static int is_block_bad(struct mtd_info *mtd, unsigned int ebnum) 35 + { 36 + int ret; 37 + loff_t addr = ebnum * mtd->erasesize; 38 + 39 + ret = mtd_block_isbad(mtd, addr); 40 + if (ret) 41 + pr_info("block %d is bad\n", ebnum); 42 + 43 + return ret; 44 + } 45 + 46 + int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, 47 + unsigned int eb, int ebcnt) 48 + { 49 + int i, bad = 0; 50 + 51 + if (!mtd_can_have_bb(mtd)) 52 + return 0; 53 + 54 + pr_info("scanning for bad eraseblocks\n"); 55 + for (i = 0; i < ebcnt; ++i) { 56 + bbt[i] = is_block_bad(mtd, eb + i) ? 1 : 0; 57 + if (bbt[i]) 58 + bad += 1; 59 + cond_resched(); 60 + } 61 + pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); 62 + 63 + return 0; 64 + } 65 + 66 + int mtdtest_erase_good_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, 67 + unsigned int eb, int ebcnt) 68 + { 69 + int err; 70 + unsigned int i; 71 + 72 + for (i = 0; i < ebcnt; ++i) { 73 + if (bbt[i]) 74 + continue; 75 + err = mtdtest_erase_eraseblock(mtd, eb + i); 76 + if (err) 77 + return err; 78 + cond_resched(); 79 + } 80 + 81 + return 0; 82 + } 83 + 84 + int mtdtest_read(struct mtd_info *mtd, loff_t addr, size_t size, void *buf) 85 + { 86 + size_t read; 87 + int err; 88 + 89 + err = mtd_read(mtd, addr, size, &read, buf); 90 + /* Ignore corrected ECC errors */ 91 + if (mtd_is_bitflip(err)) 92 + err = 0; 93 + if (!err && read != size) 94 + err = -EIO; 95 + if (err) 96 + pr_err("error: read failed at %#llx\n", addr); 97 + 98 + return err; 99 + } 100 + 101 + int mtdtest_write(struct mtd_info *mtd, loff_t addr, size_t size, 102 + const void *buf) 103 + { 104 + size_t written; 105 + int err; 106 + 107 + err = mtd_write(mtd, addr, size, &written, buf); 108 + if (!err && written != size) 109 + err = -EIO; 110 + if (err) 111 + pr_err("error: write failed at %#llx\n", addr); 112 + 113 + return err; 114 + }
+11
drivers/mtd/tests/mtd_test.h
··· 1 + #include <linux/mtd/mtd.h> 2 + 3 + int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum); 4 + int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, 5 + unsigned int eb, int ebcnt); 6 + int mtdtest_erase_good_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, 7 + unsigned int eb, int ebcnt); 8 + 9 + int mtdtest_read(struct mtd_info *mtd, loff_t addr, size_t size, void *buf); 10 + int mtdtest_write(struct mtd_info *mtd, loff_t addr, size_t size, 11 + const void *buf);
+7 -59
drivers/mtd/tests/mtd_torturetest.c drivers/mtd/tests/torturetest.c
··· 32 32 #include <linux/mtd/mtd.h> 33 33 #include <linux/slab.h> 34 34 #include <linux/sched.h> 35 + #include "mtd_test.h" 35 36 36 37 #define RETRIES 3 37 38 ··· 91 90 static inline void stop_timing(void) 92 91 { 93 92 do_gettimeofday(&finish); 94 - } 95 - 96 - /* 97 - * Erase eraseblock number @ebnum. 98 - */ 99 - static inline int erase_eraseblock(int ebnum) 100 - { 101 - int err; 102 - struct erase_info ei; 103 - loff_t addr = ebnum * mtd->erasesize; 104 - 105 - memset(&ei, 0, sizeof(struct erase_info)); 106 - ei.mtd = mtd; 107 - ei.addr = addr; 108 - ei.len = mtd->erasesize; 109 - 110 - err = mtd_erase(mtd, &ei); 111 - if (err) { 112 - pr_err("error %d while erasing EB %d\n", err, ebnum); 113 - return err; 114 - } 115 - 116 - if (ei.state == MTD_ERASE_FAILED) { 117 - pr_err("some erase error occurred at EB %d\n", 118 - ebnum); 119 - return -EIO; 120 - } 121 - 122 - return 0; 123 93 } 124 94 125 95 /* ··· 180 208 static int __init tort_init(void) 181 209 { 182 210 int err = 0, i, infinite = !cycles_count; 183 - int *bad_ebs; 211 + unsigned char *bad_ebs; 184 212 185 213 printk(KERN_INFO "\n"); 186 214 printk(KERN_INFO "=================================================\n"); ··· 237 265 if (!check_buf) 238 266 goto out_patt_FF; 239 267 240 - bad_ebs = kcalloc(ebcnt, sizeof(*bad_ebs), GFP_KERNEL); 268 + bad_ebs = kzalloc(ebcnt, GFP_KERNEL); 241 269 if (!bad_ebs) 242 270 goto out_check_buf; 243 271 ··· 255 283 } 256 284 } 257 285 258 - /* 259 - * Check if there is a bad eraseblock among those we are going to test. 260 - */ 261 - if (mtd_can_have_bb(mtd)) { 262 - for (i = eb; i < eb + ebcnt; i++) { 263 - err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); 264 - 265 - if (err < 0) { 266 - pr_info("block_isbad() returned %d " 267 - "for EB %d\n", err, i); 268 - goto out; 269 - } 270 - 271 - if (err) { 272 - pr_err("EB %d is bad. Skip it.\n", i); 273 - bad_ebs[i - eb] = 1; 274 - } 275 - } 276 - } 286 + err = mtdtest_scan_for_bad_eraseblocks(mtd, bad_ebs, eb, ebcnt); 287 + if (err) 288 + goto out; 277 289 278 290 start_timing(); 279 291 while (1) { 280 292 int i; 281 293 void *patt; 282 294 283 - /* Erase all eraseblocks */ 284 - for (i = eb; i < eb + ebcnt; i++) { 285 - if (bad_ebs[i - eb]) 286 - continue; 287 - err = erase_eraseblock(i); 288 - if (err) 289 - goto out; 290 - cond_resched(); 291 - } 295 + mtdtest_erase_good_eraseblocks(mtd, bad_ebs, eb, ebcnt); 292 296 293 297 /* Check if the eraseblocks contain only 0xFF bytes */ 294 298 if (check) {
-2
include/linux/mtd/bbm.h
··· 93 93 #define NAND_BBT_CREATE_EMPTY 0x00000400 94 94 /* Search good / bad pattern through all pages of a block */ 95 95 #define NAND_BBT_SCANALLPAGES 0x00000800 96 - /* Scan block empty during good / bad block scan */ 97 - #define NAND_BBT_SCANEMPTY 0x00001000 98 96 /* Write bbt if neccecary */ 99 97 #define NAND_BBT_WRITE 0x00002000 100 98 /* Read and write back block contents when writing bbt */
+1
include/linux/mtd/fsmc.h
··· 137 137 138 138 /** 139 139 * fsmc_nand_platform_data - platform specific NAND controller config 140 + * @nand_timings: timing setup for the physical NAND interface 140 141 * @partitions: partition table for the platform, use a default fallback 141 142 * if this is NULL 142 143 * @nr_partitions: the number of partitions in the previous entry
+3
include/linux/mtd/mtd.h
··· 173 173 /* ECC layout structure pointer - read only! */ 174 174 struct nand_ecclayout *ecclayout; 175 175 176 + /* the ecc step size. */ 177 + unsigned int ecc_step_size; 178 + 176 179 /* max number of correctible bit errors per ecc step */ 177 180 unsigned int ecc_strength; 178 181
+78 -5
include/linux/mtd/nand.h
··· 56 56 * is supported now. If you add a chip with bigger oobsize/page 57 57 * adjust this accordingly. 58 58 */ 59 - #define NAND_MAX_OOBSIZE 640 59 + #define NAND_MAX_OOBSIZE 744 60 60 #define NAND_MAX_PAGESIZE 8192 61 61 62 62 /* ··· 202 202 /* Keep gcc happy */ 203 203 struct nand_chip; 204 204 205 + /* ONFI features */ 206 + #define ONFI_FEATURE_16_BIT_BUS (1 << 0) 207 + #define ONFI_FEATURE_EXT_PARAM_PAGE (1 << 7) 208 + 205 209 /* ONFI timing mode, used in both asynchronous and synchronous mode */ 206 210 #define ONFI_TIMING_MODE_0 (1 << 0) 207 211 #define ONFI_TIMING_MODE_1 (1 << 1) ··· 221 217 /* ONFI subfeature parameters length */ 222 218 #define ONFI_SUBFEATURE_PARAM_LEN 4 223 219 220 + /* ONFI optional commands SET/GET FEATURES supported? */ 221 + #define ONFI_OPT_CMD_SET_GET_FEATURES (1 << 2) 222 + 224 223 struct nand_onfi_params { 225 224 /* rev info and features block */ 226 225 /* 'O' 'N' 'F' 'I' */ ··· 231 224 __le16 revision; 232 225 __le16 features; 233 226 __le16 opt_cmd; 234 - u8 reserved[22]; 227 + u8 reserved0[2]; 228 + __le16 ext_param_page_length; /* since ONFI 2.1 */ 229 + u8 num_of_param_pages; /* since ONFI 2.1 */ 230 + u8 reserved1[17]; 235 231 236 232 /* manufacturer information block */ 237 233 char manufacturer[12]; ··· 290 280 } __attribute__((packed)); 291 281 292 282 #define ONFI_CRC_BASE 0x4F4E 283 + 284 + /* Extended ECC information Block Definition (since ONFI 2.1) */ 285 + struct onfi_ext_ecc_info { 286 + u8 ecc_bits; 287 + u8 codeword_size; 288 + __le16 bb_per_lun; 289 + __le16 block_endurance; 290 + u8 reserved[2]; 291 + } __packed; 292 + 293 + #define ONFI_SECTION_TYPE_0 0 /* Unused section. */ 294 + #define ONFI_SECTION_TYPE_1 1 /* for additional sections. */ 295 + #define ONFI_SECTION_TYPE_2 2 /* for ECC information. */ 296 + struct onfi_ext_section { 297 + u8 type; 298 + u8 length; 299 + } __packed; 300 + 301 + #define ONFI_EXT_SECTION_MAX 8 302 + 303 + /* Extended Parameter Page Definition (since ONFI 2.1) */ 304 + struct onfi_ext_param_page { 305 + __le16 crc; 306 + u8 sig[4]; /* 'E' 'P' 'P' 'S' */ 307 + u8 reserved0[10]; 308 + struct onfi_ext_section sections[ONFI_EXT_SECTION_MAX]; 309 + 310 + /* 311 + * The actual size of the Extended Parameter Page is in 312 + * @ext_param_page_length of nand_onfi_params{}. 313 + * The following are the variable length sections. 314 + * So we do not add any fields below. Please see the ONFI spec. 315 + */ 316 + } __packed; 293 317 294 318 /** 295 319 * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices ··· 434 390 * @write_buf: [REPLACEABLE] write data from the buffer to the chip 435 391 * @read_buf: [REPLACEABLE] read data from the chip into the buffer 436 392 * @select_chip: [REPLACEABLE] select chip nr 437 - * @block_bad: [REPLACEABLE] check, if the block is bad 438 - * @block_markbad: [REPLACEABLE] mark the block bad 393 + * @block_bad: [REPLACEABLE] check if a block is bad, using OOB markers 394 + * @block_markbad: [REPLACEABLE] mark a block bad 439 395 * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific function for controlling 440 396 * ALE/CLE/nCE. Also used to write command and address 441 397 * @init_size: [BOARDSPECIFIC] hardwarespecific function for setting ··· 478 434 * bad block marker position; i.e., BBM == 11110111b is 479 435 * not bad when badblockbits == 7 480 436 * @cellinfo: [INTERN] MLC/multichip data from chip ident 437 + * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet. 438 + * Minimum amount of bit errors per @ecc_step_ds guaranteed 439 + * to be correctable. If unknown, set to zero. 440 + * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds, 441 + * also from the datasheet. It is the recommended ECC step 442 + * size, if known; if unknown, set to zero. 481 443 * @numchips: [INTERN] number of physical chips 482 444 * @chipsize: [INTERN] the size of one chip for multichip arrays 483 445 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 ··· 560 510 unsigned int pagebuf_bitflips; 561 511 int subpagesize; 562 512 uint8_t cellinfo; 513 + uint16_t ecc_strength_ds; 514 + uint16_t ecc_step_ds; 563 515 int badblockpos; 564 516 int badblockbits; 565 517 ··· 628 576 { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \ 629 577 .options = (opts) } 630 578 579 + #define NAND_ECC_INFO(_strength, _step) \ 580 + { .strength_ds = (_strength), .step_ds = (_step) } 581 + #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds) 582 + #define NAND_ECC_STEP(type) ((type)->ecc.step_ds) 583 + 631 584 /** 632 585 * struct nand_flash_dev - NAND Flash Device ID Structure 633 586 * @name: a human-readable name of the NAND chip ··· 650 593 * @options: stores various chip bit options 651 594 * @id_len: The valid length of the @id. 652 595 * @oobsize: OOB size 596 + * @ecc.strength_ds: The ECC correctability from the datasheet, same as the 597 + * @ecc_strength_ds in nand_chip{}. 598 + * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the 599 + * @ecc_step_ds in nand_chip{}, also from the datasheet. 600 + * For example, the "4bit ECC for each 512Byte" can be set with 601 + * NAND_ECC_INFO(4, 512). 653 602 */ 654 603 struct nand_flash_dev { 655 604 char *name; ··· 672 609 unsigned int options; 673 610 uint16_t id_len; 674 611 uint16_t oobsize; 612 + struct { 613 + uint16_t strength_ds; 614 + uint16_t step_ds; 615 + } ecc; 675 616 }; 676 617 677 618 /** ··· 692 625 extern struct nand_manufacturers nand_manuf_ids[]; 693 626 694 627 extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd); 695 - extern int nand_update_bbt(struct mtd_info *mtd, loff_t offs); 696 628 extern int nand_default_bbt(struct mtd_info *mtd); 629 + extern int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); 697 630 extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt); 698 631 extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, 699 632 int allowbbt); ··· 773 706 struct nand_chip *chip = mtd->priv; 774 707 775 708 return chip->priv; 709 + } 710 + 711 + /* return the supported features. */ 712 + static inline int onfi_feature(struct nand_chip *chip) 713 + { 714 + return chip->onfi_version ? le16_to_cpu(chip->onfi_params.features) : 0; 776 715 } 777 716 778 717 /* return the supported asynchronous timing mode. */
+4
include/linux/platform_data/atmel.h
··· 71 71 u8 on_flash_bbt; /* bbt on flash */ 72 72 struct mtd_partition *parts; 73 73 unsigned int num_parts; 74 + bool has_dma; /* support dma transfer */ 75 + 76 + /* default is false, only for at32ap7000 chip is true */ 77 + bool need_reset_workaround; 74 78 }; 75 79 76 80 /* Serial */
-13
include/linux/platform_data/mtd-nand-pxa3xx.h
··· 16 16 unsigned int tAR; /* ND_ALE low to ND_nRE low delay */ 17 17 }; 18 18 19 - struct pxa3xx_nand_cmdset { 20 - uint16_t read1; 21 - uint16_t read2; 22 - uint16_t program; 23 - uint16_t read_status; 24 - uint16_t read_id; 25 - uint16_t erase; 26 - uint16_t reset; 27 - uint16_t lock; 28 - uint16_t unlock; 29 - uint16_t lock_status; 30 - }; 31 - 32 19 struct pxa3xx_nand_flash { 33 20 char *name; 34 21 uint32_t chip_id;