History

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 ...

Linus Torvalds committed 12 years ago

Commit 511c41d2 parents 88ed806 8b3d58e45 files · +757 −562Browse files

Unified · Split

45 files
  1. Documentation/devicetree/bindings/mtd/atmel-nand.txt +2 −0
  2. Documentation/devicetree/bindings/mtd/mtd-physmap.txt +2 −2
  3. MAINTAINERS +1 −0
  4. arch/arm/mach-omap2/gpmc.c +2 −0
  5. drivers/mtd/bcm47xxpart.c +11 −0
  6. drivers/mtd/chips/cfi_cmdset_0002.c +2 −0
  7. drivers/mtd/devices/Makefile +0 −1
  8. drivers/mtd/devices/docg3.c +13 −13
  9. drivers/mtd/devices/m25p80.c +20 −2
  10. drivers/mtd/maps/Kconfig +1 −1
  11. drivers/mtd/maps/gpio-addr-flash.c +28 −14
  12. drivers/mtd/maps/pcmciamtd.c +1 −1
  13. drivers/mtd/maps/physmap_of.c +5 −1
  14. drivers/mtd/mtdchar.c +3 −0
  15. drivers/mtd/mtdcore.c +18 −21
  16. drivers/mtd/mtdswap.c +4 −4
  17. drivers/mtd/nand/Kconfig +5 −2
  18. drivers/mtd/nand/Makefile +1 −0
  19. drivers/mtd/nand/atmel_nand.c +58 −38
  20. drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c +49 −8
  21. drivers/mtd/nand/denali.c +304 −261
  22. drivers/mtd/nand/denali.h +4 −23
  23. drivers/mtd/nand/nand_base.c +27 −11
  24. drivers/mtd/nand/nand_bbt.c +10 −13
  25. drivers/mtd/nand/nand_ids.c +4 −0
  26. drivers/mtd/nand/nand_timings.c +1 −1
  27. drivers/mtd/nand/nandsim.c +1 −1
  28. drivers/mtd/nand/ndfc.c +2 −1
  29. drivers/mtd/nand/omap2.c +93 −73
  30. drivers/mtd/nand/omap_elm.c +0 −0
  31. drivers/mtd/nand/sm_common.h +1 −1
  32. drivers/mtd/sm_ftl.c +1 −1
  33. drivers/mtd/spi-nor/Kconfig +14 −0
  34. drivers/mtd/spi-nor/spi-nor.c +7 −35
  35. drivers/mtd/tests/mtd_test.c +2 −2
  36. drivers/mtd/tests/nandbiterrs.c +1 −1
  37. drivers/mtd/tests/oobtest.c +4 −4
  38. drivers/mtd/tests/pagetest.c +2 −2
  39. drivers/mtd/tests/readtest.c +1 −1
  40. drivers/mtd/tests/speedtest.c +7 −7
  41. drivers/mtd/tests/subpagetest.c +5 −5
  42. include/linux/mtd/cfi.h +11 −11
  43. include/linux/mtd/nand.h +12 −0
  44. include/linux/platform_data/elm.h +16 −0
  45. include/linux/platform_data/mtd-nand-omap2.h +1 −0
Documentation/devicetree/bindings/mtd/atmel-nand.txt+2−0
@@ -36,6 +36,7 @@ Optional properties: · 35 unmodified lines
3636 - reg : should specify the address and size used for NFC command registers,
3737 NFC registers and NFC Sram. NFC Sram address and size can be absent
3838 if don't want to use it.
39+ - clocks: phandle to the peripheral clock
3940 - Optional properties:
4041 - atmel,write-by-sram: boolean to enable NFC write by sram.
4142
@@ -98,6 +99,7 @@ nand0: nand@40000000 { · 56 unmodified lines
9899 compatible = "atmel,sama5d3-nfc";
99100 #address-cells = <1>;
100101 #size-cells = <1>;
102+ clocks = <&hsmc_clk>
101103 reg = <
102104 0x70000000 0x10000000 /* NFC Command Registers */
103105 0xffffc000 0x00000070 /* NFC HSMC regs */
Documentation/devicetree/bindings/mtd/mtd-physmap.txt+2−2
@@ -4,8 +4,8 @@ Flash chips (Memory Technology Devices) are often used for solid state · 3 unmodified lines
44 file systems on embedded devices.
55
66 - 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".
99 - reg : Address range(s) of the mtd chip(s)
1010 It's possible to (optionally) define multiple "reg" tuples so that
1111 non-identical chips can be described in one node.
MAINTAINERS+1−0
@@ -5992,6 +5992,7 @@ L: linux-mtd@lists.infradead.org · 5991 unmodified lines
59925992 W: http://www.linux-mtd.infradead.org/
59935993 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/
59945994 T: git git://git.infradead.org/linux-mtd.git
5995+T: git git://git.infradead.org/l2-mtd.git
59955996 S: Maintained
59965997 F: drivers/mtd/
59975998 F: include/linux/mtd/
arch/arm/mach-omap2/gpmc.c+2−0
@@ -1440,6 +1440,8 @@ static int gpmc_probe_nand_child(struct platform_device *pdev, · 1439 unmodified lines
14401440 break;
14411441 }
14421442
1443+ gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child);
1444+
14431445 val = of_get_nand_bus_width(child);
14441446 if (val == 16)
14451447 gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
drivers/mtd/bcm47xxpart.c+11−0
@@ -199,6 +199,17 @@ static int bcm47xxpart_parse(struct mtd_info *master, · 198 unmodified lines
199199 continue;
200200 }
201201
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+
202213 /* Read middle of the block */
203214 if (mtd_read(master, offset + 0x8000, 0x4,
204215 &bytes_read, (uint8_t *)buf) < 0) {
drivers/mtd/chips/cfi_cmdset_0002.c+2−0
@@ -2033,6 +2033,8 @@ static int cfi_amdstd_panic_wait(struct map_info *map, struct flchip *chip, · 2032 unmodified lines
20332033
20342034 udelay(1);
20352035 }
2036+
2037+ retries--;
20362038 }
20372039
20382040 /* the chip never became ready */
drivers/mtd/devices/Makefile+0−1
@@ -12,7 +12,6 @@ obj-$(CONFIG_MTD_LART) += lart.o · 11 unmodified lines
1212 obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o
1313 obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
1414 obj-$(CONFIG_MTD_M25P80) += m25p80.o
15−obj-$(CONFIG_MTD_NAND_OMAP_BCH) += elm.o
1615 obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o
1716 obj-$(CONFIG_MTD_SST25L) += sst25l.o
1817 obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o
drivers/mtd/devices/docg3.c+13−13
@@ -1697,16 +1697,16 @@ static int dbg_asicmode_show(struct seq_file *s, void *p) · 1696 unmodified lines
16971697
16981698 switch (mode) {
16991699 case DOC_ASICMODE_RESET:
1700− pos += seq_printf(s, "reset");
1700+ pos += seq_puts(s, "reset");
17011701 break;
17021702 case DOC_ASICMODE_NORMAL:
1703− pos += seq_printf(s, "normal");
1703+ pos += seq_puts(s, "normal");
17041704 break;
17051705 case DOC_ASICMODE_POWERDOWN:
1706− pos += seq_printf(s, "powerdown");
1706+ pos += seq_puts(s, "powerdown");
17071707 break;
17081708 }
1709− pos += seq_printf(s, ")\n");
1709+ pos += seq_puts(s, ")\n");
17101710 return pos;
17111711 }
17121712 DEBUGFS_RO_ATTR(asic_mode, dbg_asicmode_show);
@@ -1745,22 +1745,22 @@ static int dbg_protection_show(struct seq_file *s, void *p) · 32 unmodified lines
17451745 pos += seq_printf(s, "Protection = 0x%02x (",
17461746 protect);
17471747 if (protect & DOC_PROTECT_FOUNDRY_OTP_LOCK)
1748− pos += seq_printf(s, "FOUNDRY_OTP_LOCK,");
1748+ pos += seq_puts(s, "FOUNDRY_OTP_LOCK,");
17491749 if (protect & DOC_PROTECT_CUSTOMER_OTP_LOCK)
1750− pos += seq_printf(s, "CUSTOMER_OTP_LOCK,");
1750+ pos += seq_puts(s, "CUSTOMER_OTP_LOCK,");
17511751 if (protect & DOC_PROTECT_LOCK_INPUT)
1752− pos += seq_printf(s, "LOCK_INPUT,");
1752+ pos += seq_puts(s, "LOCK_INPUT,");
17531753 if (protect & DOC_PROTECT_STICKY_LOCK)
1754− pos += seq_printf(s, "STICKY_LOCK,");
1754+ pos += seq_puts(s, "STICKY_LOCK,");
17551755 if (protect & DOC_PROTECT_PROTECTION_ENABLED)
1756− pos += seq_printf(s, "PROTECTION ON,");
1756+ pos += seq_puts(s, "PROTECTION ON,");
17571757 if (protect & DOC_PROTECT_IPL_DOWNLOAD_LOCK)
1758− pos += seq_printf(s, "IPL_DOWNLOAD_LOCK,");
1758+ pos += seq_puts(s, "IPL_DOWNLOAD_LOCK,");
17591759 if (protect & DOC_PROTECT_PROTECTION_ERROR)
1760− pos += seq_printf(s, "PROTECT_ERR,");
1760+ pos += seq_puts(s, "PROTECT_ERR,");
17611761 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");
17641764
17651765 pos += seq_printf(s, "DPS0 = 0x%02x : "
17661766 "Protected area [0x%x - 0x%x] : OTP=%d, READ=%d, "
drivers/mtd/devices/m25p80.c+20−2
@@ -193,11 +193,14 @@ static int m25p_probe(struct spi_device *spi) · 192 unmodified lines
193193 {
194194 struct mtd_part_parser_data ppdata;
195195 struct flash_platform_data *data;
196+ const struct spi_device_id *id = NULL;
196197 struct m25p *flash;
197198 struct spi_nor *nor;
198199 enum read_mode mode = SPI_NOR_NORMAL;
199200 int ret;
200201
202+ data = dev_get_platdata(&spi->dev);
203+
201204 flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL);
202205 if (!flash)
203206 return -ENOMEM;
@@ -223,11 +226,26 @@ static int m25p_probe(struct spi_device *spi) · 19 unmodified lines
223226 mode = SPI_NOR_QUAD;
224227 else if (spi->mode & SPI_RX_DUAL)
225228 mode = SPI_NOR_DUAL;
226− ret = spi_nor_scan(nor, spi_get_device_id(spi), mode);
229+
230+ if (data && data->name)
231+ flash->mtd.name = data->name;
232+
233+ /* For some (historical?) reason many platforms provide two different
234+ * names in flash_platform_data: "name" and "type". Quite often name is
235+ * set to "m25p80" and then "type" provides a real chip name.
236+ * If that's the case, respect "type" and ignore a "name".
237+ */
238+ if (data && data->type)
239+ id = spi_nor_match_id(data->type);
240+
241+ /* If we didn't get name from platform, simply use "modalias". */
242+ if (!id)
243+ id = spi_get_device_id(spi);
244+
245+ ret = spi_nor_scan(nor, id, mode);
227246 if (ret)
228247 return ret;
229248
230− data = dev_get_platdata(&spi->dev);
231249 ppdata.of_node = spi->dev.of_node;
232250
233251 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
drivers/mtd/maps/Kconfig+1−1
@@ -249,7 +249,7 @@ config MTD_CFI_FLAGADM · 248 unmodified lines
249249
250250 config MTD_SOLUTIONENGINE
251251 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
253253 help
254254 This enables access to the flash chips on the Hitachi SolutionEngine and
255255 similar boards. Say 'Y' if you are building a kernel for such a board.
drivers/mtd/maps/gpio-addr-flash.c+28−14
@@ -99,22 +99,28 @@ static map_word gf_read(struct map_info *map, unsigned long ofs) · 98 unmodified lines
9999 * @from: flash offset to copy from
100100 * @len: how much to copy
101101 *
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.
106104 */
107105 static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
108106 {
109107 struct async_state *state = gf_map_info_to_state(map);
110108
111− gf_set_gpios(state, from);
109+ int this_len;
112110
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;
115116
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+ }
118124 }
119125
120126 /**
@@ -147,13 +153,21 @@ static void gf_copy_to(struct map_info *map, unsigned long to, · 26 unmodified lines
147153 {
148154 struct async_state *state = gf_map_info_to_state(map);
149155
150− gf_set_gpios(state, to);
156+ int this_len;
157+
158+ while (len) {
159+ if ((to % state->win_size) + len > state->win_size)
160+ this_len = state->win_size - (to % state->win_size);
161+ else
162+ this_len = len;
151163
152− /* BUG if operation crosses the win_size */
153− BUG_ON(!((to + len) % state->win_size <= (to + len)));
164+ gf_set_gpios(state, to);
165+ memcpy_toio(map->virt + (to % state->win_size), from, len);
154166
155− /* operation does not cross the win_size, so one shot it */
156− memcpy_toio(map->virt + (to % state->win_size), from, len);
167+ len -= this_len;
168+ to += this_len;
169+ from += this_len;
170+ }
157171 }
158172
159173 static const char * const part_probe_types[] = {
drivers/mtd/maps/pcmciamtd.c+1−1
@@ -89,7 +89,7 @@ static caddr_t remap_window(struct map_info *map, unsigned long to) · 88 unmodified lines
8989
9090 if (!pcmcia_dev_present(dev->p_dev)) {
9191 pr_debug("device removed\n");
92− return 0;
92+ return NULL;
9393 }
9494
9595 offset = to & ~(dev->win_size-1);
drivers/mtd/maps/physmap_of.c+5−1
@@ -103,7 +103,7 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev, · 102 unmodified lines
103103 if (strcmp(of_probe, "ROM") != 0)
104104 dev_warn(&dev->dev, "obsolete_probe: don't know probe "
105105 "type '%s', mapping as rom\n", of_probe);
106− return do_map_probe("mtd_rom", map);
106+ return do_map_probe("map_rom", map);
107107 }
108108 }
109109
@@ -339,6 +339,10 @@ static struct of_device_id of_flash_match[] = { · 229 unmodified lines
339339 .compatible = "mtd-ram",
340340 .data = (void *)"map_ram",
341341 },
342+ {
343+ .compatible = "mtd-rom",
344+ .data = (void *)"map_rom",
345+ },
342346 {
343347 .type = "rom",
344348 .compatible = "direct-mapped"
drivers/mtd/mtdchar.c+3−0
@@ -549,6 +549,9 @@ static int mtdchar_blkpg_ioctl(struct mtd_info *mtd, · 548 unmodified lines
549549 if (mtd_is_partition(mtd))
550550 return -EINVAL;
551551
552+ /* Sanitize user input */
553+ p.devname[BLKPG_DEVNAMELTH - 1] = '\0';
554+
552555 return mtd_add_partition(mtd, p.devname, p.start, p.length);
553556
554557 case BLKPG_DEL_PARTITION:
drivers/mtd/mtdcore.c+18−21
@@ -105,12 +105,11 @@ static LIST_HEAD(mtd_notifiers); · 104 unmodified lines
105105 */
106106 static void mtd_release(struct device *dev)
107107 {
108− struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev);
108+ struct mtd_info *mtd = dev_get_drvdata(dev);
109109 dev_t index = MTD_DEVT(mtd->index);
110110
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);
114113 }
115114
116115 static int mtd_cls_suspend(struct device *dev, pm_message_t state)
@@ -442,10 +441,8 @@ int add_mtd_device(struct mtd_info *mtd) · 325 unmodified lines
442441 if (device_register(&mtd->dev) != 0)
443442 goto fail_added;
444443
445− if (MTD_DEVT(i))
446− device_create(&mtd_class, mtd->dev.parent,
447− MTD_DEVT(i) + 1,
448− NULL, "mtd%dro", i);
444+ device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
445+ "mtd%dro", i);
449446
450447 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
451448 /* No need to get a refcount on the module containing
@@ -778,7 +775,7 @@ EXPORT_SYMBOL_GPL(__put_mtd_device); · 326 unmodified lines
778775 */
779776 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
780777 {
781− if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
778+ if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr)
782779 return -EINVAL;
783780 if (!(mtd->flags & MTD_WRITEABLE))
784781 return -EROFS;
@@ -804,7 +801,7 @@ int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, · 19 unmodified lines
804801 *phys = 0;
805802 if (!mtd->_point)
806803 return -EOPNOTSUPP;
807− if (from < 0 || from > mtd->size || len > mtd->size - from)
804+ if (from < 0 || from >= mtd->size || len > mtd->size - from)
808805 return -EINVAL;
809806 if (!len)
810807 return 0;
@@ -817,7 +814,7 @@ int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) · 6 unmodified lines
817814 {
818815 if (!mtd->_point)
819816 return -EOPNOTSUPP;
820− if (from < 0 || from > mtd->size || len > mtd->size - from)
817+ if (from < 0 || from >= mtd->size || len > mtd->size - from)
821818 return -EINVAL;
822819 if (!len)
823820 return 0;
@@ -835,7 +832,7 @@ unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len, · 11 unmodified lines
835832 {
836833 if (!mtd->_get_unmapped_area)
837834 return -EOPNOTSUPP;
838− if (offset > mtd->size || len > mtd->size - offset)
835+ if (offset >= mtd->size || len > mtd->size - offset)
839836 return -EINVAL;
840837 return mtd->_get_unmapped_area(mtd, len, offset, flags);
841838 }
@@ -846,7 +843,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, · 4 unmodified lines
846843 {
847844 int ret_code;
848845 *retlen = 0;
849− if (from < 0 || from > mtd->size || len > mtd->size - from)
846+ if (from < 0 || from >= mtd->size || len > mtd->size - from)
850847 return -EINVAL;
851848 if (!len)
852849 return 0;
@@ -869,7 +866,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, · 16 unmodified lines
869866 const u_char *buf)
870867 {
871868 *retlen = 0;
872− if (to < 0 || to > mtd->size || len > mtd->size - to)
869+ if (to < 0 || to >= mtd->size || len > mtd->size - to)
873870 return -EINVAL;
874871 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
875872 return -EROFS;
@@ -892,7 +889,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, · 16 unmodified lines
892889 *retlen = 0;
893890 if (!mtd->_panic_write)
894891 return -EOPNOTSUPP;
895− if (to < 0 || to > mtd->size || len > mtd->size - to)
892+ if (to < 0 || to >= mtd->size || len > mtd->size - to)
896893 return -EINVAL;
897894 if (!(mtd->flags & MTD_WRITEABLE))
898895 return -EROFS;
@@ -1011,7 +1008,7 @@ int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · 112 unmodified lines
10111008 {
10121009 if (!mtd->_lock)
10131010 return -EOPNOTSUPP;
1014− if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1011+ if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
10151012 return -EINVAL;
10161013 if (!len)
10171014 return 0;
@@ -1023,7 +1020,7 @@ int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · 5 unmodified lines
10231020 {
10241021 if (!mtd->_unlock)
10251022 return -EOPNOTSUPP;
1026− if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1023+ if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
10271024 return -EINVAL;
10281025 if (!len)
10291026 return 0;
@@ -1035,7 +1032,7 @@ int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) · 5 unmodified lines
10351032 {
10361033 if (!mtd->_is_locked)
10371034 return -EOPNOTSUPP;
1038− if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1035+ if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
10391036 return -EINVAL;
10401037 if (!len)
10411038 return 0;
@@ -1045,7 +1042,7 @@ EXPORT_SYMBOL_GPL(mtd_is_locked); · 3 unmodified lines
10451042
10461043 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs)
10471044 {
1048− if (ofs < 0 || ofs > mtd->size)
1045+ if (ofs < 0 || ofs >= mtd->size)
10491046 return -EINVAL;
10501047 if (!mtd->_block_isreserved)
10511048 return 0;
@@ -1055,7 +1052,7 @@ EXPORT_SYMBOL_GPL(mtd_block_isreserved); · 3 unmodified lines
10551052
10561053 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
10571054 {
1058− if (ofs < 0 || ofs > mtd->size)
1055+ if (ofs < 0 || ofs >= mtd->size)
10591056 return -EINVAL;
10601057 if (!mtd->_block_isbad)
10611058 return 0;
@@ -1067,7 +1064,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) · 5 unmodified lines
10671064 {
10681065 if (!mtd->_block_markbad)
10691066 return -EOPNOTSUPP;
1070− if (ofs < 0 || ofs > mtd->size)
1067+ if (ofs < 0 || ofs >= mtd->size)
10711068 return -EINVAL;
10721069 if (!(mtd->flags & MTD_WRITEABLE))
10731070 return -EROFS;
drivers/mtd/mtdswap.c+4−4
@@ -145,7 +145,7 @@ struct mtdswap_dev { · 144 unmodified lines
145145 struct mtdswap_oobdata {
146146 __le16 magic;
147147 __le32 count;
148−} __attribute__((packed));
148+} __packed;
149149
150150 #define MTDSWAP_MAGIC_CLEAN 0x2095
151151 #define MTDSWAP_MAGIC_DIRTY (MTDSWAP_MAGIC_CLEAN + 1)
@@ -1287,7 +1287,7 @@ static int mtdswap_show(struct seq_file *s, void *data) · 1135 unmodified lines
12871287
12881288 seq_printf(s, "total erasures: %lu\n", sum);
12891289
1290− seq_printf(s, "\n");
1290+ seq_puts(s, "\n");
12911291
12921292 seq_printf(s, "mtdswap_readsect count: %llu\n", d->sect_read_count);
12931293 seq_printf(s, "mtdswap_writesect count: %llu\n", d->sect_write_count);
@@ -1296,7 +1296,7 @@ static int mtdswap_show(struct seq_file *s, void *data) · 2 unmodified lines
12961296 seq_printf(s, "mtd write count: %llu\n", d->mtd_write_count);
12971297 seq_printf(s, "discarded pages count: %llu\n", d->discard_page_count);
12981298
1299− seq_printf(s, "\n");
1299+ seq_puts(s, "\n");
13001300 seq_printf(s, "total pages: %u\n", pages);
13011301 seq_printf(s, "pages mapped: %u\n", mapped);
13021302
@@ -1474,7 +1474,7 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) · 171 unmodified lines
14741474 }
14751475
14761476 eblocks = mtd_div_by_eb(use_size, mtd);
1477− use_size = eblocks * mtd->erasesize;
1477+ use_size = (uint64_t)eblocks * mtd->erasesize;
14781478 bad_blocks = mtdswap_badblocks(mtd, use_size);
14791479 eavailable = eblocks - bad_blocks;
14801480
drivers/mtd/nand/Kconfig+5−2
@@ -96,7 +96,7 @@ config MTD_NAND_OMAP2 · 95 unmodified lines
9696
9797 config MTD_NAND_OMAP_BCH
9898 depends on MTD_NAND_OMAP2
99− tristate "Support hardware based BCH error correction"
99+ bool "Support hardware based BCH error correction"
100100 default n
101101 select BCH
102102 help
@@ -104,7 +104,10 @@ config MTD_NAND_OMAP_BCH · 1 unmodified line
104104 locate and correct errors when using BCH ECC scheme. This offloads
105105 the cpu from doing ECC error searching and correction. However some
106106 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
108111
109112 config MTD_NAND_IDS
110113 tristate
drivers/mtd/nand/Makefile+1−0
@@ -27,6 +27,7 @@ obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o · 26 unmodified lines
2727 obj-$(CONFIG_MTD_NAND_ATMEL) += atmel_nand.o
2828 obj-$(CONFIG_MTD_NAND_GPIO) += gpio.o
2929 obj-$(CONFIG_MTD_NAND_OMAP2) += omap2.o
30+obj-$(CONFIG_MTD_NAND_OMAP_BCH_BUILD) += omap_elm.o
3031 obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o
3132 obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
3233 obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o
drivers/mtd/nand/atmel_nand.c+58−38
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 *
2828 */
2929
30+#include <linux/clk.h>
3031 #include <linux/dma-mapping.h>
3132 #include <linux/slab.h>
3233 #include <linux/module.h>
@@ -96,6 +97,8 @@ struct atmel_nfc { · 63 unmodified lines
9697 bool use_nfc_sram;
9798 bool write_by_sram;
9899
100+ struct clk *clk;
101+
99102 bool is_initialized;
100103 struct completion comp_ready;
101104 struct completion comp_cmd_done;
@@ -128,8 +131,6 @@ struct atmel_nand_host { · 26 unmodified lines
128131 u32 pmecc_lookup_table_offset_512;
129132 u32 pmecc_lookup_table_offset_1024;
130133
131− int pmecc_bytes_per_sector;
132− int pmecc_sector_number;
133134 int pmecc_degree; /* Degree of remainders */
134135 int pmecc_cw_len; /* Length of codeword */
135136
@@ -841,7 +842,7 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc, · 705 unmodified lines
841842 pos, bit_pos, err_byte, *(buf + byte_pos));
842843 } else {
843844 /* Bit flip in OOB area */
844− tmp = sector_num * host->pmecc_bytes_per_sector
845+ tmp = sector_num * nand_chip->ecc.bytes
845846 + (byte_pos - sector_size);
846847 err_byte = ecc[tmp];
847848 ecc[tmp] ^= (1 << bit_pos);
@@ -874,7 +875,7 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf, · 26 unmodified lines
874875 return 0;
875876
876877 normal_check:
877− for (i = 0; i < host->pmecc_sector_number; i++) {
878+ for (i = 0; i < nand_chip->ecc.steps; i++) {
878879 err_nbr = 0;
879880 if (pmecc_stat & 0x1) {
880881 buf_pos = buf + i * host->pmecc_sector_size;
@@ -890,7 +891,7 @@ normal_check: · 9 unmodified lines
890891 return -EIO;
891892 } else {
892893 pmecc_correct_data(mtd, buf_pos, ecc, i,
893− host->pmecc_bytes_per_sector, err_nbr);
894+ nand_chip->ecc.bytes, err_nbr);
894895 mtd->ecc_stats.corrected += err_nbr;
895896 total_err += err_nbr;
896897 }
@@ -984,11 +985,11 @@ static int atmel_nand_pmecc_write_page(struct mtd_info *mtd, · 87 unmodified lines
984985 cpu_relax();
985986 }
986987
987− for (i = 0; i < host->pmecc_sector_number; i++) {
988− for (j = 0; j < host->pmecc_bytes_per_sector; j++) {
988+ for (i = 0; i < chip->ecc.steps; i++) {
989+ for (j = 0; j < chip->ecc.bytes; j++) {
989990 int pos;
990991
991− pos = i * host->pmecc_bytes_per_sector + j;
992+ pos = i * chip->ecc.bytes + j;
992993 chip->oob_poi[eccpos[pos]] =
993994 pmecc_readb_ecc_relaxed(host->ecc, i, j);
994995 }
@@ -1031,7 +1032,7 @@ static void atmel_pmecc_core_init(struct mtd_info *mtd) · 36 unmodified lines
10311032 else if (host->pmecc_sector_size == 1024)
10321033 val |= PMECC_CFG_SECTOR1024;
10331034
1034− switch (host->pmecc_sector_number) {
1035+ switch (nand_chip->ecc.steps) {
10351036 case 1:
10361037 val |= PMECC_CFG_PAGE_1SECTOR;
10371038 break;
@@ -1148,7 +1149,6 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, · 110 unmodified lines
11481149
11491150 host->ecc = devm_ioremap_resource(&pdev->dev, regs);
11501151 if (IS_ERR(host->ecc)) {
1151− dev_err(host->dev, "ioremap failed\n");
11521152 err_no = PTR_ERR(host->ecc);
11531153 goto err;
11541154 }
@@ -1156,8 +1156,6 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, · 1 unmodified line
11561156 regs_pmerr = platform_get_resource(pdev, IORESOURCE_MEM, 2);
11571157 host->pmerrloc_base = devm_ioremap_resource(&pdev->dev, regs_pmerr);
11581158 if (IS_ERR(host->pmerrloc_base)) {
1159− dev_err(host->dev,
1160− "Can not get I/O resource for PMECC ERRLOC controller!\n");
11611159 err_no = PTR_ERR(host->pmerrloc_base);
11621160 goto err;
11631161 }
@@ -1165,7 +1163,6 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, · 1 unmodified line
11651163 regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3);
11661164 host->pmecc_rom_base = devm_ioremap_resource(&pdev->dev, regs_rom);
11671165 if (IS_ERR(host->pmecc_rom_base)) {
1168− dev_err(host->dev, "Can not get I/O resource for ROM!\n");
11691166 err_no = PTR_ERR(host->pmecc_rom_base);
11701167 goto err;
11711168 }
@@ -1174,22 +1171,29 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, · 2 unmodified lines
11741171
11751172 /* set ECC page size and oob layout */
11761173 switch (mtd->writesize) {
1174+ case 512:
1175+ case 1024:
11771176 case 2048:
1177+ case 4096:
1178+ case 8192:
1179+ if (sector_size > mtd->writesize) {
1180+ dev_err(host->dev, "pmecc sector size is bigger than the page size!\n");
1181+ err_no = -EINVAL;
1182+ goto err;
1183+ }
1184+
11781185 host->pmecc_degree = (sector_size == 512) ?
11791186 PMECC_GF_DIMENSION_13 : PMECC_GF_DIMENSION_14;
11801187 host->pmecc_cw_len = (1 << host->pmecc_degree) - 1;
1181− host->pmecc_sector_number = mtd->writesize / sector_size;
1182− host->pmecc_bytes_per_sector = pmecc_get_ecc_bytes(
1183− cap, sector_size);
11841188 host->pmecc_alpha_to = pmecc_get_alpha_to(host);
11851189 host->pmecc_index_of = host->pmecc_rom_base +
11861190 host->pmecc_lookup_table_offset;
11871191
1188− nand_chip->ecc.steps = host->pmecc_sector_number;
11891192 nand_chip->ecc.strength = cap;
1190− nand_chip->ecc.bytes = host->pmecc_bytes_per_sector;
1191− nand_chip->ecc.total = host->pmecc_bytes_per_sector *
1192− host->pmecc_sector_number;
1193+ nand_chip->ecc.bytes = pmecc_get_ecc_bytes(cap, sector_size);
1194+ nand_chip->ecc.steps = mtd->writesize / sector_size;
1195+ nand_chip->ecc.total = nand_chip->ecc.bytes *
1196+ nand_chip->ecc.steps;
11931197 if (nand_chip->ecc.total > mtd->oobsize - 2) {
11941198 dev_err(host->dev, "No room for ECC bytes\n");
11951199 err_no = -EINVAL;
@@ -1201,13 +1205,9 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, · 5 unmodified lines
12011205
12021206 nand_chip->ecc.layout = &atmel_pmecc_oobinfo;
12031207 break;
1204− case 512:
1205− case 1024:
1206− case 4096:
1207− /* TODO */
1208+ default:
12081209 dev_warn(host->dev,
12091210 "Unsupported page size for PMECC, use Software ECC\n");
1210− default:
12111211 /* page size not handled by HW ECC */
12121212 /* switching back to soft ECC */
12131213 nand_chip->ecc.mode = NAND_ECC_SOFT;
@@ -1530,10 +1530,8 @@ static int atmel_hw_nand_init_params(struct platform_device *pdev, · 316 unmodified lines
15301530 }
15311531
15321532 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))
15351534 return PTR_ERR(host->ecc);
1536− }
15371535
15381536 /* ECC is calculated for the whole page (1 step) */
15391537 nand_chip->ecc.size = mtd->writesize;
@@ -1907,15 +1905,7 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip, · 367 unmodified lines
19071905 if (offset || (data_len < mtd->writesize))
19081906 return -EINVAL;
19091907
1910− cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
19111908 len = mtd->writesize;
1912−
1913− if (unlikely(raw)) {
1914− len += mtd->oobsize;
1915− nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
1916− } else
1917− nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
1918−
19191909 /* Copy page data to sram that will write to nand via NFC */
19201910 if (use_dma) {
19211911 if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) != 0)
@@ -1925,6 +1915,15 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip, · 3 unmodified lines
19251915 memcpy32_toio(sram, buf, len);
19261916 }
19271917
1918+ cfg = nfc_readl(host->nfc->hsmc_regs, CFG);
1919+ if (unlikely(raw) && oob_required) {
1920+ memcpy32_toio(sram + len, chip->oob_poi, mtd->oobsize);
1921+ len += mtd->oobsize;
1922+ nfc_writel(host->nfc->hsmc_regs, CFG, cfg | NFC_CFG_WSPARE);
1923+ } else {
1924+ nfc_writel(host->nfc->hsmc_regs, CFG, cfg & ~NFC_CFG_WSPARE);
1925+ }
1926+
19281927 if (chip->ecc.mode == NAND_ECC_HW && host->has_pmecc)
19291928 /*
19301929 * When use NFC sram, need set up PMECC before send
@@ -2040,7 +2039,6 @@ static int atmel_nand_probe(struct platform_device *pdev) · 109 unmodified lines
20402039 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
20412040 host->io_base = devm_ioremap_resource(&pdev->dev, mem);
20422041 if (IS_ERR(host->io_base)) {
2043− dev_err(&pdev->dev, "atmel_nand: ioremap resource failed\n");
20442042 res = PTR_ERR(host->io_base);
20452043 goto err_nand_ioremap;
20462044 }
@@ -2099,7 +2097,7 @@ static int atmel_nand_probe(struct platform_device *pdev) · 52 unmodified lines
20992097 }
21002098
21012099 nand_chip->ecc.mode = host->board.ecc_mode;
2102− nand_chip->chip_delay = 20; /* 20us command delay time */
2100+ nand_chip->chip_delay = 40; /* 40us command delay time */
21032101
21042102 if (host->board.bus_width_16) /* 16-bit bus width */
21052103 nand_chip->options |= NAND_BUSWIDTH_16;
@@ -2248,6 +2246,7 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev) · 142 unmodified lines
22482246 {
22492247 struct atmel_nfc *nfc = &nand_nfc;
22502248 struct resource *nfc_cmd_regs, *nfc_hsmc_regs, *nfc_sram;
2249+ int ret;
22512250
22522251 nfc_cmd_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
22532252 nfc->base_cmd_regs = devm_ioremap_resource(&pdev->dev, nfc_cmd_regs);
@@ -2279,8 +2278,28 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev) · 25 unmodified lines
22792278 nfc_writel(nfc->hsmc_regs, IDR, 0xffffffff);
22802279 nfc_readl(nfc->hsmc_regs, SR); /* clear the NFC_SR */
22812280
2281+ nfc->clk = devm_clk_get(&pdev->dev, NULL);
2282+ if (!IS_ERR(nfc->clk)) {
2283+ ret = clk_prepare_enable(nfc->clk);
2284+ if (ret)
2285+ return ret;
2286+ } else {
2287+ dev_warn(&pdev->dev, "NFC clock missing, update your Device Tree");
2288+ }
2289+
22822290 nfc->is_initialized = true;
22832291 dev_info(&pdev->dev, "NFC is probed.\n");
2292+
2293+ return 0;
2294+}
2295+
2296+static int atmel_nand_nfc_remove(struct platform_device *pdev)
2297+{
2298+ struct atmel_nfc *nfc = &nand_nfc;
2299+
2300+ if (!IS_ERR(nfc->clk))
2301+ clk_disable_unprepare(nfc->clk);
2302+
22842303 return 0;
22852304 }
22862305
@@ -2297,6 +2316,7 @@ static struct platform_driver atmel_nand_nfc_driver = { · 10 unmodified lines
22972316 .of_match_table = of_match_ptr(atmel_nand_nfc_match),
22982317 },
22992318 .probe = atmel_nand_nfc_probe,
2319+ .remove = atmel_nand_nfc_remove,
23002320 };
23012321
23022322 static struct platform_driver atmel_nand_driver = {
drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c+49−8
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/module.h>
1515 #include <linux/kernel.h>
1616 #include <linux/slab.h>
17+#include <linux/delay.h>
1718 #include <linux/bcma/bcma.h>
1819
1920 /* Broadcom uses 1'000'000 but it seems to be too many. Tests on WNDR4500 has
@@ -23,6 +24,8 @@ · 3 unmodified lines
2324 #define NFLASH_SECTOR_SIZE 512
2425
2526 #define NCTL_CMD0 0x00010000
27+#define NCTL_COL 0x00020000 /* Update column with value from BCMA_CC_NFLASH_COL_ADDR */
28+#define NCTL_ROW 0x00040000 /* Update row (page) with value from BCMA_CC_NFLASH_ROW_ADDR */
2629 #define NCTL_CMD1W 0x00080000
2730 #define NCTL_READ 0x00100000
2831 #define NCTL_WRITE 0x00200000
@@ -109,7 +112,7 @@ static void bcm47xxnflash_ops_bcm4706_read(struct mtd_info *mtd, uint8_t *buf, · 80 unmodified lines
109112 b47n->curr_page_addr);
110113
111114 /* Prepare to read */
112− ctlcode = NCTL_CSA | NCTL_CMD1W | 0x00040000 | 0x00020000 |
115+ ctlcode = NCTL_CSA | NCTL_CMD1W | NCTL_ROW | NCTL_COL |
113116 NCTL_CMD0;
114117 ctlcode |= NAND_CMD_READSTART << 8;
115118 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, ctlcode))
@@ -167,6 +170,26 @@ static void bcm47xxnflash_ops_bcm4706_write(struct mtd_info *mtd, · 51 unmodified lines
167170 * NAND chip ops
168171 **************************************************/
169172
173+static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct mtd_info *mtd, int cmd,
174+ unsigned int ctrl)
175+{
176+ struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
177+ struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
178+ u32 code = 0;
179+
180+ if (cmd == NAND_CMD_NONE)
181+ return;
182+
183+ if (cmd & NAND_CTRL_CLE)
184+ code = cmd | NCTL_CMD0;
185+
186+ /* nCS is not needed for reset command */
187+ if (cmd != NAND_CMD_RESET)
188+ code |= NCTL_CSA;
189+
190+ bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc, code);
191+}
192+
170193 /* Default nand_select_chip calls cmd_ctrl, which is not used in BCM4706 */
171194 static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd,
172195 int chip)
@@ -174,6 +197,14 @@ static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd, · 1 unmodified line
174197 return;
175198 }
176199
200+static int bcm47xxnflash_ops_bcm4706_dev_ready(struct mtd_info *mtd)
201+{
202+ struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
203+ struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
204+
205+ return !!(bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_CTL) & NCTL_READY);
206+}
207+
177208 /*
178209 * Default nand_command and nand_command_lp don't match BCM4706 hardware layout.
179210 * For example, reading chip id is performed in a non-standard way.
@@ -198,7 +229,10 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd, · 18 unmodified lines
198229
199230 switch (command) {
200231 case NAND_CMD_RESET:
201− pr_warn("Chip reset not implemented yet\n");
232+ nand_chip->cmd_ctrl(mtd, command, NAND_CTRL_CLE);
233+
234+ ndelay(100);
235+ nand_wait_ready(mtd);
202236 break;
203237 case NAND_CMD_READID:
204238 ctlcode = NCTL_CSA | 0x01000000 | NCTL_CMD1W | NCTL_CMD0;
@@ -242,7 +276,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd, · 37 unmodified lines
242276 case NAND_CMD_ERASE1:
243277 bcma_cc_write32(cc, BCMA_CC_NFLASH_ROW_ADDR,
244278 b47n->curr_page_addr);
245− ctlcode = 0x00040000 | NCTL_CMD1W | NCTL_CMD0 |
279+ ctlcode = NCTL_ROW | NCTL_CMD1W | NCTL_CMD0 |
246280 NAND_CMD_ERASE1 | (NAND_CMD_ERASE2 << 8);
247281 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, ctlcode))
248282 pr_err("ERASE1 failed\n");
@@ -257,13 +291,13 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd, · 8 unmodified lines
257291 b47n->curr_page_addr);
258292
259293 /* Prepare to write */
260− ctlcode = 0x40000000 | 0x00040000 | 0x00020000 | 0x00010000;
294+ ctlcode = 0x40000000 | NCTL_ROW | NCTL_COL | NCTL_CMD0;
261295 ctlcode |= NAND_CMD_SEQIN;
262296 if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, ctlcode))
263297 pr_err("SEQIN failed\n");
264298 break;
265299 case NAND_CMD_PAGEPROG:
266− if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, 0x00010000 |
300+ if (bcm47xxnflash_ops_bcm4706_ctl_cmd(cc, NCTL_CMD0 |
267301 NAND_CMD_PAGEPROG))
268302 pr_err("PAGEPROG failed\n");
269303 if (bcm47xxnflash_ops_bcm4706_poll(cc))
@@ -341,6 +375,7 @@ static void bcm47xxnflash_ops_bcm4706_write_buf(struct mtd_info *mtd, · 71 unmodified lines
341375
342376 int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n)
343377 {
378+ struct nand_chip *nand_chip = (struct nand_chip *)&b47n->nand_chip;
344379 int err;
345380 u32 freq;
346381 u16 clock;
@@ -351,10 +386,14 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) · 4 unmodified lines
351386 u32 val;
352387
353388 b47n->nand_chip.select_chip = bcm47xxnflash_ops_bcm4706_select_chip;
389+ nand_chip->cmd_ctrl = bcm47xxnflash_ops_bcm4706_cmd_ctrl;
390+ nand_chip->dev_ready = bcm47xxnflash_ops_bcm4706_dev_ready;
354391 b47n->nand_chip.cmdfunc = bcm47xxnflash_ops_bcm4706_cmdfunc;
355392 b47n->nand_chip.read_byte = bcm47xxnflash_ops_bcm4706_read_byte;
356393 b47n->nand_chip.read_buf = bcm47xxnflash_ops_bcm4706_read_buf;
357394 b47n->nand_chip.write_buf = bcm47xxnflash_ops_bcm4706_write_buf;
395+
396+ nand_chip->chip_delay = 50;
358397 b47n->nand_chip.bbt_options = NAND_BBT_USE_FLASH;
359398 b47n->nand_chip.ecc.mode = NAND_ECC_NONE; /* TODO: implement ECC */
360399
@@ -364,11 +403,13 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) · 3 unmodified lines
364403
365404 /* Configure wait counters */
366405 if (b47n->cc->status & BCMA_CC_CHIPST_4706_PKG_OPTION) {
367− freq = 100000000;
406+ /* 400 MHz */
407+ freq = 400000000 / 4;
368408 } else {
369409 freq = bcma_chipco_pll_read(b47n->cc, 4);
370− freq = (freq * 0xFFF) >> 3;
371− freq = (freq * 25000000) >> 3;
410+ freq = (freq & 0xFFF) >> 3;
411+ /* Fixed reference clock 25 MHz and m = 2 */
412+ freq = (freq * 25000000 / 2) / 4;
372413 }
373414 clock = freq / 1000000;
374415 w0 = bcm47xxnflash_ops_bcm4706_ns_to_cycle(15, clock);
drivers/mtd/nand/denali.c+304−261
@@ -29,20 +29,23 @@ · 28 unmodified lines
2929
3030 MODULE_LICENSE("GPL");
3131
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
3334 * the hardware and decide what timing mode should be used.
3435 */
3536 #define NAND_DEFAULT_TIMINGS -1
3637
3738 static int onfi_timing_mode = NAND_DEFAULT_TIMINGS;
3839 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");
4142
4243 #define DENALI_NAND_NAME "denali-nand"
4344
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+ */
4649 #define DENALI_IRQ_ALL (INTR_STATUS__DMA_CMD_COMP | \
4750 INTR_STATUS__ECC_TRANSACTION_DONE | \
4851 INTR_STATUS__ECC_ERR | \
@@ -54,26 +57,34 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting." · 5 unmodified lines
5457 INTR_STATUS__RST_COMP | \
5558 INTR_STATUS__ERASE_COMP)
5659
57−/* indicates whether or not the internal value for the flash bank is
58− * valid or not */
60+/*
61+ * indicates whether or not the internal value for the flash bank is
62+ * valid or not
63+ */
5964 #define CHIP_SELECT_INVALID -1
6065
6166 #define SUPPORT_8BITECC 1
6267
63−/* This macro divides two integers and rounds fractional values up
64− * to the nearest integer value. */
68+/*
69+ * This macro divides two integers and rounds fractional values up
70+ * to the nearest integer value.
71+ */
6572 #define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y)))
6673
67−/* this macro allows us to convert from an MTD structure to our own
74+/*
75+ * this macro allows us to convert from an MTD structure to our own
6876 * device context (denali) structure.
6977 */
7078 #define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
7179
72−/* These constants are defined by the driver to enable common driver
73− * configuration options. */
80+/*
81+ * These constants are defined by the driver to enable common driver
82+ * configuration options.
83+ */
7484 #define SPARE_ACCESS 0x41
7585 #define MAIN_ACCESS 0x42
7686 #define MAIN_SPARE_ACCESS 0x43
87+#define PIPELINE_ACCESS 0x2000
7788
7889 #define DENALI_READ 0
7990 #define DENALI_WRITE 0x100
@@ -83,8 +94,10 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting." · 3 unmodified lines
8394 #define ADDR_CYCLE 1
8495 #define STATUS_CYCLE 2
8596
86−/* this is a helper macro that allows us to
87− * format the bank into the proper bits for the controller */
97+/*
98+ * this is a helper macro that allows us to
99+ * format the bank into the proper bits for the controller
100+ */
88101 #define BANK(x) ((x) << 24)
89102
90103 /* forward declarations */
@@ -95,12 +108,12 @@ static void denali_irq_enable(struct denali_nand_info *denali, · 4 unmodified lines
95108 uint32_t int_mask);
96109 static uint32_t read_interrupt_status(struct denali_nand_info *denali);
97110
98−/* Certain operations for the denali NAND controller use
99− * an indexed mode to read/write data. The operation is
100− * performed by writing the address value of the command
101− * to the device memory followed by the data. This function
111+/*
112+ * Certain operations for the denali NAND controller use an indexed mode to
113+ * read/write data. The operation is performed by writing the address value
114+ * of the command to the device memory followed by the data. This function
102115 * abstracts this common operation.
103−*/
116+ */
104117 static void index_addr(struct denali_nand_info *denali,
105118 uint32_t address, uint32_t data)
106119 {
@@ -116,8 +129,10 @@ static void index_addr_read_data(struct denali_nand_info *denali, · 9 unmodified lines
116129 *pdata = ioread32(denali->flash_mem + 0x10);
117130 }
118131
119−/* We need to buffer some data for some of the NAND core routines.
120− * The operations manage buffering that data. */
132+/*
133+ * We need to buffer some data for some of the NAND core routines.
134+ * The operations manage buffering that data.
135+ */
121136 static void reset_buf(struct denali_nand_info *denali)
122137 {
123138 denali->buf.head = denali->buf.tail = 0;
@@ -131,7 +146,7 @@ static void write_byte_to_buf(struct denali_nand_info *denali, uint8_t byte) · 7 unmodified lines
131146 /* reads the status of the device */
132147 static void read_status(struct denali_nand_info *denali)
133148 {
134− uint32_t cmd = 0x0;
149+ uint32_t cmd;
135150
136151 /* initialize the data buffer to store status */
137152 reset_buf(denali);
@@ -146,9 +161,8 @@ static void read_status(struct denali_nand_info *denali) · 8 unmodified lines
146161 /* resets a specific device connected to the core */
147162 static void reset_bank(struct denali_nand_info *denali)
148163 {
149− uint32_t irq_status = 0;
150− uint32_t irq_mask = INTR_STATUS__RST_COMP |
151− INTR_STATUS__TIME_OUT;
164+ uint32_t irq_status;
165+ uint32_t irq_mask = INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT;
152166
153167 clear_interrupts(denali);
154168
@@ -163,19 +177,18 @@ static void reset_bank(struct denali_nand_info *denali) · 8 unmodified lines
163177 /* Reset the flash controller */
164178 static uint16_t denali_nand_reset(struct denali_nand_info *denali)
165179 {
166− uint32_t i;
180+ int i;
167181
168182 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
169− __FILE__, __LINE__, __func__);
183+ __FILE__, __LINE__, __func__);
170184
171− for (i = 0 ; i < denali->max_banks; i++)
185+ for (i = 0; i < denali->max_banks; i++)
172186 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
173187 denali->flash_reg + INTR_STATUS(i));
174188
175− for (i = 0 ; i < denali->max_banks; i++) {
189+ for (i = 0; i < denali->max_banks; i++) {
176190 iowrite32(1 << i, denali->flash_reg + DEVICE_RESET);
177− while (!(ioread32(denali->flash_reg +
178− INTR_STATUS(i)) &
191+ while (!(ioread32(denali->flash_reg + INTR_STATUS(i)) &
179192 (INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT)))
180193 cpu_relax();
181194 if (ioread32(denali->flash_reg + INTR_STATUS(i)) &
@@ -186,12 +199,13 @@ static uint16_t denali_nand_reset(struct denali_nand_info *denali) · 4 unmodified lines
186199
187200 for (i = 0; i < denali->max_banks; i++)
188201 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
189− denali->flash_reg + INTR_STATUS(i));
202+ denali->flash_reg + INTR_STATUS(i));
190203
191204 return PASS;
192205 }
193206
194−/* this routine calculates the ONFI timing values for a given mode and
207+/*
208+ * this routine calculates the ONFI timing values for a given mode and
195209 * programs the clocking register accordingly. The mode is determined by
196210 * the get_onfi_nand_para routine.
197211 */
@@ -219,7 +233,7 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 21 unmodified lines
219233 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt;
220234
221235 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
222− __FILE__, __LINE__, __func__);
236+ __FILE__, __LINE__, __func__);
223237
224238 en_lo = CEIL_DIV(Trp[mode], CLK_X);
225239 en_hi = CEIL_DIV(Treh[mode], CLK_X);
@@ -239,9 +253,8 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 13 unmodified lines
239253
240254 data_invalid_rloh = (en_lo + en_hi) * CLK_X + Trloh[mode];
241255
242− data_invalid =
243− data_invalid_rhoh <
244− data_invalid_rloh ? data_invalid_rhoh : data_invalid_rloh;
256+ data_invalid = data_invalid_rhoh < data_invalid_rloh ?
257+ data_invalid_rhoh : data_invalid_rloh;
245258
246259 dv_window = data_invalid - Trea[mode];
247260
@@ -251,12 +264,12 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 3 unmodified lines
251264
252265 acc_clks = CEIL_DIV(Trea[mode], CLK_X);
253266
254− while (((acc_clks * CLK_X) - Trea[mode]) < 3)
267+ while (acc_clks * CLK_X - Trea[mode] < 3)
255268 acc_clks++;
256269
257− if ((data_invalid - acc_clks * CLK_X) < 2)
270+ if (data_invalid - acc_clks * CLK_X < 2)
258271 dev_warn(denali->dev, "%s, Line %d: Warning!\n",
259− __FILE__, __LINE__);
272+ __FILE__, __LINE__);
260273
261274 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X);
262275 re_2_we = CEIL_DIV(Trhw[mode], CLK_X);
@@ -269,7 +282,7 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 6 unmodified lines
269282 cs_cnt = 1;
270283
271284 if (Tcea[mode]) {
272− while (((cs_cnt * CLK_X) + Trea[mode]) < Tcea[mode])
285+ while (cs_cnt * CLK_X + Trea[mode] < Tcea[mode])
273286 cs_cnt++;
274287 }
275288
@@ -279,8 +292,8 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 3 unmodified lines
279292 #endif
280293
281294 /* Sighting 3462430: Temporary hack for MT29F128G08CJABAWP:B */
282− if ((ioread32(denali->flash_reg + MANUFACTURER_ID) == 0) &&
283− (ioread32(denali->flash_reg + DEVICE_ID) == 0x88))
295+ if (ioread32(denali->flash_reg + MANUFACTURER_ID) == 0 &&
296+ ioread32(denali->flash_reg + DEVICE_ID) == 0x88)
284297 acc_clks = 6;
285298
286299 iowrite32(acc_clks, denali->flash_reg + ACC_CLKS);
@@ -297,9 +310,11 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali, · 10 unmodified lines
297310 static uint16_t get_onfi_nand_para(struct denali_nand_info *denali)
298311 {
299312 int i;
300− /* we needn't to do a reset here because driver has already
313+
314+ /*
315+ * we needn't to do a reset here because driver has already
301316 * reset all the banks before
302− * */
317+ */
303318 if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) &
304319 ONFI_TIMING_MODE__VALUE))
305320 return FAIL;
@@ -312,8 +327,10 @@ static uint16_t get_onfi_nand_para(struct denali_nand_info *denali) · 6 unmodified lines
312327
313328 nand_onfi_timing_set(denali, i);
314329
315− /* By now, all the ONFI devices we know support the page cache */
316− /* rw feature. So here we enable the pipeline_rw_ahead feature */
330+ /*
331+ * By now, all the ONFI devices we know support the page cache
332+ * rw feature. So here we enable the pipeline_rw_ahead feature
333+ */
317334 /* iowrite32(1, denali->flash_reg + CACHE_WRITE_ENABLE); */
318335 /* iowrite32(1, denali->flash_reg + CACHE_READ_ENABLE); */
319336
@@ -339,8 +356,10 @@ static void get_toshiba_nand_para(struct denali_nand_info *denali) · 19 unmodified lines
339356 {
340357 uint32_t tmp;
341358
342− /* Workaround to fix a controller bug which reports a wrong */
343− /* spare area size for some kind of Toshiba NAND device */
359+ /*
360+ * Workaround to fix a controller bug which reports a wrong
361+ * spare area size for some kind of Toshiba NAND device
362+ */
344363 if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) &&
345364 (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) {
346365 iowrite32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
@@ -384,13 +403,14 @@ static void get_hynix_nand_para(struct denali_nand_info *denali, · 37 unmodified lines
384403 break;
385404 default:
386405 dev_warn(denali->dev,
387− "Spectra: Unknown Hynix NAND (Device ID: 0x%x)."
388− "Will use default parameter values instead.\n",
389− device_id);
406+ "Spectra: Unknown Hynix NAND (Device ID: 0x%x).\n"
407+ "Will use default parameter values instead.\n",
408+ device_id);
390409 }
391410 }
392411
393−/* determines how many NAND chips are connected to the controller. Note for
412+/*
413+ * determines how many NAND chips are connected to the controller. Note for
394414 * Intel CE4100 devices we don't support more than one device.
395415 */
396416 static void find_valid_banks(struct denali_nand_info *denali)
@@ -400,10 +420,9 @@ static void find_valid_banks(struct denali_nand_info *denali) · 3 unmodified lines
400420
401421 denali->total_used_banks = 1;
402422 for (i = 0; i < denali->max_banks; i++) {
403− index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90);
404− index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0);
405− index_addr_read_data(denali,
406− (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]);
423+ index_addr(denali, MODE_11 | (i << 24) | 0, 0x90);
424+ index_addr(denali, MODE_11 | (i << 24) | 1, 0);
425+ index_addr_read_data(denali, MODE_11 | (i << 24) | 2, &id[i]);
407426
408427 dev_dbg(denali->dev,
409428 "Return 1st ID for bank[%d]: %x\n", i, id[i]);
@@ -420,14 +439,14 @@ static void find_valid_banks(struct denali_nand_info *denali) · 10 unmodified lines
420439 }
421440
422441 if (denali->platform == INTEL_CE4100) {
423− /* Platform limitations of the CE4100 device limit
442+ /*
443+ * Platform limitations of the CE4100 device limit
424444 * users to a single chip solution for NAND.
425445 * Multichip support is not enabled.
426446 */
427447 if (denali->total_used_banks != 1) {
428448 dev_err(denali->dev,
429− "Sorry, Intel CE4100 only supports "
430− "a single NAND device.\n");
449+ "Sorry, Intel CE4100 only supports a single NAND device.\n");
431450 BUG();
432451 }
433452 }
@@ -448,12 +467,13 @@ static void detect_max_banks(struct denali_nand_info *denali) · 14 unmodified lines
448467
449468 static void detect_partition_feature(struct denali_nand_info *denali)
450469 {
451− /* For MRST platform, denali->fwblks represent the
470+ /*
471+ * For MRST platform, denali->fwblks represent the
452472 * number of blocks firmware is taken,
453473 * FW is in protect partition and MTD driver has no
454474 * permission to access it. So let driver know how many
455475 * blocks it can't touch.
456− * */
476+ */
457477 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) {
458478 if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) &
459479 PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) {
@@ -464,30 +484,32 @@ static void detect_partition_feature(struct denali_nand_info *denali) · 4 unmodified lines
464484 +
465485 (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) &
466486 MIN_BLK_ADDR__VALUE);
467− } else
487+ } else {
468488 denali->fwblks = SPECTRA_START_BLOCK;
469− } else
489+ }
490+ } else {
470491 denali->fwblks = SPECTRA_START_BLOCK;
492+ }
471493 }
472494
473495 static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
474496 {
475497 uint16_t status = PASS;
476498 uint32_t id_bytes[8], addr;
477− uint8_t i, maf_id, device_id;
499+ uint8_t maf_id, device_id;
500+ int i;
478501
479− dev_dbg(denali->dev,
480− "%s, Line %d, Function: %s\n",
502+ dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
481503 __FILE__, __LINE__, __func__);
482504
483− /* Use read id method to get device ID and other
484− * params. For some NAND chips, controller can't
485− * report the correct device ID by reading from
486− * DEVICE_ID register
487− * */
488− addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
489− index_addr(denali, (uint32_t)addr | 0, 0x90);
490− index_addr(denali, (uint32_t)addr | 1, 0);
505+ /*
506+ * Use read id method to get device ID and other params.
507+ * For some NAND chips, controller can't report the correct
508+ * device ID by reading from DEVICE_ID register
509+ */
510+ addr = MODE_11 | BANK(denali->flash_bank);
511+ index_addr(denali, addr | 0, 0x90);
512+ index_addr(denali, addr | 1, 0);
491513 for (i = 0; i < 8; i++)
492514 index_addr_read_data(denali, addr | 2, &id_bytes[i]);
493515 maf_id = id_bytes[0];
@@ -506,7 +528,7 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) · 12 unmodified lines
506528 }
507529
508530 dev_info(denali->dev,
509− "Dump timing register values:"
531+ "Dump timing register values:\n"
510532 "acc_clks: %d, re_2_we: %d, re_2_re: %d\n"
511533 "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n"
512534 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
@@ -523,7 +545,8 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali) · 10 unmodified lines
523545
524546 detect_partition_feature(denali);
525547
526− /* If the user specified to override the default timings
548+ /*
549+ * If the user specified to override the default timings
527550 * with a specific ONFI mode, we apply those changes here.
528551 */
529552 if (onfi_timing_mode != NAND_DEFAULT_TIMINGS)
@@ -536,7 +559,7 @@ static void denali_set_intr_modes(struct denali_nand_info *denali, · 6 unmodified lines
536559 uint16_t INT_ENABLE)
537560 {
538561 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
539− __FILE__, __LINE__, __func__);
562+ __FILE__, __LINE__, __func__);
540563
541564 if (INT_ENABLE)
542565 iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE);
@@ -544,17 +567,18 @@ static void denali_set_intr_modes(struct denali_nand_info *denali, · 1 unmodified line
544567 iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE);
545568 }
546569
547−/* validation function to verify that the controlling software is making
570+/*
571+ * validation function to verify that the controlling software is making
548572 * a valid request
549573 */
550574 static inline bool is_flash_bank_valid(int flash_bank)
551575 {
552− return (flash_bank >= 0 && flash_bank < 4);
576+ return flash_bank >= 0 && flash_bank < 4;
553577 }
554578
555579 static void denali_irq_init(struct denali_nand_info *denali)
556580 {
557− uint32_t int_mask = 0;
581+ uint32_t int_mask;
558582 int i;
559583
560584 /* Disable global interrupts */
@@ -584,7 +608,8 @@ static void denali_irq_enable(struct denali_nand_info *denali, · 23 unmodified lines
584608 iowrite32(int_mask, denali->flash_reg + INTR_EN(i));
585609 }
586610
587−/* This function only returns when an interrupt that this driver cares about
611+/*
612+ * This function only returns when an interrupt that this driver cares about
588613 * occurs. This is to reduce the overhead of servicing interrupts
589614 */
590615 static inline uint32_t denali_irq_detected(struct denali_nand_info *denali)
@@ -596,7 +621,7 @@ static inline uint32_t denali_irq_detected(struct denali_nand_info *denali) · 5 unmodified lines
596621 static inline void clear_interrupt(struct denali_nand_info *denali,
597622 uint32_t irq_mask)
598623 {
599− uint32_t intr_status_reg = 0;
624+ uint32_t intr_status_reg;
600625
601626 intr_status_reg = INTR_STATUS(denali->flash_bank);
602627
@@ -605,7 +630,8 @@ static inline void clear_interrupt(struct denali_nand_info *denali, · 2 unmodified lines
605630
606631 static void clear_interrupts(struct denali_nand_info *denali)
607632 {
608− uint32_t status = 0x0;
633+ uint32_t status;
634+
609635 spin_lock_irq(&denali->irq_lock);
610636
611637 status = read_interrupt_status(denali);
@@ -617,38 +643,40 @@ static void clear_interrupts(struct denali_nand_info *denali) · 5 unmodified lines
617643
618644 static uint32_t read_interrupt_status(struct denali_nand_info *denali)
619645 {
620− uint32_t intr_status_reg = 0;
646+ uint32_t intr_status_reg;
621647
622648 intr_status_reg = INTR_STATUS(denali->flash_bank);
623649
624650 return ioread32(denali->flash_reg + intr_status_reg);
625651 }
626652
627−/* This is the interrupt service routine. It handles all interrupts
628− * sent to this device. Note that on CE4100, this is a shared
629− * interrupt.
653+/*
654+ * This is the interrupt service routine. It handles all interrupts
655+ * sent to this device. Note that on CE4100, this is a shared interrupt.
630656 */
631657 static irqreturn_t denali_isr(int irq, void *dev_id)
632658 {
633659 struct denali_nand_info *denali = dev_id;
634− uint32_t irq_status = 0x0;
660+ uint32_t irq_status;
635661 irqreturn_t result = IRQ_NONE;
636662
637663 spin_lock(&denali->irq_lock);
638664
639− /* check to see if a valid NAND chip has
640− * been selected.
641− */
665+ /* check to see if a valid NAND chip has been selected. */
642666 if (is_flash_bank_valid(denali->flash_bank)) {
643− /* check to see if controller generated
644− * the interrupt, since this is a shared interrupt */
667+ /*
668+ * check to see if controller generated the interrupt,
669+ * since this is a shared interrupt
670+ */
645671 irq_status = denali_irq_detected(denali);
646672 if (irq_status != 0) {
647673 /* handle interrupt */
648674 /* first acknowledge it */
649675 clear_interrupt(denali, irq_status);
650− /* store the status in the device context for someone
651− to read */
676+ /*
677+ * store the status in the device context for someone
678+ * to read
679+ */
652680 denali->irq_status |= irq_status;
653681 /* notify anyone who cares that it happened */
654682 complete(&denali->complete);
@@ -663,9 +691,8 @@ static irqreturn_t denali_isr(int irq, void *dev_id) · 8 unmodified lines
663691
664692 static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask)
665693 {
666− unsigned long comp_res = 0;
667− uint32_t intr_status = 0;
668− bool retry = false;
694+ unsigned long comp_res;
695+ uint32_t intr_status;
669696 unsigned long timeout = msecs_to_jiffies(1000);
670697
671698 do {
@@ -679,12 +706,13 @@ static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask) · 7 unmodified lines
679706 spin_unlock_irq(&denali->irq_lock);
680707 /* our interrupt was detected */
681708 break;
682− } else {
683− /* these are not the interrupts you are looking for -
684− * need to wait again */
685− spin_unlock_irq(&denali->irq_lock);
686− retry = true;
687709 }
710+
711+ /*
712+ * these are not the interrupts you are looking for -
713+ * need to wait again
714+ */
715+ spin_unlock_irq(&denali->irq_lock);
688716 } while (comp_res != 0);
689717
690718 if (comp_res == 0) {
@@ -697,12 +725,14 @@ static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask) · 6 unmodified lines
697725 return intr_status;
698726 }
699727
700−/* This helper function setups the registers for ECC and whether or not
701− * the spare area will be transferred. */
728+/*
729+ * This helper function setups the registers for ECC and whether or not
730+ * the spare area will be transferred.
731+ */
702732 static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
703733 bool transfer_spare)
704734 {
705− int ecc_en_flag = 0, transfer_spare_flag = 0;
735+ int ecc_en_flag, transfer_spare_flag;
706736
707737 /* set ECC, transfer spare bits if needed */
708738 ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
@@ -710,22 +740,20 @@ static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en, · 1 unmodified line
710740
711741 /* Enable spare area/ECC per user's request. */
712742 iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE);
713− iowrite32(transfer_spare_flag,
714− denali->flash_reg + TRANSFER_SPARE_REG);
743+ iowrite32(transfer_spare_flag, denali->flash_reg + TRANSFER_SPARE_REG);
715744 }
716745
717−/* sends a pipeline command operation to the controller. See the Denali NAND
746+/*
747+ * sends a pipeline command operation to the controller. See the Denali NAND
718748 * controller's user guide for more information (section 4.2.3.6).
719749 */
720750 static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
721− bool ecc_en,
722− bool transfer_spare,
723− int access_type,
724− int op)
751+ bool ecc_en, bool transfer_spare,
752+ int access_type, int op)
725753 {
726754 int status = PASS;
727− uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0,
728− irq_mask = 0;
755+ uint32_t page_count = 1;
756+ uint32_t addr, cmd, irq_status, irq_mask;
729757
730758 if (op == DENALI_READ)
731759 irq_mask = INTR_STATUS__LOAD_COMP;
@@ -736,7 +764,6 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali, · 4 unmodified lines
736764
737765 setup_ecc_for_xfer(denali, ecc_en, transfer_spare);
738766
739− /* clear interrupts */
740767 clear_interrupts(denali);
741768
742769 addr = BANK(denali->flash_bank) | denali->page;
@@ -747,37 +774,38 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali, · 4 unmodified lines
747774 } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) {
748775 /* read spare area */
749776 cmd = MODE_10 | addr;
750− index_addr(denali, (uint32_t)cmd, access_type);
777+ index_addr(denali, cmd, access_type);
751778
752779 cmd = MODE_01 | addr;
753780 iowrite32(cmd, denali->flash_mem);
754781 } else if (op == DENALI_READ) {
755782 /* setup page read request for access type */
756783 cmd = MODE_10 | addr;
757− index_addr(denali, (uint32_t)cmd, access_type);
784+ index_addr(denali, cmd, access_type);
758785
759− /* page 33 of the NAND controller spec indicates we should not
760− use the pipeline commands in Spare area only mode. So we
761− don't.
786+ /*
787+ * page 33 of the NAND controller spec indicates we should not
788+ * use the pipeline commands in Spare area only mode.
789+ * So we don't.
762790 */
763791 if (access_type == SPARE_ACCESS) {
764792 cmd = MODE_01 | addr;
765793 iowrite32(cmd, denali->flash_mem);
766794 } else {
767− index_addr(denali, (uint32_t)cmd,
768− 0x2000 | op | page_count);
795+ index_addr(denali, cmd,
796+ PIPELINE_ACCESS | op | page_count);
769797
770− /* wait for command to be accepted
798+ /*
799+ * wait for command to be accepted
771800 * can always use status0 bit as the
772− * mask is identical for each
773− * bank. */
801+ * mask is identical for each bank.
802+ */
774803 irq_status = wait_for_irq(denali, irq_mask);
775804
776805 if (irq_status == 0) {
777806 dev_err(denali->dev,
778− "cmd, page, addr on timeout "
779− "(0x%x, 0x%x, 0x%x)\n",
780− cmd, denali->page, addr);
807+ "cmd, page, addr on timeout (0x%x, 0x%x, 0x%x)\n",
808+ cmd, denali->page, addr);
781809 status = FAIL;
782810 } else {
783811 cmd = MODE_01 | addr;
@@ -790,51 +818,51 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali, · 6 unmodified lines
790818
791819 /* helper function that simply writes a buffer to the flash */
792820 static int write_data_to_flash_mem(struct denali_nand_info *denali,
793− const uint8_t *buf,
794− int len)
821+ const uint8_t *buf, int len)
795822 {
796− uint32_t i = 0, *buf32;
823+ uint32_t *buf32;
824+ int i;
797825
798− /* verify that the len is a multiple of 4. see comment in
799− * read_data_from_flash_mem() */
826+ /*
827+ * verify that the len is a multiple of 4.
828+ * see comment in read_data_from_flash_mem()
829+ */
800830 BUG_ON((len % 4) != 0);
801831
802832 /* write the data to the flash memory */
803833 buf32 = (uint32_t *)buf;
804834 for (i = 0; i < len / 4; i++)
805835 iowrite32(*buf32++, denali->flash_mem + 0x10);
806− return i*4; /* intent is to return the number of bytes read */
836+ return i * 4; /* intent is to return the number of bytes read */
807837 }
808838
809839 /* helper function that simply reads a buffer from the flash */
810840 static int read_data_from_flash_mem(struct denali_nand_info *denali,
811− uint8_t *buf,
812− int len)
841+ uint8_t *buf, int len)
813842 {
814− uint32_t i = 0, *buf32;
815−
816− /* we assume that len will be a multiple of 4, if not
817− * it would be nice to know about it ASAP rather than
818− * have random failures...
819− * This assumption is based on the fact that this
820− * function is designed to be used to read flash pages,
821− * which are typically multiples of 4...
822− */
843+ uint32_t *buf32;
844+ int i;
823845
846+ /*
847+ * we assume that len will be a multiple of 4, if not it would be nice
848+ * to know about it ASAP rather than have random failures...
849+ * This assumption is based on the fact that this function is designed
850+ * to be used to read flash pages, which are typically multiples of 4.
851+ */
824852 BUG_ON((len % 4) != 0);
825853
826854 /* transfer the data from the flash */
827855 buf32 = (uint32_t *)buf;
828856 for (i = 0; i < len / 4; i++)
829857 *buf32++ = ioread32(denali->flash_mem + 0x10);
830− return i*4; /* intent is to return the number of bytes read */
858+ return i * 4; /* intent is to return the number of bytes read */
831859 }
832860
833861 /* writes OOB data to the device */
834862 static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
835863 {
836864 struct denali_nand_info *denali = mtd_to_denali(mtd);
837− uint32_t irq_status = 0;
865+ uint32_t irq_status;
838866 uint32_t irq_mask = INTR_STATUS__PROGRAM_COMP |
839867 INTR_STATUS__PROGRAM_FAIL;
840868 int status = 0;
@@ -863,8 +891,8 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) · 22 unmodified lines
863891 static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
864892 {
865893 struct denali_nand_info *denali = mtd_to_denali(mtd);
866− uint32_t irq_mask = INTR_STATUS__LOAD_COMP,
867− irq_status = 0, addr = 0x0, cmd = 0x0;
894+ uint32_t irq_mask = INTR_STATUS__LOAD_COMP;
895+ uint32_t irq_status, addr, cmd;
868896
869897 denali->page = page;
870898
@@ -872,16 +900,19 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) · 1 unmodified line
872900 DENALI_READ) == PASS) {
873901 read_data_from_flash_mem(denali, buf, mtd->oobsize);
874902
875− /* wait for command to be accepted
876− * can always use status0 bit as the mask is identical for each
877− * bank. */
903+ /*
904+ * wait for command to be accepted
905+ * can always use status0 bit as the
906+ * mask is identical for each bank.
907+ */
878908 irq_status = wait_for_irq(denali, irq_mask);
879909
880910 if (irq_status == 0)
881911 dev_err(denali->dev, "page on OOB timeout %d\n",
882912 denali->page);
883913
884− /* We set the device back to MAIN_ACCESS here as I observed
914+ /*
915+ * We set the device back to MAIN_ACCESS here as I observed
885916 * instability with the controller if you do a block erase
886917 * and the last transaction was a SPARE_ACCESS. Block erase
887918 * is reliable (according to the MTD test infrastructure)
@@ -889,16 +920,18 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) · 1 unmodified line
889920 */
890921 addr = BANK(denali->flash_bank) | denali->page;
891922 cmd = MODE_10 | addr;
892− index_addr(denali, (uint32_t)cmd, MAIN_ACCESS);
923+ index_addr(denali, cmd, MAIN_ACCESS);
893924 }
894925 }
895926
896−/* this function examines buffers to see if they contain data that
927+/*
928+ * this function examines buffers to see if they contain data that
897929 * indicate that the buffer is part of an erased region of flash.
898930 */
899931 static bool is_erased(uint8_t *buf, int len)
900932 {
901− int i = 0;
933+ int i;
934+
902935 for (i = 0; i < len; i++)
903936 if (buf[i] != 0xFF)
904937 return false;
@@ -921,9 +954,8 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, · 16 unmodified lines
921954
922955 if (irq_status & INTR_STATUS__ECC_ERR) {
923956 /* read the ECC errors. we'll ignore them for now */
924− uint32_t err_address = 0, err_correction_info = 0;
925− uint32_t err_byte = 0, err_sector = 0, err_device = 0;
926− uint32_t err_correction_value = 0;
957+ uint32_t err_address, err_correction_info, err_byte,
958+ err_sector, err_device, err_correction_value;
927959 denali_set_intr_modes(denali, false);
928960
929961 do {
@@ -939,15 +971,17 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, · 9 unmodified lines
939971 err_device = ECC_ERR_DEVICE(err_correction_info);
940972
941973 if (ECC_ERROR_CORRECTABLE(err_correction_info)) {
942− /* If err_byte is larger than ECC_SECTOR_SIZE,
974+ /*
975+ * If err_byte is larger than ECC_SECTOR_SIZE,
943976 * means error happened in OOB, so we ignore
944977 * it. It's no need for us to correct it
945978 * err_device is represented the NAND error
946979 * bits are happened in if there are more
947980 * than one NAND connected.
948− * */
981+ */
949982 if (err_byte < ECC_SECTOR_SIZE) {
950983 int offset;
984+
951985 offset = (err_sector *
952986 ECC_SECTOR_SIZE +
953987 err_byte) *
@@ -959,17 +993,19 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, · 5 unmodified lines
959993 bitflips++;
960994 }
961995 } else {
962− /* if the error is not correctable, need to
996+ /*
997+ * if the error is not correctable, need to
963998 * look at the page to see if it is an erased
964999 * page. if so, then it's not a real ECC error
965− * */
1000+ */
9661001 check_erased_page = true;
9671002 }
9681003 } while (!ECC_LAST_ERR(err_correction_info));
969− /* Once handle all ecc errors, controller will triger
1004+ /*
1005+ * Once handle all ecc errors, controller will triger
9701006 * a ECC_TRANSACTION_DONE interrupt, so here just wait
9711007 * for a while for this interrupt
972− * */
1008+ */
9731009 while (!(read_interrupt_status(denali) &
9741010 INTR_STATUS__ECC_TRANSACTION_DONE))
9751011 cpu_relax();
@@ -983,21 +1019,16 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, · 7 unmodified lines
9831019 /* programs the controller to either enable/disable DMA transfers */
9841020 static void denali_enable_dma(struct denali_nand_info *denali, bool en)
9851021 {
986− uint32_t reg_val = 0x0;
987−
988− if (en)
989− reg_val = DMA_ENABLE__FLAG;
990−
991− iowrite32(reg_val, denali->flash_reg + DMA_ENABLE);
1022+ iowrite32(en ? DMA_ENABLE__FLAG : 0, denali->flash_reg + DMA_ENABLE);
9921023 ioread32(denali->flash_reg + DMA_ENABLE);
9931024 }
9941025
9951026 /* setups the HW to perform the data DMA */
9961027 static void denali_setup_dma(struct denali_nand_info *denali, int op)
9971028 {
998− uint32_t mode = 0x0;
1029+ uint32_t mode;
9991030 const int page_count = 1;
1000− dma_addr_t addr = denali->buf.dma_buf;
1031+ uint32_t addr = denali->buf.dma_buf;
10011032
10021033 mode = MODE_10 | BANK(denali->flash_bank);
10031034
@@ -1007,31 +1038,31 @@ static void denali_setup_dma(struct denali_nand_info *denali, int op) · 3 unmodified lines
10071038 index_addr(denali, mode | denali->page, 0x2000 | op | page_count);
10081039
10091040 /* 2. set memory high address bits 23:8 */
1010− index_addr(denali, mode | ((uint16_t)(addr >> 16) << 8), 0x2200);
1041+ index_addr(denali, mode | ((addr >> 16) << 8), 0x2200);
10111042
10121043 /* 3. set memory low address bits 23:8 */
1013− index_addr(denali, mode | ((uint16_t)addr << 8), 0x2300);
1044+ index_addr(denali, mode | ((addr & 0xff) << 8), 0x2300);
10141045
1015− /* 4. interrupt when complete, burst len = 64 bytes*/
1046+ /* 4. interrupt when complete, burst len = 64 bytes */
10161047 index_addr(denali, mode | 0x14000, 0x2400);
10171048 }
10181049
1019−/* writes a page. user specifies type, and this function handles the
1020− * configuration details. */
1050+/*
1051+ * writes a page. user specifies type, and this function handles the
1052+ * configuration details.
1053+ */
10211054 static int write_page(struct mtd_info *mtd, struct nand_chip *chip,
10221055 const uint8_t *buf, bool raw_xfer)
10231056 {
10241057 struct denali_nand_info *denali = mtd_to_denali(mtd);
1025−
10261058 dma_addr_t addr = denali->buf.dma_buf;
10271059 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1028−
1029− uint32_t irq_status = 0;
1060+ uint32_t irq_status;
10301061 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
10311062 INTR_STATUS__PROGRAM_FAIL;
10321063
1033− /* if it is a raw xfer, we want to disable ecc, and send
1034− * the spare area.
1064+ /*
1065+ * if it is a raw xfer, we want to disable ecc and send the spare area.
10351066 * !raw_xfer - enable ecc
10361067 * raw_xfer - transfer spare
10371068 */
@@ -1058,12 +1089,9 @@ static int write_page(struct mtd_info *mtd, struct nand_chip *chip, · 20 unmodified lines
10581089 irq_status = wait_for_irq(denali, irq_mask);
10591090
10601091 if (irq_status == 0) {
1061− dev_err(denali->dev,
1062− "timeout on write_page (type = %d)\n",
1063− raw_xfer);
1064− denali->status =
1065− (irq_status & INTR_STATUS__PROGRAM_FAIL) ?
1066− NAND_STATUS_FAIL : PASS;
1092+ dev_err(denali->dev, "timeout on write_page (type = %d)\n",
1093+ raw_xfer);
1094+ denali->status = NAND_STATUS_FAIL;
10671095 }
10681096
10691097 denali_enable_dma(denali, false);
@@ -1074,27 +1102,33 @@ static int write_page(struct mtd_info *mtd, struct nand_chip *chip, · 4 unmodified lines
10741102
10751103 /* NAND core entry points */
10761104
1077−/* this is the callback that the NAND core calls to write a page. Since
1105+/*
1106+ * this is the callback that the NAND core calls to write a page. Since
10781107 * writing a page with ECC or without is similar, all the work is done
10791108 * by write_page above.
1080− * */
1109+ */
10811110 static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
10821111 const uint8_t *buf, int oob_required)
10831112 {
1084− /* for regular page writes, we let HW handle all the ECC
1085− * data written to the device. */
1113+ /*
1114+ * for regular page writes, we let HW handle all the ECC
1115+ * data written to the device.
1116+ */
10861117 return write_page(mtd, chip, buf, false);
10871118 }
10881119
1089−/* This is the callback that the NAND core calls to write a page without ECC.
1120+/*
1121+ * This is the callback that the NAND core calls to write a page without ECC.
10901122 * raw access is similar to ECC page writes, so all the work is done in the
10911123 * write_page() function above.
10921124 */
10931125 static int denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
10941126 const uint8_t *buf, int oob_required)
10951127 {
1096− /* for raw page writes, we want to disable ECC and simply write
1097− whatever data is in the buffer. */
1128+ /*
1129+ * for raw page writes, we want to disable ECC and simply write
1130+ * whatever data is in the buffer.
1131+ */
10981132 return write_page(mtd, chip, buf, true);
10991133 }
11001134
@@ -1121,15 +1155,15 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, · 20 unmodified lines
11211155 dma_addr_t addr = denali->buf.dma_buf;
11221156 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
11231157
1124− uint32_t irq_status = 0;
1158+ uint32_t irq_status;
11251159 uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
11261160 INTR_STATUS__ECC_ERR;
11271161 bool check_erased_page = false;
11281162
11291163 if (page != denali->page) {
1130− dev_err(denali->dev, "IN %s: page %d is not"
1131− " equal to denali->page %d, investigate!!",
1132− __func__, page, denali->page);
1164+ dev_err(denali->dev,
1165+ "IN %s: page %d is not equal to denali->page %d",
1166+ __func__, page, denali->page);
11331167 BUG();
11341168 }
11351169
@@ -1169,17 +1203,14 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, · 33 unmodified lines
11691203 uint8_t *buf, int oob_required, int page)
11701204 {
11711205 struct denali_nand_info *denali = mtd_to_denali(mtd);
1172−
11731206 dma_addr_t addr = denali->buf.dma_buf;
11741207 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1175−
1176− uint32_t irq_status = 0;
11771208 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP;
11781209
11791210 if (page != denali->page) {
1180− dev_err(denali->dev, "IN %s: page %d is not"
1181− " equal to denali->page %d, investigate!!",
1182− __func__, page, denali->page);
1211+ dev_err(denali->dev,
1212+ "IN %s: page %d is not equal to denali->page %d",
1213+ __func__, page, denali->page);
11831214 BUG();
11841215 }
11851216
@@ -1192,7 +1223,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, · 6 unmodified lines
11921223 denali_setup_dma(denali, DENALI_READ);
11931224
11941225 /* wait for operation to complete */
1195− irq_status = wait_for_irq(denali, irq_mask);
1226+ wait_for_irq(denali, irq_mask);
11961227
11971228 dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
11981229
@@ -1228,6 +1259,7 @@ static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip) · 29 unmodified lines
12281259 {
12291260 struct denali_nand_info *denali = mtd_to_denali(mtd);
12301261 int status = denali->status;
1262+
12311263 denali->status = 0;
12321264
12331265 return status;
@@ -1237,20 +1269,19 @@ static int denali_erase(struct mtd_info *mtd, int page) · 3 unmodified lines
12371269 {
12381270 struct denali_nand_info *denali = mtd_to_denali(mtd);
12391271
1240− uint32_t cmd = 0x0, irq_status = 0;
1272+ uint32_t cmd, irq_status;
12411273
1242− /* clear interrupts */
12431274 clear_interrupts(denali);
12441275
12451276 /* setup page read request for access type */
12461277 cmd = MODE_10 | BANK(denali->flash_bank) | page;
1247− index_addr(denali, (uint32_t)cmd, 0x1);
1278+ index_addr(denali, cmd, 0x1);
12481279
12491280 /* wait for erase to complete or failure to occur */
12501281 irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP |
12511282 INTR_STATUS__ERASE_FAIL);
12521283
1253− return (irq_status & INTR_STATUS__ERASE_FAIL) ? NAND_STATUS_FAIL : PASS;
1284+ return irq_status & INTR_STATUS__ERASE_FAIL ? NAND_STATUS_FAIL : PASS;
12541285 }
12551286
12561287 static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
@@ -1269,17 +1300,16 @@ static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, · 12 unmodified lines
12691300 case NAND_CMD_READID:
12701301 case NAND_CMD_PARAM:
12711302 reset_buf(denali);
1272− /*sometimes ManufactureId read from register is not right
1303+ /*
1304+ * sometimes ManufactureId read from register is not right
12731305 * e.g. some of Micron MT29F32G08QAA MLC NAND chips
12741306 * So here we send READID cmd to NAND insteand
1275− * */
1276− addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
1277− index_addr(denali, (uint32_t)addr | 0, 0x90);
1278− index_addr(denali, (uint32_t)addr | 1, 0);
1307+ */
1308+ addr = MODE_11 | BANK(denali->flash_bank);
1309+ index_addr(denali, addr | 0, 0x90);
1310+ index_addr(denali, addr | 1, 0);
12791311 for (i = 0; i < 8; i++) {
1280− index_addr_read_data(denali,
1281− (uint32_t)addr | 2,
1282− &id);
1312+ index_addr_read_data(denali, addr | 2, &id);
12831313 write_byte_to_buf(denali, id);
12841314 }
12851315 break;
@@ -1304,8 +1334,8 @@ static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data, · 18 unmodified lines
13041334 uint8_t *ecc_code)
13051335 {
13061336 struct denali_nand_info *denali = mtd_to_denali(mtd);
1307− dev_err(denali->dev,
1308− "denali_ecc_calculate called unexpectedly\n");
1337+
1338+ dev_err(denali->dev, "denali_ecc_calculate called unexpectedly\n");
13091339 BUG();
13101340 return -EIO;
13111341 }
@@ -1314,8 +1344,8 @@ static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data, · 2 unmodified lines
13141344 uint8_t *read_ecc, uint8_t *calc_ecc)
13151345 {
13161346 struct denali_nand_info *denali = mtd_to_denali(mtd);
1317− dev_err(denali->dev,
1318− "denali_ecc_correct called unexpectedly\n");
1347+
1348+ dev_err(denali->dev, "denali_ecc_correct called unexpectedly\n");
13191349 BUG();
13201350 return -EIO;
13211351 }
@@ -1323,8 +1353,8 @@ static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data, · 1 unmodified line
13231353 static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
13241354 {
13251355 struct denali_nand_info *denali = mtd_to_denali(mtd);
1326− dev_err(denali->dev,
1327− "denali_ecc_hwctl called unexpectedly\n");
1356+
1357+ dev_err(denali->dev, "denali_ecc_hwctl called unexpectedly\n");
13281358 BUG();
13291359 }
13301360 /* end NAND core entry points */
@@ -1332,11 +1362,12 @@ static void denali_ecc_hwctl(struct mtd_info *mtd, int mode) · 1 unmodified line
13321362 /* Initialization code to bring the device up to a known good state */
13331363 static void denali_hw_init(struct denali_nand_info *denali)
13341364 {
1335− /* tell driver how many bit controller will skip before
1365+ /*
1366+ * tell driver how many bit controller will skip before
13361367 * writing ECC code in OOB, this register may be already
13371368 * set by firmware. So we read this value out.
13381369 * if this value is 0, just let it be.
1339− * */
1370+ */
13401371 denali->bbtskipbytes = ioread32(denali->flash_reg +
13411372 SPARE_AREA_SKIP_BYTES);
13421373 detect_max_banks(denali);
@@ -1354,10 +1385,11 @@ static void denali_hw_init(struct denali_nand_info *denali) · 11 unmodified lines
13541385 denali_irq_init(denali);
13551386 }
13561387
1357−/* Althogh controller spec said SLC ECC is forceb to be 4bit,
1388+/*
1389+ * Althogh controller spec said SLC ECC is forceb to be 4bit,
13581390 * but denali controller in MRST only support 15bit and 8bit ECC
13591391 * correction
1360− * */
1392+ */
13611393 #define ECC_8BITS 14
13621394 static struct nand_ecclayout nand_8bit_oob = {
13631395 .eccbytes = 14,
@@ -1397,13 +1429,16 @@ static void denali_drv_init(struct denali_nand_info *denali) · 33 unmodified lines
13971429 denali->idx = 0;
13981430
13991431 /* setup interrupt handler */
1400− /* the completion object will be used to notify
1401− * the callee that the interrupt is done */
1432+ /*
1433+ * the completion object will be used to notify
1434+ * the callee that the interrupt is done
1435+ */
14021436 init_completion(&denali->complete);
14031437
1404− /* the spinlock will be used to synchronize the ISR
1405− * with any element that might be access shared
1406− * data (interrupt status) */
1438+ /*
1439+ * the spinlock will be used to synchronize the ISR with any
1440+ * element that might be access shared data (interrupt status)
1441+ */
14071442 spin_lock_init(&denali->irq_lock);
14081443
14091444 /* indicate that MTD has not selected a valid bank yet */
@@ -1418,7 +1453,8 @@ int denali_init(struct denali_nand_info *denali) · 8 unmodified lines
14181453 int ret;
14191454
14201455 if (denali->platform == INTEL_CE4100) {
1421− /* Due to a silicon limitation, we can only support
1456+ /*
1457+ * Due to a silicon limitation, we can only support
14221458 * ONFI timing mode 1 and below.
14231459 */
14241460 if (onfi_timing_mode < -1 || onfi_timing_mode > 1) {
@@ -1437,8 +1473,10 @@ int denali_init(struct denali_nand_info *denali) · 12 unmodified lines
14371473 denali_hw_init(denali);
14381474 denali_drv_init(denali);
14391475
1440− /* denali_isr register is done after all the hardware
1441− * initilization is finished*/
1476+ /*
1477+ * denali_isr register is done after all the hardware
1478+ * initilization is finished
1479+ */
14421480 if (request_irq(denali->irq, denali_isr, IRQF_SHARED,
14431481 DENALI_NAND_NAME, denali)) {
14441482 pr_err("Spectra: Unable to allocate IRQ\n");
@@ -1457,9 +1495,11 @@ int denali_init(struct denali_nand_info *denali) · 12 unmodified lines
14571495 denali->nand.read_byte = denali_read_byte;
14581496 denali->nand.waitfunc = denali_waitfunc;
14591497
1460− /* scan for NAND devices attached to the controller
1498+ /*
1499+ * scan for NAND devices attached to the controller
14611500 * this is the first stage in a two step process to register
1462− * with the nand subsystem */
1501+ * with the nand subsystem
1502+ */
14631503 if (nand_scan_ident(&denali->mtd, denali->max_banks, NULL)) {
14641504 ret = -ENXIO;
14651505 goto failed_req_irq;
@@ -1491,10 +1531,10 @@ int denali_init(struct denali_nand_info *denali) · 25 unmodified lines
14911531 goto failed_req_irq;
14921532 }
14931533
1494− /* support for multi nand
1495− * MTD known nothing about multi nand,
1496− * so we should tell it the real pagesize
1497− * and anything necessery
1534+ /*
1535+ * support for multi nand
1536+ * MTD known nothing about multi nand, so we should tell it
1537+ * the real pagesize and anything necessery
14981538 */
14991539 denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED);
15001540 denali->nand.chipsize <<= (denali->devnum - 1);
@@ -1510,9 +1550,11 @@ int denali_init(struct denali_nand_info *denali) · 9 unmodified lines
15101550 denali->mtd.size = denali->nand.numchips * denali->nand.chipsize;
15111551 denali->bbtskipbytes *= denali->devnum;
15121552
1513− /* second stage of the NAND scan
1553+ /*
1554+ * second stage of the NAND scan
15141555 * this stage requires information regarding ECC and
1515− * bad block management. */
1556+ * bad block management.
1557+ */
15161558
15171559 /* Bad block management */
15181560 denali->nand.bbt_td = &bbt_main_descr;
@@ -1523,7 +1565,8 @@ int denali_init(struct denali_nand_info *denali) · 4 unmodified lines
15231565 denali->nand.options |= NAND_SKIP_BBTSCAN;
15241566 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
15251567
1526− /* Denali Controller only support 15bit and 8bit ECC in MRST,
1568+ /*
1569+ * Denali Controller only support 15bit and 8bit ECC in MRST,
15271570 * so just let controller do 15bit ECC for MLC and 8bit ECC for
15281571 * SLC if possible.
15291572 * */
@@ -1539,8 +1582,7 @@ int denali_init(struct denali_nand_info *denali) · 9 unmodified lines
15391582 } else if (denali->mtd.oobsize < (denali->bbtskipbytes +
15401583 ECC_8BITS * (denali->mtd.writesize /
15411584 ECC_SECTOR_SIZE))) {
1542− pr_err("Your NAND chip OOB is not large enough to \
1543− contain 8bit ECC correction codes");
1585+ pr_err("Your NAND chip OOB is not large enough to contain 8bit ECC correction codes");
15441586 goto failed_req_irq;
15451587 } else {
15461588 denali->nand.ecc.strength = 8;
@@ -1559,18 +1601,19 @@ int denali_init(struct denali_nand_info *denali) · 12 unmodified lines
15591601 denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes -
15601602 denali->bbtskipbytes;
15611603
1562− /* Let driver know the total blocks number and
1563− * how many blocks contained by each nand chip.
1564− * blksperchip will help driver to know how many
1565− * blocks is taken by FW.
1566− * */
1567− denali->totalblks = denali->mtd.size >>
1568− denali->nand.phys_erase_shift;
1604+ /*
1605+ * Let driver know the total blocks number and how many blocks
1606+ * contained by each nand chip. blksperchip will help driver to
1607+ * know how many blocks is taken by FW.
1608+ */
1609+ denali->totalblks = denali->mtd.size >> denali->nand.phys_erase_shift;
15691610 denali->blksperchip = denali->totalblks / denali->nand.numchips;
15701611
1571− /* These functions are required by the NAND core framework, otherwise,
1612+ /*
1613+ * These functions are required by the NAND core framework, otherwise,
15721614 * the NAND core will assert. However, we don't need them, so we'll stub
1573− * them out. */
1615+ * them out.
1616+ */
15741617 denali->nand.ecc.calculate = denali_ecc_calculate;
15751618 denali->nand.ecc.correct = denali_ecc_correct;
15761619 denali->nand.ecc.hwctl = denali_ecc_hwctl;
@@ -1610,7 +1653,7 @@ void denali_remove(struct denali_nand_info *denali) · 33 unmodified lines
16101653 {
16111654 denali_irq_cleanup(denali->irq, denali);
16121655 dma_unmap_single(denali->dev, denali->buf.dma_buf,
1613− denali->mtd.writesize + denali->mtd.oobsize,
1614− DMA_BIDIRECTIONAL);
1656+ denali->mtd.writesize + denali->mtd.oobsize,
1657+ DMA_BIDIRECTIONAL);
16151658 }
16161659 EXPORT_SYMBOL(denali_remove);
drivers/mtd/nand/denali.h+4−23
@@ -17,6 +17,9 @@ · 16 unmodified lines
1717 *
1818 */
1919
20+#ifndef __DENALI_H__
21+#define __DENALI_H__
22+
2023 #include <linux/mtd/nand.h>
2124
2225 #define DEVICE_RESET 0x0
@@ -400,28 +403,6 @@ · 377 unmodified lines
400403 #define ONFI_BLOOM_TIME 1
401404 #define MODE5_WORKAROUND 0
402405
403−/* lld_nand.h */
404−/*
405− * NAND Flash Controller Device Driver
406− * Copyright (c) 2009, Intel Corporation and its suppliers.
407− *
408− * This program is free software; you can redistribute it and/or modify it
409− * under the terms and conditions of the GNU General Public License,
410− * version 2, as published by the Free Software Foundation.
411− *
412− * This program is distributed in the hope it will be useful, but WITHOUT
413− * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
414− * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
415− * more details.
416− *
417− * You should have received a copy of the GNU General Public License along with
418− * this program; if not, write to the Free Software Foundation, Inc.,
419− * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
420− *
421− */
422−
423−#ifndef _LLD_NAND_
424−#define _LLD_NAND_
425406
426407 #define MODE_00 0x00000000
427408 #define MODE_01 0x04000000
@@ -499,4 +480,4 @@ struct denali_nand_info { · 71 unmodified lines
499480 extern int denali_init(struct denali_nand_info *denali);
500481 extern void denali_remove(struct denali_nand_info *denali);
501482
502−#endif /*_LLD_NAND_*/
483+#endif /* __DENALI_H__ */
drivers/mtd/nand/nand_base.c+27−11
@@ -982,6 +982,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · 981 unmodified lines
982982
983983 chip->select_chip(mtd, chipnr);
984984
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+
985994 /* Check, if it is write protected */
986995 if (nand_check_wp(mtd)) {
987996 pr_debug("%s: device is write protected!\n",
@@ -1032,6 +1041,15 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · 44 unmodified lines
10321041
10331042 chip->select_chip(mtd, chipnr);
10341043
1044+ /*
1045+ * Reset the chip.
1046+ * If we want to check the WP through READ STATUS and check the bit 7
1047+ * we must reset the chip
1048+ * some operation can also clear the bit 7 of status register
1049+ * eg. erase/program a locked block
1050+ */
1051+ chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
1052+
10351053 /* Check, if it is write protected */
10361054 if (nand_check_wp(mtd)) {
10371055 pr_debug("%s: device is write protected!\n",
@@ -2391,8 +2409,8 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, · 1353 unmodified lines
23912409 blockmask = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
23922410
23932411 /* Invalidate the page cache, when we write to the cached page */
2394− if (to <= (chip->pagebuf << chip->page_shift) &&
2395− (chip->pagebuf << chip->page_shift) < (to + ops->len))
2412+ if (to <= ((loff_t)chip->pagebuf << chip->page_shift) &&
2413+ ((loff_t)chip->pagebuf << chip->page_shift) < (to + ops->len))
23962414 chip->pagebuf = -1;
23972415
23982416 /* Don't allow multipage oob writes with offset */
@@ -3576,6 +3594,8 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, · 1177 unmodified lines
35763594 chip->options |= type->options;
35773595 chip->ecc_strength_ds = NAND_ECC_STRENGTH(type);
35783596 chip->ecc_step_ds = NAND_ECC_STEP(type);
3597+ chip->onfi_timing_mode_default =
3598+ type->onfi_timing_mode_default;
35793599
35803600 *busw = type->options & NAND_BUSWIDTH_16;
35813601
@@ -3918,8 +3938,7 @@ int nand_scan_tail(struct mtd_info *mtd) · 336 unmodified lines
39183938 case NAND_ECC_HW_OOB_FIRST:
39193939 /* Similar to NAND_ECC_HW, but a separate read_page handle */
39203940 if (!ecc->calculate || !ecc->correct || !ecc->hwctl) {
3921− pr_warn("No ECC functions supplied; "
3922− "hardware ECC not possible\n");
3941+ pr_warn("No ECC functions supplied; hardware ECC not possible\n");
39233942 BUG();
39243943 }
39253944 if (!ecc->read_page)
@@ -3950,8 +3969,7 @@ int nand_scan_tail(struct mtd_info *mtd) · 24 unmodified lines
39503969 ecc->read_page == nand_read_page_hwecc ||
39513970 !ecc->write_page ||
39523971 ecc->write_page == nand_write_page_hwecc)) {
3953− pr_warn("No ECC functions supplied; "
3954− "hardware ECC not possible\n");
3972+ pr_warn("No ECC functions supplied; hardware ECC not possible\n");
39553973 BUG();
39563974 }
39573975 /* Use standard syndrome read/write page function? */
@@ -3975,9 +3993,8 @@ int nand_scan_tail(struct mtd_info *mtd) · 17 unmodified lines
39753993 }
39763994 break;
39773995 }
3978− pr_warn("%d byte HW ECC not possible on "
3979− "%d byte page size, fallback to SW ECC\n",
3980− ecc->size, mtd->writesize);
3996+ pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
3997+ ecc->size, mtd->writesize);
39813998 ecc->mode = NAND_ECC_SOFT;
39823999
39834000 case NAND_ECC_SOFT:
@@ -4030,8 +4047,7 @@ int nand_scan_tail(struct mtd_info *mtd) · 46 unmodified lines
40304047 break;
40314048
40324049 case NAND_ECC_NONE:
4033− pr_warn("NAND_ECC_NONE selected by board driver. "
4034− "This is not recommended!\n");
4050+ pr_warn("NAND_ECC_NONE selected by board driver. This is not recommended!\n");
40354051 ecc->read_page = nand_read_page_raw;
40364052 ecc->write_page = nand_write_page_raw;
40374053 ecc->read_oob = nand_read_oob_std;
drivers/mtd/nand/nand_bbt.c+10−13
@@ -201,12 +201,12 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, · 200 unmodified lines
201201 res = mtd_read(mtd, from, len, &retlen, buf);
202202 if (res < 0) {
203203 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);
206206 return res;
207207 } 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);
210210 ret = res;
211211 } else {
212212 pr_info("nand_bbt: error reading BBT\n");
@@ -580,8 +580,8 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr · 367 unmodified lines
580580 if (td->pages[i] == -1)
581581 pr_warn("Bad block table not found for chip %d\n", i);
582582 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]);
585585 }
586586 return 0;
587587 }
@@ -725,12 +725,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, · 137 unmodified lines
725725 res = mtd_read(mtd, to, len, &retlen, buf);
726726 if (res < 0) {
727727 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");
730729 return res;
731730 }
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");
734732 }
735733 /* Read oob data */
736734 ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
@@ -1338,9 +1336,8 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) · 601 unmodified lines
13381336 block = (int)(offs >> this->bbt_erase_shift);
13391337 res = bbt_get_entry(this, block);
13401338
1341− pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: "
1342− "(block %d) 0x%02x\n",
1343− (unsigned int)offs, block, res);
1339+ pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
1340+ (unsigned int)offs, block, res);
13441341
13451342 switch (res) {
13461343 case BBT_BLOCK_GOOD:
drivers/mtd/nand/nand_ids.c+4−0
@@ -46,6 +46,10 @@ struct nand_flash_dev nand_flash_ids[] = { · 45 unmodified lines
4646 {"SDTNRGAMA 64G 3.3V 8-bit",
4747 { .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x50} },
4848 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 },
4953
5054 LEGACY_ID_NAND("NAND 4MiB 5V 8-bit", 0x6B, 4, SZ_8K, SP_OPTIONS),
5155 LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit", 0xE3, 4, SZ_8K, SP_OPTIONS),
drivers/mtd/nand/nand_timings.c+1−1
@@ -42,7 +42,7 @@ static const struct nand_sdr_timings onfi_sdr_timings[] = { · 41 unmodified lines
4242 .tRHZ_max = 200000,
4343 .tRLOH_min = 0,
4444 .tRP_min = 50000,
45− .tRST_max = 250000000000,
45+ .tRST_max = 250000000000ULL,
4646 .tWB_max = 200000,
4747 .tRR_min = 40000,
4848 .tWC_min = 100000,
drivers/mtd/nand/nandsim.c+1−1
@@ -827,7 +827,7 @@ static int parse_badblocks(struct nandsim *ns, struct mtd_info *mtd) · 826 unmodified lines
827827 NS_ERR("invalid badblocks.\n");
828828 return -EINVAL;
829829 }
830− offset = erase_block_no * ns->geom.secsz;
830+ offset = (loff_t)erase_block_no * ns->geom.secsz;
831831 if (mtd_block_markbad(mtd, offset)) {
832832 NS_ERR("invalid badblocks.\n");
833833 return -EINVAL;
drivers/mtd/nand/ndfc.c+2−1
@@ -203,7 +203,8 @@ static int ndfc_probe(struct platform_device *ofdev) · 202 unmodified lines
203203 struct ndfc_controller *ndfc;
204204 const __be32 *reg;
205205 u32 ccr;
206− int err, len, cs;
206+ u32 cs;
207+ int err, len;
207208
208209 /* Read the reg property to get the chip select */
209210 reg = of_get_property(ofdev->dev.of_node, "reg", &len);
drivers/mtd/nand/omap2.c+93−73
@@ -136,7 +136,6 @@ · 135 unmodified lines
136136
137137 #define BADBLOCK_MARKER_LENGTH 2
138138
139−#ifdef CONFIG_MTD_NAND_OMAP_BCH
140139 static u_char bch16_vector[] = {0xf5, 0x24, 0x1c, 0xd0, 0x61, 0xb3, 0xf1, 0x55,
141140 0x2e, 0x2c, 0x86, 0xa3, 0xed, 0x36, 0x1b, 0x78,
142141 0x48, 0x76, 0xa9, 0x3b, 0x97, 0xd1, 0x7a, 0x93,
@@ -144,7 +143,6 @@ static u_char bch16_vector[] = {0xf5, 0x24, 0x1c, 0xd0, 0x61, 0xb3, 0xf1, 0x55, · 1 unmodified line
144143 static u_char bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2, 0xbe, 0xcc,
145144 0xac, 0x6b, 0xff, 0x99, 0x7b};
146145 static u_char bch4_vector[] = {0x00, 0x6b, 0x31, 0xdd, 0x41, 0xbc, 0x10};
147−#endif
148146
149147 /* oob info generated runtime depending on ecc algorithm and layout selected */
150148 static struct nand_ecclayout omap_oobinfo;
@@ -1292,7 +1290,6 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd, · 1141 unmodified lines
12921290 return 0;
12931291 }
12941292
1295−#ifdef CONFIG_MTD_NAND_OMAP_BCH
12961293 /**
12971294 * erased_sector_bitflips - count bit flips
12981295 * @data: data sector buffer
@@ -1378,7 +1375,7 @@ static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data, · 79 unmodified lines
13781375 erased_ecc_vec = bch16_vector;
13791376 break;
13801377 default:
1381− pr_err("invalid driver configuration\n");
1378+ dev_err(&info->pdev->dev, "invalid driver configuration\n");
13821379 return -EINVAL;
13831380 }
13841381
@@ -1449,7 +1446,8 @@ static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data, · 64 unmodified lines
14491446 err = 0;
14501447 for (i = 0; i < eccsteps; i++) {
14511448 if (err_vec[i].error_uncorrectable) {
1452− pr_err("nand: uncorrectable bit-flips found\n");
1449+ dev_err(&info->pdev->dev,
1450+ "uncorrectable bit-flips found\n");
14531451 err = -EBADMSG;
14541452 } else if (err_vec[i].error_reported) {
14551453 for (j = 0; j < err_vec[i].error_count; j++) {
@@ -1486,8 +1484,9 @@ static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data, · 30 unmodified lines
14861484 1 << bit_pos;
14871485 }
14881486 } else {
1489− pr_err("invalid bit-flip @ %d:%d\n",
1490− byte_pos, bit_pos);
1487+ dev_err(&info->pdev->dev,
1488+ "invalid bit-flip @ %d:%d\n",
1489+ byte_pos, bit_pos);
14911490 err = -EBADMSG;
14921491 }
14931492 }
@@ -1593,33 +1592,71 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip, · 99 unmodified lines
15931592 /**
15941593 * is_elm_present - checks for presence of ELM module by scanning DT nodes
15951594 * @omap_nand_info: NAND device structure containing platform data
1596− * @bch_type: 0x0=BCH4, 0x1=BCH8, 0x2=BCH16
15971595 */
1598−static int is_elm_present(struct omap_nand_info *info,
1599− struct device_node *elm_node, enum bch_ecc bch_type)
1596+static bool is_elm_present(struct omap_nand_info *info,
1597+ struct device_node *elm_node)
16001598 {
16011599 struct platform_device *pdev;
1602− struct nand_ecc_ctrl *ecc = &info->nand.ecc;
1603− int err;
1600+
16041601 /* check whether elm-id is passed via DT */
16051602 if (!elm_node) {
1606− pr_err("nand: error: ELM DT node not found\n");
1607− return -ENODEV;
1603+ dev_err(&info->pdev->dev, "ELM devicetree node not found\n");
1604+ return false;
16081605 }
16091606 pdev = of_find_device_by_node(elm_node);
16101607 /* check whether ELM device is registered */
16111608 if (!pdev) {
1612− pr_err("nand: error: ELM device not found\n");
1613− return -ENODEV;
1609+ dev_err(&info->pdev->dev, "ELM device not found\n");
1610+ return false;
16141611 }
16151612 /* ELM module available, now configure it */
16161613 info->elm_dev = &pdev->dev;
1617− err = elm_config(info->elm_dev, bch_type,
1618− (info->mtd.writesize / ecc->size), ecc->size, ecc->bytes);
1614+ return true;
1615+}
16191616
1620− return err;
1617+static bool omap2_nand_ecc_check(struct omap_nand_info *info,
1618+ struct omap_nand_platform_data *pdata)
1619+{
1620+ bool ecc_needs_bch, ecc_needs_omap_bch, ecc_needs_elm;
1621+
1622+ switch (info->ecc_opt) {
1623+ case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
1624+ case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
1625+ ecc_needs_omap_bch = false;
1626+ ecc_needs_bch = true;
1627+ ecc_needs_elm = false;
1628+ break;
1629+ case OMAP_ECC_BCH4_CODE_HW:
1630+ case OMAP_ECC_BCH8_CODE_HW:
1631+ case OMAP_ECC_BCH16_CODE_HW:
1632+ ecc_needs_omap_bch = true;
1633+ ecc_needs_bch = false;
1634+ ecc_needs_elm = true;
1635+ break;
1636+ default:
1637+ ecc_needs_omap_bch = false;
1638+ ecc_needs_bch = false;
1639+ ecc_needs_elm = false;
1640+ break;
1641+ }
1642+
1643+ if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_BCH)) {
1644+ dev_err(&info->pdev->dev,
1645+ "CONFIG_MTD_NAND_ECC_BCH not enabled\n");
1646+ return false;
1647+ }
1648+ if (ecc_needs_omap_bch && !IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH)) {
1649+ dev_err(&info->pdev->dev,
1650+ "CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
1651+ return false;
1652+ }
1653+ if (ecc_needs_elm && !is_elm_present(info, pdata->elm_of_node)) {
1654+ dev_err(&info->pdev->dev, "ELM not available\n");
1655+ return false;
1656+ }
1657+
1658+ return true;
16211659 }
1622−#endif /* CONFIG_MTD_NAND_ECC_BCH */
16231660
16241661 static int omap_nand_probe(struct platform_device *pdev)
16251662 {
@@ -1663,7 +1700,6 @@ static int omap_nand_probe(struct platform_device *pdev) · 37 unmodified lines
16631700 mtd->owner = THIS_MODULE;
16641701 nand_chip = &info->nand;
16651702 nand_chip->ecc.priv = NULL;
1666− nand_chip->options |= NAND_SKIP_BBTSCAN;
16671703
16681704 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
16691705 nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
@@ -1692,17 +1728,22 @@ static int omap_nand_probe(struct platform_device *pdev) · 22 unmodified lines
16921728 nand_chip->chip_delay = 50;
16931729 }
16941730
1731+ if (pdata->flash_bbt)
1732+ nand_chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
1733+ else
1734+ nand_chip->options |= NAND_SKIP_BBTSCAN;
1735+
16951736 /* scan NAND device connected to chip controller */
16961737 nand_chip->options |= pdata->devsize & NAND_BUSWIDTH_16;
16971738 if (nand_scan_ident(mtd, 1, NULL)) {
1698− pr_err("nand device scan failed, may be bus-width mismatch\n");
1739+ dev_err(&info->pdev->dev, "scan failed, may be bus-width mismatch\n");
16991740 err = -ENXIO;
17001741 goto return_error;
17011742 }
17021743
17031744 /* check for small page devices */
17041745 if ((mtd->oobsize < 64) && (pdata->ecc_opt != OMAP_ECC_HAM1_CODE_HW)) {
1705− pr_err("small page devices are not supported\n");
1746+ dev_err(&info->pdev->dev, "small page devices are not supported\n");
17061747 err = -EINVAL;
17071748 goto return_error;
17081749 }
@@ -1793,6 +1834,11 @@ static int omap_nand_probe(struct platform_device *pdev) · 84 unmodified lines
17931834 goto return_error;
17941835 }
17951836
1837+ if (!omap2_nand_ecc_check(info, pdata)) {
1838+ err = -EINVAL;
1839+ goto return_error;
1840+ }
1841+
17961842 /* populate MTD interface based on ECC scheme */
17971843 ecclayout = &omap_oobinfo;
17981844 switch (info->ecc_opt) {
@@ -1825,7 +1871,6 @@ static int omap_nand_probe(struct platform_device *pdev) · 26 unmodified lines
18251871 break;
18261872
18271873 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
1828−#ifdef CONFIG_MTD_NAND_ECC_BCH
18291874 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW_DETECTION_SW\n");
18301875 nand_chip->ecc.mode = NAND_ECC_HW;
18311876 nand_chip->ecc.size = 512;
@@ -1853,18 +1898,13 @@ static int omap_nand_probe(struct platform_device *pdev) · 21 unmodified lines
18531898 nand_chip->ecc.bytes,
18541899 &ecclayout);
18551900 if (!nand_chip->ecc.priv) {
1856− pr_err("nand: error: unable to use s/w BCH library\n");
1901+ dev_err(&info->pdev->dev, "unable to use BCH library\n");
18571902 err = -EINVAL;
1903+ goto return_error;
18581904 }
18591905 break;
1860−#else
1861− pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n");
1862− err = -EINVAL;
1863− goto return_error;
1864−#endif
18651906
18661907 case OMAP_ECC_BCH4_CODE_HW:
1867−#ifdef CONFIG_MTD_NAND_OMAP_BCH
18681908 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme\n");
18691909 nand_chip->ecc.mode = NAND_ECC_HW;
18701910 nand_chip->ecc.size = 512;
@@ -1886,21 +1926,15 @@ static int omap_nand_probe(struct platform_device *pdev) · 15 unmodified lines
18861926 /* reserved marker already included in ecclayout->eccbytes */
18871927 ecclayout->oobfree->offset =
18881928 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1889− /* This ECC scheme requires ELM H/W block */
1890− if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) {
1891− pr_err("nand: error: could not initialize ELM\n");
1892− err = -ENODEV;
1929+
1930+ err = elm_config(info->elm_dev, BCH4_ECC,
1931+ info->mtd.writesize / nand_chip->ecc.size,
1932+ nand_chip->ecc.size, nand_chip->ecc.bytes);
1933+ if (err < 0)
18931934 goto return_error;
1894− }
18951935 break;
1896−#else
1897− pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
1898− err = -EINVAL;
1899− goto return_error;
1900−#endif
19011936
19021937 case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
1903−#ifdef CONFIG_MTD_NAND_ECC_BCH
19041938 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
19051939 nand_chip->ecc.mode = NAND_ECC_HW;
19061940 nand_chip->ecc.size = 512;
@@ -1928,19 +1962,13 @@ static int omap_nand_probe(struct platform_device *pdev) · 21 unmodified lines
19281962 nand_chip->ecc.bytes,
19291963 &ecclayout);
19301964 if (!nand_chip->ecc.priv) {
1931− pr_err("nand: error: unable to use s/w BCH library\n");
1965+ dev_err(&info->pdev->dev, "unable to use BCH library\n");
19321966 err = -EINVAL;
19331967 goto return_error;
19341968 }
19351969 break;
1936−#else
1937− pr_err("nand: error: CONFIG_MTD_NAND_ECC_BCH not enabled\n");
1938− err = -EINVAL;
1939− goto return_error;
1940−#endif
19411970
19421971 case OMAP_ECC_BCH8_CODE_HW:
1943−#ifdef CONFIG_MTD_NAND_OMAP_BCH
19441972 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n");
19451973 nand_chip->ecc.mode = NAND_ECC_HW;
19461974 nand_chip->ecc.size = 512;
@@ -1952,12 +1980,13 @@ static int omap_nand_probe(struct platform_device *pdev) · 5 unmodified lines
19521980 nand_chip->ecc.calculate = omap_calculate_ecc_bch;
19531981 nand_chip->ecc.read_page = omap_read_page_bch;
19541982 nand_chip->ecc.write_page = omap_write_page_bch;
1955− /* This ECC scheme requires ELM H/W block */
1956− err = is_elm_present(info, pdata->elm_of_node, BCH8_ECC);
1957− if (err < 0) {
1958− pr_err("nand: error: could not initialize ELM\n");
1983+
1984+ err = elm_config(info->elm_dev, BCH8_ECC,
1985+ info->mtd.writesize / nand_chip->ecc.size,
1986+ nand_chip->ecc.size, nand_chip->ecc.bytes);
1987+ if (err < 0)
19591988 goto return_error;
1960− }
1989+
19611990 /* define ECC layout */
19621991 ecclayout->eccbytes = nand_chip->ecc.bytes *
19631992 (mtd->writesize /
@@ -1969,14 +1998,8 @@ static int omap_nand_probe(struct platform_device *pdev) · 5 unmodified lines
19691998 ecclayout->oobfree->offset =
19701999 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
19712000 break;
1972−#else
1973− pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
1974− err = -EINVAL;
1975− goto return_error;
1976−#endif
19772001
19782002 case OMAP_ECC_BCH16_CODE_HW:
1979−#ifdef CONFIG_MTD_NAND_OMAP_BCH
19802003 pr_info("using OMAP_ECC_BCH16_CODE_HW ECC scheme\n");
19812004 nand_chip->ecc.mode = NAND_ECC_HW;
19822005 nand_chip->ecc.size = 512;
@@ -1987,12 +2010,13 @@ static int omap_nand_probe(struct platform_device *pdev) · 4 unmodified lines
19872010 nand_chip->ecc.calculate = omap_calculate_ecc_bch;
19882011 nand_chip->ecc.read_page = omap_read_page_bch;
19892012 nand_chip->ecc.write_page = omap_write_page_bch;
1990− /* This ECC scheme requires ELM H/W block */
1991− err = is_elm_present(info, pdata->elm_of_node, BCH16_ECC);
1992− if (err < 0) {
1993− pr_err("ELM is required for this ECC scheme\n");
2013+
2014+ err = elm_config(info->elm_dev, BCH16_ECC,
2015+ info->mtd.writesize / nand_chip->ecc.size,
2016+ nand_chip->ecc.size, nand_chip->ecc.bytes);
2017+ if (err < 0)
19942018 goto return_error;
1995− }
2019+
19962020 /* define ECC layout */
19972021 ecclayout->eccbytes = nand_chip->ecc.bytes *
19982022 (mtd->writesize /
@@ -2004,13 +2028,8 @@ static int omap_nand_probe(struct platform_device *pdev) · 5 unmodified lines
20042028 ecclayout->oobfree->offset =
20052029 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
20062030 break;
2007−#else
2008− pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
2009− err = -EINVAL;
2010− goto return_error;
2011−#endif
20122031 default:
2013− pr_err("nand: error: invalid or unsupported ECC scheme\n");
2032+ dev_err(&info->pdev->dev, "invalid or unsupported ECC scheme\n");
20142033 err = -EINVAL;
20152034 goto return_error;
20162035 }
@@ -2022,8 +2041,9 @@ static int omap_nand_probe(struct platform_device *pdev) · 5 unmodified lines
20222041 ecclayout->oobfree->length = mtd->oobsize - ecclayout->oobfree->offset;
20232042 /* check if NAND device's OOB is enough to store ECC signatures */
20242043 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) {
2025− pr_err("not enough OOB bytes required = %d, available=%d\n",
2026− ecclayout->eccbytes, mtd->oobsize);
2044+ dev_err(&info->pdev->dev,
2045+ "not enough OOB bytes required = %d, available=%d\n",
2046+ ecclayout->eccbytes, mtd->oobsize);
20272047 err = -EINVAL;
20282048 goto return_error;
20292049 }
drivers/mtd/nand/omap_elm.crenamed from drivers/mtd/devices/elm.c+0−0

File renamed without changes.

drivers/mtd/nand/sm_common.h+1−1
@@ -18,7 +18,7 @@ struct sm_oob { · 17 unmodified lines
1818 uint8_t ecc2[3];
1919 uint8_t lba_copy2[2];
2020 uint8_t ecc1[3];
21−} __attribute__((packed));
21+} __packed;
2222
2323
2424 /* one sector is always 512 bytes, but it can consist of two nand pages */
drivers/mtd/sm_ftl.c+1−1
@@ -1058,7 +1058,7 @@ static int sm_write(struct mtd_blktrans_dev *dev, · 1057 unmodified lines
10581058 {
10591059 struct sm_ftl *ftl = dev->priv;
10601060 struct ftl_zone *zone;
1061− int error, zone_num, block, boffset;
1061+ int error = 0, zone_num, block, boffset;
10621062
10631063 BUG_ON(ftl->readonly);
10641064 sm_break_offset(ftl, sec_no << 9, &zone_num, &block, &boffset);
drivers/mtd/spi-nor/Kconfig+14−0
@@ -7,6 +7,20 @@ menuconfig MTD_SPI_NOR · 6 unmodified lines
77
88 if MTD_SPI_NOR
99
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+
1024 config SPI_FSL_QUADSPI
1125 tristate "Freescale Quad SPI controller"
1226 depends on ARCH_MXC
drivers/mtd/spi-nor/spi-nor.c+7−35
@@ -611,6 +611,7 @@ const struct spi_device_id spi_nor_ids[] = { · 610 unmodified lines
611611 { "m25px32-s0", INFO(0x207316, 0, 64 * 1024, 64, SECT_4K) },
612612 { "m25px32-s1", INFO(0x206316, 0, 64 * 1024, 64, SECT_4K) },
613613 { "m25px64", INFO(0x207117, 0, 64 * 1024, 128, 0) },
614+ { "m25px80", INFO(0x207114, 0, 64 * 1024, 16, 0) },
614615
615616 /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
616617 { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) },
@@ -623,7 +624,6 @@ const struct spi_device_id spi_nor_ids[] = { · 6 unmodified lines
623624 { "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64, SECT_4K) },
624625 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) },
625626 { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) },
626− { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
627627 { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) },
628628 { "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) },
629629 { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
@@ -671,11 +671,6 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor) · 41 unmodified lines
671671 return ERR_PTR(-ENODEV);
672672 }
673673
674−static const struct spi_device_id *jedec_probe(struct spi_nor *nor)
675−{
676− return nor->read_id(nor);
677−}
678−
679674 static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
680675 size_t *retlen, u_char *buf)
681676 {
@@ -920,7 +915,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · 238 unmodified lines
920915 enum read_mode mode)
921916 {
922917 struct flash_info *info;
923− struct flash_platform_data *data;
924918 struct device *dev = nor->dev;
925919 struct mtd_info *mtd = nor->mtd;
926920 struct device_node *np = dev->of_node;
@@ -931,34 +925,12 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · 4 unmodified lines
931925 if (ret)
932926 return ret;
933927
934− /* Platform data helps sort out which chip type we have, as
935− * well as how this board partitions it. If we don't have
936− * a chip ID, try the JEDEC id commands; they'll work for most
937− * newer chips, even if we don't recognize the particular chip.
938− */
939− data = dev_get_platdata(dev);
940− if (data && data->type) {
941− const struct spi_device_id *plat_id;
942−
943− for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
944− plat_id = &spi_nor_ids[i];
945− if (strcmp(data->type, plat_id->name))
946− continue;
947− break;
948− }
949−
950− if (i < ARRAY_SIZE(spi_nor_ids) - 1)
951− id = plat_id;
952− else
953− dev_warn(dev, "unrecognized id %s\n", data->type);
954− }
955−
956928 info = (void *)id->driver_data;
957929
958930 if (info->jedec_id) {
959931 const struct spi_device_id *jid;
960932
961− jid = jedec_probe(nor);
933+ jid = nor->read_id(nor);
962934 if (IS_ERR(jid)) {
963935 return PTR_ERR(jid);
964936 } else if (jid != id) {
@@ -990,11 +962,8 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · 25 unmodified lines
990962 write_sr(nor, 0);
991963 }
992964
993− if (data && data->name)
994− mtd->name = data->name;
995− else
965+ if (!mtd->name)
996966 mtd->name = dev_name(dev);
997−
998967 mtd->type = MTD_NORFLASH;
999968 mtd->writesize = 1;
1000969 mtd->flags = MTD_CAP_NORFLASH;
@@ -1018,6 +987,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · 17 unmodified lines
1018987 nor->wait_till_ready == spi_nor_wait_till_ready)
1019988 nor->wait_till_ready = spi_nor_wait_till_fsr_ready;
1020989
990+#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
1021991 /* prefer "small sector" erase if possible */
1022992 if (info->flags & SECT_4K) {
1023993 nor->erase_opcode = SPINOR_OP_BE_4K;
@@ -1025,7 +995,9 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · 1 unmodified line
1025995 } else if (info->flags & SECT_4K_PMC) {
1026996 nor->erase_opcode = SPINOR_OP_BE_4K_PMC;
1027997 mtd->erasesize = 4096;
1028− } else {
998+ } else
999+#endif
1000+ {
10291001 nor->erase_opcode = SPINOR_OP_SE;
10301002 mtd->erasesize = info->sector_size;
10311003 }
drivers/mtd/tests/mtd_test.c+2−2
@@ -10,7 +10,7 @@ int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum) · 9 unmodified lines
1010 {
1111 int err;
1212 struct erase_info ei;
13− loff_t addr = ebnum * mtd->erasesize;
13+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
1414
1515 memset(&ei, 0, sizeof(struct erase_info));
1616 ei.mtd = mtd;
@@ -33,7 +33,7 @@ int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum) · 16 unmodified lines
3333 static int is_block_bad(struct mtd_info *mtd, unsigned int ebnum)
3434 {
3535 int ret;
36− loff_t addr = ebnum * mtd->erasesize;
36+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
3737
3838 ret = mtd_block_isbad(mtd, addr);
3939 if (ret)
drivers/mtd/tests/nandbiterrs.c+1−1
@@ -364,7 +364,7 @@ static int __init mtd_nandbiterrs_init(void) · 363 unmodified lines
364364
365365 pr_info("Device uses %d subpages of %d bytes\n", subcount, subsize);
366366
367− offset = page_offset * mtd->writesize;
367+ offset = (loff_t)page_offset * mtd->writesize;
368368 eraseblock = mtd_div_by_eb(offset, mtd);
369369
370370 pr_info("Using page=%u, offset=%llu, eraseblock=%u\n",
drivers/mtd/tests/oobtest.c+4−4
@@ -120,7 +120,7 @@ static int verify_eraseblock(int ebnum) · 119 unmodified lines
120120 int i;
121121 struct mtd_oob_ops ops;
122122 int err = 0;
123− loff_t addr = ebnum * mtd->erasesize;
123+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
124124
125125 prandom_bytes_state(&rnd_state, writebuf, use_len_max * pgcnt);
126126 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
@@ -214,7 +214,7 @@ static int verify_eraseblock_in_one_go(int ebnum) · 87 unmodified lines
214214 {
215215 struct mtd_oob_ops ops;
216216 int err = 0;
217− loff_t addr = ebnum * mtd->erasesize;
217+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
218218 size_t len = mtd->ecclayout->oobavail * pgcnt;
219219
220220 prandom_bytes_state(&rnd_state, writebuf, len);
@@ -568,7 +568,7 @@ static int __init mtd_oobtest_init(void) · 347 unmodified lines
568568 size_t sz = mtd->ecclayout->oobavail;
569569 if (bbt[i] || bbt[i + 1])
570570 continue;
571− addr = (i + 1) * mtd->erasesize - mtd->writesize;
571+ addr = (loff_t)(i + 1) * mtd->erasesize - mtd->writesize;
572572 prandom_bytes_state(&rnd_state, writebuf, sz * cnt);
573573 for (pg = 0; pg < cnt; ++pg) {
574574 ops.mode = MTD_OPS_AUTO_OOB;
@@ -598,7 +598,7 @@ static int __init mtd_oobtest_init(void) · 23 unmodified lines
598598 continue;
599599 prandom_bytes_state(&rnd_state, writebuf,
600600 mtd->ecclayout->oobavail * 2);
601− addr = (i + 1) * mtd->erasesize - mtd->writesize;
601+ addr = (loff_t)(i + 1) * mtd->erasesize - mtd->writesize;
602602 ops.mode = MTD_OPS_AUTO_OOB;
603603 ops.len = 0;
604604 ops.retlen = 0;
drivers/mtd/tests/pagetest.c+2−2
@@ -52,7 +52,7 @@ static struct rnd_state rnd_state; · 51 unmodified lines
5252
5353 static int write_eraseblock(int ebnum)
5454 {
55− loff_t addr = ebnum * mtd->erasesize;
55+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
5656
5757 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
5858 cond_resched();
@@ -64,7 +64,7 @@ static int verify_eraseblock(int ebnum) · 5 unmodified lines
6464 uint32_t j;
6565 int err = 0, i;
6666 loff_t addr0, addrn;
67− loff_t addr = ebnum * mtd->erasesize;
67+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
6868
6969 addr0 = 0;
7070 for (i = 0; i < ebcnt && bbt[i]; ++i)
drivers/mtd/tests/readtest.c+1−1
@@ -47,7 +47,7 @@ static int pgcnt; · 46 unmodified lines
4747 static int read_eraseblock_by_page(int ebnum)
4848 {
4949 int i, ret, err = 0;
50− loff_t addr = ebnum * mtd->erasesize;
50+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
5151 void *buf = iobuf;
5252 void *oobbuf = iobuf1;
5353
drivers/mtd/tests/speedtest.c+7−7
@@ -55,7 +55,7 @@ static int multiblock_erase(int ebnum, int blocks) · 54 unmodified lines
5555 {
5656 int err;
5757 struct erase_info ei;
58− loff_t addr = ebnum * mtd->erasesize;
58+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
5959
6060 memset(&ei, 0, sizeof(struct erase_info));
6161 ei.mtd = mtd;
@@ -80,7 +80,7 @@ static int multiblock_erase(int ebnum, int blocks) · 18 unmodified lines
8080
8181 static int write_eraseblock(int ebnum)
8282 {
83− loff_t addr = ebnum * mtd->erasesize;
83+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
8484
8585 return mtdtest_write(mtd, addr, mtd->erasesize, iobuf);
8686 }
@@ -88,7 +88,7 @@ static int write_eraseblock(int ebnum) · 1 unmodified line
8888 static int write_eraseblock_by_page(int ebnum)
8989 {
9090 int i, err = 0;
91− loff_t addr = ebnum * mtd->erasesize;
91+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
9292 void *buf = iobuf;
9393
9494 for (i = 0; i < pgcnt; i++) {
@@ -106,7 +106,7 @@ static int write_eraseblock_by_2pages(int ebnum) · 11 unmodified lines
106106 {
107107 size_t sz = pgsize * 2;
108108 int i, n = pgcnt / 2, err = 0;
109− loff_t addr = ebnum * mtd->erasesize;
109+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
110110 void *buf = iobuf;
111111
112112 for (i = 0; i < n; i++) {
@@ -124,7 +124,7 @@ static int write_eraseblock_by_2pages(int ebnum) · 11 unmodified lines
124124
125125 static int read_eraseblock(int ebnum)
126126 {
127− loff_t addr = ebnum * mtd->erasesize;
127+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
128128
129129 return mtdtest_read(mtd, addr, mtd->erasesize, iobuf);
130130 }
@@ -132,7 +132,7 @@ static int read_eraseblock(int ebnum) · 1 unmodified line
132132 static int read_eraseblock_by_page(int ebnum)
133133 {
134134 int i, err = 0;
135− loff_t addr = ebnum * mtd->erasesize;
135+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
136136 void *buf = iobuf;
137137
138138 for (i = 0; i < pgcnt; i++) {
@@ -150,7 +150,7 @@ static int read_eraseblock_by_2pages(int ebnum) · 11 unmodified lines
150150 {
151151 size_t sz = pgsize * 2;
152152 int i, n = pgcnt / 2, err = 0;
153− loff_t addr = ebnum * mtd->erasesize;
153+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
154154 void *buf = iobuf;
155155
156156 for (i = 0; i < n; i++) {
drivers/mtd/tests/subpagetest.c+5−5
@@ -57,7 +57,7 @@ static int write_eraseblock(int ebnum) · 56 unmodified lines
5757 {
5858 size_t written;
5959 int err = 0;
60− loff_t addr = ebnum * mtd->erasesize;
60+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
6161
6262 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
6363 err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
@@ -92,7 +92,7 @@ static int write_eraseblock2(int ebnum) · 28 unmodified lines
9292 {
9393 size_t written;
9494 int err = 0, k;
95− loff_t addr = ebnum * mtd->erasesize;
95+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
9696
9797 for (k = 1; k < 33; ++k) {
9898 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
@@ -131,7 +131,7 @@ static int verify_eraseblock(int ebnum) · 32 unmodified lines
131131 {
132132 size_t read;
133133 int err = 0;
134− loff_t addr = ebnum * mtd->erasesize;
134+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
135135
136136 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
137137 clear_data(readbuf, subpgsize);
@@ -192,7 +192,7 @@ static int verify_eraseblock2(int ebnum) · 54 unmodified lines
192192 {
193193 size_t read;
194194 int err = 0, k;
195− loff_t addr = ebnum * mtd->erasesize;
195+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
196196
197197 for (k = 1; k < 33; ++k) {
198198 if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
@@ -227,7 +227,7 @@ static int verify_eraseblock_ff(int ebnum) · 28 unmodified lines
227227 uint32_t j;
228228 size_t read;
229229 int err = 0;
230− loff_t addr = ebnum * mtd->erasesize;
230+ loff_t addr = (loff_t)ebnum * mtd->erasesize;
231231
232232 memset(writebuf, 0xff, subpgsize);
233233 for (j = 0; j < mtd->erasesize / subpgsize; ++j) {
include/linux/mtd/cfi.h+11−11
@@ -153,7 +153,7 @@ struct cfi_ident { · 152 unmodified lines
153153 uint16_t MaxBufWriteSize;
154154 uint8_t NumEraseRegions;
155155 uint32_t EraseRegionInfo[0]; /* Not host ordered */
156−} __attribute__((packed));
156+} __packed;
157157
158158 /* Extended Query Structure for both PRI and ALT */
159159
@@ -161,7 +161,7 @@ struct cfi_extquery { · 1 unmodified line
161161 uint8_t pri[3];
162162 uint8_t MajorVersion;
163163 uint8_t MinorVersion;
164−} __attribute__((packed));
164+} __packed;
165165
166166 /* Vendor-Specific PRI for Intel/Sharp Extended Command Set (0x0001) */
167167
@@ -180,7 +180,7 @@ struct cfi_pri_intelext { · 12 unmodified lines
180180 uint8_t FactProtRegSize;
181181 uint8_t UserProtRegSize;
182182 uint8_t extra[0];
183−} __attribute__((packed));
183+} __packed;
184184
185185 struct cfi_intelext_otpinfo {
186186 uint32_t ProtRegAddr;
@@ -188,7 +188,7 @@ struct cfi_intelext_otpinfo { · 1 unmodified line
188188 uint8_t FactProtRegSize;
189189 uint16_t UserGroups;
190190 uint8_t UserProtRegSize;
191−} __attribute__((packed));
191+} __packed;
192192
193193 struct cfi_intelext_blockinfo {
194194 uint16_t NumIdentBlocks;
@@ -196,7 +196,7 @@ struct cfi_intelext_blockinfo { · 1 unmodified line
196196 uint16_t MinBlockEraseCycles;
197197 uint8_t BitsPerCell;
198198 uint8_t BlockCap;
199−} __attribute__((packed));
199+} __packed;
200200
201201 struct cfi_intelext_regioninfo {
202202 uint16_t NumIdentPartitions;
@@ -205,7 +205,7 @@ struct cfi_intelext_regioninfo { · 2 unmodified lines
205205 uint8_t NumOpAllowedSimEraMode;
206206 uint8_t NumBlockTypes;
207207 struct cfi_intelext_blockinfo BlockTypes[1];
208−} __attribute__((packed));
208+} __packed;
209209
210210 struct cfi_intelext_programming_regioninfo {
211211 uint8_t ProgRegShift;
@@ -214,7 +214,7 @@ struct cfi_intelext_programming_regioninfo { · 2 unmodified lines
214214 uint8_t Reserved2;
215215 uint8_t ControlInvalid;
216216 uint8_t Reserved3;
217−} __attribute__((packed));
217+} __packed;
218218
219219 /* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */
220220
@@ -233,7 +233,7 @@ struct cfi_pri_amdstd { · 12 unmodified lines
233233 uint8_t VppMin;
234234 uint8_t VppMax;
235235 uint8_t TopBottom;
236−} __attribute__((packed));
236+} __packed;
237237
238238 /* Vendor-Specific PRI for Atmel chips (command set 0x0002) */
239239
@@ -245,18 +245,18 @@ struct cfi_pri_atmel { · 5 unmodified lines
245245 uint8_t BottomBoot;
246246 uint8_t BurstMode;
247247 uint8_t PageMode;
248−} __attribute__((packed));
248+} __packed;
249249
250250 struct cfi_pri_query {
251251 uint8_t NumFields;
252252 uint32_t ProtField[1]; /* Not host ordered */
253−} __attribute__((packed));
253+} __packed;
254254
255255 struct cfi_bri_query {
256256 uint8_t PageModeReadCap;
257257 uint8_t NumFields;
258258 uint32_t ConfField[1]; /* Not host ordered */
259−} __attribute__((packed));
259+} __packed;
260260
261261 #define P_ID_NONE 0x0000
262262 #define P_ID_INTEL_EXT 0x0001
include/linux/mtd/nand.h+12−0
@@ -587,6 +587,11 @@ struct nand_buffers { · 586 unmodified lines
587587 * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds,
588588 * also from the datasheet. It is the recommended ECC step
589589 * 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)
590595 * @numchips: [INTERN] number of physical chips
591596 * @chipsize: [INTERN] the size of one chip for multichip arrays
592597 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
@@ -671,6 +676,7 @@ struct nand_chip { · 78 unmodified lines
671676 uint8_t bits_per_cell;
672677 uint16_t ecc_strength_ds;
673678 uint16_t ecc_step_ds;
679+ int onfi_timing_mode_default;
674680 int badblockpos;
675681 int badblockbits;
676682
@@ -766,12 +772,17 @@ struct nand_chip { · 89 unmodified lines
766772 * @options: stores various chip bit options
767773 * @id_len: The valid length of the @id.
768774 * @oobsize: OOB size
775+ * @ecc: ECC correctability and step information from the datasheet.
769776 * @ecc.strength_ds: The ECC correctability from the datasheet, same as the
770777 * @ecc_strength_ds in nand_chip{}.
771778 * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the
772779 * @ecc_step_ds in nand_chip{}, also from the datasheet.
773780 * For example, the "4bit ECC for each 512Byte" can be set with
774781 * NAND_ECC_INFO(4, 512).
782+ * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND
783+ * reset. Should be deduced from timings described
784+ * in the datasheet.
785+ *
775786 */
776787 struct nand_flash_dev {
777788 char *name;
@@ -792,6 +803,7 @@ struct nand_flash_dev { · 14 unmodified lines
792803 uint16_t strength_ds;
793804 uint16_t step_ds;
794805 } ecc;
806+ int onfi_timing_mode_default;
795807 };
796808
797809 /**
include/linux/platform_data/elm.h+16−0
@@ -42,8 +42,24 @@ struct elm_errorvec { · 41 unmodified lines
4242 int error_loc[16];
4343 };
4444
45+#if IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH)
4546 void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc,
4647 struct elm_errorvec *err_vec);
4748 int elm_config(struct device *dev, enum bch_ecc bch_type,
4849 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+
4965 #endif /* __ELM_H */
include/linux/platform_data/mtd-nand-omap2.h+1−0
@@ -71,6 +71,7 @@ struct omap_nand_platform_data { · 70 unmodified lines
7171 struct mtd_partition *parts;
7272 int nr_parts;
7373 bool dev_ready;
74+ bool flash_bbt;
7475 enum nand_io xfer_type;
7576 int devsize;
7677 enum omap_ecc ecc_opt;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t