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

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

Pull MTD update from Brian Norris:
"Sorry for delaying this a bit later than usual. There's one mild
regression from 3.16 that was noticed during the 3.17 cycle, and I
meant to send a fix for it along with this pull request. I'll
probably try to queue it up for a later pull request once I've had a
better look at it, hopefully by -rc2 at the latest.

Summary for this pull:

NAND
- Cleanup for Denali driver
- Atmel: add support for new page sizes
- Atmel: fix up 'raw' mode support
- Atmel: miscellaneous cleanups
- New timing mode helpers for non-ONFI NAND
- OMAP: allow driver to be (properly) built as a module
- bcm47xx: RESET support and other cleanups

SPI NOR
- Miscellaneous cleanups, to prepare framework for wider use (some
further work still pending)
- Compile-time configuration to select 4K vs. 64K support for flash
that support both (necessary for using UBIFS on some SPI NOR)

A few scattered code quality fixes, detected by Coverity

See the changesets for more"

* tag 'for-linus-20141015' of git://git.infradead.org/linux-mtd: (59 commits)
mtd: nand: omap: Correct CONFIG_MTD_NAND_OMAP_BCH help message
mtd: nand: Force omap_elm to be built as a module if omap2_nand is a module
mtd: move support for struct flash_platform_data into m25p80
mtd: spi-nor: add Kconfig option to disable 4K sectors
mtd: nand: Move ELM driver and rename as omap_elm
nand: omap2: Replace pr_err with dev_err
nand: omap2: Remove horrible ifdefs to fix module probe
mtd: nand: add Hynix's H27UCG8T2ATR-BC to nand_ids table
mtd: nand: support ONFI timing mode retrieval for non-ONFI NANDs
mtd: physmap_of: Add non-obsolete map_rom probe
mtd: physmap_of: Fix ROM support via OF
MAINTAINERS: add l2-mtd.git, 'next' tree for MTD
mtd: denali: fix indents and other trivial things
mtd: denali: remove unnecessary parentheses
mtd: denali: remove another set-but-unused variable
mtd: denali: fix include guard and license block of denali.h
mtd: nand: don't break long print messages
mtd: bcm47xxnflash: replace some magic numbers
mtd: bcm47xxnflash: NAND_CMD_RESET support
mtd: bcm47xxnflash: add cmd_ctrl handler
...

+757 -562
+2
Documentation/devicetree/bindings/mtd/atmel-nand.txt
··· 36 36 - reg : should specify the address and size used for NFC command registers, 37 37 NFC registers and NFC Sram. NFC Sram address and size can be absent 38 38 if don't want to use it. 39 + - clocks: phandle to the peripheral clock 39 40 - Optional properties: 40 41 - atmel,write-by-sram: boolean to enable NFC write by sram. 41 42 ··· 99 98 compatible = "atmel,sama5d3-nfc"; 100 99 #address-cells = <1>; 101 100 #size-cells = <1>; 101 + clocks = <&hsmc_clk> 102 102 reg = < 103 103 0x70000000 0x10000000 /* NFC Command Registers */ 104 104 0xffffc000 0x00000070 /* NFC HSMC regs */
+2 -2
Documentation/devicetree/bindings/mtd/mtd-physmap.txt
··· 4 4 file systems on embedded devices. 5 5 6 6 - compatible : should contain the specific model of mtd chip(s) 7 - used, if known, followed by either "cfi-flash", "jedec-flash" 8 - or "mtd-ram". 7 + used, if known, followed by either "cfi-flash", "jedec-flash", 8 + "mtd-ram" or "mtd-rom". 9 9 - reg : Address range(s) of the mtd chip(s) 10 10 It's possible to (optionally) define multiple "reg" tuples so that 11 11 non-identical chips can be described in one node.
+1
MAINTAINERS
··· 5992 5992 W: http://www.linux-mtd.infradead.org/ 5993 5993 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/ 5994 5994 T: git git://git.infradead.org/linux-mtd.git 5995 + T: git git://git.infradead.org/l2-mtd.git 5995 5996 S: Maintained 5996 5997 F: drivers/mtd/ 5997 5998 F: include/linux/mtd/
+2
arch/arm/mach-omap2/gpmc.c
··· 1440 1440 break; 1441 1441 } 1442 1442 1443 + gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child); 1444 + 1443 1445 val = of_get_nand_bus_width(child); 1444 1446 if (val == 16) 1445 1447 gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
+11
drivers/mtd/bcm47xxpart.c
··· 199 199 continue; 200 200 } 201 201 202 + /* 203 + * New (ARM?) devices may have NVRAM in some middle block. Last 204 + * block will be checked later, so skip it. 205 + */ 206 + if (offset != master->size - blocksize && 207 + buf[0x000 / 4] == NVRAM_HEADER) { 208 + bcm47xxpart_add_part(&parts[curr_part++], "nvram", 209 + offset, 0); 210 + continue; 211 + } 212 + 202 213 /* Read middle of the block */ 203 214 if (mtd_read(master, offset + 0x8000, 0x4, 204 215 &bytes_read, (uint8_t *)buf) < 0) {
+2
drivers/mtd/chips/cfi_cmdset_0002.c
··· 2033 2033 2034 2034 udelay(1); 2035 2035 } 2036 + 2037 + retries--; 2036 2038 } 2037 2039 2038 2040 /* the chip never became ready */
-1
drivers/mtd/devices/Makefile
··· 12 12 obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o 13 13 obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o 14 14 obj-$(CONFIG_MTD_M25P80) += m25p80.o 15 - obj-$(CONFIG_MTD_NAND_OMAP_BCH) += elm.o 16 15 obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o 17 16 obj-$(CONFIG_MTD_SST25L) += sst25l.o 18 17 obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o
+13 -13
drivers/mtd/devices/docg3.c
··· 1697 1697 1698 1698 switch (mode) { 1699 1699 case DOC_ASICMODE_RESET: 1700 - pos += seq_printf(s, "reset"); 1700 + pos += seq_puts(s, "reset"); 1701 1701 break; 1702 1702 case DOC_ASICMODE_NORMAL: 1703 - pos += seq_printf(s, "normal"); 1703 + pos += seq_puts(s, "normal"); 1704 1704 break; 1705 1705 case DOC_ASICMODE_POWERDOWN: 1706 - pos += seq_printf(s, "powerdown"); 1706 + pos += seq_puts(s, "powerdown"); 1707 1707 break; 1708 1708 } 1709 - pos += seq_printf(s, ")\n"); 1709 + pos += seq_puts(s, ")\n"); 1710 1710 return pos; 1711 1711 } 1712 1712 DEBUGFS_RO_ATTR(asic_mode, dbg_asicmode_show); ··· 1745 1745 pos += seq_printf(s, "Protection = 0x%02x (", 1746 1746 protect); 1747 1747 if (protect & DOC_PROTECT_FOUNDRY_OTP_LOCK) 1748 - pos += seq_printf(s, "FOUNDRY_OTP_LOCK,"); 1748 + pos += seq_puts(s, "FOUNDRY_OTP_LOCK,"); 1749 1749 if (protect & DOC_PROTECT_CUSTOMER_OTP_LOCK) 1750 - pos += seq_printf(s, "CUSTOMER_OTP_LOCK,"); 1750 + pos += seq_puts(s, "CUSTOMER_OTP_LOCK,"); 1751 1751 if (protect & DOC_PROTECT_LOCK_INPUT) 1752 - pos += seq_printf(s, "LOCK_INPUT,"); 1752 + pos += seq_puts(s, "LOCK_INPUT,"); 1753 1753 if (protect & DOC_PROTECT_STICKY_LOCK) 1754 - pos += seq_printf(s, "STICKY_LOCK,"); 1754 + pos += seq_puts(s, "STICKY_LOCK,"); 1755 1755 if (protect & DOC_PROTECT_PROTECTION_ENABLED) 1756 - pos += seq_printf(s, "PROTECTION ON,"); 1756 + pos += seq_puts(s, "PROTECTION ON,"); 1757 1757 if (protect & DOC_PROTECT_IPL_DOWNLOAD_LOCK) 1758 - pos += seq_printf(s, "IPL_DOWNLOAD_LOCK,"); 1758 + pos += seq_puts(s, "IPL_DOWNLOAD_LOCK,"); 1759 1759 if (protect & DOC_PROTECT_PROTECTION_ERROR) 1760 - pos += seq_printf(s, "PROTECT_ERR,"); 1760 + pos += seq_puts(s, "PROTECT_ERR,"); 1761 1761 else 1762 - pos += seq_printf(s, "NO_PROTECT_ERR"); 1763 - pos += seq_printf(s, ")\n"); 1762 + pos += seq_puts(s, "NO_PROTECT_ERR"); 1763 + pos += seq_puts(s, ")\n"); 1764 1764 1765 1765 pos += seq_printf(s, "DPS0 = 0x%02x : " 1766 1766 "Protected area [0x%x - 0x%x] : OTP=%d, READ=%d, "
drivers/mtd/devices/elm.c drivers/mtd/nand/omap_elm.c
+20 -2
drivers/mtd/devices/m25p80.c
··· 193 193 { 194 194 struct mtd_part_parser_data ppdata; 195 195 struct flash_platform_data *data; 196 + const struct spi_device_id *id = NULL; 196 197 struct m25p *flash; 197 198 struct spi_nor *nor; 198 199 enum read_mode mode = SPI_NOR_NORMAL; 199 200 int ret; 201 + 202 + data = dev_get_platdata(&spi->dev); 200 203 201 204 flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); 202 205 if (!flash) ··· 226 223 mode = SPI_NOR_QUAD; 227 224 else if (spi->mode & SPI_RX_DUAL) 228 225 mode = SPI_NOR_DUAL; 229 - ret = spi_nor_scan(nor, spi_get_device_id(spi), mode); 226 + 227 + if (data && data->name) 228 + flash->mtd.name = data->name; 229 + 230 + /* For some (historical?) reason many platforms provide two different 231 + * names in flash_platform_data: "name" and "type". Quite often name is 232 + * set to "m25p80" and then "type" provides a real chip name. 233 + * If that's the case, respect "type" and ignore a "name". 234 + */ 235 + if (data && data->type) 236 + id = spi_nor_match_id(data->type); 237 + 238 + /* If we didn't get name from platform, simply use "modalias". */ 239 + if (!id) 240 + id = spi_get_device_id(spi); 241 + 242 + ret = spi_nor_scan(nor, id, mode); 230 243 if (ret) 231 244 return ret; 232 245 233 - data = dev_get_platdata(&spi->dev); 234 246 ppdata.of_node = spi->dev.of_node; 235 247 236 248 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
+1 -1
drivers/mtd/maps/Kconfig
··· 249 249 250 250 config MTD_SOLUTIONENGINE 251 251 tristate "CFI Flash device mapped on Hitachi SolutionEngine" 252 - depends on SUPERH && SOLUTION_ENGINE && MTD_CFI && MTD_REDBOOT_PARTS 252 + depends on SOLUTION_ENGINE && MTD_CFI && MTD_REDBOOT_PARTS 253 253 help 254 254 This enables access to the flash chips on the Hitachi SolutionEngine and 255 255 similar boards. Say 'Y' if you are building a kernel for such a board.
+28 -14
drivers/mtd/maps/gpio-addr-flash.c
··· 99 99 * @from: flash offset to copy from 100 100 * @len: how much to copy 101 101 * 102 - * We rely on the MTD layer to chunk up copies such that a single request here 103 - * will not cross a window size. This allows us to only wiggle the GPIOs once 104 - * before falling back to a normal memcpy. Reading the higher layer code shows 105 - * that this is indeed the case, but add a BUG_ON() to future proof. 102 + * The "from" region may straddle more than one window, so toggle the GPIOs for 103 + * each window region before reading its data. 106 104 */ 107 105 static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 108 106 { 109 107 struct async_state *state = gf_map_info_to_state(map); 110 108 111 - gf_set_gpios(state, from); 109 + int this_len; 112 110 113 - /* BUG if operation crosses the win_size */ 114 - BUG_ON(!((from + len) % state->win_size <= (from + len))); 111 + while (len) { 112 + if ((from % state->win_size) + len > state->win_size) 113 + this_len = state->win_size - (from % state->win_size); 114 + else 115 + this_len = len; 115 116 116 - /* operation does not cross the win_size, so one shot it */ 117 - memcpy_fromio(to, map->virt + (from % state->win_size), len); 117 + gf_set_gpios(state, from); 118 + memcpy_fromio(to, map->virt + (from % state->win_size), 119 + this_len); 120 + len -= this_len; 121 + from += this_len; 122 + to += this_len; 123 + } 118 124 } 119 125 120 126 /** ··· 153 147 { 154 148 struct async_state *state = gf_map_info_to_state(map); 155 149 156 - gf_set_gpios(state, to); 150 + int this_len; 157 151 158 - /* BUG if operation crosses the win_size */ 159 - BUG_ON(!((to + len) % state->win_size <= (to + len))); 152 + while (len) { 153 + if ((to % state->win_size) + len > state->win_size) 154 + this_len = state->win_size - (to % state->win_size); 155 + else 156 + this_len = len; 160 157 161 - /* operation does not cross the win_size, so one shot it */ 162 - memcpy_toio(map->virt + (to % state->win_size), from, len); 158 + gf_set_gpios(state, to); 159 + memcpy_toio(map->virt + (to % state->win_size), from, len); 160 + 161 + len -= this_len; 162 + to += this_len; 163 + from += this_len; 164 + } 163 165 } 164 166 165 167 static const char * const part_probe_types[] = {
+1 -1
drivers/mtd/maps/pcmciamtd.c
··· 89 89 90 90 if (!pcmcia_dev_present(dev->p_dev)) { 91 91 pr_debug("device removed\n"); 92 - return 0; 92 + return NULL; 93 93 } 94 94 95 95 offset = to & ~(dev->win_size-1);
+5 -1
drivers/mtd/maps/physmap_of.c
··· 103 103 if (strcmp(of_probe, "ROM") != 0) 104 104 dev_warn(&dev->dev, "obsolete_probe: don't know probe " 105 105 "type '%s', mapping as rom\n", of_probe); 106 - return do_map_probe("mtd_rom", map); 106 + return do_map_probe("map_rom", map); 107 107 } 108 108 } 109 109 ··· 338 338 { 339 339 .compatible = "mtd-ram", 340 340 .data = (void *)"map_ram", 341 + }, 342 + { 343 + .compatible = "mtd-rom", 344 + .data = (void *)"map_rom", 341 345 }, 342 346 { 343 347 .type = "rom",
+3
drivers/mtd/mtdchar.c
··· 549 549 if (mtd_is_partition(mtd)) 550 550 return -EINVAL; 551 551 552 + /* Sanitize user input */ 553 + p.devname[BLKPG_DEVNAMELTH - 1] = '\0'; 554 + 552 555 return mtd_add_partition(mtd, p.devname, p.start, p.length); 553 556 554 557 case BLKPG_DEL_PARTITION:
+18 -21
drivers/mtd/mtdcore.c
··· 105 105 */ 106 106 static void mtd_release(struct device *dev) 107 107 { 108 - struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev); 108 + struct mtd_info *mtd = dev_get_drvdata(dev); 109 109 dev_t index = MTD_DEVT(mtd->index); 110 110 111 - /* remove /dev/mtdXro node if needed */ 112 - if (index) 113 - device_destroy(&mtd_class, index + 1); 111 + /* remove /dev/mtdXro node */ 112 + device_destroy(&mtd_class, index + 1); 114 113 } 115 114 116 115 static int mtd_cls_suspend(struct device *dev, pm_message_t state) ··· 441 442 if (device_register(&mtd->dev) != 0) 442 443 goto fail_added; 443 444 444 - if (MTD_DEVT(i)) 445 - device_create(&mtd_class, mtd->dev.parent, 446 - MTD_DEVT(i) + 1, 447 - NULL, "mtd%dro", i); 445 + device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL, 446 + "mtd%dro", i); 448 447 449 448 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name); 450 449 /* No need to get a refcount on the module containing ··· 775 778 */ 776 779 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) 777 780 { 778 - if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) 781 + if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr) 779 782 return -EINVAL; 780 783 if (!(mtd->flags & MTD_WRITEABLE)) 781 784 return -EROFS; ··· 801 804 *phys = 0; 802 805 if (!mtd->_point) 803 806 return -EOPNOTSUPP; 804 - if (from < 0 || from > mtd->size || len > mtd->size - from) 807 + if (from < 0 || from >= mtd->size || len > mtd->size - from) 805 808 return -EINVAL; 806 809 if (!len) 807 810 return 0; ··· 814 817 { 815 818 if (!mtd->_point) 816 819 return -EOPNOTSUPP; 817 - if (from < 0 || from > mtd->size || len > mtd->size - from) 820 + if (from < 0 || from >= mtd->size || len > mtd->size - from) 818 821 return -EINVAL; 819 822 if (!len) 820 823 return 0; ··· 832 835 { 833 836 if (!mtd->_get_unmapped_area) 834 837 return -EOPNOTSUPP; 835 - if (offset > mtd->size || len > mtd->size - offset) 838 + if (offset >= mtd->size || len > mtd->size - offset) 836 839 return -EINVAL; 837 840 return mtd->_get_unmapped_area(mtd, len, offset, flags); 838 841 } ··· 843 846 { 844 847 int ret_code; 845 848 *retlen = 0; 846 - if (from < 0 || from > mtd->size || len > mtd->size - from) 849 + if (from < 0 || from >= mtd->size || len > mtd->size - from) 847 850 return -EINVAL; 848 851 if (!len) 849 852 return 0; ··· 866 869 const u_char *buf) 867 870 { 868 871 *retlen = 0; 869 - if (to < 0 || to > mtd->size || len > mtd->size - to) 872 + if (to < 0 || to >= mtd->size || len > mtd->size - to) 870 873 return -EINVAL; 871 874 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE)) 872 875 return -EROFS; ··· 889 892 *retlen = 0; 890 893 if (!mtd->_panic_write) 891 894 return -EOPNOTSUPP; 892 - if (to < 0 || to > mtd->size || len > mtd->size - to) 895 + if (to < 0 || to >= mtd->size || len > mtd->size - to) 893 896 return -EINVAL; 894 897 if (!(mtd->flags & MTD_WRITEABLE)) 895 898 return -EROFS; ··· 1008 1011 { 1009 1012 if (!mtd->_lock) 1010 1013 return -EOPNOTSUPP; 1011 - if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 1014 + if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) 1012 1015 return -EINVAL; 1013 1016 if (!len) 1014 1017 return 0; ··· 1020 1023 { 1021 1024 if (!mtd->_unlock) 1022 1025 return -EOPNOTSUPP; 1023 - if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 1026 + if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) 1024 1027 return -EINVAL; 1025 1028 if (!len) 1026 1029 return 0; ··· 1032 1035 { 1033 1036 if (!mtd->_is_locked) 1034 1037 return -EOPNOTSUPP; 1035 - if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) 1038 + if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs) 1036 1039 return -EINVAL; 1037 1040 if (!len) 1038 1041 return 0; ··· 1042 1045 1043 1046 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs) 1044 1047 { 1045 - if (ofs < 0 || ofs > mtd->size) 1048 + if (ofs < 0 || ofs >= mtd->size) 1046 1049 return -EINVAL; 1047 1050 if (!mtd->_block_isreserved) 1048 1051 return 0; ··· 1052 1055 1053 1056 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) 1054 1057 { 1055 - if (ofs < 0 || ofs > mtd->size) 1058 + if (ofs < 0 || ofs >= mtd->size) 1056 1059 return -EINVAL; 1057 1060 if (!mtd->_block_isbad) 1058 1061 return 0; ··· 1064 1067 { 1065 1068 if (!mtd->_block_markbad) 1066 1069 return -EOPNOTSUPP; 1067 - if (ofs < 0 || ofs > mtd->size) 1070 + if (ofs < 0 || ofs >= mtd->size) 1068 1071 return -EINVAL; 1069 1072 if (!(mtd->flags & MTD_WRITEABLE)) 1070 1073 return -EROFS;
+4 -4
drivers/mtd/mtdswap.c
··· 145 145 struct mtdswap_oobdata { 146 146 __le16 magic; 147 147 __le32 count; 148 - } __attribute__((packed)); 148 + } __packed; 149 149 150 150 #define MTDSWAP_MAGIC_CLEAN 0x2095 151 151 #define MTDSWAP_MAGIC_DIRTY (MTDSWAP_MAGIC_CLEAN + 1) ··· 1287 1287 1288 1288 seq_printf(s, "total erasures: %lu\n", sum); 1289 1289 1290 - seq_printf(s, "\n"); 1290 + seq_puts(s, "\n"); 1291 1291 1292 1292 seq_printf(s, "mtdswap_readsect count: %llu\n", d->sect_read_count); 1293 1293 seq_printf(s, "mtdswap_writesect count: %llu\n", d->sect_write_count); ··· 1296 1296 seq_printf(s, "mtd write count: %llu\n", d->mtd_write_count); 1297 1297 seq_printf(s, "discarded pages count: %llu\n", d->discard_page_count); 1298 1298 1299 - seq_printf(s, "\n"); 1299 + seq_puts(s, "\n"); 1300 1300 seq_printf(s, "total pages: %u\n", pages); 1301 1301 seq_printf(s, "pages mapped: %u\n", mapped); 1302 1302 ··· 1474 1474 } 1475 1475 1476 1476 eblocks = mtd_div_by_eb(use_size, mtd); 1477 - use_size = eblocks * mtd->erasesize; 1477 + use_size = (uint64_t)eblocks * mtd->erasesize; 1478 1478 bad_blocks = mtdswap_badblocks(mtd, use_size); 1479 1479 eavailable = eblocks - bad_blocks; 1480 1480
+5 -2
drivers/mtd/nand/Kconfig
··· 96 96 97 97 config MTD_NAND_OMAP_BCH 98 98 depends on MTD_NAND_OMAP2 99 - tristate "Support hardware based BCH error correction" 99 + bool "Support hardware based BCH error correction" 100 100 default n 101 101 select BCH 102 102 help ··· 104 104 locate and correct errors when using BCH ECC scheme. This offloads 105 105 the cpu from doing ECC error searching and correction. However some 106 106 legacy OMAP families like OMAP2xxx, OMAP3xxx do not have ELM engine 107 - so they should not enable this config symbol. 107 + so this is optional for them. 108 + 109 + config MTD_NAND_OMAP_BCH_BUILD 110 + def_tristate MTD_NAND_OMAP2 && MTD_NAND_OMAP_BCH 108 111 109 112 config MTD_NAND_IDS 110 113 tristate
+1
drivers/mtd/nand/Makefile
··· 27 27 obj-$(CONFIG_MTD_NAND_ATMEL) += atmel_nand.o 28 28 obj-$(CONFIG_MTD_NAND_GPIO) += gpio.o 29 29 obj-$(CONFIG_MTD_NAND_OMAP2) += omap2.o 30 + obj-$(CONFIG_MTD_NAND_OMAP_BCH_BUILD) += omap_elm.o 30 31 obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o 31 32 obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o 32 33 obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o
+58 -38
drivers/mtd/nand/atmel_nand.c
··· 27 27 * 28 28 */ 29 29 30 + #include <linux/clk.h> 30 31 #include <linux/dma-mapping.h> 31 32 #include <linux/slab.h> 32 33 #include <linux/module.h> ··· 97 96 bool use_nfc_sram; 98 97 bool write_by_sram; 99 98 99 + struct clk *clk; 100 + 100 101 bool is_initialized; 101 102 struct completion comp_ready; 102 103 struct completion comp_cmd_done; ··· 131 128 u32 pmecc_lookup_table_offset_512; 132 129 u32 pmecc_lookup_table_offset_1024; 133 130 134 - int pmecc_bytes_per_sector; 135 - int pmecc_sector_number; 136 131 int pmecc_degree; /* Degree of remainders */ 137 132 int pmecc_cw_len; /* Length of codeword */ 138 133 ··· 842 841 pos, bit_pos, err_byte, *(buf + byte_pos)); 843 842 } else { 844 843 /* Bit flip in OOB area */ 845 - tmp = sector_num * host->pmecc_bytes_per_sector 844 + tmp = sector_num * nand_chip->ecc.bytes 846 845 + (byte_pos - sector_size); 847 846 err_byte = ecc[tmp]; 848 847 ecc[tmp] ^= (1 << bit_pos); ··· 875 874 return 0; 876 875 877 876 normal_check: 878 - for (i = 0; i < host->pmecc_sector_number; i++) { 877 + for (i = 0; i < nand_chip->ecc.steps; i++) { 879 878 err_nbr = 0; 880 879 if (pmecc_stat & 0x1) { 881 880 buf_pos = buf + i * host->pmecc_sector_size; ··· 891 890 return -EIO; 892 891 } else { 893 892 pmecc_correct_data(mtd, buf_pos, ecc, i, 894 - host->pmecc_bytes_per_sector, err_nbr); 893 + nand_chip->ecc.bytes, err_nbr); 895 894 mtd->ecc_stats.corrected += err_nbr; 896 895 total_err += err_nbr; 897 896 } ··· 985 984 cpu_relax(); 986 985 } 987 986 988 - for (i = 0; i < host->pmecc_sector_number; i++) { 989 - for (j = 0; j < host->pmecc_bytes_per_sector; j++) { 987 + for (i = 0; i < chip->ecc.steps; i++) { 988 + for (j = 0; j < chip->ecc.bytes; j++) { 990 989 int pos; 991 990 992 - pos = i * host->pmecc_bytes_per_sector + j; 991 + pos = i * chip->ecc.bytes + j; 993 992 chip->oob_poi[eccpos[pos]] = 994 993 pmecc_readb_ecc_relaxed(host->ecc, i, j); 995 994 } ··· 1032 1031 else if (host->pmecc_sector_size == 1024) 1033 1032 val |= PMECC_CFG_SECTOR1024; 1034 1033 1035 - switch (host->pmecc_sector_number) { 1034 + switch (nand_chip->ecc.steps) { 1036 1035 case 1: 1037 1036 val |= PMECC_CFG_PAGE_1SECTOR; 1038 1037 break; ··· 1149 1148 1150 1149 host->ecc = devm_ioremap_resource(&pdev->dev, regs); 1151 1150 if (IS_ERR(host->ecc)) { 1152 - dev_err(host->dev, "ioremap failed\n"); 1153 1151 err_no = PTR_ERR(host->ecc); 1154 1152 goto err; 1155 1153 } ··· 1156 1156 regs_pmerr = platform_get_resource(pdev, IORESOURCE_MEM, 2); 1157 1157 host->pmerrloc_base = devm_ioremap_resource(&pdev->dev, regs_pmerr); 1158 1158 if (IS_ERR(host->pmerrloc_base)) { 1159 - dev_err(host->dev, 1160 - "Can not get I/O resource for PMECC ERRLOC controller!\n"); 1161 1159 err_no = PTR_ERR(host->pmerrloc_base); 1162 1160 goto err; 1163 1161 } ··· 1163 1165 regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3); 1164 1166 host->pmecc_rom_base = devm_ioremap_resource(&pdev->dev, regs_rom); 1165 1167 if (IS_ERR(host->pmecc_rom_base)) { 1166 - dev_err(host->dev, "Can not get I/O resource for ROM!\n"); 1167 1168 err_no = PTR_ERR(host->pmecc_rom_base); 1168 1169 goto err; 1169 1170 } ··· 1171 1174 1172 1175 /* set ECC page size and oob layout */ 1173 1176 switch (mtd->writesize) { 1177 + case 512: 1178 + case 1024: 1174 1179 case 2048: 1180 + case 4096: 1181 + case 8192: 1182 + if (sector_size > mtd->writesize) { 1183 + dev_err(host->dev, "pmecc sector size is bigger than the page size!\n"); 1184 + err_no = -EINVAL; 1185 + goto err; 1186 + } 1187 + 1175 1188 host->pmecc_degree = (sector_size == 512) ? 1176 1189 PMECC_GF_DIMENSION_13 : PMECC_GF_DIMENSION_14; 1177 1190 host->pmecc_cw_len = (1 << host->pmecc_degree) - 1; 1178 - host->pmecc_sector_number = mtd->writesize / sector_size; 1179 - host->pmecc_bytes_per_sector = pmecc_get_ecc_bytes( 1180 - cap, sector_size); 1181 1191 host->pmecc_alpha_to = pmecc_get_alpha_to(host); 1182 1192 host->pmecc_index_of = host->pmecc_rom_base + 1183 1193 host->pmecc_lookup_table_offset; 1184 1194 1185 - nand_chip->ecc.steps = host->pmecc_sector_number; 1186 1195 nand_chip->ecc.strength = cap; 1187 - nand_chip->ecc.bytes = host->pmecc_bytes_per_sector; 1188 - nand_chip->ecc.total = host->pmecc_bytes_per_sector * 1189 - host->pmecc_sector_number; 1196 + nand_chip->ecc.bytes = pmecc_get_ecc_bytes(cap, sector_size); 1197 + nand_chip->ecc.steps = mtd->writesize / sector_size; 1198 + nand_chip->ecc.total = nand_chip->ecc.bytes * 1199 + nand_chip->ecc.steps; 1190 1200 if (nand_chip->ecc.total > mtd->oobsize - 2) { 1191 1201 dev_err(host->dev, "No room for ECC bytes\n"); 1192 1202 err_no = -EINVAL; ··· 1205 1201 1206 1202 nand_chip->ecc.layout = &atmel_pmecc_oobinfo; 1207 1203 break; 1208 - case 512: 1209 - case 1024: 1210 - case 4096: 1211 - /* TODO */ 1204 + default: 1212 1205 dev_warn(host->dev, 1213 1206 "Unsupported page size for PMECC, use Software ECC\n"); 1214 - default: 1215 1207 /* page size not handled by HW ECC */ 1216 1208 /* switching back to soft ECC */ 1217 1209 nand_chip->ecc.mode = NAND_ECC_SOFT; ··· 1530 1530 } 1531 1531 1532 1532 host->ecc = devm_ioremap_resource(&pdev->dev, regs); 1533 - if (IS_ERR(host->ecc)) { 1534 - dev_err(host->dev, "ioremap failed\n"); 1533 + if (IS_ERR(host->ecc)) 1535 1534 return PTR_ERR(host->ecc); 1536 - } 1537 1535 1538 1536 /* ECC is calculated for the whole page (1 step) */ 1539 1537 nand_chip->ecc.size = mtd->writesize; ··· 1905 1907 if (offset || (data_len < mtd->writesize)) 1906 1908 return -EINVAL; 1907 1909 1908 - cfg = nfc_readl(host->nfc->hsmc_regs, CFG); 1909 1910 len = mtd->writesize; 1910 - 1911 - if (unlikely(raw)) { 1912 - len += mtd->oobsize; 1913 - nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE); 1914 - } else 1915 - nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE); 1916 - 1917 1911 /* Copy page data to sram that will write to nand via NFC */ 1918 1912 if (use_dma) { 1919 1913 if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0) ··· 1913 1923 memcpy32_toio(sram, buf, len); 1914 1924 } else { 1915 1925 memcpy32_toio(sram, buf, len); 1926 + } 1927 + 1928 + cfg = nfc_readl(host->nfc->hsmc_regs, CFG); 1929 + if (unlikely(raw) && oob_required) { 1930 + memcpy32_toio(sram + len, chip->oob_poi, mtd->oobsize); 1931 + len += mtd->oobsize; 1932 + nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE); 1933 + } else { 1934 + nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE); 1916 1935 } 1917 1936 1918 1937 if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc) ··· 2039 2040 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2040 2041 host->io_base = devm_ioremap_resource(&pdev->dev, mem); 2041 2042 if (IS_ERR(host->io_base)) { 2042 - dev_err(&pdev->dev, "atmel_nand: ioremap resource failed\n"); 2043 2043 res = PTR_ERR(host->io_base); 2044 2044 goto err_nand_ioremap; 2045 2045 } ··· 2097 2099 } 2098 2100 2099 2101 nand_chip->ecc.mode = host->board.ecc_mode; 2100 - nand_chip->chip_delay = 20; /* 20us command delay time */ 2102 + nand_chip->chip_delay = 40; /* 40us command delay time */ 2101 2103 2102 2104 if (host->board.bus_width_16) /* 16-bit bus width */ 2103 2105 nand_chip->options |= NAND_BUSWIDTH_16; ··· 2246 2248 { 2247 2249 struct atmel_nfc *nfc = &nand_nfc; 2248 2250 struct resource *nfc_cmd_regs, *nfc_hsmc_regs, *nfc_sram; 2251 + int ret; 2249 2252 2250 2253 nfc_cmd_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2251 2254 nfc->base_cmd_regs = devm_ioremap_resource(&pdev->dev, nfc_cmd_regs); ··· 2278 2279 nfc_writel(nfc->hsmc_regs, IDR, 0xffffffff); 2279 2280 nfc_readl(nfc->hsmc_regs, SR); /* clear the NFC_SR */ 2280 2281 2282 + nfc->clk = devm_clk_get(&pdev->dev, NULL); 2283 + if (!IS_ERR(nfc->clk)) { 2284 + ret = clk_prepare_enable(nfc->clk); 2285 + if (ret) 2286 + return ret; 2287 + } else { 2288 + dev_warn(&pdev->dev, "NFC clock missing, update your Device Tree"); 2289 + } 2290 + 2281 2291 nfc->is_initialized = true; 2282 2292 dev_info(&pdev->dev, "NFC is probed.\n"); 2293 + 2294 + return 0; 2295 + } 2296 + 2297 + static int atmel_nand_nfc_remove(struct platform_device *pdev) 2298 + { 2299 + struct atmel_nfc *nfc = &nand_nfc; 2300 + 2301 + if (!IS_ERR(nfc->clk)) 2302 + clk_disable_unprepare(nfc->clk); 2303 + 2283 2304 return 0; 2284 2305 } 2285 2306 ··· 2316 2297 .of_match_table = of_match_ptr(atmel_nand_nfc_match), 2317 2298 }, 2318 2299 .probe = atmel_nand_nfc_probe, 2300 + .remove = atmel_nand_nfc_remove, 2319 2301 }; 2320 2302 2321 2303 static struct platform_driver atmel_nand_driver = {
+49 -8
drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/slab.h> 17 + #include <linux/delay.h> 17 18 #include <linux/bcma/bcma.h> 18 19 19 20 /* Broadcom uses 1'000'000 but it seems to be too many. Tests on WNDR4500 has ··· 24 23 #define NFLASH_SECTOR_SIZE 512 25 24 26 25 #define NCTL_CMD0 0x00010000 26 + #define NCTL_COL 0x00020000 /* Update column with value from BCMA_CC_NFLASH_COL_ADDR */ 27 + #define NCTL_ROW 0x00040000 /* Update row (page) with value from BCMA_CC_NFLASH_ROW_ADDR */ 27 28 #define NCTL_CMD1W 0x00080000 28 29 #define NCTL_READ 0x00100000 29 30 #define NCTL_WRITE 0x00200000 ··· 112 109 b47n->curr_page_addr); 113 110 114 111 /* Prepare to read */ 115 - ctlcode = NCTL_CSA | NCTL_CMD1W | 0x00040000 | 0x00020000 | 112 + ctlcode = NCTL_CSA | NCTL_CMD1W | NCTL_ROW | NCTL_COL | 116 113 NCTL_CMD0; 117 114 ctlcode |= NAND_CMD_READSTART << 8; 118 115 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, ctlcode)) ··· 170 167 * NAND chip ops 171 168 **************************************************/ 172 169 170 + static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct mtd_info *mtd, int cmd, 171 + unsigned int ctrl) 172 + { 173 + struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 174 + struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 175 + u32 code = 0; 176 + 177 + if (cmd == NAND_CMD_NONE) 178 + return; 179 + 180 + if (cmd & NAND_CTRL_CLE) 181 + code = cmd | NCTL_CMD0; 182 + 183 + /* nCS is not needed for reset command */ 184 + if (cmd != NAND_CMD_RESET) 185 + code |= NCTL_CSA; 186 + 187 + bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, code); 188 + } 189 + 173 190 /* Default nand_select_chip calls cmd_ctrl, which is not used in BCM4706 */ 174 191 static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd, 175 192 int chip) 176 193 { 177 194 return; 195 + } 196 + 197 + static int bcm47xxnflash_ops_bcm4706_dev_ready(struct mtd_info *mtd) 198 + { 199 + struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 200 + struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 201 + 202 + return !!(bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_CTL) & NCTL_READY); 178 203 } 179 204 180 205 /* ··· 229 198 230 199 switch (command) { 231 200 case NAND_CMD_RESET: 232 - pr_warn("Chip reset not implemented yet\n"); 201 + nand_chip->cmd_ctrl(mtd, command, NAND_CTRL_CLE); 202 + 203 + ndelay(100); 204 + nand_wait_ready(mtd); 233 205 break; 234 206 case NAND_CMD_READID: 235 207 ctlcode = NCTL_CSA | 0x01000000 | NCTL_CMD1W | NCTL_CMD0; ··· 276 242 case NAND_CMD_ERASE1: 277 243 bcma_cc_write32(cc, BCMA_CC_NFLASH_ROW_ADDR, 278 244 b47n->curr_page_addr); 279 - ctlcode = 0x00040000 | NCTL_CMD1W | NCTL_CMD0 | 245 + ctlcode = NCTL_ROW | NCTL_CMD1W | NCTL_CMD0 | 280 246 NAND_CMD_ERASE1 | (NAND_CMD_ERASE2 << 8); 281 247 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, ctlcode)) 282 248 pr_err("ERASE1 failed\n"); ··· 291 257 b47n->curr_page_addr); 292 258 293 259 /* Prepare to write */ 294 - ctlcode = 0x40000000 | 0x00040000 | 0x00020000 | 0x00010000; 260 + ctlcode = 0x40000000 | NCTL_ROW | NCTL_COL | NCTL_CMD0; 295 261 ctlcode |= NAND_CMD_SEQIN; 296 262 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, ctlcode)) 297 263 pr_err("SEQIN failed\n"); 298 264 break; 299 265 case NAND_CMD_PAGEPROG: 300 - if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, 0x00010000 | 266 + if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, NCTL_CMD0 | 301 267 NAND_CMD_PAGEPROG)) 302 268 pr_err("PAGEPROG failed\n"); 303 269 if (bcm47xxnflash_ops_bcm4706_poll(cc)) ··· 375 341 376 342 int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) 377 343 { 344 + struct nand_chip *nand_chip = (struct nand_chip *)&b47n->nand_chip; 378 345 int err; 379 346 u32 freq; 380 347 u16 clock; ··· 386 351 u32 val; 387 352 388 353 b47n->nand_chip.select_chip = bcm47xxnflash_ops_bcm4706_select_chip; 354 + nand_chip->cmd_ctrl = bcm47xxnflash_ops_bcm4706_cmd_ctrl; 355 + nand_chip->dev_ready = bcm47xxnflash_ops_bcm4706_dev_ready; 389 356 b47n->nand_chip.cmdfunc = bcm47xxnflash_ops_bcm4706_cmdfunc; 390 357 b47n->nand_chip.read_byte = bcm47xxnflash_ops_bcm4706_read_byte; 391 358 b47n->nand_chip.read_buf = bcm47xxnflash_ops_bcm4706_read_buf; 392 359 b47n->nand_chip.write_buf = bcm47xxnflash_ops_bcm4706_write_buf; 360 + 361 + nand_chip->chip_delay = 50; 393 362 b47n->nand_chip.bbt_options = NAND_BBT_USE_FLASH; 394 363 b47n->nand_chip.ecc.mode = NAND_ECC_NONE; /* TODO: implement ECC */ 395 364 ··· 403 364 404 365 /* Configure wait counters */ 405 366 if (b47n->cc->status & BCMA_CC_CHIPST_4706_PKG_OPTION) { 406 - freq = 100000000; 367 + /* 400 MHz */ 368 + freq = 400000000 / 4; 407 369 } else { 408 370 freq = bcma_chipco_pll_read(b47n->cc, 4); 409 - freq = (freq * 0xFFF) >> 3; 410 - freq = (freq * 25000000) >> 3; 371 + freq = (freq & 0xFFF) >> 3; 372 + /* Fixed reference clock 25 MHz and m = 2 */ 373 + freq = (freq * 25000000 / 2) / 4; 411 374 } 412 375 clock = freq / 1000000; 413 376 w0 = bcm47xxnflash_ops_bcm4706_ns_to_cycle(15, clock);
+303 -260
drivers/mtd/nand/denali.c
··· 29 29 30 30 MODULE_LICENSE("GPL"); 31 31 32 - /* We define a module parameter that allows the user to override 32 + /* 33 + * We define a module parameter that allows the user to override 33 34 * the hardware and decide what timing mode should be used. 34 35 */ 35 36 #define NAND_DEFAULT_TIMINGS -1 36 37 37 38 static int onfi_timing_mode = NAND_DEFAULT_TIMINGS; 38 39 module_param(onfi_timing_mode, int, S_IRUGO); 39 - MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting." 40 - " -1 indicates use default timings"); 40 + MODULE_PARM_DESC(onfi_timing_mode, 41 + "Overrides default ONFI setting. -1 indicates use default timings"); 41 42 42 43 #define DENALI_NAND_NAME "denali-nand" 43 44 44 - /* We define a macro here that combines all interrupts this driver uses into 45 - * a single constant value, for convenience. */ 45 + /* 46 + * We define a macro here that combines all interrupts this driver uses into 47 + * a single constant value, for convenience. 48 + */ 46 49 #define DENALI_IRQ_ALL (INTR_STATUS__DMA_CMD_COMP | \ 47 50 INTR_STATUS__ECC_TRANSACTION_DONE | \ 48 51 INTR_STATUS__ECC_ERR | \ ··· 57 54 INTR_STATUS__RST_COMP | \ 58 55 INTR_STATUS__ERASE_COMP) 59 56 60 - /* indicates whether or not the internal value for the flash bank is 61 - * valid or not */ 57 + /* 58 + * indicates whether or not the internal value for the flash bank is 59 + * valid or not 60 + */ 62 61 #define CHIP_SELECT_INVALID -1 63 62 64 63 #define SUPPORT_8BITECC 1 65 64 66 - /* This macro divides two integers and rounds fractional values up 67 - * to the nearest integer value. */ 65 + /* 66 + * This macro divides two integers and rounds fractional values up 67 + * to the nearest integer value. 68 + */ 68 69 #define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y))) 69 70 70 - /* this macro allows us to convert from an MTD structure to our own 71 + /* 72 + * this macro allows us to convert from an MTD structure to our own 71 73 * device context (denali) structure. 72 74 */ 73 75 #define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd) 74 76 75 - /* These constants are defined by the driver to enable common driver 76 - * configuration options. */ 77 + /* 78 + * These constants are defined by the driver to enable common driver 79 + * configuration options. 80 + */ 77 81 #define SPARE_ACCESS 0x41 78 82 #define MAIN_ACCESS 0x42 79 83 #define MAIN_SPARE_ACCESS 0x43 84 + #define PIPELINE_ACCESS 0x2000 80 85 81 86 #define DENALI_READ 0 82 87 #define DENALI_WRITE 0x100 ··· 94 83 #define ADDR_CYCLE 1 95 84 #define STATUS_CYCLE 2 96 85 97 - /* this is a helper macro that allows us to 98 - * format the bank into the proper bits for the controller */ 86 + /* 87 + * this is a helper macro that allows us to 88 + * format the bank into the proper bits for the controller 89 + */ 99 90 #define BANK(x) ((x) << 24) 100 91 101 92 /* forward declarations */ ··· 108 95 uint32_t int_mask); 109 96 static uint32_t read_interrupt_status(struct denali_nand_info *denali); 110 97 111 - /* Certain operations for the denali NAND controller use 112 - * an indexed mode to read/write data. The operation is 113 - * performed by writing the address value of the command 114 - * to the device memory followed by the data. This function 98 + /* 99 + * Certain operations for the denali NAND controller use an indexed mode to 100 + * read/write data. The operation is performed by writing the address value 101 + * of the command to the device memory followed by the data. This function 115 102 * abstracts this common operation. 116 - */ 103 + */ 117 104 static void index_addr(struct denali_nand_info *denali, 118 105 uint32_t address, uint32_t data) 119 106 { ··· 129 116 *pdata = ioread32(denali->flash_mem + 0x10); 130 117 } 131 118 132 - /* We need to buffer some data for some of the NAND core routines. 133 - * The operations manage buffering that data. */ 119 + /* 120 + * We need to buffer some data for some of the NAND core routines. 121 + * The operations manage buffering that data. 122 + */ 134 123 static void reset_buf(struct denali_nand_info *denali) 135 124 { 136 125 denali->buf.head = denali->buf.tail = 0; ··· 146 131 /* reads the status of the device */ 147 132 static void read_status(struct denali_nand_info *denali) 148 133 { 149 - uint32_t cmd = 0x0; 134 + uint32_t cmd; 150 135 151 136 /* initialize the data buffer to store status */ 152 137 reset_buf(denali); ··· 161 146 /* resets a specific device connected to the core */ 162 147 static void reset_bank(struct denali_nand_info *denali) 163 148 { 164 - uint32_t irq_status = 0; 165 - uint32_t irq_mask = INTR_STATUS__RST_COMP | 166 - INTR_STATUS__TIME_OUT; 149 + uint32_t irq_status; 150 + uint32_t irq_mask = INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT; 167 151 168 152 clear_interrupts(denali); 169 153 ··· 177 163 /* Reset the flash controller */ 178 164 static uint16_t denali_nand_reset(struct denali_nand_info *denali) 179 165 { 180 - uint32_t i; 166 + int i; 181 167 182 168 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 183 - __FILE__, __LINE__, __func__); 169 + __FILE__, __LINE__, __func__); 184 170 185 - for (i = 0 ; i < denali->max_banks; i++) 171 + for (i = 0; i < denali->max_banks; i++) 186 172 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT, 187 173 denali->flash_reg + INTR_STATUS(i)); 188 174 189 - for (i = 0 ; i < denali->max_banks; i++) { 175 + for (i = 0; i < denali->max_banks; i++) { 190 176 iowrite32(1 << i, denali->flash_reg + DEVICE_RESET); 191 - while (!(ioread32(denali->flash_reg + 192 - INTR_STATUS(i)) & 177 + while (!(ioread32(denali->flash_reg + INTR_STATUS(i)) & 193 178 (INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT))) 194 179 cpu_relax(); 195 180 if (ioread32(denali->flash_reg + INTR_STATUS(i)) & ··· 199 186 200 187 for (i = 0; i < denali->max_banks; i++) 201 188 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT, 202 - denali->flash_reg + INTR_STATUS(i)); 189 + denali->flash_reg + INTR_STATUS(i)); 203 190 204 191 return PASS; 205 192 } 206 193 207 - /* this routine calculates the ONFI timing values for a given mode and 194 + /* 195 + * this routine calculates the ONFI timing values for a given mode and 208 196 * programs the clocking register accordingly. The mode is determined by 209 197 * the get_onfi_nand_para routine. 210 198 */ ··· 233 219 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt; 234 220 235 221 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 236 - __FILE__, __LINE__, __func__); 222 + __FILE__, __LINE__, __func__); 237 223 238 224 en_lo = CEIL_DIV(Trp[mode], CLK_X); 239 225 en_hi = CEIL_DIV(Treh[mode], CLK_X); ··· 253 239 254 240 data_invalid_rloh = (en_lo + en_hi) * CLK_X + Trloh[mode]; 255 241 256 - data_invalid = 257 - data_invalid_rhoh < 258 - data_invalid_rloh ? data_invalid_rhoh : data_invalid_rloh; 242 + data_invalid = data_invalid_rhoh < data_invalid_rloh ? 243 + data_invalid_rhoh : data_invalid_rloh; 259 244 260 245 dv_window = data_invalid - Trea[mode]; 261 246 ··· 264 251 265 252 acc_clks = CEIL_DIV(Trea[mode], CLK_X); 266 253 267 - while (((acc_clks * CLK_X) - Trea[mode]) < 3) 254 + while (acc_clks * CLK_X - Trea[mode] < 3) 268 255 acc_clks++; 269 256 270 - if ((data_invalid - acc_clks * CLK_X) < 2) 257 + if (data_invalid - acc_clks * CLK_X < 2) 271 258 dev_warn(denali->dev, "%s, Line %d: Warning!\n", 272 - __FILE__, __LINE__); 259 + __FILE__, __LINE__); 273 260 274 261 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X); 275 262 re_2_we = CEIL_DIV(Trhw[mode], CLK_X); ··· 282 269 cs_cnt = 1; 283 270 284 271 if (Tcea[mode]) { 285 - while (((cs_cnt * CLK_X) + Trea[mode]) < Tcea[mode]) 272 + while (cs_cnt * CLK_X + Trea[mode] < Tcea[mode]) 286 273 cs_cnt++; 287 274 } 288 275 ··· 292 279 #endif 293 280 294 281 /* Sighting 3462430: Temporary hack for MT29F128G08CJABAWP:B */ 295 - if ((ioread32(denali->flash_reg + MANUFACTURER_ID) == 0) && 296 - (ioread32(denali->flash_reg + DEVICE_ID) == 0x88)) 282 + if (ioread32(denali->flash_reg + MANUFACTURER_ID) == 0 && 283 + ioread32(denali->flash_reg + DEVICE_ID) == 0x88) 297 284 acc_clks = 6; 298 285 299 286 iowrite32(acc_clks, denali->flash_reg + ACC_CLKS); ··· 310 297 static uint16_t get_onfi_nand_para(struct denali_nand_info *denali) 311 298 { 312 299 int i; 313 - /* we needn't to do a reset here because driver has already 300 + 301 + /* 302 + * we needn't to do a reset here because driver has already 314 303 * reset all the banks before 315 - * */ 304 + */ 316 305 if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) & 317 306 ONFI_TIMING_MODE__VALUE)) 318 307 return FAIL; ··· 327 312 328 313 nand_onfi_timing_set(denali, i); 329 314 330 - /* By now, all the ONFI devices we know support the page cache */ 331 - /* rw feature. So here we enable the pipeline_rw_ahead feature */ 315 + /* 316 + * By now, all the ONFI devices we know support the page cache 317 + * rw feature. So here we enable the pipeline_rw_ahead feature 318 + */ 332 319 /* iowrite32(1, denali->flash_reg + CACHE_WRITE_ENABLE); */ 333 320 /* iowrite32(1, denali->flash_reg + CACHE_READ_ENABLE); */ 334 321 ··· 356 339 { 357 340 uint32_t tmp; 358 341 359 - /* Workaround to fix a controller bug which reports a wrong */ 360 - /* spare area size for some kind of Toshiba NAND device */ 342 + /* 343 + * Workaround to fix a controller bug which reports a wrong 344 + * spare area size for some kind of Toshiba NAND device 345 + */ 361 346 if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) && 362 347 (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) { 363 348 iowrite32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE); ··· 403 384 break; 404 385 default: 405 386 dev_warn(denali->dev, 406 - "Spectra: Unknown Hynix NAND (Device ID: 0x%x)." 407 - "Will use default parameter values instead.\n", 408 - device_id); 387 + "Spectra: Unknown Hynix NAND (Device ID: 0x%x).\n" 388 + "Will use default parameter values instead.\n", 389 + device_id); 409 390 } 410 391 } 411 392 412 - /* determines how many NAND chips are connected to the controller. Note for 393 + /* 394 + * determines how many NAND chips are connected to the controller. Note for 413 395 * Intel CE4100 devices we don't support more than one device. 414 396 */ 415 397 static void find_valid_banks(struct denali_nand_info *denali) ··· 420 400 421 401 denali->total_used_banks = 1; 422 402 for (i = 0; i < denali->max_banks; i++) { 423 - index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90); 424 - index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0); 425 - index_addr_read_data(denali, 426 - (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]); 403 + index_addr(denali, MODE_11 | (i << 24) | 0, 0x90); 404 + index_addr(denali, MODE_11 | (i << 24) | 1, 0); 405 + index_addr_read_data(denali, MODE_11 | (i << 24) | 2, &id[i]); 427 406 428 407 dev_dbg(denali->dev, 429 408 "Return 1st ID for bank[%d]: %x\n", i, id[i]); ··· 439 420 } 440 421 441 422 if (denali->platform == INTEL_CE4100) { 442 - /* Platform limitations of the CE4100 device limit 423 + /* 424 + * Platform limitations of the CE4100 device limit 443 425 * users to a single chip solution for NAND. 444 426 * Multichip support is not enabled. 445 427 */ 446 428 if (denali->total_used_banks != 1) { 447 429 dev_err(denali->dev, 448 - "Sorry, Intel CE4100 only supports " 449 - "a single NAND device.\n"); 430 + "Sorry, Intel CE4100 only supports a single NAND device.\n"); 450 431 BUG(); 451 432 } 452 433 } ··· 467 448 468 449 static void detect_partition_feature(struct denali_nand_info *denali) 469 450 { 470 - /* For MRST platform, denali->fwblks represent the 451 + /* 452 + * For MRST platform, denali->fwblks represent the 471 453 * number of blocks firmware is taken, 472 454 * FW is in protect partition and MTD driver has no 473 455 * permission to access it. So let driver know how many 474 456 * blocks it can't touch. 475 - * */ 457 + */ 476 458 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) { 477 459 if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) & 478 460 PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) { ··· 484 464 + 485 465 (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) & 486 466 MIN_BLK_ADDR__VALUE); 487 - } else 467 + } else { 488 468 denali->fwblks = SPECTRA_START_BLOCK; 489 - } else 469 + } 470 + } else { 490 471 denali->fwblks = SPECTRA_START_BLOCK; 472 + } 491 473 } 492 474 493 475 static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) 494 476 { 495 477 uint16_t status = PASS; 496 478 uint32_t id_bytes[8], addr; 497 - uint8_t i, maf_id, device_id; 479 + uint8_t maf_id, device_id; 480 + int i; 498 481 499 - dev_dbg(denali->dev, 500 - "%s, Line %d, Function: %s\n", 482 + dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 501 483 __FILE__, __LINE__, __func__); 502 484 503 - /* Use read id method to get device ID and other 504 - * params. For some NAND chips, controller can't 505 - * report the correct device ID by reading from 506 - * DEVICE_ID register 507 - * */ 508 - addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); 509 - index_addr(denali, (uint32_t)addr | 0, 0x90); 510 - index_addr(denali, (uint32_t)addr | 1, 0); 485 + /* 486 + * Use read id method to get device ID and other params. 487 + * For some NAND chips, controller can't report the correct 488 + * device ID by reading from DEVICE_ID register 489 + */ 490 + addr = MODE_11 | BANK(denali->flash_bank); 491 + index_addr(denali, addr | 0, 0x90); 492 + index_addr(denali, addr | 1, 0); 511 493 for (i = 0; i < 8; i++) 512 494 index_addr_read_data(denali, addr | 2, &id_bytes[i]); 513 495 maf_id = id_bytes[0]; ··· 528 506 } 529 507 530 508 dev_info(denali->dev, 531 - "Dump timing register values:" 509 + "Dump timing register values:\n" 532 510 "acc_clks: %d, re_2_we: %d, re_2_re: %d\n" 533 511 "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n" 534 512 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n", ··· 545 523 546 524 detect_partition_feature(denali); 547 525 548 - /* If the user specified to override the default timings 526 + /* 527 + * If the user specified to override the default timings 549 528 * with a specific ONFI mode, we apply those changes here. 550 529 */ 551 530 if (onfi_timing_mode != NAND_DEFAULT_TIMINGS) ··· 559 536 uint16_t INT_ENABLE) 560 537 { 561 538 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n", 562 - __FILE__, __LINE__, __func__); 539 + __FILE__, __LINE__, __func__); 563 540 564 541 if (INT_ENABLE) 565 542 iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE); ··· 567 544 iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE); 568 545 } 569 546 570 - /* validation function to verify that the controlling software is making 547 + /* 548 + * validation function to verify that the controlling software is making 571 549 * a valid request 572 550 */ 573 551 static inline bool is_flash_bank_valid(int flash_bank) 574 552 { 575 - return (flash_bank >= 0 && flash_bank < 4); 553 + return flash_bank >= 0 && flash_bank < 4; 576 554 } 577 555 578 556 static void denali_irq_init(struct denali_nand_info *denali) 579 557 { 580 - uint32_t int_mask = 0; 558 + uint32_t int_mask; 581 559 int i; 582 560 583 561 /* Disable global interrupts */ ··· 608 584 iowrite32(int_mask, denali->flash_reg + INTR_EN(i)); 609 585 } 610 586 611 - /* This function only returns when an interrupt that this driver cares about 587 + /* 588 + * This function only returns when an interrupt that this driver cares about 612 589 * occurs. This is to reduce the overhead of servicing interrupts 613 590 */ 614 591 static inline uint32_t denali_irq_detected(struct denali_nand_info *denali) ··· 621 596 static inline void clear_interrupt(struct denali_nand_info *denali, 622 597 uint32_t irq_mask) 623 598 { 624 - uint32_t intr_status_reg = 0; 599 + uint32_t intr_status_reg; 625 600 626 601 intr_status_reg = INTR_STATUS(denali->flash_bank); 627 602 ··· 630 605 631 606 static void clear_interrupts(struct denali_nand_info *denali) 632 607 { 633 - uint32_t status = 0x0; 608 + uint32_t status; 609 + 634 610 spin_lock_irq(&denali->irq_lock); 635 611 636 612 status = read_interrupt_status(denali); ··· 643 617 644 618 static uint32_t read_interrupt_status(struct denali_nand_info *denali) 645 619 { 646 - uint32_t intr_status_reg = 0; 620 + uint32_t intr_status_reg; 647 621 648 622 intr_status_reg = INTR_STATUS(denali->flash_bank); 649 623 650 624 return ioread32(denali->flash_reg + intr_status_reg); 651 625 } 652 626 653 - /* This is the interrupt service routine. It handles all interrupts 654 - * sent to this device. Note that on CE4100, this is a shared 655 - * interrupt. 627 + /* 628 + * This is the interrupt service routine. It handles all interrupts 629 + * sent to this device. Note that on CE4100, this is a shared interrupt. 656 630 */ 657 631 static irqreturn_t denali_isr(int irq, void *dev_id) 658 632 { 659 633 struct denali_nand_info *denali = dev_id; 660 - uint32_t irq_status = 0x0; 634 + uint32_t irq_status; 661 635 irqreturn_t result = IRQ_NONE; 662 636 663 637 spin_lock(&denali->irq_lock); 664 638 665 - /* check to see if a valid NAND chip has 666 - * been selected. 667 - */ 639 + /* check to see if a valid NAND chip has been selected. */ 668 640 if (is_flash_bank_valid(denali->flash_bank)) { 669 - /* check to see if controller generated 670 - * the interrupt, since this is a shared interrupt */ 641 + /* 642 + * check to see if controller generated the interrupt, 643 + * since this is a shared interrupt 644 + */ 671 645 irq_status = denali_irq_detected(denali); 672 646 if (irq_status != 0) { 673 647 /* handle interrupt */ 674 648 /* first acknowledge it */ 675 649 clear_interrupt(denali, irq_status); 676 - /* store the status in the device context for someone 677 - to read */ 650 + /* 651 + * store the status in the device context for someone 652 + * to read 653 + */ 678 654 denali->irq_status |= irq_status; 679 655 /* notify anyone who cares that it happened */ 680 656 complete(&denali->complete); ··· 691 663 692 664 static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask) 693 665 { 694 - unsigned long comp_res = 0; 695 - uint32_t intr_status = 0; 696 - bool retry = false; 666 + unsigned long comp_res; 667 + uint32_t intr_status; 697 668 unsigned long timeout = msecs_to_jiffies(1000); 698 669 699 670 do { ··· 706 679 spin_unlock_irq(&denali->irq_lock); 707 680 /* our interrupt was detected */ 708 681 break; 709 - } else { 710 - /* these are not the interrupts you are looking for - 711 - * need to wait again */ 712 - spin_unlock_irq(&denali->irq_lock); 713 - retry = true; 714 682 } 683 + 684 + /* 685 + * these are not the interrupts you are looking for - 686 + * need to wait again 687 + */ 688 + spin_unlock_irq(&denali->irq_lock); 715 689 } while (comp_res != 0); 716 690 717 691 if (comp_res == 0) { ··· 725 697 return intr_status; 726 698 } 727 699 728 - /* This helper function setups the registers for ECC and whether or not 729 - * the spare area will be transferred. */ 700 + /* 701 + * This helper function setups the registers for ECC and whether or not 702 + * the spare area will be transferred. 703 + */ 730 704 static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en, 731 705 bool transfer_spare) 732 706 { 733 - int ecc_en_flag = 0, transfer_spare_flag = 0; 707 + int ecc_en_flag, transfer_spare_flag; 734 708 735 709 /* set ECC, transfer spare bits if needed */ 736 710 ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0; ··· 740 710 741 711 /* Enable spare area/ECC per user's request. */ 742 712 iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE); 743 - iowrite32(transfer_spare_flag, 744 - denali->flash_reg + TRANSFER_SPARE_REG); 713 + iowrite32(transfer_spare_flag, denali->flash_reg + TRANSFER_SPARE_REG); 745 714 } 746 715 747 - /* sends a pipeline command operation to the controller. See the Denali NAND 716 + /* 717 + * sends a pipeline command operation to the controller. See the Denali NAND 748 718 * controller's user guide for more information (section 4.2.3.6). 749 719 */ 750 720 static int denali_send_pipeline_cmd(struct denali_nand_info *denali, 751 - bool ecc_en, 752 - bool transfer_spare, 753 - int access_type, 754 - int op) 721 + bool ecc_en, bool transfer_spare, 722 + int access_type, int op) 755 723 { 756 724 int status = PASS; 757 - uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0, 758 - irq_mask = 0; 725 + uint32_t page_count = 1; 726 + uint32_t addr, cmd, irq_status, irq_mask; 759 727 760 728 if (op == DENALI_READ) 761 729 irq_mask = INTR_STATUS__LOAD_COMP; ··· 764 736 765 737 setup_ecc_for_xfer(denali, ecc_en, transfer_spare); 766 738 767 - /* clear interrupts */ 768 739 clear_interrupts(denali); 769 740 770 741 addr = BANK(denali->flash_bank) | denali->page; ··· 774 747 } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) { 775 748 /* read spare area */ 776 749 cmd = MODE_10 | addr; 777 - index_addr(denali, (uint32_t)cmd, access_type); 750 + index_addr(denali, cmd, access_type); 778 751 779 752 cmd = MODE_01 | addr; 780 753 iowrite32(cmd, denali->flash_mem); 781 754 } else if (op == DENALI_READ) { 782 755 /* setup page read request for access type */ 783 756 cmd = MODE_10 | addr; 784 - index_addr(denali, (uint32_t)cmd, access_type); 757 + index_addr(denali, cmd, access_type); 785 758 786 - /* page 33 of the NAND controller spec indicates we should not 787 - use the pipeline commands in Spare area only mode. So we 788 - don't. 759 + /* 760 + * page 33 of the NAND controller spec indicates we should not 761 + * use the pipeline commands in Spare area only mode. 762 + * So we don't. 789 763 */ 790 764 if (access_type == SPARE_ACCESS) { 791 765 cmd = MODE_01 | addr; 792 766 iowrite32(cmd, denali->flash_mem); 793 767 } else { 794 - index_addr(denali, (uint32_t)cmd, 795 - 0x2000 | op | page_count); 768 + index_addr(denali, cmd, 769 + PIPELINE_ACCESS | op | page_count); 796 770 797 - /* wait for command to be accepted 771 + /* 772 + * wait for command to be accepted 798 773 * can always use status0 bit as the 799 - * mask is identical for each 800 - * bank. */ 774 + * mask is identical for each bank. 775 + */ 801 776 irq_status = wait_for_irq(denali, irq_mask); 802 777 803 778 if (irq_status == 0) { 804 779 dev_err(denali->dev, 805 - "cmd, page, addr on timeout " 806 - "(0x%x, 0x%x, 0x%x)\n", 807 - cmd, denali->page, addr); 780 + "cmd, page, addr on timeout (0x%x, 0x%x, 0x%x)\n", 781 + cmd, denali->page, addr); 808 782 status = FAIL; 809 783 } else { 810 784 cmd = MODE_01 | addr; ··· 818 790 819 791 /* helper function that simply writes a buffer to the flash */ 820 792 static int write_data_to_flash_mem(struct denali_nand_info *denali, 821 - const uint8_t *buf, 822 - int len) 793 + const uint8_t *buf, int len) 823 794 { 824 - uint32_t i = 0, *buf32; 795 + uint32_t *buf32; 796 + int i; 825 797 826 - /* verify that the len is a multiple of 4. see comment in 827 - * read_data_from_flash_mem() */ 798 + /* 799 + * verify that the len is a multiple of 4. 800 + * see comment in read_data_from_flash_mem() 801 + */ 828 802 BUG_ON((len % 4) != 0); 829 803 830 804 /* write the data to the flash memory */ 831 805 buf32 = (uint32_t *)buf; 832 806 for (i = 0; i < len / 4; i++) 833 807 iowrite32(*buf32++, denali->flash_mem + 0x10); 834 - return i*4; /* intent is to return the number of bytes read */ 808 + return i * 4; /* intent is to return the number of bytes read */ 835 809 } 836 810 837 811 /* helper function that simply reads a buffer from the flash */ 838 812 static int read_data_from_flash_mem(struct denali_nand_info *denali, 839 - uint8_t *buf, 840 - int len) 813 + uint8_t *buf, int len) 841 814 { 842 - uint32_t i = 0, *buf32; 815 + uint32_t *buf32; 816 + int i; 843 817 844 - /* we assume that len will be a multiple of 4, if not 845 - * it would be nice to know about it ASAP rather than 846 - * have random failures... 847 - * This assumption is based on the fact that this 848 - * function is designed to be used to read flash pages, 849 - * which are typically multiples of 4... 818 + /* 819 + * we assume that len will be a multiple of 4, if not it would be nice 820 + * to know about it ASAP rather than have random failures... 821 + * This assumption is based on the fact that this function is designed 822 + * to be used to read flash pages, which are typically multiples of 4. 850 823 */ 851 - 852 824 BUG_ON((len % 4) != 0); 853 825 854 826 /* transfer the data from the flash */ 855 827 buf32 = (uint32_t *)buf; 856 828 for (i = 0; i < len / 4; i++) 857 829 *buf32++ = ioread32(denali->flash_mem + 0x10); 858 - return i*4; /* intent is to return the number of bytes read */ 830 + return i * 4; /* intent is to return the number of bytes read */ 859 831 } 860 832 861 833 /* writes OOB data to the device */ 862 834 static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) 863 835 { 864 836 struct denali_nand_info *denali = mtd_to_denali(mtd); 865 - uint32_t irq_status = 0; 837 + uint32_t irq_status; 866 838 uint32_t irq_mask = INTR_STATUS__PROGRAM_COMP | 867 839 INTR_STATUS__PROGRAM_FAIL; 868 840 int status = 0; ··· 891 863 static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) 892 864 { 893 865 struct denali_nand_info *denali = mtd_to_denali(mtd); 894 - uint32_t irq_mask = INTR_STATUS__LOAD_COMP, 895 - irq_status = 0, addr = 0x0, cmd = 0x0; 866 + uint32_t irq_mask = INTR_STATUS__LOAD_COMP; 867 + uint32_t irq_status, addr, cmd; 896 868 897 869 denali->page = page; 898 870 ··· 900 872 DENALI_READ) == PASS) { 901 873 read_data_from_flash_mem(denali, buf, mtd->oobsize); 902 874 903 - /* wait for command to be accepted 904 - * can always use status0 bit as the mask is identical for each 905 - * bank. */ 875 + /* 876 + * wait for command to be accepted 877 + * can always use status0 bit as the 878 + * mask is identical for each bank. 879 + */ 906 880 irq_status = wait_for_irq(denali, irq_mask); 907 881 908 882 if (irq_status == 0) 909 883 dev_err(denali->dev, "page on OOB timeout %d\n", 910 884 denali->page); 911 885 912 - /* We set the device back to MAIN_ACCESS here as I observed 886 + /* 887 + * We set the device back to MAIN_ACCESS here as I observed 913 888 * instability with the controller if you do a block erase 914 889 * and the last transaction was a SPARE_ACCESS. Block erase 915 890 * is reliable (according to the MTD test infrastructure) ··· 920 889 */ 921 890 addr = BANK(denali->flash_bank) | denali->page; 922 891 cmd = MODE_10 | addr; 923 - index_addr(denali, (uint32_t)cmd, MAIN_ACCESS); 892 + index_addr(denali, cmd, MAIN_ACCESS); 924 893 } 925 894 } 926 895 927 - /* this function examines buffers to see if they contain data that 896 + /* 897 + * this function examines buffers to see if they contain data that 928 898 * indicate that the buffer is part of an erased region of flash. 929 899 */ 930 900 static bool is_erased(uint8_t *buf, int len) 931 901 { 932 - int i = 0; 902 + int i; 903 + 933 904 for (i = 0; i < len; i++) 934 905 if (buf[i] != 0xFF) 935 906 return false; ··· 954 921 955 922 if (irq_status & INTR_STATUS__ECC_ERR) { 956 923 /* read the ECC errors. we'll ignore them for now */ 957 - uint32_t err_address = 0, err_correction_info = 0; 958 - uint32_t err_byte = 0, err_sector = 0, err_device = 0; 959 - uint32_t err_correction_value = 0; 924 + uint32_t err_address, err_correction_info, err_byte, 925 + err_sector, err_device, err_correction_value; 960 926 denali_set_intr_modes(denali, false); 961 927 962 928 do { ··· 971 939 err_device = ECC_ERR_DEVICE(err_correction_info); 972 940 973 941 if (ECC_ERROR_CORRECTABLE(err_correction_info)) { 974 - /* If err_byte is larger than ECC_SECTOR_SIZE, 942 + /* 943 + * If err_byte is larger than ECC_SECTOR_SIZE, 975 944 * means error happened in OOB, so we ignore 976 945 * it. It's no need for us to correct it 977 946 * err_device is represented the NAND error 978 947 * bits are happened in if there are more 979 948 * than one NAND connected. 980 - * */ 949 + */ 981 950 if (err_byte < ECC_SECTOR_SIZE) { 982 951 int offset; 952 + 983 953 offset = (err_sector * 984 954 ECC_SECTOR_SIZE + 985 955 err_byte) * ··· 993 959 bitflips++; 994 960 } 995 961 } else { 996 - /* if the error is not correctable, need to 962 + /* 963 + * if the error is not correctable, need to 997 964 * look at the page to see if it is an erased 998 965 * page. if so, then it's not a real ECC error 999 - * */ 966 + */ 1000 967 check_erased_page = true; 1001 968 } 1002 969 } while (!ECC_LAST_ERR(err_correction_info)); 1003 - /* Once handle all ecc errors, controller will triger 970 + /* 971 + * Once handle all ecc errors, controller will triger 1004 972 * a ECC_TRANSACTION_DONE interrupt, so here just wait 1005 973 * for a while for this interrupt 1006 - * */ 974 + */ 1007 975 while (!(read_interrupt_status(denali) & 1008 976 INTR_STATUS__ECC_TRANSACTION_DONE)) 1009 977 cpu_relax(); ··· 1019 983 /* programs the controller to either enable/disable DMA transfers */ 1020 984 static void denali_enable_dma(struct denali_nand_info *denali, bool en) 1021 985 { 1022 - uint32_t reg_val = 0x0; 1023 - 1024 - if (en) 1025 - reg_val = DMA_ENABLE__FLAG; 1026 - 1027 - iowrite32(reg_val, denali->flash_reg + DMA_ENABLE); 986 + iowrite32(en ? DMA_ENABLE__FLAG : 0, denali->flash_reg + DMA_ENABLE); 1028 987 ioread32(denali->flash_reg + DMA_ENABLE); 1029 988 } 1030 989 1031 990 /* setups the HW to perform the data DMA */ 1032 991 static void denali_setup_dma(struct denali_nand_info *denali, int op) 1033 992 { 1034 - uint32_t mode = 0x0; 993 + uint32_t mode; 1035 994 const int page_count = 1; 1036 - dma_addr_t addr = denali->buf.dma_buf; 995 + uint32_t addr = denali->buf.dma_buf; 1037 996 1038 997 mode = MODE_10 | BANK(denali->flash_bank); 1039 998 ··· 1038 1007 index_addr(denali, mode | denali->page, 0x2000 | op | page_count); 1039 1008 1040 1009 /* 2. set memory high address bits 23:8 */ 1041 - index_addr(denali, mode | ((uint16_t)(addr >> 16) << 8), 0x2200); 1010 + index_addr(denali, mode | ((addr >> 16) << 8), 0x2200); 1042 1011 1043 1012 /* 3. set memory low address bits 23:8 */ 1044 - index_addr(denali, mode | ((uint16_t)addr << 8), 0x2300); 1013 + index_addr(denali, mode | ((addr & 0xff) << 8), 0x2300); 1045 1014 1046 - /* 4. interrupt when complete, burst len = 64 bytes*/ 1015 + /* 4. interrupt when complete, burst len = 64 bytes */ 1047 1016 index_addr(denali, mode | 0x14000, 0x2400); 1048 1017 } 1049 1018 1050 - /* writes a page. user specifies type, and this function handles the 1051 - * configuration details. */ 1019 + /* 1020 + * writes a page. user specifies type, and this function handles the 1021 + * configuration details. 1022 + */ 1052 1023 static int write_page(struct mtd_info *mtd, struct nand_chip *chip, 1053 1024 const uint8_t *buf, bool raw_xfer) 1054 1025 { 1055 1026 struct denali_nand_info *denali = mtd_to_denali(mtd); 1056 - 1057 1027 dma_addr_t addr = denali->buf.dma_buf; 1058 1028 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1059 - 1060 - uint32_t irq_status = 0; 1029 + uint32_t irq_status; 1061 1030 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP | 1062 1031 INTR_STATUS__PROGRAM_FAIL; 1063 1032 1064 - /* if it is a raw xfer, we want to disable ecc, and send 1065 - * the spare area. 1033 + /* 1034 + * if it is a raw xfer, we want to disable ecc and send the spare area. 1066 1035 * !raw_xfer - enable ecc 1067 1036 * raw_xfer - transfer spare 1068 1037 */ ··· 1089 1058 irq_status = wait_for_irq(denali, irq_mask); 1090 1059 1091 1060 if (irq_status == 0) { 1092 - dev_err(denali->dev, 1093 - "timeout on write_page (type = %d)\n", 1094 - raw_xfer); 1095 - denali->status = 1096 - (irq_status & INTR_STATUS__PROGRAM_FAIL) ? 1097 - NAND_STATUS_FAIL : PASS; 1061 + dev_err(denali->dev, "timeout on write_page (type = %d)\n", 1062 + raw_xfer); 1063 + denali->status = NAND_STATUS_FAIL; 1098 1064 } 1099 1065 1100 1066 denali_enable_dma(denali, false); ··· 1102 1074 1103 1075 /* NAND core entry points */ 1104 1076 1105 - /* this is the callback that the NAND core calls to write a page. Since 1077 + /* 1078 + * this is the callback that the NAND core calls to write a page. Since 1106 1079 * writing a page with ECC or without is similar, all the work is done 1107 1080 * by write_page above. 1108 - * */ 1081 + */ 1109 1082 static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1110 1083 const uint8_t *buf, int oob_required) 1111 1084 { 1112 - /* for regular page writes, we let HW handle all the ECC 1113 - * data written to the device. */ 1085 + /* 1086 + * for regular page writes, we let HW handle all the ECC 1087 + * data written to the device. 1088 + */ 1114 1089 return write_page(mtd, chip, buf, false); 1115 1090 } 1116 1091 1117 - /* This is the callback that the NAND core calls to write a page without ECC. 1092 + /* 1093 + * This is the callback that the NAND core calls to write a page without ECC. 1118 1094 * raw access is similar to ECC page writes, so all the work is done in the 1119 1095 * write_page() function above. 1120 1096 */ 1121 1097 static int denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1122 1098 const uint8_t *buf, int oob_required) 1123 1099 { 1124 - /* for raw page writes, we want to disable ECC and simply write 1125 - whatever data is in the buffer. */ 1100 + /* 1101 + * for raw page writes, we want to disable ECC and simply write 1102 + * whatever data is in the buffer. 1103 + */ 1126 1104 return write_page(mtd, chip, buf, true); 1127 1105 } 1128 1106 ··· 1155 1121 dma_addr_t addr = denali->buf.dma_buf; 1156 1122 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1157 1123 1158 - uint32_t irq_status = 0; 1124 + uint32_t irq_status; 1159 1125 uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE | 1160 1126 INTR_STATUS__ECC_ERR; 1161 1127 bool check_erased_page = false; 1162 1128 1163 1129 if (page != denali->page) { 1164 - dev_err(denali->dev, "IN %s: page %d is not" 1165 - " equal to denali->page %d, investigate!!", 1166 - __func__, page, denali->page); 1130 + dev_err(denali->dev, 1131 + "IN %s: page %d is not equal to denali->page %d", 1132 + __func__, page, denali->page); 1167 1133 BUG(); 1168 1134 } 1169 1135 ··· 1203 1169 uint8_t *buf, int oob_required, int page) 1204 1170 { 1205 1171 struct denali_nand_info *denali = mtd_to_denali(mtd); 1206 - 1207 1172 dma_addr_t addr = denali->buf.dma_buf; 1208 1173 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1209 - 1210 - uint32_t irq_status = 0; 1211 1174 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP; 1212 1175 1213 1176 if (page != denali->page) { 1214 - dev_err(denali->dev, "IN %s: page %d is not" 1215 - " equal to denali->page %d, investigate!!", 1216 - __func__, page, denali->page); 1177 + dev_err(denali->dev, 1178 + "IN %s: page %d is not equal to denali->page %d", 1179 + __func__, page, denali->page); 1217 1180 BUG(); 1218 1181 } 1219 1182 ··· 1223 1192 denali_setup_dma(denali, DENALI_READ); 1224 1193 1225 1194 /* wait for operation to complete */ 1226 - irq_status = wait_for_irq(denali, irq_mask); 1195 + wait_for_irq(denali, irq_mask); 1227 1196 1228 1197 dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE); 1229 1198 ··· 1259 1228 { 1260 1229 struct denali_nand_info *denali = mtd_to_denali(mtd); 1261 1230 int status = denali->status; 1231 + 1262 1232 denali->status = 0; 1263 1233 1264 1234 return status; ··· 1269 1237 { 1270 1238 struct denali_nand_info *denali = mtd_to_denali(mtd); 1271 1239 1272 - uint32_t cmd = 0x0, irq_status = 0; 1240 + uint32_t cmd, irq_status; 1273 1241 1274 - /* clear interrupts */ 1275 1242 clear_interrupts(denali); 1276 1243 1277 1244 /* setup page read request for access type */ 1278 1245 cmd = MODE_10 | BANK(denali->flash_bank) | page; 1279 - index_addr(denali, (uint32_t)cmd, 0x1); 1246 + index_addr(denali, cmd, 0x1); 1280 1247 1281 1248 /* wait for erase to complete or failure to occur */ 1282 1249 irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP | 1283 1250 INTR_STATUS__ERASE_FAIL); 1284 1251 1285 - return (irq_status & INTR_STATUS__ERASE_FAIL) ? NAND_STATUS_FAIL : PASS; 1252 + return irq_status & INTR_STATUS__ERASE_FAIL ? NAND_STATUS_FAIL : PASS; 1286 1253 } 1287 1254 1288 1255 static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, ··· 1300 1269 case NAND_CMD_READID: 1301 1270 case NAND_CMD_PARAM: 1302 1271 reset_buf(denali); 1303 - /*sometimes ManufactureId read from register is not right 1272 + /* 1273 + * sometimes ManufactureId read from register is not right 1304 1274 * e.g. some of Micron MT29F32G08QAA MLC NAND chips 1305 1275 * So here we send READID cmd to NAND insteand 1306 - * */ 1307 - addr = (uint32_t)MODE_11 | BANK(denali->flash_bank); 1308 - index_addr(denali, (uint32_t)addr | 0, 0x90); 1309 - index_addr(denali, (uint32_t)addr | 1, 0); 1276 + */ 1277 + addr = MODE_11 | BANK(denali->flash_bank); 1278 + index_addr(denali, addr | 0, 0x90); 1279 + index_addr(denali, addr | 1, 0); 1310 1280 for (i = 0; i < 8; i++) { 1311 - index_addr_read_data(denali, 1312 - (uint32_t)addr | 2, 1313 - &id); 1281 + index_addr_read_data(denali, addr | 2, &id); 1314 1282 write_byte_to_buf(denali, id); 1315 1283 } 1316 1284 break; ··· 1334 1304 uint8_t *ecc_code) 1335 1305 { 1336 1306 struct denali_nand_info *denali = mtd_to_denali(mtd); 1337 - dev_err(denali->dev, 1338 - "denali_ecc_calculate called unexpectedly\n"); 1307 + 1308 + dev_err(denali->dev, "denali_ecc_calculate called unexpectedly\n"); 1339 1309 BUG(); 1340 1310 return -EIO; 1341 1311 } ··· 1344 1314 uint8_t *read_ecc, uint8_t *calc_ecc) 1345 1315 { 1346 1316 struct denali_nand_info *denali = mtd_to_denali(mtd); 1347 - dev_err(denali->dev, 1348 - "denali_ecc_correct called unexpectedly\n"); 1317 + 1318 + dev_err(denali->dev, "denali_ecc_correct called unexpectedly\n"); 1349 1319 BUG(); 1350 1320 return -EIO; 1351 1321 } ··· 1353 1323 static void denali_ecc_hwctl(struct mtd_info *mtd, int mode) 1354 1324 { 1355 1325 struct denali_nand_info *denali = mtd_to_denali(mtd); 1356 - dev_err(denali->dev, 1357 - "denali_ecc_hwctl called unexpectedly\n"); 1326 + 1327 + dev_err(denali->dev, "denali_ecc_hwctl called unexpectedly\n"); 1358 1328 BUG(); 1359 1329 } 1360 1330 /* end NAND core entry points */ ··· 1362 1332 /* Initialization code to bring the device up to a known good state */ 1363 1333 static void denali_hw_init(struct denali_nand_info *denali) 1364 1334 { 1365 - /* tell driver how many bit controller will skip before 1335 + /* 1336 + * tell driver how many bit controller will skip before 1366 1337 * writing ECC code in OOB, this register may be already 1367 1338 * set by firmware. So we read this value out. 1368 1339 * if this value is 0, just let it be. 1369 - * */ 1340 + */ 1370 1341 denali->bbtskipbytes = ioread32(denali->flash_reg + 1371 1342 SPARE_AREA_SKIP_BYTES); 1372 1343 detect_max_banks(denali); ··· 1385 1354 denali_irq_init(denali); 1386 1355 } 1387 1356 1388 - /* Althogh controller spec said SLC ECC is forceb to be 4bit, 1357 + /* 1358 + * Althogh controller spec said SLC ECC is forceb to be 4bit, 1389 1359 * but denali controller in MRST only support 15bit and 8bit ECC 1390 1360 * correction 1391 - * */ 1361 + */ 1392 1362 #define ECC_8BITS 14 1393 1363 static struct nand_ecclayout nand_8bit_oob = { 1394 1364 .eccbytes = 14, ··· 1429 1397 denali->idx = 0; 1430 1398 1431 1399 /* setup interrupt handler */ 1432 - /* the completion object will be used to notify 1433 - * the callee that the interrupt is done */ 1400 + /* 1401 + * the completion object will be used to notify 1402 + * the callee that the interrupt is done 1403 + */ 1434 1404 init_completion(&denali->complete); 1435 1405 1436 - /* the spinlock will be used to synchronize the ISR 1437 - * with any element that might be access shared 1438 - * data (interrupt status) */ 1406 + /* 1407 + * the spinlock will be used to synchronize the ISR with any 1408 + * element that might be access shared data (interrupt status) 1409 + */ 1439 1410 spin_lock_init(&denali->irq_lock); 1440 1411 1441 1412 /* indicate that MTD has not selected a valid bank yet */ ··· 1453 1418 int ret; 1454 1419 1455 1420 if (denali->platform == INTEL_CE4100) { 1456 - /* Due to a silicon limitation, we can only support 1421 + /* 1422 + * Due to a silicon limitation, we can only support 1457 1423 * ONFI timing mode 1 and below. 1458 1424 */ 1459 1425 if (onfi_timing_mode < -1 || onfi_timing_mode > 1) { ··· 1473 1437 denali_hw_init(denali); 1474 1438 denali_drv_init(denali); 1475 1439 1476 - /* denali_isr register is done after all the hardware 1477 - * initilization is finished*/ 1440 + /* 1441 + * denali_isr register is done after all the hardware 1442 + * initilization is finished 1443 + */ 1478 1444 if (request_irq(denali->irq, denali_isr, IRQF_SHARED, 1479 1445 DENALI_NAND_NAME, denali)) { 1480 1446 pr_err("Spectra: Unable to allocate IRQ\n"); ··· 1495 1457 denali->nand.read_byte = denali_read_byte; 1496 1458 denali->nand.waitfunc = denali_waitfunc; 1497 1459 1498 - /* scan for NAND devices attached to the controller 1460 + /* 1461 + * scan for NAND devices attached to the controller 1499 1462 * this is the first stage in a two step process to register 1500 - * with the nand subsystem */ 1463 + * with the nand subsystem 1464 + */ 1501 1465 if (nand_scan_ident(&denali->mtd, denali->max_banks, NULL)) { 1502 1466 ret = -ENXIO; 1503 1467 goto failed_req_irq; ··· 1531 1491 goto failed_req_irq; 1532 1492 } 1533 1493 1534 - /* support for multi nand 1535 - * MTD known nothing about multi nand, 1536 - * so we should tell it the real pagesize 1537 - * and anything necessery 1494 + /* 1495 + * support for multi nand 1496 + * MTD known nothing about multi nand, so we should tell it 1497 + * the real pagesize and anything necessery 1538 1498 */ 1539 1499 denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED); 1540 1500 denali->nand.chipsize <<= (denali->devnum - 1); ··· 1550 1510 denali->mtd.size = denali->nand.numchips * denali->nand.chipsize; 1551 1511 denali->bbtskipbytes *= denali->devnum; 1552 1512 1553 - /* second stage of the NAND scan 1513 + /* 1514 + * second stage of the NAND scan 1554 1515 * this stage requires information regarding ECC and 1555 - * bad block management. */ 1516 + * bad block management. 1517 + */ 1556 1518 1557 1519 /* Bad block management */ 1558 1520 denali->nand.bbt_td = &bbt_main_descr; ··· 1565 1523 denali->nand.options |= NAND_SKIP_BBTSCAN; 1566 1524 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME; 1567 1525 1568 - /* Denali Controller only support 15bit and 8bit ECC in MRST, 1526 + /* 1527 + * Denali Controller only support 15bit and 8bit ECC in MRST, 1569 1528 * so just let controller do 15bit ECC for MLC and 8bit ECC for 1570 1529 * SLC if possible. 1571 1530 * */ ··· 1582 1539 } else if (denali->mtd.oobsize < (denali->bbtskipbytes + 1583 1540 ECC_8BITS * (denali->mtd.writesize / 1584 1541 ECC_SECTOR_SIZE))) { 1585 - pr_err("Your NAND chip OOB is not large enough to \ 1586 - contain 8bit ECC correction codes"); 1542 + pr_err("Your NAND chip OOB is not large enough to contain 8bit ECC correction codes"); 1587 1543 goto failed_req_irq; 1588 1544 } else { 1589 1545 denali->nand.ecc.strength = 8; ··· 1601 1559 denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes - 1602 1560 denali->bbtskipbytes; 1603 1561 1604 - /* Let driver know the total blocks number and 1605 - * how many blocks contained by each nand chip. 1606 - * blksperchip will help driver to know how many 1607 - * blocks is taken by FW. 1608 - * */ 1609 - denali->totalblks = denali->mtd.size >> 1610 - denali->nand.phys_erase_shift; 1562 + /* 1563 + * Let driver know the total blocks number and how many blocks 1564 + * contained by each nand chip. blksperchip will help driver to 1565 + * know how many blocks is taken by FW. 1566 + */ 1567 + denali->totalblks = denali->mtd.size >> denali->nand.phys_erase_shift; 1611 1568 denali->blksperchip = denali->totalblks / denali->nand.numchips; 1612 1569 1613 - /* These functions are required by the NAND core framework, otherwise, 1570 + /* 1571 + * These functions are required by the NAND core framework, otherwise, 1614 1572 * the NAND core will assert. However, we don't need them, so we'll stub 1615 - * them out. */ 1573 + * them out. 1574 + */ 1616 1575 denali->nand.ecc.calculate = denali_ecc_calculate; 1617 1576 denali->nand.ecc.correct = denali_ecc_correct; 1618 1577 denali->nand.ecc.hwctl = denali_ecc_hwctl; ··· 1653 1610 { 1654 1611 denali_irq_cleanup(denali->irq, denali); 1655 1612 dma_unmap_single(denali->dev, denali->buf.dma_buf, 1656 - denali->mtd.writesize + denali->mtd.oobsize, 1657 - DMA_BIDIRECTIONAL); 1613 + denali->mtd.writesize + denali->mtd.oobsize, 1614 + DMA_BIDIRECTIONAL); 1658 1615 } 1659 1616 EXPORT_SYMBOL(denali_remove);
+4 -23
drivers/mtd/nand/denali.h
··· 17 17 * 18 18 */ 19 19 20 + #ifndef __DENALI_H__ 21 + #define __DENALI_H__ 22 + 20 23 #include <linux/mtd/nand.h> 21 24 22 25 #define DEVICE_RESET 0x0 ··· 403 400 #define ONFI_BLOOM_TIME 1 404 401 #define MODE5_WORKAROUND 0 405 402 406 - /* lld_nand.h */ 407 - /* 408 - * NAND Flash Controller Device Driver 409 - * Copyright (c) 2009, Intel Corporation and its suppliers. 410 - * 411 - * This program is free software; you can redistribute it and/or modify it 412 - * under the terms and conditions of the GNU General Public License, 413 - * version 2, as published by the Free Software Foundation. 414 - * 415 - * This program is distributed in the hope it will be useful, but WITHOUT 416 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 417 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 418 - * more details. 419 - * 420 - * You should have received a copy of the GNU General Public License along with 421 - * this program; if not, write to the Free Software Foundation, Inc., 422 - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 423 - * 424 - */ 425 - 426 - #ifndef _LLD_NAND_ 427 - #define _LLD_NAND_ 428 403 429 404 #define MODE_00 0x00000000 430 405 #define MODE_01 0x04000000 ··· 480 499 extern int denali_init(struct denali_nand_info *denali); 481 500 extern void denali_remove(struct denali_nand_info *denali); 482 501 483 - #endif /*_LLD_NAND_*/ 502 + #endif /* __DENALI_H__ */
+27 -11
drivers/mtd/nand/nand_base.c
··· 982 982 983 983 chip->select_chip(mtd, chipnr); 984 984 985 + /* 986 + * Reset the chip. 987 + * If we want to check the WP through READ STATUS and check the bit 7 988 + * we must reset the chip 989 + * some operation can also clear the bit 7 of status register 990 + * eg. erase/program a locked block 991 + */ 992 + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 993 + 985 994 /* Check, if it is write protected */ 986 995 if (nand_check_wp(mtd)) { 987 996 pr_debug("%s: device is write protected!\n", ··· 1040 1031 chipnr = ofs >> chip->chip_shift; 1041 1032 1042 1033 chip->select_chip(mtd, chipnr); 1034 + 1035 + /* 1036 + * Reset the chip. 1037 + * If we want to check the WP through READ STATUS and check the bit 7 1038 + * we must reset the chip 1039 + * some operation can also clear the bit 7 of status register 1040 + * eg. erase/program a locked block 1041 + */ 1042 + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 1043 1043 1044 1044 /* Check, if it is write protected */ 1045 1045 if (nand_check_wp(mtd)) { ··· 2409 2391 blockmask = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1; 2410 2392 2411 2393 /* Invalidate the page cache, when we write to the cached page */ 2412 - if (to <= (chip->pagebuf << chip->page_shift) && 2413 - (chip->pagebuf << chip->page_shift) < (to + ops->len)) 2394 + if (to <= ((loff_t)chip->pagebuf << chip->page_shift) && 2395 + ((loff_t)chip->pagebuf << chip->page_shift) < (to + ops->len)) 2414 2396 chip->pagebuf = -1; 2415 2397 2416 2398 /* Don't allow multipage oob writes with offset */ ··· 3594 3576 chip->options |= type->options; 3595 3577 chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); 3596 3578 chip->ecc_step_ds = NAND_ECC_STEP(type); 3579 + chip->onfi_timing_mode_default = 3580 + type->onfi_timing_mode_default; 3597 3581 3598 3582 *busw = type->options & NAND_BUSWIDTH_16; 3599 3583 ··· 3938 3918 case NAND_ECC_HW_OOB_FIRST: 3939 3919 /* Similar to NAND_ECC_HW, but a separate read_page handle */ 3940 3920 if (!ecc->calculate || !ecc->correct || !ecc->hwctl) { 3941 - pr_warn("No ECC functions supplied; " 3942 - "hardware ECC not possible\n"); 3921 + pr_warn("No ECC functions supplied; hardware ECC not possible\n"); 3943 3922 BUG(); 3944 3923 } 3945 3924 if (!ecc->read_page) ··· 3969 3950 ecc->read_page == nand_read_page_hwecc || 3970 3951 !ecc->write_page || 3971 3952 ecc->write_page == nand_write_page_hwecc)) { 3972 - pr_warn("No ECC functions supplied; " 3973 - "hardware ECC not possible\n"); 3953 + pr_warn("No ECC functions supplied; hardware ECC not possible\n"); 3974 3954 BUG(); 3975 3955 } 3976 3956 /* Use standard syndrome read/write page function? */ ··· 3993 3975 } 3994 3976 break; 3995 3977 } 3996 - pr_warn("%d byte HW ECC not possible on " 3997 - "%d byte page size, fallback to SW ECC\n", 3998 - ecc->size, mtd->writesize); 3978 + pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n", 3979 + ecc->size, mtd->writesize); 3999 3980 ecc->mode = NAND_ECC_SOFT; 4000 3981 4001 3982 case NAND_ECC_SOFT: ··· 4047 4030 break; 4048 4031 4049 4032 case NAND_ECC_NONE: 4050 - pr_warn("NAND_ECC_NONE selected by board driver. " 4051 - "This is not recommended!\n"); 4033 + pr_warn("NAND_ECC_NONE selected by board driver. This is not recommended!\n"); 4052 4034 ecc->read_page = nand_read_page_raw; 4053 4035 ecc->write_page = nand_write_page_raw; 4054 4036 ecc->read_oob = nand_read_oob_std;
+10 -13
drivers/mtd/nand/nand_bbt.c
··· 201 201 res = mtd_read(mtd, from, len, &retlen, buf); 202 202 if (res < 0) { 203 203 if (mtd_is_eccerr(res)) { 204 - pr_info("nand_bbt: ECC error in BBT at " 205 - "0x%012llx\n", from & ~mtd->writesize); 204 + pr_info("nand_bbt: ECC error in BBT at 0x%012llx\n", 205 + from & ~mtd->writesize); 206 206 return res; 207 207 } else if (mtd_is_bitflip(res)) { 208 - pr_info("nand_bbt: corrected error in BBT at " 209 - "0x%012llx\n", from & ~mtd->writesize); 208 + pr_info("nand_bbt: corrected error in BBT at 0x%012llx\n", 209 + from & ~mtd->writesize); 210 210 ret = res; 211 211 } else { 212 212 pr_info("nand_bbt: error reading BBT\n"); ··· 580 580 if (td->pages[i] == -1) 581 581 pr_warn("Bad block table not found for chip %d\n", i); 582 582 else 583 - pr_info("Bad block table found at page %d, version " 584 - "0x%02X\n", td->pages[i], td->version[i]); 583 + pr_info("Bad block table found at page %d, version 0x%02X\n", 584 + td->pages[i], td->version[i]); 585 585 } 586 586 return 0; 587 587 } ··· 725 725 res = mtd_read(mtd, to, len, &retlen, buf); 726 726 if (res < 0) { 727 727 if (retlen != len) { 728 - pr_info("nand_bbt: error reading block " 729 - "for writing the bad block table\n"); 728 + pr_info("nand_bbt: error reading block for writing the bad block table\n"); 730 729 return res; 731 730 } 732 - pr_warn("nand_bbt: ECC error while reading " 733 - "block for writing bad block table\n"); 731 + pr_warn("nand_bbt: ECC error while reading block for writing bad block table\n"); 734 732 } 735 733 /* Read oob data */ 736 734 ops.ooblen = (len >> this->page_shift) * mtd->oobsize; ··· 1336 1338 block = (int)(offs >> this->bbt_erase_shift); 1337 1339 res = bbt_get_entry(this, block); 1338 1340 1339 - pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: " 1340 - "(block %d) 0x%02x\n", 1341 - (unsigned int)offs, block, res); 1341 + pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1342 + (unsigned int)offs, block, res); 1342 1343 1343 1344 switch (res) { 1344 1345 case BBT_BLOCK_GOOD:
+4
drivers/mtd/nand/nand_ids.c
··· 46 46 {"SDTNRGAMA 64G 3.3V 8-bit", 47 47 { .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x50} }, 48 48 SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) }, 49 + {"H27UCG8T2ATR-BC 64G 3.3V 8-bit", 50 + { .id = {0xad, 0xde, 0x94, 0xda, 0x74, 0xc4} }, 51 + SZ_8K, SZ_8K, SZ_2M, 0, 6, 640, NAND_ECC_INFO(40, SZ_1K), 52 + 4 }, 49 53 50 54 LEGACY_ID_NAND("NAND 4MiB 5V 8-bit", 0x6B, 4, SZ_8K, SP_OPTIONS), 51 55 LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit", 0xE3, 4, SZ_8K, SP_OPTIONS),
+1 -1
drivers/mtd/nand/nand_timings.c
··· 42 42 .tRHZ_max = 200000, 43 43 .tRLOH_min = 0, 44 44 .tRP_min = 50000, 45 - .tRST_max = 250000000000, 45 + .tRST_max = 250000000000ULL, 46 46 .tWB_max = 200000, 47 47 .tRR_min = 40000, 48 48 .tWC_min = 100000,
+1 -1
drivers/mtd/nand/nandsim.c
··· 827 827 NS_ERR("invalid badblocks.\n"); 828 828 return -EINVAL; 829 829 } 830 - offset = erase_block_no * ns->geom.secsz; 830 + offset = (loff_t)erase_block_no * ns->geom.secsz; 831 831 if (mtd_block_markbad(mtd, offset)) { 832 832 NS_ERR("invalid badblocks.\n"); 833 833 return -EINVAL;
+2 -1
drivers/mtd/nand/ndfc.c
··· 203 203 struct ndfc_controller *ndfc; 204 204 const __be32 *reg; 205 205 u32 ccr; 206 - int err, len, cs; 206 + u32 cs; 207 + int err, len; 207 208 208 209 /* Read the reg property to get the chip select */ 209 210 reg = of_get_property(ofdev->dev.of_node, "reg", &len);
+94 -74
drivers/mtd/nand/omap2.c
··· 136 136 137 137 #define BADBLOCK_MARKER_LENGTH 2 138 138 139 - #ifdef CONFIG_MTD_NAND_OMAP_BCH 140 139 static u_char bch16_vector[] = {0xf5, 0x24, 0x1c, 0xd0, 0x61, 0xb3, 0xf1, 0x55, 141 140 0x2e, 0x2c, 0x86, 0xa3, 0xed, 0x36, 0x1b, 0x78, 142 141 0x48, 0x76, 0xa9, 0x3b, 0x97, 0xd1, 0x7a, 0x93, ··· 143 144 static u_char bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2, 0xbe, 0xcc, 144 145 0xac, 0x6b, 0xff, 0x99, 0x7b}; 145 146 static u_char bch4_vector[] = {0x00, 0x6b, 0x31, 0xdd, 0x41, 0xbc, 0x10}; 146 - #endif 147 147 148 148 /* oob info generated runtime depending on ecc algorithm and layout selected */ 149 149 static struct nand_ecclayout omap_oobinfo; ··· 1290 1292 return 0; 1291 1293 } 1292 1294 1293 - #ifdef CONFIG_MTD_NAND_OMAP_BCH 1294 1295 /** 1295 1296 * erased_sector_bitflips - count bit flips 1296 1297 * @data: data sector buffer ··· 1375 1378 erased_ecc_vec = bch16_vector; 1376 1379 break; 1377 1380 default: 1378 - pr_err("invalid driver configuration\n"); 1381 + dev_err(&info->pdev->dev, "invalid driver configuration\n"); 1379 1382 return -EINVAL; 1380 1383 } 1381 1384 ··· 1446 1449 err = 0; 1447 1450 for (i = 0; i < eccsteps; i++) { 1448 1451 if (err_vec[i].error_uncorrectable) { 1449 - pr_err("nand: uncorrectable bit-flips found\n"); 1452 + dev_err(&info->pdev->dev, 1453 + "uncorrectable bit-flips found\n"); 1450 1454 err = -EBADMSG; 1451 1455 } else if (err_vec[i].error_reported) { 1452 1456 for (j = 0; j < err_vec[i].error_count; j++) { ··· 1484 1486 1 << bit_pos; 1485 1487 } 1486 1488 } else { 1487 - pr_err("invalid bit-flip @ %d:%d\n", 1488 - byte_pos, bit_pos); 1489 + dev_err(&info->pdev->dev, 1490 + "invalid bit-flip @ %d:%d\n", 1491 + byte_pos, bit_pos); 1489 1492 err = -EBADMSG; 1490 1493 } 1491 1494 } ··· 1592 1593 /** 1593 1594 * is_elm_present - checks for presence of ELM module by scanning DT nodes 1594 1595 * @omap_nand_info: NAND device structure containing platform data 1595 - * @bch_type: 0x0=BCH4, 0x1=BCH8, 0x2=BCH16 1596 1596 */ 1597 - static int is_elm_present(struct omap_nand_info *info, 1598 - struct device_node *elm_node, enum bch_ecc bch_type) 1597 + static bool is_elm_present(struct omap_nand_info *info, 1598 + struct device_node *elm_node) 1599 1599 { 1600 1600 struct platform_device *pdev; 1601 - struct nand_ecc_ctrl *ecc = &info->nand.ecc; 1602 - int err; 1601 + 1603 1602 /* check whether elm-id is passed via DT */ 1604 1603 if (!elm_node) { 1605 - pr_err("nand: error: ELM DT node not found\n"); 1606 - return -ENODEV; 1604 + dev_err(&info->pdev->dev, "ELM devicetree node not found\n"); 1605 + return false; 1607 1606 } 1608 1607 pdev = of_find_device_by_node(elm_node); 1609 1608 /* check whether ELM device is registered */ 1610 1609 if (!pdev) { 1611 - pr_err("nand: error: ELM device not found\n"); 1612 - return -ENODEV; 1610 + dev_err(&info->pdev->dev, "ELM device not found\n"); 1611 + return false; 1613 1612 } 1614 1613 /* ELM module available, now configure it */ 1615 1614 info->elm_dev = &pdev->dev; 1616 - err = elm_config(info->elm_dev, bch_type, 1617 - (info->mtd.writesize / ecc->size), ecc->size, ecc->bytes); 1618 - 1619 - return err; 1615 + return true; 1620 1616 } 1621 - #endif /* CONFIG_MTD_NAND_ECC_BCH */ 1617 + 1618 + static bool omap2_nand_ecc_check(struct omap_nand_info *info, 1619 + struct omap_nand_platform_data *pdata) 1620 + { 1621 + bool ecc_needs_bch, ecc_needs_omap_bch, ecc_needs_elm; 1622 + 1623 + switch (info->ecc_opt) { 1624 + case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW: 1625 + case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW: 1626 + ecc_needs_omap_bch = false; 1627 + ecc_needs_bch = true; 1628 + ecc_needs_elm = false; 1629 + break; 1630 + case OMAP_ECC_BCH4_CODE_HW: 1631 + case OMAP_ECC_BCH8_CODE_HW: 1632 + case OMAP_ECC_BCH16_CODE_HW: 1633 + ecc_needs_omap_bch = true; 1634 + ecc_needs_bch = false; 1635 + ecc_needs_elm = true; 1636 + break; 1637 + default: 1638 + ecc_needs_omap_bch = false; 1639 + ecc_needs_bch = false; 1640 + ecc_needs_elm = false; 1641 + break; 1642 + } 1643 + 1644 + if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_BCH)) { 1645 + dev_err(&info->pdev->dev, 1646 + "CONFIG_MTD_NAND_ECC_BCH not enabled\n"); 1647 + return false; 1648 + } 1649 + if (ecc_needs_omap_bch && !IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH)) { 1650 + dev_err(&info->pdev->dev, 1651 + "CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 1652 + return false; 1653 + } 1654 + if (ecc_needs_elm && !is_elm_present(info, pdata->elm_of_node)) { 1655 + dev_err(&info->pdev->dev, "ELM not available\n"); 1656 + return false; 1657 + } 1658 + 1659 + return true; 1660 + } 1622 1661 1623 1662 static int omap_nand_probe(struct platform_device *pdev) 1624 1663 { ··· 1700 1663 mtd->owner = THIS_MODULE; 1701 1664 nand_chip = &info->nand; 1702 1665 nand_chip->ecc.priv = NULL; 1703 - nand_chip->options |= NAND_SKIP_BBTSCAN; 1704 1666 1705 1667 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1706 1668 nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res); ··· 1728 1692 nand_chip->chip_delay = 50; 1729 1693 } 1730 1694 1695 + if (pdata->flash_bbt) 1696 + nand_chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB; 1697 + else 1698 + nand_chip->options |= NAND_SKIP_BBTSCAN; 1699 + 1731 1700 /* scan NAND device connected to chip controller */ 1732 1701 nand_chip->options |= pdata->devsize & NAND_BUSWIDTH_16; 1733 1702 if (nand_scan_ident(mtd, 1, NULL)) { 1734 - pr_err("nand device scan failed, may be bus-width mismatch\n"); 1703 + dev_err(&info->pdev->dev, "scan failed, may be bus-width mismatch\n"); 1735 1704 err = -ENXIO; 1736 1705 goto return_error; 1737 1706 } 1738 1707 1739 1708 /* check for small page devices */ 1740 1709 if ((mtd->oobsize < 64) && (pdata->ecc_opt != OMAP_ECC_HAM1_CODE_HW)) { 1741 - pr_err("small page devices are not supported\n"); 1710 + dev_err(&info->pdev->dev, "small page devices are not supported\n"); 1742 1711 err = -EINVAL; 1743 1712 goto return_error; 1744 1713 } ··· 1834 1793 goto return_error; 1835 1794 } 1836 1795 1796 + if (!omap2_nand_ecc_check(info, pdata)) { 1797 + err = -EINVAL; 1798 + goto return_error; 1799 + } 1800 + 1837 1801 /* populate MTD interface based on ECC scheme */ 1838 1802 ecclayout = &omap_oobinfo; 1839 1803 switch (info->ecc_opt) { ··· 1871 1825 break; 1872 1826 1873 1827 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW: 1874 - #ifdef CONFIG_MTD_NAND_ECC_BCH 1875 1828 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW_DETECTION_SW\n"); 1876 1829 nand_chip->ecc.mode = NAND_ECC_HW; 1877 1830 nand_chip->ecc.size = 512; ··· 1898 1853 nand_chip->ecc.bytes, 1899 1854 &ecclayout); 1900 1855 if (!nand_chip->ecc.priv) { 1901 - pr_err("nand: error: unable to use s/w BCH library\n"); 1856 + dev_err(&info->pdev->dev, "unable to use BCH library\n"); 1902 1857 err = -EINVAL; 1858 + goto return_error; 1903 1859 } 1904 1860 break; 1905 - #else 1906 - pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n"); 1907 - err = -EINVAL; 1908 - goto return_error; 1909 - #endif 1910 1861 1911 1862 case OMAP_ECC_BCH4_CODE_HW: 1912 - #ifdef CONFIG_MTD_NAND_OMAP_BCH 1913 1863 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme\n"); 1914 1864 nand_chip->ecc.mode = NAND_ECC_HW; 1915 1865 nand_chip->ecc.size = 512; ··· 1926 1886 /* reserved marker already included in ecclayout->eccbytes */ 1927 1887 ecclayout->oobfree->offset = 1928 1888 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1; 1929 - /* This ECC scheme requires ELM H/W block */ 1930 - if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) { 1931 - pr_err("nand: error: could not initialize ELM\n"); 1932 - err = -ENODEV; 1889 + 1890 + err = elm_config(info->elm_dev, BCH4_ECC, 1891 + info->mtd.writesize / nand_chip->ecc.size, 1892 + nand_chip->ecc.size, nand_chip->ecc.bytes); 1893 + if (err < 0) 1933 1894 goto return_error; 1934 - } 1935 1895 break; 1936 - #else 1937 - pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 1938 - err = -EINVAL; 1939 - goto return_error; 1940 - #endif 1941 1896 1942 1897 case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW: 1943 - #ifdef CONFIG_MTD_NAND_ECC_BCH 1944 1898 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n"); 1945 1899 nand_chip->ecc.mode = NAND_ECC_HW; 1946 1900 nand_chip->ecc.size = 512; ··· 1962 1928 nand_chip->ecc.bytes, 1963 1929 &ecclayout); 1964 1930 if (!nand_chip->ecc.priv) { 1965 - pr_err("nand: error: unable to use s/w BCH library\n"); 1931 + dev_err(&info->pdev->dev, "unable to use BCH library\n"); 1966 1932 err = -EINVAL; 1967 1933 goto return_error; 1968 1934 } 1969 1935 break; 1970 - #else 1971 - pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n"); 1972 - err = -EINVAL; 1973 - goto return_error; 1974 - #endif 1975 1936 1976 1937 case OMAP_ECC_BCH8_CODE_HW: 1977 - #ifdef CONFIG_MTD_NAND_OMAP_BCH 1978 1938 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n"); 1979 1939 nand_chip->ecc.mode = NAND_ECC_HW; 1980 1940 nand_chip->ecc.size = 512; ··· 1980 1952 nand_chip->ecc.calculate = omap_calculate_ecc_bch; 1981 1953 nand_chip->ecc.read_page = omap_read_page_bch; 1982 1954 nand_chip->ecc.write_page = omap_write_page_bch; 1983 - /* This ECC scheme requires ELM H/W block */ 1984 - err = is_elm_present(info, pdata->elm_of_node, BCH8_ECC); 1985 - if (err < 0) { 1986 - pr_err("nand: error: could not initialize ELM\n"); 1955 + 1956 + err = elm_config(info->elm_dev, BCH8_ECC, 1957 + info->mtd.writesize / nand_chip->ecc.size, 1958 + nand_chip->ecc.size, nand_chip->ecc.bytes); 1959 + if (err < 0) 1987 1960 goto return_error; 1988 - } 1961 + 1989 1962 /* define ECC layout */ 1990 1963 ecclayout->eccbytes = nand_chip->ecc.bytes * 1991 1964 (mtd->writesize / ··· 1998 1969 ecclayout->oobfree->offset = 1999 1970 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1; 2000 1971 break; 2001 - #else 2002 - pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 2003 - err = -EINVAL; 2004 - goto return_error; 2005 - #endif 2006 1972 2007 1973 case OMAP_ECC_BCH16_CODE_HW: 2008 - #ifdef CONFIG_MTD_NAND_OMAP_BCH 2009 1974 pr_info("using OMAP_ECC_BCH16_CODE_HW ECC scheme\n"); 2010 1975 nand_chip->ecc.mode = NAND_ECC_HW; 2011 1976 nand_chip->ecc.size = 512; ··· 2010 1987 nand_chip->ecc.calculate = omap_calculate_ecc_bch; 2011 1988 nand_chip->ecc.read_page = omap_read_page_bch; 2012 1989 nand_chip->ecc.write_page = omap_write_page_bch; 2013 - /* This ECC scheme requires ELM H/W block */ 2014 - err = is_elm_present(info, pdata->elm_of_node, BCH16_ECC); 2015 - if (err < 0) { 2016 - pr_err("ELM is required for this ECC scheme\n"); 1990 + 1991 + err = elm_config(info->elm_dev, BCH16_ECC, 1992 + info->mtd.writesize / nand_chip->ecc.size, 1993 + nand_chip->ecc.size, nand_chip->ecc.bytes); 1994 + if (err < 0) 2017 1995 goto return_error; 2018 - } 1996 + 2019 1997 /* define ECC layout */ 2020 1998 ecclayout->eccbytes = nand_chip->ecc.bytes * 2021 1999 (mtd->writesize / ··· 2028 2004 ecclayout->oobfree->offset = 2029 2005 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1; 2030 2006 break; 2031 - #else 2032 - pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 2033 - err = -EINVAL; 2034 - goto return_error; 2035 - #endif 2036 2007 default: 2037 - pr_err("nand: error: invalid or unsupported ECC scheme\n"); 2008 + dev_err(&info->pdev->dev, "invalid or unsupported ECC scheme\n"); 2038 2009 err = -EINVAL; 2039 2010 goto return_error; 2040 2011 } ··· 2041 2022 ecclayout->oobfree->length = mtd->oobsize - ecclayout->oobfree->offset; 2042 2023 /* check if NAND device's OOB is enough to store ECC signatures */ 2043 2024 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) { 2044 - pr_err("not enough OOB bytes required = %d, available=%d\n", 2045 - ecclayout->eccbytes, mtd->oobsize); 2025 + dev_err(&info->pdev->dev, 2026 + "not enough OOB bytes required = %d, available=%d\n", 2027 + ecclayout->eccbytes, mtd->oobsize); 2046 2028 err = -EINVAL; 2047 2029 goto return_error; 2048 2030 }
+1 -1
drivers/mtd/nand/sm_common.h
··· 18 18 uint8_t ecc2[3]; 19 19 uint8_t lba_copy2[2]; 20 20 uint8_t ecc1[3]; 21 - } __attribute__((packed)); 21 + } __packed; 22 22 23 23 24 24 /* one sector is always 512 bytes, but it can consist of two nand pages */
+1 -1
drivers/mtd/sm_ftl.c
··· 1058 1058 { 1059 1059 struct sm_ftl *ftl = dev->priv; 1060 1060 struct ftl_zone *zone; 1061 - int error, zone_num, block, boffset; 1061 + int error = 0, zone_num, block, boffset; 1062 1062 1063 1063 BUG_ON(ftl->readonly); 1064 1064 sm_break_offset(ftl, sec_no << 9, &zone_num, &block, &boffset);
+14
drivers/mtd/spi-nor/Kconfig
··· 7 7 8 8 if MTD_SPI_NOR 9 9 10 + config MTD_SPI_NOR_USE_4K_SECTORS 11 + bool "Use small 4096 B erase sectors" 12 + default y 13 + help 14 + Many flash memories support erasing small (4096 B) sectors. Depending 15 + on the usage this feature may provide performance gain in comparison 16 + to erasing whole blocks (32/64 KiB). 17 + Changing a small part of the flash's contents is usually faster with 18 + small sectors. On the other hand erasing should be faster when using 19 + 64 KiB block instead of 16 × 4 KiB sectors. 20 + 21 + Please note that some tools/drivers/filesystems may not work with 22 + 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). 23 + 10 24 config SPI_FSL_QUADSPI 11 25 tristate "Freescale Quad SPI controller" 12 26 depends on ARCH_MXC
+7 -35
drivers/mtd/spi-nor/spi-nor.c
··· 611 611 { "m25px32-s0", INFO(0x207316, 0, 64 * 1024, 64, SECT_4K) }, 612 612 { "m25px32-s1", INFO(0x206316, 0, 64 * 1024, 64, SECT_4K) }, 613 613 { "m25px64", INFO(0x207117, 0, 64 * 1024, 128, 0) }, 614 + { "m25px80", INFO(0x207114, 0, 64 * 1024, 16, 0) }, 614 615 615 616 /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ 616 617 { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) }, ··· 624 623 { "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64, SECT_4K) }, 625 624 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 626 625 { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, 627 - { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) }, 628 626 { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) }, 629 627 { "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) }, 630 628 { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) }, ··· 669 669 } 670 670 dev_err(nor->dev, "unrecognized JEDEC id %06x\n", jedec); 671 671 return ERR_PTR(-ENODEV); 672 - } 673 - 674 - static const struct spi_device_id *jedec_probe(struct spi_nor *nor) 675 - { 676 - return nor->read_id(nor); 677 672 } 678 673 679 674 static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, ··· 915 920 enum read_mode mode) 916 921 { 917 922 struct flash_info *info; 918 - struct flash_platform_data *data; 919 923 struct device *dev = nor->dev; 920 924 struct mtd_info *mtd = nor->mtd; 921 925 struct device_node *np = dev->of_node; ··· 925 931 if (ret) 926 932 return ret; 927 933 928 - /* Platform data helps sort out which chip type we have, as 929 - * well as how this board partitions it. If we don't have 930 - * a chip ID, try the JEDEC id commands; they'll work for most 931 - * newer chips, even if we don't recognize the particular chip. 932 - */ 933 - data = dev_get_platdata(dev); 934 - if (data && data->type) { 935 - const struct spi_device_id *plat_id; 936 - 937 - for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) { 938 - plat_id = &spi_nor_ids[i]; 939 - if (strcmp(data->type, plat_id->name)) 940 - continue; 941 - break; 942 - } 943 - 944 - if (i < ARRAY_SIZE(spi_nor_ids) - 1) 945 - id = plat_id; 946 - else 947 - dev_warn(dev, "unrecognized id %s\n", data->type); 948 - } 949 - 950 934 info = (void *)id->driver_data; 951 935 952 936 if (info->jedec_id) { 953 937 const struct spi_device_id *jid; 954 938 955 - jid = jedec_probe(nor); 939 + jid = nor->read_id(nor); 956 940 if (IS_ERR(jid)) { 957 941 return PTR_ERR(jid); 958 942 } else if (jid != id) { ··· 962 990 write_sr(nor, 0); 963 991 } 964 992 965 - if (data && data->name) 966 - mtd->name = data->name; 967 - else 993 + if (!mtd->name) 968 994 mtd->name = dev_name(dev); 969 - 970 995 mtd->type = MTD_NORFLASH; 971 996 mtd->writesize = 1; 972 997 mtd->flags = MTD_CAP_NORFLASH; ··· 987 1018 nor->wait_till_ready == spi_nor_wait_till_ready) 988 1019 nor->wait_till_ready = spi_nor_wait_till_fsr_ready; 989 1020 1021 + #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS 990 1022 /* prefer "small sector" erase if possible */ 991 1023 if (info->flags & SECT_4K) { 992 1024 nor->erase_opcode = SPINOR_OP_BE_4K; ··· 995 1025 } else if (info->flags & SECT_4K_PMC) { 996 1026 nor->erase_opcode = SPINOR_OP_BE_4K_PMC; 997 1027 mtd->erasesize = 4096; 998 - } else { 1028 + } else 1029 + #endif 1030 + { 999 1031 nor->erase_opcode = SPINOR_OP_SE; 1000 1032 mtd->erasesize = info->sector_size; 1001 1033 }
+2 -2
drivers/mtd/tests/mtd_test.c
··· 10 10 { 11 11 int err; 12 12 struct erase_info ei; 13 - loff_t addr = ebnum * mtd->erasesize; 13 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 14 14 15 15 memset(&ei, 0, sizeof(struct erase_info)); 16 16 ei.mtd = mtd; ··· 33 33 static int is_block_bad(struct mtd_info *mtd, unsigned int ebnum) 34 34 { 35 35 int ret; 36 - loff_t addr = ebnum * mtd->erasesize; 36 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 37 37 38 38 ret = mtd_block_isbad(mtd, addr); 39 39 if (ret)
+1 -1
drivers/mtd/tests/nandbiterrs.c
··· 364 364 365 365 pr_info("Device uses %d subpages of %d bytes\n", subcount, subsize); 366 366 367 - offset = page_offset * mtd->writesize; 367 + offset = (loff_t)page_offset * mtd->writesize; 368 368 eraseblock = mtd_div_by_eb(offset, mtd); 369 369 370 370 pr_info("Using page=%u, offset=%llu, eraseblock=%u\n",
+4 -4
drivers/mtd/tests/oobtest.c
··· 120 120 int i; 121 121 struct mtd_oob_ops ops; 122 122 int err = 0; 123 - loff_t addr = ebnum * mtd->erasesize; 123 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 124 124 125 125 prandom_bytes_state(&rnd_state, writebuf, use_len_max * pgcnt); 126 126 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { ··· 214 214 { 215 215 struct mtd_oob_ops ops; 216 216 int err = 0; 217 - loff_t addr = ebnum * mtd->erasesize; 217 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 218 218 size_t len = mtd->ecclayout->oobavail * pgcnt; 219 219 220 220 prandom_bytes_state(&rnd_state, writebuf, len); ··· 568 568 size_t sz = mtd->ecclayout->oobavail; 569 569 if (bbt[i] || bbt[i + 1]) 570 570 continue; 571 - addr = (i + 1) * mtd->erasesize - mtd->writesize; 571 + addr = (loff_t)(i + 1) * mtd->erasesize - mtd->writesize; 572 572 prandom_bytes_state(&rnd_state, writebuf, sz * cnt); 573 573 for (pg = 0; pg < cnt; ++pg) { 574 574 ops.mode = MTD_OPS_AUTO_OOB; ··· 598 598 continue; 599 599 prandom_bytes_state(&rnd_state, writebuf, 600 600 mtd->ecclayout->oobavail * 2); 601 - addr = (i + 1) * mtd->erasesize - mtd->writesize; 601 + addr = (loff_t)(i + 1) * mtd->erasesize - mtd->writesize; 602 602 ops.mode = MTD_OPS_AUTO_OOB; 603 603 ops.len = 0; 604 604 ops.retlen = 0;
+2 -2
drivers/mtd/tests/pagetest.c
··· 52 52 53 53 static int write_eraseblock(int ebnum) 54 54 { 55 - loff_t addr = ebnum * mtd->erasesize; 55 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 56 56 57 57 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize); 58 58 cond_resched(); ··· 64 64 uint32_t j; 65 65 int err = 0, i; 66 66 loff_t addr0, addrn; 67 - loff_t addr = ebnum * mtd->erasesize; 67 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 68 68 69 69 addr0 = 0; 70 70 for (i = 0; i < ebcnt && bbt[i]; ++i)
+1 -1
drivers/mtd/tests/readtest.c
··· 47 47 static int read_eraseblock_by_page(int ebnum) 48 48 { 49 49 int i, ret, err = 0; 50 - loff_t addr = ebnum * mtd->erasesize; 50 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 51 51 void *buf = iobuf; 52 52 void *oobbuf = iobuf1; 53 53
+7 -7
drivers/mtd/tests/speedtest.c
··· 55 55 { 56 56 int err; 57 57 struct erase_info ei; 58 - loff_t addr = ebnum * mtd->erasesize; 58 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 59 59 60 60 memset(&ei, 0, sizeof(struct erase_info)); 61 61 ei.mtd = mtd; ··· 80 80 81 81 static int write_eraseblock(int ebnum) 82 82 { 83 - loff_t addr = ebnum * mtd->erasesize; 83 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 84 84 85 85 return mtdtest_write(mtd, addr, mtd->erasesize, iobuf); 86 86 } ··· 88 88 static int write_eraseblock_by_page(int ebnum) 89 89 { 90 90 int i, err = 0; 91 - loff_t addr = ebnum * mtd->erasesize; 91 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 92 92 void *buf = iobuf; 93 93 94 94 for (i = 0; i < pgcnt; i++) { ··· 106 106 { 107 107 size_t sz = pgsize * 2; 108 108 int i, n = pgcnt / 2, err = 0; 109 - loff_t addr = ebnum * mtd->erasesize; 109 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 110 110 void *buf = iobuf; 111 111 112 112 for (i = 0; i < n; i++) { ··· 124 124 125 125 static int read_eraseblock(int ebnum) 126 126 { 127 - loff_t addr = ebnum * mtd->erasesize; 127 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 128 128 129 129 return mtdtest_read(mtd, addr, mtd->erasesize, iobuf); 130 130 } ··· 132 132 static int read_eraseblock_by_page(int ebnum) 133 133 { 134 134 int i, err = 0; 135 - loff_t addr = ebnum * mtd->erasesize; 135 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 136 136 void *buf = iobuf; 137 137 138 138 for (i = 0; i < pgcnt; i++) { ··· 150 150 { 151 151 size_t sz = pgsize * 2; 152 152 int i, n = pgcnt / 2, err = 0; 153 - loff_t addr = ebnum * mtd->erasesize; 153 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 154 154 void *buf = iobuf; 155 155 156 156 for (i = 0; i < n; i++) {
+5 -5
drivers/mtd/tests/subpagetest.c
··· 57 57 { 58 58 size_t written; 59 59 int err = 0; 60 - loff_t addr = ebnum * mtd->erasesize; 60 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 61 61 62 62 prandom_bytes_state(&rnd_state, writebuf, subpgsize); 63 63 err = mtd_write(mtd, addr, subpgsize, &written, writebuf); ··· 92 92 { 93 93 size_t written; 94 94 int err = 0, k; 95 - loff_t addr = ebnum * mtd->erasesize; 95 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 96 96 97 97 for (k = 1; k < 33; ++k) { 98 98 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize) ··· 131 131 { 132 132 size_t read; 133 133 int err = 0; 134 - loff_t addr = ebnum * mtd->erasesize; 134 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 135 135 136 136 prandom_bytes_state(&rnd_state, writebuf, subpgsize); 137 137 clear_data(readbuf, subpgsize); ··· 192 192 { 193 193 size_t read; 194 194 int err = 0, k; 195 - loff_t addr = ebnum * mtd->erasesize; 195 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 196 196 197 197 for (k = 1; k < 33; ++k) { 198 198 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize) ··· 227 227 uint32_t j; 228 228 size_t read; 229 229 int err = 0; 230 - loff_t addr = ebnum * mtd->erasesize; 230 + loff_t addr = (loff_t)ebnum * mtd->erasesize; 231 231 232 232 memset(writebuf, 0xff, subpgsize); 233 233 for (j = 0; j < mtd->erasesize / subpgsize; ++j) {
+11 -11
include/linux/mtd/cfi.h
··· 153 153 uint16_t MaxBufWriteSize; 154 154 uint8_t NumEraseRegions; 155 155 uint32_t EraseRegionInfo[0]; /* Not host ordered */ 156 - } __attribute__((packed)); 156 + } __packed; 157 157 158 158 /* Extended Query Structure for both PRI and ALT */ 159 159 ··· 161 161 uint8_t pri[3]; 162 162 uint8_t MajorVersion; 163 163 uint8_t MinorVersion; 164 - } __attribute__((packed)); 164 + } __packed; 165 165 166 166 /* Vendor-Specific PRI for Intel/Sharp Extended Command Set (0x0001) */ 167 167 ··· 180 180 uint8_t FactProtRegSize; 181 181 uint8_t UserProtRegSize; 182 182 uint8_t extra[0]; 183 - } __attribute__((packed)); 183 + } __packed; 184 184 185 185 struct cfi_intelext_otpinfo { 186 186 uint32_t ProtRegAddr; ··· 188 188 uint8_t FactProtRegSize; 189 189 uint16_t UserGroups; 190 190 uint8_t UserProtRegSize; 191 - } __attribute__((packed)); 191 + } __packed; 192 192 193 193 struct cfi_intelext_blockinfo { 194 194 uint16_t NumIdentBlocks; ··· 196 196 uint16_t MinBlockEraseCycles; 197 197 uint8_t BitsPerCell; 198 198 uint8_t BlockCap; 199 - } __attribute__((packed)); 199 + } __packed; 200 200 201 201 struct cfi_intelext_regioninfo { 202 202 uint16_t NumIdentPartitions; ··· 205 205 uint8_t NumOpAllowedSimEraMode; 206 206 uint8_t NumBlockTypes; 207 207 struct cfi_intelext_blockinfo BlockTypes[1]; 208 - } __attribute__((packed)); 208 + } __packed; 209 209 210 210 struct cfi_intelext_programming_regioninfo { 211 211 uint8_t ProgRegShift; ··· 214 214 uint8_t Reserved2; 215 215 uint8_t ControlInvalid; 216 216 uint8_t Reserved3; 217 - } __attribute__((packed)); 217 + } __packed; 218 218 219 219 /* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */ 220 220 ··· 233 233 uint8_t VppMin; 234 234 uint8_t VppMax; 235 235 uint8_t TopBottom; 236 - } __attribute__((packed)); 236 + } __packed; 237 237 238 238 /* Vendor-Specific PRI for Atmel chips (command set 0x0002) */ 239 239 ··· 245 245 uint8_t BottomBoot; 246 246 uint8_t BurstMode; 247 247 uint8_t PageMode; 248 - } __attribute__((packed)); 248 + } __packed; 249 249 250 250 struct cfi_pri_query { 251 251 uint8_t NumFields; 252 252 uint32_t ProtField[1]; /* Not host ordered */ 253 - } __attribute__((packed)); 253 + } __packed; 254 254 255 255 struct cfi_bri_query { 256 256 uint8_t PageModeReadCap; 257 257 uint8_t NumFields; 258 258 uint32_t ConfField[1]; /* Not host ordered */ 259 - } __attribute__((packed)); 259 + } __packed; 260 260 261 261 #define P_ID_NONE 0x0000 262 262 #define P_ID_INTEL_EXT 0x0001
+12
include/linux/mtd/nand.h
··· 587 587 * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds, 588 588 * also from the datasheet. It is the recommended ECC step 589 589 * size, if known; if unknown, set to zero. 590 + * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is 591 + * either deduced from the datasheet if the NAND 592 + * chip is not ONFI compliant or set to 0 if it is 593 + * (an ONFI chip is always configured in mode 0 594 + * after a NAND reset) 590 595 * @numchips: [INTERN] number of physical chips 591 596 * @chipsize: [INTERN] the size of one chip for multichip arrays 592 597 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 ··· 676 671 uint8_t bits_per_cell; 677 672 uint16_t ecc_strength_ds; 678 673 uint16_t ecc_step_ds; 674 + int onfi_timing_mode_default; 679 675 int badblockpos; 680 676 int badblockbits; 681 677 ··· 772 766 * @options: stores various chip bit options 773 767 * @id_len: The valid length of the @id. 774 768 * @oobsize: OOB size 769 + * @ecc: ECC correctability and step information from the datasheet. 775 770 * @ecc.strength_ds: The ECC correctability from the datasheet, same as the 776 771 * @ecc_strength_ds in nand_chip{}. 777 772 * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the 778 773 * @ecc_step_ds in nand_chip{}, also from the datasheet. 779 774 * For example, the "4bit ECC for each 512Byte" can be set with 780 775 * NAND_ECC_INFO(4, 512). 776 + * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND 777 + * reset. Should be deduced from timings described 778 + * in the datasheet. 779 + * 781 780 */ 782 781 struct nand_flash_dev { 783 782 char *name; ··· 803 792 uint16_t strength_ds; 804 793 uint16_t step_ds; 805 794 } ecc; 795 + int onfi_timing_mode_default; 806 796 }; 807 797 808 798 /**
+16
include/linux/platform_data/elm.h
··· 42 42 int error_loc[16]; 43 43 }; 44 44 45 + #if IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH) 45 46 void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc, 46 47 struct elm_errorvec *err_vec); 47 48 int elm_config(struct device *dev, enum bch_ecc bch_type, 48 49 int ecc_steps, int ecc_step_size, int ecc_syndrome_size); 50 + #else 51 + static inline void 52 + elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc, 53 + struct elm_errorvec *err_vec) 54 + { 55 + } 56 + 57 + static inline int elm_config(struct device *dev, enum bch_ecc bch_type, 58 + int ecc_steps, int ecc_step_size, 59 + int ecc_syndrome_size) 60 + { 61 + return -ENOSYS; 62 + } 63 + #endif /* CONFIG_MTD_NAND_ECC_BCH */ 64 + 49 65 #endif /* __ELM_H */
+1
include/linux/platform_data/mtd-nand-omap2.h
··· 71 71 struct mtd_partition *parts; 72 72 int nr_parts; 73 73 bool dev_ready; 74 + bool flash_bbt; 74 75 enum nand_io xfer_type; 75 76 int devsize; 76 77 enum omap_ecc ecc_opt;