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

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

Pull MTD updates from Brian Norris:
"Generic MTD:

- populate the MTD device 'of_node' field (and get a proper 'of_node'
symlink in sysfs)

This yielded some new helper functions, and changes across a
variety of drivers

- partitioning cleanups, to prepare for better device-tree based
partitioning in the future

Eliminate a lot of boilerplate for drivers that want to use
OF-based partition parsing

The DT bindings for this didn't settle yet, so most non-cleanup
portions are deferred for a future release

NAND:

- embed a struct mtd_info inside struct nand_chip

This is really long overdue; too many drivers have to do the same
silly boilerplate to allocate and link up two "independent"
structs, when in fact, everyone is assuming there is an exact 1:1
relationship between a NAND chips struct and its underlying MTD.
This aids improved helpers and should make certain abstractions
easier in the future.

Also causes a lot of churn, helped along by some automated code
transformations

- add more core support for detecting (and "correcting") bitflips in
erased pages; requires opt-in by drivers, but at least we kill a
few bad implementations and hopefully stave off future ones

- pxa3xx_nand: cleanups, a few fixes, and PM improvements

- new JZ4780 NAND driver

SPI NOR:

- provide default erase function, for controllers that just want to
send the SECTOR_ERASE command directly

- fix some module auto-loading issues with device tree
("jedec,spi-nor")

- error handling fixes

- new Mediatek QSPI flash driver

Other:

- cfi: force valid geometry Kconfig (finally!)

This one used to trip up randconfigs occasionally, since bots
aren't deterred by big scary "advanced configuration" menus

More? Probably. See the commit logs"

* tag 'for-linus-20160112' of git://git.infradead.org/linux-mtd: (168 commits)
mtd: jz4780_nand: replace if/else blocks with switch/case
mtd: nand: jz4780: Update ecc correction error codes
mtd: nandsim: use nand_get_controller_data()
mtd: jz4780_nand: remove useless mtd->priv = chip assignment
staging: mt29f_spinand: make use of nand_set/get_controller_data() helpers
mtd: nand: make use of nand_set/get_controller_data() helpers
ARM: make use of nand_set/get_controller_data() helpers
mtd: nand: add helpers to access ->priv
mtd: nand: jz4780: driver for NAND devices on JZ4780 SoCs
mtd: nand: jz4740: remove custom 'erased check' implementation
mtd: nand: diskonchip: remove custom 'erased check' implementation
mtd: nand: davinci: remove custom 'erased check' implementation
mtd: nand: use nand_check_erased_ecc_chunk in default ECC read functions
mtd: nand: return consistent error codes in ecc.correct() implementations
doc: dt: mtd: new binding for jz4780-{nand,bch}
mtd: cfi_cmdset_0001: fixing memory leak and handling failed kmalloc
mtd: spi-nor: wait until lock/unlock operations are ready
mtd: tests: consolidate kmalloc/memset 0 call to kzalloc
jffs2: use to_delayed_work
mtd: nand: assign reasonable default name for NAND drivers
...

+3472 -1756
+17 -18
Documentation/DocBook/mtdnand.tmpl
··· 162 162 <sect1 id="Basic_defines"> 163 163 <title>Basic defines</title> 164 164 <para> 165 - At least you have to provide a mtd structure and 166 - a storage for the ioremap'ed chip address. 167 - You can allocate the mtd structure using kmalloc 168 - or you can allocate it statically. 169 - In case of static allocation you have to allocate 170 - a nand_chip structure too. 165 + At least you have to provide a nand_chip structure 166 + and a storage for the ioremap'ed chip address. 167 + You can allocate the nand_chip structure using 168 + kmalloc or you can allocate it statically. 169 + The NAND chip structure embeds an mtd structure 170 + which will be registered to the MTD subsystem. 171 + You can extract a pointer to the mtd structure 172 + from a nand_chip pointer using the nand_to_mtd() 173 + helper. 171 174 </para> 172 175 <para> 173 176 Kmalloc based example ··· 183 180 Static example 184 181 </para> 185 182 <programlisting> 186 - static struct mtd_info board_mtd; 187 183 static struct nand_chip board_chip; 188 184 static void __iomem *baseaddr; 189 185 </programlisting> ··· 237 235 <programlisting> 238 236 static void board_hwcontrol(struct mtd_info *mtd, int cmd) 239 237 { 240 - struct nand_chip *this = (struct nand_chip *) mtd->priv; 238 + struct nand_chip *this = mtd_to_nand(mtd); 241 239 switch(cmd){ 242 240 case NAND_CTL_SETCLE: this->IO_ADDR_W |= CLE_ADRR_BIT; break; 243 241 case NAND_CTL_CLRCLE: this->IO_ADDR_W &amp;= ~CLE_ADRR_BIT; break; ··· 276 274 int err = 0; 277 275 278 276 /* Allocate memory for MTD device structure and private data */ 279 - board_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 280 - if (!board_mtd) { 277 + this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 278 + if (!this) { 281 279 printk ("Unable to allocate NAND MTD device structure.\n"); 282 280 err = -ENOMEM; 283 281 goto out; 284 282 } 283 + 284 + board_mtd = nand_to_mtd(this); 285 285 286 286 /* map physical address */ 287 287 baseaddr = ioremap(CHIP_PHYSICAL_ADDRESS, 1024); ··· 292 288 err = -EIO; 293 289 goto out_mtd; 294 290 } 295 - 296 - /* Get pointer to private data */ 297 - this = (struct nand_chip *) (); 298 - /* Link the private data with the MTD structure */ 299 - board_mtd->priv = this; 300 291 301 292 /* Set address of NAND IO lines */ 302 293 this->IO_ADDR_R = baseaddr; ··· 316 317 out_ior: 317 318 iounmap(baseaddr); 318 319 out_mtd: 319 - kfree (board_mtd); 320 + kfree (this); 320 321 out: 321 322 return err; 322 323 } ··· 342 343 iounmap(baseaddr); 343 344 344 345 /* Free the MTD device structure */ 345 - kfree (board_mtd); 346 + kfree (mtd_to_nand(board_mtd)); 346 347 } 347 348 module_exit(board_cleanup); 348 349 #endif ··· 398 399 <programlisting> 399 400 static void board_select_chip (struct mtd_info *mtd, int chip) 400 401 { 401 - struct nand_chip *this = (struct nand_chip *) mtd->priv; 402 + struct nand_chip *this = mtd_to_nand(mtd); 402 403 403 404 /* Deselect all chips */ 404 405 this->IO_ADDR_R &amp;= ~BOARD_NAND_ADDR_MASK;
+32
Documentation/devicetree/bindings/mtd/brcm,brcmnand.txt
··· 45 45 - #size-cells : <0> 46 46 47 47 Optional properties: 48 + - clock : reference to the clock for the NAND controller 49 + - clock-names : "nand" (required for the above clock) 48 50 - brcm,nand-has-wp : Some versions of this IP include a write-protect 49 51 (WP) control bit. It is always available on >= 50 52 v7.0. Use this property to describe the rare ··· 72 70 * "brcm,nand-bcm63138" 73 71 - reg: (required) the 'NAND_INT_BASE' register range, with separate status 74 72 and enable registers 73 + - reg-names: (required) "nand-int-base" 74 + 75 + * "brcm,nand-bcm6368" 76 + - compatible: should contain "brcm,nand-bcm<soc>", "brcm,nand-bcm6368" 77 + - reg: (required) the 'NAND_INTR_BASE' register range, with combined status 78 + and enable registers, and boot address registers 75 79 - reg-names: (required) "nand-int-base" 76 80 77 81 * "brcm,nand-iproc" ··· 154 146 flash0.kernel@10000000 { 155 147 reg = <0x10000000 0x400000>; 156 148 }; 149 + }; 150 + }; 151 + 152 + nand@10000200 { 153 + compatible = "brcm,nand-bcm63168", "brcm,nand-bcm6368", 154 + "brcm,brcmnand-v4.0", "brcm,brcmnand"; 155 + reg = <0x10000200 0x180>, 156 + <0x10000600 0x200>, 157 + <0x100000b0 0x10>; 158 + reg-names = "nand", "nand-cache", "nand-int-base"; 159 + interrupt-parent = <&periph_intc>; 160 + interrupts = <50>; 161 + clocks = <&periph_clk 20>; 162 + clock-names = "nand"; 163 + 164 + #address-cells = <1>; 165 + #size-cells = <0>; 166 + 167 + nand0: nandcs@0 { 168 + compatible = "brcm,nandcs"; 169 + reg = <0>; 170 + nand-on-flash-bbt; 171 + nand-ecc-strength = <1>; 172 + nand-ecc-step-size = <512>; 157 173 }; 158 174 };
+86
Documentation/devicetree/bindings/mtd/ingenic,jz4780-nand.txt
··· 1 + * Ingenic JZ4780 NAND/BCH 2 + 3 + This file documents the device tree bindings for NAND flash devices on the 4 + JZ4780. NAND devices are connected to the NEMC controller (described in 5 + memory-controllers/ingenic,jz4780-nemc.txt), and thus NAND device nodes must 6 + be children of the NEMC node. 7 + 8 + Required NAND controller device properties: 9 + - compatible: Should be set to "ingenic,jz4780-nand". 10 + - reg: For each bank with a NAND chip attached, should specify a bank number, 11 + an offset of 0 and a size of 0x1000000 (i.e. the whole NEMC bank). 12 + 13 + Optional NAND controller device properties: 14 + - ingenic,bch-controller: To make use of the hardware BCH controller, this 15 + property must contain a phandle for the BCH controller node. The required 16 + properties for this node are described below. If this is not specified, 17 + software BCH will be used instead. 18 + 19 + Optional children nodes: 20 + - Individual NAND chips are children of the NAND controller node. 21 + 22 + Required children node properties: 23 + - reg: An integer ranging from 1 to 6 representing the CS line to use. 24 + 25 + Optional children node properties: 26 + - nand-ecc-step-size: ECC block size in bytes. 27 + - nand-ecc-strength: ECC strength (max number of correctable bits). 28 + - nand-ecc-mode: String, operation mode of the NAND ecc mode. "hw" by default 29 + - nand-on-flash-bbt: boolean to enable on flash bbt option, if not present false 30 + - rb-gpios: GPIO specifier for the busy pin. 31 + - wp-gpios: GPIO specifier for the write protect pin. 32 + 33 + Optional child node of NAND chip nodes: 34 + - partitions: see Documentation/devicetree/bindings/mtd/partition.txt 35 + 36 + Example: 37 + 38 + nemc: nemc@13410000 { 39 + ... 40 + 41 + nandc: nand-controller@1 { 42 + compatible = "ingenic,jz4780-nand"; 43 + reg = <1 0 0x1000000>; /* Bank 1 */ 44 + 45 + #address-cells = <1>; 46 + #size-cells = <0>; 47 + 48 + ingenic,bch-controller = <&bch>; 49 + 50 + nand@1 { 51 + reg = <1>; 52 + 53 + nand-ecc-step-size = <1024>; 54 + nand-ecc-strength = <24>; 55 + nand-ecc-mode = "hw"; 56 + nand-on-flash-bbt; 57 + 58 + rb-gpios = <&gpa 20 GPIO_ACTIVE_LOW>; 59 + wp-gpios = <&gpf 22 GPIO_ACTIVE_LOW>; 60 + 61 + partitions { 62 + #address-cells = <2>; 63 + #size-cells = <2>; 64 + ... 65 + } 66 + }; 67 + }; 68 + }; 69 + 70 + The BCH controller is a separate SoC component used for error correction on 71 + NAND devices. The following is a description of the device properties for a 72 + BCH controller. 73 + 74 + Required BCH properties: 75 + - compatible: Should be set to "ingenic,jz4780-bch". 76 + - reg: Should specify the BCH controller registers location and length. 77 + - clocks: Clock for the BCH controller. 78 + 79 + Example: 80 + 81 + bch: bch@134d0000 { 82 + compatible = "ingenic,jz4780-bch"; 83 + reg = <0x134d0000 0x10000>; 84 + 85 + clocks = <&cgu JZ4780_CLK_BCH>; 86 + };
+51 -5
Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt
··· 1 - * MTD SPI driver for ST M25Pxx (and similar) serial flash chips 1 + * SPI NOR flash: ST M25Pxx (and similar) serial flash chips 2 2 3 3 Required properties: 4 4 - #address-cells, #size-cells : Must be present if the device has sub-nodes 5 5 representing partitions. 6 6 - compatible : May include a device-specific string consisting of the 7 - manufacturer and name of the chip. Bear in mind the DT binding 8 - is not Linux-only, but in case of Linux, see the "m25p_ids" 9 - table in drivers/mtd/devices/m25p80.c for the list of supported 10 - chips. 7 + manufacturer and name of the chip. A list of supported chip 8 + names follows. 11 9 Must also include "jedec,spi-nor" for any SPI NOR flash that can 12 10 be identified by the JEDEC READ ID opcode (0x9F). 11 + 12 + Supported chip names: 13 + at25df321a 14 + at25df641 15 + at26df081a 16 + mr25h256 17 + mx25l4005a 18 + mx25l1606e 19 + mx25l6405d 20 + mx25l12805d 21 + mx25l25635e 22 + n25q064 23 + n25q128a11 24 + n25q128a13 25 + n25q512a 26 + s25fl256s1 27 + s25fl512s 28 + s25sl12801 29 + s25fl008k 30 + s25fl064k 31 + sst25vf040b 32 + m25p40 33 + m25p80 34 + m25p16 35 + m25p32 36 + m25p64 37 + m25p128 38 + w25x80 39 + w25x32 40 + w25q32 41 + w25q32dw 42 + w25q80bl 43 + w25q128 44 + w25q256 45 + 46 + The following chip names have been used historically to 47 + designate quirky versions of flash chips that do not support the 48 + JEDEC READ ID opcode (0x9F): 49 + m25p05-nonjedec 50 + m25p10-nonjedec 51 + m25p20-nonjedec 52 + m25p40-nonjedec 53 + m25p80-nonjedec 54 + m25p16-nonjedec 55 + m25p32-nonjedec 56 + m25p64-nonjedec 57 + m25p128-nonjedec 58 + 13 59 - reg : Chip-Select number 14 60 - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at 15 61
+41
Documentation/devicetree/bindings/mtd/mtk-quadspi.txt
··· 1 + * Serial NOR flash controller for MTK MT81xx (and similar) 2 + 3 + Required properties: 4 + - compatible: should be "mediatek,mt8173-nor"; 5 + - reg: physical base address and length of the controller's register 6 + - clocks: the phandle of the clocks needed by the nor controller 7 + - clock-names: the names of the clocks 8 + the clocks should be named "spi" and "sf". "spi" is used for spi bus, 9 + and "sf" is used for controller, these are the clocks witch 10 + hardware needs to enabling nor flash and nor flash controller. 11 + See Documentation/devicetree/bindings/clock/clock-bindings.txt for details. 12 + - #address-cells: should be <1> 13 + - #size-cells: should be <0> 14 + 15 + The SPI flash must be a child of the nor_flash node and must have a 16 + compatible property. Also see jedec,spi-nor.txt. 17 + 18 + Required properties: 19 + - compatible: May include a device-specific string consisting of the manufacturer 20 + and name of the chip. Must also include "jedec,spi-nor" for any 21 + SPI NOR flash that can be identified by the JEDEC READ ID opcode (0x9F). 22 + - reg : Chip-Select number 23 + 24 + Example: 25 + 26 + nor_flash: spi@1100d000 { 27 + compatible = "mediatek,mt8173-nor"; 28 + reg = <0 0x1100d000 0 0xe0>; 29 + clocks = <&pericfg CLK_PERI_SPI>, 30 + <&topckgen CLK_TOP_SPINFI_IFR_SEL>; 31 + clock-names = "spi", "sf"; 32 + #address-cells = <1>; 33 + #size-cells = <0>; 34 + status = "disabled"; 35 + 36 + flash@0 { 37 + compatible = "jedec,spi-nor"; 38 + reg = <0>; 39 + }; 40 + }; 41 +
+2
Documentation/devicetree/bindings/mtd/partition.txt
··· 32 32 partition should only be mounted read-only. This is usually used for flash 33 33 partitions containing early-boot firmware images or data which should not be 34 34 clobbered. 35 + - lock : Do not unlock the partition at initialization time (not supported on 36 + all devices) 35 37 36 38 Examples: 37 39
+29 -29
Documentation/mtd/nand_ecc.txt
··· 107 107 if (i & 0x01) 108 108 rp1 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp1; 109 109 else 110 - rp0 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp1; 110 + rp0 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp0; 111 111 if (i & 0x02) 112 112 rp3 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp3; 113 113 else ··· 127 127 if (i & 0x20) 128 128 rp11 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp11; 129 129 else 130 - rp10 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp10; 130 + rp10 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp10; 131 131 if (i & 0x40) 132 132 rp13 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp13; 133 133 else ··· 158 158 individually, let us try to rearrange things. 159 159 For the column parity this is easy. We can just xor the bytes and in the 160 160 end filter out the relevant bits. This is pretty nice as it will bring 161 - all cp calculation out of the if loop. 161 + all cp calculation out of the for loop. 162 162 163 163 Similarly we can first xor the bytes for the various rows. 164 164 This leads to: ··· 271 271 Of course this means some modification as the row parity is byte by 272 272 byte. A quick analysis: 273 273 for the column parity we use the par variable. When extending to 32 bits 274 - we can in the end easily calculate p0 and p1 from it. 274 + we can in the end easily calculate rp0 and rp1 from it. 275 275 (because par now consists of 4 bytes, contributing to rp1, rp0, rp1, rp0 276 - respectively) 276 + respectively, from MSB to LSB) 277 277 also rp2 and rp3 can be easily retrieved from par as rp3 covers the 278 - first two bytes and rp2 the last two bytes. 278 + first two MSBs and rp2 covers the last two LSBs. 279 279 280 280 Note that of course now the loop is executed only 64 times (256/4). 281 281 And note that care must taken wrt byte ordering. The way bytes are ··· 387 387 388 388 The code (of course) works, and hurray: we are a little bit faster than 389 389 the linux driver code (about 15%). But wait, don't cheer too quickly. 390 - THere is more to be gained. 390 + There is more to be gained. 391 391 If we look at e.g. rp14 and rp15 we see that we either xor our data with 392 392 rp14 or with rp15. However we also have par which goes over all data. 393 393 This means there is no need to calculate rp14 as it can be calculated from 394 - rp15 through rp14 = par ^ rp15; 394 + rp15 through rp14 = par ^ rp15, because par = rp14 ^ rp15; 395 395 (or if desired we can avoid calculating rp15 and calculate it from 396 396 rp14). That is why some places refer to inverse parity. 397 397 Of course the same thing holds for rp4/5, rp6/7, rp8/9, rp10/11 and rp12/13. ··· 419 419 if (i & 0x20) rp15 ^= cur; 420 420 421 421 and outside the loop added: 422 - rp4 = par ^ rp5; 423 - rp6 = par ^ rp7; 424 - rp8 = par ^ rp9; 425 - rp10 = par ^ rp11; 426 - rp12 = par ^ rp13; 427 - rp14 = par ^ rp15; 422 + rp4 = par ^ rp5; 423 + rp6 = par ^ rp7; 424 + rp8 = par ^ rp9; 425 + rp10 = par ^ rp11; 426 + rp12 = par ^ rp13; 427 + rp14 = par ^ rp15; 428 428 429 429 And after that the code takes about 30% more time, although the number of 430 430 statements is reduced. This is also reflected in the assembly code. ··· 524 524 525 525 cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; 526 526 cur = *bp++; tmppar ^= cur; rp6 ^= cur; 527 - cur = *bp++; tmppar ^= cur; rp4 ^= cur; 528 - cur = *bp++; tmppar ^= cur; rp10 ^= tmppar; 527 + cur = *bp++; tmppar ^= cur; rp4 ^= cur; 528 + cur = *bp++; tmppar ^= cur; rp10 ^= tmppar; 529 529 530 - cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; rp8 ^= cur; 530 + cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; rp8 ^= cur; 531 531 cur = *bp++; tmppar ^= cur; rp6 ^= cur; rp8 ^= cur; 532 - cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp8 ^= cur; 532 + cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp8 ^= cur; 533 533 cur = *bp++; tmppar ^= cur; rp8 ^= cur; 534 534 535 535 cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; ··· 537 537 cur = *bp++; tmppar ^= cur; rp4 ^= cur; 538 538 cur = *bp++; tmppar ^= cur; 539 539 540 - par ^= tmppar; 540 + par ^= tmppar; 541 541 if ((i & 0x1) == 0) rp12 ^= tmppar; 542 542 if ((i & 0x2) == 0) rp14 ^= tmppar; 543 543 } ··· 548 548 549 549 While making the changes I also found that I could exploit that tmppar 550 550 contains the running parity for this iteration. So instead of having: 551 - rp4 ^= cur; rp6 = cur; 552 - I removed the rp6 = cur; statement and did rp6 ^= tmppar; on next 551 + rp4 ^= cur; rp6 ^= cur; 552 + I removed the rp6 ^= cur; statement and did rp6 ^= tmppar; on next 553 553 statement. A similar change was done for rp8 and rp10 554 554 555 555 ··· 593 593 594 594 cur = *bp++; tmppar ^= cur; rp4_6 ^= cur; 595 595 cur = *bp++; tmppar ^= cur; rp6 ^= cur; 596 - cur = *bp++; tmppar ^= cur; rp4 ^= cur; 597 - cur = *bp++; tmppar ^= cur; rp10 ^= tmppar; 596 + cur = *bp++; tmppar ^= cur; rp4 ^= cur; 597 + cur = *bp++; tmppar ^= cur; rp10 ^= tmppar; 598 598 599 - notrp8 = tmppar; 600 - cur = *bp++; tmppar ^= cur; rp4_6 ^= cur; 599 + notrp8 = tmppar; 600 + cur = *bp++; tmppar ^= cur; rp4_6 ^= cur; 601 601 cur = *bp++; tmppar ^= cur; rp6 ^= cur; 602 - cur = *bp++; tmppar ^= cur; rp4 ^= cur; 602 + cur = *bp++; tmppar ^= cur; rp4 ^= cur; 603 603 cur = *bp++; tmppar ^= cur; 604 - rp8 = rp8 ^ tmppar ^ notrp8; 604 + rp8 = rp8 ^ tmppar ^ notrp8; 605 605 606 606 cur = *bp++; tmppar ^= cur; rp4_6 ^= cur; 607 607 cur = *bp++; tmppar ^= cur; rp6 ^= cur; 608 608 cur = *bp++; tmppar ^= cur; rp4 ^= cur; 609 609 cur = *bp++; tmppar ^= cur; 610 610 611 - par ^= tmppar; 611 + par ^= tmppar; 612 612 if ((i & 0x1) == 0) rp12 ^= tmppar; 613 613 if ((i & 0x2) == 0) rp14 ^= tmppar; 614 614 } ··· 700 700 The gain when calculating the ecc is tremendous. Om my development hardware 701 701 a speedup of a factor of 18 for ecc calculation was achieved. On a test on an 702 702 embedded system with a MIPS core a factor 7 was obtained. 703 - On a test with a Linksys NSLU2 (ARMv5TE processor) the speedup was a factor 703 + On a test with a Linksys NSLU2 (ARMv5TE processor) the speedup was a factor 704 704 5 (big endian mode, gcc 4.1.2, -O3) 705 705 For correction not much gain could be obtained (as bitflips are rare). Then 706 706 again there are also much less cycles spent there.
+2 -2
arch/arm/mach-ep93xx/snappercl15.c
··· 49 49 static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 50 50 unsigned int ctrl) 51 51 { 52 - struct nand_chip *chip = mtd->priv; 52 + struct nand_chip *chip = mtd_to_nand(mtd); 53 53 static u16 nand_state = SNAPPERCL15_NAND_WPN; 54 54 u16 set; 55 55 ··· 76 76 77 77 static int snappercl15_nand_dev_ready(struct mtd_info *mtd) 78 78 { 79 - struct nand_chip *chip = mtd->priv; 79 + struct nand_chip *chip = mtd_to_nand(mtd); 80 80 81 81 return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY); 82 82 }
+2 -2
arch/arm/mach-ep93xx/ts72xx.c
··· 74 74 static void ts72xx_nand_hwcontrol(struct mtd_info *mtd, 75 75 int cmd, unsigned int ctrl) 76 76 { 77 - struct nand_chip *chip = mtd->priv; 77 + struct nand_chip *chip = mtd_to_nand(mtd); 78 78 79 79 if (ctrl & NAND_CTRL_CHANGE) { 80 80 void __iomem *addr = chip->IO_ADDR_R; ··· 96 96 97 97 static int ts72xx_nand_device_ready(struct mtd_info *mtd) 98 98 { 99 - struct nand_chip *chip = mtd->priv; 99 + struct nand_chip *chip = mtd_to_nand(mtd); 100 100 void __iomem *addr = chip->IO_ADDR_R; 101 101 102 102 addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE);
+1 -1
arch/arm/mach-imx/mach-qong.c
··· 131 131 */ 132 132 static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 133 133 { 134 - struct nand_chip *nand_chip = mtd->priv; 134 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 135 135 136 136 if (cmd == NAND_CMD_NONE) 137 137 return;
+3 -3
arch/arm/mach-ixp4xx/ixdp425-setup.c
··· 76 76 static void 77 77 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 78 78 { 79 - struct nand_chip *this = mtd->priv; 80 - int offset = (int)this->priv; 79 + struct nand_chip *this = mtd_to_nand(mtd); 80 + int offset = (int)nand_get_controller_data(this); 81 81 82 82 if (ctrl & NAND_CTRL_CHANGE) { 83 83 if (ctrl & NAND_NCE) { ··· 88 88 89 89 offset = (ctrl & NAND_CLE) ? IXDP425_NAND_CMD_BYTE : 0; 90 90 offset |= (ctrl & NAND_ALE) ? IXDP425_NAND_ADDR_BYTE : 0; 91 - this->priv = (void *)offset; 91 + nand_set_controller_data(this, (void *)offset); 92 92 } 93 93 94 94 if (cmd != NAND_CMD_NONE)
+1 -1
arch/arm/mach-omap1/board-nand.c
··· 22 22 23 23 void omap1_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 24 24 { 25 - struct nand_chip *this = mtd->priv; 25 + struct nand_chip *this = mtd_to_nand(mtd); 26 26 unsigned long mask; 27 27 28 28 if (cmd == NAND_CMD_NONE)
+3 -3
arch/arm/mach-orion5x/ts78xx-setup.c
··· 176 176 static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 177 177 unsigned int ctrl) 178 178 { 179 - struct nand_chip *this = mtd->priv; 179 + struct nand_chip *this = mtd_to_nand(mtd); 180 180 181 181 if (ctrl & NAND_CTRL_CHANGE) { 182 182 unsigned char bits; ··· 200 200 static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd, 201 201 const uint8_t *buf, int len) 202 202 { 203 - struct nand_chip *chip = mtd->priv; 203 + struct nand_chip *chip = mtd_to_nand(mtd); 204 204 void __iomem *io_base = chip->IO_ADDR_W; 205 205 unsigned long off = ((unsigned long)buf & 3); 206 206 int sz; ··· 227 227 static void ts78xx_ts_nand_read_buf(struct mtd_info *mtd, 228 228 uint8_t *buf, int len) 229 229 { 230 - struct nand_chip *chip = mtd->priv; 230 + struct nand_chip *chip = mtd_to_nand(mtd); 231 231 void __iomem *io_base = chip->IO_ADDR_R; 232 232 unsigned long off = ((unsigned long)buf & 3); 233 233 int sz;
+1 -1
arch/arm/mach-pxa/balloon3.c
··· 572 572 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 573 573 static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 574 574 { 575 - struct nand_chip *this = mtd->priv; 575 + struct nand_chip *this = mtd_to_nand(mtd); 576 576 uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0; 577 577 578 578 if (ctrl & NAND_CTRL_CHANGE) {
+1 -1
arch/arm/mach-pxa/em-x270.c
··· 289 289 static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat, 290 290 unsigned int ctrl) 291 291 { 292 - struct nand_chip *this = mtd->priv; 292 + struct nand_chip *this = mtd_to_nand(mtd); 293 293 unsigned long nandaddr = (unsigned long)this->IO_ADDR_W; 294 294 295 295 dsb();
+1 -1
arch/arm/mach-pxa/palmtx.c
··· 250 250 static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd, 251 251 unsigned int ctrl) 252 252 { 253 - struct nand_chip *this = mtd->priv; 253 + struct nand_chip *this = mtd_to_nand(mtd); 254 254 char __iomem *nandaddr = this->IO_ADDR_W; 255 255 256 256 if (cmd == NAND_CMD_NONE)
+1 -1
arch/blackfin/mach-bf537/boards/stamp.c
··· 404 404 #define BFIN_NAND_PLAT_ALE 1 405 405 static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 406 406 { 407 - struct nand_chip *this = mtd->priv; 407 + struct nand_chip *this = mtd_to_nand(mtd); 408 408 409 409 if (cmd == NAND_CMD_NONE) 410 410 return;
+1 -1
arch/blackfin/mach-bf561/boards/acvilon.c
··· 267 267 static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 268 268 unsigned int ctrl) 269 269 { 270 - struct nand_chip *this = mtd->priv; 270 + struct nand_chip *this = mtd_to_nand(mtd); 271 271 272 272 if (cmd == NAND_CMD_NONE) 273 273 return;
+2 -6
arch/cris/arch-v32/drivers/mach-a3/nandflash.c
··· 36 36 #define CE_BIT 12 37 37 38 38 struct mtd_info_wrapper { 39 - struct mtd_info info; 40 39 struct nand_chip chip; 41 40 }; 42 41 ··· 51 52 { 52 53 unsigned long flags; 53 54 reg_pio_rw_dout dout; 54 - struct nand_chip *this = mtd->priv; 55 + struct nand_chip *this = mtd_to_nand(mtd); 55 56 56 57 local_irq_save(flags); 57 58 ··· 147 148 148 149 /* Get pointer to private data */ 149 150 this = &wrapper->chip; 150 - crisv32_mtd = &wrapper->info; 151 - 152 - /* Link the private data with the MTD structure */ 153 - crisv32_mtd->priv = this; 151 + crisv32_mtd = nand_to_mtd(this); 154 152 155 153 /* Set address of NAND IO lines */ 156 154 this->IO_ADDR_R = read_cs;
+2 -6
arch/cris/arch-v32/drivers/mach-fs/nandflash.c
··· 31 31 #define BY_BIT 7 32 32 33 33 struct mtd_info_wrapper { 34 - struct mtd_info info; 35 34 struct nand_chip chip; 36 35 }; 37 36 ··· 50 51 { 51 52 unsigned long flags; 52 53 reg_gio_rw_pa_dout dout; 53 - struct nand_chip *this = mtd->priv; 54 + struct nand_chip *this = mtd_to_nand(mtd); 54 55 55 56 local_irq_save(flags); 56 57 ··· 128 129 129 130 /* Get pointer to private data */ 130 131 this = &wrapper->chip; 131 - crisv32_mtd = &wrapper->info; 132 + crisv32_mtd = nand_to_mtd(this); 132 133 133 134 pa_oe.oe |= 1 << CE_BIT; 134 135 pa_oe.oe |= 1 << ALE_BIT; ··· 139 140 bif_cfg.gated_csp0 = regk_bif_core_rd; 140 141 bif_cfg.gated_csp1 = regk_bif_core_wr; 141 142 REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg); 142 - 143 - /* Link the private data with the MTD structure */ 144 - crisv32_mtd->priv = this; 145 143 146 144 /* Set address of NAND IO lines */ 147 145 this->IO_ADDR_R = read_cs;
+1 -1
arch/mips/alchemy/devboards/db1200.c
··· 200 200 static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 201 201 unsigned int ctrl) 202 202 { 203 - struct nand_chip *this = mtd->priv; 203 + struct nand_chip *this = mtd_to_nand(mtd); 204 204 unsigned long ioaddr = (unsigned long)this->IO_ADDR_W; 205 205 206 206 ioaddr &= 0xffffff00;
+1 -1
arch/mips/alchemy/devboards/db1300.c
··· 150 150 static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 151 151 unsigned int ctrl) 152 152 { 153 - struct nand_chip *this = mtd->priv; 153 + struct nand_chip *this = mtd_to_nand(mtd); 154 154 unsigned long ioaddr = (unsigned long)this->IO_ADDR_W; 155 155 156 156 ioaddr &= 0xffffff00;
+1 -1
arch/mips/alchemy/devboards/db1550.c
··· 128 128 static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 129 129 unsigned int ctrl) 130 130 { 131 - struct nand_chip *this = mtd->priv; 131 + struct nand_chip *this = mtd_to_nand(mtd); 132 132 unsigned long ioaddr = (unsigned long)this->IO_ADDR_W; 133 133 134 134 ioaddr &= 0xffffff00;
+1 -1
arch/mips/pnx833x/common/platform.c
··· 180 180 static void 181 181 pnx833x_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 182 182 { 183 - struct nand_chip *this = mtd->priv; 183 + struct nand_chip *this = mtd_to_nand(mtd); 184 184 unsigned long nandaddr = (unsigned long)this->IO_ADDR_W; 185 185 186 186 if (cmd == NAND_CMD_NONE)
+1 -1
arch/mips/rb532/devices.c
··· 148 148 149 149 static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 150 150 { 151 - struct nand_chip *chip = mtd->priv; 151 + struct nand_chip *chip = mtd_to_nand(mtd); 152 152 unsigned char orbits, nandbits; 153 153 154 154 if (ctrl & NAND_CTRL_CHANGE) {
+1 -1
arch/sh/boards/mach-migor/setup.c
··· 167 167 static void migor_nand_flash_cmd_ctl(struct mtd_info *mtd, int cmd, 168 168 unsigned int ctrl) 169 169 { 170 - struct nand_chip *chip = mtd->priv; 170 + struct nand_chip *chip = mtd_to_nand(mtd); 171 171 172 172 if (cmd == NAND_CMD_NONE) 173 173 return;
+1 -1
drivers/mtd/Kconfig
··· 112 112 113 113 config MTD_AFS_PARTS 114 114 tristate "ARM Firmware Suite partition parsing" 115 - depends on ARM 115 + depends on (ARM || ARM64) 116 116 ---help--- 117 117 The ARM Firmware Suite allows the user to divide flash devices into 118 118 multiple 'images'. Each such image has a header containing its name
+32 -48
drivers/mtd/afs.c
··· 34 34 #include <linux/mtd/map.h> 35 35 #include <linux/mtd/partitions.h> 36 36 37 - struct footer_struct { 37 + #define AFSV1_FOOTER_MAGIC 0xA0FFFF9F 38 + 39 + struct footer_v1 { 38 40 u32 image_info_base; /* Address of first word of ImageFooter */ 39 41 u32 image_start; /* Start of area reserved by this footer */ 40 42 u32 signature; /* 'Magic' number proves it's a footer */ ··· 44 42 u32 checksum; /* Just this structure */ 45 43 }; 46 44 47 - struct image_info_struct { 45 + struct image_info_v1 { 48 46 u32 bootFlags; /* Boot flags, compression etc. */ 49 47 u32 imageNumber; /* Unique number, selects for boot etc. */ 50 48 u32 loadAddress; /* Address program should be loaded to */ ··· 69 67 } 70 68 71 69 static int 72 - afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, 73 - u_int off, u_int mask) 70 + afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, 71 + u_int off, u_int mask) 74 72 { 75 - struct footer_struct fs; 73 + struct footer_v1 fs; 76 74 u_int ptr = off + mtd->erasesize - sizeof(fs); 77 75 size_t sz; 78 76 int ret; ··· 87 85 return ret; 88 86 } 89 87 90 - ret = 1; 91 - 92 88 /* 93 89 * Does it contain the magic number? 94 90 */ 95 - if (fs.signature != 0xa0ffff9f) 96 - ret = 0; 91 + if (fs.signature != AFSV1_FOOTER_MAGIC) 92 + return 0; 97 93 98 94 /* 99 95 * Check the checksum. 100 96 */ 101 97 if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) 102 - ret = 0; 98 + return 0; 103 99 104 100 /* 105 101 * Don't touch the SIB. 106 102 */ 107 103 if (fs.type == 2) 108 - ret = 0; 104 + return 0; 109 105 110 106 *iis_start = fs.image_info_base & mask; 111 107 *img_start = fs.image_start & mask; ··· 113 113 * be located after the footer structure. 114 114 */ 115 115 if (*iis_start >= ptr) 116 - ret = 0; 116 + return 0; 117 117 118 118 /* 119 119 * Check the start of this image. The image 120 120 * data can not be located after this block. 121 121 */ 122 122 if (*img_start > off) 123 - ret = 0; 123 + return 0; 124 124 125 - return ret; 125 + return 1; 126 126 } 127 127 128 128 static int 129 - afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr) 129 + afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) 130 130 { 131 131 size_t sz; 132 132 int ret, i; ··· 162 162 } 163 163 164 164 static int parse_afs_partitions(struct mtd_info *mtd, 165 - struct mtd_partition **pparts, 165 + const struct mtd_partition **pparts, 166 166 struct mtd_part_parser_data *data) 167 167 { 168 168 struct mtd_partition *parts; ··· 182 182 * the strings. 183 183 */ 184 184 for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) { 185 - struct image_info_struct iis; 185 + struct image_info_v1 iis; 186 186 u_int iis_ptr, img_ptr; 187 187 188 - ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); 188 + ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 189 189 if (ret < 0) 190 190 break; 191 - if (ret == 0) 192 - continue; 191 + if (ret) { 192 + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 193 + if (ret < 0) 194 + break; 195 + if (ret == 0) 196 + continue; 193 197 194 - ret = afs_read_iis(mtd, &iis, iis_ptr); 195 - if (ret < 0) 196 - break; 197 - if (ret == 0) 198 - continue; 199 - 200 - sz += sizeof(struct mtd_partition); 201 - sz += strlen(iis.name) + 1; 202 - idx += 1; 198 + sz += sizeof(struct mtd_partition); 199 + sz += strlen(iis.name) + 1; 200 + idx += 1; 201 + } 203 202 } 204 203 205 204 if (!sz) ··· 214 215 * Identify the partitions 215 216 */ 216 217 for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { 217 - struct image_info_struct iis; 218 + struct image_info_v1 iis; 218 219 u_int iis_ptr, img_ptr; 219 220 220 221 /* Read the footer. */ 221 - ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); 222 + ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 222 223 if (ret < 0) 223 224 break; 224 225 if (ret == 0) 225 226 continue; 226 227 227 228 /* Read the image info block */ 228 - ret = afs_read_iis(mtd, &iis, iis_ptr); 229 + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 229 230 if (ret < 0) 230 231 break; 231 232 if (ret == 0) ··· 256 257 } 257 258 258 259 static struct mtd_part_parser afs_parser = { 259 - .owner = THIS_MODULE, 260 260 .parse_fn = parse_afs_partitions, 261 261 .name = "afs", 262 262 }; 263 - 264 - static int __init afs_parser_init(void) 265 - { 266 - register_mtd_parser(&afs_parser); 267 - return 0; 268 - } 269 - 270 - static void __exit afs_parser_exit(void) 271 - { 272 - deregister_mtd_parser(&afs_parser); 273 - } 274 - 275 - module_init(afs_parser_init); 276 - module_exit(afs_parser_exit); 277 - 263 + module_mtd_part_parser(afs_parser); 278 264 279 265 MODULE_AUTHOR("ARM Ltd"); 280 266 MODULE_DESCRIPTION("ARM Firmware Suite partition parser");
+2 -16
drivers/mtd/ar7part.c
··· 43 43 }; 44 44 45 45 static int create_mtd_partitions(struct mtd_info *master, 46 - struct mtd_partition **pparts, 46 + const struct mtd_partition **pparts, 47 47 struct mtd_part_parser_data *data) 48 48 { 49 49 struct ar7_bin_rec header; ··· 132 132 } 133 133 134 134 static struct mtd_part_parser ar7_parser = { 135 - .owner = THIS_MODULE, 136 135 .parse_fn = create_mtd_partitions, 137 136 .name = "ar7part", 138 137 }; 139 - 140 - static int __init ar7_parser_init(void) 141 - { 142 - register_mtd_parser(&ar7_parser); 143 - return 0; 144 - } 145 - 146 - static void __exit ar7_parser_exit(void) 147 - { 148 - deregister_mtd_parser(&ar7_parser); 149 - } 150 - 151 - module_init(ar7_parser_init); 152 - module_exit(ar7_parser_exit); 138 + module_mtd_part_parser(ar7_parser); 153 139 154 140 MODULE_LICENSE("GPL"); 155 141 MODULE_AUTHOR( "Felix Fietkau <nbd@openwrt.org>, "
+2 -16
drivers/mtd/bcm47xxpart.c
··· 82 82 } 83 83 84 84 static int bcm47xxpart_parse(struct mtd_info *master, 85 - struct mtd_partition **pparts, 85 + const struct mtd_partition **pparts, 86 86 struct mtd_part_parser_data *data) 87 87 { 88 88 struct mtd_partition *parts; ··· 313 313 }; 314 314 315 315 static struct mtd_part_parser bcm47xxpart_mtd_parser = { 316 - .owner = THIS_MODULE, 317 316 .parse_fn = bcm47xxpart_parse, 318 317 .name = "bcm47xxpart", 319 318 }; 320 - 321 - static int __init bcm47xxpart_init(void) 322 - { 323 - register_mtd_parser(&bcm47xxpart_mtd_parser); 324 - return 0; 325 - } 326 - 327 - static void __exit bcm47xxpart_exit(void) 328 - { 329 - deregister_mtd_parser(&bcm47xxpart_mtd_parser); 330 - } 331 - 332 - module_init(bcm47xxpart_init); 333 - module_exit(bcm47xxpart_exit); 319 + module_mtd_part_parser(bcm47xxpart_mtd_parser); 334 320 335 321 MODULE_LICENSE("GPL"); 336 322 MODULE_DESCRIPTION("MTD partitioning for BCM47XX flash memories");
+2 -16
drivers/mtd/bcm63xxpart.c
··· 68 68 } 69 69 70 70 static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, 71 - struct mtd_partition **pparts, 71 + const struct mtd_partition **pparts, 72 72 struct mtd_part_parser_data *data) 73 73 { 74 74 /* CFE, NVRAM and global Linux are always present */ ··· 214 214 }; 215 215 216 216 static struct mtd_part_parser bcm63xx_cfe_parser = { 217 - .owner = THIS_MODULE, 218 217 .parse_fn = bcm63xx_parse_cfe_partitions, 219 218 .name = "bcm63xxpart", 220 219 }; 221 - 222 - static int __init bcm63xx_cfe_parser_init(void) 223 - { 224 - register_mtd_parser(&bcm63xx_cfe_parser); 225 - return 0; 226 - } 227 - 228 - static void __exit bcm63xx_cfe_parser_exit(void) 229 - { 230 - deregister_mtd_parser(&bcm63xx_cfe_parser); 231 - } 232 - 233 - module_init(bcm63xx_cfe_parser_init); 234 - module_exit(bcm63xx_cfe_parser_exit); 220 + module_mtd_part_parser(bcm63xx_cfe_parser); 235 221 236 222 MODULE_LICENSE("GPL"); 237 223 MODULE_AUTHOR("Daniel Dickinson <openwrt@cshore.neomailbox.net>");
+4
drivers/mtd/chips/Kconfig
··· 67 67 config MTD_CFI_GEOMETRY 68 68 bool "Specific CFI Flash geometry selection" 69 69 depends on MTD_CFI_ADV_OPTIONS 70 + select MTD_MAP_BANK_WIDTH_1 if !(MTD_MAP_BANK_WIDTH_2 || \ 71 + MTD_MAP_BANK_WIDTH_4 || MTD_MAP_BANK_WIDTH_8 || \ 72 + MTD_MAP_BANK_WIDTH_16 || MTD_MAP_BANK_WIDTH_32) 73 + select MTD_CFI_I1 if !(MTD_CFI_I2 || MTD_CFI_I4 || MTD_CFI_I8) 70 74 help 71 75 This option does not affect the code directly, but will enable 72 76 some other configuration options which would allow you to reduce
+7 -1
drivers/mtd/chips/cfi_cmdset_0001.c
··· 596 596 mtd->size = devsize * cfi->numchips; 597 597 598 598 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; 599 - mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) 599 + mtd->eraseregions = kzalloc(sizeof(struct mtd_erase_region_info) 600 600 * mtd->numeraseregions, GFP_KERNEL); 601 601 if (!mtd->eraseregions) 602 602 goto setup_err; ··· 614 614 mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].erasesize = ersize; 615 615 mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].numblocks = ernum; 616 616 mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap = kmalloc(ernum / 8 + 1, GFP_KERNEL); 617 + if (!mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap) 618 + goto setup_err; 617 619 } 618 620 offset += (ersize * ernum); 619 621 } ··· 652 650 return mtd; 653 651 654 652 setup_err: 653 + if (mtd->eraseregions) 654 + for (i=0; i<cfi->cfiq->NumEraseRegions; i++) 655 + for (j=0; j<cfi->numchips; j++) 656 + kfree(mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap); 655 657 kfree(mtd->eraseregions); 656 658 kfree(mtd); 657 659 kfree(cfi->cmdset_priv);
+2 -4
drivers/mtd/chips/cfi_cmdset_0002.c
··· 615 615 616 616 for (i=0; i<cfi->cfiq->NumEraseRegions / 2; i++) { 617 617 int j = (cfi->cfiq->NumEraseRegions-1)-i; 618 - __u32 swap; 619 618 620 - swap = cfi->cfiq->EraseRegionInfo[i]; 621 - cfi->cfiq->EraseRegionInfo[i] = cfi->cfiq->EraseRegionInfo[j]; 622 - cfi->cfiq->EraseRegionInfo[j] = swap; 619 + swap(cfi->cfiq->EraseRegionInfo[i], 620 + cfi->cfiq->EraseRegionInfo[j]); 623 621 } 624 622 } 625 623 /* Set the default CFI lock/unlock addresses */
+1 -2
drivers/mtd/cmdlinepart.c
··· 304 304 * the first one in the chain if a NULL mtd_id is passed in. 305 305 */ 306 306 static int parse_cmdline_partitions(struct mtd_info *master, 307 - struct mtd_partition **pparts, 307 + const struct mtd_partition **pparts, 308 308 struct mtd_part_parser_data *data) 309 309 { 310 310 unsigned long long offset; ··· 382 382 __setup("mtdparts=", mtdpart_setup); 383 383 384 384 static struct mtd_part_parser cmdline_parser = { 385 - .owner = THIS_MODULE, 386 385 .parse_fn = parse_cmdline_partitions, 387 386 .name = "cmdlinepart", 388 387 };
+16 -28
drivers/mtd/devices/m25p80.c
··· 152 152 return 0; 153 153 } 154 154 155 - static int m25p80_erase(struct spi_nor *nor, loff_t offset) 156 - { 157 - struct m25p *flash = nor->priv; 158 - 159 - dev_dbg(nor->dev, "%dKiB at 0x%08x\n", 160 - flash->spi_nor.mtd.erasesize / 1024, (u32)offset); 161 - 162 - /* Set up command buffer. */ 163 - flash->command[0] = nor->erase_opcode; 164 - m25p_addr2cmd(nor, offset, flash->command); 165 - 166 - spi_write(flash->spi, flash->command, m25p_cmdsz(nor)); 167 - 168 - return 0; 169 - } 170 - 171 155 /* 172 156 * board specific setup should have ensured the SPI clock used here 173 157 * matches what the READ command supports, at least until this driver ··· 159 175 */ 160 176 static int m25p_probe(struct spi_device *spi) 161 177 { 162 - struct mtd_part_parser_data ppdata; 163 178 struct flash_platform_data *data; 164 179 struct m25p *flash; 165 180 struct spi_nor *nor; 166 181 enum read_mode mode = SPI_NOR_NORMAL; 167 - char *flash_name = NULL; 182 + char *flash_name; 168 183 int ret; 169 184 170 185 data = dev_get_platdata(&spi->dev); ··· 177 194 /* install the hooks */ 178 195 nor->read = m25p80_read; 179 196 nor->write = m25p80_write; 180 - nor->erase = m25p80_erase; 181 197 nor->write_reg = m25p80_write_reg; 182 198 nor->read_reg = m25p80_read_reg; 183 199 184 200 nor->dev = &spi->dev; 185 - nor->flash_node = spi->dev.of_node; 201 + spi_nor_set_flash_node(nor, spi->dev.of_node); 186 202 nor->priv = flash; 187 203 188 204 spi_set_drvdata(spi, flash); ··· 202 220 */ 203 221 if (data && data->type) 204 222 flash_name = data->type; 223 + else if (!strcmp(spi->modalias, "spi-nor")) 224 + flash_name = NULL; /* auto-detect */ 205 225 else 206 226 flash_name = spi->modalias; 207 227 ··· 211 227 if (ret) 212 228 return ret; 213 229 214 - ppdata.of_node = spi->dev.of_node; 215 - 216 - return mtd_device_parse_register(&nor->mtd, NULL, &ppdata, 217 - data ? data->parts : NULL, 218 - data ? data->nr_parts : 0); 230 + return mtd_device_register(&nor->mtd, data ? data->parts : NULL, 231 + data ? data->nr_parts : 0); 219 232 } 220 233 221 234 ··· 238 257 */ 239 258 static const struct spi_device_id m25p_ids[] = { 240 259 /* 260 + * Allow non-DT platform devices to bind to the "spi-nor" modalias, and 261 + * hack around the fact that the SPI core does not provide uevent 262 + * matching for .of_match_table 263 + */ 264 + {"spi-nor"}, 265 + 266 + /* 241 267 * Entries not used in DTs that should be safe to drop after replacing 242 - * them with "nor-jedec" in platform data. 268 + * them with "spi-nor" in platform data. 243 269 */ 244 270 {"s25sl064a"}, {"w25x16"}, {"m25p10"}, {"m25px64"}, 245 271 246 272 /* 247 - * Entries that were used in DTs without "nor-jedec" fallback and should 248 - * be kept for backward compatibility. 273 + * Entries that were used in DTs without "jedec,spi-nor" fallback and 274 + * should be kept for backward compatibility. 249 275 */ 250 276 {"at25df321a"}, {"at25df641"}, {"at26df081a"}, 251 277 {"mr25h256"},
+2 -3
drivers/mtd/devices/mtd_dataflash.c
··· 624 624 { 625 625 struct dataflash *priv; 626 626 struct mtd_info *device; 627 - struct mtd_part_parser_data ppdata; 628 627 struct flash_platform_data *pdata = dev_get_platdata(&spi->dev); 629 628 char *otp_tag = ""; 630 629 int err = 0; ··· 655 656 device->priv = priv; 656 657 657 658 device->dev.parent = &spi->dev; 659 + mtd_set_of_node(device, spi->dev.of_node); 658 660 659 661 if (revision >= 'c') 660 662 otp_tag = otp_setup(device, revision); ··· 665 665 pagesize, otp_tag); 666 666 spi_set_drvdata(spi, priv); 667 667 668 - ppdata.of_node = spi->dev.of_node; 669 - err = mtd_device_parse_register(device, NULL, &ppdata, 668 + err = mtd_device_register(device, 670 669 pdata ? pdata->parts : NULL, 671 670 pdata ? pdata->nr_parts : 0); 672 671
+2 -4
drivers/mtd/devices/spear_smi.c
··· 810 810 u32 bank, struct device_node *np) 811 811 { 812 812 struct spear_smi *dev = platform_get_drvdata(pdev); 813 - struct mtd_part_parser_data ppdata = {}; 814 813 struct spear_smi_flash_info *flash_info; 815 814 struct spear_smi_plat_data *pdata; 816 815 struct spear_snor_flash *flash; ··· 854 855 flash->mtd.name = flash_devices[flash_index].name; 855 856 856 857 flash->mtd.dev.parent = &pdev->dev; 858 + mtd_set_of_node(&flash->mtd, np); 857 859 flash->mtd.type = MTD_NORFLASH; 858 860 flash->mtd.writesize = 1; 859 861 flash->mtd.flags = MTD_CAP_NORFLASH; ··· 881 881 count = flash_info->nr_partitions; 882 882 } 883 883 #endif 884 - ppdata.of_node = np; 885 884 886 - ret = mtd_device_parse_register(&flash->mtd, NULL, &ppdata, parts, 887 - count); 885 + ret = mtd_device_register(&flash->mtd, parts, count); 888 886 if (ret) { 889 887 dev_err(&dev->pdev->dev, "Err MTD partition=%d\n", ret); 890 888 return ret;
+2 -3
drivers/mtd/devices/st_spi_fsm.c
··· 2025 2025 static int stfsm_probe(struct platform_device *pdev) 2026 2026 { 2027 2027 struct device_node *np = pdev->dev.of_node; 2028 - struct mtd_part_parser_data ppdata; 2029 2028 struct flash_info *info; 2030 2029 struct resource *res; 2031 2030 struct stfsm *fsm; ··· 2034 2035 dev_err(&pdev->dev, "No DT found\n"); 2035 2036 return -EINVAL; 2036 2037 } 2037 - ppdata.of_node = np; 2038 2038 2039 2039 fsm = devm_kzalloc(&pdev->dev, sizeof(*fsm), GFP_KERNEL); 2040 2040 if (!fsm) ··· 2104 2106 2105 2107 fsm->mtd.name = info->name; 2106 2108 fsm->mtd.dev.parent = &pdev->dev; 2109 + mtd_set_of_node(&fsm->mtd, np); 2107 2110 fsm->mtd.type = MTD_NORFLASH; 2108 2111 fsm->mtd.writesize = 4; 2109 2112 fsm->mtd.writebufsize = fsm->mtd.writesize; ··· 2123 2124 (long long)fsm->mtd.size, (long long)(fsm->mtd.size >> 20), 2124 2125 fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10)); 2125 2126 2126 - return mtd_device_parse_register(&fsm->mtd, NULL, &ppdata, NULL, 0); 2127 + return mtd_device_register(&fsm->mtd, NULL, 0); 2127 2128 } 2128 2129 2129 2130 static int stfsm_remove(struct platform_device *pdev)
+2 -6
drivers/mtd/ftl.c
··· 571 571 572 572 573 573 /* Update the maps and usage stats*/ 574 - i = xfer->EraseCount; 575 - xfer->EraseCount = eun->EraseCount; 576 - eun->EraseCount = i; 577 - i = xfer->Offset; 578 - xfer->Offset = eun->Offset; 579 - eun->Offset = i; 574 + swap(xfer->EraseCount, eun->EraseCount); 575 + swap(xfer->Offset, eun->Offset); 580 576 part->FreeTotal -= eun->Free; 581 577 part->FreeTotal += free; 582 578 eun->Free = free;
+2 -3
drivers/mtd/maps/lantiq-flash.c
··· 110 110 static int 111 111 ltq_mtd_probe(struct platform_device *pdev) 112 112 { 113 - struct mtd_part_parser_data ppdata; 114 113 struct ltq_mtd *ltq_mtd; 115 114 struct cfi_private *cfi; 116 115 int err; ··· 160 161 } 161 162 162 163 ltq_mtd->mtd->dev.parent = &pdev->dev; 164 + mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node); 163 165 164 166 cfi = ltq_mtd->map->fldrv_priv; 165 167 cfi->addr_unlock1 ^= 1; 166 168 cfi->addr_unlock2 ^= 1; 167 169 168 - ppdata.of_node = pdev->dev.of_node; 169 - err = mtd_device_parse_register(ltq_mtd->mtd, NULL, &ppdata, NULL, 0); 170 + err = mtd_device_register(ltq_mtd->mtd, NULL, 0); 170 171 if (err) { 171 172 dev_err(&pdev->dev, "failed to add partitions\n"); 172 173 goto err_destroy;
+3 -3
drivers/mtd/maps/physmap_of.c
··· 166 166 int reg_tuple_size; 167 167 struct mtd_info **mtd_list = NULL; 168 168 resource_size_t res_size; 169 - struct mtd_part_parser_data ppdata; 170 169 bool map_indirect; 171 170 const char *mtd_name = NULL; 172 171 ··· 309 310 if (err) 310 311 goto err_out; 311 312 312 - ppdata.of_node = dp; 313 + info->cmtd->dev.parent = &dev->dev; 314 + mtd_set_of_node(info->cmtd, dp); 313 315 part_probe_types = of_get_probes(dp); 314 316 if (!part_probe_types) { 315 317 err = -ENOMEM; 316 318 goto err_out; 317 319 } 318 - mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata, 320 + mtd_device_parse_register(info->cmtd, part_probe_types, NULL, 319 321 NULL, 0); 320 322 of_free_probes(part_probe_types); 321 323
+23 -17
drivers/mtd/mtdcore.c
··· 32 32 #include <linux/err.h> 33 33 #include <linux/ioctl.h> 34 34 #include <linux/init.h> 35 + #include <linux/of.h> 35 36 #include <linux/proc_fs.h> 36 37 #include <linux/idr.h> 37 38 #include <linux/backing-dev.h> ··· 446 445 mtd->dev.devt = MTD_DEVT(i); 447 446 dev_set_name(&mtd->dev, "mtd%d", i); 448 447 dev_set_drvdata(&mtd->dev, mtd); 448 + of_node_get(mtd_get_of_node(mtd)); 449 449 error = device_register(&mtd->dev); 450 450 if (error) 451 451 goto fail_added; ··· 469 467 return 0; 470 468 471 469 fail_added: 470 + of_node_put(mtd_get_of_node(mtd)); 472 471 idr_remove(&mtd_idr, i); 473 472 fail_locked: 474 473 mutex_unlock(&mtd_table_mutex); ··· 511 508 device_unregister(&mtd->dev); 512 509 513 510 idr_remove(&mtd_idr, mtd->index); 511 + of_node_put(mtd_get_of_node(mtd)); 514 512 515 513 module_put(THIS_MODULE); 516 514 ret = 0; ··· 523 519 } 524 520 525 521 static int mtd_add_device_partitions(struct mtd_info *mtd, 526 - struct mtd_partition *real_parts, 527 - int nbparts) 522 + struct mtd_partitions *parts) 528 523 { 524 + const struct mtd_partition *real_parts = parts->parts; 525 + int nbparts = parts->nr_parts; 529 526 int ret; 530 527 531 528 if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { ··· 595 590 const struct mtd_partition *parts, 596 591 int nr_parts) 597 592 { 593 + struct mtd_partitions parsed; 598 594 int ret; 599 - struct mtd_partition *real_parts = NULL; 600 595 601 596 mtd_set_dev_defaults(mtd); 602 597 603 - ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); 604 - if (ret <= 0 && nr_parts && parts) { 605 - real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, 606 - GFP_KERNEL); 607 - if (!real_parts) 608 - ret = -ENOMEM; 609 - else 610 - ret = nr_parts; 611 - } 612 - /* Didn't come up with either parsed OR fallback partitions */ 613 - if (ret < 0) { 598 + memset(&parsed, 0, sizeof(parsed)); 599 + 600 + ret = parse_mtd_partitions(mtd, types, &parsed, parser_data); 601 + if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) { 602 + /* Fall back to driver-provided partitions */ 603 + parsed = (struct mtd_partitions){ 604 + .parts = parts, 605 + .nr_parts = nr_parts, 606 + }; 607 + } else if (ret < 0) { 608 + /* Didn't come up with parsed OR fallback partitions */ 614 609 pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n", 615 610 ret); 616 611 /* Don't abort on errors; we can still use unpartitioned MTD */ 617 - ret = 0; 612 + memset(&parsed, 0, sizeof(parsed)); 618 613 } 619 614 620 - ret = mtd_add_device_partitions(mtd, real_parts, ret); 615 + ret = mtd_add_device_partitions(mtd, &parsed); 621 616 if (ret) 622 617 goto out; 623 618 ··· 637 632 } 638 633 639 634 out: 640 - kfree(real_parts); 635 + /* Cleanup any parsed partitions */ 636 + mtd_part_parser_cleanup(&parsed); 641 637 return ret; 642 638 } 643 639 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
+6 -1
drivers/mtd/mtdcore.h
··· 10 10 int del_mtd_device(struct mtd_info *mtd); 11 11 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int); 12 12 int del_mtd_partitions(struct mtd_info *); 13 + 14 + struct mtd_partitions; 15 + 13 16 int parse_mtd_partitions(struct mtd_info *master, const char * const *types, 14 - struct mtd_partition **pparts, 17 + struct mtd_partitions *pparts, 15 18 struct mtd_part_parser_data *data); 19 + 20 + void mtd_part_parser_cleanup(struct mtd_partitions *parts); 16 21 17 22 int __init init_mtdchar(void); 18 23 void __exit cleanup_mtdchar(void);
+88 -47
drivers/mtd/mtdpart.c
··· 48 48 49 49 /* 50 50 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve 51 - * the pointer to that structure with this macro. 51 + * the pointer to that structure. 52 52 */ 53 - #define PART(x) ((struct mtd_part *)(x)) 53 + static inline struct mtd_part *mtd_to_part(const struct mtd_info *mtd) 54 + { 55 + return container_of(mtd, struct mtd_part, mtd); 56 + } 54 57 55 58 56 59 /* ··· 64 61 static int part_read(struct mtd_info *mtd, loff_t from, size_t len, 65 62 size_t *retlen, u_char *buf) 66 63 { 67 - struct mtd_part *part = PART(mtd); 64 + struct mtd_part *part = mtd_to_part(mtd); 68 65 struct mtd_ecc_stats stats; 69 66 int res; 70 67 ··· 83 80 static int part_point(struct mtd_info *mtd, loff_t from, size_t len, 84 81 size_t *retlen, void **virt, resource_size_t *phys) 85 82 { 86 - struct mtd_part *part = PART(mtd); 83 + struct mtd_part *part = mtd_to_part(mtd); 87 84 88 85 return part->master->_point(part->master, from + part->offset, len, 89 86 retlen, virt, phys); ··· 91 88 92 89 static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) 93 90 { 94 - struct mtd_part *part = PART(mtd); 91 + struct mtd_part *part = mtd_to_part(mtd); 95 92 96 93 return part->master->_unpoint(part->master, from + part->offset, len); 97 94 } ··· 101 98 unsigned long offset, 102 99 unsigned long flags) 103 100 { 104 - struct mtd_part *part = PART(mtd); 101 + struct mtd_part *part = mtd_to_part(mtd); 105 102 106 103 offset += part->offset; 107 104 return part->master->_get_unmapped_area(part->master, len, offset, ··· 111 108 static int part_read_oob(struct mtd_info *mtd, loff_t from, 112 109 struct mtd_oob_ops *ops) 113 110 { 114 - struct mtd_part *part = PART(mtd); 111 + struct mtd_part *part = mtd_to_part(mtd); 115 112 int res; 116 113 117 114 if (from >= mtd->size) ··· 149 146 static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from, 150 147 size_t len, size_t *retlen, u_char *buf) 151 148 { 152 - struct mtd_part *part = PART(mtd); 149 + struct mtd_part *part = mtd_to_part(mtd); 153 150 return part->master->_read_user_prot_reg(part->master, from, len, 154 151 retlen, buf); 155 152 } ··· 157 154 static int part_get_user_prot_info(struct mtd_info *mtd, size_t len, 158 155 size_t *retlen, struct otp_info *buf) 159 156 { 160 - struct mtd_part *part = PART(mtd); 157 + struct mtd_part *part = mtd_to_part(mtd); 161 158 return part->master->_get_user_prot_info(part->master, len, retlen, 162 159 buf); 163 160 } ··· 165 162 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, 166 163 size_t len, size_t *retlen, u_char *buf) 167 164 { 168 - struct mtd_part *part = PART(mtd); 165 + struct mtd_part *part = mtd_to_part(mtd); 169 166 return part->master->_read_fact_prot_reg(part->master, from, len, 170 167 retlen, buf); 171 168 } ··· 173 170 static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len, 174 171 size_t *retlen, struct otp_info *buf) 175 172 { 176 - struct mtd_part *part = PART(mtd); 173 + struct mtd_part *part = mtd_to_part(mtd); 177 174 return part->master->_get_fact_prot_info(part->master, len, retlen, 178 175 buf); 179 176 } ··· 181 178 static int part_write(struct mtd_info *mtd, loff_t to, size_t len, 182 179 size_t *retlen, const u_char *buf) 183 180 { 184 - struct mtd_part *part = PART(mtd); 181 + struct mtd_part *part = mtd_to_part(mtd); 185 182 return part->master->_write(part->master, to + part->offset, len, 186 183 retlen, buf); 187 184 } ··· 189 186 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len, 190 187 size_t *retlen, const u_char *buf) 191 188 { 192 - struct mtd_part *part = PART(mtd); 189 + struct mtd_part *part = mtd_to_part(mtd); 193 190 return part->master->_panic_write(part->master, to + part->offset, len, 194 191 retlen, buf); 195 192 } ··· 197 194 static int part_write_oob(struct mtd_info *mtd, loff_t to, 198 195 struct mtd_oob_ops *ops) 199 196 { 200 - struct mtd_part *part = PART(mtd); 197 + struct mtd_part *part = mtd_to_part(mtd); 201 198 202 199 if (to >= mtd->size) 203 200 return -EINVAL; ··· 209 206 static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, 210 207 size_t len, size_t *retlen, u_char *buf) 211 208 { 212 - struct mtd_part *part = PART(mtd); 209 + struct mtd_part *part = mtd_to_part(mtd); 213 210 return part->master->_write_user_prot_reg(part->master, from, len, 214 211 retlen, buf); 215 212 } ··· 217 214 static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, 218 215 size_t len) 219 216 { 220 - struct mtd_part *part = PART(mtd); 217 + struct mtd_part *part = mtd_to_part(mtd); 221 218 return part->master->_lock_user_prot_reg(part->master, from, len); 222 219 } 223 220 224 221 static int part_writev(struct mtd_info *mtd, const struct kvec *vecs, 225 222 unsigned long count, loff_t to, size_t *retlen) 226 223 { 227 - struct mtd_part *part = PART(mtd); 224 + struct mtd_part *part = mtd_to_part(mtd); 228 225 return part->master->_writev(part->master, vecs, count, 229 226 to + part->offset, retlen); 230 227 } 231 228 232 229 static int part_erase(struct mtd_info *mtd, struct erase_info *instr) 233 230 { 234 - struct mtd_part *part = PART(mtd); 231 + struct mtd_part *part = mtd_to_part(mtd); 235 232 int ret; 236 233 237 234 instr->addr += part->offset; ··· 247 244 void mtd_erase_callback(struct erase_info *instr) 248 245 { 249 246 if (instr->mtd->_erase == part_erase) { 250 - struct mtd_part *part = PART(instr->mtd); 247 + struct mtd_part *part = mtd_to_part(instr->mtd); 251 248 252 249 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) 253 250 instr->fail_addr -= part->offset; ··· 260 257 261 258 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 262 259 { 263 - struct mtd_part *part = PART(mtd); 260 + struct mtd_part *part = mtd_to_part(mtd); 264 261 return part->master->_lock(part->master, ofs + part->offset, len); 265 262 } 266 263 267 264 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 268 265 { 269 - struct mtd_part *part = PART(mtd); 266 + struct mtd_part *part = mtd_to_part(mtd); 270 267 return part->master->_unlock(part->master, ofs + part->offset, len); 271 268 } 272 269 273 270 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) 274 271 { 275 - struct mtd_part *part = PART(mtd); 272 + struct mtd_part *part = mtd_to_part(mtd); 276 273 return part->master->_is_locked(part->master, ofs + part->offset, len); 277 274 } 278 275 279 276 static void part_sync(struct mtd_info *mtd) 280 277 { 281 - struct mtd_part *part = PART(mtd); 278 + struct mtd_part *part = mtd_to_part(mtd); 282 279 part->master->_sync(part->master); 283 280 } 284 281 285 282 static int part_suspend(struct mtd_info *mtd) 286 283 { 287 - struct mtd_part *part = PART(mtd); 284 + struct mtd_part *part = mtd_to_part(mtd); 288 285 return part->master->_suspend(part->master); 289 286 } 290 287 291 288 static void part_resume(struct mtd_info *mtd) 292 289 { 293 - struct mtd_part *part = PART(mtd); 290 + struct mtd_part *part = mtd_to_part(mtd); 294 291 part->master->_resume(part->master); 295 292 } 296 293 297 294 static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs) 298 295 { 299 - struct mtd_part *part = PART(mtd); 296 + struct mtd_part *part = mtd_to_part(mtd); 300 297 ofs += part->offset; 301 298 return part->master->_block_isreserved(part->master, ofs); 302 299 } 303 300 304 301 static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) 305 302 { 306 - struct mtd_part *part = PART(mtd); 303 + struct mtd_part *part = mtd_to_part(mtd); 307 304 ofs += part->offset; 308 305 return part->master->_block_isbad(part->master, ofs); 309 306 } 310 307 311 308 static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) 312 309 { 313 - struct mtd_part *part = PART(mtd); 310 + struct mtd_part *part = mtd_to_part(mtd); 314 311 int res; 315 312 316 313 ofs += part->offset; ··· 561 558 struct device_attribute *attr, char *buf) 562 559 { 563 560 struct mtd_info *mtd = dev_get_drvdata(dev); 564 - struct mtd_part *part = PART(mtd); 561 + struct mtd_part *part = mtd_to_part(mtd); 565 562 return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset); 566 563 } 567 564 ··· 599 596 if (length <= 0) 600 597 return -EINVAL; 601 598 599 + memset(&part, 0, sizeof(part)); 602 600 part.name = name; 603 601 part.size = length; 604 602 part.offset = offset; 605 - part.mask_flags = 0; 606 - part.ecclayout = NULL; 607 603 608 604 new = allocate_partition(master, &part, -1, offset); 609 605 if (IS_ERR(new)) ··· 687 685 static DEFINE_SPINLOCK(part_parser_lock); 688 686 static LIST_HEAD(part_parsers); 689 687 690 - static struct mtd_part_parser *get_partition_parser(const char *name) 688 + static struct mtd_part_parser *mtd_part_parser_get(const char *name) 691 689 { 692 690 struct mtd_part_parser *p, *ret = NULL; 693 691 ··· 704 702 return ret; 705 703 } 706 704 707 - #define put_partition_parser(p) do { module_put((p)->owner); } while (0) 708 - 709 - void register_mtd_parser(struct mtd_part_parser *p) 705 + static inline void mtd_part_parser_put(const struct mtd_part_parser *p) 710 706 { 707 + module_put(p->owner); 708 + } 709 + 710 + /* 711 + * Many partition parsers just expected the core to kfree() all their data in 712 + * one chunk. Do that by default. 713 + */ 714 + static void mtd_part_parser_cleanup_default(const struct mtd_partition *pparts, 715 + int nr_parts) 716 + { 717 + kfree(pparts); 718 + } 719 + 720 + int __register_mtd_parser(struct mtd_part_parser *p, struct module *owner) 721 + { 722 + p->owner = owner; 723 + 724 + if (!p->cleanup) 725 + p->cleanup = &mtd_part_parser_cleanup_default; 726 + 711 727 spin_lock(&part_parser_lock); 712 728 list_add(&p->list, &part_parsers); 713 729 spin_unlock(&part_parser_lock); 730 + 731 + return 0; 714 732 } 715 - EXPORT_SYMBOL_GPL(register_mtd_parser); 733 + EXPORT_SYMBOL_GPL(__register_mtd_parser); 716 734 717 735 void deregister_mtd_parser(struct mtd_part_parser *p) 718 736 { ··· 756 734 * parse_mtd_partitions - parse MTD partitions 757 735 * @master: the master partition (describes whole MTD device) 758 736 * @types: names of partition parsers to try or %NULL 759 - * @pparts: array of partitions found is returned here 737 + * @pparts: info about partitions found is returned here 760 738 * @data: MTD partition parser-specific data 761 739 * 762 740 * This function tries to find partition on MTD device @master. It uses MTD ··· 768 746 * 769 747 * This function may return: 770 748 * o a negative error code in case of failure 771 - * o zero if no partitions were found 772 - * o a positive number of found partitions, in which case on exit @pparts will 773 - * point to an array containing this number of &struct mtd_info objects. 749 + * o zero otherwise, and @pparts will describe the partitions, number of 750 + * partitions, and the parser which parsed them. Caller must release 751 + * resources with mtd_part_parser_cleanup() when finished with the returned 752 + * data. 774 753 */ 775 754 int parse_mtd_partitions(struct mtd_info *master, const char *const *types, 776 - struct mtd_partition **pparts, 755 + struct mtd_partitions *pparts, 777 756 struct mtd_part_parser_data *data) 778 757 { 779 758 struct mtd_part_parser *parser; ··· 785 762 786 763 for ( ; *types; types++) { 787 764 pr_debug("%s: parsing partitions %s\n", master->name, *types); 788 - parser = get_partition_parser(*types); 765 + parser = mtd_part_parser_get(*types); 789 766 if (!parser && !request_module("%s", *types)) 790 - parser = get_partition_parser(*types); 767 + parser = mtd_part_parser_get(*types); 791 768 pr_debug("%s: got parser %s\n", master->name, 792 769 parser ? parser->name : NULL); 793 770 if (!parser) 794 771 continue; 795 - ret = (*parser->parse_fn)(master, pparts, data); 772 + ret = (*parser->parse_fn)(master, &pparts->parts, data); 796 773 pr_debug("%s: parser %s: %i\n", 797 774 master->name, parser->name, ret); 798 - put_partition_parser(parser); 799 775 if (ret > 0) { 800 776 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", 801 777 ret, parser->name, master->name); 802 - return ret; 778 + pparts->nr_parts = ret; 779 + pparts->parser = parser; 780 + return 0; 803 781 } 782 + mtd_part_parser_put(parser); 804 783 /* 805 784 * Stash the first error we see; only report it if no parser 806 785 * succeeds ··· 811 786 err = ret; 812 787 } 813 788 return err; 789 + } 790 + 791 + void mtd_part_parser_cleanup(struct mtd_partitions *parts) 792 + { 793 + const struct mtd_part_parser *parser; 794 + 795 + if (!parts) 796 + return; 797 + 798 + parser = parts->parser; 799 + if (parser) { 800 + if (parser->cleanup) 801 + parser->cleanup(parts->parts, parts->nr_parts); 802 + 803 + mtd_part_parser_put(parser); 804 + } 814 805 } 815 806 816 807 int mtd_is_partition(const struct mtd_info *mtd) ··· 852 811 if (!mtd_is_partition(mtd)) 853 812 return mtd->size; 854 813 855 - return PART(mtd)->master->size; 814 + return mtd_to_part(mtd)->master->size; 856 815 } 857 816 EXPORT_SYMBOL_GPL(mtd_get_device_size);
+9 -2
drivers/mtd/nand/Kconfig
··· 55 55 config MTD_NAND_DENALI_DT 56 56 tristate "Support Denali NAND controller as a DT device" 57 57 select MTD_NAND_DENALI 58 - depends on HAS_DMA && HAVE_CLK 58 + depends on HAS_DMA && HAVE_CLK && OF 59 59 help 60 60 Enable the driver for NAND flash on platforms using a Denali NAND 61 61 controller as a DT device. ··· 480 480 481 481 config MTD_NAND_SH_FLCTL 482 482 tristate "Support for NAND on Renesas SuperH FLCTL" 483 - depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST 483 + depends on SUPERH || COMPILE_TEST 484 484 depends on HAS_IOMEM 485 485 depends on HAS_DMA 486 486 help ··· 518 518 depends on MACH_JZ4740 519 519 help 520 520 Enables support for NAND Flash on JZ4740 SoC based boards. 521 + 522 + config MTD_NAND_JZ4780 523 + tristate "Support for NAND on JZ4780 SoC" 524 + depends on MACH_JZ4780 && JZ4780_NEMC 525 + help 526 + Enables support for NAND Flash connected to the NEMC on JZ4780 SoC 527 + based boards, using the BCH controller for hardware error correction. 521 528 522 529 config MTD_NAND_FSMC 523 530 tristate "Support for NAND on ST Micros FSMC"
+1
drivers/mtd/nand/Makefile
··· 49 49 obj-$(CONFIG_MTD_NAND_VF610_NFC) += vf610_nfc.o 50 50 obj-$(CONFIG_MTD_NAND_RICOH) += r852.o 51 51 obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o 52 + obj-$(CONFIG_MTD_NAND_JZ4780) += jz4780_nand.o jz4780_bch.o 52 53 obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/ 53 54 obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o 54 55 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/
+10 -16
drivers/mtd/nand/ams-delta.c
··· 64 64 65 65 static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte) 66 66 { 67 - struct nand_chip *this = mtd->priv; 68 - void __iomem *io_base = this->priv; 67 + struct nand_chip *this = mtd_to_nand(mtd); 68 + void __iomem *io_base = (void __iomem *)nand_get_controller_data(this); 69 69 70 70 writew(0, io_base + OMAP_MPUIO_IO_CNTL); 71 71 writew(byte, this->IO_ADDR_W); ··· 77 77 static u_char ams_delta_read_byte(struct mtd_info *mtd) 78 78 { 79 79 u_char res; 80 - struct nand_chip *this = mtd->priv; 81 - void __iomem *io_base = this->priv; 80 + struct nand_chip *this = mtd_to_nand(mtd); 81 + void __iomem *io_base = (void __iomem *)nand_get_controller_data(this); 82 82 83 83 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE, 0); 84 84 ndelay(40); ··· 183 183 return -ENXIO; 184 184 185 185 /* Allocate memory for MTD device structure and private data */ 186 - ams_delta_mtd = kzalloc(sizeof(struct mtd_info) + 187 - sizeof(struct nand_chip), GFP_KERNEL); 188 - if (!ams_delta_mtd) { 186 + this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 187 + if (!this) { 189 188 printk (KERN_WARNING "Unable to allocate E3 NAND MTD device structure.\n"); 190 189 err = -ENOMEM; 191 190 goto out; 192 191 } 193 192 193 + ams_delta_mtd = nand_to_mtd(this); 194 194 ams_delta_mtd->owner = THIS_MODULE; 195 - 196 - /* Get pointer to private data */ 197 - this = (struct nand_chip *) (&ams_delta_mtd[1]); 198 - 199 - /* Link the private data with the MTD structure */ 200 - ams_delta_mtd->priv = this; 201 195 202 196 /* 203 197 * Don't try to request the memory region from here, ··· 206 212 goto out_free; 207 213 } 208 214 209 - this->priv = io_base; 215 + nand_set_controller_data(this, (void *)io_base); 210 216 211 217 /* Set address of NAND IO lines */ 212 218 this->IO_ADDR_R = io_base + OMAP_MPUIO_INPUT_LATCH; ··· 250 256 gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB); 251 257 iounmap(io_base); 252 258 out_free: 253 - kfree(ams_delta_mtd); 259 + kfree(this); 254 260 out: 255 261 return err; 256 262 } ··· 270 276 iounmap(io_base); 271 277 272 278 /* Free the MTD device structure */ 273 - kfree(ams_delta_mtd); 279 + kfree(mtd_to_nand(ams_delta_mtd)); 274 280 275 281 return 0; 276 282 }
+67 -67
drivers/mtd/nand/atmel_nand.c
··· 116 116 117 117 struct atmel_nand_host { 118 118 struct nand_chip nand_chip; 119 - struct mtd_info mtd; 120 119 void __iomem *io_base; 121 120 dma_addr_t io_phys; 122 121 struct atmel_nand_data board; ··· 127 128 128 129 struct atmel_nfc *nfc; 129 130 130 - struct atmel_nand_caps *caps; 131 + const struct atmel_nand_caps *caps; 131 132 bool has_pmecc; 132 133 u8 pmecc_corr_cap; 133 134 u16 pmecc_sector_size; ··· 181 182 */ 182 183 static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 183 184 { 184 - struct nand_chip *nand_chip = mtd->priv; 185 - struct atmel_nand_host *host = nand_chip->priv; 185 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 186 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 186 187 187 188 if (ctrl & NAND_CTRL_CHANGE) { 188 189 if (ctrl & NAND_NCE) ··· 204 205 */ 205 206 static int atmel_nand_device_ready(struct mtd_info *mtd) 206 207 { 207 - struct nand_chip *nand_chip = mtd->priv; 208 - struct atmel_nand_host *host = nand_chip->priv; 208 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 209 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 209 210 210 211 return gpio_get_value(host->board.rdy_pin) ^ 211 212 !!host->board.rdy_pin_active_low; ··· 214 215 /* Set up for hardware ready pin and enable pin. */ 215 216 static int atmel_nand_set_enable_ready_pins(struct mtd_info *mtd) 216 217 { 217 - struct nand_chip *chip = mtd->priv; 218 - struct atmel_nand_host *host = chip->priv; 218 + struct nand_chip *chip = mtd_to_nand(mtd); 219 + struct atmel_nand_host *host = nand_get_controller_data(chip); 219 220 int res = 0; 220 221 221 222 if (gpio_is_valid(host->board.rdy_pin)) { ··· 266 267 */ 267 268 static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len) 268 269 { 269 - struct nand_chip *nand_chip = mtd->priv; 270 - struct atmel_nand_host *host = nand_chip->priv; 270 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 271 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 271 272 272 273 if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) { 273 274 memcpy(buf, host->nfc->data_in_sram, len); ··· 279 280 280 281 static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len) 281 282 { 282 - struct nand_chip *nand_chip = mtd->priv; 283 - struct atmel_nand_host *host = nand_chip->priv; 283 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 284 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 284 285 285 286 if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) { 286 287 memcpy(buf, host->nfc->data_in_sram, len); ··· 292 293 293 294 static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len) 294 295 { 295 - struct nand_chip *nand_chip = mtd->priv; 296 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 296 297 297 298 __raw_writesb(nand_chip->IO_ADDR_W, buf, len); 298 299 } 299 300 300 301 static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len) 301 302 { 302 - struct nand_chip *nand_chip = mtd->priv; 303 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 303 304 304 305 __raw_writesw(nand_chip->IO_ADDR_W, buf, len / 2); 305 306 } ··· 316 317 return -EINVAL; 317 318 318 319 if (bank) { 320 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 321 + 319 322 /* Only for a 2k-page or lower flash, NFC can handle 2 banks */ 320 - if (host->mtd.writesize > 2048) 323 + if (mtd->writesize > 2048) 321 324 return -EINVAL; 322 325 nfc_writel(host->nfc->hsmc_regs, BANK, ATMEL_HSMC_NFC_BANK1); 323 326 } else { ··· 353 352 dma_addr_t dma_src_addr, dma_dst_addr, phys_addr; 354 353 struct dma_async_tx_descriptor *tx = NULL; 355 354 dma_cookie_t cookie; 356 - struct nand_chip *chip = mtd->priv; 357 - struct atmel_nand_host *host = chip->priv; 355 + struct nand_chip *chip = mtd_to_nand(mtd); 356 + struct atmel_nand_host *host = nand_get_controller_data(chip); 358 357 void *p = buf; 359 358 int err = -EIO; 360 359 enum dma_data_direction dir = is_read ? DMA_FROM_DEVICE : DMA_TO_DEVICE; ··· 426 425 427 426 static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len) 428 427 { 429 - struct nand_chip *chip = mtd->priv; 430 - struct atmel_nand_host *host = chip->priv; 428 + struct nand_chip *chip = mtd_to_nand(mtd); 429 + struct atmel_nand_host *host = nand_get_controller_data(chip); 431 430 432 431 if (use_dma && len > mtd->oobsize) 433 432 /* only use DMA for bigger than oob size: better performances */ ··· 442 441 443 442 static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 444 443 { 445 - struct nand_chip *chip = mtd->priv; 446 - struct atmel_nand_host *host = chip->priv; 444 + struct nand_chip *chip = mtd_to_nand(mtd); 445 + struct atmel_nand_host *host = nand_get_controller_data(chip); 447 446 448 447 if (use_dma && len > mtd->oobsize) 449 448 /* only use DMA for bigger than oob size: better performances */ ··· 534 533 535 534 static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector) 536 535 { 537 - struct nand_chip *nand_chip = mtd->priv; 538 - struct atmel_nand_host *host = nand_chip->priv; 536 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 537 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 539 538 int i; 540 539 uint32_t value; 541 540 ··· 551 550 552 551 static void pmecc_substitute(struct mtd_info *mtd) 553 552 { 554 - struct nand_chip *nand_chip = mtd->priv; 555 - struct atmel_nand_host *host = nand_chip->priv; 553 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 554 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 556 555 int16_t __iomem *alpha_to = host->pmecc_alpha_to; 557 556 int16_t __iomem *index_of = host->pmecc_index_of; 558 557 int16_t *partial_syn = host->pmecc_partial_syn; ··· 593 592 594 593 static void pmecc_get_sigma(struct mtd_info *mtd) 595 594 { 596 - struct nand_chip *nand_chip = mtd->priv; 597 - struct atmel_nand_host *host = nand_chip->priv; 595 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 596 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 598 597 599 598 int16_t *lmu = host->pmecc_lmu; 600 599 int16_t *si = host->pmecc_si; ··· 751 750 752 751 static int pmecc_err_location(struct mtd_info *mtd) 753 752 { 754 - struct nand_chip *nand_chip = mtd->priv; 755 - struct atmel_nand_host *host = nand_chip->priv; 753 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 754 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 756 755 unsigned long end_time; 757 756 const int cap = host->pmecc_corr_cap; 758 757 const int num = 2 * cap + 1; ··· 803 802 static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc, 804 803 int sector_num, int extra_bytes, int err_nbr) 805 804 { 806 - struct nand_chip *nand_chip = mtd->priv; 807 - struct atmel_nand_host *host = nand_chip->priv; 805 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 806 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 808 807 int i = 0; 809 808 int byte_pos, bit_pos, sector_size, pos; 810 809 uint32_t tmp; ··· 849 848 static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf, 850 849 u8 *ecc) 851 850 { 852 - struct nand_chip *nand_chip = mtd->priv; 853 - struct atmel_nand_host *host = nand_chip->priv; 851 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 852 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 854 853 int i, err_nbr; 855 854 uint8_t *buf_pos; 856 855 int max_bitflips = 0; ··· 920 919 static int atmel_nand_pmecc_read_page(struct mtd_info *mtd, 921 920 struct nand_chip *chip, uint8_t *buf, int oob_required, int page) 922 921 { 923 - struct atmel_nand_host *host = chip->priv; 922 + struct atmel_nand_host *host = nand_get_controller_data(chip); 924 923 int eccsize = chip->ecc.size * chip->ecc.steps; 925 924 uint8_t *oob = chip->oob_poi; 926 925 uint32_t *eccpos = chip->ecc.layout->eccpos; ··· 958 957 struct nand_chip *chip, const uint8_t *buf, int oob_required, 959 958 int page) 960 959 { 961 - struct atmel_nand_host *host = chip->priv; 960 + struct atmel_nand_host *host = nand_get_controller_data(chip); 962 961 uint32_t *eccpos = chip->ecc.layout->eccpos; 963 962 int i, j; 964 963 unsigned long end_time; ··· 993 992 994 993 static void atmel_pmecc_core_init(struct mtd_info *mtd) 995 994 { 996 - struct nand_chip *nand_chip = mtd->priv; 997 - struct atmel_nand_host *host = nand_chip->priv; 995 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 996 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 998 997 uint32_t val = 0; 999 998 struct nand_ecclayout *ecc_layout; 1000 999 ··· 1160 1159 static int atmel_pmecc_nand_init_params(struct platform_device *pdev, 1161 1160 struct atmel_nand_host *host) 1162 1161 { 1163 - struct mtd_info *mtd = &host->mtd; 1164 1162 struct nand_chip *nand_chip = &host->nand_chip; 1163 + struct mtd_info *mtd = nand_to_mtd(nand_chip); 1165 1164 struct resource *regs, *regs_pmerr, *regs_rom; 1166 1165 uint16_t *galois_table; 1167 1166 int cap, sector_size, err_no; ··· 1309 1308 static int atmel_nand_calculate(struct mtd_info *mtd, 1310 1309 const u_char *dat, unsigned char *ecc_code) 1311 1310 { 1312 - struct nand_chip *nand_chip = mtd->priv; 1313 - struct atmel_nand_host *host = nand_chip->priv; 1311 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1312 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 1314 1313 unsigned int ecc_value; 1315 1314 1316 1315 /* get the first 2 ECC bytes */ ··· 1356 1355 * Workaround: Reset the parity registers before reading the 1357 1356 * actual data. 1358 1357 */ 1359 - struct atmel_nand_host *host = chip->priv; 1358 + struct atmel_nand_host *host = nand_get_controller_data(chip); 1360 1359 if (host->board.need_reset_workaround) 1361 1360 ecc_writel(host->ecc, CR, ATMEL_ECC_RST); 1362 1361 ··· 1413 1412 static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat, 1414 1413 u_char *read_ecc, u_char *isnull) 1415 1414 { 1416 - struct nand_chip *nand_chip = mtd->priv; 1417 - struct atmel_nand_host *host = nand_chip->priv; 1415 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1416 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 1418 1417 unsigned int ecc_status; 1419 1418 unsigned int ecc_word, ecc_bit; 1420 1419 ··· 1445 1444 * We can't correct so many errors */ 1446 1445 dev_dbg(host->dev, "atmel_nand : multiple errors detected." 1447 1446 " Unable to correct.\n"); 1448 - return -EIO; 1447 + return -EBADMSG; 1449 1448 } 1450 1449 1451 1450 /* if there's a single bit error : we can correct it */ ··· 1479 1478 */ 1480 1479 static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) 1481 1480 { 1482 - struct nand_chip *nand_chip = mtd->priv; 1483 - struct atmel_nand_host *host = nand_chip->priv; 1481 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1482 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 1484 1483 1485 1484 if (host->board.need_reset_workaround) 1486 1485 ecc_writel(host->ecc, CR, ATMEL_ECC_RST); ··· 1587 1586 static int atmel_hw_nand_init_params(struct platform_device *pdev, 1588 1587 struct atmel_nand_host *host) 1589 1588 { 1590 - struct mtd_info *mtd = &host->mtd; 1591 1589 struct nand_chip *nand_chip = &host->nand_chip; 1590 + struct mtd_info *mtd = nand_to_mtd(nand_chip); 1592 1591 struct resource *regs; 1593 1592 1594 1593 regs = platform_get_resource(pdev, IORESOURCE_MEM, 1); ··· 1772 1771 static int nfc_device_ready(struct mtd_info *mtd) 1773 1772 { 1774 1773 u32 status, mask; 1775 - struct nand_chip *nand_chip = mtd->priv; 1776 - struct atmel_nand_host *host = nand_chip->priv; 1774 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1775 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 1777 1776 1778 1777 status = nfc_read_status(host); 1779 1778 mask = nfc_readl(host->nfc->hsmc_regs, IMR); ··· 1788 1787 1789 1788 static void nfc_select_chip(struct mtd_info *mtd, int chip) 1790 1789 { 1791 - struct nand_chip *nand_chip = mtd->priv; 1792 - struct atmel_nand_host *host = nand_chip->priv; 1790 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1791 + struct atmel_nand_host *host = nand_get_controller_data(nand_chip); 1793 1792 1794 1793 if (chip == -1) 1795 1794 nfc_writel(host->nfc->hsmc_regs, CTRL, NFC_CTRL_DISABLE); ··· 1800 1799 static int nfc_make_addr(struct mtd_info *mtd, int command, int column, 1801 1800 int page_addr, unsigned int *addr1234, unsigned int *cycle0) 1802 1801 { 1803 - struct nand_chip *chip = mtd->priv; 1802 + struct nand_chip *chip = mtd_to_nand(mtd); 1804 1803 1805 1804 int acycle = 0; 1806 1805 unsigned char addr_bytes[8]; ··· 1840 1839 static void nfc_nand_command(struct mtd_info *mtd, unsigned int command, 1841 1840 int column, int page_addr) 1842 1841 { 1843 - struct nand_chip *chip = mtd->priv; 1844 - struct atmel_nand_host *host = chip->priv; 1842 + struct nand_chip *chip = mtd_to_nand(mtd); 1843 + struct atmel_nand_host *host = nand_get_controller_data(chip); 1845 1844 unsigned long timeout; 1846 1845 unsigned int nfc_addr_cmd = 0; 1847 1846 ··· 1967 1966 { 1968 1967 int cfg, len; 1969 1968 int status = 0; 1970 - struct atmel_nand_host *host = chip->priv; 1969 + struct atmel_nand_host *host = nand_get_controller_data(chip); 1971 1970 void *sram = host->nfc->sram_bank0 + nfc_get_sram_off(host); 1972 1971 1973 1972 /* Subpage write is not supported */ ··· 2027 2026 2028 2027 static int nfc_sram_init(struct mtd_info *mtd) 2029 2028 { 2030 - struct nand_chip *chip = mtd->priv; 2031 - struct atmel_nand_host *host = chip->priv; 2029 + struct nand_chip *chip = mtd_to_nand(mtd); 2030 + struct atmel_nand_host *host = nand_get_controller_data(chip); 2032 2031 int res = 0; 2033 2032 2034 2033 /* Initialize the NFC CFG register */ ··· 2094 2093 struct mtd_info *mtd; 2095 2094 struct nand_chip *nand_chip; 2096 2095 struct resource *mem; 2097 - struct mtd_part_parser_data ppdata = {}; 2098 2096 int res, irq; 2099 2097 2100 2098 /* Allocate memory for the device structure (and zero it) */ ··· 2113 2113 } 2114 2114 host->io_phys = (dma_addr_t)mem->start; 2115 2115 2116 - mtd = &host->mtd; 2117 2116 nand_chip = &host->nand_chip; 2117 + mtd = nand_to_mtd(nand_chip); 2118 2118 host->dev = &pdev->dev; 2119 2119 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { 2120 + nand_set_flash_node(nand_chip, pdev->dev.of_node); 2120 2121 /* Only when CONFIG_OF is enabled of_node can be parsed */ 2121 2122 res = atmel_of_init_port(host, pdev->dev.of_node); 2122 2123 if (res) ··· 2127 2126 sizeof(struct atmel_nand_data)); 2128 2127 } 2129 2128 2130 - nand_chip->priv = host; /* link the private data structures */ 2131 - mtd->priv = nand_chip; 2129 + /* link the private data structures */ 2130 + nand_set_controller_data(nand_chip, host); 2132 2131 mtd->dev.parent = &pdev->dev; 2133 2132 2134 2133 /* Set address of NAND IO lines */ ··· 2260 2259 } 2261 2260 2262 2261 mtd->name = "atmel_nand"; 2263 - ppdata.of_node = pdev->dev.of_node; 2264 - res = mtd_device_parse_register(mtd, NULL, &ppdata, 2265 - host->board.parts, host->board.num_parts); 2262 + res = mtd_device_register(mtd, host->board.parts, 2263 + host->board.num_parts); 2266 2264 if (!res) 2267 2265 return res; 2268 2266 ··· 2284 2284 static int atmel_nand_remove(struct platform_device *pdev) 2285 2285 { 2286 2286 struct atmel_nand_host *host = platform_get_drvdata(pdev); 2287 - struct mtd_info *mtd = &host->mtd; 2287 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 2288 2288 2289 2289 nand_release(mtd); 2290 2290 ··· 2304 2304 return 0; 2305 2305 } 2306 2306 2307 - static struct atmel_nand_caps at91rm9200_caps = { 2307 + static const struct atmel_nand_caps at91rm9200_caps = { 2308 2308 .pmecc_correct_erase_page = false, 2309 2309 }; 2310 2310 2311 - static struct atmel_nand_caps sama5d4_caps = { 2311 + static const struct atmel_nand_caps sama5d4_caps = { 2312 2312 .pmecc_correct_erase_page = true, 2313 2313 }; 2314 2314
+21 -19
drivers/mtd/nand/au1550nd.c
··· 23 23 24 24 25 25 struct au1550nd_ctx { 26 - struct mtd_info info; 27 26 struct nand_chip chip; 28 27 29 28 int cs; ··· 38 39 */ 39 40 static u_char au_read_byte(struct mtd_info *mtd) 40 41 { 41 - struct nand_chip *this = mtd->priv; 42 + struct nand_chip *this = mtd_to_nand(mtd); 42 43 u_char ret = readb(this->IO_ADDR_R); 43 44 wmb(); /* drain writebuffer */ 44 45 return ret; ··· 53 54 */ 54 55 static void au_write_byte(struct mtd_info *mtd, u_char byte) 55 56 { 56 - struct nand_chip *this = mtd->priv; 57 + struct nand_chip *this = mtd_to_nand(mtd); 57 58 writeb(byte, this->IO_ADDR_W); 58 59 wmb(); /* drain writebuffer */ 59 60 } ··· 66 67 */ 67 68 static u_char au_read_byte16(struct mtd_info *mtd) 68 69 { 69 - struct nand_chip *this = mtd->priv; 70 + struct nand_chip *this = mtd_to_nand(mtd); 70 71 u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R)); 71 72 wmb(); /* drain writebuffer */ 72 73 return ret; ··· 81 82 */ 82 83 static void au_write_byte16(struct mtd_info *mtd, u_char byte) 83 84 { 84 - struct nand_chip *this = mtd->priv; 85 + struct nand_chip *this = mtd_to_nand(mtd); 85 86 writew(le16_to_cpu((u16) byte), this->IO_ADDR_W); 86 87 wmb(); /* drain writebuffer */ 87 88 } ··· 94 95 */ 95 96 static u16 au_read_word(struct mtd_info *mtd) 96 97 { 97 - struct nand_chip *this = mtd->priv; 98 + struct nand_chip *this = mtd_to_nand(mtd); 98 99 u16 ret = readw(this->IO_ADDR_R); 99 100 wmb(); /* drain writebuffer */ 100 101 return ret; ··· 111 112 static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 112 113 { 113 114 int i; 114 - struct nand_chip *this = mtd->priv; 115 + struct nand_chip *this = mtd_to_nand(mtd); 115 116 116 117 for (i = 0; i < len; i++) { 117 118 writeb(buf[i], this->IO_ADDR_W); ··· 130 131 static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len) 131 132 { 132 133 int i; 133 - struct nand_chip *this = mtd->priv; 134 + struct nand_chip *this = mtd_to_nand(mtd); 134 135 135 136 for (i = 0; i < len; i++) { 136 137 buf[i] = readb(this->IO_ADDR_R); ··· 149 150 static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) 150 151 { 151 152 int i; 152 - struct nand_chip *this = mtd->priv; 153 + struct nand_chip *this = mtd_to_nand(mtd); 153 154 u16 *p = (u16 *) buf; 154 155 len >>= 1; 155 156 ··· 171 172 static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len) 172 173 { 173 174 int i; 174 - struct nand_chip *this = mtd->priv; 175 + struct nand_chip *this = mtd_to_nand(mtd); 175 176 u16 *p = (u16 *) buf; 176 177 len >>= 1; 177 178 ··· 196 197 197 198 static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) 198 199 { 199 - struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info); 200 - struct nand_chip *this = mtd->priv; 200 + struct nand_chip *this = mtd_to_nand(mtd); 201 + struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx, 202 + chip); 201 203 202 204 switch (cmd) { 203 205 ··· 267 267 */ 268 268 static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) 269 269 { 270 - struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info); 271 - struct nand_chip *this = mtd->priv; 270 + struct nand_chip *this = mtd_to_nand(mtd); 271 + struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx, 272 + chip); 272 273 int ce_override = 0, i; 273 274 unsigned long flags = 0; 274 275 ··· 406 405 struct au1550nd_platdata *pd; 407 406 struct au1550nd_ctx *ctx; 408 407 struct nand_chip *this; 408 + struct mtd_info *mtd; 409 409 struct resource *r; 410 410 int ret, cs; 411 411 ··· 440 438 } 441 439 442 440 this = &ctx->chip; 443 - ctx->info.priv = this; 444 - ctx->info.dev.parent = &pdev->dev; 441 + mtd = nand_to_mtd(this); 442 + mtd->dev.parent = &pdev->dev; 445 443 446 444 /* figure out which CS# r->start belongs to */ 447 445 cs = find_nand_cs(r->start); ··· 469 467 this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf; 470 468 this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf; 471 469 472 - ret = nand_scan(&ctx->info, 1); 470 + ret = nand_scan(mtd, 1); 473 471 if (ret) { 474 472 dev_err(&pdev->dev, "NAND scan failed with %d\n", ret); 475 473 goto out3; 476 474 } 477 475 478 - mtd_device_register(&ctx->info, pd->parts, pd->num_parts); 476 + mtd_device_register(mtd, pd->parts, pd->num_parts); 479 477 480 478 platform_set_drvdata(pdev, ctx); 481 479 ··· 495 493 struct au1550nd_ctx *ctx = platform_get_drvdata(pdev); 496 494 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 497 495 498 - nand_release(&ctx->info); 496 + nand_release(nand_to_mtd(&ctx->chip)); 499 497 iounmap(ctx->base); 500 498 release_mem_region(r->start, 0x1000); 501 499 kfree(ctx);
-1
drivers/mtd/nand/bcm47xxnflash/bcm47xxnflash.h
··· 12 12 struct bcma_drv_cc *cc; 13 13 14 14 struct nand_chip nand_chip; 15 - struct mtd_info mtd; 16 15 17 16 unsigned curr_command; 18 17 int curr_page_addr;
+9 -7
drivers/mtd/nand/bcm47xxnflash/main.c
··· 27 27 { 28 28 struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev); 29 29 struct bcm47xxnflash *b47n; 30 + struct mtd_info *mtd; 30 31 int err = 0; 31 32 32 33 b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL); 33 34 if (!b47n) 34 35 return -ENOMEM; 35 36 36 - b47n->nand_chip.priv = b47n; 37 - b47n->mtd.dev.parent = &pdev->dev; 38 - b47n->mtd.priv = &b47n->nand_chip; /* Required */ 37 + nand_set_controller_data(&b47n->nand_chip, b47n); 38 + mtd = nand_to_mtd(&b47n->nand_chip); 39 + mtd->dev.parent = &pdev->dev; 39 40 b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash); 40 41 41 42 if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) { ··· 50 49 return err; 51 50 } 52 51 53 - err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0); 52 + platform_set_drvdata(pdev, b47n); 53 + 54 + err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0); 54 55 if (err) { 55 56 pr_err("Failed to register MTD device: %d\n", err); 56 57 return err; ··· 63 60 64 61 static int bcm47xxnflash_remove(struct platform_device *pdev) 65 62 { 66 - struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev); 63 + struct bcm47xxnflash *nflash = platform_get_drvdata(pdev); 67 64 68 - if (nflash->mtd) 69 - mtd_device_unregister(nflash->mtd); 65 + nand_release(nand_to_mtd(&nflash->nand_chip)); 70 66 71 67 return 0; 72 68 }
+17 -17
drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
··· 89 89 static void bcm47xxnflash_ops_bcm4706_read(struct mtd_info *mtd, uint8_t *buf, 90 90 int len) 91 91 { 92 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 93 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 92 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 93 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 94 94 95 95 u32 ctlcode; 96 96 u32 *dest = (u32 *)buf; ··· 139 139 static void bcm47xxnflash_ops_bcm4706_write(struct mtd_info *mtd, 140 140 const uint8_t *buf, int len) 141 141 { 142 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 143 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 142 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 143 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 144 144 struct bcma_drv_cc *cc = b47n->cc; 145 145 146 146 u32 ctlcode; ··· 173 173 static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct mtd_info *mtd, int cmd, 174 174 unsigned int ctrl) 175 175 { 176 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 177 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 176 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 177 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 178 178 u32 code = 0; 179 179 180 180 if (cmd == NAND_CMD_NONE) ··· 199 199 200 200 static int bcm47xxnflash_ops_bcm4706_dev_ready(struct mtd_info *mtd) 201 201 { 202 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 203 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 202 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 203 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 204 204 205 205 return !!(bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_CTL) & NCTL_READY); 206 206 } ··· 216 216 unsigned command, int column, 217 217 int page_addr) 218 218 { 219 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 220 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 219 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 220 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 221 221 struct bcma_drv_cc *cc = b47n->cc; 222 222 u32 ctlcode; 223 223 int i; ··· 312 312 313 313 static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct mtd_info *mtd) 314 314 { 315 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 316 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 315 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 316 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 317 317 struct bcma_drv_cc *cc = b47n->cc; 318 318 u32 tmp = 0; 319 319 ··· 341 341 static void bcm47xxnflash_ops_bcm4706_read_buf(struct mtd_info *mtd, 342 342 uint8_t *buf, int len) 343 343 { 344 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 345 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 344 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 345 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 346 346 347 347 switch (b47n->curr_command) { 348 348 case NAND_CMD_READ0: ··· 357 357 static void bcm47xxnflash_ops_bcm4706_write_buf(struct mtd_info *mtd, 358 358 const uint8_t *buf, int len) 359 359 { 360 - struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv; 361 - struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv; 360 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 361 + struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); 362 362 363 363 switch (b47n->curr_command) { 364 364 case NAND_CMD_SEQIN: ··· 421 421 (w4 << 24 | w3 << 18 | w2 << 12 | w1 << 6 | w0)); 422 422 423 423 /* Scan NAND */ 424 - err = nand_scan(&b47n->mtd, 1); 424 + err = nand_scan(nand_to_mtd(&b47n->nand_chip), 1); 425 425 if (err) { 426 426 pr_err("Could not scan NAND flash: %d\n", err); 427 427 goto exit;
+26 -19
drivers/mtd/nand/bf5xx_nand.c
··· 142 142 struct bf5xx_nand_info { 143 143 /* mtd info */ 144 144 struct nand_hw_control controller; 145 - struct mtd_info mtd; 146 145 struct nand_chip chip; 147 146 148 147 /* platform info */ ··· 159 160 */ 160 161 static struct bf5xx_nand_info *mtd_to_nand_info(struct mtd_info *mtd) 161 162 { 162 - return container_of(mtd, struct bf5xx_nand_info, mtd); 163 + return container_of(mtd_to_nand(mtd), struct bf5xx_nand_info, 164 + chip); 163 165 } 164 166 165 167 static struct bf5xx_nand_info *to_nand_info(struct platform_device *pdev) ··· 252 252 */ 253 253 if (hweight32(syndrome[0]) == 1) { 254 254 dev_err(info->device, "ECC data was incorrect!\n"); 255 - return 1; 255 + return -EBADMSG; 256 256 } 257 257 258 258 syndrome[1] = (calced & 0x7FF) ^ (stored & 0x7FF); ··· 285 285 data = data ^ (0x1 << failing_bit); 286 286 *(dat + failing_byte) = data; 287 287 288 - return 0; 288 + return 1; 289 289 } 290 290 291 291 /* ··· 298 298 dev_err(info->device, 299 299 "Please discard data, mark bad block\n"); 300 300 301 - return 1; 301 + return -EBADMSG; 302 302 } 303 303 304 304 static int bf5xx_nand_correct_data(struct mtd_info *mtd, u_char *dat, 305 305 u_char *read_ecc, u_char *calc_ecc) 306 306 { 307 - struct nand_chip *chip = mtd->priv; 308 - int ret; 307 + struct nand_chip *chip = mtd_to_nand(mtd); 308 + int ret, bitflips = 0; 309 309 310 310 ret = bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc); 311 + if (ret < 0) 312 + return ret; 313 + 314 + bitflips = ret; 311 315 312 316 /* If ecc size is 512, correct second 256 bytes */ 313 317 if (chip->ecc.size == 512) { 314 318 dat += 256; 315 319 read_ecc += 3; 316 320 calc_ecc += 3; 317 - ret |= bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc); 321 + ret = bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc); 322 + if (ret < 0) 323 + return ret; 324 + 325 + bitflips += ret; 318 326 } 319 327 320 - return ret; 328 + return bitflips; 321 329 } 322 330 323 331 static void bf5xx_nand_enable_hwecc(struct mtd_info *mtd, int mode) ··· 337 329 const u_char *dat, u_char *ecc_code) 338 330 { 339 331 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 340 - struct nand_chip *chip = mtd->priv; 332 + struct nand_chip *chip = mtd_to_nand(mtd); 341 333 u16 ecc0, ecc1; 342 334 u32 code[2]; 343 335 u8 *p; ··· 474 466 uint8_t *buf, int is_read) 475 467 { 476 468 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 477 - struct nand_chip *chip = mtd->priv; 469 + struct nand_chip *chip = mtd_to_nand(mtd); 478 470 unsigned short val; 479 471 480 472 dev_dbg(info->device, " mtd->%p, buf->%p, is_read %d\n", ··· 540 532 uint8_t *buf, int len) 541 533 { 542 534 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 543 - struct nand_chip *chip = mtd->priv; 535 + struct nand_chip *chip = mtd_to_nand(mtd); 544 536 545 537 dev_dbg(info->device, "mtd->%p, buf->%p, int %d\n", mtd, buf, len); 546 538 ··· 554 546 const uint8_t *buf, int len) 555 547 { 556 548 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 557 - struct nand_chip *chip = mtd->priv; 549 + struct nand_chip *chip = mtd_to_nand(mtd); 558 550 559 551 dev_dbg(info->device, "mtd->%p, buf->%p, len %d\n", mtd, buf, len); 560 552 ··· 668 660 */ 669 661 static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info) 670 662 { 671 - struct mtd_info *mtd = &info->mtd; 663 + struct mtd_info *mtd = nand_to_mtd(&info->chip); 672 664 struct mtd_partition *parts = info->platform->partitions; 673 665 int nr = info->platform->nr_partitions; 674 666 ··· 683 675 * and their partitions, then go through freeing the 684 676 * resources used 685 677 */ 686 - nand_release(&info->mtd); 678 + nand_release(nand_to_mtd(&info->chip)); 687 679 688 680 peripheral_free_list(bfin_nfc_pin_req); 689 681 bf5xx_nand_dma_remove(info); ··· 693 685 694 686 static int bf5xx_nand_scan(struct mtd_info *mtd) 695 687 { 696 - struct nand_chip *chip = mtd->priv; 688 + struct nand_chip *chip = mtd_to_nand(mtd); 697 689 int ret; 698 690 699 691 ret = nand_scan_ident(mtd, 1, NULL); ··· 764 756 765 757 /* initialise chip data struct */ 766 758 chip = &info->chip; 759 + mtd = nand_to_mtd(&info->chip); 767 760 768 761 if (plat->data_width) 769 762 chip->options |= NAND_BUSWIDTH_16; ··· 781 772 chip->cmd_ctrl = bf5xx_nand_hwcontrol; 782 773 chip->dev_ready = bf5xx_nand_devready; 783 774 784 - chip->priv = &info->mtd; 775 + nand_set_controller_data(chip, mtd); 785 776 chip->controller = &info->controller; 786 777 787 778 chip->IO_ADDR_R = (void __iomem *) NFC_READ; ··· 790 781 chip->chip_delay = 0; 791 782 792 783 /* initialise mtd info data struct */ 793 - mtd = &info->mtd; 794 - mtd->priv = chip; 795 784 mtd->dev.parent = &pdev->dev; 796 785 797 786 /* initialise the hardware */
+1
drivers/mtd/nand/brcmnand/Makefile
··· 2 2 # more specific iproc_nand.o, for instance 3 3 obj-$(CONFIG_MTD_NAND_BRCMNAND) += iproc_nand.o 4 4 obj-$(CONFIG_MTD_NAND_BRCMNAND) += bcm63138_nand.o 5 + obj-$(CONFIG_MTD_NAND_BRCMNAND) += bcm6368_nand.o 5 6 obj-$(CONFIG_MTD_NAND_BRCMNAND) += brcmstb_nand.o 6 7 obj-$(CONFIG_MTD_NAND_BRCMNAND) += brcmnand.o
+142
drivers/mtd/nand/brcmnand/bcm6368_nand.c
··· 1 + /* 2 + * Copyright 2015 Simon Arlott 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * Derived from bcm63138_nand.c: 14 + * Copyright © 2015 Broadcom Corporation 15 + * 16 + * Derived from bcm963xx_4.12L.06B_consumer/shared/opensource/include/bcm963xx/63268_map_part.h: 17 + * Copyright 2000-2010 Broadcom Corporation 18 + * 19 + * Derived from bcm963xx_4.12L.06B_consumer/shared/opensource/flash/nandflash.c: 20 + * Copyright 2000-2010 Broadcom Corporation 21 + */ 22 + 23 + #include <linux/device.h> 24 + #include <linux/io.h> 25 + #include <linux/ioport.h> 26 + #include <linux/module.h> 27 + #include <linux/of.h> 28 + #include <linux/of_address.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/slab.h> 31 + 32 + #include "brcmnand.h" 33 + 34 + struct bcm6368_nand_soc { 35 + struct brcmnand_soc soc; 36 + void __iomem *base; 37 + }; 38 + 39 + #define BCM6368_NAND_INT 0x00 40 + #define BCM6368_NAND_STATUS_SHIFT 0 41 + #define BCM6368_NAND_STATUS_MASK (0xfff << BCM6368_NAND_STATUS_SHIFT) 42 + #define BCM6368_NAND_ENABLE_SHIFT 16 43 + #define BCM6368_NAND_ENABLE_MASK (0xffff << BCM6368_NAND_ENABLE_SHIFT) 44 + #define BCM6368_NAND_BASE_ADDR0 0x04 45 + #define BCM6368_NAND_BASE_ADDR1 0x0c 46 + 47 + enum { 48 + BCM6368_NP_READ = BIT(0), 49 + BCM6368_BLOCK_ERASE = BIT(1), 50 + BCM6368_COPY_BACK = BIT(2), 51 + BCM6368_PAGE_PGM = BIT(3), 52 + BCM6368_CTRL_READY = BIT(4), 53 + BCM6368_DEV_RBPIN = BIT(5), 54 + BCM6368_ECC_ERR_UNC = BIT(6), 55 + BCM6368_ECC_ERR_CORR = BIT(7), 56 + }; 57 + 58 + static bool bcm6368_nand_intc_ack(struct brcmnand_soc *soc) 59 + { 60 + struct bcm6368_nand_soc *priv = 61 + container_of(soc, struct bcm6368_nand_soc, soc); 62 + void __iomem *mmio = priv->base + BCM6368_NAND_INT; 63 + u32 val = brcmnand_readl(mmio); 64 + 65 + if (val & (BCM6368_CTRL_READY << BCM6368_NAND_STATUS_SHIFT)) { 66 + /* Ack interrupt */ 67 + val &= ~BCM6368_NAND_STATUS_MASK; 68 + val |= BCM6368_CTRL_READY << BCM6368_NAND_STATUS_SHIFT; 69 + brcmnand_writel(val, mmio); 70 + return true; 71 + } 72 + 73 + return false; 74 + } 75 + 76 + static void bcm6368_nand_intc_set(struct brcmnand_soc *soc, bool en) 77 + { 78 + struct bcm6368_nand_soc *priv = 79 + container_of(soc, struct bcm6368_nand_soc, soc); 80 + void __iomem *mmio = priv->base + BCM6368_NAND_INT; 81 + u32 val = brcmnand_readl(mmio); 82 + 83 + /* Don't ack any interrupts */ 84 + val &= ~BCM6368_NAND_STATUS_MASK; 85 + 86 + if (en) 87 + val |= BCM6368_CTRL_READY << BCM6368_NAND_ENABLE_SHIFT; 88 + else 89 + val &= ~(BCM6368_CTRL_READY << BCM6368_NAND_ENABLE_SHIFT); 90 + 91 + brcmnand_writel(val, mmio); 92 + } 93 + 94 + static int bcm6368_nand_probe(struct platform_device *pdev) 95 + { 96 + struct device *dev = &pdev->dev; 97 + struct bcm6368_nand_soc *priv; 98 + struct brcmnand_soc *soc; 99 + struct resource *res; 100 + 101 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 102 + if (!priv) 103 + return -ENOMEM; 104 + soc = &priv->soc; 105 + 106 + res = platform_get_resource_byname(pdev, 107 + IORESOURCE_MEM, "nand-int-base"); 108 + priv->base = devm_ioremap_resource(dev, res); 109 + if (IS_ERR(priv->base)) 110 + return PTR_ERR(priv->base); 111 + 112 + soc->ctlrdy_ack = bcm6368_nand_intc_ack; 113 + soc->ctlrdy_set_enabled = bcm6368_nand_intc_set; 114 + 115 + /* Disable and ack all interrupts */ 116 + brcmnand_writel(0, priv->base + BCM6368_NAND_INT); 117 + brcmnand_writel(BCM6368_NAND_STATUS_MASK, 118 + priv->base + BCM6368_NAND_INT); 119 + 120 + return brcmnand_probe(pdev, soc); 121 + } 122 + 123 + static const struct of_device_id bcm6368_nand_of_match[] = { 124 + { .compatible = "brcm,nand-bcm6368" }, 125 + {}, 126 + }; 127 + MODULE_DEVICE_TABLE(of, bcm6368_nand_of_match); 128 + 129 + static struct platform_driver bcm6368_nand_driver = { 130 + .probe = bcm6368_nand_probe, 131 + .remove = brcmnand_remove, 132 + .driver = { 133 + .name = "bcm6368_nand", 134 + .pm = &brcmnand_pm_ops, 135 + .of_match_table = bcm6368_nand_of_match, 136 + } 137 + }; 138 + module_platform_driver(bcm6368_nand_driver); 139 + 140 + MODULE_LICENSE("GPL"); 141 + MODULE_AUTHOR("Simon Arlott"); 142 + MODULE_DESCRIPTION("NAND driver for BCM6368");
+98 -68
drivers/mtd/nand/brcmnand/brcmnand.c
··· 11 11 * GNU General Public License for more details. 12 12 */ 13 13 14 + #include <linux/clk.h> 14 15 #include <linux/version.h> 15 16 #include <linux/module.h> 16 17 #include <linux/init.h> ··· 123 122 /* Some SoCs provide custom interrupt status register(s) */ 124 123 struct brcmnand_soc *soc; 125 124 125 + /* Some SoCs have a gateable clock for the controller */ 126 + struct clk *clk; 127 + 126 128 int cmd_pending; 127 129 bool dma_pending; 128 130 struct completion done; ··· 138 134 dma_addr_t dma_pa; 139 135 140 136 /* in-memory cache of the FLASH_CACHE, used only for some commands */ 141 - u32 flash_cache[FC_WORDS]; 137 + u8 flash_cache[FC_BYTES]; 142 138 143 139 /* Controller revision details */ 144 140 const u16 *reg_offsets; ··· 180 176 181 177 struct brcmnand_host { 182 178 struct list_head node; 183 - struct device_node *of_node; 184 179 185 180 struct nand_chip chip; 186 - struct mtd_info mtd; 187 181 struct platform_device *pdev; 188 182 int cs; 189 183 ··· 876 874 877 875 static void brcmnand_wp(struct mtd_info *mtd, int wp) 878 876 { 879 - struct nand_chip *chip = mtd->priv; 880 - struct brcmnand_host *host = chip->priv; 877 + struct nand_chip *chip = mtd_to_nand(mtd); 878 + struct brcmnand_host *host = nand_get_controller_data(chip); 881 879 struct brcmnand_controller *ctrl = host->ctrl; 882 880 883 881 if ((ctrl->features & BRCMNAND_HAS_WP) && wp_on == 1) { ··· 1042 1040 1043 1041 static int brcmnand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) 1044 1042 { 1045 - struct nand_chip *chip = mtd->priv; 1046 - struct brcmnand_host *host = chip->priv; 1043 + struct nand_chip *chip = mtd_to_nand(mtd); 1044 + struct brcmnand_host *host = nand_get_controller_data(chip); 1047 1045 struct brcmnand_controller *ctrl = host->ctrl; 1048 1046 unsigned long timeo = msecs_to_jiffies(100); 1049 1047 ··· 1077 1075 enum brcmnand_llop_type type, u32 data, 1078 1076 bool last_op) 1079 1077 { 1080 - struct mtd_info *mtd = &host->mtd; 1078 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 1081 1079 struct nand_chip *chip = &host->chip; 1082 1080 struct brcmnand_controller *ctrl = host->ctrl; 1083 1081 u32 tmp; ··· 1116 1114 static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command, 1117 1115 int column, int page_addr) 1118 1116 { 1119 - struct nand_chip *chip = mtd->priv; 1120 - struct brcmnand_host *host = chip->priv; 1117 + struct nand_chip *chip = mtd_to_nand(mtd); 1118 + struct brcmnand_host *host = nand_get_controller_data(chip); 1121 1119 struct brcmnand_controller *ctrl = host->ctrl; 1122 1120 u64 addr = (u64)page_addr << chip->page_shift; 1123 1121 int native_cmd = 0; ··· 1190 1188 1191 1189 if (native_cmd == CMD_PARAMETER_READ || 1192 1190 native_cmd == CMD_PARAMETER_CHANGE_COL) { 1191 + /* Copy flash cache word-wise */ 1192 + u32 *flash_cache = (u32 *)ctrl->flash_cache; 1193 1193 int i; 1194 1194 1195 1195 brcmnand_soc_data_bus_prepare(ctrl->soc); ··· 1201 1197 * SECTOR_SIZE_1K may invalidate it 1202 1198 */ 1203 1199 for (i = 0; i < FC_WORDS; i++) 1204 - ctrl->flash_cache[i] = brcmnand_read_fc(ctrl, i); 1200 + /* 1201 + * Flash cache is big endian for parameter pages, at 1202 + * least on STB SoCs 1203 + */ 1204 + flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i)); 1205 1205 1206 1206 brcmnand_soc_data_bus_unprepare(ctrl->soc); 1207 1207 ··· 1222 1214 1223 1215 static uint8_t brcmnand_read_byte(struct mtd_info *mtd) 1224 1216 { 1225 - struct nand_chip *chip = mtd->priv; 1226 - struct brcmnand_host *host = chip->priv; 1217 + struct nand_chip *chip = mtd_to_nand(mtd); 1218 + struct brcmnand_host *host = nand_get_controller_data(chip); 1227 1219 struct brcmnand_controller *ctrl = host->ctrl; 1228 1220 uint8_t ret = 0; 1229 1221 int addr, offs; ··· 1258 1250 if (host->last_byte > 0 && offs == 0) 1259 1251 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, addr, -1); 1260 1252 1261 - ret = ctrl->flash_cache[offs >> 2] >> 1262 - (24 - ((offs & 0x03) << 3)); 1253 + ret = ctrl->flash_cache[offs]; 1263 1254 break; 1264 1255 case NAND_CMD_GET_FEATURES: 1265 1256 if (host->last_byte >= ONFI_SUBFEATURE_PARAM_LEN) { ··· 1289 1282 int len) 1290 1283 { 1291 1284 int i; 1292 - struct nand_chip *chip = mtd->priv; 1293 - struct brcmnand_host *host = chip->priv; 1285 + struct nand_chip *chip = mtd_to_nand(mtd); 1286 + struct brcmnand_host *host = nand_get_controller_data(chip); 1294 1287 1295 1288 switch (host->last_cmd) { 1296 1289 case NAND_CMD_SET_FEATURES: ··· 1400 1393 u64 addr, unsigned int trans, u32 *buf, 1401 1394 u8 *oob, u64 *err_addr) 1402 1395 { 1403 - struct brcmnand_host *host = chip->priv; 1396 + struct brcmnand_host *host = nand_get_controller_data(chip); 1404 1397 struct brcmnand_controller *ctrl = host->ctrl; 1405 1398 int i, j, ret = 0; 1406 1399 1407 1400 /* Clear error addresses */ 1408 1401 brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0); 1409 1402 brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0); 1403 + brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0); 1404 + brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0); 1410 1405 1411 1406 brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, 1412 1407 (host->cs << 16) | ((addr >> 32) & 0xffff)); ··· 1463 1454 static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, 1464 1455 u64 addr, unsigned int trans, u32 *buf, u8 *oob) 1465 1456 { 1466 - struct brcmnand_host *host = chip->priv; 1457 + struct brcmnand_host *host = nand_get_controller_data(chip); 1467 1458 struct brcmnand_controller *ctrl = host->ctrl; 1468 1459 u64 err_addr = 0; 1469 1460 int err; ··· 1513 1504 static int brcmnand_read_page(struct mtd_info *mtd, struct nand_chip *chip, 1514 1505 uint8_t *buf, int oob_required, int page) 1515 1506 { 1516 - struct brcmnand_host *host = chip->priv; 1507 + struct brcmnand_host *host = nand_get_controller_data(chip); 1517 1508 u8 *oob = oob_required ? (u8 *)chip->oob_poi : NULL; 1518 1509 1519 1510 return brcmnand_read(mtd, chip, host->last_addr, ··· 1523 1514 static int brcmnand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1524 1515 uint8_t *buf, int oob_required, int page) 1525 1516 { 1526 - struct brcmnand_host *host = chip->priv; 1517 + struct brcmnand_host *host = nand_get_controller_data(chip); 1527 1518 u8 *oob = oob_required ? (u8 *)chip->oob_poi : NULL; 1528 1519 int ret; 1529 1520 ··· 1545 1536 static int brcmnand_read_oob_raw(struct mtd_info *mtd, struct nand_chip *chip, 1546 1537 int page) 1547 1538 { 1548 - struct brcmnand_host *host = chip->priv; 1539 + struct brcmnand_host *host = nand_get_controller_data(chip); 1549 1540 1550 1541 brcmnand_set_ecc_enabled(host, 0); 1551 1542 brcmnand_read(mtd, chip, (u64)page << chip->page_shift, ··· 1555 1546 return 0; 1556 1547 } 1557 1548 1558 - static int brcmnand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, 1559 - uint32_t data_offs, uint32_t readlen, 1560 - uint8_t *bufpoi, int page) 1561 - { 1562 - struct brcmnand_host *host = chip->priv; 1563 - 1564 - return brcmnand_read(mtd, chip, host->last_addr + data_offs, 1565 - readlen >> FC_SHIFT, (u32 *)bufpoi, NULL); 1566 - } 1567 - 1568 1549 static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip, 1569 1550 u64 addr, const u32 *buf, u8 *oob) 1570 1551 { 1571 - struct brcmnand_host *host = chip->priv; 1552 + struct brcmnand_host *host = nand_get_controller_data(chip); 1572 1553 struct brcmnand_controller *ctrl = host->ctrl; 1573 1554 unsigned int i, j, trans = mtd->writesize >> FC_SHIFT; 1574 1555 int status, ret = 0; ··· 1629 1630 static int brcmnand_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1630 1631 const uint8_t *buf, int oob_required, int page) 1631 1632 { 1632 - struct brcmnand_host *host = chip->priv; 1633 + struct brcmnand_host *host = nand_get_controller_data(chip); 1633 1634 void *oob = oob_required ? chip->oob_poi : NULL; 1634 1635 1635 1636 brcmnand_write(mtd, chip, host->last_addr, (const u32 *)buf, oob); ··· 1640 1641 struct nand_chip *chip, const uint8_t *buf, 1641 1642 int oob_required, int page) 1642 1643 { 1643 - struct brcmnand_host *host = chip->priv; 1644 + struct brcmnand_host *host = nand_get_controller_data(chip); 1644 1645 void *oob = oob_required ? chip->oob_poi : NULL; 1645 1646 1646 1647 brcmnand_set_ecc_enabled(host, 0); ··· 1659 1660 static int brcmnand_write_oob_raw(struct mtd_info *mtd, struct nand_chip *chip, 1660 1661 int page) 1661 1662 { 1662 - struct brcmnand_host *host = chip->priv; 1663 + struct brcmnand_host *host = nand_get_controller_data(chip); 1663 1664 int ret; 1664 1665 1665 1666 brcmnand_set_ecc_enabled(host, 0); ··· 1805 1806 1806 1807 static int brcmnand_setup_dev(struct brcmnand_host *host) 1807 1808 { 1808 - struct mtd_info *mtd = &host->mtd; 1809 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 1809 1810 struct nand_chip *chip = &host->chip; 1810 1811 struct brcmnand_controller *ctrl = host->ctrl; 1811 1812 struct brcmnand_cfg *cfg = &host->hwcfg; ··· 1815 1816 1816 1817 memset(cfg, 0, sizeof(*cfg)); 1817 1818 1818 - ret = of_property_read_u32(chip->flash_node, 1819 + ret = of_property_read_u32(nand_get_flash_node(chip), 1819 1820 "brcm,nand-oob-sector-size", 1820 1821 &oob_sector); 1821 1822 if (ret) { ··· 1904 1905 return 0; 1905 1906 } 1906 1907 1907 - static int brcmnand_init_cs(struct brcmnand_host *host) 1908 + static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn) 1908 1909 { 1909 1910 struct brcmnand_controller *ctrl = host->ctrl; 1910 - struct device_node *dn = host->of_node; 1911 1911 struct platform_device *pdev = host->pdev; 1912 1912 struct mtd_info *mtd; 1913 1913 struct nand_chip *chip; 1914 1914 int ret; 1915 1915 u16 cfg_offs; 1916 - struct mtd_part_parser_data ppdata = { .of_node = dn }; 1917 1916 1918 1917 ret = of_property_read_u32(dn, "reg", &host->cs); 1919 1918 if (ret) { ··· 1919 1922 return -ENXIO; 1920 1923 } 1921 1924 1922 - mtd = &host->mtd; 1925 + mtd = nand_to_mtd(&host->chip); 1923 1926 chip = &host->chip; 1924 1927 1925 - chip->flash_node = dn; 1926 - chip->priv = host; 1927 - mtd->priv = chip; 1928 + nand_set_flash_node(chip, dn); 1929 + nand_set_controller_data(chip, host); 1928 1930 mtd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "brcmnand.%d", 1929 1931 host->cs); 1930 1932 mtd->owner = THIS_MODULE; ··· 1941 1945 1942 1946 chip->ecc.mode = NAND_ECC_HW; 1943 1947 chip->ecc.read_page = brcmnand_read_page; 1944 - chip->ecc.read_subpage = brcmnand_read_subpage; 1945 1948 chip->ecc.write_page = brcmnand_write_page; 1946 1949 chip->ecc.read_page_raw = brcmnand_read_page_raw; 1947 1950 chip->ecc.write_page_raw = brcmnand_write_page_raw; ··· 1988 1993 if (nand_scan_tail(mtd)) 1989 1994 return -ENXIO; 1990 1995 1991 - return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 1996 + return mtd_device_register(mtd, NULL, 0); 1992 1997 } 1993 1998 1994 1999 static void brcmnand_save_restore_cs_config(struct brcmnand_host *host, ··· 2062 2067 } 2063 2068 2064 2069 list_for_each_entry(host, &ctrl->host_list, node) { 2065 - struct mtd_info *mtd = &host->mtd; 2066 - struct nand_chip *chip = mtd->priv; 2070 + struct nand_chip *chip = &host->chip; 2071 + struct mtd_info *mtd = nand_to_mtd(chip); 2067 2072 2068 2073 brcmnand_save_restore_cs_config(host, 1); 2069 2074 ··· 2129 2134 if (IS_ERR(ctrl->nand_base)) 2130 2135 return PTR_ERR(ctrl->nand_base); 2131 2136 2137 + /* Enable clock before using NAND registers */ 2138 + ctrl->clk = devm_clk_get(dev, "nand"); 2139 + if (!IS_ERR(ctrl->clk)) { 2140 + ret = clk_prepare_enable(ctrl->clk); 2141 + if (ret) 2142 + return ret; 2143 + } else { 2144 + ret = PTR_ERR(ctrl->clk); 2145 + if (ret == -EPROBE_DEFER) 2146 + return ret; 2147 + 2148 + ctrl->clk = NULL; 2149 + } 2150 + 2132 2151 /* Initialize NAND revision */ 2133 2152 ret = brcmnand_revision_init(ctrl); 2134 2153 if (ret) 2135 - return ret; 2154 + goto err; 2136 2155 2137 2156 /* 2138 2157 * Most chips have this cache at a fixed offset within 'nand' block. ··· 2155 2146 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand-cache"); 2156 2147 if (res) { 2157 2148 ctrl->nand_fc = devm_ioremap_resource(dev, res); 2158 - if (IS_ERR(ctrl->nand_fc)) 2159 - return PTR_ERR(ctrl->nand_fc); 2149 + if (IS_ERR(ctrl->nand_fc)) { 2150 + ret = PTR_ERR(ctrl->nand_fc); 2151 + goto err; 2152 + } 2160 2153 } else { 2161 2154 ctrl->nand_fc = ctrl->nand_base + 2162 2155 ctrl->reg_offsets[BRCMNAND_FC_BASE]; ··· 2168 2157 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "flash-dma"); 2169 2158 if (res) { 2170 2159 ctrl->flash_dma_base = devm_ioremap_resource(dev, res); 2171 - if (IS_ERR(ctrl->flash_dma_base)) 2172 - return PTR_ERR(ctrl->flash_dma_base); 2160 + if (IS_ERR(ctrl->flash_dma_base)) { 2161 + ret = PTR_ERR(ctrl->flash_dma_base); 2162 + goto err; 2163 + } 2173 2164 2174 2165 flash_dma_writel(ctrl, FLASH_DMA_MODE, 1); /* linked-list */ 2175 2166 flash_dma_writel(ctrl, FLASH_DMA_ERROR_STATUS, 0); ··· 2180 2167 ctrl->dma_desc = dmam_alloc_coherent(dev, 2181 2168 sizeof(*ctrl->dma_desc), 2182 2169 &ctrl->dma_pa, GFP_KERNEL); 2183 - if (!ctrl->dma_desc) 2184 - return -ENOMEM; 2170 + if (!ctrl->dma_desc) { 2171 + ret = -ENOMEM; 2172 + goto err; 2173 + } 2185 2174 2186 2175 ctrl->dma_irq = platform_get_irq(pdev, 1); 2187 2176 if ((int)ctrl->dma_irq < 0) { 2188 2177 dev_err(dev, "missing FLASH_DMA IRQ\n"); 2189 - return -ENODEV; 2178 + ret = -ENODEV; 2179 + goto err; 2190 2180 } 2191 2181 2192 2182 ret = devm_request_irq(dev, ctrl->dma_irq, ··· 2198 2182 if (ret < 0) { 2199 2183 dev_err(dev, "can't allocate IRQ %d: error %d\n", 2200 2184 ctrl->dma_irq, ret); 2201 - return ret; 2185 + goto err; 2202 2186 } 2203 2187 2204 2188 dev_info(dev, "enabling FLASH_DMA\n"); ··· 2222 2206 ctrl->irq = platform_get_irq(pdev, 0); 2223 2207 if ((int)ctrl->irq < 0) { 2224 2208 dev_err(dev, "no IRQ defined\n"); 2225 - return -ENODEV; 2209 + ret = -ENODEV; 2210 + goto err; 2226 2211 } 2227 2212 2228 2213 /* ··· 2247 2230 if (ret < 0) { 2248 2231 dev_err(dev, "can't allocate IRQ %d: error %d\n", 2249 2232 ctrl->irq, ret); 2250 - return ret; 2233 + goto err; 2251 2234 } 2252 2235 2253 2236 for_each_available_child_of_node(dn, child) { ··· 2255 2238 struct brcmnand_host *host; 2256 2239 2257 2240 host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); 2258 - if (!host) 2259 - return -ENOMEM; 2241 + if (!host) { 2242 + of_node_put(child); 2243 + ret = -ENOMEM; 2244 + goto err; 2245 + } 2260 2246 host->pdev = pdev; 2261 2247 host->ctrl = ctrl; 2262 - host->of_node = child; 2263 2248 2264 - ret = brcmnand_init_cs(host); 2265 - if (ret) 2249 + ret = brcmnand_init_cs(host, child); 2250 + if (ret) { 2251 + devm_kfree(dev, host); 2266 2252 continue; /* Try all chip-selects */ 2253 + } 2267 2254 2268 2255 list_add_tail(&host->node, &ctrl->host_list); 2269 2256 } 2270 2257 } 2271 2258 2272 2259 /* No chip-selects could initialize properly */ 2273 - if (list_empty(&ctrl->host_list)) 2274 - return -ENODEV; 2260 + if (list_empty(&ctrl->host_list)) { 2261 + ret = -ENODEV; 2262 + goto err; 2263 + } 2275 2264 2276 2265 return 0; 2266 + 2267 + err: 2268 + clk_disable_unprepare(ctrl->clk); 2269 + return ret; 2270 + 2277 2271 } 2278 2272 EXPORT_SYMBOL_GPL(brcmnand_probe); 2279 2273 ··· 2294 2266 struct brcmnand_host *host; 2295 2267 2296 2268 list_for_each_entry(host, &ctrl->host_list, node) 2297 - nand_release(&host->mtd); 2269 + nand_release(nand_to_mtd(&host->chip)); 2270 + 2271 + clk_disable_unprepare(ctrl->clk); 2298 2272 2299 2273 dev_set_drvdata(&pdev->dev, NULL); 2300 2274
+26 -17
drivers/mtd/nand/cafe_nand.c
··· 101 101 102 102 static int cafe_device_ready(struct mtd_info *mtd) 103 103 { 104 - struct cafe_priv *cafe = mtd->priv; 104 + struct nand_chip *chip = mtd_to_nand(mtd); 105 + struct cafe_priv *cafe = nand_get_controller_data(chip); 105 106 int result = !!(cafe_readl(cafe, NAND_STATUS) & 0x40000000); 106 107 uint32_t irqs = cafe_readl(cafe, NAND_IRQ); 107 108 ··· 118 117 119 118 static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 120 119 { 121 - struct cafe_priv *cafe = mtd->priv; 120 + struct nand_chip *chip = mtd_to_nand(mtd); 121 + struct cafe_priv *cafe = nand_get_controller_data(chip); 122 122 123 123 if (usedma) 124 124 memcpy(cafe->dmabuf + cafe->datalen, buf, len); ··· 134 132 135 133 static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 136 134 { 137 - struct cafe_priv *cafe = mtd->priv; 135 + struct nand_chip *chip = mtd_to_nand(mtd); 136 + struct cafe_priv *cafe = nand_get_controller_data(chip); 138 137 139 138 if (usedma) 140 139 memcpy(buf, cafe->dmabuf + cafe->datalen, len); ··· 149 146 150 147 static uint8_t cafe_read_byte(struct mtd_info *mtd) 151 148 { 152 - struct cafe_priv *cafe = mtd->priv; 149 + struct nand_chip *chip = mtd_to_nand(mtd); 150 + struct cafe_priv *cafe = nand_get_controller_data(chip); 153 151 uint8_t d; 154 152 155 153 cafe_read_buf(mtd, &d, 1); ··· 162 158 static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command, 163 159 int column, int page_addr) 164 160 { 165 - struct cafe_priv *cafe = mtd->priv; 161 + struct nand_chip *chip = mtd_to_nand(mtd); 162 + struct cafe_priv *cafe = nand_get_controller_data(chip); 166 163 int adrbytes = 0; 167 164 uint32_t ctl1; 168 165 uint32_t doneint = 0x80000000; ··· 318 313 319 314 static void cafe_select_chip(struct mtd_info *mtd, int chipnr) 320 315 { 321 - struct cafe_priv *cafe = mtd->priv; 316 + struct nand_chip *chip = mtd_to_nand(mtd); 317 + struct cafe_priv *cafe = nand_get_controller_data(chip); 322 318 323 319 cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr); 324 320 ··· 334 328 static irqreturn_t cafe_nand_interrupt(int irq, void *id) 335 329 { 336 330 struct mtd_info *mtd = id; 337 - struct cafe_priv *cafe = mtd->priv; 331 + struct nand_chip *chip = mtd_to_nand(mtd); 332 + struct cafe_priv *cafe = nand_get_controller_data(chip); 338 333 uint32_t irqs = cafe_readl(cafe, NAND_IRQ); 339 334 cafe_writel(cafe, irqs & ~0x90000000, NAND_IRQ); 340 335 if (!irqs) ··· 384 377 static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip, 385 378 uint8_t *buf, int oob_required, int page) 386 379 { 387 - struct cafe_priv *cafe = mtd->priv; 380 + struct cafe_priv *cafe = nand_get_controller_data(chip); 388 381 unsigned int max_bitflips = 0; 389 382 390 383 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n", ··· 526 519 const uint8_t *buf, int oob_required, 527 520 int page) 528 521 { 529 - struct cafe_priv *cafe = mtd->priv; 522 + struct cafe_priv *cafe = nand_get_controller_data(chip); 530 523 531 524 chip->write_buf(mtd, buf, mtd->writesize); 532 525 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); ··· 605 598 606 599 pci_set_master(pdev); 607 600 608 - mtd = kzalloc(sizeof(*mtd) + sizeof(struct cafe_priv), GFP_KERNEL); 609 - if (!mtd) 601 + cafe = kzalloc(sizeof(*cafe), GFP_KERNEL); 602 + if (!cafe) 610 603 return -ENOMEM; 611 - cafe = (void *)(&mtd[1]); 612 604 605 + mtd = nand_to_mtd(&cafe->nand); 613 606 mtd->dev.parent = &pdev->dev; 614 - mtd->priv = cafe; 607 + nand_set_controller_data(&cafe->nand, cafe); 615 608 616 609 cafe->pdev = pdev; 617 610 cafe->mmio = pci_iomap(pdev, 0, 0); ··· 791 784 out_ior: 792 785 pci_iounmap(pdev, cafe->mmio); 793 786 out_free_mtd: 794 - kfree(mtd); 787 + kfree(cafe); 795 788 out: 796 789 return err; 797 790 } ··· 799 792 static void cafe_nand_remove(struct pci_dev *pdev) 800 793 { 801 794 struct mtd_info *mtd = pci_get_drvdata(pdev); 802 - struct cafe_priv *cafe = mtd->priv; 795 + struct nand_chip *chip = mtd_to_nand(mtd); 796 + struct cafe_priv *cafe = nand_get_controller_data(chip); 803 797 804 798 /* Disable NAND IRQ in global IRQ mask register */ 805 799 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK); ··· 812 804 2112 + sizeof(struct nand_buffers) + 813 805 mtd->writesize + mtd->oobsize, 814 806 cafe->dmabuf, cafe->dmaaddr); 815 - kfree(mtd); 807 + kfree(cafe); 816 808 } 817 809 818 810 static const struct pci_device_id cafe_nand_tbl[] = { ··· 827 819 { 828 820 uint32_t ctrl; 829 821 struct mtd_info *mtd = pci_get_drvdata(pdev); 830 - struct cafe_priv *cafe = mtd->priv; 822 + struct nand_chip *chip = mtd_to_nand(mtd); 823 + struct cafe_priv *cafe = nand_get_controller_data(chip); 831 824 832 825 /* Start off by resetting the NAND controller completely */ 833 826 cafe_writel(cafe, 1, NAND_RESET);
+9 -14
drivers/mtd/nand/cmx270_nand.c
··· 53 53 54 54 static u_char cmx270_read_byte(struct mtd_info *mtd) 55 55 { 56 - struct nand_chip *this = mtd->priv; 56 + struct nand_chip *this = mtd_to_nand(mtd); 57 57 58 58 return (readl(this->IO_ADDR_R) >> 16); 59 59 } ··· 61 61 static void cmx270_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 62 62 { 63 63 int i; 64 - struct nand_chip *this = mtd->priv; 64 + struct nand_chip *this = mtd_to_nand(mtd); 65 65 66 66 for (i=0; i<len; i++) 67 67 writel((*buf++ << 16), this->IO_ADDR_W); ··· 70 70 static void cmx270_read_buf(struct mtd_info *mtd, u_char *buf, int len) 71 71 { 72 72 int i; 73 - struct nand_chip *this = mtd->priv; 73 + struct nand_chip *this = mtd_to_nand(mtd); 74 74 75 75 for (i=0; i<len; i++) 76 76 *buf++ = readl(this->IO_ADDR_R) >> 16; ··· 94 94 static void cmx270_hwcontrol(struct mtd_info *mtd, int dat, 95 95 unsigned int ctrl) 96 96 { 97 - struct nand_chip* this = mtd->priv; 97 + struct nand_chip *this = mtd_to_nand(mtd); 98 98 unsigned int nandaddr = (unsigned int)this->IO_ADDR_W; 99 99 100 100 dsb(); ··· 160 160 gpio_direction_input(GPIO_NAND_RB); 161 161 162 162 /* Allocate memory for MTD device structure and private data */ 163 - cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) + 164 - sizeof(struct nand_chip), 165 - GFP_KERNEL); 166 - if (!cmx270_nand_mtd) { 163 + this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 164 + if (!this) { 167 165 ret = -ENOMEM; 168 166 goto err_kzalloc; 169 167 } ··· 173 175 goto err_ioremap; 174 176 } 175 177 176 - /* Get pointer to private data */ 177 - this = (struct nand_chip *)(&cmx270_nand_mtd[1]); 178 + cmx270_nand_mtd = nand_to_mtd(this); 178 179 179 180 /* Link the private data with the MTD structure */ 180 181 cmx270_nand_mtd->owner = THIS_MODULE; 181 - cmx270_nand_mtd->priv = this; 182 182 183 183 /* insert callbacks */ 184 184 this->IO_ADDR_R = cmx270_nand_io; ··· 212 216 err_scan: 213 217 iounmap(cmx270_nand_io); 214 218 err_ioremap: 215 - kfree(cmx270_nand_mtd); 219 + kfree(this); 216 220 err_kzalloc: 217 221 gpio_free(GPIO_NAND_RB); 218 222 err_gpio_request: ··· 236 240 237 241 iounmap(cmx270_nand_io); 238 242 239 - /* Free the MTD device structure */ 240 - kfree (cmx270_nand_mtd); 243 + kfree(mtd_to_nand(cmx270_nand_mtd)); 241 244 } 242 245 module_exit(cmx270_cleanup); 243 246
+16 -18
drivers/mtd/nand/cs553x_nand.c
··· 97 97 98 98 static void cs553x_read_buf(struct mtd_info *mtd, u_char *buf, int len) 99 99 { 100 - struct nand_chip *this = mtd->priv; 100 + struct nand_chip *this = mtd_to_nand(mtd); 101 101 102 102 while (unlikely(len > 0x800)) { 103 103 memcpy_fromio(buf, this->IO_ADDR_R, 0x800); ··· 109 109 110 110 static void cs553x_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 111 111 { 112 - struct nand_chip *this = mtd->priv; 112 + struct nand_chip *this = mtd_to_nand(mtd); 113 113 114 114 while (unlikely(len > 0x800)) { 115 115 memcpy_toio(this->IO_ADDR_R, buf, 0x800); ··· 121 121 122 122 static unsigned char cs553x_read_byte(struct mtd_info *mtd) 123 123 { 124 - struct nand_chip *this = mtd->priv; 124 + struct nand_chip *this = mtd_to_nand(mtd); 125 125 return readb(this->IO_ADDR_R); 126 126 } 127 127 128 128 static void cs553x_write_byte(struct mtd_info *mtd, u_char byte) 129 129 { 130 - struct nand_chip *this = mtd->priv; 130 + struct nand_chip *this = mtd_to_nand(mtd); 131 131 int i = 100000; 132 132 133 133 while (i && readb(this->IO_ADDR_R + MM_NAND_STS) & CS_NAND_CTLR_BUSY) { ··· 140 140 static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd, 141 141 unsigned int ctrl) 142 142 { 143 - struct nand_chip *this = mtd->priv; 143 + struct nand_chip *this = mtd_to_nand(mtd); 144 144 void __iomem *mmio_base = this->IO_ADDR_R; 145 145 if (ctrl & NAND_CTRL_CHANGE) { 146 146 unsigned char ctl = (ctrl & ~NAND_CTRL_CHANGE ) ^ 0x01; ··· 152 152 153 153 static int cs553x_device_ready(struct mtd_info *mtd) 154 154 { 155 - struct nand_chip *this = mtd->priv; 155 + struct nand_chip *this = mtd_to_nand(mtd); 156 156 void __iomem *mmio_base = this->IO_ADDR_R; 157 157 unsigned char foo = readb(mmio_base + MM_NAND_STS); 158 158 ··· 161 161 162 162 static void cs_enable_hwecc(struct mtd_info *mtd, int mode) 163 163 { 164 - struct nand_chip *this = mtd->priv; 164 + struct nand_chip *this = mtd_to_nand(mtd); 165 165 void __iomem *mmio_base = this->IO_ADDR_R; 166 166 167 167 writeb(0x07, mmio_base + MM_NAND_ECC_CTL); ··· 170 170 static int cs_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code) 171 171 { 172 172 uint32_t ecc; 173 - struct nand_chip *this = mtd->priv; 173 + struct nand_chip *this = mtd_to_nand(mtd); 174 174 void __iomem *mmio_base = this->IO_ADDR_R; 175 175 176 176 ecc = readl(mmio_base + MM_NAND_STS); ··· 197 197 } 198 198 199 199 /* Allocate memory for MTD device structure and private data */ 200 - new_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 201 - if (!new_mtd) { 200 + this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 201 + if (!this) { 202 202 err = -ENOMEM; 203 203 goto out; 204 204 } 205 205 206 - /* Get pointer to private data */ 207 - this = (struct nand_chip *)(&new_mtd[1]); 206 + new_mtd = nand_to_mtd(this); 208 207 209 208 /* Link the private data with the MTD structure */ 210 - new_mtd->priv = this; 211 209 new_mtd->owner = THIS_MODULE; 212 210 213 211 /* map physical address */ ··· 255 257 out_ior: 256 258 iounmap(this->IO_ADDR_R); 257 259 out_mtd: 258 - kfree(new_mtd); 260 + kfree(this); 259 261 out: 260 262 return err; 261 263 } ··· 335 337 if (!mtd) 336 338 continue; 337 339 338 - this = cs553x_mtd[i]->priv; 340 + this = mtd_to_nand(mtd); 339 341 mmio_base = this->IO_ADDR_R; 340 342 341 343 /* Release resources, unregister device */ 342 - nand_release(cs553x_mtd[i]); 343 - kfree(cs553x_mtd[i]->name); 344 + nand_release(mtd); 345 + kfree(mtd->name); 344 346 cs553x_mtd[i] = NULL; 345 347 346 348 /* unmap physical address */ 347 349 iounmap(mmio_base); 348 350 349 351 /* Free the MTD device structure */ 350 - kfree(mtd); 352 + kfree(this); 351 353 } 352 354 } 353 355
+25 -35
drivers/mtd/nand/davinci_nand.c
··· 53 53 * outputs in a "wire-AND" configuration, with no per-chip signals. 54 54 */ 55 55 struct davinci_nand_info { 56 - struct mtd_info mtd; 57 56 struct nand_chip chip; 58 57 struct nand_ecclayout ecclayout; 59 58 ··· 79 80 static DEFINE_SPINLOCK(davinci_nand_lock); 80 81 static bool ecc4_busy; 81 82 82 - #define to_davinci_nand(m) container_of(m, struct davinci_nand_info, mtd) 83 - 83 + static inline struct davinci_nand_info *to_davinci_nand(struct mtd_info *mtd) 84 + { 85 + return container_of(mtd_to_nand(mtd), struct davinci_nand_info, chip); 86 + } 84 87 85 88 static inline unsigned int davinci_nand_readl(struct davinci_nand_info *info, 86 89 int offset) ··· 107 106 { 108 107 struct davinci_nand_info *info = to_davinci_nand(mtd); 109 108 uint32_t addr = info->current_cs; 110 - struct nand_chip *nand = mtd->priv; 109 + struct nand_chip *nand = mtd_to_nand(mtd); 111 110 112 111 /* Did the control lines change? */ 113 112 if (ctrl & NAND_CTRL_CHANGE) { ··· 193 192 static int nand_davinci_correct_1bit(struct mtd_info *mtd, u_char *dat, 194 193 u_char *read_ecc, u_char *calc_ecc) 195 194 { 196 - struct nand_chip *chip = mtd->priv; 195 + struct nand_chip *chip = mtd_to_nand(mtd); 197 196 uint32_t eccNand = read_ecc[0] | (read_ecc[1] << 8) | 198 197 (read_ecc[2] << 16); 199 198 uint32_t eccCalc = calc_ecc[0] | (calc_ecc[1] << 8) | ··· 207 206 dat[diff >> (12 + 3)] ^= BIT((diff >> 12) & 7); 208 207 return 1; 209 208 } else { 210 - return -1; 209 + return -EBADMSG; 211 210 } 212 211 } else if (!(diff & (diff - 1))) { 213 212 /* Single bit ECC error in the ECC itself, ··· 215 214 return 1; 216 215 } else { 217 216 /* Uncorrectable error */ 218 - return -1; 217 + return -EBADMSG; 219 218 } 220 219 221 220 } ··· 317 316 unsigned num_errors, corrected; 318 317 unsigned long timeo; 319 318 320 - /* All bytes 0xff? It's an erased page; ignore its ECC. */ 321 - for (i = 0; i < 10; i++) { 322 - if (ecc_code[i] != 0xff) 323 - goto compare; 324 - } 325 - return 0; 326 - 327 - compare: 328 319 /* Unpack ten bytes into eight 10 bit values. We know we're 329 320 * little-endian, and use type punning for less shifting/masking. 330 321 */ ··· 383 390 return 0; 384 391 case 1: /* five or more errors detected */ 385 392 davinci_nand_readl(info, NAND_ERR_ERRVAL1_OFFSET); 386 - return -EIO; 393 + return -EBADMSG; 387 394 case 2: /* error addresses computed */ 388 395 case 3: 389 396 num_errors = 1 + ((fsr >> 16) & 0x03); ··· 440 447 */ 441 448 static void nand_davinci_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 442 449 { 443 - struct nand_chip *chip = mtd->priv; 450 + struct nand_chip *chip = mtd_to_nand(mtd); 444 451 445 452 if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0) 446 453 ioread32_rep(chip->IO_ADDR_R, buf, len >> 2); ··· 453 460 static void nand_davinci_write_buf(struct mtd_info *mtd, 454 461 const uint8_t *buf, int len) 455 462 { 456 - struct nand_chip *chip = mtd->priv; 463 + struct nand_chip *chip = mtd_to_nand(mtd); 457 464 458 465 if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0) 459 466 iowrite32_rep(chip->IO_ADDR_R, buf, len >> 2); ··· 629 636 int ret; 630 637 uint32_t val; 631 638 nand_ecc_modes_t ecc_mode; 639 + struct mtd_info *mtd; 632 640 633 641 pdata = nand_davinci_get_pdata(pdev); 634 642 if (IS_ERR(pdata)) ··· 676 682 info->base = base; 677 683 info->vaddr = vaddr; 678 684 679 - info->mtd.priv = &info->chip; 680 - info->mtd.dev.parent = &pdev->dev; 685 + mtd = nand_to_mtd(&info->chip); 686 + mtd->dev.parent = &pdev->dev; 687 + nand_set_flash_node(&info->chip, pdev->dev.of_node); 681 688 682 689 info->chip.IO_ADDR_R = vaddr; 683 690 info->chip.IO_ADDR_W = vaddr; ··· 741 746 info->chip.ecc.correct = nand_davinci_correct_4bit; 742 747 info->chip.ecc.hwctl = nand_davinci_hwctl_4bit; 743 748 info->chip.ecc.bytes = 10; 749 + info->chip.ecc.options = NAND_ECC_GENERIC_ERASED_CHECK; 744 750 } else { 745 751 info->chip.ecc.calculate = nand_davinci_calculate_1bit; 746 752 info->chip.ecc.correct = nand_davinci_correct_1bit; ··· 780 784 spin_unlock_irq(&davinci_nand_lock); 781 785 782 786 /* Scan to find existence of the device(s) */ 783 - ret = nand_scan_ident(&info->mtd, pdata->mask_chipsel ? 2 : 1, NULL); 787 + ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL); 784 788 if (ret < 0) { 785 789 dev_dbg(&pdev->dev, "no NAND chip(s) found\n"); 786 790 goto err; ··· 792 796 * usable: 10 bytes are needed, not 6. 793 797 */ 794 798 if (pdata->ecc_bits == 4) { 795 - int chunks = info->mtd.writesize / 512; 799 + int chunks = mtd->writesize / 512; 796 800 797 - if (!chunks || info->mtd.oobsize < 16) { 801 + if (!chunks || mtd->oobsize < 16) { 798 802 dev_dbg(&pdev->dev, "too small\n"); 799 803 ret = -EINVAL; 800 804 goto err; ··· 806 810 */ 807 811 if (chunks == 1) { 808 812 info->ecclayout = hwecc4_small; 809 - info->ecclayout.oobfree[1].length = 810 - info->mtd.oobsize - 16; 813 + info->ecclayout.oobfree[1].length = mtd->oobsize - 16; 811 814 goto syndrome_done; 812 815 } 813 816 if (chunks == 4) { ··· 827 832 info->chip.ecc.layout = &info->ecclayout; 828 833 } 829 834 830 - ret = nand_scan_tail(&info->mtd); 835 + ret = nand_scan_tail(mtd); 831 836 if (ret < 0) 832 837 goto err; 833 838 834 839 if (pdata->parts) 835 - ret = mtd_device_parse_register(&info->mtd, NULL, NULL, 840 + ret = mtd_device_parse_register(mtd, NULL, NULL, 836 841 pdata->parts, pdata->nr_parts); 837 - else { 838 - struct mtd_part_parser_data ppdata; 839 - 840 - ppdata.of_node = pdev->dev.of_node; 841 - ret = mtd_device_parse_register(&info->mtd, NULL, &ppdata, 842 - NULL, 0); 843 - } 842 + else 843 + ret = mtd_device_register(mtd, NULL, 0); 844 844 if (ret < 0) 845 845 goto err; 846 846 ··· 865 875 ecc4_busy = false; 866 876 spin_unlock_irq(&davinci_nand_lock); 867 877 868 - nand_release(&info->mtd); 878 + nand_release(nand_to_mtd(&info->chip)); 869 879 870 880 clk_disable_unprepare(info->clk); 871 881
+44 -31
drivers/mtd/nand/denali.c
··· 75 75 * this macro allows us to convert from an MTD structure to our own 76 76 * device context (denali) structure. 77 77 */ 78 - #define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd) 78 + static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd) 79 + { 80 + return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand); 81 + } 79 82 80 83 /* 81 84 * These constants are defined by the driver to enable common driver ··· 989 986 * than one NAND connected. 990 987 */ 991 988 if (err_byte < ECC_SECTOR_SIZE) { 989 + struct mtd_info *mtd = 990 + nand_to_mtd(&denali->nand); 992 991 int offset; 993 992 994 993 offset = (err_sector * ··· 1000 995 err_device; 1001 996 /* correct the ECC error */ 1002 997 buf[offset] ^= err_correction_value; 1003 - denali->mtd.ecc_stats.corrected++; 998 + mtd->ecc_stats.corrected++; 1004 999 bitflips++; 1005 1000 } 1006 1001 } else { ··· 1067 1062 { 1068 1063 struct denali_nand_info *denali = mtd_to_denali(mtd); 1069 1064 dma_addr_t addr = denali->buf.dma_buf; 1070 - size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1065 + size_t size = mtd->writesize + mtd->oobsize; 1071 1066 uint32_t irq_status; 1072 1067 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP | 1073 1068 INTR_STATUS__PROGRAM_FAIL; ··· 1165 1160 struct denali_nand_info *denali = mtd_to_denali(mtd); 1166 1161 1167 1162 dma_addr_t addr = denali->buf.dma_buf; 1168 - size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1163 + size_t size = mtd->writesize + mtd->oobsize; 1169 1164 1170 1165 uint32_t irq_status; 1171 1166 uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE | ··· 1198 1193 denali_enable_dma(denali, false); 1199 1194 1200 1195 if (check_erased_page) { 1201 - read_oob_data(&denali->mtd, chip->oob_poi, denali->page); 1196 + read_oob_data(mtd, chip->oob_poi, denali->page); 1202 1197 1203 1198 /* check ECC failures that may have occurred on erased pages */ 1204 1199 if (check_erased_page) { 1205 - if (!is_erased(buf, denali->mtd.writesize)) 1206 - denali->mtd.ecc_stats.failed++; 1207 - if (!is_erased(buf, denali->mtd.oobsize)) 1208 - denali->mtd.ecc_stats.failed++; 1200 + if (!is_erased(buf, mtd->writesize)) 1201 + mtd->ecc_stats.failed++; 1202 + if (!is_erased(buf, mtd->oobsize)) 1203 + mtd->ecc_stats.failed++; 1209 1204 } 1210 1205 } 1211 1206 return max_bitflips; ··· 1216 1211 { 1217 1212 struct denali_nand_info *denali = mtd_to_denali(mtd); 1218 1213 dma_addr_t addr = denali->buf.dma_buf; 1219 - size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1214 + size_t size = mtd->writesize + mtd->oobsize; 1220 1215 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP; 1221 1216 1222 1217 if (page != denali->page) { ··· 1433 1428 1434 1429 int denali_init(struct denali_nand_info *denali) 1435 1430 { 1431 + struct mtd_info *mtd = nand_to_mtd(&denali->nand); 1436 1432 int ret; 1437 1433 1438 1434 if (denali->platform == INTEL_CE4100) { ··· 1453 1447 if (!denali->buf.buf) 1454 1448 return -ENOMEM; 1455 1449 1456 - denali->mtd.dev.parent = denali->dev; 1450 + mtd->dev.parent = denali->dev; 1457 1451 denali_hw_init(denali); 1458 1452 denali_drv_init(denali); 1459 1453 ··· 1469 1463 1470 1464 /* now that our ISR is registered, we can enable interrupts */ 1471 1465 denali_set_intr_modes(denali, true); 1472 - denali->mtd.name = "denali-nand"; 1473 - denali->mtd.priv = &denali->nand; 1466 + mtd->name = "denali-nand"; 1474 1467 1475 1468 /* register the driver with the NAND core subsystem */ 1476 1469 denali->nand.select_chip = denali_select_chip; ··· 1482 1477 * this is the first stage in a two step process to register 1483 1478 * with the nand subsystem 1484 1479 */ 1485 - if (nand_scan_ident(&denali->mtd, denali->max_banks, NULL)) { 1480 + if (nand_scan_ident(mtd, denali->max_banks, NULL)) { 1486 1481 ret = -ENXIO; 1487 1482 goto failed_req_irq; 1488 1483 } ··· 1490 1485 /* allocate the right size buffer now */ 1491 1486 devm_kfree(denali->dev, denali->buf.buf); 1492 1487 denali->buf.buf = devm_kzalloc(denali->dev, 1493 - denali->mtd.writesize + denali->mtd.oobsize, 1488 + mtd->writesize + mtd->oobsize, 1494 1489 GFP_KERNEL); 1495 1490 if (!denali->buf.buf) { 1496 1491 ret = -ENOMEM; ··· 1505 1500 } 1506 1501 1507 1502 denali->buf.dma_buf = dma_map_single(denali->dev, denali->buf.buf, 1508 - denali->mtd.writesize + denali->mtd.oobsize, 1503 + mtd->writesize + mtd->oobsize, 1509 1504 DMA_BIDIRECTIONAL); 1510 1505 if (dma_mapping_error(denali->dev, denali->buf.dma_buf)) { 1511 1506 dev_err(denali->dev, "Spectra: failed to map DMA buffer\n"); ··· 1526 1521 denali->nand.bbt_erase_shift += (denali->devnum - 1); 1527 1522 denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift; 1528 1523 denali->nand.chip_shift += (denali->devnum - 1); 1529 - denali->mtd.writesize <<= (denali->devnum - 1); 1530 - denali->mtd.oobsize <<= (denali->devnum - 1); 1531 - denali->mtd.erasesize <<= (denali->devnum - 1); 1532 - denali->mtd.size = denali->nand.numchips * denali->nand.chipsize; 1524 + mtd->writesize <<= (denali->devnum - 1); 1525 + mtd->oobsize <<= (denali->devnum - 1); 1526 + mtd->erasesize <<= (denali->devnum - 1); 1527 + mtd->size = denali->nand.numchips * denali->nand.chipsize; 1533 1528 denali->bbtskipbytes *= denali->devnum; 1534 1529 1535 1530 /* ··· 1556 1551 * SLC if possible. 1557 1552 * */ 1558 1553 if (!nand_is_slc(&denali->nand) && 1559 - (denali->mtd.oobsize > (denali->bbtskipbytes + 1560 - ECC_15BITS * (denali->mtd.writesize / 1554 + (mtd->oobsize > (denali->bbtskipbytes + 1555 + ECC_15BITS * (mtd->writesize / 1561 1556 ECC_SECTOR_SIZE)))) { 1562 1557 /* if MLC OOB size is large enough, use 15bit ECC*/ 1563 1558 denali->nand.ecc.strength = 15; 1564 1559 denali->nand.ecc.layout = &nand_15bit_oob; 1565 1560 denali->nand.ecc.bytes = ECC_15BITS; 1566 1561 iowrite32(15, denali->flash_reg + ECC_CORRECTION); 1567 - } else if (denali->mtd.oobsize < (denali->bbtskipbytes + 1568 - ECC_8BITS * (denali->mtd.writesize / 1562 + } else if (mtd->oobsize < (denali->bbtskipbytes + 1563 + ECC_8BITS * (mtd->writesize / 1569 1564 ECC_SECTOR_SIZE))) { 1570 1565 pr_err("Your NAND chip OOB is not large enough to contain 8bit ECC correction codes"); 1571 1566 goto failed_req_irq; ··· 1579 1574 denali->nand.ecc.bytes *= denali->devnum; 1580 1575 denali->nand.ecc.strength *= denali->devnum; 1581 1576 denali->nand.ecc.layout->eccbytes *= 1582 - denali->mtd.writesize / ECC_SECTOR_SIZE; 1577 + mtd->writesize / ECC_SECTOR_SIZE; 1583 1578 denali->nand.ecc.layout->oobfree[0].offset = 1584 1579 denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes; 1585 1580 denali->nand.ecc.layout->oobfree[0].length = 1586 - denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes - 1581 + mtd->oobsize - denali->nand.ecc.layout->eccbytes - 1587 1582 denali->bbtskipbytes; 1588 1583 1589 1584 /* ··· 1591 1586 * contained by each nand chip. blksperchip will help driver to 1592 1587 * know how many blocks is taken by FW. 1593 1588 */ 1594 - denali->totalblks = denali->mtd.size >> denali->nand.phys_erase_shift; 1589 + denali->totalblks = mtd->size >> denali->nand.phys_erase_shift; 1595 1590 denali->blksperchip = denali->totalblks / denali->nand.numchips; 1596 1591 1597 1592 /* override the default read operations */ ··· 1604 1599 denali->nand.ecc.write_oob = denali_write_oob; 1605 1600 denali->nand.erase = denali_erase; 1606 1601 1607 - if (nand_scan_tail(&denali->mtd)) { 1602 + if (nand_scan_tail(mtd)) { 1608 1603 ret = -ENXIO; 1609 1604 goto failed_req_irq; 1610 1605 } 1611 1606 1612 - ret = mtd_device_register(&denali->mtd, NULL, 0); 1607 + ret = mtd_device_register(mtd, NULL, 0); 1613 1608 if (ret) { 1614 1609 dev_err(denali->dev, "Spectra: Failed to register MTD: %d\n", 1615 1610 ret); ··· 1627 1622 /* driver exit point */ 1628 1623 void denali_remove(struct denali_nand_info *denali) 1629 1624 { 1625 + struct mtd_info *mtd = nand_to_mtd(&denali->nand); 1626 + /* 1627 + * Pre-compute DMA buffer size to avoid any problems in case 1628 + * nand_release() ever changes in a way that mtd->writesize and 1629 + * mtd->oobsize are not reliable after this call. 1630 + */ 1631 + int bufsize = mtd->writesize + mtd->oobsize; 1632 + 1633 + nand_release(mtd); 1630 1634 denali_irq_cleanup(denali->irq, denali); 1631 - dma_unmap_single(denali->dev, denali->buf.dma_buf, 1632 - denali->mtd.writesize + denali->mtd.oobsize, 1635 + dma_unmap_single(denali->dev, denali->buf.dma_buf, bufsize, 1633 1636 DMA_BIDIRECTIONAL); 1634 1637 } 1635 1638 EXPORT_SYMBOL(denali_remove);
-1
drivers/mtd/nand/denali.h
··· 450 450 #define DT 3 451 451 452 452 struct denali_nand_info { 453 - struct mtd_info mtd; 454 453 struct nand_chip nand; 455 454 int flash_bank; /* currently selected chip */ 456 455 int status;
+78 -111
drivers/mtd/nand/diskonchip.c
··· 74 74 int (*late_init)(struct mtd_info *mtd); 75 75 }; 76 76 77 - /* This is the syndrome computed by the HW ecc generator upon reading an empty 78 - page, one with all 0xff for data and stored ecc code. */ 79 - static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a }; 80 - 81 77 /* This is the ecc value computed by the HW ecc generator upon writing an empty 82 78 page, one with all 0xff for data. */ 83 79 static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 }; ··· 295 299 296 300 static void doc2000_write_byte(struct mtd_info *mtd, u_char datum) 297 301 { 298 - struct nand_chip *this = mtd->priv; 299 - struct doc_priv *doc = this->priv; 302 + struct nand_chip *this = mtd_to_nand(mtd); 303 + struct doc_priv *doc = nand_get_controller_data(this); 300 304 void __iomem *docptr = doc->virtadr; 301 305 302 306 if (debug) ··· 307 311 308 312 static u_char doc2000_read_byte(struct mtd_info *mtd) 309 313 { 310 - struct nand_chip *this = mtd->priv; 311 - struct doc_priv *doc = this->priv; 314 + struct nand_chip *this = mtd_to_nand(mtd); 315 + struct doc_priv *doc = nand_get_controller_data(this); 312 316 void __iomem *docptr = doc->virtadr; 313 317 u_char ret; 314 318 ··· 322 326 323 327 static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len) 324 328 { 325 - struct nand_chip *this = mtd->priv; 326 - struct doc_priv *doc = this->priv; 329 + struct nand_chip *this = mtd_to_nand(mtd); 330 + struct doc_priv *doc = nand_get_controller_data(this); 327 331 void __iomem *docptr = doc->virtadr; 328 332 int i; 329 333 if (debug) ··· 339 343 340 344 static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len) 341 345 { 342 - struct nand_chip *this = mtd->priv; 343 - struct doc_priv *doc = this->priv; 346 + struct nand_chip *this = mtd_to_nand(mtd); 347 + struct doc_priv *doc = nand_get_controller_data(this); 344 348 void __iomem *docptr = doc->virtadr; 345 349 int i; 346 350 ··· 354 358 355 359 static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len) 356 360 { 357 - struct nand_chip *this = mtd->priv; 358 - struct doc_priv *doc = this->priv; 361 + struct nand_chip *this = mtd_to_nand(mtd); 362 + struct doc_priv *doc = nand_get_controller_data(this); 359 363 void __iomem *docptr = doc->virtadr; 360 364 int i; 361 365 ··· 375 379 376 380 static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr) 377 381 { 378 - struct nand_chip *this = mtd->priv; 379 - struct doc_priv *doc = this->priv; 382 + struct nand_chip *this = mtd_to_nand(mtd); 383 + struct doc_priv *doc = nand_get_controller_data(this); 380 384 uint16_t ret; 381 385 382 386 doc200x_select_chip(mtd, nr); ··· 421 425 422 426 static void __init doc2000_count_chips(struct mtd_info *mtd) 423 427 { 424 - struct nand_chip *this = mtd->priv; 425 - struct doc_priv *doc = this->priv; 428 + struct nand_chip *this = mtd_to_nand(mtd); 429 + struct doc_priv *doc = nand_get_controller_data(this); 426 430 uint16_t mfrid; 427 431 int i; 428 432 ··· 443 447 444 448 static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this) 445 449 { 446 - struct doc_priv *doc = this->priv; 450 + struct doc_priv *doc = nand_get_controller_data(this); 447 451 448 452 int status; 449 453 ··· 457 461 458 462 static void doc2001_write_byte(struct mtd_info *mtd, u_char datum) 459 463 { 460 - struct nand_chip *this = mtd->priv; 461 - struct doc_priv *doc = this->priv; 464 + struct nand_chip *this = mtd_to_nand(mtd); 465 + struct doc_priv *doc = nand_get_controller_data(this); 462 466 void __iomem *docptr = doc->virtadr; 463 467 464 468 WriteDOC(datum, docptr, CDSNSlowIO); ··· 468 472 469 473 static u_char doc2001_read_byte(struct mtd_info *mtd) 470 474 { 471 - struct nand_chip *this = mtd->priv; 472 - struct doc_priv *doc = this->priv; 475 + struct nand_chip *this = mtd_to_nand(mtd); 476 + struct doc_priv *doc = nand_get_controller_data(this); 473 477 void __iomem *docptr = doc->virtadr; 474 478 475 479 //ReadDOC(docptr, CDSNSlowIO); ··· 482 486 483 487 static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len) 484 488 { 485 - struct nand_chip *this = mtd->priv; 486 - struct doc_priv *doc = this->priv; 489 + struct nand_chip *this = mtd_to_nand(mtd); 490 + struct doc_priv *doc = nand_get_controller_data(this); 487 491 void __iomem *docptr = doc->virtadr; 488 492 int i; 489 493 ··· 495 499 496 500 static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len) 497 501 { 498 - struct nand_chip *this = mtd->priv; 499 - struct doc_priv *doc = this->priv; 502 + struct nand_chip *this = mtd_to_nand(mtd); 503 + struct doc_priv *doc = nand_get_controller_data(this); 500 504 void __iomem *docptr = doc->virtadr; 501 505 int i; 502 506 ··· 512 516 513 517 static u_char doc2001plus_read_byte(struct mtd_info *mtd) 514 518 { 515 - struct nand_chip *this = mtd->priv; 516 - struct doc_priv *doc = this->priv; 519 + struct nand_chip *this = mtd_to_nand(mtd); 520 + struct doc_priv *doc = nand_get_controller_data(this); 517 521 void __iomem *docptr = doc->virtadr; 518 522 u_char ret; 519 523 ··· 527 531 528 532 static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len) 529 533 { 530 - struct nand_chip *this = mtd->priv; 531 - struct doc_priv *doc = this->priv; 534 + struct nand_chip *this = mtd_to_nand(mtd); 535 + struct doc_priv *doc = nand_get_controller_data(this); 532 536 void __iomem *docptr = doc->virtadr; 533 537 int i; 534 538 ··· 545 549 546 550 static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len) 547 551 { 548 - struct nand_chip *this = mtd->priv; 549 - struct doc_priv *doc = this->priv; 552 + struct nand_chip *this = mtd_to_nand(mtd); 553 + struct doc_priv *doc = nand_get_controller_data(this); 550 554 void __iomem *docptr = doc->virtadr; 551 555 int i; 552 556 ··· 576 580 577 581 static void doc2001plus_select_chip(struct mtd_info *mtd, int chip) 578 582 { 579 - struct nand_chip *this = mtd->priv; 580 - struct doc_priv *doc = this->priv; 583 + struct nand_chip *this = mtd_to_nand(mtd); 584 + struct doc_priv *doc = nand_get_controller_data(this); 581 585 void __iomem *docptr = doc->virtadr; 582 586 int floor = 0; 583 587 ··· 603 607 604 608 static void doc200x_select_chip(struct mtd_info *mtd, int chip) 605 609 { 606 - struct nand_chip *this = mtd->priv; 607 - struct doc_priv *doc = this->priv; 610 + struct nand_chip *this = mtd_to_nand(mtd); 611 + struct doc_priv *doc = nand_get_controller_data(this); 608 612 void __iomem *docptr = doc->virtadr; 609 613 int floor = 0; 610 614 ··· 634 638 static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd, 635 639 unsigned int ctrl) 636 640 { 637 - struct nand_chip *this = mtd->priv; 638 - struct doc_priv *doc = this->priv; 641 + struct nand_chip *this = mtd_to_nand(mtd); 642 + struct doc_priv *doc = nand_get_controller_data(this); 639 643 void __iomem *docptr = doc->virtadr; 640 644 641 645 if (ctrl & NAND_CTRL_CHANGE) { ··· 657 661 658 662 static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) 659 663 { 660 - struct nand_chip *this = mtd->priv; 661 - struct doc_priv *doc = this->priv; 664 + struct nand_chip *this = mtd_to_nand(mtd); 665 + struct doc_priv *doc = nand_get_controller_data(this); 662 666 void __iomem *docptr = doc->virtadr; 663 667 664 668 /* ··· 763 767 764 768 static int doc200x_dev_ready(struct mtd_info *mtd) 765 769 { 766 - struct nand_chip *this = mtd->priv; 767 - struct doc_priv *doc = this->priv; 770 + struct nand_chip *this = mtd_to_nand(mtd); 771 + struct doc_priv *doc = nand_get_controller_data(this); 768 772 void __iomem *docptr = doc->virtadr; 769 773 770 774 if (DoC_is_MillenniumPlus(doc)) { ··· 803 807 804 808 static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode) 805 809 { 806 - struct nand_chip *this = mtd->priv; 807 - struct doc_priv *doc = this->priv; 810 + struct nand_chip *this = mtd_to_nand(mtd); 811 + struct doc_priv *doc = nand_get_controller_data(this); 808 812 void __iomem *docptr = doc->virtadr; 809 813 810 814 /* Prime the ECC engine */ ··· 822 826 823 827 static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode) 824 828 { 825 - struct nand_chip *this = mtd->priv; 826 - struct doc_priv *doc = this->priv; 829 + struct nand_chip *this = mtd_to_nand(mtd); 830 + struct doc_priv *doc = nand_get_controller_data(this); 827 831 void __iomem *docptr = doc->virtadr; 828 832 829 833 /* Prime the ECC engine */ ··· 842 846 /* This code is only called on write */ 843 847 static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsigned char *ecc_code) 844 848 { 845 - struct nand_chip *this = mtd->priv; 846 - struct doc_priv *doc = this->priv; 849 + struct nand_chip *this = mtd_to_nand(mtd); 850 + struct doc_priv *doc = nand_get_controller_data(this); 847 851 void __iomem *docptr = doc->virtadr; 848 852 int i; 849 853 int emptymatch = 1; ··· 903 907 u_char *read_ecc, u_char *isnull) 904 908 { 905 909 int i, ret = 0; 906 - struct nand_chip *this = mtd->priv; 907 - struct doc_priv *doc = this->priv; 910 + struct nand_chip *this = mtd_to_nand(mtd); 911 + struct doc_priv *doc = nand_get_controller_data(this); 908 912 void __iomem *docptr = doc->virtadr; 909 913 uint8_t calc_ecc[6]; 910 914 volatile u_char dummy; 911 - int emptymatch = 1; 912 915 913 916 /* flush the pipeline */ 914 917 if (DoC_is_2000(doc)) { ··· 931 936 calc_ecc[i] = ReadDOC_(docptr, DoC_Mplus_ECCSyndrome0 + i); 932 937 else 933 938 calc_ecc[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); 934 - if (calc_ecc[i] != empty_read_syndrome[i]) 935 - emptymatch = 0; 936 939 } 937 - /* If emptymatch=1, the read syndrome is consistent with an 938 - all-0xff data and stored ecc block. Check the stored ecc. */ 939 - if (emptymatch) { 940 - for (i = 0; i < 6; i++) { 941 - if (read_ecc[i] == 0xff) 942 - continue; 943 - emptymatch = 0; 944 - break; 945 - } 946 - } 947 - /* If emptymatch still =1, check the data block. */ 948 - if (emptymatch) { 949 - /* Note: this somewhat expensive test should not be triggered 950 - often. It could be optimized away by examining the data in 951 - the readbuf routine, and remembering the result. */ 952 - for (i = 0; i < 512; i++) { 953 - if (dat[i] == 0xff) 954 - continue; 955 - emptymatch = 0; 956 - break; 957 - } 958 - } 959 - /* If emptymatch still =1, this is almost certainly a freshly- 960 - erased block, in which case the ECC will not come out right. 961 - We'll suppress the error and tell the caller everything's 962 - OK. Because it is. */ 963 - if (!emptymatch) 964 - ret = doc_ecc_decode(rs_decoder, dat, calc_ecc); 940 + 941 + ret = doc_ecc_decode(rs_decoder, dat, calc_ecc); 965 942 if (ret > 0) 966 943 printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret); 967 944 } ··· 974 1007 mh1_page in the DOC private structure. */ 975 1008 static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const char *id, int findmirror) 976 1009 { 977 - struct nand_chip *this = mtd->priv; 978 - struct doc_priv *doc = this->priv; 1010 + struct nand_chip *this = mtd_to_nand(mtd); 1011 + struct doc_priv *doc = nand_get_controller_data(this); 979 1012 unsigned offs; 980 1013 int ret; 981 1014 size_t retlen; ··· 1017 1050 1018 1051 static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts) 1019 1052 { 1020 - struct nand_chip *this = mtd->priv; 1021 - struct doc_priv *doc = this->priv; 1053 + struct nand_chip *this = mtd_to_nand(mtd); 1054 + struct doc_priv *doc = nand_get_controller_data(this); 1022 1055 int ret = 0; 1023 1056 u_char *buf; 1024 1057 struct NFTLMediaHeader *mh; ··· 1119 1152 /* This is a stripped-down copy of the code in inftlmount.c */ 1120 1153 static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts) 1121 1154 { 1122 - struct nand_chip *this = mtd->priv; 1123 - struct doc_priv *doc = this->priv; 1155 + struct nand_chip *this = mtd_to_nand(mtd); 1156 + struct doc_priv *doc = nand_get_controller_data(this); 1124 1157 int ret = 0; 1125 1158 u_char *buf; 1126 1159 struct INFTLMediaHeader *mh; ··· 1239 1272 static int __init nftl_scan_bbt(struct mtd_info *mtd) 1240 1273 { 1241 1274 int ret, numparts; 1242 - struct nand_chip *this = mtd->priv; 1243 - struct doc_priv *doc = this->priv; 1275 + struct nand_chip *this = mtd_to_nand(mtd); 1276 + struct doc_priv *doc = nand_get_controller_data(this); 1244 1277 struct mtd_partition parts[2]; 1245 1278 1246 1279 memset((char *)parts, 0, sizeof(parts)); ··· 1274 1307 static int __init inftl_scan_bbt(struct mtd_info *mtd) 1275 1308 { 1276 1309 int ret, numparts; 1277 - struct nand_chip *this = mtd->priv; 1278 - struct doc_priv *doc = this->priv; 1310 + struct nand_chip *this = mtd_to_nand(mtd); 1311 + struct doc_priv *doc = nand_get_controller_data(this); 1279 1312 struct mtd_partition parts[5]; 1280 1313 1281 1314 if (this->numchips > doc->chips_per_floor) { ··· 1327 1360 1328 1361 static inline int __init doc2000_init(struct mtd_info *mtd) 1329 1362 { 1330 - struct nand_chip *this = mtd->priv; 1331 - struct doc_priv *doc = this->priv; 1363 + struct nand_chip *this = mtd_to_nand(mtd); 1364 + struct doc_priv *doc = nand_get_controller_data(this); 1332 1365 1333 1366 this->read_byte = doc2000_read_byte; 1334 1367 this->write_buf = doc2000_writebuf; ··· 1343 1376 1344 1377 static inline int __init doc2001_init(struct mtd_info *mtd) 1345 1378 { 1346 - struct nand_chip *this = mtd->priv; 1347 - struct doc_priv *doc = this->priv; 1379 + struct nand_chip *this = mtd_to_nand(mtd); 1380 + struct doc_priv *doc = nand_get_controller_data(this); 1348 1381 1349 1382 this->read_byte = doc2001_read_byte; 1350 1383 this->write_buf = doc2001_writebuf; ··· 1373 1406 1374 1407 static inline int __init doc2001plus_init(struct mtd_info *mtd) 1375 1408 { 1376 - struct nand_chip *this = mtd->priv; 1377 - struct doc_priv *doc = this->priv; 1409 + struct nand_chip *this = mtd_to_nand(mtd); 1410 + struct doc_priv *doc = nand_get_controller_data(this); 1378 1411 1379 1412 this->read_byte = doc2001plus_read_byte; 1380 1413 this->write_buf = doc2001plus_writebuf; ··· 1490 1523 for (mtd = doclist; mtd; mtd = doc->nextdoc) { 1491 1524 unsigned char oldval; 1492 1525 unsigned char newval; 1493 - nand = mtd->priv; 1494 - doc = nand->priv; 1526 + nand = mtd_to_nand(mtd); 1527 + doc = nand_get_controller_data(nand); 1495 1528 /* Use the alias resolution register to determine if this is 1496 1529 in fact the same DOC aliased to a new address. If writes 1497 1530 to one chip's alias resolution register change the value on ··· 1523 1556 1524 1557 printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr); 1525 1558 1526 - len = sizeof(struct mtd_info) + 1527 - sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr)); 1528 - mtd = kzalloc(len, GFP_KERNEL); 1529 - if (!mtd) { 1559 + len = sizeof(struct nand_chip) + sizeof(struct doc_priv) + 1560 + (2 * sizeof(struct nand_bbt_descr)); 1561 + nand = kzalloc(len, GFP_KERNEL); 1562 + if (!nand) { 1530 1563 ret = -ENOMEM; 1531 1564 goto fail; 1532 1565 } 1533 1566 1534 - nand = (struct nand_chip *) (mtd + 1); 1567 + mtd = nand_to_mtd(nand); 1535 1568 doc = (struct doc_priv *) (nand + 1); 1536 1569 nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); 1537 1570 nand->bbt_md = nand->bbt_td + 1; 1538 1571 1539 - mtd->priv = nand; 1540 1572 mtd->owner = THIS_MODULE; 1541 1573 1542 - nand->priv = doc; 1574 + nand_set_controller_data(nand, doc); 1543 1575 nand->select_chip = doc200x_select_chip; 1544 1576 nand->cmd_ctrl = doc200x_hwcontrol; 1545 1577 nand->dev_ready = doc200x_dev_ready; ··· 1553 1587 nand->ecc.size = 512; 1554 1588 nand->ecc.bytes = 6; 1555 1589 nand->ecc.strength = 2; 1590 + nand->ecc.options = NAND_ECC_GENERIC_ERASED_CHECK; 1556 1591 nand->bbt_options = NAND_BBT_USE_FLASH; 1557 1592 /* Skip the automatic BBT scan so we can run it manually */ 1558 1593 nand->options |= NAND_SKIP_BBTSCAN; ··· 1582 1615 haven't yet added it. This is handled without incident by 1583 1616 mtd_device_unregister, as far as I can tell. */ 1584 1617 nand_release(mtd); 1585 - kfree(mtd); 1618 + kfree(nand); 1586 1619 goto fail; 1587 1620 } 1588 1621 ··· 1610 1643 struct doc_priv *doc; 1611 1644 1612 1645 for (mtd = doclist; mtd; mtd = nextmtd) { 1613 - nand = mtd->priv; 1614 - doc = nand->priv; 1646 + nand = mtd_to_nand(mtd); 1647 + doc = nand_get_controller_data(nand); 1615 1648 1616 1649 nextmtd = doc->nextdoc; 1617 1650 nand_release(mtd); 1618 1651 iounmap(doc->virtadr); 1619 1652 release_mem_region(doc->physadr, DOC_IOREMAP_LEN); 1620 - kfree(mtd); 1653 + kfree(nand); 1621 1654 } 1622 1655 } 1623 1656
+49 -53
drivers/mtd/nand/docg4.c
··· 242 242 static void docg4_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 243 243 { 244 244 int i; 245 - struct nand_chip *nand = mtd->priv; 245 + struct nand_chip *nand = mtd_to_nand(mtd); 246 246 uint16_t *p = (uint16_t *) buf; 247 247 len >>= 1; 248 248 ··· 253 253 static void docg4_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 254 254 { 255 255 int i; 256 - struct nand_chip *nand = mtd->priv; 256 + struct nand_chip *nand = mtd_to_nand(mtd); 257 257 uint16_t *p = (uint16_t *) buf; 258 258 len >>= 1; 259 259 ··· 297 297 static int docg4_wait(struct mtd_info *mtd, struct nand_chip *nand) 298 298 { 299 299 300 - struct docg4_priv *doc = nand->priv; 300 + struct docg4_priv *doc = nand_get_controller_data(nand); 301 301 int status = NAND_STATUS_WP; /* inverse logic?? */ 302 302 dev_dbg(doc->dev, "%s...\n", __func__); 303 303 ··· 318 318 * Select among multiple cascaded chips ("floors"). Multiple floors are 319 319 * not yet supported, so the only valid non-negative value is 0. 320 320 */ 321 - struct nand_chip *nand = mtd->priv; 322 - struct docg4_priv *doc = nand->priv; 321 + struct nand_chip *nand = mtd_to_nand(mtd); 322 + struct docg4_priv *doc = nand_get_controller_data(nand); 323 323 void __iomem *docptr = doc->virtadr; 324 324 325 325 dev_dbg(doc->dev, "%s: chip %d\n", __func__, chip); ··· 337 337 { 338 338 /* full device reset */ 339 339 340 - struct nand_chip *nand = mtd->priv; 341 - struct docg4_priv *doc = nand->priv; 340 + struct nand_chip *nand = mtd_to_nand(mtd); 341 + struct docg4_priv *doc = nand_get_controller_data(nand); 342 342 void __iomem *docptr = doc->virtadr; 343 343 344 344 writew(DOC_ASICMODE_RESET | DOC_ASICMODE_MDWREN, ··· 375 375 * Up to four bitflips can be corrected. 376 376 */ 377 377 378 - struct nand_chip *nand = mtd->priv; 379 - struct docg4_priv *doc = nand->priv; 378 + struct nand_chip *nand = mtd_to_nand(mtd); 379 + struct docg4_priv *doc = nand_get_controller_data(nand); 380 380 void __iomem *docptr = doc->virtadr; 381 381 int i, numerrs, errpos[4]; 382 382 const uint8_t blank_read_hwecc[8] = { ··· 464 464 465 465 static uint8_t docg4_read_byte(struct mtd_info *mtd) 466 466 { 467 - struct nand_chip *nand = mtd->priv; 468 - struct docg4_priv *doc = nand->priv; 467 + struct nand_chip *nand = mtd_to_nand(mtd); 468 + struct docg4_priv *doc = nand_get_controller_data(nand); 469 469 470 470 dev_dbg(doc->dev, "%s\n", __func__); 471 471 ··· 545 545 * internal buffer out to the flash array, or some such. 546 546 */ 547 547 548 - struct nand_chip *nand = mtd->priv; 549 - struct docg4_priv *doc = nand->priv; 548 + struct nand_chip *nand = mtd_to_nand(mtd); 549 + struct docg4_priv *doc = nand_get_controller_data(nand); 550 550 void __iomem *docptr = doc->virtadr; 551 551 int retval = 0; 552 552 ··· 582 582 { 583 583 /* common starting sequence for all operations */ 584 584 585 - struct nand_chip *nand = mtd->priv; 586 - struct docg4_priv *doc = nand->priv; 585 + struct nand_chip *nand = mtd_to_nand(mtd); 586 + struct docg4_priv *doc = nand_get_controller_data(nand); 587 587 void __iomem *docptr = doc->virtadr; 588 588 589 589 writew(DOC_CTRL_UNKNOWN | DOC_CTRL_CE, docptr + DOC_FLASHCONTROL); ··· 599 599 { 600 600 /* first step in reading a page */ 601 601 602 - struct nand_chip *nand = mtd->priv; 603 - struct docg4_priv *doc = nand->priv; 602 + struct nand_chip *nand = mtd_to_nand(mtd); 603 + struct docg4_priv *doc = nand_get_controller_data(nand); 604 604 void __iomem *docptr = doc->virtadr; 605 605 606 606 dev_dbg(doc->dev, ··· 626 626 { 627 627 /* first step in writing a page */ 628 628 629 - struct nand_chip *nand = mtd->priv; 630 - struct docg4_priv *doc = nand->priv; 629 + struct nand_chip *nand = mtd_to_nand(mtd); 630 + struct docg4_priv *doc = nand_get_controller_data(nand); 631 631 void __iomem *docptr = doc->virtadr; 632 632 633 633 dev_dbg(doc->dev, ··· 691 691 { 692 692 /* handle standard nand commands */ 693 693 694 - struct nand_chip *nand = mtd->priv; 695 - struct docg4_priv *doc = nand->priv; 694 + struct nand_chip *nand = mtd_to_nand(mtd); 695 + struct docg4_priv *doc = nand_get_controller_data(nand); 696 696 uint32_t g4_addr = mtd_to_docg4_address(page_addr, column); 697 697 698 698 dev_dbg(doc->dev, "%s %x, page_addr=%x, column=%x\n", ··· 756 756 static int read_page(struct mtd_info *mtd, struct nand_chip *nand, 757 757 uint8_t *buf, int page, bool use_ecc) 758 758 { 759 - struct docg4_priv *doc = nand->priv; 759 + struct docg4_priv *doc = nand_get_controller_data(nand); 760 760 void __iomem *docptr = doc->virtadr; 761 761 uint16_t status, edc_err, *buf16; 762 762 int bits_corrected = 0; ··· 836 836 static int docg4_read_oob(struct mtd_info *mtd, struct nand_chip *nand, 837 837 int page) 838 838 { 839 - struct docg4_priv *doc = nand->priv; 839 + struct docg4_priv *doc = nand_get_controller_data(nand); 840 840 void __iomem *docptr = doc->virtadr; 841 841 uint16_t status; 842 842 ··· 874 874 875 875 static int docg4_erase_block(struct mtd_info *mtd, int page) 876 876 { 877 - struct nand_chip *nand = mtd->priv; 878 - struct docg4_priv *doc = nand->priv; 877 + struct nand_chip *nand = mtd_to_nand(mtd); 878 + struct docg4_priv *doc = nand_get_controller_data(nand); 879 879 void __iomem *docptr = doc->virtadr; 880 880 uint16_t g4_page; 881 881 ··· 923 923 static int write_page(struct mtd_info *mtd, struct nand_chip *nand, 924 924 const uint8_t *buf, bool use_ecc) 925 925 { 926 - struct docg4_priv *doc = nand->priv; 926 + struct docg4_priv *doc = nand_get_controller_data(nand); 927 927 void __iomem *docptr = doc->virtadr; 928 928 uint8_t ecc_buf[8]; 929 929 ··· 1003 1003 */ 1004 1004 1005 1005 /* note that bytes 7..14 are hw generated hamming/ecc and overwritten */ 1006 - struct docg4_priv *doc = nand->priv; 1006 + struct docg4_priv *doc = nand_get_controller_data(nand); 1007 1007 doc->oob_page = page; 1008 1008 memcpy(doc->oob_buf, nand->oob_poi, 16); 1009 1009 return 0; ··· 1016 1016 * update the memory-based bbt accordingly. 1017 1017 */ 1018 1018 1019 - struct nand_chip *nand = mtd->priv; 1020 - struct docg4_priv *doc = nand->priv; 1019 + struct nand_chip *nand = mtd_to_nand(mtd); 1020 + struct docg4_priv *doc = nand_get_controller_data(nand); 1021 1021 uint32_t g4_addr = mtd_to_docg4_address(DOCG4_FACTORY_BBT_PAGE, 0); 1022 1022 uint8_t *buf; 1023 1023 int i, block; ··· 1089 1089 1090 1090 int ret, i; 1091 1091 uint8_t *buf; 1092 - struct nand_chip *nand = mtd->priv; 1093 - struct docg4_priv *doc = nand->priv; 1092 + struct nand_chip *nand = mtd_to_nand(mtd); 1093 + struct docg4_priv *doc = nand_get_controller_data(nand); 1094 1094 struct nand_bbt_descr *bbtd = nand->badblock_pattern; 1095 1095 int page = (int)(ofs >> nand->page_shift); 1096 1096 uint32_t g4_addr = mtd_to_docg4_address(page, 0); ··· 1202 1202 * things as well, such as call nand_set_defaults(). 1203 1203 */ 1204 1204 1205 - struct nand_chip *nand = mtd->priv; 1206 - struct docg4_priv *doc = nand->priv; 1205 + struct nand_chip *nand = mtd_to_nand(mtd); 1206 + struct docg4_priv *doc = nand_get_controller_data(nand); 1207 1207 1208 1208 mtd->size = DOCG4_CHIP_SIZE; 1209 1209 mtd->name = "Msys_Diskonchip_G4"; ··· 1261 1261 1262 1262 static int __init read_id_reg(struct mtd_info *mtd) 1263 1263 { 1264 - struct nand_chip *nand = mtd->priv; 1265 - struct docg4_priv *doc = nand->priv; 1264 + struct nand_chip *nand = mtd_to_nand(mtd); 1265 + struct docg4_priv *doc = nand_get_controller_data(nand); 1266 1266 void __iomem *docptr = doc->virtadr; 1267 1267 uint16_t id1, id2; 1268 1268 ··· 1305 1305 return -EIO; 1306 1306 } 1307 1307 1308 - len = sizeof(struct mtd_info) + sizeof(struct nand_chip) + 1309 - sizeof(struct docg4_priv); 1310 - mtd = kzalloc(len, GFP_KERNEL); 1311 - if (mtd == NULL) { 1308 + len = sizeof(struct nand_chip) + sizeof(struct docg4_priv); 1309 + nand = kzalloc(len, GFP_KERNEL); 1310 + if (nand == NULL) { 1312 1311 retval = -ENOMEM; 1313 - goto fail; 1312 + goto fail_unmap; 1314 1313 } 1315 - nand = (struct nand_chip *) (mtd + 1); 1314 + 1315 + mtd = nand_to_mtd(nand); 1316 1316 doc = (struct docg4_priv *) (nand + 1); 1317 - mtd->priv = nand; 1318 - nand->priv = doc; 1317 + nand_set_controller_data(nand, doc); 1319 1318 mtd->dev.parent = &pdev->dev; 1320 1319 doc->virtadr = virtadr; 1321 1320 doc->dev = dev; ··· 1352 1353 doc->mtd = mtd; 1353 1354 return 0; 1354 1355 1355 - fail: 1356 + fail: 1357 + nand_release(mtd); /* deletes partitions and mtd devices */ 1358 + free_bch(doc->bch); 1359 + kfree(nand); 1360 + 1361 + fail_unmap: 1356 1362 iounmap(virtadr); 1357 - if (mtd) { 1358 - /* re-declarations avoid compiler warning */ 1359 - struct nand_chip *nand = mtd->priv; 1360 - struct docg4_priv *doc = nand->priv; 1361 - nand_release(mtd); /* deletes partitions and mtd devices */ 1362 - free_bch(doc->bch); 1363 - kfree(mtd); 1364 - } 1365 1363 1366 1364 return retval; 1367 1365 } ··· 1368 1372 struct docg4_priv *doc = platform_get_drvdata(pdev); 1369 1373 nand_release(doc->mtd); 1370 1374 free_bch(doc->bch); 1371 - kfree(doc->mtd); 1375 + kfree(mtd_to_nand(doc->mtd)); 1372 1376 iounmap(doc->virtadr); 1373 1377 return 0; 1374 1378 }
+33 -31
drivers/mtd/nand/fsl_elbc_nand.c
··· 48 48 /* mtd information per set */ 49 49 50 50 struct fsl_elbc_mtd { 51 - struct mtd_info mtd; 52 51 struct nand_chip chip; 53 52 struct fsl_lbc_ctrl *ctrl; 54 53 ··· 143 144 */ 144 145 static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob) 145 146 { 146 - struct nand_chip *chip = mtd->priv; 147 - struct fsl_elbc_mtd *priv = chip->priv; 147 + struct nand_chip *chip = mtd_to_nand(mtd); 148 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 148 149 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 149 150 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 150 151 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand; ··· 194 195 */ 195 196 static int fsl_elbc_run_command(struct mtd_info *mtd) 196 197 { 197 - struct nand_chip *chip = mtd->priv; 198 - struct fsl_elbc_mtd *priv = chip->priv; 198 + struct nand_chip *chip = mtd_to_nand(mtd); 199 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 199 200 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 200 201 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand; 201 202 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; ··· 267 268 268 269 static void fsl_elbc_do_read(struct nand_chip *chip, int oob) 269 270 { 270 - struct fsl_elbc_mtd *priv = chip->priv; 271 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 271 272 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 272 273 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 273 274 ··· 299 300 static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, 300 301 int column, int page_addr) 301 302 { 302 - struct nand_chip *chip = mtd->priv; 303 - struct fsl_elbc_mtd *priv = chip->priv; 303 + struct nand_chip *chip = mtd_to_nand(mtd); 304 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 304 305 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 305 306 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand; 306 307 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; ··· 524 525 */ 525 526 static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 526 527 { 527 - struct nand_chip *chip = mtd->priv; 528 - struct fsl_elbc_mtd *priv = chip->priv; 528 + struct nand_chip *chip = mtd_to_nand(mtd); 529 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 529 530 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand; 530 531 unsigned int bufsize = mtd->writesize + mtd->oobsize; 531 532 ··· 562 563 */ 563 564 static u8 fsl_elbc_read_byte(struct mtd_info *mtd) 564 565 { 565 - struct nand_chip *chip = mtd->priv; 566 - struct fsl_elbc_mtd *priv = chip->priv; 566 + struct nand_chip *chip = mtd_to_nand(mtd); 567 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 567 568 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand; 568 569 569 570 /* If there are still bytes in the FCM, then use the next byte. */ ··· 579 580 */ 580 581 static void fsl_elbc_read_buf(struct mtd_info *mtd, u8 *buf, int len) 581 582 { 582 - struct nand_chip *chip = mtd->priv; 583 - struct fsl_elbc_mtd *priv = chip->priv; 583 + struct nand_chip *chip = mtd_to_nand(mtd); 584 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 584 585 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand; 585 586 int avail; 586 587 ··· 604 605 */ 605 606 static int fsl_elbc_wait(struct mtd_info *mtd, struct nand_chip *chip) 606 607 { 607 - struct fsl_elbc_mtd *priv = chip->priv; 608 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 608 609 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand; 609 610 610 611 if (elbc_fcm_ctrl->status != LTESR_CC) ··· 618 619 619 620 static int fsl_elbc_chip_init_tail(struct mtd_info *mtd) 620 621 { 621 - struct nand_chip *chip = mtd->priv; 622 - struct fsl_elbc_mtd *priv = chip->priv; 622 + struct nand_chip *chip = mtd_to_nand(mtd); 623 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 623 624 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 624 625 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 625 626 unsigned int al; ··· 696 697 static int fsl_elbc_read_page(struct mtd_info *mtd, struct nand_chip *chip, 697 698 uint8_t *buf, int oob_required, int page) 698 699 { 699 - struct fsl_elbc_mtd *priv = chip->priv; 700 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 700 701 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 701 702 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand; 702 703 ··· 741 742 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 742 743 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand; 743 744 struct nand_chip *chip = &priv->chip; 745 + struct mtd_info *mtd = nand_to_mtd(chip); 744 746 745 747 dev_dbg(priv->dev, "eLBC Set Information for bank %d\n", priv->bank); 746 748 747 749 /* Fill in fsl_elbc_mtd structure */ 748 - priv->mtd.priv = chip; 749 - priv->mtd.dev.parent = priv->dev; 750 + mtd->dev.parent = priv->dev; 751 + nand_set_flash_node(chip, priv->dev->of_node); 750 752 751 753 /* set timeout to maximum */ 752 754 priv->fmr = 15 << FMR_CWTO_SHIFT; ··· 770 770 chip->bbt_options = NAND_BBT_USE_FLASH; 771 771 772 772 chip->controller = &elbc_fcm_ctrl->controller; 773 - chip->priv = priv; 773 + nand_set_controller_data(chip, priv); 774 774 775 775 chip->ecc.read_page = fsl_elbc_read_page; 776 776 chip->ecc.write_page = fsl_elbc_write_page; ··· 797 797 static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv) 798 798 { 799 799 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand; 800 - nand_release(&priv->mtd); 800 + struct mtd_info *mtd = nand_to_mtd(&priv->chip); 801 801 802 - kfree(priv->mtd.name); 802 + nand_release(mtd); 803 + 804 + kfree(mtd->name); 803 805 804 806 if (priv->vbase) 805 807 iounmap(priv->vbase); ··· 825 823 int bank; 826 824 struct device *dev; 827 825 struct device_node *node = pdev->dev.of_node; 828 - struct mtd_part_parser_data ppdata; 826 + struct mtd_info *mtd; 829 827 830 - ppdata.of_node = pdev->dev.of_node; 831 828 if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs) 832 829 return -ENODEV; 833 830 lbc = fsl_lbc_ctrl_dev->regs; ··· 888 887 goto err; 889 888 } 890 889 891 - priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start); 892 - if (!priv->mtd.name) { 890 + mtd = nand_to_mtd(&priv->chip); 891 + mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start); 892 + if (!nand_to_mtd(&priv->chip)->name) { 893 893 ret = -ENOMEM; 894 894 goto err; 895 895 } ··· 899 897 if (ret) 900 898 goto err; 901 899 902 - ret = nand_scan_ident(&priv->mtd, 1, NULL); 900 + ret = nand_scan_ident(mtd, 1, NULL); 903 901 if (ret) 904 902 goto err; 905 903 906 - ret = fsl_elbc_chip_init_tail(&priv->mtd); 904 + ret = fsl_elbc_chip_init_tail(mtd); 907 905 if (ret) 908 906 goto err; 909 907 910 - ret = nand_scan_tail(&priv->mtd); 908 + ret = nand_scan_tail(mtd); 911 909 if (ret) 912 910 goto err; 913 911 914 912 /* First look for RedBoot table or partitions on the command 915 913 * line, these take precedence over device tree information */ 916 - mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata, 914 + mtd_device_parse_register(mtd, part_probe_types, NULL, 917 915 NULL, 0); 918 916 919 917 printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
+38 -36
drivers/mtd/nand/fsl_ifc_nand.c
··· 40 40 41 41 /* mtd information per set */ 42 42 struct fsl_ifc_mtd { 43 - struct mtd_info mtd; 44 43 struct nand_chip chip; 45 44 struct fsl_ifc_ctrl *ctrl; 46 45 ··· 229 230 */ 230 231 static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob) 231 232 { 232 - struct nand_chip *chip = mtd->priv; 233 - struct fsl_ifc_mtd *priv = chip->priv; 233 + struct nand_chip *chip = mtd_to_nand(mtd); 234 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 234 235 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 235 236 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 236 237 int buf_num; ··· 252 253 253 254 static int is_blank(struct mtd_info *mtd, unsigned int bufnum) 254 255 { 255 - struct nand_chip *chip = mtd->priv; 256 - struct fsl_ifc_mtd *priv = chip->priv; 256 + struct nand_chip *chip = mtd_to_nand(mtd); 257 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 257 258 u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2); 258 259 u32 __iomem *mainarea = (u32 __iomem *)addr; 259 260 u8 __iomem *oob = addr + mtd->writesize; ··· 291 292 */ 292 293 static void fsl_ifc_run_command(struct mtd_info *mtd) 293 294 { 294 - struct nand_chip *chip = mtd->priv; 295 - struct fsl_ifc_mtd *priv = chip->priv; 295 + struct nand_chip *chip = mtd_to_nand(mtd); 296 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 296 297 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 297 298 struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl; 298 299 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; ··· 369 370 int oob, 370 371 struct mtd_info *mtd) 371 372 { 372 - struct fsl_ifc_mtd *priv = chip->priv; 373 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 373 374 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 374 375 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 375 376 ··· 408 409 /* cmdfunc send commands to the IFC NAND Machine */ 409 410 static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command, 410 411 int column, int page_addr) { 411 - struct nand_chip *chip = mtd->priv; 412 - struct fsl_ifc_mtd *priv = chip->priv; 412 + struct nand_chip *chip = mtd_to_nand(mtd); 413 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 413 414 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 414 415 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 415 416 ··· 623 624 */ 624 625 static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 625 626 { 626 - struct nand_chip *chip = mtd->priv; 627 - struct fsl_ifc_mtd *priv = chip->priv; 627 + struct nand_chip *chip = mtd_to_nand(mtd); 628 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 628 629 unsigned int bufsize = mtd->writesize + mtd->oobsize; 629 630 630 631 if (len <= 0) { ··· 649 650 */ 650 651 static uint8_t fsl_ifc_read_byte(struct mtd_info *mtd) 651 652 { 652 - struct nand_chip *chip = mtd->priv; 653 - struct fsl_ifc_mtd *priv = chip->priv; 653 + struct nand_chip *chip = mtd_to_nand(mtd); 654 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 654 655 unsigned int offset; 655 656 656 657 /* ··· 672 673 */ 673 674 static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd) 674 675 { 675 - struct nand_chip *chip = mtd->priv; 676 - struct fsl_ifc_mtd *priv = chip->priv; 676 + struct nand_chip *chip = mtd_to_nand(mtd); 677 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 677 678 uint16_t data; 678 679 679 680 /* ··· 695 696 */ 696 697 static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len) 697 698 { 698 - struct nand_chip *chip = mtd->priv; 699 - struct fsl_ifc_mtd *priv = chip->priv; 699 + struct nand_chip *chip = mtd_to_nand(mtd); 700 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 700 701 int avail; 701 702 702 703 if (len < 0) { ··· 721 722 */ 722 723 static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip) 723 724 { 724 - struct fsl_ifc_mtd *priv = chip->priv; 725 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 725 726 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 726 727 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 727 728 u32 nand_fsr; ··· 750 751 static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip, 751 752 uint8_t *buf, int oob_required, int page) 752 753 { 753 - struct fsl_ifc_mtd *priv = chip->priv; 754 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 754 755 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 755 756 struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl; 756 757 ··· 781 782 782 783 static int fsl_ifc_chip_init_tail(struct mtd_info *mtd) 783 784 { 784 - struct nand_chip *chip = mtd->priv; 785 - struct fsl_ifc_mtd *priv = chip->priv; 785 + struct nand_chip *chip = mtd_to_nand(mtd); 786 + struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 786 787 787 788 dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__, 788 789 chip->numchips); ··· 876 877 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 877 878 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 878 879 struct nand_chip *chip = &priv->chip; 880 + struct mtd_info *mtd = nand_to_mtd(&priv->chip); 879 881 struct nand_ecclayout *layout; 880 882 u32 csor; 881 883 882 884 /* Fill in fsl_ifc_mtd structure */ 883 - priv->mtd.priv = chip; 884 - priv->mtd.dev.parent = priv->dev; 885 + mtd->dev.parent = priv->dev; 886 + nand_set_flash_node(chip, priv->dev->of_node); 885 887 886 888 /* fill in nand_chip structure */ 887 889 /* set up function call table */ ··· 914 914 } 915 915 916 916 chip->controller = &ifc_nand_ctrl->controller; 917 - chip->priv = priv; 917 + nand_set_controller_data(chip, priv); 918 918 919 919 chip->ecc.read_page = fsl_ifc_read_page; 920 920 chip->ecc.write_page = fsl_ifc_write_page; ··· 993 993 994 994 static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv) 995 995 { 996 - nand_release(&priv->mtd); 996 + struct mtd_info *mtd = nand_to_mtd(&priv->chip); 997 997 998 - kfree(priv->mtd.name); 998 + nand_release(mtd); 999 + 1000 + kfree(mtd->name); 999 1001 1000 1002 if (priv->vbase) 1001 1003 iounmap(priv->vbase); ··· 1032 1030 int ret; 1033 1031 int bank; 1034 1032 struct device_node *node = dev->dev.of_node; 1035 - struct mtd_part_parser_data ppdata; 1033 + struct mtd_info *mtd; 1036 1034 1037 - ppdata.of_node = dev->dev.of_node; 1038 1035 if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs) 1039 1036 return -ENODEV; 1040 1037 ifc = fsl_ifc_ctrl_dev->regs; ··· 1105 1104 IFC_NAND_EVTER_INTR_FTOERIR_EN | 1106 1105 IFC_NAND_EVTER_INTR_WPERIR_EN, 1107 1106 &ifc->ifc_nand.nand_evter_intr_en); 1108 - priv->mtd.name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start); 1109 - if (!priv->mtd.name) { 1107 + 1108 + mtd = nand_to_mtd(&priv->chip); 1109 + mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start); 1110 + if (!mtd->name) { 1110 1111 ret = -ENOMEM; 1111 1112 goto err; 1112 1113 } ··· 1117 1114 if (ret) 1118 1115 goto err; 1119 1116 1120 - ret = nand_scan_ident(&priv->mtd, 1, NULL); 1117 + ret = nand_scan_ident(mtd, 1, NULL); 1121 1118 if (ret) 1122 1119 goto err; 1123 1120 1124 - ret = fsl_ifc_chip_init_tail(&priv->mtd); 1121 + ret = fsl_ifc_chip_init_tail(mtd); 1125 1122 if (ret) 1126 1123 goto err; 1127 1124 1128 - ret = nand_scan_tail(&priv->mtd); 1125 + ret = nand_scan_tail(mtd); 1129 1126 if (ret) 1130 1127 goto err; 1131 1128 1132 1129 /* First look for RedBoot table or partitions on the command 1133 1130 * line, these take precedence over device tree information */ 1134 - mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata, 1135 - NULL, 0); 1131 + mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0); 1136 1132 1137 1133 dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n", 1138 1134 (unsigned long long)res.start, priv->bank);
+18 -17
drivers/mtd/nand/fsl_upm.c
··· 31 31 32 32 struct fsl_upm_nand { 33 33 struct device *dev; 34 - struct mtd_info mtd; 35 34 struct nand_chip chip; 36 35 int last_ctrl; 37 36 struct mtd_partition *parts; ··· 48 49 49 50 static inline struct fsl_upm_nand *to_fsl_upm_nand(struct mtd_info *mtdinfo) 50 51 { 51 - return container_of(mtdinfo, struct fsl_upm_nand, mtd); 52 + return container_of(mtd_to_nand(mtdinfo), struct fsl_upm_nand, 53 + chip); 52 54 } 53 55 54 56 static int fun_chip_ready(struct mtd_info *mtd) ··· 66 66 static void fun_wait_rnb(struct fsl_upm_nand *fun) 67 67 { 68 68 if (fun->rnb_gpio[fun->mchip_number] >= 0) { 69 + struct mtd_info *mtd = nand_to_mtd(&fun->chip); 69 70 int cnt = 1000000; 70 71 71 - while (--cnt && !fun_chip_ready(&fun->mtd)) 72 + while (--cnt && !fun_chip_ready(mtd)) 72 73 cpu_relax(); 73 74 if (!cnt) 74 75 dev_err(fun->dev, "tired waiting for RNB\n"); ··· 80 79 81 80 static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 82 81 { 83 - struct nand_chip *chip = mtd->priv; 82 + struct nand_chip *chip = mtd_to_nand(mtd); 84 83 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd); 85 84 u32 mar; 86 85 ··· 110 109 111 110 static void fun_select_chip(struct mtd_info *mtd, int mchip_nr) 112 111 { 113 - struct nand_chip *chip = mtd->priv; 112 + struct nand_chip *chip = mtd_to_nand(mtd); 114 113 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd); 115 114 116 115 if (mchip_nr == -1) { ··· 158 157 const struct device_node *upm_np, 159 158 const struct resource *io_res) 160 159 { 160 + struct mtd_info *mtd = nand_to_mtd(&fun->chip); 161 161 int ret; 162 162 struct device_node *flash_np; 163 - struct mtd_part_parser_data ppdata; 164 163 165 164 fun->chip.IO_ADDR_R = fun->io_base; 166 165 fun->chip.IO_ADDR_W = fun->io_base; ··· 176 175 if (fun->rnb_gpio[0] >= 0) 177 176 fun->chip.dev_ready = fun_chip_ready; 178 177 179 - fun->mtd.priv = &fun->chip; 180 - fun->mtd.dev.parent = fun->dev; 178 + mtd->dev.parent = fun->dev; 181 179 182 180 flash_np = of_get_next_child(upm_np, NULL); 183 181 if (!flash_np) 184 182 return -ENODEV; 185 183 186 - fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start, 187 - flash_np->name); 188 - if (!fun->mtd.name) { 184 + nand_set_flash_node(&fun->chip, flash_np); 185 + mtd->name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start, 186 + flash_np->name); 187 + if (!mtd->name) { 189 188 ret = -ENOMEM; 190 189 goto err; 191 190 } 192 191 193 - ret = nand_scan(&fun->mtd, fun->mchip_count); 192 + ret = nand_scan(mtd, fun->mchip_count); 194 193 if (ret) 195 194 goto err; 196 195 197 - ppdata.of_node = flash_np; 198 - ret = mtd_device_parse_register(&fun->mtd, NULL, &ppdata, NULL, 0); 196 + ret = mtd_device_register(mtd, NULL, 0); 199 197 err: 200 198 of_node_put(flash_np); 201 199 if (ret) 202 - kfree(fun->mtd.name); 200 + kfree(mtd->name); 203 201 return ret; 204 202 } 205 203 ··· 322 322 static int fun_remove(struct platform_device *ofdev) 323 323 { 324 324 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); 325 + struct mtd_info *mtd = nand_to_mtd(&fun->chip); 325 326 int i; 326 327 327 - nand_release(&fun->mtd); 328 - kfree(fun->mtd.name); 328 + nand_release(mtd); 329 + kfree(mtd->name); 329 330 330 331 for (i = 0; i < fun->mchip_count; i++) { 331 332 if (fun->rnb_gpio[i] < 0)
+31 -38
drivers/mtd/nand/fsmc_nand.c
··· 299 299 */ 300 300 struct fsmc_nand_data { 301 301 u32 pid; 302 - struct mtd_info mtd; 303 302 struct nand_chip nand; 304 303 struct mtd_partition *partitions; 305 304 unsigned int nr_partitions; ··· 325 326 void (*select_chip)(uint32_t bank, uint32_t busw); 326 327 }; 327 328 329 + static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd) 330 + { 331 + return container_of(mtd_to_nand(mtd), struct fsmc_nand_data, nand); 332 + } 333 + 328 334 /* Assert CS signal based on chipnr */ 329 335 static void fsmc_select_chip(struct mtd_info *mtd, int chipnr) 330 336 { 331 - struct nand_chip *chip = mtd->priv; 337 + struct nand_chip *chip = mtd_to_nand(mtd); 332 338 struct fsmc_nand_data *host; 333 339 334 - host = container_of(mtd, struct fsmc_nand_data, mtd); 340 + host = mtd_to_fsmc(mtd); 335 341 336 342 switch (chipnr) { 337 343 case -1: ··· 362 358 */ 363 359 static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 364 360 { 365 - struct nand_chip *this = mtd->priv; 366 - struct fsmc_nand_data *host = container_of(mtd, 367 - struct fsmc_nand_data, mtd); 361 + struct nand_chip *this = mtd_to_nand(mtd); 362 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 368 363 void __iomem *regs = host->regs_va; 369 364 unsigned int bank = host->bank; 370 365 ··· 448 445 */ 449 446 static void fsmc_enable_hwecc(struct mtd_info *mtd, int mode) 450 447 { 451 - struct fsmc_nand_data *host = container_of(mtd, 452 - struct fsmc_nand_data, mtd); 448 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 453 449 void __iomem *regs = host->regs_va; 454 450 uint32_t bank = host->bank; 455 451 ··· 468 466 static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data, 469 467 uint8_t *ecc) 470 468 { 471 - struct fsmc_nand_data *host = container_of(mtd, 472 - struct fsmc_nand_data, mtd); 469 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 473 470 void __iomem *regs = host->regs_va; 474 471 uint32_t bank = host->bank; 475 472 uint32_t ecc_tmp; ··· 518 517 static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data, 519 518 uint8_t *ecc) 520 519 { 521 - struct fsmc_nand_data *host = container_of(mtd, 522 - struct fsmc_nand_data, mtd); 520 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 523 521 void __iomem *regs = host->regs_va; 524 522 uint32_t bank = host->bank; 525 523 uint32_t ecc_tmp; ··· 629 629 static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 630 630 { 631 631 int i; 632 - struct nand_chip *chip = mtd->priv; 632 + struct nand_chip *chip = mtd_to_nand(mtd); 633 633 634 634 if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) && 635 635 IS_ALIGNED(len, sizeof(uint32_t))) { ··· 652 652 static void fsmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 653 653 { 654 654 int i; 655 - struct nand_chip *chip = mtd->priv; 655 + struct nand_chip *chip = mtd_to_nand(mtd); 656 656 657 657 if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) && 658 658 IS_ALIGNED(len, sizeof(uint32_t))) { ··· 674 674 */ 675 675 static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t *buf, int len) 676 676 { 677 - struct fsmc_nand_data *host; 677 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 678 678 679 - host = container_of(mtd, struct fsmc_nand_data, mtd); 680 679 dma_xfer(host, buf, len, DMA_FROM_DEVICE); 681 680 } 682 681 ··· 688 689 static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf, 689 690 int len) 690 691 { 691 - struct fsmc_nand_data *host; 692 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 692 693 693 - host = container_of(mtd, struct fsmc_nand_data, mtd); 694 694 dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE); 695 695 } 696 696 ··· 710 712 static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 711 713 uint8_t *buf, int oob_required, int page) 712 714 { 713 - struct fsmc_nand_data *host = container_of(mtd, 714 - struct fsmc_nand_data, mtd); 715 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 715 716 struct fsmc_eccplace *ecc_place = host->ecc_place; 716 717 int i, j, s, stat, eccsize = chip->ecc.size; 717 718 int eccbytes = chip->ecc.bytes; ··· 779 782 static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat, 780 783 uint8_t *read_ecc, uint8_t *calc_ecc) 781 784 { 782 - struct fsmc_nand_data *host = container_of(mtd, 783 - struct fsmc_nand_data, mtd); 784 - struct nand_chip *chip = mtd->priv; 785 + struct nand_chip *chip = mtd_to_nand(mtd); 786 + struct fsmc_nand_data *host = mtd_to_fsmc(mtd); 785 787 void __iomem *regs = host->regs_va; 786 788 unsigned int bank = host->bank; 787 789 uint32_t err_idx[8]; ··· 922 926 { 923 927 struct fsmc_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 924 928 struct device_node __maybe_unused *np = pdev->dev.of_node; 925 - struct mtd_part_parser_data ppdata = {}; 926 929 struct fsmc_nand_data *host; 927 930 struct mtd_info *mtd; 928 931 struct nand_chip *nand; ··· 1007 1012 init_completion(&host->dma_access_complete); 1008 1013 1009 1014 /* Link all private pointers */ 1010 - mtd = &host->mtd; 1015 + mtd = nand_to_mtd(&host->nand); 1011 1016 nand = &host->nand; 1012 - mtd->priv = nand; 1013 - nand->priv = host; 1017 + nand_set_controller_data(nand, host); 1018 + nand_set_flash_node(nand, np); 1014 1019 1015 - host->mtd.dev.parent = &pdev->dev; 1020 + mtd->dev.parent = &pdev->dev; 1016 1021 nand->IO_ADDR_R = host->data_va; 1017 1022 nand->IO_ADDR_W = host->data_va; 1018 1023 nand->cmd_ctrl = fsmc_cmd_ctrl; ··· 1028 1033 nand->options = pdata->options; 1029 1034 nand->select_chip = fsmc_select_chip; 1030 1035 nand->badblockbits = 7; 1031 - nand->flash_node = np; 1036 + nand_set_flash_node(nand, np); 1032 1037 1033 1038 if (pdata->width == FSMC_NAND_BW16) 1034 1039 nand->options |= NAND_BUSWIDTH_16; ··· 1075 1080 /* 1076 1081 * Scan to find existence of the device 1077 1082 */ 1078 - if (nand_scan_ident(&host->mtd, 1, NULL)) { 1083 + if (nand_scan_ident(mtd, 1, NULL)) { 1079 1084 ret = -ENXIO; 1080 1085 dev_err(&pdev->dev, "No NAND Device found!\n"); 1081 1086 goto err_scan_ident; 1082 1087 } 1083 1088 1084 1089 if (AMBA_REV_BITS(host->pid) >= 8) { 1085 - switch (host->mtd.oobsize) { 1090 + switch (mtd->oobsize) { 1086 1091 case 16: 1087 1092 nand->ecc.layout = &fsmc_ecc4_16_layout; 1088 1093 host->ecc_place = &fsmc_ecc4_sp_place; ··· 1133 1138 * generated later in nand_bch_init() later. 1134 1139 */ 1135 1140 if (nand->ecc.mode != NAND_ECC_SOFT_BCH) { 1136 - switch (host->mtd.oobsize) { 1141 + switch (mtd->oobsize) { 1137 1142 case 16: 1138 1143 nand->ecc.layout = &fsmc_ecc1_16_layout; 1139 1144 break; ··· 1154 1159 } 1155 1160 1156 1161 /* Second stage of scan to fill MTD data-structures */ 1157 - if (nand_scan_tail(&host->mtd)) { 1162 + if (nand_scan_tail(mtd)) { 1158 1163 ret = -ENXIO; 1159 1164 goto err_probe; 1160 1165 } ··· 1169 1174 /* 1170 1175 * Check for partition info passed 1171 1176 */ 1172 - host->mtd.name = "nand"; 1173 - ppdata.of_node = np; 1174 - ret = mtd_device_parse_register(&host->mtd, NULL, &ppdata, 1175 - host->partitions, host->nr_partitions); 1177 + mtd->name = "nand"; 1178 + ret = mtd_device_register(mtd, host->partitions, host->nr_partitions); 1176 1179 if (ret) 1177 1180 goto err_probe; 1178 1181 ··· 1200 1207 struct fsmc_nand_data *host = platform_get_drvdata(pdev); 1201 1208 1202 1209 if (host) { 1203 - nand_release(&host->mtd); 1210 + nand_release(nand_to_mtd(&host->nand)); 1204 1211 1205 1212 if (host->mode == USE_DMA_ACCESS) { 1206 1213 dma_release_channel(host->write_dma_chan);
+13 -13
drivers/mtd/nand/gpio.c
··· 35 35 36 36 struct gpiomtd { 37 37 void __iomem *io_sync; 38 - struct mtd_info mtd_info; 39 38 struct nand_chip nand_chip; 40 39 struct gpio_nand_platdata plat; 41 40 }; 42 41 43 - #define gpio_nand_getpriv(x) container_of(x, struct gpiomtd, mtd_info) 42 + static inline struct gpiomtd *gpio_nand_getpriv(struct mtd_info *mtd) 43 + { 44 + return container_of(mtd_to_nand(mtd), struct gpiomtd, nand_chip); 45 + } 44 46 45 47 46 48 #ifdef CONFIG_ARM ··· 197 195 { 198 196 struct gpiomtd *gpiomtd = platform_get_drvdata(pdev); 199 197 200 - nand_release(&gpiomtd->mtd_info); 198 + nand_release(nand_to_mtd(&gpiomtd->nand_chip)); 201 199 202 200 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 203 201 gpio_set_value(gpiomtd->plat.gpio_nwp, 0); ··· 210 208 { 211 209 struct gpiomtd *gpiomtd; 212 210 struct nand_chip *chip; 211 + struct mtd_info *mtd; 213 212 struct resource *res; 214 - struct mtd_part_parser_data ppdata = {}; 215 213 int ret = 0; 216 214 217 215 if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev)) ··· 270 268 chip->dev_ready = gpio_nand_devready; 271 269 } 272 270 271 + nand_set_flash_node(chip, pdev->dev.of_node); 273 272 chip->IO_ADDR_W = chip->IO_ADDR_R; 274 273 chip->ecc.mode = NAND_ECC_SOFT; 275 274 chip->options = gpiomtd->plat.options; 276 275 chip->chip_delay = gpiomtd->plat.chip_delay; 277 276 chip->cmd_ctrl = gpio_nand_cmd_ctrl; 278 277 279 - gpiomtd->mtd_info.priv = chip; 280 - gpiomtd->mtd_info.dev.parent = &pdev->dev; 278 + mtd = nand_to_mtd(chip); 279 + mtd->dev.parent = &pdev->dev; 281 280 282 281 platform_set_drvdata(pdev, gpiomtd); 283 282 284 283 if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) 285 284 gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); 286 285 287 - if (nand_scan(&gpiomtd->mtd_info, 1)) { 286 + if (nand_scan(mtd, 1)) { 288 287 ret = -ENXIO; 289 288 goto err_wp; 290 289 } 291 290 292 291 if (gpiomtd->plat.adjust_parts) 293 - gpiomtd->plat.adjust_parts(&gpiomtd->plat, 294 - gpiomtd->mtd_info.size); 292 + gpiomtd->plat.adjust_parts(&gpiomtd->plat, mtd->size); 295 293 296 - ppdata.of_node = pdev->dev.of_node; 297 - ret = mtd_device_parse_register(&gpiomtd->mtd_info, NULL, &ppdata, 298 - gpiomtd->plat.parts, 299 - gpiomtd->plat.num_parts); 294 + ret = mtd_device_register(mtd, gpiomtd->plat.parts, 295 + gpiomtd->plat.num_parts); 300 296 if (!ret) 301 297 return 0; 302 298
+1 -1
drivers/mtd/nand/gpmi-nand/gpmi-lib.c
··· 919 919 { 920 920 struct resources *r = &this->resources; 921 921 struct nand_chip *nand = &this->nand; 922 - struct mtd_info *mtd = &this->mtd; 922 + struct mtd_info *mtd = nand_to_mtd(nand); 923 923 uint8_t *feature; 924 924 unsigned long rate; 925 925 int ret;
+34 -37
drivers/mtd/nand/gpmi-nand/gpmi-nand.c
··· 107 107 static inline int get_ecc_strength(struct gpmi_nand_data *this) 108 108 { 109 109 struct bch_geometry *geo = &this->bch_geometry; 110 - struct mtd_info *mtd = &this->mtd; 110 + struct mtd_info *mtd = nand_to_mtd(&this->nand); 111 111 int ecc_strength; 112 112 113 113 ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8) ··· 139 139 static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this) 140 140 { 141 141 struct bch_geometry *geo = &this->bch_geometry; 142 - struct mtd_info *mtd = &this->mtd; 143 - struct nand_chip *chip = mtd->priv; 142 + struct nand_chip *chip = &this->nand; 143 + struct mtd_info *mtd = nand_to_mtd(chip); 144 144 struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree; 145 145 unsigned int block_mark_bit_offset; 146 146 ··· 257 257 static int legacy_set_geometry(struct gpmi_nand_data *this) 258 258 { 259 259 struct bch_geometry *geo = &this->bch_geometry; 260 - struct mtd_info *mtd = &this->mtd; 260 + struct mtd_info *mtd = nand_to_mtd(&this->nand); 261 261 unsigned int metadata_size; 262 262 unsigned int status_size; 263 263 unsigned int block_mark_bit_offset; ··· 804 804 { 805 805 struct bch_geometry *geo = &this->bch_geometry; 806 806 struct device *dev = this->dev; 807 - struct mtd_info *mtd = &this->mtd; 807 + struct mtd_info *mtd = nand_to_mtd(&this->nand); 808 808 809 809 /* [1] Allocate a command buffer. PAGE_SIZE is enough. */ 810 810 this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL); ··· 856 856 857 857 static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl) 858 858 { 859 - struct nand_chip *chip = mtd->priv; 860 - struct gpmi_nand_data *this = chip->priv; 859 + struct nand_chip *chip = mtd_to_nand(mtd); 860 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 861 861 int ret; 862 862 863 863 /* ··· 890 890 891 891 static int gpmi_dev_ready(struct mtd_info *mtd) 892 892 { 893 - struct nand_chip *chip = mtd->priv; 894 - struct gpmi_nand_data *this = chip->priv; 893 + struct nand_chip *chip = mtd_to_nand(mtd); 894 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 895 895 896 896 return gpmi_is_ready(this, this->current_chip); 897 897 } 898 898 899 899 static void gpmi_select_chip(struct mtd_info *mtd, int chipnr) 900 900 { 901 - struct nand_chip *chip = mtd->priv; 902 - struct gpmi_nand_data *this = chip->priv; 901 + struct nand_chip *chip = mtd_to_nand(mtd); 902 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 903 903 904 904 if ((this->current_chip < 0) && (chipnr >= 0)) 905 905 gpmi_begin(this); ··· 911 911 912 912 static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 913 913 { 914 - struct nand_chip *chip = mtd->priv; 915 - struct gpmi_nand_data *this = chip->priv; 914 + struct nand_chip *chip = mtd_to_nand(mtd); 915 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 916 916 917 917 dev_dbg(this->dev, "len is %d\n", len); 918 918 this->upper_buf = buf; ··· 923 923 924 924 static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 925 925 { 926 - struct nand_chip *chip = mtd->priv; 927 - struct gpmi_nand_data *this = chip->priv; 926 + struct nand_chip *chip = mtd_to_nand(mtd); 927 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 928 928 929 929 dev_dbg(this->dev, "len is %d\n", len); 930 930 this->upper_buf = (uint8_t *)buf; ··· 935 935 936 936 static uint8_t gpmi_read_byte(struct mtd_info *mtd) 937 937 { 938 - struct nand_chip *chip = mtd->priv; 939 - struct gpmi_nand_data *this = chip->priv; 938 + struct nand_chip *chip = mtd_to_nand(mtd); 939 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 940 940 uint8_t *buf = this->data_buffer_dma; 941 941 942 942 gpmi_read_buf(mtd, buf, 1); ··· 994 994 static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, 995 995 uint8_t *buf, int oob_required, int page) 996 996 { 997 - struct gpmi_nand_data *this = chip->priv; 997 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 998 998 struct bch_geometry *nfc_geo = &this->bch_geometry; 999 999 void *payload_virt; 1000 1000 dma_addr_t payload_phys; ··· 1074 1074 static int gpmi_ecc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, 1075 1075 uint32_t offs, uint32_t len, uint8_t *buf, int page) 1076 1076 { 1077 - struct gpmi_nand_data *this = chip->priv; 1077 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1078 1078 void __iomem *bch_regs = this->resources.bch_regs; 1079 1079 struct bch_geometry old_geo = this->bch_geometry; 1080 1080 struct bch_geometry *geo = &this->bch_geometry; ··· 1162 1162 static int gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1163 1163 const uint8_t *buf, int oob_required, int page) 1164 1164 { 1165 - struct gpmi_nand_data *this = chip->priv; 1165 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1166 1166 struct bch_geometry *nfc_geo = &this->bch_geometry; 1167 1167 const void *payload_virt; 1168 1168 dma_addr_t payload_phys; ··· 1298 1298 static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 1299 1299 int page) 1300 1300 { 1301 - struct gpmi_nand_data *this = chip->priv; 1301 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1302 1302 1303 1303 dev_dbg(this->dev, "page number is %d\n", page); 1304 1304 /* clear the OOB buffer */ ··· 1359 1359 struct nand_chip *chip, uint8_t *buf, 1360 1360 int oob_required, int page) 1361 1361 { 1362 - struct gpmi_nand_data *this = chip->priv; 1362 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1363 1363 struct bch_geometry *nfc_geo = &this->bch_geometry; 1364 1364 int eccsize = nfc_geo->ecc_chunk_size; 1365 1365 int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; ··· 1448 1448 const uint8_t *buf, 1449 1449 int oob_required, int page) 1450 1450 { 1451 - struct gpmi_nand_data *this = chip->priv; 1451 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1452 1452 struct bch_geometry *nfc_geo = &this->bch_geometry; 1453 1453 int eccsize = nfc_geo->ecc_chunk_size; 1454 1454 int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; ··· 1538 1538 1539 1539 static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs) 1540 1540 { 1541 - struct nand_chip *chip = mtd->priv; 1542 - struct gpmi_nand_data *this = chip->priv; 1541 + struct nand_chip *chip = mtd_to_nand(mtd); 1542 + struct gpmi_nand_data *this = nand_get_controller_data(chip); 1543 1543 int ret = 0; 1544 1544 uint8_t *block_mark; 1545 1545 int column, page, status, chipnr; ··· 1600 1600 { 1601 1601 struct boot_rom_geometry *rom_geo = &this->rom_geometry; 1602 1602 struct device *dev = this->dev; 1603 - struct mtd_info *mtd = &this->mtd; 1604 1603 struct nand_chip *chip = &this->nand; 1604 + struct mtd_info *mtd = nand_to_mtd(chip); 1605 1605 unsigned int search_area_size_in_strides; 1606 1606 unsigned int stride; 1607 1607 unsigned int page; ··· 1655 1655 { 1656 1656 struct device *dev = this->dev; 1657 1657 struct boot_rom_geometry *rom_geo = &this->rom_geometry; 1658 - struct mtd_info *mtd = &this->mtd; 1659 1658 struct nand_chip *chip = &this->nand; 1659 + struct mtd_info *mtd = nand_to_mtd(chip); 1660 1660 unsigned int block_size_in_pages; 1661 1661 unsigned int search_area_size_in_strides; 1662 1662 unsigned int search_area_size_in_pages; ··· 1735 1735 { 1736 1736 struct device *dev = this->dev; 1737 1737 struct nand_chip *chip = &this->nand; 1738 - struct mtd_info *mtd = &this->mtd; 1738 + struct mtd_info *mtd = nand_to_mtd(chip); 1739 1739 unsigned int block_count; 1740 1740 unsigned int block; 1741 1741 int chipnr; ··· 1831 1831 1832 1832 static void gpmi_nand_exit(struct gpmi_nand_data *this) 1833 1833 { 1834 - nand_release(&this->mtd); 1834 + nand_release(nand_to_mtd(&this->nand)); 1835 1835 gpmi_free_dma_buffer(this); 1836 1836 } 1837 1837 1838 1838 static int gpmi_init_last(struct gpmi_nand_data *this) 1839 1839 { 1840 - struct mtd_info *mtd = &this->mtd; 1841 - struct nand_chip *chip = mtd->priv; 1840 + struct nand_chip *chip = &this->nand; 1842 1841 struct nand_ecc_ctrl *ecc = &chip->ecc; 1843 1842 struct bch_geometry *bch_geo = &this->bch_geometry; 1844 1843 int ret; ··· 1885 1886 1886 1887 static int gpmi_nand_init(struct gpmi_nand_data *this) 1887 1888 { 1888 - struct mtd_info *mtd = &this->mtd; 1889 1889 struct nand_chip *chip = &this->nand; 1890 - struct mtd_part_parser_data ppdata = {}; 1890 + struct mtd_info *mtd = nand_to_mtd(chip); 1891 1891 int ret; 1892 1892 1893 1893 /* init current chip */ 1894 1894 this->current_chip = -1; 1895 1895 1896 1896 /* init the MTD data structures */ 1897 - mtd->priv = chip; 1898 1897 mtd->name = "gpmi-nand"; 1899 1898 mtd->dev.parent = this->dev; 1900 1899 1901 1900 /* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */ 1902 - chip->priv = this; 1901 + nand_set_controller_data(chip, this); 1902 + nand_set_flash_node(chip, this->pdev->dev.of_node); 1903 1903 chip->select_chip = gpmi_select_chip; 1904 1904 chip->cmd_ctrl = gpmi_cmd_ctrl; 1905 1905 chip->dev_ready = gpmi_dev_ready; ··· 1952 1954 if (ret) 1953 1955 goto err_out; 1954 1956 1955 - ppdata.of_node = this->pdev->dev.of_node; 1956 - ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 1957 + ret = mtd_device_register(mtd, NULL, 0); 1957 1958 if (ret) 1958 1959 goto err_out; 1959 1960 return 0;
-1
drivers/mtd/nand/gpmi-nand/gpmi-nand.h
··· 160 160 161 161 /* MTD / NAND */ 162 162 struct nand_chip nand; 163 - struct mtd_info mtd; 164 163 165 164 /* General-use Variables */ 166 165 int current_chip;
+25 -28
drivers/mtd/nand/hisi504_nand.c
··· 134 134 135 135 struct hinfc_host { 136 136 struct nand_chip chip; 137 - struct mtd_info mtd; 138 137 struct device *dev; 139 138 void __iomem *iobase; 140 139 void __iomem *mmio; ··· 188 189 189 190 static void hisi_nfc_dma_transfer(struct hinfc_host *host, int todev) 190 191 { 191 - struct mtd_info *mtd = &host->mtd; 192 - struct nand_chip *chip = mtd->priv; 192 + struct nand_chip *chip = &host->chip; 193 + struct mtd_info *mtd = nand_to_mtd(chip); 193 194 unsigned long val; 194 195 int ret; 195 196 ··· 261 262 262 263 static int hisi_nfc_send_cmd_readstart(struct hinfc_host *host) 263 264 { 264 - struct mtd_info *mtd = &host->mtd; 265 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 265 266 266 267 if ((host->addr_value[0] == host->cache_addr_value[0]) && 267 268 (host->addr_value[1] == host->cache_addr_value[1])) ··· 356 357 357 358 static void hisi_nfc_select_chip(struct mtd_info *mtd, int chipselect) 358 359 { 359 - struct nand_chip *chip = mtd->priv; 360 - struct hinfc_host *host = chip->priv; 360 + struct nand_chip *chip = mtd_to_nand(mtd); 361 + struct hinfc_host *host = nand_get_controller_data(chip); 361 362 362 363 if (chipselect < 0) 363 364 return; ··· 367 368 368 369 static uint8_t hisi_nfc_read_byte(struct mtd_info *mtd) 369 370 { 370 - struct nand_chip *chip = mtd->priv; 371 - struct hinfc_host *host = chip->priv; 371 + struct nand_chip *chip = mtd_to_nand(mtd); 372 + struct hinfc_host *host = nand_get_controller_data(chip); 372 373 373 374 if (host->command == NAND_CMD_STATUS) 374 375 return *(uint8_t *)(host->mmio); ··· 383 384 384 385 static u16 hisi_nfc_read_word(struct mtd_info *mtd) 385 386 { 386 - struct nand_chip *chip = mtd->priv; 387 - struct hinfc_host *host = chip->priv; 387 + struct nand_chip *chip = mtd_to_nand(mtd); 388 + struct hinfc_host *host = nand_get_controller_data(chip); 388 389 389 390 host->offset += 2; 390 391 return *(u16 *)(host->buffer + host->offset - 2); ··· 393 394 static void 394 395 hisi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 395 396 { 396 - struct nand_chip *chip = mtd->priv; 397 - struct hinfc_host *host = chip->priv; 397 + struct nand_chip *chip = mtd_to_nand(mtd); 398 + struct hinfc_host *host = nand_get_controller_data(chip); 398 399 399 400 memcpy(host->buffer + host->offset, buf, len); 400 401 host->offset += len; ··· 402 403 403 404 static void hisi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 404 405 { 405 - struct nand_chip *chip = mtd->priv; 406 - struct hinfc_host *host = chip->priv; 406 + struct nand_chip *chip = mtd_to_nand(mtd); 407 + struct hinfc_host *host = nand_get_controller_data(chip); 407 408 408 409 memcpy(buf, host->buffer + host->offset, len); 409 410 host->offset += len; ··· 411 412 412 413 static void set_addr(struct mtd_info *mtd, int column, int page_addr) 413 414 { 414 - struct nand_chip *chip = mtd->priv; 415 - struct hinfc_host *host = chip->priv; 415 + struct nand_chip *chip = mtd_to_nand(mtd); 416 + struct hinfc_host *host = nand_get_controller_data(chip); 416 417 unsigned int command = host->command; 417 418 418 419 host->addr_cycle = 0; ··· 447 448 static void hisi_nfc_cmdfunc(struct mtd_info *mtd, unsigned command, int column, 448 449 int page_addr) 449 450 { 450 - struct nand_chip *chip = mtd->priv; 451 - struct hinfc_host *host = chip->priv; 451 + struct nand_chip *chip = mtd_to_nand(mtd); 452 + struct hinfc_host *host = nand_get_controller_data(chip); 452 453 int is_cache_invalid = 1; 453 454 unsigned int flag = 0; 454 455 ··· 542 543 static int hisi_nand_read_page_hwecc(struct mtd_info *mtd, 543 544 struct nand_chip *chip, uint8_t *buf, int oob_required, int page) 544 545 { 545 - struct hinfc_host *host = chip->priv; 546 + struct hinfc_host *host = nand_get_controller_data(chip); 546 547 int max_bitflips = 0, stat = 0, stat_max = 0, status_ecc; 547 548 int stat_1, stat_2; 548 549 ··· 574 575 static int hisi_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 575 576 int page) 576 577 { 577 - struct hinfc_host *host = chip->priv; 578 + struct hinfc_host *host = nand_get_controller_data(chip); 578 579 579 580 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); 580 581 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); ··· 642 643 int size, strength, ecc_bits; 643 644 struct device *dev = host->dev; 644 645 struct nand_chip *chip = &host->chip; 645 - struct mtd_info *mtd = &host->mtd; 646 + struct mtd_info *mtd = nand_to_mtd(chip); 646 647 struct device_node *np = host->dev->of_node; 647 648 648 649 size = of_get_nand_ecc_step_size(np); ··· 703 704 struct mtd_info *mtd; 704 705 struct resource *res; 705 706 struct device_node *np = dev->of_node; 706 - struct mtd_part_parser_data ppdata; 707 707 708 708 host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); 709 709 if (!host) ··· 711 713 712 714 platform_set_drvdata(pdev, host); 713 715 chip = &host->chip; 714 - mtd = &host->mtd; 716 + mtd = nand_to_mtd(chip); 715 717 716 718 irq = platform_get_irq(pdev, 0); 717 719 if (irq < 0) { ··· 735 737 goto err_res; 736 738 } 737 739 738 - mtd->priv = chip; 739 740 mtd->name = "hisi_nand"; 740 741 mtd->dev.parent = &pdev->dev; 741 742 742 - chip->priv = host; 743 + nand_set_controller_data(chip, host); 744 + nand_set_flash_node(chip, np); 743 745 chip->cmdfunc = hisi_nfc_cmdfunc; 744 746 chip->select_chip = hisi_nfc_select_chip; 745 747 chip->read_byte = hisi_nfc_read_byte; ··· 803 805 goto err_res; 804 806 } 805 807 806 - ppdata.of_node = np; 807 - ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 808 + ret = mtd_device_register(mtd, NULL, 0); 808 809 if (ret) { 809 810 dev_err(dev, "Err MTD partition=%d\n", ret); 810 811 goto err_mtd; ··· 820 823 static int hisi_nfc_remove(struct platform_device *pdev) 821 824 { 822 825 struct hinfc_host *host = platform_get_drvdata(pdev); 823 - struct mtd_info *mtd = &host->mtd; 826 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 824 827 825 828 nand_release(mtd); 826 829
+9 -28
drivers/mtd/nand/jz4740_nand.c
··· 59 59 #define JZ_NAND_MEM_ADDR_OFFSET 0x10000 60 60 61 61 struct jz_nand { 62 - struct mtd_info mtd; 63 62 struct nand_chip chip; 64 63 void __iomem *base; 65 64 struct resource *mem; ··· 75 76 76 77 static inline struct jz_nand *mtd_to_jz_nand(struct mtd_info *mtd) 77 78 { 78 - return container_of(mtd, struct jz_nand, mtd); 79 + return container_of(mtd_to_nand(mtd), struct jz_nand, chip); 79 80 } 80 81 81 82 static void jz_nand_select_chip(struct mtd_info *mtd, int chipnr) 82 83 { 83 84 struct jz_nand *nand = mtd_to_jz_nand(mtd); 84 - struct nand_chip *chip = mtd->priv; 85 + struct nand_chip *chip = mtd_to_nand(mtd); 85 86 uint32_t ctrl; 86 87 int banknr; 87 88 ··· 103 104 static void jz_nand_cmd_ctrl(struct mtd_info *mtd, int dat, unsigned int ctrl) 104 105 { 105 106 struct jz_nand *nand = mtd_to_jz_nand(mtd); 106 - struct nand_chip *chip = mtd->priv; 107 + struct nand_chip *chip = mtd_to_nand(mtd); 107 108 uint32_t reg; 108 109 void __iomem *bank_base = nand->bank_base[nand->selected_bank]; 109 110 ··· 224 225 uint32_t t; 225 226 unsigned int timeout = 1000; 226 227 227 - t = read_ecc[0]; 228 - 229 - if (t == 0xff) { 230 - for (i = 1; i < 9; ++i) 231 - t &= read_ecc[i]; 232 - 233 - t &= dat[0]; 234 - t &= dat[nand->chip.ecc.size / 2]; 235 - t &= dat[nand->chip.ecc.size - 1]; 236 - 237 - if (t == 0xff) { 238 - for (i = 1; i < nand->chip.ecc.size - 1; ++i) 239 - t &= dat[i]; 240 - if (t == 0xff) 241 - return 0; 242 - } 243 - } 244 - 245 228 for (i = 0; i < 9; ++i) 246 229 writeb(read_ecc[i], nand->base + JZ_REG_NAND_PAR0 + i); 247 230 ··· 236 255 } while (!(status & JZ_NAND_STATUS_DEC_FINISH) && --timeout); 237 256 238 257 if (timeout == 0) 239 - return -1; 258 + return -ETIMEDOUT; 240 259 241 260 reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL); 242 261 reg &= ~JZ_NAND_ECC_CTRL_ENABLE; ··· 244 263 245 264 if (status & JZ_NAND_STATUS_ERROR) { 246 265 if (status & JZ_NAND_STATUS_UNCOR_ERROR) 247 - return -1; 266 + return -EBADMSG; 248 267 249 268 error_count = (status & JZ_NAND_STATUS_ERR_COUNT) >> 29; 250 269 ··· 315 334 char gpio_name[9]; 316 335 char res_name[6]; 317 336 uint32_t ctrl; 318 - struct mtd_info *mtd = &nand->mtd; 319 337 struct nand_chip *chip = &nand->chip; 338 + struct mtd_info *mtd = nand_to_mtd(chip); 320 339 321 340 /* Request GPIO port. */ 322 341 gpio = JZ_GPIO_MEM_CS0 + bank - 1; ··· 413 432 goto err_iounmap_mmio; 414 433 } 415 434 416 - mtd = &nand->mtd; 417 435 chip = &nand->chip; 418 - mtd->priv = chip; 436 + mtd = nand_to_mtd(chip); 419 437 mtd->dev.parent = &pdev->dev; 420 438 mtd->name = "jz4740-nand"; 421 439 ··· 425 445 chip->ecc.size = 512; 426 446 chip->ecc.bytes = 9; 427 447 chip->ecc.strength = 4; 448 + chip->ecc.options = NAND_ECC_GENERIC_ERASED_CHECK; 428 449 429 450 if (pdata) 430 451 chip->ecc.layout = pdata->ecc_layout; ··· 524 543 struct jz_nand *nand = platform_get_drvdata(pdev); 525 544 size_t i; 526 545 527 - nand_release(&nand->mtd); 546 + nand_release(nand_to_mtd(&nand->chip)); 528 547 529 548 /* Deassert and disable all chips */ 530 549 writel(0, nand->base + JZ_REG_NAND_CTRL);
+381
drivers/mtd/nand/jz4780_bch.c
··· 1 + /* 2 + * JZ4780 BCH controller 3 + * 4 + * Copyright (c) 2015 Imagination Technologies 5 + * Author: Alex Smith <alex.smith@imgtec.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/bitops.h> 13 + #include <linux/clk.h> 14 + #include <linux/delay.h> 15 + #include <linux/init.h> 16 + #include <linux/iopoll.h> 17 + #include <linux/module.h> 18 + #include <linux/mutex.h> 19 + #include <linux/of.h> 20 + #include <linux/of_platform.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/sched.h> 23 + #include <linux/slab.h> 24 + 25 + #include "jz4780_bch.h" 26 + 27 + #define BCH_BHCR 0x0 28 + #define BCH_BHCCR 0x8 29 + #define BCH_BHCNT 0xc 30 + #define BCH_BHDR 0x10 31 + #define BCH_BHPAR0 0x14 32 + #define BCH_BHERR0 0x84 33 + #define BCH_BHINT 0x184 34 + #define BCH_BHINTES 0x188 35 + #define BCH_BHINTEC 0x18c 36 + #define BCH_BHINTE 0x190 37 + 38 + #define BCH_BHCR_BSEL_SHIFT 4 39 + #define BCH_BHCR_BSEL_MASK (0x7f << BCH_BHCR_BSEL_SHIFT) 40 + #define BCH_BHCR_ENCE BIT(2) 41 + #define BCH_BHCR_INIT BIT(1) 42 + #define BCH_BHCR_BCHE BIT(0) 43 + 44 + #define BCH_BHCNT_PARITYSIZE_SHIFT 16 45 + #define BCH_BHCNT_PARITYSIZE_MASK (0x7f << BCH_BHCNT_PARITYSIZE_SHIFT) 46 + #define BCH_BHCNT_BLOCKSIZE_SHIFT 0 47 + #define BCH_BHCNT_BLOCKSIZE_MASK (0x7ff << BCH_BHCNT_BLOCKSIZE_SHIFT) 48 + 49 + #define BCH_BHERR_MASK_SHIFT 16 50 + #define BCH_BHERR_MASK_MASK (0xffff << BCH_BHERR_MASK_SHIFT) 51 + #define BCH_BHERR_INDEX_SHIFT 0 52 + #define BCH_BHERR_INDEX_MASK (0x7ff << BCH_BHERR_INDEX_SHIFT) 53 + 54 + #define BCH_BHINT_ERRC_SHIFT 24 55 + #define BCH_BHINT_ERRC_MASK (0x7f << BCH_BHINT_ERRC_SHIFT) 56 + #define BCH_BHINT_TERRC_SHIFT 16 57 + #define BCH_BHINT_TERRC_MASK (0x7f << BCH_BHINT_TERRC_SHIFT) 58 + #define BCH_BHINT_DECF BIT(3) 59 + #define BCH_BHINT_ENCF BIT(2) 60 + #define BCH_BHINT_UNCOR BIT(1) 61 + #define BCH_BHINT_ERR BIT(0) 62 + 63 + #define BCH_CLK_RATE (200 * 1000 * 1000) 64 + 65 + /* Timeout for BCH calculation/correction. */ 66 + #define BCH_TIMEOUT_US 100000 67 + 68 + struct jz4780_bch { 69 + struct device *dev; 70 + void __iomem *base; 71 + struct clk *clk; 72 + struct mutex lock; 73 + }; 74 + 75 + static void jz4780_bch_init(struct jz4780_bch *bch, 76 + struct jz4780_bch_params *params, bool encode) 77 + { 78 + u32 reg; 79 + 80 + /* Clear interrupt status. */ 81 + writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); 82 + 83 + /* Set up BCH count register. */ 84 + reg = params->size << BCH_BHCNT_BLOCKSIZE_SHIFT; 85 + reg |= params->bytes << BCH_BHCNT_PARITYSIZE_SHIFT; 86 + writel(reg, bch->base + BCH_BHCNT); 87 + 88 + /* Initialise and enable BCH. */ 89 + reg = BCH_BHCR_BCHE | BCH_BHCR_INIT; 90 + reg |= params->strength << BCH_BHCR_BSEL_SHIFT; 91 + if (encode) 92 + reg |= BCH_BHCR_ENCE; 93 + writel(reg, bch->base + BCH_BHCR); 94 + } 95 + 96 + static void jz4780_bch_disable(struct jz4780_bch *bch) 97 + { 98 + writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); 99 + writel(BCH_BHCR_BCHE, bch->base + BCH_BHCCR); 100 + } 101 + 102 + static void jz4780_bch_write_data(struct jz4780_bch *bch, const void *buf, 103 + size_t size) 104 + { 105 + size_t size32 = size / sizeof(u32); 106 + size_t size8 = size % sizeof(u32); 107 + const u32 *src32; 108 + const u8 *src8; 109 + 110 + src32 = (const u32 *)buf; 111 + while (size32--) 112 + writel(*src32++, bch->base + BCH_BHDR); 113 + 114 + src8 = (const u8 *)src32; 115 + while (size8--) 116 + writeb(*src8++, bch->base + BCH_BHDR); 117 + } 118 + 119 + static void jz4780_bch_read_parity(struct jz4780_bch *bch, void *buf, 120 + size_t size) 121 + { 122 + size_t size32 = size / sizeof(u32); 123 + size_t size8 = size % sizeof(u32); 124 + u32 *dest32; 125 + u8 *dest8; 126 + u32 val, offset = 0; 127 + 128 + dest32 = (u32 *)buf; 129 + while (size32--) { 130 + *dest32++ = readl(bch->base + BCH_BHPAR0 + offset); 131 + offset += sizeof(u32); 132 + } 133 + 134 + dest8 = (u8 *)dest32; 135 + val = readl(bch->base + BCH_BHPAR0 + offset); 136 + switch (size8) { 137 + case 3: 138 + dest8[2] = (val >> 16) & 0xff; 139 + case 2: 140 + dest8[1] = (val >> 8) & 0xff; 141 + case 1: 142 + dest8[0] = val & 0xff; 143 + break; 144 + } 145 + } 146 + 147 + static bool jz4780_bch_wait_complete(struct jz4780_bch *bch, unsigned int irq, 148 + u32 *status) 149 + { 150 + u32 reg; 151 + int ret; 152 + 153 + /* 154 + * While we could use interrupts here and sleep until the operation 155 + * completes, the controller works fairly quickly (usually a few 156 + * microseconds) and so the overhead of sleeping until we get an 157 + * interrupt quite noticeably decreases performance. 158 + */ 159 + ret = readl_poll_timeout(bch->base + BCH_BHINT, reg, 160 + (reg & irq) == irq, 0, BCH_TIMEOUT_US); 161 + if (ret) 162 + return false; 163 + 164 + if (status) 165 + *status = reg; 166 + 167 + writel(reg, bch->base + BCH_BHINT); 168 + return true; 169 + } 170 + 171 + /** 172 + * jz4780_bch_calculate() - calculate ECC for a data buffer 173 + * @bch: BCH device. 174 + * @params: BCH parameters. 175 + * @buf: input buffer with raw data. 176 + * @ecc_code: output buffer with ECC. 177 + * 178 + * Return: 0 on success, -ETIMEDOUT if timed out while waiting for BCH 179 + * controller. 180 + */ 181 + int jz4780_bch_calculate(struct jz4780_bch *bch, struct jz4780_bch_params *params, 182 + const u8 *buf, u8 *ecc_code) 183 + { 184 + int ret = 0; 185 + 186 + mutex_lock(&bch->lock); 187 + jz4780_bch_init(bch, params, true); 188 + jz4780_bch_write_data(bch, buf, params->size); 189 + 190 + if (jz4780_bch_wait_complete(bch, BCH_BHINT_ENCF, NULL)) { 191 + jz4780_bch_read_parity(bch, ecc_code, params->bytes); 192 + } else { 193 + dev_err(bch->dev, "timed out while calculating ECC\n"); 194 + ret = -ETIMEDOUT; 195 + } 196 + 197 + jz4780_bch_disable(bch); 198 + mutex_unlock(&bch->lock); 199 + return ret; 200 + } 201 + EXPORT_SYMBOL(jz4780_bch_calculate); 202 + 203 + /** 204 + * jz4780_bch_correct() - detect and correct bit errors 205 + * @bch: BCH device. 206 + * @params: BCH parameters. 207 + * @buf: raw data read from the chip. 208 + * @ecc_code: ECC read from the chip. 209 + * 210 + * Given the raw data and the ECC read from the NAND device, detects and 211 + * corrects errors in the data. 212 + * 213 + * Return: the number of bit errors corrected, -EBADMSG if there are too many 214 + * errors to correct or -ETIMEDOUT if we timed out waiting for the controller. 215 + */ 216 + int jz4780_bch_correct(struct jz4780_bch *bch, struct jz4780_bch_params *params, 217 + u8 *buf, u8 *ecc_code) 218 + { 219 + u32 reg, mask, index; 220 + int i, ret, count; 221 + 222 + mutex_lock(&bch->lock); 223 + 224 + jz4780_bch_init(bch, params, false); 225 + jz4780_bch_write_data(bch, buf, params->size); 226 + jz4780_bch_write_data(bch, ecc_code, params->bytes); 227 + 228 + if (!jz4780_bch_wait_complete(bch, BCH_BHINT_DECF, &reg)) { 229 + dev_err(bch->dev, "timed out while correcting data\n"); 230 + ret = -ETIMEDOUT; 231 + goto out; 232 + } 233 + 234 + if (reg & BCH_BHINT_UNCOR) { 235 + dev_warn(bch->dev, "uncorrectable ECC error\n"); 236 + ret = -EBADMSG; 237 + goto out; 238 + } 239 + 240 + /* Correct any detected errors. */ 241 + if (reg & BCH_BHINT_ERR) { 242 + count = (reg & BCH_BHINT_ERRC_MASK) >> BCH_BHINT_ERRC_SHIFT; 243 + ret = (reg & BCH_BHINT_TERRC_MASK) >> BCH_BHINT_TERRC_SHIFT; 244 + 245 + for (i = 0; i < count; i++) { 246 + reg = readl(bch->base + BCH_BHERR0 + (i * 4)); 247 + mask = (reg & BCH_BHERR_MASK_MASK) >> 248 + BCH_BHERR_MASK_SHIFT; 249 + index = (reg & BCH_BHERR_INDEX_MASK) >> 250 + BCH_BHERR_INDEX_SHIFT; 251 + buf[(index * 2) + 0] ^= mask; 252 + buf[(index * 2) + 1] ^= mask >> 8; 253 + } 254 + } else { 255 + ret = 0; 256 + } 257 + 258 + out: 259 + jz4780_bch_disable(bch); 260 + mutex_unlock(&bch->lock); 261 + return ret; 262 + } 263 + EXPORT_SYMBOL(jz4780_bch_correct); 264 + 265 + /** 266 + * jz4780_bch_get() - get the BCH controller device 267 + * @np: BCH device tree node. 268 + * 269 + * Gets the BCH controller device from the specified device tree node. The 270 + * device must be released with jz4780_bch_release() when it is no longer being 271 + * used. 272 + * 273 + * Return: a pointer to jz4780_bch, errors are encoded into the pointer. 274 + * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 275 + */ 276 + static struct jz4780_bch *jz4780_bch_get(struct device_node *np) 277 + { 278 + struct platform_device *pdev; 279 + struct jz4780_bch *bch; 280 + 281 + pdev = of_find_device_by_node(np); 282 + if (!pdev || !platform_get_drvdata(pdev)) 283 + return ERR_PTR(-EPROBE_DEFER); 284 + 285 + get_device(&pdev->dev); 286 + 287 + bch = platform_get_drvdata(pdev); 288 + clk_prepare_enable(bch->clk); 289 + 290 + bch->dev = &pdev->dev; 291 + return bch; 292 + } 293 + 294 + /** 295 + * of_jz4780_bch_get() - get the BCH controller from a DT node 296 + * @of_node: the node that contains a bch-controller property. 297 + * 298 + * Get the bch-controller property from the given device tree 299 + * node and pass it to jz4780_bch_get to do the work. 300 + * 301 + * Return: a pointer to jz4780_bch, errors are encoded into the pointer. 302 + * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 303 + */ 304 + struct jz4780_bch *of_jz4780_bch_get(struct device_node *of_node) 305 + { 306 + struct jz4780_bch *bch = NULL; 307 + struct device_node *np; 308 + 309 + np = of_parse_phandle(of_node, "ingenic,bch-controller", 0); 310 + 311 + if (np) { 312 + bch = jz4780_bch_get(np); 313 + of_node_put(np); 314 + } 315 + return bch; 316 + } 317 + EXPORT_SYMBOL(of_jz4780_bch_get); 318 + 319 + /** 320 + * jz4780_bch_release() - release the BCH controller device 321 + * @bch: BCH device. 322 + */ 323 + void jz4780_bch_release(struct jz4780_bch *bch) 324 + { 325 + clk_disable_unprepare(bch->clk); 326 + put_device(bch->dev); 327 + } 328 + EXPORT_SYMBOL(jz4780_bch_release); 329 + 330 + static int jz4780_bch_probe(struct platform_device *pdev) 331 + { 332 + struct device *dev = &pdev->dev; 333 + struct jz4780_bch *bch; 334 + struct resource *res; 335 + 336 + bch = devm_kzalloc(dev, sizeof(*bch), GFP_KERNEL); 337 + if (!bch) 338 + return -ENOMEM; 339 + 340 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 341 + bch->base = devm_ioremap_resource(dev, res); 342 + if (IS_ERR(bch->base)) 343 + return PTR_ERR(bch->base); 344 + 345 + jz4780_bch_disable(bch); 346 + 347 + bch->clk = devm_clk_get(dev, NULL); 348 + if (IS_ERR(bch->clk)) { 349 + dev_err(dev, "failed to get clock: %ld\n", PTR_ERR(bch->clk)); 350 + return PTR_ERR(bch->clk); 351 + } 352 + 353 + clk_set_rate(bch->clk, BCH_CLK_RATE); 354 + 355 + mutex_init(&bch->lock); 356 + 357 + bch->dev = dev; 358 + platform_set_drvdata(pdev, bch); 359 + 360 + return 0; 361 + } 362 + 363 + static const struct of_device_id jz4780_bch_dt_match[] = { 364 + { .compatible = "ingenic,jz4780-bch" }, 365 + {}, 366 + }; 367 + MODULE_DEVICE_TABLE(of, jz4780_bch_dt_match); 368 + 369 + static struct platform_driver jz4780_bch_driver = { 370 + .probe = jz4780_bch_probe, 371 + .driver = { 372 + .name = "jz4780-bch", 373 + .of_match_table = of_match_ptr(jz4780_bch_dt_match), 374 + }, 375 + }; 376 + module_platform_driver(jz4780_bch_driver); 377 + 378 + MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); 379 + MODULE_AUTHOR("Harvey Hunt <harvey.hunt@imgtec.com>"); 380 + MODULE_DESCRIPTION("Ingenic JZ4780 BCH error correction driver"); 381 + MODULE_LICENSE("GPL v2");
+43
drivers/mtd/nand/jz4780_bch.h
··· 1 + /* 2 + * JZ4780 BCH controller 3 + * 4 + * Copyright (c) 2015 Imagination Technologies 5 + * Author: Alex Smith <alex.smith@imgtec.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #ifndef __DRIVERS_MTD_NAND_JZ4780_BCH_H__ 13 + #define __DRIVERS_MTD_NAND_JZ4780_BCH_H__ 14 + 15 + #include <linux/types.h> 16 + 17 + struct device; 18 + struct device_node; 19 + struct jz4780_bch; 20 + 21 + /** 22 + * struct jz4780_bch_params - BCH parameters 23 + * @size: data bytes per ECC step. 24 + * @bytes: ECC bytes per step. 25 + * @strength: number of correctable bits per ECC step. 26 + */ 27 + struct jz4780_bch_params { 28 + int size; 29 + int bytes; 30 + int strength; 31 + }; 32 + 33 + int jz4780_bch_calculate(struct jz4780_bch *bch, 34 + struct jz4780_bch_params *params, 35 + const u8 *buf, u8 *ecc_code); 36 + int jz4780_bch_correct(struct jz4780_bch *bch, 37 + struct jz4780_bch_params *params, u8 *buf, 38 + u8 *ecc_code); 39 + 40 + void jz4780_bch_release(struct jz4780_bch *bch); 41 + struct jz4780_bch *of_jz4780_bch_get(struct device_node *np); 42 + 43 + #endif /* __DRIVERS_MTD_NAND_JZ4780_BCH_H__ */
+428
drivers/mtd/nand/jz4780_nand.c
··· 1 + /* 2 + * JZ4780 NAND driver 3 + * 4 + * Copyright (c) 2015 Imagination Technologies 5 + * Author: Alex Smith <alex.smith@imgtec.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/delay.h> 13 + #include <linux/init.h> 14 + #include <linux/io.h> 15 + #include <linux/list.h> 16 + #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/of_address.h> 19 + #include <linux/gpio/consumer.h> 20 + #include <linux/of_mtd.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/slab.h> 23 + #include <linux/mtd/mtd.h> 24 + #include <linux/mtd/nand.h> 25 + #include <linux/mtd/partitions.h> 26 + 27 + #include <linux/jz4780-nemc.h> 28 + 29 + #include "jz4780_bch.h" 30 + 31 + #define DRV_NAME "jz4780-nand" 32 + 33 + #define OFFSET_DATA 0x00000000 34 + #define OFFSET_CMD 0x00400000 35 + #define OFFSET_ADDR 0x00800000 36 + 37 + /* Command delay when there is no R/B pin. */ 38 + #define RB_DELAY_US 100 39 + 40 + struct jz4780_nand_cs { 41 + unsigned int bank; 42 + void __iomem *base; 43 + }; 44 + 45 + struct jz4780_nand_controller { 46 + struct device *dev; 47 + struct jz4780_bch *bch; 48 + struct nand_hw_control controller; 49 + unsigned int num_banks; 50 + struct list_head chips; 51 + int selected; 52 + struct jz4780_nand_cs cs[]; 53 + }; 54 + 55 + struct jz4780_nand_chip { 56 + struct nand_chip chip; 57 + struct list_head chip_list; 58 + 59 + struct nand_ecclayout ecclayout; 60 + 61 + struct gpio_desc *busy_gpio; 62 + struct gpio_desc *wp_gpio; 63 + unsigned int reading: 1; 64 + }; 65 + 66 + static inline struct jz4780_nand_chip *to_jz4780_nand_chip(struct mtd_info *mtd) 67 + { 68 + return container_of(mtd_to_nand(mtd), struct jz4780_nand_chip, chip); 69 + } 70 + 71 + static inline struct jz4780_nand_controller *to_jz4780_nand_controller(struct nand_hw_control *ctrl) 72 + { 73 + return container_of(ctrl, struct jz4780_nand_controller, controller); 74 + } 75 + 76 + static void jz4780_nand_select_chip(struct mtd_info *mtd, int chipnr) 77 + { 78 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 79 + struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 80 + struct jz4780_nand_cs *cs; 81 + 82 + /* Ensure the currently selected chip is deasserted. */ 83 + if (chipnr == -1 && nfc->selected >= 0) { 84 + cs = &nfc->cs[nfc->selected]; 85 + jz4780_nemc_assert(nfc->dev, cs->bank, false); 86 + } 87 + 88 + nfc->selected = chipnr; 89 + } 90 + 91 + static void jz4780_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 92 + unsigned int ctrl) 93 + { 94 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 95 + struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 96 + struct jz4780_nand_cs *cs; 97 + 98 + if (WARN_ON(nfc->selected < 0)) 99 + return; 100 + 101 + cs = &nfc->cs[nfc->selected]; 102 + 103 + jz4780_nemc_assert(nfc->dev, cs->bank, ctrl & NAND_NCE); 104 + 105 + if (cmd == NAND_CMD_NONE) 106 + return; 107 + 108 + if (ctrl & NAND_ALE) 109 + writeb(cmd, cs->base + OFFSET_ADDR); 110 + else if (ctrl & NAND_CLE) 111 + writeb(cmd, cs->base + OFFSET_CMD); 112 + } 113 + 114 + static int jz4780_nand_dev_ready(struct mtd_info *mtd) 115 + { 116 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 117 + 118 + return !gpiod_get_value_cansleep(nand->busy_gpio); 119 + } 120 + 121 + static void jz4780_nand_ecc_hwctl(struct mtd_info *mtd, int mode) 122 + { 123 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 124 + 125 + nand->reading = (mode == NAND_ECC_READ); 126 + } 127 + 128 + static int jz4780_nand_ecc_calculate(struct mtd_info *mtd, const u8 *dat, 129 + u8 *ecc_code) 130 + { 131 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 132 + struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 133 + struct jz4780_bch_params params; 134 + 135 + /* 136 + * Don't need to generate the ECC when reading, BCH does it for us as 137 + * part of decoding/correction. 138 + */ 139 + if (nand->reading) 140 + return 0; 141 + 142 + params.size = nand->chip.ecc.size; 143 + params.bytes = nand->chip.ecc.bytes; 144 + params.strength = nand->chip.ecc.strength; 145 + 146 + return jz4780_bch_calculate(nfc->bch, &params, dat, ecc_code); 147 + } 148 + 149 + static int jz4780_nand_ecc_correct(struct mtd_info *mtd, u8 *dat, 150 + u8 *read_ecc, u8 *calc_ecc) 151 + { 152 + struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd); 153 + struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 154 + struct jz4780_bch_params params; 155 + 156 + params.size = nand->chip.ecc.size; 157 + params.bytes = nand->chip.ecc.bytes; 158 + params.strength = nand->chip.ecc.strength; 159 + 160 + return jz4780_bch_correct(nfc->bch, &params, dat, read_ecc); 161 + } 162 + 163 + static int jz4780_nand_init_ecc(struct jz4780_nand_chip *nand, struct device *dev) 164 + { 165 + struct nand_chip *chip = &nand->chip; 166 + struct mtd_info *mtd = nand_to_mtd(chip); 167 + struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(chip->controller); 168 + struct nand_ecclayout *layout = &nand->ecclayout; 169 + u32 start, i; 170 + 171 + chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) * 172 + (chip->ecc.strength / 8); 173 + 174 + switch (chip->ecc.mode) { 175 + case NAND_ECC_HW: 176 + if (!nfc->bch) { 177 + dev_err(dev, "HW BCH selected, but BCH controller not found\n"); 178 + return -ENODEV; 179 + } 180 + 181 + chip->ecc.hwctl = jz4780_nand_ecc_hwctl; 182 + chip->ecc.calculate = jz4780_nand_ecc_calculate; 183 + chip->ecc.correct = jz4780_nand_ecc_correct; 184 + /* fall through */ 185 + case NAND_ECC_SOFT: 186 + case NAND_ECC_SOFT_BCH: 187 + dev_info(dev, "using %s (strength %d, size %d, bytes %d)\n", 188 + (nfc->bch) ? "hardware BCH" : "software ECC", 189 + chip->ecc.strength, chip->ecc.size, chip->ecc.bytes); 190 + break; 191 + case NAND_ECC_NONE: 192 + dev_info(dev, "not using ECC\n"); 193 + break; 194 + default: 195 + dev_err(dev, "ECC mode %d not supported\n", chip->ecc.mode); 196 + return -EINVAL; 197 + } 198 + 199 + /* The NAND core will generate the ECC layout for SW ECC */ 200 + if (chip->ecc.mode != NAND_ECC_HW) 201 + return 0; 202 + 203 + /* Generate ECC layout. ECC codes are right aligned in the OOB area. */ 204 + layout->eccbytes = mtd->writesize / chip->ecc.size * chip->ecc.bytes; 205 + 206 + if (layout->eccbytes > mtd->oobsize - 2) { 207 + dev_err(dev, 208 + "invalid ECC config: required %d ECC bytes, but only %d are available", 209 + layout->eccbytes, mtd->oobsize - 2); 210 + return -EINVAL; 211 + } 212 + 213 + start = mtd->oobsize - layout->eccbytes; 214 + for (i = 0; i < layout->eccbytes; i++) 215 + layout->eccpos[i] = start + i; 216 + 217 + layout->oobfree[0].offset = 2; 218 + layout->oobfree[0].length = mtd->oobsize - layout->eccbytes - 2; 219 + 220 + chip->ecc.layout = layout; 221 + return 0; 222 + } 223 + 224 + static int jz4780_nand_init_chip(struct platform_device *pdev, 225 + struct jz4780_nand_controller *nfc, 226 + struct device_node *np, 227 + unsigned int chipnr) 228 + { 229 + struct device *dev = &pdev->dev; 230 + struct jz4780_nand_chip *nand; 231 + struct jz4780_nand_cs *cs; 232 + struct resource *res; 233 + struct nand_chip *chip; 234 + struct mtd_info *mtd; 235 + const __be32 *reg; 236 + int ret = 0; 237 + 238 + cs = &nfc->cs[chipnr]; 239 + 240 + reg = of_get_property(np, "reg", NULL); 241 + if (!reg) 242 + return -EINVAL; 243 + 244 + cs->bank = be32_to_cpu(*reg); 245 + 246 + jz4780_nemc_set_type(nfc->dev, cs->bank, JZ4780_NEMC_BANK_NAND); 247 + 248 + res = platform_get_resource(pdev, IORESOURCE_MEM, chipnr); 249 + cs->base = devm_ioremap_resource(dev, res); 250 + if (IS_ERR(cs->base)) 251 + return PTR_ERR(cs->base); 252 + 253 + nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL); 254 + if (!nand) 255 + return -ENOMEM; 256 + 257 + nand->busy_gpio = devm_gpiod_get_optional(dev, "rb", GPIOD_IN); 258 + 259 + if (IS_ERR(nand->busy_gpio)) { 260 + ret = PTR_ERR(nand->busy_gpio); 261 + dev_err(dev, "failed to request busy GPIO: %d\n", ret); 262 + return ret; 263 + } else if (nand->busy_gpio) { 264 + nand->chip.dev_ready = jz4780_nand_dev_ready; 265 + } 266 + 267 + nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW); 268 + 269 + if (IS_ERR(nand->wp_gpio)) { 270 + ret = PTR_ERR(nand->wp_gpio); 271 + dev_err(dev, "failed to request WP GPIO: %d\n", ret); 272 + return ret; 273 + } 274 + 275 + chip = &nand->chip; 276 + mtd = nand_to_mtd(chip); 277 + mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev), 278 + cs->bank); 279 + if (!mtd->name) 280 + return -ENOMEM; 281 + mtd->dev.parent = dev; 282 + 283 + chip->IO_ADDR_R = cs->base + OFFSET_DATA; 284 + chip->IO_ADDR_W = cs->base + OFFSET_DATA; 285 + chip->chip_delay = RB_DELAY_US; 286 + chip->options = NAND_NO_SUBPAGE_WRITE; 287 + chip->select_chip = jz4780_nand_select_chip; 288 + chip->cmd_ctrl = jz4780_nand_cmd_ctrl; 289 + chip->ecc.mode = NAND_ECC_HW; 290 + chip->controller = &nfc->controller; 291 + nand_set_flash_node(chip, np); 292 + 293 + ret = nand_scan_ident(mtd, 1, NULL); 294 + if (ret) 295 + return ret; 296 + 297 + ret = jz4780_nand_init_ecc(nand, dev); 298 + if (ret) 299 + return ret; 300 + 301 + ret = nand_scan_tail(mtd); 302 + if (ret) 303 + return ret; 304 + 305 + ret = mtd_device_register(mtd, NULL, 0); 306 + if (ret) { 307 + nand_release(mtd); 308 + return ret; 309 + } 310 + 311 + list_add_tail(&nand->chip_list, &nfc->chips); 312 + 313 + return 0; 314 + } 315 + 316 + static void jz4780_nand_cleanup_chips(struct jz4780_nand_controller *nfc) 317 + { 318 + struct jz4780_nand_chip *chip; 319 + 320 + while (!list_empty(&nfc->chips)) { 321 + chip = list_first_entry(&nfc->chips, struct jz4780_nand_chip, chip_list); 322 + nand_release(nand_to_mtd(&chip->chip)); 323 + list_del(&chip->chip_list); 324 + } 325 + } 326 + 327 + static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc, 328 + struct platform_device *pdev) 329 + { 330 + struct device *dev = &pdev->dev; 331 + struct device_node *np; 332 + int i = 0; 333 + int ret; 334 + int num_chips = of_get_child_count(dev->of_node); 335 + 336 + if (num_chips > nfc->num_banks) { 337 + dev_err(dev, "found %d chips but only %d banks\n", num_chips, nfc->num_banks); 338 + return -EINVAL; 339 + } 340 + 341 + for_each_child_of_node(dev->of_node, np) { 342 + ret = jz4780_nand_init_chip(pdev, nfc, np, i); 343 + if (ret) { 344 + jz4780_nand_cleanup_chips(nfc); 345 + return ret; 346 + } 347 + 348 + i++; 349 + } 350 + 351 + return 0; 352 + } 353 + 354 + static int jz4780_nand_probe(struct platform_device *pdev) 355 + { 356 + struct device *dev = &pdev->dev; 357 + unsigned int num_banks; 358 + struct jz4780_nand_controller *nfc; 359 + int ret; 360 + 361 + num_banks = jz4780_nemc_num_banks(dev); 362 + if (num_banks == 0) { 363 + dev_err(dev, "no banks found\n"); 364 + return -ENODEV; 365 + } 366 + 367 + nfc = devm_kzalloc(dev, sizeof(*nfc) + (sizeof(nfc->cs[0]) * num_banks), GFP_KERNEL); 368 + if (!nfc) 369 + return -ENOMEM; 370 + 371 + /* 372 + * Check for BCH HW before we call nand_scan_ident, to prevent us from 373 + * having to call it again if the BCH driver returns -EPROBE_DEFER. 374 + */ 375 + nfc->bch = of_jz4780_bch_get(dev->of_node); 376 + if (IS_ERR(nfc->bch)) 377 + return PTR_ERR(nfc->bch); 378 + 379 + nfc->dev = dev; 380 + nfc->num_banks = num_banks; 381 + 382 + spin_lock_init(&nfc->controller.lock); 383 + INIT_LIST_HEAD(&nfc->chips); 384 + init_waitqueue_head(&nfc->controller.wq); 385 + 386 + ret = jz4780_nand_init_chips(nfc, pdev); 387 + if (ret) { 388 + if (nfc->bch) 389 + jz4780_bch_release(nfc->bch); 390 + return ret; 391 + } 392 + 393 + platform_set_drvdata(pdev, nfc); 394 + return 0; 395 + } 396 + 397 + static int jz4780_nand_remove(struct platform_device *pdev) 398 + { 399 + struct jz4780_nand_controller *nfc = platform_get_drvdata(pdev); 400 + 401 + if (nfc->bch) 402 + jz4780_bch_release(nfc->bch); 403 + 404 + jz4780_nand_cleanup_chips(nfc); 405 + 406 + return 0; 407 + } 408 + 409 + static const struct of_device_id jz4780_nand_dt_match[] = { 410 + { .compatible = "ingenic,jz4780-nand" }, 411 + {}, 412 + }; 413 + MODULE_DEVICE_TABLE(of, jz4780_nand_dt_match); 414 + 415 + static struct platform_driver jz4780_nand_driver = { 416 + .probe = jz4780_nand_probe, 417 + .remove = jz4780_nand_remove, 418 + .driver = { 419 + .name = DRV_NAME, 420 + .of_match_table = of_match_ptr(jz4780_nand_dt_match), 421 + }, 422 + }; 423 + module_platform_driver(jz4780_nand_driver); 424 + 425 + MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); 426 + MODULE_AUTHOR("Harvey Hunt <harvey.hunt@imgtec.com>"); 427 + MODULE_DESCRIPTION("Ingenic JZ4780 NAND driver"); 428 + MODULE_LICENSE("GPL v2");
+19 -21
drivers/mtd/nand/lpc32xx_mlc.c
··· 173 173 struct nand_chip nand_chip; 174 174 struct lpc32xx_mlc_platform_data *pdata; 175 175 struct clk *clk; 176 - struct mtd_info mtd; 177 176 void __iomem *io_base; 178 177 int irq; 179 178 struct lpc32xx_nand_cfg_mlc *ncfg; ··· 274 275 static void lpc32xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 275 276 unsigned int ctrl) 276 277 { 277 - struct nand_chip *nand_chip = mtd->priv; 278 - struct lpc32xx_nand_host *host = nand_chip->priv; 278 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 279 + struct lpc32xx_nand_host *host = nand_get_controller_data(nand_chip); 279 280 280 281 if (cmd != NAND_CMD_NONE) { 281 282 if (ctrl & NAND_CLE) ··· 290 291 */ 291 292 static int lpc32xx_nand_device_ready(struct mtd_info *mtd) 292 293 { 293 - struct nand_chip *nand_chip = mtd->priv; 294 - struct lpc32xx_nand_host *host = nand_chip->priv; 294 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 295 + struct lpc32xx_nand_host *host = nand_get_controller_data(nand_chip); 295 296 296 297 if ((readb(MLC_ISR(host->io_base)) & 297 298 (MLCISR_CONTROLLER_READY | MLCISR_NAND_READY)) == ··· 317 318 318 319 static int lpc32xx_waitfunc_nand(struct mtd_info *mtd, struct nand_chip *chip) 319 320 { 320 - struct lpc32xx_nand_host *host = chip->priv; 321 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 321 322 322 323 if (readb(MLC_ISR(host->io_base)) & MLCISR_NAND_READY) 323 324 goto exit; ··· 337 338 static int lpc32xx_waitfunc_controller(struct mtd_info *mtd, 338 339 struct nand_chip *chip) 339 340 { 340 - struct lpc32xx_nand_host *host = chip->priv; 341 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 341 342 342 343 if (readb(MLC_ISR(host->io_base)) & MLCISR_CONTROLLER_READY) 343 344 goto exit; ··· 388 389 static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len, 389 390 enum dma_transfer_direction dir) 390 391 { 391 - struct nand_chip *chip = mtd->priv; 392 - struct lpc32xx_nand_host *host = chip->priv; 392 + struct nand_chip *chip = mtd_to_nand(mtd); 393 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 393 394 struct dma_async_tx_descriptor *desc; 394 395 int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; 395 396 int res; ··· 430 431 static int lpc32xx_read_page(struct mtd_info *mtd, struct nand_chip *chip, 431 432 uint8_t *buf, int oob_required, int page) 432 433 { 433 - struct lpc32xx_nand_host *host = chip->priv; 434 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 434 435 int i, j; 435 436 uint8_t *oobbuf = chip->oob_poi; 436 437 uint32_t mlc_isr; ··· 497 498 const uint8_t *buf, int oob_required, 498 499 int page) 499 500 { 500 - struct lpc32xx_nand_host *host = chip->priv; 501 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 501 502 const uint8_t *oobbuf = chip->oob_poi; 502 503 uint8_t *dma_buf = (uint8_t *)buf; 503 504 int res; ··· 542 543 static int lpc32xx_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 543 544 int page) 544 545 { 545 - struct lpc32xx_nand_host *host = chip->priv; 546 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 546 547 547 548 /* Read whole page - necessary with MLC controller! */ 548 549 lpc32xx_read_page(mtd, chip, host->dummy_buf, 1, page); ··· 565 566 566 567 static int lpc32xx_dma_setup(struct lpc32xx_nand_host *host) 567 568 { 568 - struct mtd_info *mtd = &host->mtd; 569 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 569 570 dma_cap_mask_t mask; 570 571 571 572 if (!host->pdata || !host->pdata->dma_filter) { ··· 646 647 struct nand_chip *nand_chip; 647 648 struct resource *rc; 648 649 int res; 649 - struct mtd_part_parser_data ppdata = {}; 650 650 651 651 /* Allocate memory for the device structure (and zero it) */ 652 652 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); ··· 659 661 660 662 host->io_base_phy = rc->start; 661 663 662 - mtd = &host->mtd; 663 664 nand_chip = &host->nand_chip; 665 + mtd = nand_to_mtd(nand_chip); 664 666 if (pdev->dev.of_node) 665 667 host->ncfg = lpc32xx_parse_dt(&pdev->dev); 666 668 if (!host->ncfg) { ··· 679 681 680 682 host->pdata = dev_get_platdata(&pdev->dev); 681 683 682 - nand_chip->priv = host; /* link the private data structures */ 683 - mtd->priv = nand_chip; 684 + /* link the private data structures */ 685 + nand_set_controller_data(nand_chip, host); 686 + nand_set_flash_node(nand_chip, pdev->dev.of_node); 684 687 mtd->dev.parent = &pdev->dev; 685 688 686 689 /* Get NAND clock */ ··· 785 786 786 787 mtd->name = DRV_NAME; 787 788 788 - ppdata.of_node = pdev->dev.of_node; 789 - res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts, 790 - host->ncfg->num_parts); 789 + res = mtd_device_register(mtd, host->ncfg->parts, 790 + host->ncfg->num_parts); 791 791 if (!res) 792 792 return res; 793 793 ··· 813 815 static int lpc32xx_nand_remove(struct platform_device *pdev) 814 816 { 815 817 struct lpc32xx_nand_host *host = platform_get_drvdata(pdev); 816 - struct mtd_info *mtd = &host->mtd; 818 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 817 819 818 820 nand_release(mtd); 819 821 free_irq(host->irq, host);
+23 -26
drivers/mtd/nand/lpc32xx_slc.c
··· 204 204 struct nand_chip nand_chip; 205 205 struct lpc32xx_slc_platform_data *pdata; 206 206 struct clk *clk; 207 - struct mtd_info mtd; 208 207 void __iomem *io_base; 209 208 struct lpc32xx_nand_cfg_slc *ncfg; 210 209 ··· 259 260 unsigned int ctrl) 260 261 { 261 262 uint32_t tmp; 262 - struct nand_chip *chip = mtd->priv; 263 - struct lpc32xx_nand_host *host = chip->priv; 263 + struct nand_chip *chip = mtd_to_nand(mtd); 264 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 264 265 265 266 /* Does CE state need to be changed? */ 266 267 tmp = readl(SLC_CFG(host->io_base)); ··· 283 284 */ 284 285 static int lpc32xx_nand_device_ready(struct mtd_info *mtd) 285 286 { 286 - struct nand_chip *chip = mtd->priv; 287 - struct lpc32xx_nand_host *host = chip->priv; 287 + struct nand_chip *chip = mtd_to_nand(mtd); 288 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 288 289 int rdy = 0; 289 290 290 291 if ((readl(SLC_STAT(host->io_base)) & SLCSTAT_NAND_READY) != 0) ··· 338 339 */ 339 340 static uint8_t lpc32xx_nand_read_byte(struct mtd_info *mtd) 340 341 { 341 - struct nand_chip *chip = mtd->priv; 342 - struct lpc32xx_nand_host *host = chip->priv; 342 + struct nand_chip *chip = mtd_to_nand(mtd); 343 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 343 344 344 345 return (uint8_t)readl(SLC_DATA(host->io_base)); 345 346 } ··· 349 350 */ 350 351 static void lpc32xx_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 351 352 { 352 - struct nand_chip *chip = mtd->priv; 353 - struct lpc32xx_nand_host *host = chip->priv; 353 + struct nand_chip *chip = mtd_to_nand(mtd); 354 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 354 355 355 356 /* Direct device read with no ECC */ 356 357 while (len-- > 0) ··· 362 363 */ 363 364 static void lpc32xx_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 364 365 { 365 - struct nand_chip *chip = mtd->priv; 366 - struct lpc32xx_nand_host *host = chip->priv; 366 + struct nand_chip *chip = mtd_to_nand(mtd); 367 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 367 368 368 369 /* Direct device write with no ECC */ 369 370 while (len-- > 0) ··· 427 428 static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma, 428 429 void *mem, int len, enum dma_transfer_direction dir) 429 430 { 430 - struct nand_chip *chip = mtd->priv; 431 - struct lpc32xx_nand_host *host = chip->priv; 431 + struct nand_chip *chip = mtd_to_nand(mtd); 432 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 432 433 struct dma_async_tx_descriptor *desc; 433 434 int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; 434 435 int res; ··· 487 488 static int lpc32xx_xfer(struct mtd_info *mtd, uint8_t *buf, int eccsubpages, 488 489 int read) 489 490 { 490 - struct nand_chip *chip = mtd->priv; 491 - struct lpc32xx_nand_host *host = chip->priv; 491 + struct nand_chip *chip = mtd_to_nand(mtd); 492 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 492 493 int i, status = 0; 493 494 unsigned long timeout; 494 495 int res; ··· 603 604 struct nand_chip *chip, uint8_t *buf, 604 605 int oob_required, int page) 605 606 { 606 - struct lpc32xx_nand_host *host = chip->priv; 607 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 607 608 int stat, i, status; 608 609 uint8_t *oobecc, tmpecc[LPC32XX_ECC_SAVE_SIZE]; 609 610 ··· 665 666 const uint8_t *buf, 666 667 int oob_required, int page) 667 668 { 668 - struct lpc32xx_nand_host *host = chip->priv; 669 + struct lpc32xx_nand_host *host = nand_get_controller_data(chip); 669 670 uint8_t *pb = chip->oob_poi + chip->ecc.layout->eccpos[0]; 670 671 int error; 671 672 ··· 702 703 703 704 static int lpc32xx_nand_dma_setup(struct lpc32xx_nand_host *host) 704 705 { 705 - struct mtd_info *mtd = &host->mtd; 706 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 706 707 dma_cap_mask_t mask; 707 708 708 709 if (!host->pdata || !host->pdata->dma_filter) { ··· 762 763 struct mtd_info *mtd; 763 764 struct nand_chip *chip; 764 765 struct resource *rc; 765 - struct mtd_part_parser_data ppdata = {}; 766 766 int res; 767 767 768 768 rc = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 798 800 799 801 host->pdata = dev_get_platdata(&pdev->dev); 800 802 801 - mtd = &host->mtd; 802 803 chip = &host->nand_chip; 803 - chip->priv = host; 804 - mtd->priv = chip; 804 + mtd = nand_to_mtd(chip); 805 + nand_set_controller_data(chip, host); 806 + nand_set_flash_node(chip, pdev->dev.of_node); 805 807 mtd->owner = THIS_MODULE; 806 808 mtd->dev.parent = &pdev->dev; 807 809 ··· 906 908 } 907 909 908 910 mtd->name = "nxp_lpc3220_slc"; 909 - ppdata.of_node = pdev->dev.of_node; 910 - res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts, 911 - host->ncfg->num_parts); 911 + res = mtd_device_register(mtd, host->ncfg->parts, 912 + host->ncfg->num_parts); 912 913 if (!res) 913 914 return res; 914 915 ··· 930 933 { 931 934 uint32_t tmp; 932 935 struct lpc32xx_nand_host *host = platform_get_drvdata(pdev); 933 - struct mtd_info *mtd = &host->mtd; 936 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 934 937 935 938 nand_release(mtd); 936 939 dma_release_channel(host->dma_chan);
+27 -30
drivers/mtd/nand/mpc5121_nfc.c
··· 118 118 #define NFC_TIMEOUT (HZ / 10) /* 1/10 s */ 119 119 120 120 struct mpc5121_nfc_prv { 121 - struct mtd_info mtd; 122 121 struct nand_chip chip; 123 122 int irq; 124 123 void __iomem *regs; ··· 134 135 /* Read NFC register */ 135 136 static inline u16 nfc_read(struct mtd_info *mtd, uint reg) 136 137 { 137 - struct nand_chip *chip = mtd->priv; 138 - struct mpc5121_nfc_prv *prv = chip->priv; 138 + struct nand_chip *chip = mtd_to_nand(mtd); 139 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 139 140 140 141 return in_be16(prv->regs + reg); 141 142 } ··· 143 144 /* Write NFC register */ 144 145 static inline void nfc_write(struct mtd_info *mtd, uint reg, u16 val) 145 146 { 146 - struct nand_chip *chip = mtd->priv; 147 - struct mpc5121_nfc_prv *prv = chip->priv; 147 + struct nand_chip *chip = mtd_to_nand(mtd); 148 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 148 149 149 150 out_be16(prv->regs + reg, val); 150 151 } ··· 213 214 static irqreturn_t mpc5121_nfc_irq(int irq, void *data) 214 215 { 215 216 struct mtd_info *mtd = data; 216 - struct nand_chip *chip = mtd->priv; 217 - struct mpc5121_nfc_prv *prv = chip->priv; 217 + struct nand_chip *chip = mtd_to_nand(mtd); 218 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 218 219 219 220 nfc_set(mtd, NFC_CONFIG1, NFC_INT_MASK); 220 221 wake_up(&prv->irq_waitq); ··· 225 226 /* Wait for operation complete */ 226 227 static void mpc5121_nfc_done(struct mtd_info *mtd) 227 228 { 228 - struct nand_chip *chip = mtd->priv; 229 - struct mpc5121_nfc_prv *prv = chip->priv; 229 + struct nand_chip *chip = mtd_to_nand(mtd); 230 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 230 231 int rv; 231 232 232 233 if ((nfc_read(mtd, NFC_CONFIG2) & NFC_INT) == 0) { ··· 245 246 /* Do address cycle(s) */ 246 247 static void mpc5121_nfc_addr_cycle(struct mtd_info *mtd, int column, int page) 247 248 { 248 - struct nand_chip *chip = mtd->priv; 249 + struct nand_chip *chip = mtd_to_nand(mtd); 249 250 u32 pagemask = chip->pagemask; 250 251 251 252 if (column != -1) { ··· 280 281 /* Init external chip select logic on ADS5121 board */ 281 282 static int ads5121_chipselect_init(struct mtd_info *mtd) 282 283 { 283 - struct nand_chip *chip = mtd->priv; 284 - struct mpc5121_nfc_prv *prv = chip->priv; 284 + struct nand_chip *chip = mtd_to_nand(mtd); 285 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 285 286 struct device_node *dn; 286 287 287 288 dn = of_find_compatible_node(NULL, NULL, "fsl,mpc5121ads-cpld"); ··· 302 303 /* Control chips select signal on ADS5121 board */ 303 304 static void ads5121_select_chip(struct mtd_info *mtd, int chip) 304 305 { 305 - struct nand_chip *nand = mtd->priv; 306 - struct mpc5121_nfc_prv *prv = nand->priv; 306 + struct nand_chip *nand = mtd_to_nand(mtd); 307 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(nand); 307 308 u8 v; 308 309 309 310 v = in_8(prv->csreg); ··· 332 333 static void mpc5121_nfc_command(struct mtd_info *mtd, unsigned command, 333 334 int column, int page) 334 335 { 335 - struct nand_chip *chip = mtd->priv; 336 - struct mpc5121_nfc_prv *prv = chip->priv; 336 + struct nand_chip *chip = mtd_to_nand(mtd); 337 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 337 338 338 339 prv->column = (column >= 0) ? column : 0; 339 340 prv->spareonly = 0; ··· 405 406 static void mpc5121_nfc_copy_spare(struct mtd_info *mtd, uint offset, 406 407 u8 *buffer, uint size, int wr) 407 408 { 408 - struct nand_chip *nand = mtd->priv; 409 - struct mpc5121_nfc_prv *prv = nand->priv; 409 + struct nand_chip *nand = mtd_to_nand(mtd); 410 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(nand); 410 411 uint o, s, sbsize, blksize; 411 412 412 413 /* ··· 457 458 static void mpc5121_nfc_buf_copy(struct mtd_info *mtd, u_char *buf, int len, 458 459 int wr) 459 460 { 460 - struct nand_chip *chip = mtd->priv; 461 - struct mpc5121_nfc_prv *prv = chip->priv; 461 + struct nand_chip *chip = mtd_to_nand(mtd); 462 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 462 463 uint c = prv->column; 463 464 uint l; 464 465 ··· 535 536 */ 536 537 static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) 537 538 { 538 - struct nand_chip *chip = mtd->priv; 539 - struct mpc5121_nfc_prv *prv = chip->priv; 539 + struct nand_chip *chip = mtd_to_nand(mtd); 540 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 540 541 struct mpc512x_reset_module *rm; 541 542 struct device_node *rmnode; 542 543 uint rcw_pagesize = 0; ··· 614 615 /* Free driver resources */ 615 616 static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd) 616 617 { 617 - struct nand_chip *chip = mtd->priv; 618 - struct mpc5121_nfc_prv *prv = chip->priv; 618 + struct nand_chip *chip = mtd_to_nand(mtd); 619 + struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip); 619 620 620 621 if (prv->clk) 621 622 clk_disable_unprepare(prv->clk); ··· 638 639 int resettime = 0; 639 640 int retval = 0; 640 641 int rev, len; 641 - struct mtd_part_parser_data ppdata; 642 642 643 643 /* 644 644 * Check SoC revision. This driver supports only NFC ··· 653 655 if (!prv) 654 656 return -ENOMEM; 655 657 656 - mtd = &prv->mtd; 657 658 chip = &prv->chip; 659 + mtd = nand_to_mtd(chip); 658 660 659 - mtd->priv = chip; 660 661 mtd->dev.parent = dev; 661 - chip->priv = prv; 662 + nand_set_controller_data(chip, prv); 663 + nand_set_flash_node(chip, dn); 662 664 prv->dev = dev; 663 665 664 666 /* Read NFC configuration from Reset Config Word */ ··· 701 703 } 702 704 703 705 mtd->name = "MPC5121 NAND"; 704 - ppdata.of_node = dn; 705 706 chip->dev_ready = mpc5121_nfc_dev_ready; 706 707 chip->cmdfunc = mpc5121_nfc_command; 707 708 chip->read_byte = mpc5121_nfc_read_byte; ··· 812 815 dev_set_drvdata(dev, mtd); 813 816 814 817 /* Register device in MTD */ 815 - retval = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 818 + retval = mtd_device_register(mtd, NULL, 0); 816 819 if (retval) { 817 820 dev_err(dev, "Error adding MTD device!\n"); 818 821 goto error;
+42 -46
drivers/mtd/nand/mxc_nand.c
··· 173 173 }; 174 174 175 175 struct mxc_nand_host { 176 - struct mtd_info mtd; 177 176 struct nand_chip nand; 178 177 struct device *dev; 179 178 ··· 531 532 532 533 static void send_page_v3(struct mtd_info *mtd, unsigned int ops) 533 534 { 534 - struct nand_chip *nand_chip = mtd->priv; 535 - struct mxc_nand_host *host = nand_chip->priv; 535 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 536 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 536 537 uint32_t tmp; 537 538 538 539 tmp = readl(NFC_V3_CONFIG1); ··· 547 548 548 549 static void send_page_v2(struct mtd_info *mtd, unsigned int ops) 549 550 { 550 - struct nand_chip *nand_chip = mtd->priv; 551 - struct mxc_nand_host *host = nand_chip->priv; 551 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 552 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 552 553 553 554 /* NANDFC buffer 0 is used for page read/write */ 554 555 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR); ··· 561 562 562 563 static void send_page_v1(struct mtd_info *mtd, unsigned int ops) 563 564 { 564 - struct nand_chip *nand_chip = mtd->priv; 565 - struct mxc_nand_host *host = nand_chip->priv; 565 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 566 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 566 567 int bufs, i; 567 568 568 569 if (mtd->writesize > 512) ··· 662 663 static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat, 663 664 u_char *read_ecc, u_char *calc_ecc) 664 665 { 665 - struct nand_chip *nand_chip = mtd->priv; 666 - struct mxc_nand_host *host = nand_chip->priv; 666 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 667 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 667 668 668 669 /* 669 670 * 1-Bit errors are automatically corrected in HW. No need for ··· 674 675 675 676 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) { 676 677 pr_debug("MXC_NAND: HWECC uncorrectable 2-bit ECC error\n"); 677 - return -1; 678 + return -EBADMSG; 678 679 } 679 680 680 681 return 0; ··· 683 684 static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat, 684 685 u_char *read_ecc, u_char *calc_ecc) 685 686 { 686 - struct nand_chip *nand_chip = mtd->priv; 687 - struct mxc_nand_host *host = nand_chip->priv; 687 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 688 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 688 689 u32 ecc_stat, err; 689 690 int no_subpages = 1; 690 691 int ret = 0; ··· 701 702 err = ecc_stat & ecc_bit_mask; 702 703 if (err > err_limit) { 703 704 printk(KERN_WARNING "UnCorrectable RS-ECC Error\n"); 704 - return -1; 705 + return -EBADMSG; 705 706 } else { 706 707 ret += err; 707 708 } ··· 721 722 722 723 static u_char mxc_nand_read_byte(struct mtd_info *mtd) 723 724 { 724 - struct nand_chip *nand_chip = mtd->priv; 725 - struct mxc_nand_host *host = nand_chip->priv; 725 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 726 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 726 727 uint8_t ret; 727 728 728 729 /* Check for status request */ ··· 745 746 746 747 static uint16_t mxc_nand_read_word(struct mtd_info *mtd) 747 748 { 748 - struct nand_chip *nand_chip = mtd->priv; 749 - struct mxc_nand_host *host = nand_chip->priv; 749 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 750 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 750 751 uint16_t ret; 751 752 752 753 ret = *(uint16_t *)(host->data_buf + host->buf_start); ··· 761 762 static void mxc_nand_write_buf(struct mtd_info *mtd, 762 763 const u_char *buf, int len) 763 764 { 764 - struct nand_chip *nand_chip = mtd->priv; 765 - struct mxc_nand_host *host = nand_chip->priv; 765 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 766 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 766 767 u16 col = host->buf_start; 767 768 int n = mtd->oobsize + mtd->writesize - col; 768 769 ··· 779 780 */ 780 781 static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 781 782 { 782 - struct nand_chip *nand_chip = mtd->priv; 783 - struct mxc_nand_host *host = nand_chip->priv; 783 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 784 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 784 785 u16 col = host->buf_start; 785 786 int n = mtd->oobsize + mtd->writesize - col; 786 787 ··· 795 796 * deselect of the NAND chip */ 796 797 static void mxc_nand_select_chip_v1_v3(struct mtd_info *mtd, int chip) 797 798 { 798 - struct nand_chip *nand_chip = mtd->priv; 799 - struct mxc_nand_host *host = nand_chip->priv; 799 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 800 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 800 801 801 802 if (chip == -1) { 802 803 /* Disable the NFC clock */ ··· 816 817 817 818 static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip) 818 819 { 819 - struct nand_chip *nand_chip = mtd->priv; 820 - struct mxc_nand_host *host = nand_chip->priv; 820 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 821 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 821 822 822 823 if (chip == -1) { 823 824 /* Disable the NFC clock */ ··· 849 850 */ 850 851 static void copy_spare(struct mtd_info *mtd, bool bfrom) 851 852 { 852 - struct nand_chip *this = mtd->priv; 853 - struct mxc_nand_host *host = this->priv; 853 + struct nand_chip *this = mtd_to_nand(mtd); 854 + struct mxc_nand_host *host = nand_get_controller_data(this); 854 855 u16 i, oob_chunk_size; 855 856 u16 num_chunks = mtd->writesize / 512; 856 857 ··· 892 893 */ 893 894 static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr) 894 895 { 895 - struct nand_chip *nand_chip = mtd->priv; 896 - struct mxc_nand_host *host = nand_chip->priv; 896 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 897 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 897 898 898 899 /* Write out column address, if necessary */ 899 900 if (column != -1) { ··· 978 979 979 980 static void preset_v1(struct mtd_info *mtd) 980 981 { 981 - struct nand_chip *nand_chip = mtd->priv; 982 - struct mxc_nand_host *host = nand_chip->priv; 982 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 983 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 983 984 uint16_t config1 = 0; 984 985 985 986 if (nand_chip->ecc.mode == NAND_ECC_HW && mtd->writesize) ··· 1006 1007 1007 1008 static void preset_v2(struct mtd_info *mtd) 1008 1009 { 1009 - struct nand_chip *nand_chip = mtd->priv; 1010 - struct mxc_nand_host *host = nand_chip->priv; 1010 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1011 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 1011 1012 uint16_t config1 = 0; 1012 1013 1013 1014 config1 |= NFC_V2_CONFIG1_FP_INT; ··· 1052 1053 1053 1054 static void preset_v3(struct mtd_info *mtd) 1054 1055 { 1055 - struct nand_chip *chip = mtd->priv; 1056 - struct mxc_nand_host *host = chip->priv; 1056 + struct nand_chip *chip = mtd_to_nand(mtd); 1057 + struct mxc_nand_host *host = nand_get_controller_data(chip); 1057 1058 uint32_t config2, config3; 1058 1059 int i, addr_phases; 1059 1060 ··· 1066 1067 1067 1068 /* Blocks to be unlocked */ 1068 1069 for (i = 0; i < NAND_MAX_CHIPS; i++) 1069 - writel(0x0 | (0xffff << 16), 1070 - NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2)); 1070 + writel(0xffff << 16, NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2)); 1071 1071 1072 1072 writel(0, NFC_V3_IPC); 1073 1073 ··· 1123 1125 static void mxc_nand_command(struct mtd_info *mtd, unsigned command, 1124 1126 int column, int page_addr) 1125 1127 { 1126 - struct nand_chip *nand_chip = mtd->priv; 1127 - struct mxc_nand_host *host = nand_chip->priv; 1128 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 1129 + struct mxc_nand_host *host = nand_get_controller_data(nand_chip); 1128 1130 1129 1131 pr_debug("mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n", 1130 1132 command, column, page_addr); ··· 1513 1515 host->dev = &pdev->dev; 1514 1516 /* structures must be linked */ 1515 1517 this = &host->nand; 1516 - mtd = &host->mtd; 1517 - mtd->priv = this; 1518 + mtd = nand_to_mtd(this); 1518 1519 mtd->dev.parent = &pdev->dev; 1519 1520 mtd->name = DRIVER_NAME; 1520 1521 1521 1522 /* 50 us command delay time */ 1522 1523 this->chip_delay = 5; 1523 1524 1524 - this->priv = host; 1525 + nand_set_controller_data(this, host); 1526 + nand_set_flash_node(this, pdev->dev.of_node), 1525 1527 this->dev_ready = mxc_nand_dev_ready; 1526 1528 this->cmdfunc = mxc_nand_command; 1527 1529 this->read_byte = mxc_nand_read_byte; ··· 1681 1683 1682 1684 /* Register the partitions */ 1683 1685 mtd_device_parse_register(mtd, part_probes, 1684 - &(struct mtd_part_parser_data){ 1685 - .of_node = pdev->dev.of_node, 1686 - }, 1686 + NULL, 1687 1687 host->pdata.parts, 1688 1688 host->pdata.nr_parts); 1689 1689 ··· 1700 1704 { 1701 1705 struct mxc_nand_host *host = platform_get_drvdata(pdev); 1702 1706 1703 - nand_release(&host->mtd); 1707 + nand_release(nand_to_mtd(&host->nand)); 1704 1708 if (host->clk_act) 1705 1709 clk_disable_unprepare(host->clk); 1706 1710
+100 -57
drivers/mtd/nand/nand_base.c
··· 106 106 static int check_offs_len(struct mtd_info *mtd, 107 107 loff_t ofs, uint64_t len) 108 108 { 109 - struct nand_chip *chip = mtd->priv; 109 + struct nand_chip *chip = mtd_to_nand(mtd); 110 110 int ret = 0; 111 111 112 112 /* Start address must align on block boundary */ ··· 132 132 */ 133 133 static void nand_release_device(struct mtd_info *mtd) 134 134 { 135 - struct nand_chip *chip = mtd->priv; 135 + struct nand_chip *chip = mtd_to_nand(mtd); 136 136 137 137 /* Release the controller and the chip */ 138 138 spin_lock(&chip->controller->lock); ··· 150 150 */ 151 151 static uint8_t nand_read_byte(struct mtd_info *mtd) 152 152 { 153 - struct nand_chip *chip = mtd->priv; 153 + struct nand_chip *chip = mtd_to_nand(mtd); 154 154 return readb(chip->IO_ADDR_R); 155 155 } 156 156 ··· 163 163 */ 164 164 static uint8_t nand_read_byte16(struct mtd_info *mtd) 165 165 { 166 - struct nand_chip *chip = mtd->priv; 166 + struct nand_chip *chip = mtd_to_nand(mtd); 167 167 return (uint8_t) cpu_to_le16(readw(chip->IO_ADDR_R)); 168 168 } 169 169 ··· 175 175 */ 176 176 static u16 nand_read_word(struct mtd_info *mtd) 177 177 { 178 - struct nand_chip *chip = mtd->priv; 178 + struct nand_chip *chip = mtd_to_nand(mtd); 179 179 return readw(chip->IO_ADDR_R); 180 180 } 181 181 ··· 188 188 */ 189 189 static void nand_select_chip(struct mtd_info *mtd, int chipnr) 190 190 { 191 - struct nand_chip *chip = mtd->priv; 191 + struct nand_chip *chip = mtd_to_nand(mtd); 192 192 193 193 switch (chipnr) { 194 194 case -1: ··· 211 211 */ 212 212 static void nand_write_byte(struct mtd_info *mtd, uint8_t byte) 213 213 { 214 - struct nand_chip *chip = mtd->priv; 214 + struct nand_chip *chip = mtd_to_nand(mtd); 215 215 216 216 chip->write_buf(mtd, &byte, 1); 217 217 } ··· 225 225 */ 226 226 static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte) 227 227 { 228 - struct nand_chip *chip = mtd->priv; 228 + struct nand_chip *chip = mtd_to_nand(mtd); 229 229 uint16_t word = byte; 230 230 231 231 /* ··· 257 257 */ 258 258 static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 259 259 { 260 - struct nand_chip *chip = mtd->priv; 260 + struct nand_chip *chip = mtd_to_nand(mtd); 261 261 262 262 iowrite8_rep(chip->IO_ADDR_W, buf, len); 263 263 } ··· 272 272 */ 273 273 static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 274 274 { 275 - struct nand_chip *chip = mtd->priv; 275 + struct nand_chip *chip = mtd_to_nand(mtd); 276 276 277 277 ioread8_rep(chip->IO_ADDR_R, buf, len); 278 278 } ··· 287 287 */ 288 288 static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 289 289 { 290 - struct nand_chip *chip = mtd->priv; 290 + struct nand_chip *chip = mtd_to_nand(mtd); 291 291 u16 *p = (u16 *) buf; 292 292 293 293 iowrite16_rep(chip->IO_ADDR_W, p, len >> 1); ··· 303 303 */ 304 304 static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) 305 305 { 306 - struct nand_chip *chip = mtd->priv; 306 + struct nand_chip *chip = mtd_to_nand(mtd); 307 307 u16 *p = (u16 *) buf; 308 308 309 309 ioread16_rep(chip->IO_ADDR_R, p, len >> 1); ··· 320 320 static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 321 321 { 322 322 int page, chipnr, res = 0, i = 0; 323 - struct nand_chip *chip = mtd->priv; 323 + struct nand_chip *chip = mtd_to_nand(mtd); 324 324 u16 bad; 325 325 326 326 if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ··· 380 380 */ 381 381 static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) 382 382 { 383 - struct nand_chip *chip = mtd->priv; 383 + struct nand_chip *chip = mtd_to_nand(mtd); 384 384 struct mtd_oob_ops ops; 385 385 uint8_t buf[2] = { 0, 0 }; 386 386 int ret = 0, res, i = 0; ··· 430 430 */ 431 431 static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs) 432 432 { 433 - struct nand_chip *chip = mtd->priv; 433 + struct nand_chip *chip = mtd_to_nand(mtd); 434 434 int res, ret = 0; 435 435 436 436 if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) { ··· 471 471 */ 472 472 static int nand_check_wp(struct mtd_info *mtd) 473 473 { 474 - struct nand_chip *chip = mtd->priv; 474 + struct nand_chip *chip = mtd_to_nand(mtd); 475 475 476 476 /* Broken xD cards report WP despite being writable */ 477 477 if (chip->options & NAND_BROKEN_XD) ··· 491 491 */ 492 492 static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs) 493 493 { 494 - struct nand_chip *chip = mtd->priv; 494 + struct nand_chip *chip = mtd_to_nand(mtd); 495 495 496 496 if (!chip->bbt) 497 497 return 0; ··· 512 512 static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, 513 513 int allowbbt) 514 514 { 515 - struct nand_chip *chip = mtd->priv; 515 + struct nand_chip *chip = mtd_to_nand(mtd); 516 516 517 517 if (!chip->bbt) 518 518 return chip->block_bad(mtd, ofs, getchip); ··· 531 531 */ 532 532 static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo) 533 533 { 534 - struct nand_chip *chip = mtd->priv; 534 + struct nand_chip *chip = mtd_to_nand(mtd); 535 535 int i; 536 536 537 537 /* Wait for the device to get ready */ ··· 551 551 */ 552 552 void nand_wait_ready(struct mtd_info *mtd) 553 553 { 554 - struct nand_chip *chip = mtd->priv; 554 + struct nand_chip *chip = mtd_to_nand(mtd); 555 555 unsigned long timeo = 400; 556 556 557 557 if (in_interrupt() || oops_in_progress) ··· 582 582 */ 583 583 static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) 584 584 { 585 - register struct nand_chip *chip = mtd->priv; 585 + register struct nand_chip *chip = mtd_to_nand(mtd); 586 586 587 587 timeo = jiffies + msecs_to_jiffies(timeo); 588 588 do { ··· 605 605 static void nand_command(struct mtd_info *mtd, unsigned int command, 606 606 int column, int page_addr) 607 607 { 608 - register struct nand_chip *chip = mtd->priv; 608 + register struct nand_chip *chip = mtd_to_nand(mtd); 609 609 int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE; 610 610 611 611 /* Write out the command to the device */ ··· 708 708 static void nand_command_lp(struct mtd_info *mtd, unsigned int command, 709 709 int column, int page_addr) 710 710 { 711 - register struct nand_chip *chip = mtd->priv; 711 + register struct nand_chip *chip = mtd_to_nand(mtd); 712 712 713 713 /* Emulate NAND_CMD_READOOB */ 714 714 if (command == NAND_CMD_READOOB) { ··· 832 832 static int 833 833 nand_get_device(struct mtd_info *mtd, int new_state) 834 834 { 835 - struct nand_chip *chip = mtd->priv; 835 + struct nand_chip *chip = mtd_to_nand(mtd); 836 836 spinlock_t *lock = &chip->controller->lock; 837 837 wait_queue_head_t *wq = &chip->controller->wq; 838 838 DECLARE_WAITQUEUE(wait, current); ··· 952 952 { 953 953 int ret = 0; 954 954 int status, page; 955 - struct nand_chip *chip = mtd->priv; 955 + struct nand_chip *chip = mtd_to_nand(mtd); 956 956 957 957 /* Submit address of first page to unlock */ 958 958 page = ofs >> chip->page_shift; ··· 987 987 { 988 988 int ret = 0; 989 989 int chipnr; 990 - struct nand_chip *chip = mtd->priv; 990 + struct nand_chip *chip = mtd_to_nand(mtd); 991 991 992 992 pr_debug("%s: start = 0x%012llx, len = %llu\n", 993 993 __func__, (unsigned long long)ofs, len); ··· 1050 1050 { 1051 1051 int ret = 0; 1052 1052 int chipnr, status, page; 1053 - struct nand_chip *chip = mtd->priv; 1053 + struct nand_chip *chip = mtd_to_nand(mtd); 1054 1054 1055 1055 pr_debug("%s: start = 0x%012llx, len = %llu\n", 1056 1056 __func__, (unsigned long long)ofs, len); ··· 1426 1426 1427 1427 stat = chip->ecc.correct(mtd, p, 1428 1428 &chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]); 1429 + if (stat == -EBADMSG && 1430 + (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { 1431 + /* check for empty pages with bitflips */ 1432 + stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, 1433 + &chip->buffers->ecccode[i], 1434 + chip->ecc.bytes, 1435 + NULL, 0, 1436 + chip->ecc.strength); 1437 + } 1438 + 1429 1439 if (stat < 0) { 1430 1440 mtd->ecc_stats.failed++; 1431 1441 } else { ··· 1485 1475 int stat; 1486 1476 1487 1477 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); 1478 + if (stat == -EBADMSG && 1479 + (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { 1480 + /* check for empty pages with bitflips */ 1481 + stat = nand_check_erased_ecc_chunk(p, eccsize, 1482 + &ecc_code[i], eccbytes, 1483 + NULL, 0, 1484 + chip->ecc.strength); 1485 + } 1486 + 1488 1487 if (stat < 0) { 1489 1488 mtd->ecc_stats.failed++; 1490 1489 } else { ··· 1546 1527 chip->ecc.calculate(mtd, p, &ecc_calc[i]); 1547 1528 1548 1529 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); 1530 + if (stat == -EBADMSG && 1531 + (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { 1532 + /* check for empty pages with bitflips */ 1533 + stat = nand_check_erased_ecc_chunk(p, eccsize, 1534 + &ecc_code[i], eccbytes, 1535 + NULL, 0, 1536 + chip->ecc.strength); 1537 + } 1538 + 1549 1539 if (stat < 0) { 1550 1540 mtd->ecc_stats.failed++; 1551 1541 } else { ··· 1582 1554 int i, eccsize = chip->ecc.size; 1583 1555 int eccbytes = chip->ecc.bytes; 1584 1556 int eccsteps = chip->ecc.steps; 1557 + int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad; 1585 1558 uint8_t *p = buf; 1586 1559 uint8_t *oob = chip->oob_poi; 1587 1560 unsigned int max_bitflips = 0; ··· 1602 1573 chip->read_buf(mtd, oob, eccbytes); 1603 1574 stat = chip->ecc.correct(mtd, p, oob, NULL); 1604 1575 1605 - if (stat < 0) { 1606 - mtd->ecc_stats.failed++; 1607 - } else { 1608 - mtd->ecc_stats.corrected += stat; 1609 - max_bitflips = max_t(unsigned int, max_bitflips, stat); 1610 - } 1611 - 1612 1576 oob += eccbytes; 1613 1577 1614 1578 if (chip->ecc.postpad) { 1615 1579 chip->read_buf(mtd, oob, chip->ecc.postpad); 1616 1580 oob += chip->ecc.postpad; 1581 + } 1582 + 1583 + if (stat == -EBADMSG && 1584 + (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { 1585 + /* check for empty pages with bitflips */ 1586 + stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, 1587 + oob - eccpadbytes, 1588 + eccpadbytes, 1589 + NULL, 0, 1590 + chip->ecc.strength); 1591 + } 1592 + 1593 + if (stat < 0) { 1594 + mtd->ecc_stats.failed++; 1595 + } else { 1596 + mtd->ecc_stats.corrected += stat; 1597 + max_bitflips = max_t(unsigned int, max_bitflips, stat); 1617 1598 } 1618 1599 } 1619 1600 ··· 1694 1655 */ 1695 1656 static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) 1696 1657 { 1697 - struct nand_chip *chip = mtd->priv; 1658 + struct nand_chip *chip = mtd_to_nand(mtd); 1698 1659 1699 1660 pr_debug("setting READ RETRY mode %d\n", retry_mode); 1700 1661 ··· 1719 1680 struct mtd_oob_ops *ops) 1720 1681 { 1721 1682 int chipnr, page, realpage, col, bytes, aligned, oob_required; 1722 - struct nand_chip *chip = mtd->priv; 1683 + struct nand_chip *chip = mtd_to_nand(mtd); 1723 1684 int ret = 0; 1724 1685 uint32_t readlen = ops->len; 1725 1686 uint32_t oobreadlen = ops->ooblen; ··· 2063 2024 struct mtd_oob_ops *ops) 2064 2025 { 2065 2026 int page, realpage, chipnr; 2066 - struct nand_chip *chip = mtd->priv; 2027 + struct nand_chip *chip = mtd_to_nand(mtd); 2067 2028 struct mtd_ecc_stats stats; 2068 2029 int readlen = ops->ooblen; 2069 2030 int len; ··· 2511 2472 static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len, 2512 2473 struct mtd_oob_ops *ops) 2513 2474 { 2514 - struct nand_chip *chip = mtd->priv; 2475 + struct nand_chip *chip = mtd_to_nand(mtd); 2515 2476 2516 2477 /* 2517 2478 * Initialise to all 0xFF, to avoid the possibility of left over OOB ··· 2571 2532 struct mtd_oob_ops *ops) 2572 2533 { 2573 2534 int chipnr, realpage, page, blockmask, column; 2574 - struct nand_chip *chip = mtd->priv; 2535 + struct nand_chip *chip = mtd_to_nand(mtd); 2575 2536 uint32_t writelen = ops->len; 2576 2537 2577 2538 uint32_t oobwritelen = ops->ooblen; ··· 2701 2662 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, 2702 2663 size_t *retlen, const uint8_t *buf) 2703 2664 { 2704 - struct nand_chip *chip = mtd->priv; 2665 + struct nand_chip *chip = mtd_to_nand(mtd); 2705 2666 struct mtd_oob_ops ops; 2706 2667 int ret; 2707 2668 ··· 2761 2722 struct mtd_oob_ops *ops) 2762 2723 { 2763 2724 int chipnr, page, status, len; 2764 - struct nand_chip *chip = mtd->priv; 2725 + struct nand_chip *chip = mtd_to_nand(mtd); 2765 2726 2766 2727 pr_debug("%s: to = 0x%08x, len = %i\n", 2767 2728 __func__, (unsigned int)to, (int)ops->ooblen); ··· 2886 2847 */ 2887 2848 static int single_erase(struct mtd_info *mtd, int page) 2888 2849 { 2889 - struct nand_chip *chip = mtd->priv; 2850 + struct nand_chip *chip = mtd_to_nand(mtd); 2890 2851 /* Send commands to erase a block */ 2891 2852 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); 2892 2853 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); ··· 2918 2879 int allowbbt) 2919 2880 { 2920 2881 int page, status, pages_per_block, ret, chipnr; 2921 - struct nand_chip *chip = mtd->priv; 2882 + struct nand_chip *chip = mtd_to_nand(mtd); 2922 2883 loff_t len; 2923 2884 2924 2885 pr_debug("%s: start = 0x%012llx, len = %llu\n", ··· 3133 3094 */ 3134 3095 static void nand_resume(struct mtd_info *mtd) 3135 3096 { 3136 - struct nand_chip *chip = mtd->priv; 3097 + struct nand_chip *chip = mtd_to_nand(mtd); 3137 3098 3138 3099 if (chip->state == FL_PM_SUSPENDED) 3139 3100 nand_release_device(mtd); ··· 3305 3266 3306 3267 static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode) 3307 3268 { 3308 - struct nand_chip *chip = mtd->priv; 3269 + struct nand_chip *chip = mtd_to_nand(mtd); 3309 3270 uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode}; 3310 3271 3311 3272 return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, ··· 3976 3937 return type; 3977 3938 } 3978 3939 3979 - static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, 3980 - struct device_node *dn) 3940 + static int nand_dt_init(struct nand_chip *chip) 3981 3941 { 3942 + struct device_node *dn = nand_get_flash_node(chip); 3982 3943 int ecc_mode, ecc_strength, ecc_step; 3944 + 3945 + if (!dn) 3946 + return 0; 3983 3947 3984 3948 if (of_get_nand_bus_width(dn) == 16) 3985 3949 chip->options |= NAND_BUSWIDTH_16; ··· 4027 3985 struct nand_flash_dev *table) 4028 3986 { 4029 3987 int i, nand_maf_id, nand_dev_id; 4030 - struct nand_chip *chip = mtd->priv; 3988 + struct nand_chip *chip = mtd_to_nand(mtd); 4031 3989 struct nand_flash_dev *type; 4032 3990 int ret; 4033 3991 4034 - if (chip->flash_node) { 4035 - ret = nand_dt_init(mtd, chip, chip->flash_node); 4036 - if (ret) 4037 - return ret; 4038 - } 3992 + ret = nand_dt_init(chip); 3993 + if (ret) 3994 + return ret; 3995 + 3996 + if (!mtd->name && mtd->dev.parent) 3997 + mtd->name = dev_name(mtd->dev.parent); 4039 3998 4040 3999 /* Set the default functions */ 4041 4000 nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); ··· 4096 4053 */ 4097 4054 static bool nand_ecc_strength_good(struct mtd_info *mtd) 4098 4055 { 4099 - struct nand_chip *chip = mtd->priv; 4056 + struct nand_chip *chip = mtd_to_nand(mtd); 4100 4057 struct nand_ecc_ctrl *ecc = &chip->ecc; 4101 4058 int corr, ds_corr; 4102 4059 ··· 4125 4082 int nand_scan_tail(struct mtd_info *mtd) 4126 4083 { 4127 4084 int i; 4128 - struct nand_chip *chip = mtd->priv; 4085 + struct nand_chip *chip = mtd_to_nand(mtd); 4129 4086 struct nand_ecc_ctrl *ecc = &chip->ecc; 4130 4087 struct nand_buffers *nbuf; 4131 4088 ··· 4209 4166 ecc->write_oob = nand_write_oob_std; 4210 4167 if (!ecc->read_subpage) 4211 4168 ecc->read_subpage = nand_read_subpage; 4212 - if (!ecc->write_subpage) 4169 + if (!ecc->write_subpage && ecc->hwctl && ecc->calculate) 4213 4170 ecc->write_subpage = nand_write_subpage_hwecc; 4214 4171 4215 4172 case NAND_ECC_HW_SYNDROME: ··· 4469 4426 */ 4470 4427 void nand_release(struct mtd_info *mtd) 4471 4428 { 4472 - struct nand_chip *chip = mtd->priv; 4429 + struct nand_chip *chip = mtd_to_nand(mtd); 4473 4430 4474 4431 if (chip->ecc.mode == NAND_ECC_SOFT_BCH) 4475 4432 nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
+16 -16
drivers/mtd/nand/nand_bbt.c
··· 172 172 struct nand_bbt_descr *td, int offs) 173 173 { 174 174 int res, ret = 0, i, j, act = 0; 175 - struct nand_chip *this = mtd->priv; 175 + struct nand_chip *this = mtd_to_nand(mtd); 176 176 size_t retlen, len, totlen; 177 177 loff_t from; 178 178 int bits = td->options & NAND_BBT_NRBITS_MSK; ··· 263 263 */ 264 264 static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) 265 265 { 266 - struct nand_chip *this = mtd->priv; 266 + struct nand_chip *this = mtd_to_nand(mtd); 267 267 int res = 0, i; 268 268 269 269 if (td->options & NAND_BBT_PERCHIP) { ··· 388 388 static void read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, 389 389 struct nand_bbt_descr *td, struct nand_bbt_descr *md) 390 390 { 391 - struct nand_chip *this = mtd->priv; 391 + struct nand_chip *this = mtd_to_nand(mtd); 392 392 393 393 /* Read the primary version, if available */ 394 394 if (td->options & NAND_BBT_VERSION) { ··· 454 454 static int create_bbt(struct mtd_info *mtd, uint8_t *buf, 455 455 struct nand_bbt_descr *bd, int chip) 456 456 { 457 - struct nand_chip *this = mtd->priv; 457 + struct nand_chip *this = mtd_to_nand(mtd); 458 458 int i, numblocks, numpages; 459 459 int startblock; 460 460 loff_t from; ··· 523 523 */ 524 524 static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) 525 525 { 526 - struct nand_chip *this = mtd->priv; 526 + struct nand_chip *this = mtd_to_nand(mtd); 527 527 int i, chips; 528 528 int startblock, block, dir; 529 529 int scanlen = mtd->writesize + mtd->oobsize; ··· 618 618 struct nand_bbt_descr *td, struct nand_bbt_descr *md, 619 619 int chipsel) 620 620 { 621 - struct nand_chip *this = mtd->priv; 621 + struct nand_chip *this = mtd_to_nand(mtd); 622 622 struct erase_info einfo; 623 623 int i, res, chip = 0; 624 624 int bits, startblock, dir, page, offs, numblocks, sft, sftmsk; ··· 819 819 */ 820 820 static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 821 821 { 822 - struct nand_chip *this = mtd->priv; 822 + struct nand_chip *this = mtd_to_nand(mtd); 823 823 824 824 return create_bbt(mtd, this->buffers->databuf, bd, -1); 825 825 } ··· 838 838 static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) 839 839 { 840 840 int i, chips, writeops, create, chipsel, res, res2; 841 - struct nand_chip *this = mtd->priv; 841 + struct nand_chip *this = mtd_to_nand(mtd); 842 842 struct nand_bbt_descr *td = this->bbt_td; 843 843 struct nand_bbt_descr *md = this->bbt_md; 844 844 struct nand_bbt_descr *rd, *rd2; ··· 962 962 */ 963 963 static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) 964 964 { 965 - struct nand_chip *this = mtd->priv; 965 + struct nand_chip *this = mtd_to_nand(mtd); 966 966 int i, j, chips, block, nrblocks, update; 967 967 uint8_t oldval; 968 968 ··· 1022 1022 */ 1023 1023 static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd) 1024 1024 { 1025 - struct nand_chip *this = mtd->priv; 1025 + struct nand_chip *this = mtd_to_nand(mtd); 1026 1026 u32 pattern_len; 1027 1027 u32 bits; 1028 1028 u32 table_size; ··· 1074 1074 */ 1075 1075 static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 1076 1076 { 1077 - struct nand_chip *this = mtd->priv; 1077 + struct nand_chip *this = mtd_to_nand(mtd); 1078 1078 int len, res; 1079 1079 uint8_t *buf; 1080 1080 struct nand_bbt_descr *td = this->bbt_td; ··· 1147 1147 */ 1148 1148 static int nand_update_bbt(struct mtd_info *mtd, loff_t offs) 1149 1149 { 1150 - struct nand_chip *this = mtd->priv; 1150 + struct nand_chip *this = mtd_to_nand(mtd); 1151 1151 int len, res = 0; 1152 1152 int chip, chipsel; 1153 1153 uint8_t *buf; ··· 1281 1281 */ 1282 1282 int nand_default_bbt(struct mtd_info *mtd) 1283 1283 { 1284 - struct nand_chip *this = mtd->priv; 1284 + struct nand_chip *this = mtd_to_nand(mtd); 1285 1285 int ret; 1286 1286 1287 1287 /* Is a flash based bad block table requested? */ ··· 1317 1317 */ 1318 1318 int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs) 1319 1319 { 1320 - struct nand_chip *this = mtd->priv; 1320 + struct nand_chip *this = mtd_to_nand(mtd); 1321 1321 int block; 1322 1322 1323 1323 block = (int)(offs >> this->bbt_erase_shift); ··· 1332 1332 */ 1333 1333 int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) 1334 1334 { 1335 - struct nand_chip *this = mtd->priv; 1335 + struct nand_chip *this = mtd_to_nand(mtd); 1336 1336 int block, res; 1337 1337 1338 1338 block = (int)(offs >> this->bbt_erase_shift); ··· 1359 1359 */ 1360 1360 int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs) 1361 1361 { 1362 - struct nand_chip *this = mtd->priv; 1362 + struct nand_chip *this = mtd_to_nand(mtd); 1363 1363 int block, ret = 0; 1364 1364 1365 1365 block = (int)(offs >> this->bbt_erase_shift);
+3 -3
drivers/mtd/nand/nand_bch.c
··· 52 52 int nand_bch_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, 53 53 unsigned char *code) 54 54 { 55 - const struct nand_chip *chip = mtd->priv; 55 + const struct nand_chip *chip = mtd_to_nand(mtd); 56 56 struct nand_bch_control *nbc = chip->ecc.priv; 57 57 unsigned int i; 58 58 ··· 79 79 int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf, 80 80 unsigned char *read_ecc, unsigned char *calc_ecc) 81 81 { 82 - const struct nand_chip *chip = mtd->priv; 82 + const struct nand_chip *chip = mtd_to_nand(mtd); 83 83 struct nand_bch_control *nbc = chip->ecc.priv; 84 84 unsigned int *errloc = nbc->errloc; 85 85 int i, count; ··· 98 98 } 99 99 } else if (count < 0) { 100 100 printk(KERN_ERR "ecc unrecoverable error\n"); 101 - count = -1; 101 + count = -EBADMSG; 102 102 } 103 103 return count; 104 104 }
+3 -3
drivers/mtd/nand/nand_ecc.c
··· 424 424 unsigned char *code) 425 425 { 426 426 __nand_calculate_ecc(buf, 427 - ((struct nand_chip *)mtd->priv)->ecc.size, code); 427 + mtd_to_nand(mtd)->ecc.size, code); 428 428 429 429 return 0; 430 430 } ··· 507 507 return 1; /* error in ECC data; no action needed */ 508 508 509 509 pr_err("%s: uncorrectable ECC error\n", __func__); 510 - return -1; 510 + return -EBADMSG; 511 511 } 512 512 EXPORT_SYMBOL(__nand_correct_data); 513 513 ··· 524 524 unsigned char *read_ecc, unsigned char *calc_ecc) 525 525 { 526 526 return __nand_correct_data(buf, read_ecc, calc_ecc, 527 - ((struct nand_chip *)mtd->priv)->ecc.size); 527 + mtd_to_nand(mtd)->ecc.size); 528 528 } 529 529 EXPORT_SYMBOL(nand_correct_data); 530 530
+23 -18
drivers/mtd/nand/nandsim.c
··· 666 666 */ 667 667 static int init_nandsim(struct mtd_info *mtd) 668 668 { 669 - struct nand_chip *chip = mtd->priv; 670 - struct nandsim *ns = chip->priv; 669 + struct nand_chip *chip = mtd_to_nand(mtd); 670 + struct nandsim *ns = nand_get_controller_data(chip); 671 671 int i, ret = 0; 672 672 uint64_t remains; 673 673 uint64_t next_offset; ··· 1908 1908 1909 1909 static u_char ns_nand_read_byte(struct mtd_info *mtd) 1910 1910 { 1911 - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; 1911 + struct nand_chip *chip = mtd_to_nand(mtd); 1912 + struct nandsim *ns = nand_get_controller_data(chip); 1912 1913 u_char outb = 0x00; 1913 1914 1914 1915 /* Sanity and correctness checks */ ··· 1970 1969 1971 1970 static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte) 1972 1971 { 1973 - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; 1972 + struct nand_chip *chip = mtd_to_nand(mtd); 1973 + struct nandsim *ns = nand_get_controller_data(chip); 1974 1974 1975 1975 /* Sanity and correctness checks */ 1976 1976 if (!ns->lines.ce) { ··· 2125 2123 2126 2124 static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask) 2127 2125 { 2128 - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; 2126 + struct nand_chip *chip = mtd_to_nand(mtd); 2127 + struct nandsim *ns = nand_get_controller_data(chip); 2129 2128 2130 2129 ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; 2131 2130 ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; ··· 2144 2141 2145 2142 static uint16_t ns_nand_read_word(struct mtd_info *mtd) 2146 2143 { 2147 - struct nand_chip *chip = (struct nand_chip *)mtd->priv; 2144 + struct nand_chip *chip = mtd_to_nand(mtd); 2148 2145 2149 2146 NS_DBG("read_word\n"); 2150 2147 ··· 2153 2150 2154 2151 static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 2155 2152 { 2156 - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; 2153 + struct nand_chip *chip = mtd_to_nand(mtd); 2154 + struct nandsim *ns = nand_get_controller_data(chip); 2157 2155 2158 2156 /* Check that chip is expecting data input */ 2159 2157 if (!(ns->state & STATE_DATAIN_MASK)) { ··· 2181 2177 2182 2178 static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 2183 2179 { 2184 - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; 2180 + struct nand_chip *chip = mtd_to_nand(mtd); 2181 + struct nandsim *ns = nand_get_controller_data(chip); 2185 2182 2186 2183 /* Sanity and correctness checks */ 2187 2184 if (!ns->lines.ce) { ··· 2203 2198 int i; 2204 2199 2205 2200 for (i = 0; i < len; i++) 2206 - buf[i] = ((struct nand_chip *)mtd->priv)->read_byte(mtd); 2201 + buf[i] = mtd_to_nand(mtd)->read_byte(mtd); 2207 2202 2208 2203 return; 2209 2204 } ··· 2241 2236 } 2242 2237 2243 2238 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ 2244 - nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) 2245 - + sizeof(struct nandsim), GFP_KERNEL); 2246 - if (!nsmtd) { 2239 + chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim), 2240 + GFP_KERNEL); 2241 + if (!chip) { 2247 2242 NS_ERR("unable to allocate core structures.\n"); 2248 2243 return -ENOMEM; 2249 2244 } 2250 - chip = (struct nand_chip *)(nsmtd + 1); 2251 - nsmtd->priv = (void *)chip; 2245 + nsmtd = nand_to_mtd(chip); 2252 2246 nand = (struct nandsim *)(chip + 1); 2253 - chip->priv = (void *)nand; 2247 + nand_set_controller_data(chip, (void *)nand); 2254 2248 2255 2249 /* 2256 2250 * Register simulator's callbacks. ··· 2396 2392 for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i) 2397 2393 kfree(nand->partitions[i].name); 2398 2394 error: 2399 - kfree(nsmtd); 2395 + kfree(chip); 2400 2396 free_lists(); 2401 2397 2402 2398 return retval; ··· 2409 2405 */ 2410 2406 static void __exit ns_cleanup_module(void) 2411 2407 { 2412 - struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv; 2408 + struct nand_chip *chip = mtd_to_nand(nsmtd); 2409 + struct nandsim *ns = nand_get_controller_data(chip); 2413 2410 int i; 2414 2411 2415 2412 nandsim_debugfs_remove(ns); ··· 2418 2413 nand_release(nsmtd); /* Unregister driver */ 2419 2414 for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) 2420 2415 kfree(ns->partitions[i].name); 2421 - kfree(nsmtd); /* Free other structures */ 2416 + kfree(mtd_to_nand(nsmtd)); /* Free other structures */ 2422 2417 free_lists(); 2423 2418 } 2424 2419
+27 -28
drivers/mtd/nand/ndfc.c
··· 37 37 struct ndfc_controller { 38 38 struct platform_device *ofdev; 39 39 void __iomem *ndfcbase; 40 - struct mtd_info mtd; 41 40 struct nand_chip chip; 42 41 int chip_select; 43 42 struct nand_hw_control ndfc_control; ··· 47 48 static void ndfc_select_chip(struct mtd_info *mtd, int chip) 48 49 { 49 50 uint32_t ccr; 50 - struct nand_chip *nchip = mtd->priv; 51 - struct ndfc_controller *ndfc = nchip->priv; 51 + struct nand_chip *nchip = mtd_to_nand(mtd); 52 + struct ndfc_controller *ndfc = nand_get_controller_data(nchip); 52 53 53 54 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR); 54 55 if (chip >= 0) { ··· 61 62 62 63 static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 63 64 { 64 - struct nand_chip *chip = mtd->priv; 65 - struct ndfc_controller *ndfc = chip->priv; 65 + struct nand_chip *chip = mtd_to_nand(mtd); 66 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 66 67 67 68 if (cmd == NAND_CMD_NONE) 68 69 return; ··· 75 76 76 77 static int ndfc_ready(struct mtd_info *mtd) 77 78 { 78 - struct nand_chip *chip = mtd->priv; 79 - struct ndfc_controller *ndfc = chip->priv; 79 + struct nand_chip *chip = mtd_to_nand(mtd); 80 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 80 81 81 82 return in_be32(ndfc->ndfcbase + NDFC_STAT) & NDFC_STAT_IS_READY; 82 83 } ··· 84 85 static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode) 85 86 { 86 87 uint32_t ccr; 87 - struct nand_chip *chip = mtd->priv; 88 - struct ndfc_controller *ndfc = chip->priv; 88 + struct nand_chip *chip = mtd_to_nand(mtd); 89 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 89 90 90 91 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR); 91 92 ccr |= NDFC_CCR_RESET_ECC; ··· 96 97 static int ndfc_calculate_ecc(struct mtd_info *mtd, 97 98 const u_char *dat, u_char *ecc_code) 98 99 { 99 - struct nand_chip *chip = mtd->priv; 100 - struct ndfc_controller *ndfc = chip->priv; 100 + struct nand_chip *chip = mtd_to_nand(mtd); 101 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 101 102 uint32_t ecc; 102 103 uint8_t *p = (uint8_t *)&ecc; 103 104 ··· 120 121 */ 121 122 static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 122 123 { 123 - struct nand_chip *chip = mtd->priv; 124 - struct ndfc_controller *ndfc = chip->priv; 124 + struct nand_chip *chip = mtd_to_nand(mtd); 125 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 125 126 uint32_t *p = (uint32_t *) buf; 126 127 127 128 for(;len > 0; len -= 4) ··· 130 131 131 132 static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 132 133 { 133 - struct nand_chip *chip = mtd->priv; 134 - struct ndfc_controller *ndfc = chip->priv; 134 + struct nand_chip *chip = mtd_to_nand(mtd); 135 + struct ndfc_controller *ndfc = nand_get_controller_data(chip); 135 136 uint32_t *p = (uint32_t *) buf; 136 137 137 138 for(;len > 0; len -= 4) ··· 146 147 { 147 148 struct device_node *flash_np; 148 149 struct nand_chip *chip = &ndfc->chip; 149 - struct mtd_part_parser_data ppdata; 150 + struct mtd_info *mtd = nand_to_mtd(chip); 150 151 int ret; 151 152 152 153 chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA; ··· 165 166 chip->ecc.size = 256; 166 167 chip->ecc.bytes = 3; 167 168 chip->ecc.strength = 1; 168 - chip->priv = ndfc; 169 + nand_set_controller_data(chip, ndfc); 169 170 170 - ndfc->mtd.priv = chip; 171 - ndfc->mtd.dev.parent = &ndfc->ofdev->dev; 171 + mtd->dev.parent = &ndfc->ofdev->dev; 172 172 173 173 flash_np = of_get_next_child(node, NULL); 174 174 if (!flash_np) 175 175 return -ENODEV; 176 + nand_set_flash_node(chip, flash_np); 176 177 177 - ppdata.of_node = flash_np; 178 - ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s", 179 - dev_name(&ndfc->ofdev->dev), flash_np->name); 180 - if (!ndfc->mtd.name) { 178 + mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(&ndfc->ofdev->dev), 179 + flash_np->name); 180 + if (!mtd->name) { 181 181 ret = -ENOMEM; 182 182 goto err; 183 183 } 184 184 185 - ret = nand_scan(&ndfc->mtd, 1); 185 + ret = nand_scan(mtd, 1); 186 186 if (ret) 187 187 goto err; 188 188 189 - ret = mtd_device_parse_register(&ndfc->mtd, NULL, &ppdata, NULL, 0); 189 + ret = mtd_device_register(mtd, NULL, 0); 190 190 191 191 err: 192 192 of_node_put(flash_np); 193 193 if (ret) 194 - kfree(ndfc->mtd.name); 194 + kfree(mtd->name); 195 195 return ret; 196 196 } 197 197 ··· 257 259 static int ndfc_remove(struct platform_device *ofdev) 258 260 { 259 261 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev); 262 + struct mtd_info *mtd = nand_to_mtd(&ndfc->chip); 260 263 261 - nand_release(&ndfc->mtd); 262 - kfree(ndfc->mtd.name); 264 + nand_release(mtd); 265 + kfree(mtd->name); 263 266 264 267 return 0; 265 268 }
+17 -23
drivers/mtd/nand/nuc900_nand.c
··· 55 55 __raw_writel((val), (dev)->reg + REG_SMADDR) 56 56 57 57 struct nuc900_nand { 58 - struct mtd_info mtd; 59 58 struct nand_chip chip; 60 59 void __iomem *reg; 61 60 struct clk *clk; 62 61 spinlock_t lock; 63 62 }; 63 + 64 + static inline struct nuc900_nand *mtd_to_nuc900(struct mtd_info *mtd) 65 + { 66 + return container_of(mtd_to_nand(mtd), struct nuc900_nand, chip); 67 + } 64 68 65 69 static const struct mtd_partition partitions[] = { 66 70 { ··· 82 78 static unsigned char nuc900_nand_read_byte(struct mtd_info *mtd) 83 79 { 84 80 unsigned char ret; 85 - struct nuc900_nand *nand; 86 - 87 - nand = container_of(mtd, struct nuc900_nand, mtd); 81 + struct nuc900_nand *nand = mtd_to_nuc900(mtd); 88 82 89 83 ret = (unsigned char)read_data_reg(nand); 90 84 ··· 93 91 unsigned char *buf, int len) 94 92 { 95 93 int i; 96 - struct nuc900_nand *nand; 97 - 98 - nand = container_of(mtd, struct nuc900_nand, mtd); 94 + struct nuc900_nand *nand = mtd_to_nuc900(mtd); 99 95 100 96 for (i = 0; i < len; i++) 101 97 buf[i] = (unsigned char)read_data_reg(nand); ··· 103 103 const unsigned char *buf, int len) 104 104 { 105 105 int i; 106 - struct nuc900_nand *nand; 107 - 108 - nand = container_of(mtd, struct nuc900_nand, mtd); 106 + struct nuc900_nand *nand = mtd_to_nuc900(mtd); 109 107 110 108 for (i = 0; i < len; i++) 111 109 write_data_reg(nand, buf[i]); ··· 122 124 123 125 static int nuc900_nand_devready(struct mtd_info *mtd) 124 126 { 125 - struct nuc900_nand *nand; 127 + struct nuc900_nand *nand = mtd_to_nuc900(mtd); 126 128 int ready; 127 - 128 - nand = container_of(mtd, struct nuc900_nand, mtd); 129 129 130 130 ready = (nuc900_check_rb(nand)) ? 1 : 0; 131 131 return ready; ··· 132 136 static void nuc900_nand_command_lp(struct mtd_info *mtd, unsigned int command, 133 137 int column, int page_addr) 134 138 { 135 - register struct nand_chip *chip = mtd->priv; 136 - struct nuc900_nand *nand; 137 - 138 - nand = container_of(mtd, struct nuc900_nand, mtd); 139 + register struct nand_chip *chip = mtd_to_nand(mtd); 140 + struct nuc900_nand *nand = mtd_to_nuc900(mtd); 139 141 140 142 if (command == NAND_CMD_READOOB) { 141 143 column += mtd->writesize; ··· 235 241 { 236 242 struct nuc900_nand *nuc900_nand; 237 243 struct nand_chip *chip; 244 + struct mtd_info *mtd; 238 245 struct resource *res; 239 246 240 247 nuc900_nand = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_nand), ··· 243 248 if (!nuc900_nand) 244 249 return -ENOMEM; 245 250 chip = &(nuc900_nand->chip); 251 + mtd = nand_to_mtd(chip); 246 252 247 - nuc900_nand->mtd.priv = chip; 248 - nuc900_nand->mtd.dev.parent = &pdev->dev; 253 + mtd->dev.parent = &pdev->dev; 249 254 spin_lock_init(&nuc900_nand->lock); 250 255 251 256 nuc900_nand->clk = devm_clk_get(&pdev->dev, NULL); ··· 269 274 270 275 nuc900_nand_enable(nuc900_nand); 271 276 272 - if (nand_scan(&(nuc900_nand->mtd), 1)) 277 + if (nand_scan(mtd, 1)) 273 278 return -ENXIO; 274 279 275 - mtd_device_register(&(nuc900_nand->mtd), partitions, 276 - ARRAY_SIZE(partitions)); 280 + mtd_device_register(mtd, partitions, ARRAY_SIZE(partitions)); 277 281 278 282 platform_set_drvdata(pdev, nuc900_nand); 279 283 ··· 283 289 { 284 290 struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev); 285 291 286 - nand_release(&nuc900_nand->mtd); 292 + nand_release(nand_to_mtd(&nuc900_nand->chip)); 287 293 clk_disable(nuc900_nand->clk); 288 294 289 295 return 0;
+38 -54
drivers/mtd/nand/omap2.c
··· 152 152 153 153 struct omap_nand_info { 154 154 struct omap_nand_platform_data *pdata; 155 - struct mtd_info mtd; 156 155 struct nand_chip nand; 157 156 struct platform_device *pdev; 158 157 ··· 175 176 struct device *elm_dev; 176 177 struct device_node *of_node; 177 178 }; 179 + 180 + static inline struct omap_nand_info *mtd_to_omap(struct mtd_info *mtd) 181 + { 182 + return container_of(mtd_to_nand(mtd), struct omap_nand_info, nand); 183 + } 178 184 179 185 /** 180 186 * omap_prefetch_enable - configures and starts prefetch transfer ··· 251 247 */ 252 248 static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 253 249 { 254 - struct omap_nand_info *info = container_of(mtd, 255 - struct omap_nand_info, mtd); 250 + struct omap_nand_info *info = mtd_to_omap(mtd); 256 251 257 252 if (cmd != NAND_CMD_NONE) { 258 253 if (ctrl & NAND_CLE) ··· 273 270 */ 274 271 static void omap_read_buf8(struct mtd_info *mtd, u_char *buf, int len) 275 272 { 276 - struct nand_chip *nand = mtd->priv; 273 + struct nand_chip *nand = mtd_to_nand(mtd); 277 274 278 275 ioread8_rep(nand->IO_ADDR_R, buf, len); 279 276 } ··· 286 283 */ 287 284 static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len) 288 285 { 289 - struct omap_nand_info *info = container_of(mtd, 290 - struct omap_nand_info, mtd); 286 + struct omap_nand_info *info = mtd_to_omap(mtd); 291 287 u_char *p = (u_char *)buf; 292 288 u32 status = 0; 293 289 ··· 308 306 */ 309 307 static void omap_read_buf16(struct mtd_info *mtd, u_char *buf, int len) 310 308 { 311 - struct nand_chip *nand = mtd->priv; 309 + struct nand_chip *nand = mtd_to_nand(mtd); 312 310 313 311 ioread16_rep(nand->IO_ADDR_R, buf, len / 2); 314 312 } ··· 321 319 */ 322 320 static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len) 323 321 { 324 - struct omap_nand_info *info = container_of(mtd, 325 - struct omap_nand_info, mtd); 322 + struct omap_nand_info *info = mtd_to_omap(mtd); 326 323 u16 *p = (u16 *) buf; 327 324 u32 status = 0; 328 325 /* FIXME try bursts of writesw() or DMA ... */ ··· 345 344 */ 346 345 static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len) 347 346 { 348 - struct omap_nand_info *info = container_of(mtd, 349 - struct omap_nand_info, mtd); 347 + struct omap_nand_info *info = mtd_to_omap(mtd); 350 348 uint32_t r_count = 0; 351 349 int ret = 0; 352 350 u32 *p = (u32 *)buf; ··· 392 392 static void omap_write_buf_pref(struct mtd_info *mtd, 393 393 const u_char *buf, int len) 394 394 { 395 - struct omap_nand_info *info = container_of(mtd, 396 - struct omap_nand_info, mtd); 395 + struct omap_nand_info *info = mtd_to_omap(mtd); 397 396 uint32_t w_count = 0; 398 397 int i = 0, ret = 0; 399 398 u16 *p = (u16 *)buf; ··· 457 458 static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr, 458 459 unsigned int len, int is_write) 459 460 { 460 - struct omap_nand_info *info = container_of(mtd, 461 - struct omap_nand_info, mtd); 461 + struct omap_nand_info *info = mtd_to_omap(mtd); 462 462 struct dma_async_tx_descriptor *tx; 463 463 enum dma_data_direction dir = is_write ? DMA_TO_DEVICE : 464 464 DMA_FROM_DEVICE; ··· 621 623 */ 622 624 static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len) 623 625 { 624 - struct omap_nand_info *info = container_of(mtd, 625 - struct omap_nand_info, mtd); 626 + struct omap_nand_info *info = mtd_to_omap(mtd); 626 627 int ret = 0; 627 628 628 629 if (len <= mtd->oobsize) { ··· 668 671 static void omap_write_buf_irq_pref(struct mtd_info *mtd, 669 672 const u_char *buf, int len) 670 673 { 671 - struct omap_nand_info *info = container_of(mtd, 672 - struct omap_nand_info, mtd); 674 + struct omap_nand_info *info = mtd_to_omap(mtd); 673 675 int ret = 0; 674 676 unsigned long tim, limit; 675 677 u32 val; ··· 826 830 case 1: 827 831 /* Uncorrectable error */ 828 832 pr_debug("ECC UNCORRECTED_ERROR 1\n"); 829 - return -1; 833 + return -EBADMSG; 830 834 831 835 case 11: 832 836 /* UN-Correctable error */ 833 837 pr_debug("ECC UNCORRECTED_ERROR B\n"); 834 - return -1; 838 + return -EBADMSG; 835 839 836 840 case 12: 837 841 /* Correctable error */ ··· 861 865 return 0; 862 866 } 863 867 pr_debug("UNCORRECTED_ERROR default\n"); 864 - return -1; 868 + return -EBADMSG; 865 869 } 866 870 } 867 871 ··· 882 886 static int omap_correct_data(struct mtd_info *mtd, u_char *dat, 883 887 u_char *read_ecc, u_char *calc_ecc) 884 888 { 885 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 886 - mtd); 889 + struct omap_nand_info *info = mtd_to_omap(mtd); 887 890 int blockCnt = 0, i = 0, ret = 0; 888 891 int stat = 0; 889 892 ··· 923 928 static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat, 924 929 u_char *ecc_code) 925 930 { 926 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 927 - mtd); 931 + struct omap_nand_info *info = mtd_to_omap(mtd); 928 932 u32 val; 929 933 930 934 val = readl(info->reg.gpmc_ecc_config); ··· 947 953 */ 948 954 static void omap_enable_hwecc(struct mtd_info *mtd, int mode) 949 955 { 950 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 951 - mtd); 952 - struct nand_chip *chip = mtd->priv; 956 + struct omap_nand_info *info = mtd_to_omap(mtd); 957 + struct nand_chip *chip = mtd_to_nand(mtd); 953 958 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0; 954 959 u32 val; 955 960 ··· 994 1001 */ 995 1002 static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip) 996 1003 { 997 - struct nand_chip *this = mtd->priv; 998 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 999 - mtd); 1004 + struct nand_chip *this = mtd_to_nand(mtd); 1005 + struct omap_nand_info *info = mtd_to_omap(mtd); 1000 1006 unsigned long timeo = jiffies; 1001 1007 int status, state = this->state; 1002 1008 ··· 1023 1031 static int omap_dev_ready(struct mtd_info *mtd) 1024 1032 { 1025 1033 unsigned int val = 0; 1026 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 1027 - mtd); 1034 + struct omap_nand_info *info = mtd_to_omap(mtd); 1028 1035 1029 1036 val = readl(info->reg.gpmc_status); 1030 1037 ··· 1049 1058 { 1050 1059 unsigned int bch_type; 1051 1060 unsigned int dev_width, nsectors; 1052 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 1053 - mtd); 1061 + struct omap_nand_info *info = mtd_to_omap(mtd); 1054 1062 enum omap_ecc ecc_opt = info->ecc_opt; 1055 - struct nand_chip *chip = mtd->priv; 1063 + struct nand_chip *chip = mtd_to_nand(mtd); 1056 1064 u32 val, wr_mode; 1057 1065 unsigned int ecc_size1, ecc_size0; 1058 1066 ··· 1152 1162 static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd, 1153 1163 const u_char *dat, u_char *ecc_calc) 1154 1164 { 1155 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 1156 - mtd); 1165 + struct omap_nand_info *info = mtd_to_omap(mtd); 1157 1166 int eccbytes = info->nand.ecc.bytes; 1158 1167 struct gpmc_nand_regs *gpmc_regs = &info->reg; 1159 1168 u8 *ecc_code; ··· 1323 1334 static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data, 1324 1335 u_char *read_ecc, u_char *calc_ecc) 1325 1336 { 1326 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 1327 - mtd); 1337 + struct omap_nand_info *info = mtd_to_omap(mtd); 1328 1338 struct nand_ecc_ctrl *ecc = &info->nand.ecc; 1329 1339 int eccsteps = info->nand.ecc.steps; 1330 1340 int i , j, stat = 0; ··· 1651 1663 unsigned sig; 1652 1664 unsigned oob_index; 1653 1665 struct resource *res; 1654 - struct mtd_part_parser_data ppdata = {}; 1655 1666 1656 1667 pdata = dev_get_platdata(&pdev->dev); 1657 1668 if (pdata == NULL) { ··· 1670 1683 info->reg = pdata->reg; 1671 1684 info->of_node = pdata->of_node; 1672 1685 info->ecc_opt = pdata->ecc_opt; 1673 - mtd = &info->mtd; 1674 - mtd->priv = &info->nand; 1675 - mtd->dev.parent = &pdev->dev; 1676 1686 nand_chip = &info->nand; 1687 + mtd = nand_to_mtd(nand_chip); 1688 + mtd->dev.parent = &pdev->dev; 1677 1689 nand_chip->ecc.priv = NULL; 1690 + nand_set_flash_node(nand_chip, pdata->of_node); 1678 1691 1679 1692 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1680 1693 nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res); ··· 1896 1909 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1; 1897 1910 1898 1911 err = elm_config(info->elm_dev, BCH4_ECC, 1899 - info->mtd.writesize / nand_chip->ecc.size, 1912 + mtd->writesize / nand_chip->ecc.size, 1900 1913 nand_chip->ecc.size, nand_chip->ecc.bytes); 1901 1914 if (err < 0) 1902 1915 goto return_error; ··· 1950 1963 nand_chip->ecc.write_page = omap_write_page_bch; 1951 1964 1952 1965 err = elm_config(info->elm_dev, BCH8_ECC, 1953 - info->mtd.writesize / nand_chip->ecc.size, 1966 + mtd->writesize / nand_chip->ecc.size, 1954 1967 nand_chip->ecc.size, nand_chip->ecc.bytes); 1955 1968 if (err < 0) 1956 1969 goto return_error; ··· 1980 1993 nand_chip->ecc.write_page = omap_write_page_bch; 1981 1994 1982 1995 err = elm_config(info->elm_dev, BCH16_ECC, 1983 - info->mtd.writesize / nand_chip->ecc.size, 1996 + mtd->writesize / nand_chip->ecc.size, 1984 1997 nand_chip->ecc.size, nand_chip->ecc.bytes); 1985 1998 if (err < 0) 1986 1999 goto return_error; ··· 2024 2037 goto return_error; 2025 2038 } 2026 2039 2027 - ppdata.of_node = pdata->of_node; 2028 - mtd_device_parse_register(mtd, NULL, &ppdata, pdata->parts, 2029 - pdata->nr_parts); 2040 + mtd_device_register(mtd, pdata->parts, pdata->nr_parts); 2030 2041 2031 2042 platform_set_drvdata(pdev, mtd); 2032 2043 ··· 2043 2058 static int omap_nand_remove(struct platform_device *pdev) 2044 2059 { 2045 2060 struct mtd_info *mtd = platform_get_drvdata(pdev); 2046 - struct nand_chip *nand_chip = mtd->priv; 2047 - struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 2048 - mtd); 2061 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 2062 + struct omap_nand_info *info = mtd_to_omap(mtd); 2049 2063 if (nand_chip->ecc.priv) { 2050 2064 nand_bch_free(nand_chip->ecc.priv); 2051 2065 nand_chip->ecc.priv = NULL;
+1 -1
drivers/mtd/nand/omap_elm.c
··· 414 414 ret = devm_request_irq(&pdev->dev, irq->start, elm_isr, 0, 415 415 pdev->name, info); 416 416 if (ret) { 417 - dev_err(&pdev->dev, "failure requesting irq %i\n", irq->start); 417 + dev_err(&pdev->dev, "failure requesting %pr\n", irq); 418 418 return ret; 419 419 } 420 420
+8 -11
drivers/mtd/nand/orion_nand.c
··· 25 25 26 26 static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 27 27 { 28 - struct nand_chip *nc = mtd->priv; 29 - struct orion_nand_data *board = nc->priv; 28 + struct nand_chip *nc = mtd_to_nand(mtd); 29 + struct orion_nand_data *board = nand_get_controller_data(nc); 30 30 u32 offs; 31 31 32 32 if (cmd == NAND_CMD_NONE) ··· 47 47 48 48 static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 49 49 { 50 - struct nand_chip *chip = mtd->priv; 50 + struct nand_chip *chip = mtd_to_nand(mtd); 51 51 void __iomem *io_base = chip->IO_ADDR_R; 52 52 uint64_t *buf64; 53 53 int i = 0; ··· 76 76 static int __init orion_nand_probe(struct platform_device *pdev) 77 77 { 78 78 struct mtd_info *mtd; 79 - struct mtd_part_parser_data ppdata = {}; 80 79 struct nand_chip *nc; 81 80 struct orion_nand_data *board; 82 81 struct resource *res; ··· 85 86 u32 val = 0; 86 87 87 88 nc = devm_kzalloc(&pdev->dev, 88 - sizeof(struct nand_chip) + sizeof(struct mtd_info), 89 + sizeof(struct nand_chip), 89 90 GFP_KERNEL); 90 91 if (!nc) 91 92 return -ENOMEM; 92 - mtd = (struct mtd_info *)(nc + 1); 93 + mtd = nand_to_mtd(nc); 93 94 94 95 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 95 96 io_base = devm_ioremap_resource(&pdev->dev, res); ··· 122 123 board = dev_get_platdata(&pdev->dev); 123 124 } 124 125 125 - mtd->priv = nc; 126 126 mtd->dev.parent = &pdev->dev; 127 127 128 - nc->priv = board; 128 + nand_set_controller_data(nc, board); 129 + nand_set_flash_node(nc, pdev->dev.of_node); 129 130 nc->IO_ADDR_R = nc->IO_ADDR_W = io_base; 130 131 nc->cmd_ctrl = orion_nand_cmd_ctrl; 131 132 nc->read_buf = orion_nand_read_buf; ··· 160 161 } 161 162 162 163 mtd->name = "orion_nand"; 163 - ppdata.of_node = pdev->dev.of_node; 164 - ret = mtd_device_parse_register(mtd, NULL, &ppdata, 165 - board->parts, board->nr_parts); 164 + ret = mtd_device_register(mtd, board->parts, board->nr_parts); 166 165 if (ret) { 167 166 nand_release(mtd); 168 167 goto no_dev;
+9 -12
drivers/mtd/nand/pasemi_nand.c
··· 45 45 46 46 static void pasemi_read_buf(struct mtd_info *mtd, u_char *buf, int len) 47 47 { 48 - struct nand_chip *chip = mtd->priv; 48 + struct nand_chip *chip = mtd_to_nand(mtd); 49 49 50 50 while (len > 0x800) { 51 51 memcpy_fromio(buf, chip->IO_ADDR_R, 0x800); ··· 57 57 58 58 static void pasemi_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 59 59 { 60 - struct nand_chip *chip = mtd->priv; 60 + struct nand_chip *chip = mtd_to_nand(mtd); 61 61 62 62 while (len > 0x800) { 63 63 memcpy_toio(chip->IO_ADDR_R, buf, 0x800); ··· 70 70 static void pasemi_hwcontrol(struct mtd_info *mtd, int cmd, 71 71 unsigned int ctrl) 72 72 { 73 - struct nand_chip *chip = mtd->priv; 73 + struct nand_chip *chip = mtd_to_nand(mtd); 74 74 75 75 if (cmd == NAND_CMD_NONE) 76 76 return; ··· 110 110 pr_debug("pasemi_nand at %pR\n", &res); 111 111 112 112 /* Allocate memory for MTD device structure and private data */ 113 - pasemi_nand_mtd = kzalloc(sizeof(struct mtd_info) + 114 - sizeof(struct nand_chip), GFP_KERNEL); 115 - if (!pasemi_nand_mtd) { 113 + chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 114 + if (!chip) { 116 115 printk(KERN_WARNING 117 116 "Unable to allocate PASEMI NAND MTD device structure\n"); 118 117 err = -ENOMEM; 119 118 goto out; 120 119 } 121 120 122 - /* Get pointer to private data */ 123 - chip = (struct nand_chip *)&pasemi_nand_mtd[1]; 121 + pasemi_nand_mtd = nand_to_mtd(chip); 124 122 125 123 /* Link the private data with the MTD structure */ 126 - pasemi_nand_mtd->priv = chip; 127 124 pasemi_nand_mtd->dev.parent = &ofdev->dev; 128 125 129 126 chip->IO_ADDR_R = of_iomap(np, 0); ··· 177 180 out_ior: 178 181 iounmap(chip->IO_ADDR_R); 179 182 out_mtd: 180 - kfree(pasemi_nand_mtd); 183 + kfree(chip); 181 184 out: 182 185 return err; 183 186 } ··· 189 192 if (!pasemi_nand_mtd) 190 193 return 0; 191 194 192 - chip = pasemi_nand_mtd->priv; 195 + chip = mtd_to_nand(pasemi_nand_mtd); 193 196 194 197 /* Release resources, unregister device */ 195 198 nand_release(pasemi_nand_mtd); ··· 199 202 iounmap(chip->IO_ADDR_R); 200 203 201 204 /* Free the MTD device structure */ 202 - kfree(pasemi_nand_mtd); 205 + kfree(chip); 203 206 204 207 pasemi_nand_mtd = NULL; 205 208
+8 -10
drivers/mtd/nand/plat_nand.c
··· 20 20 21 21 struct plat_nand_data { 22 22 struct nand_chip chip; 23 - struct mtd_info mtd; 24 23 void __iomem *io_base; 25 24 }; 26 25 ··· 29 30 static int plat_nand_probe(struct platform_device *pdev) 30 31 { 31 32 struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); 32 - struct mtd_part_parser_data ppdata; 33 33 struct plat_nand_data *data; 34 + struct mtd_info *mtd; 34 35 struct resource *res; 35 36 const char **part_types; 36 37 int err = 0; ··· 56 57 if (IS_ERR(data->io_base)) 57 58 return PTR_ERR(data->io_base); 58 59 59 - data->chip.priv = &data; 60 - data->mtd.priv = &data->chip; 61 - data->mtd.dev.parent = &pdev->dev; 60 + nand_set_flash_node(&data->chip, pdev->dev.of_node); 61 + mtd = nand_to_mtd(&data->chip); 62 + mtd->dev.parent = &pdev->dev; 62 63 63 64 data->chip.IO_ADDR_R = data->io_base; 64 65 data->chip.IO_ADDR_W = data->io_base; ··· 86 87 } 87 88 88 89 /* Scan to find existence of the device */ 89 - if (nand_scan(&data->mtd, pdata->chip.nr_chips)) { 90 + if (nand_scan(mtd, pdata->chip.nr_chips)) { 90 91 err = -ENXIO; 91 92 goto out; 92 93 } 93 94 94 95 part_types = pdata->chip.part_probe_types; 95 96 96 - ppdata.of_node = pdev->dev.of_node; 97 - err = mtd_device_parse_register(&data->mtd, part_types, &ppdata, 97 + err = mtd_device_parse_register(mtd, part_types, NULL, 98 98 pdata->chip.partitions, 99 99 pdata->chip.nr_partitions); 100 100 101 101 if (!err) 102 102 return err; 103 103 104 - nand_release(&data->mtd); 104 + nand_release(mtd); 105 105 out: 106 106 if (pdata->ctrl.remove) 107 107 pdata->ctrl.remove(pdev); ··· 115 117 struct plat_nand_data *data = platform_get_drvdata(pdev); 116 118 struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); 117 119 118 - nand_release(&data->mtd); 120 + nand_release(nand_to_mtd(&data->chip)); 119 121 if (pdata->ctrl.remove) 120 122 pdata->ctrl.remove(pdev); 121 123
+81 -90
drivers/mtd/nand/pxa3xx_nand.c
··· 30 30 #include <linux/of.h> 31 31 #include <linux/of_device.h> 32 32 #include <linux/of_mtd.h> 33 - 34 - #if defined(CONFIG_ARM) && (defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP)) 35 - #define ARCH_HAS_DMA 36 - #endif 37 - 38 33 #include <linux/platform_data/mtd-nand-pxa3xx.h> 39 34 40 35 #define CHIP_DELAY_TIMEOUT msecs_to_jiffies(200) ··· 167 172 168 173 struct pxa3xx_nand_host { 169 174 struct nand_chip chip; 170 - struct mtd_info *mtd; 171 175 void *info_data; 172 176 173 177 /* page size of attached chip */ ··· 449 455 struct nand_chip *chip = &host->chip; 450 456 struct pxa3xx_nand_info *info = host->info_data; 451 457 const struct pxa3xx_nand_flash *f = NULL; 458 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 452 459 int i, id, ntypes; 453 460 454 461 ntypes = ARRAY_SIZE(builtin_flash_types); 455 462 456 - chip->cmdfunc(host->mtd, NAND_CMD_READID, 0x00, -1); 463 + chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); 457 464 458 - id = chip->read_byte(host->mtd); 459 - id |= chip->read_byte(host->mtd) << 0x8; 465 + id = chip->read_byte(mtd); 466 + id |= chip->read_byte(mtd) << 0x8; 460 467 461 468 for (i = 0; i < ntypes; i++) { 462 469 f = &builtin_flash_types[i]; ··· 890 895 static void prepare_start_command(struct pxa3xx_nand_info *info, int command) 891 896 { 892 897 struct pxa3xx_nand_host *host = info->host[info->cs]; 893 - struct mtd_info *mtd = host->mtd; 898 + struct mtd_info *mtd = nand_to_mtd(&host->chip); 894 899 895 900 /* reset data and oob column point to handle data */ 896 901 info->buf_start = 0; ··· 943 948 struct mtd_info *mtd; 944 949 945 950 host = info->host[info->cs]; 946 - mtd = host->mtd; 951 + mtd = nand_to_mtd(&host->chip); 947 952 addr_cycle = 0; 948 953 exec_cmd = 1; 949 954 ··· 1113 1118 static void nand_cmdfunc(struct mtd_info *mtd, unsigned command, 1114 1119 int column, int page_addr) 1115 1120 { 1116 - struct pxa3xx_nand_host *host = mtd->priv; 1121 + struct nand_chip *chip = mtd_to_nand(mtd); 1122 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1117 1123 struct pxa3xx_nand_info *info = host->info_data; 1118 1124 int exec_cmd; 1119 1125 ··· 1162 1166 const unsigned command, 1163 1167 int column, int page_addr) 1164 1168 { 1165 - struct pxa3xx_nand_host *host = mtd->priv; 1169 + struct nand_chip *chip = mtd_to_nand(mtd); 1170 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1166 1171 struct pxa3xx_nand_info *info = host->info_data; 1167 1172 int exec_cmd, ext_cmd_type; 1168 1173 ··· 1283 1286 struct nand_chip *chip, uint8_t *buf, int oob_required, 1284 1287 int page) 1285 1288 { 1286 - struct pxa3xx_nand_host *host = mtd->priv; 1289 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1287 1290 struct pxa3xx_nand_info *info = host->info_data; 1288 1291 1289 1292 chip->read_buf(mtd, buf, mtd->writesize); ··· 1309 1312 1310 1313 static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd) 1311 1314 { 1312 - struct pxa3xx_nand_host *host = mtd->priv; 1315 + struct nand_chip *chip = mtd_to_nand(mtd); 1316 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1313 1317 struct pxa3xx_nand_info *info = host->info_data; 1314 1318 char retval = 0xFF; 1315 1319 ··· 1323 1325 1324 1326 static u16 pxa3xx_nand_read_word(struct mtd_info *mtd) 1325 1327 { 1326 - struct pxa3xx_nand_host *host = mtd->priv; 1328 + struct nand_chip *chip = mtd_to_nand(mtd); 1329 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1327 1330 struct pxa3xx_nand_info *info = host->info_data; 1328 1331 u16 retval = 0xFFFF; 1329 1332 ··· 1337 1338 1338 1339 static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 1339 1340 { 1340 - struct pxa3xx_nand_host *host = mtd->priv; 1341 + struct nand_chip *chip = mtd_to_nand(mtd); 1342 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1341 1343 struct pxa3xx_nand_info *info = host->info_data; 1342 1344 int real_len = min_t(size_t, len, info->buf_count - info->buf_start); 1343 1345 ··· 1349 1349 static void pxa3xx_nand_write_buf(struct mtd_info *mtd, 1350 1350 const uint8_t *buf, int len) 1351 1351 { 1352 - struct pxa3xx_nand_host *host = mtd->priv; 1352 + struct nand_chip *chip = mtd_to_nand(mtd); 1353 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1353 1354 struct pxa3xx_nand_info *info = host->info_data; 1354 1355 int real_len = min_t(size_t, len, info->buf_count - info->buf_start); 1355 1356 ··· 1365 1364 1366 1365 static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) 1367 1366 { 1368 - struct pxa3xx_nand_host *host = mtd->priv; 1367 + struct nand_chip *chip = mtd_to_nand(mtd); 1368 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1369 1369 struct pxa3xx_nand_info *info = host->info_data; 1370 1370 1371 1371 if (info->need_wait) { ··· 1389 1387 return NAND_STATUS_READY; 1390 1388 } 1391 1389 1392 - static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info) 1390 + static int pxa3xx_nand_config_ident(struct pxa3xx_nand_info *info) 1393 1391 { 1392 + struct pxa3xx_nand_host *host = info->host[info->cs]; 1394 1393 struct platform_device *pdev = info->pdev; 1395 1394 struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 1396 - struct pxa3xx_nand_host *host = info->host[info->cs]; 1397 - struct mtd_info *mtd = host->mtd; 1398 - struct nand_chip *chip = mtd->priv; 1395 + const struct nand_sdr_timings *timings; 1399 1396 1400 - /* configure default flash values */ 1397 + /* Configure default flash values */ 1398 + info->chunk_size = PAGE_CHUNK_SIZE; 1401 1399 info->reg_ndcr = 0x0; /* enable all interrupts */ 1402 1400 info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; 1403 1401 info->reg_ndcr |= NDCR_RD_ID_CNT(READ_ID_BYTES); 1404 - info->reg_ndcr |= NDCR_SPARE_EN; /* enable spare by default */ 1405 - info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0; 1406 - info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0; 1407 - info->reg_ndcr |= (mtd->writesize == 2048) ? NDCR_PAGE_SZ : 0; 1402 + info->reg_ndcr |= NDCR_SPARE_EN; 1408 1403 1404 + /* use the common timing to make a try */ 1405 + timings = onfi_async_timing_mode_to_sdr_timings(0); 1406 + if (IS_ERR(timings)) 1407 + return PTR_ERR(timings); 1408 + 1409 + pxa3xx_nand_set_sdr_timing(host, timings); 1409 1410 return 0; 1410 1411 } 1411 1412 1412 - static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) 1413 + static void pxa3xx_nand_config_tail(struct pxa3xx_nand_info *info) 1413 1414 { 1415 + struct pxa3xx_nand_host *host = info->host[info->cs]; 1416 + struct nand_chip *chip = &host->chip; 1417 + struct mtd_info *mtd = nand_to_mtd(chip); 1418 + 1419 + info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0; 1420 + info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0; 1421 + info->reg_ndcr |= (mtd->writesize == 2048) ? NDCR_PAGE_SZ : 0; 1422 + } 1423 + 1424 + static void pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) 1425 + { 1426 + struct platform_device *pdev = info->pdev; 1427 + struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 1414 1428 uint32_t ndcr = nand_readl(info, NDCR); 1415 1429 1416 1430 /* Set an initial chunk size */ 1417 1431 info->chunk_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512; 1418 1432 info->reg_ndcr = ndcr & 1419 1433 ~(NDCR_INT_MASK | NDCR_ND_ARB_EN | NFCV1_NDCR_ARB_CNTL); 1434 + info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; 1420 1435 info->ndtr0cs0 = nand_readl(info, NDTR0CS0); 1421 1436 info->ndtr1cs0 = nand_readl(info, NDTR1CS0); 1422 - return 0; 1423 1437 } 1424 1438 1425 1439 static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info) ··· 1499 1481 dma_release_channel(info->dma_chan); 1500 1482 } 1501 1483 kfree(info->data_buff); 1502 - } 1503 - 1504 - static int pxa3xx_nand_sensing(struct pxa3xx_nand_host *host) 1505 - { 1506 - struct pxa3xx_nand_info *info = host->info_data; 1507 - struct mtd_info *mtd; 1508 - struct nand_chip *chip; 1509 - const struct nand_sdr_timings *timings; 1510 - int ret; 1511 - 1512 - mtd = info->host[info->cs]->mtd; 1513 - chip = mtd->priv; 1514 - 1515 - /* use the common timing to make a try */ 1516 - timings = onfi_async_timing_mode_to_sdr_timings(0); 1517 - if (IS_ERR(timings)) 1518 - return PTR_ERR(timings); 1519 - 1520 - pxa3xx_nand_set_sdr_timing(host, timings); 1521 - 1522 - chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0); 1523 - ret = chip->waitfunc(mtd, chip); 1524 - if (ret & NAND_STATUS_FAIL) 1525 - return -ENODEV; 1526 - 1527 - return 0; 1528 1484 } 1529 1485 1530 1486 static int pxa_ecc_init(struct pxa3xx_nand_info *info, ··· 1572 1580 1573 1581 static int pxa3xx_nand_scan(struct mtd_info *mtd) 1574 1582 { 1575 - struct pxa3xx_nand_host *host = mtd->priv; 1583 + struct nand_chip *chip = mtd_to_nand(mtd); 1584 + struct pxa3xx_nand_host *host = nand_get_controller_data(chip); 1576 1585 struct pxa3xx_nand_info *info = host->info_data; 1577 1586 struct platform_device *pdev = info->pdev; 1578 1587 struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); 1579 - struct nand_chip *chip = mtd->priv; 1580 1588 int ret; 1581 1589 uint16_t ecc_strength, ecc_step; 1582 1590 1583 - if (pdata->keep_config && !pxa3xx_nand_detect_config(info)) 1584 - goto KEEP_CONFIG; 1585 - 1586 - /* Set a default chunk size */ 1587 - info->chunk_size = 512; 1588 - 1589 - ret = pxa3xx_nand_config_flash(info); 1590 - if (ret) 1591 - return ret; 1592 - 1593 - ret = pxa3xx_nand_sensing(host); 1594 - if (ret) { 1595 - dev_info(&info->pdev->dev, "There is no chip on cs %d!\n", 1596 - info->cs); 1597 - 1598 - return ret; 1591 + if (pdata->keep_config) { 1592 + pxa3xx_nand_detect_config(info); 1593 + } else { 1594 + ret = pxa3xx_nand_config_ident(info); 1595 + if (ret) 1596 + return ret; 1599 1597 } 1600 1598 1601 - KEEP_CONFIG: 1602 - info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; 1603 1599 if (info->reg_ndcr & NDCR_DWIDTH_M) 1604 1600 chip->options |= NAND_BUSWIDTH_16; 1605 1601 ··· 1672 1692 host->row_addr_cycles = 3; 1673 1693 else 1674 1694 host->row_addr_cycles = 2; 1695 + 1696 + if (!pdata->keep_config) 1697 + pxa3xx_nand_config_tail(info); 1698 + 1675 1699 return nand_scan_tail(mtd); 1676 1700 } 1677 1701 1678 1702 static int alloc_nand_resource(struct platform_device *pdev) 1679 1703 { 1704 + struct device_node *np = pdev->dev.of_node; 1680 1705 struct pxa3xx_nand_platform_data *pdata; 1681 1706 struct pxa3xx_nand_info *info; 1682 1707 struct pxa3xx_nand_host *host; ··· 1693 1708 pdata = dev_get_platdata(&pdev->dev); 1694 1709 if (pdata->num_cs <= 0) 1695 1710 return -ENODEV; 1696 - info = devm_kzalloc(&pdev->dev, sizeof(*info) + (sizeof(*mtd) + 1697 - sizeof(*host)) * pdata->num_cs, GFP_KERNEL); 1711 + info = devm_kzalloc(&pdev->dev, 1712 + sizeof(*info) + sizeof(*host) * pdata->num_cs, 1713 + GFP_KERNEL); 1698 1714 if (!info) 1699 1715 return -ENOMEM; 1700 1716 1701 1717 info->pdev = pdev; 1702 1718 info->variant = pxa3xx_nand_get_variant(pdev); 1703 1719 for (cs = 0; cs < pdata->num_cs; cs++) { 1704 - mtd = (void *)&info[1] + (sizeof(*mtd) + sizeof(*host)) * cs; 1705 - chip = (struct nand_chip *)(&mtd[1]); 1706 - host = (struct pxa3xx_nand_host *)chip; 1720 + host = (void *)&info[1] + sizeof(*host) * cs; 1721 + chip = &host->chip; 1722 + nand_set_controller_data(chip, host); 1723 + mtd = nand_to_mtd(chip); 1707 1724 info->host[cs] = host; 1708 - host->mtd = mtd; 1709 1725 host->cs = cs; 1710 1726 host->info_data = info; 1711 - mtd->priv = host; 1712 1727 mtd->dev.parent = &pdev->dev; 1728 + /* FIXME: all chips use the same device tree partitions */ 1729 + nand_set_flash_node(chip, np); 1713 1730 1731 + nand_set_controller_data(chip, host); 1714 1732 chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; 1715 1733 chip->ecc.write_page = pxa3xx_nand_write_page_hwecc; 1716 1734 chip->controller = &info->controller; ··· 1833 1845 clk_disable_unprepare(info->clk); 1834 1846 1835 1847 for (cs = 0; cs < pdata->num_cs; cs++) 1836 - nand_release(info->host[cs]->mtd); 1848 + nand_release(nand_to_mtd(&info->host[cs]->chip)); 1837 1849 return 0; 1838 1850 } 1839 1851 ··· 1874 1886 static int pxa3xx_nand_probe(struct platform_device *pdev) 1875 1887 { 1876 1888 struct pxa3xx_nand_platform_data *pdata; 1877 - struct mtd_part_parser_data ppdata = {}; 1878 1889 struct pxa3xx_nand_info *info; 1879 1890 int ret, cs, probe_success, dma_available; 1880 1891 ··· 1904 1917 info = platform_get_drvdata(pdev); 1905 1918 probe_success = 0; 1906 1919 for (cs = 0; cs < pdata->num_cs; cs++) { 1907 - struct mtd_info *mtd = info->host[cs]->mtd; 1920 + struct mtd_info *mtd = nand_to_mtd(&info->host[cs]->chip); 1908 1921 1909 1922 /* 1910 1923 * The mtd name matches the one used in 'mtdparts' kernel ··· 1920 1933 continue; 1921 1934 } 1922 1935 1923 - ppdata.of_node = pdev->dev.of_node; 1924 - ret = mtd_device_parse_register(mtd, NULL, 1925 - &ppdata, pdata->parts[cs], 1926 - pdata->nr_parts[cs]); 1936 + ret = mtd_device_register(mtd, pdata->parts[cs], 1937 + pdata->nr_parts[cs]); 1927 1938 if (!ret) 1928 1939 probe_success = 1; 1929 1940 } ··· 1944 1959 return -EAGAIN; 1945 1960 } 1946 1961 1962 + clk_disable(info->clk); 1947 1963 return 0; 1948 1964 } 1949 1965 1950 1966 static int pxa3xx_nand_resume(struct device *dev) 1951 1967 { 1952 1968 struct pxa3xx_nand_info *info = dev_get_drvdata(dev); 1969 + int ret; 1970 + 1971 + ret = clk_enable(info->clk); 1972 + if (ret < 0) 1973 + return ret; 1953 1974 1954 1975 /* We don't want to handle interrupt without calling mtd routine */ 1955 1976 disable_int(info, NDCR_INT_MASK);
+20 -26
drivers/mtd/nand/r852.c
··· 64 64 /* returns pointer to our private structure */ 65 65 static inline struct r852_device *r852_get_dev(struct mtd_info *mtd) 66 66 { 67 - struct nand_chip *chip = mtd->priv; 68 - return chip->priv; 67 + struct nand_chip *chip = mtd_to_nand(mtd); 68 + return nand_get_controller_data(chip); 69 69 } 70 70 71 71 ··· 361 361 */ 362 362 static int r852_wait(struct mtd_info *mtd, struct nand_chip *chip) 363 363 { 364 - struct r852_device *dev = chip->priv; 364 + struct r852_device *dev = nand_get_controller_data(chip); 365 365 366 366 unsigned long timeout; 367 367 int status; ··· 477 477 478 478 if (dev->dma_error) { 479 479 dev->dma_error = 0; 480 - return -1; 480 + return -EIO; 481 481 } 482 482 483 483 r852_write_reg(dev, R852_CTL, dev->ctlreg | R852_CTL_ECC_ACCESS); ··· 491 491 /* ecc uncorrectable error */ 492 492 if (ecc_status & R852_ECC_FAIL) { 493 493 dbg("ecc: unrecoverable error, in half %d", i); 494 - error = -1; 494 + error = -EBADMSG; 495 495 goto exit; 496 496 } 497 497 ··· 634 634 */ 635 635 static int r852_register_nand_device(struct r852_device *dev) 636 636 { 637 - dev->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL); 638 - 639 - if (!dev->mtd) 640 - goto error1; 637 + struct mtd_info *mtd = nand_to_mtd(dev->chip); 641 638 642 639 WARN_ON(dev->card_registred); 643 640 644 - dev->mtd->priv = dev->chip; 645 - dev->mtd->dev.parent = &dev->pci_dev->dev; 641 + mtd->dev.parent = &dev->pci_dev->dev; 646 642 647 643 if (dev->readonly) 648 644 dev->chip->options |= NAND_ROM; 649 645 650 646 r852_engine_enable(dev); 651 647 652 - if (sm_register_device(dev->mtd, dev->sm)) 653 - goto error2; 648 + if (sm_register_device(mtd, dev->sm)) 649 + goto error1; 654 650 655 - if (device_create_file(&dev->mtd->dev, &dev_attr_media_type)) { 651 + if (device_create_file(&mtd->dev, &dev_attr_media_type)) { 656 652 message("can't create media type sysfs attribute"); 657 653 goto error3; 658 654 } ··· 656 660 dev->card_registred = 1; 657 661 return 0; 658 662 error3: 659 - nand_release(dev->mtd); 660 - error2: 661 - kfree(dev->mtd); 663 + nand_release(mtd); 662 664 error1: 663 665 /* Force card redetect */ 664 666 dev->card_detected = 0; ··· 669 675 670 676 static void r852_unregister_nand_device(struct r852_device *dev) 671 677 { 678 + struct mtd_info *mtd = nand_to_mtd(dev->chip); 679 + 672 680 if (!dev->card_registred) 673 681 return; 674 682 675 - device_remove_file(&dev->mtd->dev, &dev_attr_media_type); 676 - nand_release(dev->mtd); 683 + device_remove_file(&mtd->dev, &dev_attr_media_type); 684 + nand_release(mtd); 677 685 r852_engine_disable(dev); 678 686 dev->card_registred = 0; 679 - kfree(dev->mtd); 680 - dev->mtd = NULL; 681 687 } 682 688 683 689 /* Card state updater */ ··· 879 885 if (!dev) 880 886 goto error5; 881 887 882 - chip->priv = dev; 888 + nand_set_controller_data(chip, dev); 883 889 dev->chip = chip; 884 890 dev->pci_dev = pci_dev; 885 891 pci_set_drvdata(pci_dev, dev); ··· 974 980 975 981 /* Stop interrupts */ 976 982 r852_disable_irqs(dev); 977 - synchronize_irq(dev->irq); 978 983 free_irq(dev->irq, dev); 979 984 980 985 /* Cleanup */ ··· 1025 1032 static int r852_resume(struct device *device) 1026 1033 { 1027 1034 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device)); 1035 + struct mtd_info *mtd = nand_to_mtd(dev->chip); 1028 1036 1029 1037 r852_disable_irqs(dev); 1030 1038 r852_card_update_present(dev); ··· 1045 1051 /* Otherwise, initialize the card */ 1046 1052 if (dev->card_registred) { 1047 1053 r852_engine_enable(dev); 1048 - dev->chip->select_chip(dev->mtd, 0); 1049 - dev->chip->cmdfunc(dev->mtd, NAND_CMD_RESET, -1, -1); 1050 - dev->chip->select_chip(dev->mtd, -1); 1054 + dev->chip->select_chip(mtd, 0); 1055 + dev->chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 1056 + dev->chip->select_chip(mtd, -1); 1051 1057 } 1052 1058 1053 1059 /* Program card detection IRQ */
-1
drivers/mtd/nand/r852.h
··· 108 108 109 109 struct r852_device { 110 110 void __iomem *mmio; /* mmio */ 111 - struct mtd_info *mtd; /* mtd backpointer */ 112 111 struct nand_chip *chip; /* nand chip backpointer */ 113 112 struct pci_dev *pci_dev; /* pci backpointer */ 114 113
+17 -14
drivers/mtd/nand/s3c2410.c
··· 104 104 * @scan_res: The result from calling nand_scan_ident(). 105 105 */ 106 106 struct s3c2410_nand_mtd { 107 - struct mtd_info mtd; 108 107 struct nand_chip chip; 109 108 struct s3c2410_nand_set *set; 110 109 struct s3c2410_nand_info *info; ··· 167 168 168 169 static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd) 169 170 { 170 - return container_of(mtd, struct s3c2410_nand_mtd, mtd); 171 + return container_of(mtd_to_nand(mtd), struct s3c2410_nand_mtd, 172 + chip); 171 173 } 172 174 173 175 static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd) ··· 382 382 { 383 383 struct s3c2410_nand_info *info; 384 384 struct s3c2410_nand_mtd *nmtd; 385 - struct nand_chip *this = mtd->priv; 385 + struct nand_chip *this = mtd_to_nand(mtd); 386 386 unsigned long cur; 387 387 388 - nmtd = this->priv; 388 + nmtd = nand_get_controller_data(this); 389 389 info = nmtd->info; 390 390 391 391 if (chip != -1) ··· 634 634 635 635 static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 636 636 { 637 - struct nand_chip *this = mtd->priv; 637 + struct nand_chip *this = mtd_to_nand(mtd); 638 638 readsb(this->IO_ADDR_R, buf, len); 639 639 } 640 640 ··· 656 656 static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, 657 657 int len) 658 658 { 659 - struct nand_chip *this = mtd->priv; 659 + struct nand_chip *this = mtd_to_nand(mtd); 660 660 writesb(this->IO_ADDR_W, buf, len); 661 661 } 662 662 ··· 745 745 746 746 for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) { 747 747 pr_debug("releasing mtd %d (%p)\n", mtdno, ptr); 748 - nand_release(&ptr->mtd); 748 + nand_release(nand_to_mtd(&ptr->chip)); 749 749 } 750 750 } 751 751 ··· 762 762 struct s3c2410_nand_set *set) 763 763 { 764 764 if (set) { 765 - mtd->mtd.name = set->name; 765 + struct mtd_info *mtdinfo = nand_to_mtd(&mtd->chip); 766 766 767 - return mtd_device_parse_register(&mtd->mtd, NULL, NULL, 767 + mtdinfo->name = set->name; 768 + 769 + return mtd_device_parse_register(mtdinfo, NULL, NULL, 768 770 set->partitions, set->nr_partitions); 769 771 } 770 772 ··· 794 792 chip->read_buf = s3c2410_nand_read_buf; 795 793 chip->select_chip = s3c2410_nand_select_chip; 796 794 chip->chip_delay = 50; 797 - chip->priv = nmtd; 795 + nand_set_controller_data(chip, nmtd); 798 796 chip->options = set->options; 799 797 chip->controller = &info->controller; 800 798 ··· 833 831 chip->IO_ADDR_R = chip->IO_ADDR_W; 834 832 835 833 nmtd->info = info; 836 - nmtd->mtd.priv = chip; 837 834 nmtd->set = set; 838 835 839 836 #ifdef CONFIG_MTD_NAND_S3C2410_HWECC ··· 1013 1012 nmtd = info->mtds; 1014 1013 1015 1014 for (setno = 0; setno < nr_sets; setno++, nmtd++) { 1015 + struct mtd_info *mtd = nand_to_mtd(&nmtd->chip); 1016 + 1016 1017 pr_debug("initialising set %d (%p, info %p)\n", 1017 1018 setno, nmtd, info); 1018 1019 1019 - nmtd->mtd.dev.parent = &pdev->dev; 1020 + mtd->dev.parent = &pdev->dev; 1020 1021 s3c2410_nand_init_chip(info, nmtd, sets); 1021 1022 1022 - nmtd->scan_res = nand_scan_ident(&nmtd->mtd, 1023 + nmtd->scan_res = nand_scan_ident(mtd, 1023 1024 (sets) ? sets->nr_chips : 1, 1024 1025 NULL); 1025 1026 1026 1027 if (nmtd->scan_res == 0) { 1027 1028 s3c2410_nand_update_chip(info, nmtd); 1028 - nand_scan_tail(&nmtd->mtd); 1029 + nand_scan_tail(mtd); 1029 1030 s3c2410_nand_add_partition(info, nmtd, sets); 1030 1031 } 1031 1032
+9 -11
drivers/mtd/nand/sh_flctl.c
··· 160 160 161 161 memset(&cfg, 0, sizeof(cfg)); 162 162 cfg.direction = DMA_MEM_TO_DEV; 163 - cfg.dst_addr = (dma_addr_t)FLDTFIFO(flctl); 163 + cfg.dst_addr = flctl->fifo; 164 164 cfg.src_addr = 0; 165 165 ret = dmaengine_slave_config(flctl->chan_fifo0_tx, &cfg); 166 166 if (ret < 0) ··· 176 176 177 177 cfg.direction = DMA_DEV_TO_MEM; 178 178 cfg.dst_addr = 0; 179 - cfg.src_addr = (dma_addr_t)FLDTFIFO(flctl); 179 + cfg.src_addr = flctl->fifo; 180 180 ret = dmaengine_slave_config(flctl->chan_fifo0_rx, &cfg); 181 181 if (ret < 0) 182 182 goto err; ··· 607 607 case FL_REPAIRABLE: 608 608 dev_info(&flctl->pdev->dev, 609 609 "applied ecc on page 0x%x", page_addr); 610 - flctl->mtd.ecc_stats.corrected++; 610 + mtd->ecc_stats.corrected++; 611 611 break; 612 612 case FL_ERROR: 613 613 dev_warn(&flctl->pdev->dev, 614 614 "page 0x%x contains corrupted data\n", 615 615 page_addr); 616 - flctl->mtd.ecc_stats.failed++; 616 + mtd->ecc_stats.failed++; 617 617 break; 618 618 default: 619 619 ; ··· 1086 1086 struct sh_flctl_platform_data *pdata; 1087 1087 int ret; 1088 1088 int irq; 1089 - struct mtd_part_parser_data ppdata = {}; 1090 1089 1091 1090 flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL); 1092 1091 if (!flctl) ··· 1095 1096 flctl->reg = devm_ioremap_resource(&pdev->dev, res); 1096 1097 if (IS_ERR(flctl->reg)) 1097 1098 return PTR_ERR(flctl->reg); 1099 + flctl->fifo = res->start + 0x24; /* FLDTFIFO */ 1098 1100 1099 1101 irq = platform_get_irq(pdev, 0); 1100 1102 if (irq < 0) { ··· 1121 1121 } 1122 1122 1123 1123 platform_set_drvdata(pdev, flctl); 1124 - flctl_mtd = &flctl->mtd; 1125 1124 nand = &flctl->chip; 1126 - flctl_mtd->priv = nand; 1125 + flctl_mtd = nand_to_mtd(nand); 1126 + nand_set_flash_node(nand, pdev->dev.of_node); 1127 1127 flctl_mtd->dev.parent = &pdev->dev; 1128 1128 flctl->pdev = pdev; 1129 1129 flctl->hwecc = pdata->has_hwecc; ··· 1163 1163 if (ret) 1164 1164 goto err_chip; 1165 1165 1166 - ppdata.of_node = pdev->dev.of_node; 1167 - ret = mtd_device_parse_register(flctl_mtd, NULL, &ppdata, pdata->parts, 1168 - pdata->nr_parts); 1166 + ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts); 1169 1167 1170 1168 return 0; 1171 1169 ··· 1178 1180 struct sh_flctl *flctl = platform_get_drvdata(pdev); 1179 1181 1180 1182 flctl_release_dma(flctl); 1181 - nand_release(&flctl->mtd); 1183 + nand_release(nand_to_mtd(&flctl->chip)); 1182 1184 pm_runtime_disable(&pdev->dev); 1183 1185 1184 1186 return 0;
+13 -10
drivers/mtd/nand/sharpsl.c
··· 29 29 #include <asm/mach-types.h> 30 30 31 31 struct sharpsl_nand { 32 - struct mtd_info mtd; 33 32 struct nand_chip chip; 34 33 35 34 void __iomem *io; 36 35 }; 37 36 38 - #define mtd_to_sharpsl(_mtd) container_of(_mtd, struct sharpsl_nand, mtd) 37 + static inline struct sharpsl_nand *mtd_to_sharpsl(struct mtd_info *mtd) 38 + { 39 + return container_of(mtd_to_nand(mtd), struct sharpsl_nand, chip); 40 + } 39 41 40 42 /* register offset */ 41 43 #define ECCLPLB 0x00 /* line parity 7 - 0 bit */ ··· 68 66 unsigned int ctrl) 69 67 { 70 68 struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); 71 - struct nand_chip *chip = mtd->priv; 69 + struct nand_chip *chip = mtd_to_nand(mtd); 72 70 73 71 if (ctrl & NAND_CTRL_CHANGE) { 74 72 unsigned char bits = ctrl & 0x07; ··· 111 109 static int sharpsl_nand_probe(struct platform_device *pdev) 112 110 { 113 111 struct nand_chip *this; 112 + struct mtd_info *mtd; 114 113 struct resource *r; 115 114 int err = 0; 116 115 struct sharpsl_nand *sharpsl; ··· 146 143 this = (struct nand_chip *)(&sharpsl->chip); 147 144 148 145 /* Link the private data with the MTD structure */ 149 - sharpsl->mtd.priv = this; 150 - sharpsl->mtd.dev.parent = &pdev->dev; 146 + mtd = nand_to_mtd(this); 147 + mtd->dev.parent = &pdev->dev; 151 148 152 149 platform_set_drvdata(pdev, sharpsl); 153 150 ··· 176 173 this->ecc.correct = nand_correct_data; 177 174 178 175 /* Scan to find existence of the device */ 179 - err = nand_scan(&sharpsl->mtd, 1); 176 + err = nand_scan(mtd, 1); 180 177 if (err) 181 178 goto err_scan; 182 179 183 180 /* Register the partitions */ 184 - sharpsl->mtd.name = "sharpsl-nand"; 181 + mtd->name = "sharpsl-nand"; 185 182 186 - err = mtd_device_parse_register(&sharpsl->mtd, NULL, NULL, 183 + err = mtd_device_parse_register(mtd, NULL, NULL, 187 184 data->partitions, data->nr_partitions); 188 185 if (err) 189 186 goto err_add; ··· 192 189 return 0; 193 190 194 191 err_add: 195 - nand_release(&sharpsl->mtd); 192 + nand_release(mtd); 196 193 197 194 err_scan: 198 195 iounmap(sharpsl->io); ··· 210 207 struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev); 211 208 212 209 /* Release resources, unregister device */ 213 - nand_release(&sharpsl->mtd); 210 + nand_release(nand_to_mtd(&sharpsl->chip)); 214 211 215 212 iounmap(sharpsl->io); 216 213
+1 -1
drivers/mtd/nand/sm_common.c
··· 102 102 103 103 int sm_register_device(struct mtd_info *mtd, int smartmedia) 104 104 { 105 - struct nand_chip *chip = mtd->priv; 105 + struct nand_chip *chip = mtd_to_nand(mtd); 106 106 int ret; 107 107 108 108 chip->options |= NAND_SKIP_BBTSCAN;
+14 -16
drivers/mtd/nand/socrates_nand.c
··· 30 30 31 31 struct socrates_nand_host { 32 32 struct nand_chip nand_chip; 33 - struct mtd_info mtd; 34 33 void __iomem *io_base; 35 34 struct device *dev; 36 35 }; ··· 44 45 const uint8_t *buf, int len) 45 46 { 46 47 int i; 47 - struct nand_chip *this = mtd->priv; 48 - struct socrates_nand_host *host = this->priv; 48 + struct nand_chip *this = mtd_to_nand(mtd); 49 + struct socrates_nand_host *host = nand_get_controller_data(this); 49 50 50 51 for (i = 0; i < len; i++) { 51 52 out_be32(host->io_base, FPGA_NAND_ENABLE | ··· 63 64 static void socrates_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 64 65 { 65 66 int i; 66 - struct nand_chip *this = mtd->priv; 67 - struct socrates_nand_host *host = this->priv; 67 + struct nand_chip *this = mtd_to_nand(mtd); 68 + struct socrates_nand_host *host = nand_get_controller_data(this); 68 69 uint32_t val; 69 70 70 71 val = FPGA_NAND_ENABLE | FPGA_NAND_CMD_READ; ··· 104 105 static void socrates_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, 105 106 unsigned int ctrl) 106 107 { 107 - struct nand_chip *nand_chip = mtd->priv; 108 - struct socrates_nand_host *host = nand_chip->priv; 108 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 109 + struct socrates_nand_host *host = nand_get_controller_data(nand_chip); 109 110 uint32_t val; 110 111 111 112 if (cmd == NAND_CMD_NONE) ··· 129 130 */ 130 131 static int socrates_nand_device_ready(struct mtd_info *mtd) 131 132 { 132 - struct nand_chip *nand_chip = mtd->priv; 133 - struct socrates_nand_host *host = nand_chip->priv; 133 + struct nand_chip *nand_chip = mtd_to_nand(mtd); 134 + struct socrates_nand_host *host = nand_get_controller_data(nand_chip); 134 135 135 136 if (in_be32(host->io_base) & FPGA_NAND_BUSY) 136 137 return 0; /* busy */ ··· 146 147 struct mtd_info *mtd; 147 148 struct nand_chip *nand_chip; 148 149 int res; 149 - struct mtd_part_parser_data ppdata; 150 150 151 151 /* Allocate memory for the device structure (and zero it) */ 152 152 host = devm_kzalloc(&ofdev->dev, sizeof(*host), GFP_KERNEL); ··· 158 160 return -EIO; 159 161 } 160 162 161 - mtd = &host->mtd; 162 163 nand_chip = &host->nand_chip; 164 + mtd = nand_to_mtd(nand_chip); 163 165 host->dev = &ofdev->dev; 164 166 165 - nand_chip->priv = host; /* link the private data structures */ 166 - mtd->priv = nand_chip; 167 + /* link the private data structures */ 168 + nand_set_controller_data(nand_chip, host); 169 + nand_set_flash_node(nand_chip, ofdev->dev.of_node); 167 170 mtd->name = "socrates_nand"; 168 171 mtd->dev.parent = &ofdev->dev; 169 - ppdata.of_node = ofdev->dev.of_node; 170 172 171 173 /*should never be accessed directly */ 172 174 nand_chip->IO_ADDR_R = (void *)0xdeadbeef; ··· 198 200 goto out; 199 201 } 200 202 201 - res = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 203 + res = mtd_device_register(mtd, NULL, 0); 202 204 if (!res) 203 205 return res; 204 206 ··· 215 217 static int socrates_nand_remove(struct platform_device *ofdev) 216 218 { 217 219 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev); 218 - struct mtd_info *mtd = &host->mtd; 220 + struct mtd_info *mtd = nand_to_mtd(&host->nand_chip); 219 221 220 222 nand_release(mtd); 221 223
+24 -26
drivers/mtd/nand/sunxi_nand.c
··· 234 234 struct sunxi_nand_chip { 235 235 struct list_head node; 236 236 struct nand_chip nand; 237 - struct mtd_info mtd; 238 237 unsigned long clk_rate; 239 238 u32 timing_cfg; 240 239 u32 timing_ctl; ··· 349 350 350 351 static int sunxi_nfc_dev_ready(struct mtd_info *mtd) 351 352 { 352 - struct nand_chip *nand = mtd->priv; 353 + struct nand_chip *nand = mtd_to_nand(mtd); 353 354 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 354 355 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 355 356 struct sunxi_nand_rb *rb; ··· 387 388 388 389 static void sunxi_nfc_select_chip(struct mtd_info *mtd, int chip) 389 390 { 390 - struct nand_chip *nand = mtd->priv; 391 + struct nand_chip *nand = mtd_to_nand(mtd); 391 392 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 392 393 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 393 394 struct sunxi_nand_chip_sel *sel; ··· 432 433 433 434 static void sunxi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 434 435 { 435 - struct nand_chip *nand = mtd->priv; 436 + struct nand_chip *nand = mtd_to_nand(mtd); 436 437 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 437 438 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 438 439 int ret; ··· 465 466 static void sunxi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, 466 467 int len) 467 468 { 468 - struct nand_chip *nand = mtd->priv; 469 + struct nand_chip *nand = mtd_to_nand(mtd); 469 470 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 470 471 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 471 472 int ret; ··· 506 507 static void sunxi_nfc_cmd_ctrl(struct mtd_info *mtd, int dat, 507 508 unsigned int ctrl) 508 509 { 509 - struct nand_chip *nand = mtd->priv; 510 + struct nand_chip *nand = mtd_to_nand(mtd); 510 511 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 511 512 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 512 513 int ret; ··· 540 541 541 542 static void sunxi_nfc_hw_ecc_enable(struct mtd_info *mtd) 542 543 { 543 - struct nand_chip *nand = mtd->priv; 544 + struct nand_chip *nand = mtd_to_nand(mtd); 544 545 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 545 546 struct sunxi_nand_hw_ecc *data = nand->ecc.priv; 546 547 u32 ecc_ctl; ··· 555 556 556 557 static void sunxi_nfc_hw_ecc_disable(struct mtd_info *mtd) 557 558 { 558 - struct nand_chip *nand = mtd->priv; 559 + struct nand_chip *nand = mtd_to_nand(mtd); 559 560 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 560 561 561 562 writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN, ··· 576 577 int *cur_off, 577 578 unsigned int *max_bitflips) 578 579 { 579 - struct nand_chip *nand = mtd->priv; 580 + struct nand_chip *nand = mtd_to_nand(mtd); 580 581 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 581 582 struct nand_ecc_ctrl *ecc = &nand->ecc; 582 583 u32 status; ··· 637 638 static void sunxi_nfc_hw_ecc_read_extra_oob(struct mtd_info *mtd, 638 639 u8 *oob, int *cur_off) 639 640 { 640 - struct nand_chip *nand = mtd->priv; 641 + struct nand_chip *nand = mtd_to_nand(mtd); 641 642 struct nand_ecc_ctrl *ecc = &nand->ecc; 642 643 int offset = ((ecc->bytes + 4) * ecc->steps); 643 644 int len = mtd->oobsize - offset; ··· 664 665 const u8 *oob, int oob_off, 665 666 int *cur_off) 666 667 { 667 - struct nand_chip *nand = mtd->priv; 668 + struct nand_chip *nand = mtd_to_nand(mtd); 668 669 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 669 670 struct nand_ecc_ctrl *ecc = &nand->ecc; 670 671 int ret; ··· 701 702 static void sunxi_nfc_hw_ecc_write_extra_oob(struct mtd_info *mtd, 702 703 u8 *oob, int *cur_off) 703 704 { 704 - struct nand_chip *nand = mtd->priv; 705 + struct nand_chip *nand = mtd_to_nand(mtd); 705 706 struct nand_ecc_ctrl *ecc = &nand->ecc; 706 707 int offset = ((ecc->bytes + 4) * ecc->steps); 707 708 int len = mtd->oobsize - offset; ··· 990 991 static int sunxi_nand_chip_init_timings(struct sunxi_nand_chip *chip, 991 992 struct device_node *np) 992 993 { 994 + struct mtd_info *mtd = nand_to_mtd(&chip->nand); 993 995 const struct nand_sdr_timings *timings; 994 996 int ret; 995 997 int mode; ··· 1008 1008 1009 1009 feature[0] = mode; 1010 1010 for (i = 0; i < chip->nsels; i++) { 1011 - chip->nand.select_chip(&chip->mtd, i); 1012 - ret = chip->nand.onfi_set_features(&chip->mtd, 1013 - &chip->nand, 1011 + chip->nand.select_chip(mtd, i); 1012 + ret = chip->nand.onfi_set_features(mtd, &chip->nand, 1014 1013 ONFI_FEATURE_ADDR_TIMING_MODE, 1015 1014 feature); 1016 - chip->nand.select_chip(&chip->mtd, -1); 1015 + chip->nand.select_chip(mtd, -1); 1017 1016 if (ret) 1018 1017 return ret; 1019 1018 } ··· 1030 1031 struct device_node *np) 1031 1032 { 1032 1033 static const u8 strengths[] = { 16, 24, 28, 32, 40, 48, 56, 60, 64 }; 1033 - struct nand_chip *nand = mtd->priv; 1034 + struct nand_chip *nand = mtd_to_nand(mtd); 1034 1035 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 1035 1036 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); 1036 1037 struct sunxi_nand_hw_ecc *data; ··· 1188 1189 static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, 1189 1190 struct device_node *np) 1190 1191 { 1191 - struct nand_chip *nand = mtd->priv; 1192 + struct nand_chip *nand = mtd_to_nand(mtd); 1192 1193 int ret; 1193 1194 1194 1195 if (!ecc->size) { ··· 1231 1232 { 1232 1233 const struct nand_sdr_timings *timings; 1233 1234 struct sunxi_nand_chip *chip; 1234 - struct mtd_part_parser_data ppdata; 1235 1235 struct mtd_info *mtd; 1236 1236 struct nand_chip *nand; 1237 1237 int nsels; ··· 1328 1330 * in the DT. 1329 1331 */ 1330 1332 nand->ecc.mode = NAND_ECC_HW; 1331 - nand->flash_node = np; 1333 + nand_set_flash_node(nand, np); 1332 1334 nand->select_chip = sunxi_nfc_select_chip; 1333 1335 nand->cmd_ctrl = sunxi_nfc_cmd_ctrl; 1334 1336 nand->read_buf = sunxi_nfc_read_buf; 1335 1337 nand->write_buf = sunxi_nfc_write_buf; 1336 1338 nand->read_byte = sunxi_nfc_read_byte; 1337 1339 1338 - mtd = &chip->mtd; 1340 + mtd = nand_to_mtd(nand); 1339 1341 mtd->dev.parent = dev; 1340 - mtd->priv = nand; 1341 1342 1342 1343 ret = nand_scan_ident(mtd, nsels, NULL); 1343 1344 if (ret) ··· 1363 1366 return ret; 1364 1367 } 1365 1368 1366 - ppdata.of_node = np; 1367 - ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 1369 + ret = mtd_device_register(mtd, NULL, 0); 1368 1370 if (ret) { 1369 1371 dev_err(dev, "failed to register mtd device: %d\n", ret); 1370 1372 nand_release(mtd); ··· 1389 1393 1390 1394 for_each_child_of_node(np, nand_np) { 1391 1395 ret = sunxi_nand_chip_init(dev, nfc, nand_np); 1392 - if (ret) 1396 + if (ret) { 1397 + of_node_put(nand_np); 1393 1398 return ret; 1399 + } 1394 1400 } 1395 1401 1396 1402 return 0; ··· 1405 1407 while (!list_empty(&nfc->chips)) { 1406 1408 chip = list_first_entry(&nfc->chips, struct sunxi_nand_chip, 1407 1409 node); 1408 - nand_release(&chip->mtd); 1410 + nand_release(nand_to_mtd(&chip->nand)); 1409 1411 sunxi_nand_ecc_cleanup(&chip->nand.ecc); 1410 1412 list_del(&chip->node); 1411 1413 }
+7 -6
drivers/mtd/nand/tmio_nand.c
··· 103 103 /*--------------------------------------------------------------------------*/ 104 104 105 105 struct tmio_nand { 106 - struct mtd_info mtd; 107 106 struct nand_chip chip; 108 107 109 108 struct platform_device *dev; ··· 118 119 unsigned read_good:1; 119 120 }; 120 121 121 - #define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd) 122 + static inline struct tmio_nand *mtd_to_tmio(struct mtd_info *mtd) 123 + { 124 + return container_of(mtd_to_nand(mtd), struct tmio_nand, chip); 125 + } 122 126 123 127 124 128 /*--------------------------------------------------------------------------*/ ··· 130 128 unsigned int ctrl) 131 129 { 132 130 struct tmio_nand *tmio = mtd_to_tmio(mtd); 133 - struct nand_chip *chip = mtd->priv; 131 + struct nand_chip *chip = mtd_to_nand(mtd); 134 132 135 133 if (ctrl & NAND_CTRL_CHANGE) { 136 134 u8 mode; ··· 380 378 tmio->dev = dev; 381 379 382 380 platform_set_drvdata(dev, tmio); 383 - mtd = &tmio->mtd; 384 381 nand_chip = &tmio->chip; 385 - mtd->priv = nand_chip; 382 + mtd = nand_to_mtd(nand_chip); 386 383 mtd->name = "tmio-nand"; 387 384 mtd->dev.parent = &dev->dev; 388 385 ··· 457 456 { 458 457 struct tmio_nand *tmio = platform_get_drvdata(dev); 459 458 460 - nand_release(&tmio->mtd); 459 + nand_release(nand_to_mtd(&tmio->chip)); 461 460 tmio_hw_stop(dev, tmio); 462 461 return 0; 463 462 }
+11 -14
drivers/mtd/nand/txx9ndfmc.c
··· 63 63 struct txx9ndfmc_priv { 64 64 struct platform_device *dev; 65 65 struct nand_chip chip; 66 - struct mtd_info mtd; 67 66 int cs; 68 67 const char *mtdname; 69 68 }; ··· 78 79 79 80 static struct platform_device *mtd_to_platdev(struct mtd_info *mtd) 80 81 { 81 - struct nand_chip *chip = mtd->priv; 82 - struct txx9ndfmc_priv *txx9_priv = chip->priv; 82 + struct nand_chip *chip = mtd_to_nand(mtd); 83 + struct txx9ndfmc_priv *txx9_priv = nand_get_controller_data(chip); 83 84 return txx9_priv->dev; 84 85 } 85 86 ··· 134 135 static void txx9ndfmc_cmd_ctrl(struct mtd_info *mtd, int cmd, 135 136 unsigned int ctrl) 136 137 { 137 - struct nand_chip *chip = mtd->priv; 138 - struct txx9ndfmc_priv *txx9_priv = chip->priv; 138 + struct nand_chip *chip = mtd_to_nand(mtd); 139 + struct txx9ndfmc_priv *txx9_priv = nand_get_controller_data(chip); 139 140 struct platform_device *dev = txx9_priv->dev; 140 141 struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev); 141 142 ··· 174 175 uint8_t *ecc_code) 175 176 { 176 177 struct platform_device *dev = mtd_to_platdev(mtd); 177 - struct nand_chip *chip = mtd->priv; 178 + struct nand_chip *chip = mtd_to_nand(mtd); 178 179 int eccbytes; 179 180 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR); 180 181 ··· 194 195 static int txx9ndfmc_correct_data(struct mtd_info *mtd, unsigned char *buf, 195 196 unsigned char *read_ecc, unsigned char *calc_ecc) 196 197 { 197 - struct nand_chip *chip = mtd->priv; 198 + struct nand_chip *chip = mtd_to_nand(mtd); 198 199 int eccsize; 199 200 int corrected = 0; 200 201 int stat; ··· 256 257 257 258 static int txx9ndfmc_nand_scan(struct mtd_info *mtd) 258 259 { 259 - struct nand_chip *chip = mtd->priv; 260 + struct nand_chip *chip = mtd_to_nand(mtd); 260 261 int ret; 261 262 262 263 ret = nand_scan_ident(mtd, 1, NULL); ··· 321 322 if (!txx9_priv) 322 323 continue; 323 324 chip = &txx9_priv->chip; 324 - mtd = &txx9_priv->mtd; 325 + mtd = nand_to_mtd(chip); 325 326 mtd->dev.parent = &dev->dev; 326 - 327 - mtd->priv = chip; 328 327 329 328 chip->read_byte = txx9ndfmc_read_byte; 330 329 chip->read_buf = txx9ndfmc_read_buf; ··· 340 343 chip->chip_delay = 100; 341 344 chip->controller = &drvdata->hw_control; 342 345 343 - chip->priv = txx9_priv; 346 + nand_set_controller_data(chip, txx9_priv); 344 347 txx9_priv->dev = dev; 345 348 346 349 if (plat->ch_mask != 1) { ··· 388 391 389 392 if (!mtd) 390 393 continue; 391 - chip = mtd->priv; 392 - txx9_priv = chip->priv; 394 + chip = mtd_to_nand(mtd); 395 + txx9_priv = nand_get_controller_data(chip); 393 396 394 397 nand_release(mtd); 395 398 kfree(txx9_priv->mtdname);
+10 -13
drivers/mtd/nand/vf610_nfc.c
··· 156 156 }; 157 157 158 158 struct vf610_nfc { 159 - struct mtd_info mtd; 160 159 struct nand_chip chip; 161 160 struct device *dev; 162 161 void __iomem *regs; ··· 170 171 u32 ecc_mode; 171 172 }; 172 173 173 - #define mtd_to_nfc(_mtd) container_of(_mtd, struct vf610_nfc, mtd) 174 + static inline struct vf610_nfc *mtd_to_nfc(struct mtd_info *mtd) 175 + { 176 + return container_of(mtd_to_nand(mtd), struct vf610_nfc, chip); 177 + } 174 178 175 179 static struct nand_ecclayout vf610_nfc_ecc45 = { 176 180 .eccbytes = 45, ··· 676 674 return -ENOMEM; 677 675 678 676 nfc->dev = &pdev->dev; 679 - mtd = &nfc->mtd; 680 677 chip = &nfc->chip; 678 + mtd = nand_to_mtd(chip); 681 679 682 - mtd->priv = chip; 683 680 mtd->owner = THIS_MODULE; 684 681 mtd->dev.parent = nfc->dev; 685 682 mtd->name = DRV_NAME; ··· 708 707 for_each_available_child_of_node(nfc->dev->of_node, child) { 709 708 if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) { 710 709 711 - if (chip->flash_node) { 710 + if (nand_get_flash_node(chip)) { 712 711 dev_err(nfc->dev, 713 712 "Only one NAND chip supported!\n"); 714 713 err = -EINVAL; 715 714 goto error; 716 715 } 717 716 718 - chip->flash_node = child; 717 + nand_set_flash_node(chip, child); 719 718 } 720 719 } 721 720 722 - if (!chip->flash_node) { 721 + if (!nand_get_flash_node(chip)) { 723 722 dev_err(nfc->dev, "NAND chip sub-node missing!\n"); 724 723 err = -ENODEV; 725 724 goto err_clk; ··· 812 811 platform_set_drvdata(pdev, mtd); 813 812 814 813 /* Register device in MTD */ 815 - return mtd_device_parse_register(mtd, NULL, 816 - &(struct mtd_part_parser_data){ 817 - .of_node = chip->flash_node, 818 - }, 819 - NULL, 0); 814 + return mtd_device_register(mtd, NULL, 0); 820 815 821 816 error: 822 - of_node_put(chip->flash_node); 817 + of_node_put(nand_get_flash_node(chip)); 823 818 err_clk: 824 819 clk_disable_unprepare(nfc->clk); 825 820 return err;
+2 -2
drivers/mtd/nand/xway_nand.c
··· 89 89 90 90 static void xway_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 91 91 { 92 - struct nand_chip *this = mtd->priv; 92 + struct nand_chip *this = mtd_to_nand(mtd); 93 93 unsigned long nandaddr = (unsigned long) this->IO_ADDR_W; 94 94 unsigned long flags; 95 95 ··· 118 118 119 119 static unsigned char xway_read_byte(struct mtd_info *mtd) 120 120 { 121 - struct nand_chip *this = mtd->priv; 121 + struct nand_chip *this = mtd_to_nand(mtd); 122 122 unsigned long nandaddr = (unsigned long) this->IO_ADDR_R; 123 123 unsigned long flags; 124 124 int ret;
+25 -28
drivers/mtd/ofpart.c
··· 26 26 } 27 27 28 28 static int parse_ofpart_partitions(struct mtd_info *master, 29 - struct mtd_partition **pparts, 29 + const struct mtd_partition **pparts, 30 30 struct mtd_part_parser_data *data) 31 31 { 32 + struct mtd_partition *parts; 32 33 struct device_node *mtd_node; 33 34 struct device_node *ofpart_node; 34 35 const char *partname; ··· 38 37 bool dedicated = true; 39 38 40 39 41 - if (!data) 42 - return 0; 43 - 44 - mtd_node = data->of_node; 40 + /* Pull of_node from the master device node */ 41 + mtd_node = mtd_get_of_node(master); 45 42 if (!mtd_node) 46 43 return 0; 47 44 ··· 71 72 if (nr_parts == 0) 72 73 return 0; 73 74 74 - *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL); 75 - if (!*pparts) 75 + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); 76 + if (!parts) 76 77 return -ENOMEM; 77 78 78 79 i = 0; ··· 106 107 goto ofpart_fail; 107 108 } 108 109 109 - (*pparts)[i].offset = of_read_number(reg, a_cells); 110 - (*pparts)[i].size = of_read_number(reg + a_cells, s_cells); 110 + parts[i].offset = of_read_number(reg, a_cells); 111 + parts[i].size = of_read_number(reg + a_cells, s_cells); 111 112 112 113 partname = of_get_property(pp, "label", &len); 113 114 if (!partname) 114 115 partname = of_get_property(pp, "name", &len); 115 - (*pparts)[i].name = partname; 116 + parts[i].name = partname; 116 117 117 118 if (of_get_property(pp, "read-only", &len)) 118 - (*pparts)[i].mask_flags |= MTD_WRITEABLE; 119 + parts[i].mask_flags |= MTD_WRITEABLE; 119 120 120 121 if (of_get_property(pp, "lock", &len)) 121 - (*pparts)[i].mask_flags |= MTD_POWERUP_LOCK; 122 + parts[i].mask_flags |= MTD_POWERUP_LOCK; 122 123 123 124 i++; 124 125 } ··· 126 127 if (!nr_parts) 127 128 goto ofpart_none; 128 129 130 + *pparts = parts; 129 131 return nr_parts; 130 132 131 133 ofpart_fail: ··· 135 135 ret = -EINVAL; 136 136 ofpart_none: 137 137 of_node_put(pp); 138 - kfree(*pparts); 139 - *pparts = NULL; 138 + kfree(parts); 140 139 return ret; 141 140 } 142 141 143 142 static struct mtd_part_parser ofpart_parser = { 144 - .owner = THIS_MODULE, 145 143 .parse_fn = parse_ofpart_partitions, 146 144 .name = "ofpart", 147 145 }; 148 146 149 147 static int parse_ofoldpart_partitions(struct mtd_info *master, 150 - struct mtd_partition **pparts, 148 + const struct mtd_partition **pparts, 151 149 struct mtd_part_parser_data *data) 152 150 { 151 + struct mtd_partition *parts; 153 152 struct device_node *dp; 154 153 int i, plen, nr_parts; 155 154 const struct { ··· 156 157 } *part; 157 158 const char *names; 158 159 159 - if (!data) 160 - return 0; 161 - 162 - dp = data->of_node; 160 + /* Pull of_node from the master device node */ 161 + dp = mtd_get_of_node(master); 163 162 if (!dp) 164 163 return 0; 165 164 ··· 170 173 171 174 nr_parts = plen / sizeof(part[0]); 172 175 173 - *pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL); 174 - if (!*pparts) 176 + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); 177 + if (!parts) 175 178 return -ENOMEM; 176 179 177 180 names = of_get_property(dp, "partition-names", &plen); 178 181 179 182 for (i = 0; i < nr_parts; i++) { 180 - (*pparts)[i].offset = be32_to_cpu(part->offset); 181 - (*pparts)[i].size = be32_to_cpu(part->len) & ~1; 183 + parts[i].offset = be32_to_cpu(part->offset); 184 + parts[i].size = be32_to_cpu(part->len) & ~1; 182 185 /* bit 0 set signifies read only partition */ 183 186 if (be32_to_cpu(part->len) & 1) 184 - (*pparts)[i].mask_flags = MTD_WRITEABLE; 187 + parts[i].mask_flags = MTD_WRITEABLE; 185 188 186 189 if (names && (plen > 0)) { 187 190 int len = strlen(names) + 1; 188 191 189 - (*pparts)[i].name = names; 192 + parts[i].name = names; 190 193 plen -= len; 191 194 names += len; 192 195 } else { 193 - (*pparts)[i].name = "unnamed"; 196 + parts[i].name = "unnamed"; 194 197 } 195 198 196 199 part++; 197 200 } 198 201 202 + *pparts = parts; 199 203 return nr_parts; 200 204 } 201 205 202 206 static struct mtd_part_parser ofoldpart_parser = { 203 - .owner = THIS_MODULE, 204 207 .parse_fn = parse_ofoldpart_partitions, 205 208 .name = "ofoldpart", 206 209 };
+3 -5
drivers/mtd/onenand/omap2.c
··· 614 614 struct onenand_chip *this; 615 615 int r; 616 616 struct resource *res; 617 - struct mtd_part_parser_data ppdata = {}; 618 617 619 618 pdata = dev_get_platdata(&pdev->dev); 620 619 if (pdata == NULL) { ··· 712 713 c->mtd.priv = &c->onenand; 713 714 714 715 c->mtd.dev.parent = &pdev->dev; 716 + mtd_set_of_node(&c->mtd, pdata->of_node); 715 717 716 718 this = &c->onenand; 717 719 if (c->dma_channel >= 0) { ··· 743 743 if ((r = onenand_scan(&c->mtd, 1)) < 0) 744 744 goto err_release_regulator; 745 745 746 - ppdata.of_node = pdata->of_node; 747 - r = mtd_device_parse_register(&c->mtd, NULL, &ppdata, 748 - pdata ? pdata->parts : NULL, 749 - pdata ? pdata->nr_parts : 0); 746 + r = mtd_device_register(&c->mtd, pdata ? pdata->parts : NULL, 747 + pdata ? pdata->nr_parts : 0); 750 748 if (r) 751 749 goto err_release_onenand; 752 750
+2 -17
drivers/mtd/redboot.c
··· 57 57 } 58 58 59 59 static int parse_redboot_partitions(struct mtd_info *master, 60 - struct mtd_partition **pparts, 60 + const struct mtd_partition **pparts, 61 61 struct mtd_part_parser_data *data) 62 62 { 63 63 int nrparts = 0; ··· 290 290 } 291 291 292 292 static struct mtd_part_parser redboot_parser = { 293 - .owner = THIS_MODULE, 294 293 .parse_fn = parse_redboot_partitions, 295 294 .name = "RedBoot", 296 295 }; 296 + module_mtd_part_parser(redboot_parser); 297 297 298 298 /* mtd parsers will request the module by parser name */ 299 299 MODULE_ALIAS("RedBoot"); 300 - 301 - static int __init redboot_parser_init(void) 302 - { 303 - register_mtd_parser(&redboot_parser); 304 - return 0; 305 - } 306 - 307 - static void __exit redboot_parser_exit(void) 308 - { 309 - deregister_mtd_parser(&redboot_parser); 310 - } 311 - 312 - module_init(redboot_parser_init); 313 - module_exit(redboot_parser_exit); 314 - 315 300 MODULE_LICENSE("GPL"); 316 301 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 317 302 MODULE_DESCRIPTION("Parsing code for RedBoot Flash Image System (FIS) tables");
+2 -1
drivers/mtd/sm_ftl.c
··· 206 206 } 207 207 208 208 /* Breaks offset into parts */ 209 - static void sm_break_offset(struct sm_ftl *ftl, loff_t offset, 209 + static void sm_break_offset(struct sm_ftl *ftl, loff_t loffset, 210 210 int *zone, int *block, int *boffset) 211 211 { 212 + u64 offset = loffset; 212 213 *boffset = do_div(offset, ftl->block_size); 213 214 *block = do_div(offset, ftl->max_lba); 214 215 *zone = offset >= ftl->zone_count ? -1 : offset;
+7
drivers/mtd/spi-nor/Kconfig
··· 7 7 8 8 if MTD_SPI_NOR 9 9 10 + config MTD_MT81xx_NOR 11 + tristate "Mediatek MT81xx SPI NOR flash controller" 12 + help 13 + This enables access to SPI NOR flash, using MT81xx SPI NOR flash 14 + controller. This controller does not support generic SPI BUS, it only 15 + supports SPI NOR Flash. 16 + 10 17 config MTD_SPI_NOR_USE_4K_SECTORS 11 18 bool "Use small 4096 B erase sectors" 12 19 default y
+1
drivers/mtd/spi-nor/Makefile
··· 1 1 obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o 2 2 obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o 3 + obj-$(CONFIG_MTD_MT81xx_NOR) += mtk-quadspi.o 3 4 obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
+6 -8
drivers/mtd/spi-nor/fsl-quadspi.c
··· 269 269 struct clk *clk, *clk_en; 270 270 struct device *dev; 271 271 struct completion c; 272 - struct fsl_qspi_devtype_data *devtype_data; 272 + const struct fsl_qspi_devtype_data *devtype_data; 273 273 u32 nor_size; 274 274 u32 nor_num; 275 275 u32 clk_rate; ··· 927 927 static int fsl_qspi_probe(struct platform_device *pdev) 928 928 { 929 929 struct device_node *np = pdev->dev.of_node; 930 - struct mtd_part_parser_data ppdata; 931 930 struct device *dev = &pdev->dev; 932 931 struct fsl_qspi *q; 933 932 struct resource *res; 934 933 struct spi_nor *nor; 935 934 struct mtd_info *mtd; 936 935 int ret, i = 0; 937 - const struct of_device_id *of_id = 938 - of_match_device(fsl_qspi_dt_ids, &pdev->dev); 939 936 940 937 q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL); 941 938 if (!q) ··· 943 946 return -ENODEV; 944 947 945 948 q->dev = dev; 946 - q->devtype_data = (struct fsl_qspi_devtype_data *)of_id->data; 949 + q->devtype_data = of_device_get_match_data(dev); 950 + if (!q->devtype_data) 951 + return -ENODEV; 947 952 platform_set_drvdata(pdev, q); 948 953 949 954 /* find the resources */ ··· 1012 1013 mtd = &nor->mtd; 1013 1014 1014 1015 nor->dev = dev; 1015 - nor->flash_node = np; 1016 + spi_nor_set_flash_node(nor, np); 1016 1017 nor->priv = q; 1017 1018 1018 1019 /* fill the hooks */ ··· 1037 1038 if (ret) 1038 1039 goto mutex_failed; 1039 1040 1040 - ppdata.of_node = np; 1041 - ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 1041 + ret = mtd_device_register(mtd, NULL, 0); 1042 1042 if (ret) 1043 1043 goto mutex_failed; 1044 1044
+485
drivers/mtd/spi-nor/mtk-quadspi.c
··· 1 + /* 2 + * Copyright (c) 2015 MediaTek Inc. 3 + * Author: Bayi Cheng <bayi.cheng@mediatek.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + */ 14 + 15 + #include <linux/clk.h> 16 + #include <linux/delay.h> 17 + #include <linux/device.h> 18 + #include <linux/init.h> 19 + #include <linux/io.h> 20 + #include <linux/iopoll.h> 21 + #include <linux/ioport.h> 22 + #include <linux/math64.h> 23 + #include <linux/module.h> 24 + #include <linux/mtd/mtd.h> 25 + #include <linux/mutex.h> 26 + #include <linux/of.h> 27 + #include <linux/of_device.h> 28 + #include <linux/pinctrl/consumer.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/slab.h> 31 + #include <linux/mtd/mtd.h> 32 + #include <linux/mtd/partitions.h> 33 + #include <linux/mtd/spi-nor.h> 34 + 35 + #define MTK_NOR_CMD_REG 0x00 36 + #define MTK_NOR_CNT_REG 0x04 37 + #define MTK_NOR_RDSR_REG 0x08 38 + #define MTK_NOR_RDATA_REG 0x0c 39 + #define MTK_NOR_RADR0_REG 0x10 40 + #define MTK_NOR_RADR1_REG 0x14 41 + #define MTK_NOR_RADR2_REG 0x18 42 + #define MTK_NOR_WDATA_REG 0x1c 43 + #define MTK_NOR_PRGDATA0_REG 0x20 44 + #define MTK_NOR_PRGDATA1_REG 0x24 45 + #define MTK_NOR_PRGDATA2_REG 0x28 46 + #define MTK_NOR_PRGDATA3_REG 0x2c 47 + #define MTK_NOR_PRGDATA4_REG 0x30 48 + #define MTK_NOR_PRGDATA5_REG 0x34 49 + #define MTK_NOR_SHREG0_REG 0x38 50 + #define MTK_NOR_SHREG1_REG 0x3c 51 + #define MTK_NOR_SHREG2_REG 0x40 52 + #define MTK_NOR_SHREG3_REG 0x44 53 + #define MTK_NOR_SHREG4_REG 0x48 54 + #define MTK_NOR_SHREG5_REG 0x4c 55 + #define MTK_NOR_SHREG6_REG 0x50 56 + #define MTK_NOR_SHREG7_REG 0x54 57 + #define MTK_NOR_SHREG8_REG 0x58 58 + #define MTK_NOR_SHREG9_REG 0x5c 59 + #define MTK_NOR_CFG1_REG 0x60 60 + #define MTK_NOR_CFG2_REG 0x64 61 + #define MTK_NOR_CFG3_REG 0x68 62 + #define MTK_NOR_STATUS0_REG 0x70 63 + #define MTK_NOR_STATUS1_REG 0x74 64 + #define MTK_NOR_STATUS2_REG 0x78 65 + #define MTK_NOR_STATUS3_REG 0x7c 66 + #define MTK_NOR_FLHCFG_REG 0x84 67 + #define MTK_NOR_TIME_REG 0x94 68 + #define MTK_NOR_PP_DATA_REG 0x98 69 + #define MTK_NOR_PREBUF_STUS_REG 0x9c 70 + #define MTK_NOR_DELSEL0_REG 0xa0 71 + #define MTK_NOR_DELSEL1_REG 0xa4 72 + #define MTK_NOR_INTRSTUS_REG 0xa8 73 + #define MTK_NOR_INTREN_REG 0xac 74 + #define MTK_NOR_CHKSUM_CTL_REG 0xb8 75 + #define MTK_NOR_CHKSUM_REG 0xbc 76 + #define MTK_NOR_CMD2_REG 0xc0 77 + #define MTK_NOR_WRPROT_REG 0xc4 78 + #define MTK_NOR_RADR3_REG 0xc8 79 + #define MTK_NOR_DUAL_REG 0xcc 80 + #define MTK_NOR_DELSEL2_REG 0xd0 81 + #define MTK_NOR_DELSEL3_REG 0xd4 82 + #define MTK_NOR_DELSEL4_REG 0xd8 83 + 84 + /* commands for mtk nor controller */ 85 + #define MTK_NOR_READ_CMD 0x0 86 + #define MTK_NOR_RDSR_CMD 0x2 87 + #define MTK_NOR_PRG_CMD 0x4 88 + #define MTK_NOR_WR_CMD 0x10 89 + #define MTK_NOR_PIO_WR_CMD 0x90 90 + #define MTK_NOR_WRSR_CMD 0x20 91 + #define MTK_NOR_PIO_READ_CMD 0x81 92 + #define MTK_NOR_WR_BUF_ENABLE 0x1 93 + #define MTK_NOR_WR_BUF_DISABLE 0x0 94 + #define MTK_NOR_ENABLE_SF_CMD 0x30 95 + #define MTK_NOR_DUAD_ADDR_EN 0x8 96 + #define MTK_NOR_QUAD_READ_EN 0x4 97 + #define MTK_NOR_DUAL_ADDR_EN 0x2 98 + #define MTK_NOR_DUAL_READ_EN 0x1 99 + #define MTK_NOR_DUAL_DISABLE 0x0 100 + #define MTK_NOR_FAST_READ 0x1 101 + 102 + #define SFLASH_WRBUF_SIZE 128 103 + 104 + /* Can shift up to 48 bits (6 bytes) of TX/RX */ 105 + #define MTK_NOR_MAX_RX_TX_SHIFT 6 106 + /* can shift up to 56 bits (7 bytes) transfer by MTK_NOR_PRG_CMD */ 107 + #define MTK_NOR_MAX_SHIFT 7 108 + 109 + /* Helpers for accessing the program data / shift data registers */ 110 + #define MTK_NOR_PRG_REG(n) (MTK_NOR_PRGDATA0_REG + 4 * (n)) 111 + #define MTK_NOR_SHREG(n) (MTK_NOR_SHREG0_REG + 4 * (n)) 112 + 113 + struct mt8173_nor { 114 + struct spi_nor nor; 115 + struct device *dev; 116 + void __iomem *base; /* nor flash base address */ 117 + struct clk *spi_clk; 118 + struct clk *nor_clk; 119 + }; 120 + 121 + static void mt8173_nor_set_read_mode(struct mt8173_nor *mt8173_nor) 122 + { 123 + struct spi_nor *nor = &mt8173_nor->nor; 124 + 125 + switch (nor->flash_read) { 126 + case SPI_NOR_FAST: 127 + writeb(nor->read_opcode, mt8173_nor->base + 128 + MTK_NOR_PRGDATA3_REG); 129 + writeb(MTK_NOR_FAST_READ, mt8173_nor->base + 130 + MTK_NOR_CFG1_REG); 131 + break; 132 + case SPI_NOR_DUAL: 133 + writeb(nor->read_opcode, mt8173_nor->base + 134 + MTK_NOR_PRGDATA3_REG); 135 + writeb(MTK_NOR_DUAL_READ_EN, mt8173_nor->base + 136 + MTK_NOR_DUAL_REG); 137 + break; 138 + case SPI_NOR_QUAD: 139 + writeb(nor->read_opcode, mt8173_nor->base + 140 + MTK_NOR_PRGDATA4_REG); 141 + writeb(MTK_NOR_QUAD_READ_EN, mt8173_nor->base + 142 + MTK_NOR_DUAL_REG); 143 + break; 144 + default: 145 + writeb(MTK_NOR_DUAL_DISABLE, mt8173_nor->base + 146 + MTK_NOR_DUAL_REG); 147 + break; 148 + } 149 + } 150 + 151 + static int mt8173_nor_execute_cmd(struct mt8173_nor *mt8173_nor, u8 cmdval) 152 + { 153 + int reg; 154 + u8 val = cmdval & 0x1f; 155 + 156 + writeb(cmdval, mt8173_nor->base + MTK_NOR_CMD_REG); 157 + return readl_poll_timeout(mt8173_nor->base + MTK_NOR_CMD_REG, reg, 158 + !(reg & val), 100, 10000); 159 + } 160 + 161 + static int mt8173_nor_do_tx_rx(struct mt8173_nor *mt8173_nor, u8 op, 162 + u8 *tx, int txlen, u8 *rx, int rxlen) 163 + { 164 + int len = 1 + txlen + rxlen; 165 + int i, ret, idx; 166 + 167 + if (len > MTK_NOR_MAX_SHIFT) 168 + return -EINVAL; 169 + 170 + writeb(len * 8, mt8173_nor->base + MTK_NOR_CNT_REG); 171 + 172 + /* start at PRGDATA5, go down to PRGDATA0 */ 173 + idx = MTK_NOR_MAX_RX_TX_SHIFT - 1; 174 + 175 + /* opcode */ 176 + writeb(op, mt8173_nor->base + MTK_NOR_PRG_REG(idx)); 177 + idx--; 178 + 179 + /* program TX data */ 180 + for (i = 0; i < txlen; i++, idx--) 181 + writeb(tx[i], mt8173_nor->base + MTK_NOR_PRG_REG(idx)); 182 + 183 + /* clear out rest of TX registers */ 184 + while (idx >= 0) { 185 + writeb(0, mt8173_nor->base + MTK_NOR_PRG_REG(idx)); 186 + idx--; 187 + } 188 + 189 + ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PRG_CMD); 190 + if (ret) 191 + return ret; 192 + 193 + /* restart at first RX byte */ 194 + idx = rxlen - 1; 195 + 196 + /* read out RX data */ 197 + for (i = 0; i < rxlen; i++, idx--) 198 + rx[i] = readb(mt8173_nor->base + MTK_NOR_SHREG(idx)); 199 + 200 + return 0; 201 + } 202 + 203 + /* Do a WRSR (Write Status Register) command */ 204 + static int mt8173_nor_wr_sr(struct mt8173_nor *mt8173_nor, u8 sr) 205 + { 206 + writeb(sr, mt8173_nor->base + MTK_NOR_PRGDATA5_REG); 207 + writeb(8, mt8173_nor->base + MTK_NOR_CNT_REG); 208 + return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WRSR_CMD); 209 + } 210 + 211 + static int mt8173_nor_write_buffer_enable(struct mt8173_nor *mt8173_nor) 212 + { 213 + u8 reg; 214 + 215 + /* the bit0 of MTK_NOR_CFG2_REG is pre-fetch buffer 216 + * 0: pre-fetch buffer use for read 217 + * 1: pre-fetch buffer use for page program 218 + */ 219 + writel(MTK_NOR_WR_BUF_ENABLE, mt8173_nor->base + MTK_NOR_CFG2_REG); 220 + return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg, 221 + 0x01 == (reg & 0x01), 100, 10000); 222 + } 223 + 224 + static int mt8173_nor_write_buffer_disable(struct mt8173_nor *mt8173_nor) 225 + { 226 + u8 reg; 227 + 228 + writel(MTK_NOR_WR_BUF_DISABLE, mt8173_nor->base + MTK_NOR_CFG2_REG); 229 + return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg, 230 + MTK_NOR_WR_BUF_DISABLE == (reg & 0x1), 100, 231 + 10000); 232 + } 233 + 234 + static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr) 235 + { 236 + int i; 237 + 238 + for (i = 0; i < 3; i++) { 239 + writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR0_REG + i * 4); 240 + addr >>= 8; 241 + } 242 + /* Last register is non-contiguous */ 243 + writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR3_REG); 244 + } 245 + 246 + static int mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length, 247 + size_t *retlen, u_char *buffer) 248 + { 249 + int i, ret; 250 + int addr = (int)from; 251 + u8 *buf = (u8 *)buffer; 252 + struct mt8173_nor *mt8173_nor = nor->priv; 253 + 254 + /* set mode for fast read mode ,dual mode or quad mode */ 255 + mt8173_nor_set_read_mode(mt8173_nor); 256 + mt8173_nor_set_addr(mt8173_nor, addr); 257 + 258 + for (i = 0; i < length; i++, (*retlen)++) { 259 + ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_READ_CMD); 260 + if (ret < 0) 261 + return ret; 262 + buf[i] = readb(mt8173_nor->base + MTK_NOR_RDATA_REG); 263 + } 264 + return 0; 265 + } 266 + 267 + static int mt8173_nor_write_single_byte(struct mt8173_nor *mt8173_nor, 268 + int addr, int length, u8 *data) 269 + { 270 + int i, ret; 271 + 272 + mt8173_nor_set_addr(mt8173_nor, addr); 273 + 274 + for (i = 0; i < length; i++) { 275 + writeb(*data++, mt8173_nor->base + MTK_NOR_WDATA_REG); 276 + ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_WR_CMD); 277 + if (ret < 0) 278 + return ret; 279 + } 280 + return 0; 281 + } 282 + 283 + static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr, 284 + const u8 *buf) 285 + { 286 + int i, bufidx, data; 287 + 288 + mt8173_nor_set_addr(mt8173_nor, addr); 289 + 290 + bufidx = 0; 291 + for (i = 0; i < SFLASH_WRBUF_SIZE; i += 4) { 292 + data = buf[bufidx + 3]<<24 | buf[bufidx + 2]<<16 | 293 + buf[bufidx + 1]<<8 | buf[bufidx]; 294 + bufidx += 4; 295 + writel(data, mt8173_nor->base + MTK_NOR_PP_DATA_REG); 296 + } 297 + return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WR_CMD); 298 + } 299 + 300 + static void mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len, 301 + size_t *retlen, const u_char *buf) 302 + { 303 + int ret; 304 + struct mt8173_nor *mt8173_nor = nor->priv; 305 + 306 + ret = mt8173_nor_write_buffer_enable(mt8173_nor); 307 + if (ret < 0) 308 + dev_warn(mt8173_nor->dev, "write buffer enable failed!\n"); 309 + 310 + while (len >= SFLASH_WRBUF_SIZE) { 311 + ret = mt8173_nor_write_buffer(mt8173_nor, to, buf); 312 + if (ret < 0) 313 + dev_err(mt8173_nor->dev, "write buffer failed!\n"); 314 + len -= SFLASH_WRBUF_SIZE; 315 + to += SFLASH_WRBUF_SIZE; 316 + buf += SFLASH_WRBUF_SIZE; 317 + (*retlen) += SFLASH_WRBUF_SIZE; 318 + } 319 + ret = mt8173_nor_write_buffer_disable(mt8173_nor); 320 + if (ret < 0) 321 + dev_warn(mt8173_nor->dev, "write buffer disable failed!\n"); 322 + 323 + if (len) { 324 + ret = mt8173_nor_write_single_byte(mt8173_nor, to, (int)len, 325 + (u8 *)buf); 326 + if (ret < 0) 327 + dev_err(mt8173_nor->dev, "write single byte failed!\n"); 328 + (*retlen) += len; 329 + } 330 + } 331 + 332 + static int mt8173_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) 333 + { 334 + int ret; 335 + struct mt8173_nor *mt8173_nor = nor->priv; 336 + 337 + switch (opcode) { 338 + case SPINOR_OP_RDSR: 339 + ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_RDSR_CMD); 340 + if (ret < 0) 341 + return ret; 342 + if (len == 1) 343 + *buf = readb(mt8173_nor->base + MTK_NOR_RDSR_REG); 344 + else 345 + dev_err(mt8173_nor->dev, "len should be 1 for read status!\n"); 346 + break; 347 + default: 348 + ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, NULL, 0, buf, len); 349 + break; 350 + } 351 + return ret; 352 + } 353 + 354 + static int mt8173_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, 355 + int len) 356 + { 357 + int ret; 358 + struct mt8173_nor *mt8173_nor = nor->priv; 359 + 360 + switch (opcode) { 361 + case SPINOR_OP_WRSR: 362 + /* We only handle 1 byte */ 363 + ret = mt8173_nor_wr_sr(mt8173_nor, *buf); 364 + break; 365 + default: 366 + ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, buf, len, NULL, 0); 367 + if (ret) 368 + dev_warn(mt8173_nor->dev, "write reg failure!\n"); 369 + break; 370 + } 371 + return ret; 372 + } 373 + 374 + static int __init mtk_nor_init(struct mt8173_nor *mt8173_nor, 375 + struct device_node *flash_node) 376 + { 377 + int ret; 378 + struct spi_nor *nor; 379 + 380 + /* initialize controller to accept commands */ 381 + writel(MTK_NOR_ENABLE_SF_CMD, mt8173_nor->base + MTK_NOR_WRPROT_REG); 382 + 383 + nor = &mt8173_nor->nor; 384 + nor->dev = mt8173_nor->dev; 385 + nor->priv = mt8173_nor; 386 + spi_nor_set_flash_node(nor, flash_node); 387 + 388 + /* fill the hooks to spi nor */ 389 + nor->read = mt8173_nor_read; 390 + nor->read_reg = mt8173_nor_read_reg; 391 + nor->write = mt8173_nor_write; 392 + nor->write_reg = mt8173_nor_write_reg; 393 + nor->mtd.name = "mtk_nor"; 394 + /* initialized with NULL */ 395 + ret = spi_nor_scan(nor, NULL, SPI_NOR_DUAL); 396 + if (ret) 397 + return ret; 398 + 399 + return mtd_device_register(&nor->mtd, NULL, 0); 400 + } 401 + 402 + static int mtk_nor_drv_probe(struct platform_device *pdev) 403 + { 404 + struct device_node *flash_np; 405 + struct resource *res; 406 + int ret; 407 + struct mt8173_nor *mt8173_nor; 408 + 409 + if (!pdev->dev.of_node) { 410 + dev_err(&pdev->dev, "No DT found\n"); 411 + return -EINVAL; 412 + } 413 + 414 + mt8173_nor = devm_kzalloc(&pdev->dev, sizeof(*mt8173_nor), GFP_KERNEL); 415 + if (!mt8173_nor) 416 + return -ENOMEM; 417 + platform_set_drvdata(pdev, mt8173_nor); 418 + 419 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 420 + mt8173_nor->base = devm_ioremap_resource(&pdev->dev, res); 421 + if (IS_ERR(mt8173_nor->base)) 422 + return PTR_ERR(mt8173_nor->base); 423 + 424 + mt8173_nor->spi_clk = devm_clk_get(&pdev->dev, "spi"); 425 + if (IS_ERR(mt8173_nor->spi_clk)) 426 + return PTR_ERR(mt8173_nor->spi_clk); 427 + 428 + mt8173_nor->nor_clk = devm_clk_get(&pdev->dev, "sf"); 429 + if (IS_ERR(mt8173_nor->nor_clk)) 430 + return PTR_ERR(mt8173_nor->nor_clk); 431 + 432 + mt8173_nor->dev = &pdev->dev; 433 + ret = clk_prepare_enable(mt8173_nor->spi_clk); 434 + if (ret) 435 + return ret; 436 + 437 + ret = clk_prepare_enable(mt8173_nor->nor_clk); 438 + if (ret) { 439 + clk_disable_unprepare(mt8173_nor->spi_clk); 440 + return ret; 441 + } 442 + /* only support one attached flash */ 443 + flash_np = of_get_next_available_child(pdev->dev.of_node, NULL); 444 + if (!flash_np) { 445 + dev_err(&pdev->dev, "no SPI flash device to configure\n"); 446 + ret = -ENODEV; 447 + goto nor_free; 448 + } 449 + ret = mtk_nor_init(mt8173_nor, flash_np); 450 + 451 + nor_free: 452 + if (ret) { 453 + clk_disable_unprepare(mt8173_nor->spi_clk); 454 + clk_disable_unprepare(mt8173_nor->nor_clk); 455 + } 456 + return ret; 457 + } 458 + 459 + static int mtk_nor_drv_remove(struct platform_device *pdev) 460 + { 461 + struct mt8173_nor *mt8173_nor = platform_get_drvdata(pdev); 462 + 463 + clk_disable_unprepare(mt8173_nor->spi_clk); 464 + clk_disable_unprepare(mt8173_nor->nor_clk); 465 + return 0; 466 + } 467 + 468 + static const struct of_device_id mtk_nor_of_ids[] = { 469 + { .compatible = "mediatek,mt8173-nor"}, 470 + { /* sentinel */ } 471 + }; 472 + MODULE_DEVICE_TABLE(of, mtk_nor_of_ids); 473 + 474 + static struct platform_driver mtk_nor_driver = { 475 + .probe = mtk_nor_drv_probe, 476 + .remove = mtk_nor_drv_remove, 477 + .driver = { 478 + .name = "mtk-nor", 479 + .of_match_table = mtk_nor_of_ids, 480 + }, 481 + }; 482 + 483 + module_platform_driver(mtk_nor_driver); 484 + MODULE_LICENSE("GPL v2"); 485 + MODULE_DESCRIPTION("MediaTek SPI NOR Flash Driver");
+2 -4
drivers/mtd/spi-nor/nxp-spifi.c
··· 271 271 static int nxp_spifi_setup_flash(struct nxp_spifi *spifi, 272 272 struct device_node *np) 273 273 { 274 - struct mtd_part_parser_data ppdata; 275 274 enum read_mode flash_read; 276 275 u32 ctrl, property; 277 276 u16 mode = 0; ··· 329 330 writel(ctrl, spifi->io_base + SPIFI_CTRL); 330 331 331 332 spifi->nor.dev = spifi->dev; 332 - spifi->nor.flash_node = np; 333 + spi_nor_set_flash_node(&spifi->nor, np); 333 334 spifi->nor.priv = spifi; 334 335 spifi->nor.read = nxp_spifi_read; 335 336 spifi->nor.write = nxp_spifi_write; ··· 360 361 return ret; 361 362 } 362 363 363 - ppdata.of_node = np; 364 - ret = mtd_device_parse_register(&spifi->nor.mtd, NULL, &ppdata, NULL, 0); 364 + ret = mtd_device_register(&spifi->nor.mtd, NULL, 0); 365 365 if (ret) { 366 366 dev_err(spifi->dev, "mtd device parse failed\n"); 367 367 return ret;
+60 -21
drivers/mtd/spi-nor/spi-nor.c
··· 38 38 #define CHIP_ERASE_2MB_READY_WAIT_JIFFIES (40UL * HZ) 39 39 40 40 #define SPI_NOR_MAX_ID_LEN 6 41 + #define SPI_NOR_MAX_ADDR_WIDTH 4 41 42 42 43 struct flash_info { 43 44 char *name; ··· 314 313 } 315 314 316 315 /* 316 + * Initiate the erasure of a single sector 317 + */ 318 + static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) 319 + { 320 + u8 buf[SPI_NOR_MAX_ADDR_WIDTH]; 321 + int i; 322 + 323 + if (nor->erase) 324 + return nor->erase(nor, addr); 325 + 326 + /* 327 + * Default implementation, if driver doesn't have a specialized HW 328 + * control 329 + */ 330 + for (i = nor->addr_width - 1; i >= 0; i--) { 331 + buf[i] = addr & 0xff; 332 + addr >>= 8; 333 + } 334 + 335 + return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width); 336 + } 337 + 338 + /* 317 339 * Erase an address range on the nor chip. The address range may extend 318 340 * one or more erase sectors. Return an error is there is a problem erasing. 319 341 */ ··· 395 371 while (len) { 396 372 write_enable(nor); 397 373 398 - if (nor->erase(nor, addr)) { 399 - ret = -EIO; 374 + ret = spi_nor_erase_sector(nor, addr); 375 + if (ret) 400 376 goto erase_err; 401 - } 402 377 403 378 addr += mtd->erasesize; 404 379 len -= mtd->erasesize; ··· 410 387 411 388 write_disable(nor); 412 389 413 - spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE); 414 - 415 - instr->state = MTD_ERASE_DONE; 416 - mtd_erase_callback(instr); 417 - 418 - return ret; 419 - 420 390 erase_err: 421 391 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE); 422 - instr->state = MTD_ERASE_FAILED; 392 + 393 + instr->state = ret ? MTD_ERASE_FAILED : MTD_ERASE_DONE; 394 + mtd_erase_callback(instr); 395 + 423 396 return ret; 424 397 } 425 398 ··· 478 459 static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) 479 460 { 480 461 struct mtd_info *mtd = &nor->mtd; 481 - u8 status_old, status_new; 462 + int status_old, status_new; 482 463 u8 mask = SR_BP2 | SR_BP1 | SR_BP0; 483 464 u8 shift = ffs(mask) - 1, pow, val; 465 + int ret; 484 466 485 467 status_old = read_sr(nor); 468 + if (status_old < 0) 469 + return status_old; 486 470 487 471 /* SPI NOR always locks to the end */ 488 472 if (ofs + len != mtd->size) { ··· 520 498 return -EINVAL; 521 499 522 500 write_enable(nor); 523 - return write_sr(nor, status_new); 501 + ret = write_sr(nor, status_new); 502 + if (ret) 503 + return ret; 504 + return spi_nor_wait_till_ready(nor); 524 505 } 525 506 526 507 /* ··· 534 509 static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) 535 510 { 536 511 struct mtd_info *mtd = &nor->mtd; 537 - uint8_t status_old, status_new; 512 + int status_old, status_new; 538 513 u8 mask = SR_BP2 | SR_BP1 | SR_BP0; 539 514 u8 shift = ffs(mask) - 1, pow, val; 515 + int ret; 540 516 541 517 status_old = read_sr(nor); 518 + if (status_old < 0) 519 + return status_old; 542 520 543 521 /* Cannot unlock; would unlock larger region than requested */ 544 522 if (stm_is_locked_sr(nor, ofs - mtd->erasesize, mtd->erasesize, ··· 574 546 return -EINVAL; 575 547 576 548 write_enable(nor); 577 - return write_sr(nor, status_new); 549 + ret = write_sr(nor, status_new); 550 + if (ret) 551 + return ret; 552 + return spi_nor_wait_till_ready(nor); 578 553 } 579 554 580 555 /* ··· 746 715 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, 747 716 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) }, 748 717 { "mx25l1606e", INFO(0xc22015, 0, 64 * 1024, 32, SECT_4K) }, 749 - { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) }, 718 + { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) }, 750 719 { "mx25l3255e", INFO(0xc29e16, 0, 64 * 1024, 64, SECT_4K) }, 751 - { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) }, 720 + { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) }, 752 721 { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) }, 753 722 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, 754 723 { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) }, ··· 887 856 888 857 tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN); 889 858 if (tmp < 0) { 890 - dev_dbg(nor->dev, " error %d reading JEDEC ID\n", tmp); 859 + dev_dbg(nor->dev, "error %d reading JEDEC ID\n", tmp); 891 860 return ERR_PTR(tmp); 892 861 } 893 862 ··· 898 867 return &spi_nor_ids[tmp]; 899 868 } 900 869 } 901 - dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %2x, %2x\n", 870 + dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n", 902 871 id[0], id[1], id[2]); 903 872 return ERR_PTR(-ENODEV); 904 873 } ··· 1044 1013 int ret, val; 1045 1014 1046 1015 val = read_sr(nor); 1016 + if (val < 0) 1017 + return val; 1047 1018 write_enable(nor); 1048 1019 1049 1020 write_sr(nor, val | SR_QUAD_EN_MX); ··· 1171 1138 static int spi_nor_check(struct spi_nor *nor) 1172 1139 { 1173 1140 if (!nor->dev || !nor->read || !nor->write || 1174 - !nor->read_reg || !nor->write_reg || !nor->erase) { 1141 + !nor->read_reg || !nor->write_reg) { 1175 1142 pr_err("spi-nor: please fill all the necessary fields!\n"); 1176 1143 return -EINVAL; 1177 1144 } ··· 1184 1151 const struct flash_info *info = NULL; 1185 1152 struct device *dev = nor->dev; 1186 1153 struct mtd_info *mtd = &nor->mtd; 1187 - struct device_node *np = nor->flash_node; 1154 + struct device_node *np = spi_nor_get_flash_node(nor); 1188 1155 int ret; 1189 1156 int i; 1190 1157 ··· 1369 1336 set_4byte(nor, info, 1); 1370 1337 } else { 1371 1338 nor->addr_width = 3; 1339 + } 1340 + 1341 + if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) { 1342 + dev_err(dev, "address width is too large: %u\n", 1343 + nor->addr_width); 1344 + return -EINVAL; 1372 1345 } 1373 1346 1374 1347 nor->read_dummy = spi_nor_read_dummy_cycles(nor);
+1 -2
drivers/mtd/tests/pagetest.c
··· 127 127 unsigned char *pp1, *pp2, *pp3, *pp4; 128 128 129 129 pr_info("crosstest\n"); 130 - pp1 = kmalloc(pgsize * 4, GFP_KERNEL); 130 + pp1 = kzalloc(pgsize * 4, GFP_KERNEL); 131 131 if (!pp1) 132 132 return -ENOMEM; 133 133 pp2 = pp1 + pgsize; 134 134 pp3 = pp2 + pgsize; 135 135 pp4 = pp3 + pgsize; 136 - memset(pp1, 0, pgsize * 4); 137 136 138 137 addr0 = 0; 139 138 for (i = 0; i < ebcnt && bbt[i]; ++i)
+10 -14
drivers/staging/mt29f_spinand/mt29f_spinand.c
··· 31 31 32 32 static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd) 33 33 { 34 - struct nand_chip *chip = (struct nand_chip *)mtd->priv; 35 - struct spinand_info *info = (struct spinand_info *)chip->priv; 34 + struct nand_chip *chip = mtd_to_nand(mtd); 35 + struct spinand_info *info = nand_get_controller_data(chip); 36 36 struct spinand_state *state = (struct spinand_state *)info->priv; 37 37 38 38 return state; ··· 633 633 u8 *p = buf; 634 634 int eccsize = chip->ecc.size; 635 635 int eccsteps = chip->ecc.steps; 636 - struct spinand_info *info = (struct spinand_info *)chip->priv; 636 + struct spinand_info *info = nand_get_controller_data(chip); 637 637 638 638 enable_read_hw_ecc = 1; 639 639 ··· 679 679 680 680 static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip) 681 681 { 682 - struct spinand_info *info = (struct spinand_info *)chip->priv; 682 + struct spinand_info *info = nand_get_controller_data(chip); 683 683 684 684 unsigned long timeo = jiffies; 685 685 int retval, state = chip->state; ··· 744 744 static void spinand_cmdfunc(struct mtd_info *mtd, unsigned int command, 745 745 int column, int page) 746 746 { 747 - struct nand_chip *chip = (struct nand_chip *)mtd->priv; 748 - struct spinand_info *info = (struct spinand_info *)chip->priv; 747 + struct nand_chip *chip = mtd_to_nand(mtd); 748 + struct spinand_info *info = nand_get_controller_data(chip); 749 749 struct spinand_state *state = (struct spinand_state *)info->priv; 750 750 751 751 switch (command) { ··· 850 850 struct nand_chip *chip; 851 851 struct spinand_info *info; 852 852 struct spinand_state *state; 853 - struct mtd_part_parser_data ppdata; 854 853 855 854 info = devm_kzalloc(&spi_nand->dev, sizeof(struct spinand_info), 856 855 GFP_KERNEL); ··· 893 894 pr_info("%s: disable ecc failed!\n", __func__); 894 895 #endif 895 896 896 - chip->priv = info; 897 + nand_set_flash_node(chip, spi_nand->dev.of_node); 898 + nand_set_controller_data(chip, info); 897 899 chip->read_buf = spinand_read_buf; 898 900 chip->write_buf = spinand_write_buf; 899 901 chip->read_byte = spinand_read_byte; ··· 903 903 chip->options |= NAND_CACHEPRG; 904 904 chip->select_chip = spinand_select_chip; 905 905 906 - mtd = devm_kzalloc(&spi_nand->dev, sizeof(struct mtd_info), GFP_KERNEL); 907 - if (!mtd) 908 - return -ENOMEM; 906 + mtd = nand_to_mtd(chip); 909 907 910 908 dev_set_drvdata(&spi_nand->dev, mtd); 911 909 912 - mtd->priv = chip; 913 910 mtd->dev.parent = &spi_nand->dev; 914 911 mtd->oobsize = 64; 915 912 916 913 if (nand_scan(mtd, 1)) 917 914 return -ENXIO; 918 915 919 - ppdata.of_node = spi_nand->dev.of_node; 920 - return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); 916 + return mtd_device_register(mtd, NULL, 0); 921 917 } 922 918 923 919 /*
+1 -1
fs/jffs2/wbuf.c
··· 1153 1153 { 1154 1154 struct delayed_work *dwork; 1155 1155 1156 - dwork = container_of(work, struct delayed_work, work); 1156 + dwork = to_delayed_work(work); 1157 1157 return container_of(dwork, struct jffs2_sb_info, wbuf_dwork); 1158 1158 } 1159 1159
+2 -4
include/linux/bcma/bcma_driver_chipcommon.h
··· 579 579 }; 580 580 581 581 #ifdef CONFIG_BCMA_SFLASH 582 + struct mtd_info; 583 + 582 584 struct bcma_sflash { 583 585 bool present; 584 586 u32 window; ··· 594 592 #endif 595 593 596 594 #ifdef CONFIG_BCMA_NFLASH 597 - struct mtd_info; 598 - 599 595 struct bcma_nflash { 600 596 bool present; 601 597 bool boot; /* This is the flash the SoC boots from */ 602 - 603 - struct mtd_info *mtd; 604 598 }; 605 599 #endif 606 600
+2
include/linux/mtd/map.h
··· 142 142 #endif 143 143 144 144 #ifndef map_bankwidth 145 + #ifdef CONFIG_MTD 145 146 #warning "No CONFIG_MTD_MAP_BANK_WIDTH_xx selected. No NOR chip support can work" 147 + #endif 146 148 static inline int map_bankwidth(void *map) 147 149 { 148 150 BUG();
+11
include/linux/mtd/mtd.h
··· 254 254 int usecount; 255 255 }; 256 256 257 + static inline void mtd_set_of_node(struct mtd_info *mtd, 258 + struct device_node *np) 259 + { 260 + mtd->dev.of_node = np; 261 + } 262 + 263 + static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd) 264 + { 265 + return mtd->dev.of_node; 266 + } 267 + 257 268 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr); 258 269 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, 259 270 void **virt, resource_size_t *phys);
+54 -17
include/linux/mtd/nand.h
··· 129 129 /* Enable Hardware ECC before syndrome is read back from flash */ 130 130 #define NAND_ECC_READSYN 2 131 131 132 + /* 133 + * Enable generic NAND 'page erased' check. This check is only done when 134 + * ecc.correct() returns -EBADMSG. 135 + * Set this flag if your implementation does not fix bitflips in erased 136 + * pages and you want to rely on the default implementation. 137 + */ 138 + #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0) 139 + 132 140 /* Bit mask for flags passed to do_nand_read_ecc */ 133 141 #define NAND_GET_DEVICE 0x80 134 142 ··· 284 276 __le16 t_r; 285 277 __le16 t_ccs; 286 278 __le16 src_sync_timing_mode; 287 - __le16 src_ssync_features; 279 + u8 src_ssync_features; 288 280 __le16 clk_pin_capacitance_typ; 289 281 __le16 io_pin_capacitance_typ; 290 282 __le16 input_pin_capacitance_typ; 291 283 u8 input_pin_capacitance_max; 292 284 u8 driver_strength_support; 293 285 __le16 t_int_r; 294 - __le16 t_ald; 295 - u8 reserved4[7]; 286 + __le16 t_adl; 287 + u8 reserved4[8]; 296 288 297 289 /* vendor */ 298 290 __le16 vendor_revision; ··· 415 407 __le16 input_pin_capacitance_typ; 416 408 __le16 clk_pin_capacitance_typ; 417 409 u8 driver_strength_support; 418 - __le16 t_ald; 410 + __le16 t_adl; 419 411 u8 reserved4[36]; 420 412 421 413 /* ECC and endurance block */ ··· 459 451 * @total: total number of ECC bytes per page 460 452 * @prepad: padding information for syndrome based ECC generators 461 453 * @postpad: padding information for syndrome based ECC generators 454 + * @options: ECC specific options (see NAND_ECC_XXX flags defined above) 462 455 * @layout: ECC layout control struct pointer 463 456 * @priv: pointer to private ECC control data 464 457 * @hwctl: function to control hardware ECC generator. Must only 465 458 * be provided if an hardware ECC is available 466 459 * @calculate: function for ECC calculation or readback from ECC hardware 467 - * @correct: function for ECC correction, matching to ECC generator (sw/hw) 460 + * @correct: function for ECC correction, matching to ECC generator (sw/hw). 461 + * Should return a positive number representing the number of 462 + * corrected bitflips, -EBADMSG if the number of bitflips exceed 463 + * ECC strength, or any other error code if the error is not 464 + * directly related to correction. 465 + * If -EBADMSG is returned the input buffers should be left 466 + * untouched. 468 467 * @read_page_raw: function to read a raw page without ECC. This function 469 468 * should hide the specific layout used by the ECC 470 469 * controller and always return contiguous in-band and ··· 509 494 int strength; 510 495 int prepad; 511 496 int postpad; 497 + unsigned int options; 512 498 struct nand_ecclayout *layout; 513 499 void *priv; 514 500 void (*hwctl)(struct mtd_info *mtd, int mode); ··· 556 540 557 541 /** 558 542 * struct nand_chip - NAND Private Flash Chip Data 543 + * @mtd: MTD device registered to the MTD framework 559 544 * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the 560 545 * flash device 561 546 * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the 562 547 * flash device. 563 - * @flash_node: [BOARDSPECIFIC] device node describing this instance 564 548 * @read_byte: [REPLACEABLE] read one byte from the chip 565 549 * @read_word: [REPLACEABLE] read one word from the chip 566 550 * @write_byte: [REPLACEABLE] write a single byte to the chip on the ··· 656 640 */ 657 641 658 642 struct nand_chip { 643 + struct mtd_info mtd; 659 644 void __iomem *IO_ADDR_R; 660 645 void __iomem *IO_ADDR_W; 661 - 662 - struct device_node *flash_node; 663 646 664 647 uint8_t (*read_byte)(struct mtd_info *mtd); 665 648 u16 (*read_word)(struct mtd_info *mtd); ··· 733 718 734 719 void *priv; 735 720 }; 721 + 722 + static inline void nand_set_flash_node(struct nand_chip *chip, 723 + struct device_node *np) 724 + { 725 + mtd_set_of_node(&chip->mtd, np); 726 + } 727 + 728 + static inline struct device_node *nand_get_flash_node(struct nand_chip *chip) 729 + { 730 + return mtd_get_of_node(&chip->mtd); 731 + } 732 + 733 + static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd) 734 + { 735 + return container_of(mtd, struct nand_chip, mtd); 736 + } 737 + 738 + static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip) 739 + { 740 + return &chip->mtd; 741 + } 742 + 743 + static inline void *nand_get_controller_data(struct nand_chip *chip) 744 + { 745 + return chip->priv; 746 + } 747 + 748 + static inline void nand_set_controller_data(struct nand_chip *chip, void *priv) 749 + { 750 + chip->priv = priv; 751 + } 736 752 737 753 /* 738 754 * NAND Flash Manufacturer ID Codes ··· 952 906 struct platform_nand_chip chip; 953 907 struct platform_nand_ctrl ctrl; 954 908 }; 955 - 956 - /* Some helpers to access the data structures */ 957 - static inline 958 - struct platform_nand_chip *get_platform_nandchip(struct mtd_info *mtd) 959 - { 960 - struct nand_chip *chip = mtd->priv; 961 - 962 - return chip->priv; 963 - } 964 909 965 910 /* return the supported features. */ 966 911 static inline int onfi_feature(struct nand_chip *chip)
+1 -1
include/linux/mtd/nand_bch.h
··· 55 55 nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf, 56 56 unsigned char *read_ecc, unsigned char *calc_ecc) 57 57 { 58 - return -1; 58 + return -ENOTSUPP; 59 59 } 60 60 61 61 static inline struct nand_bch_control *
+22 -5
include/linux/mtd/partitions.h
··· 41 41 uint64_t size; /* partition size */ 42 42 uint64_t offset; /* offset within the master MTD space */ 43 43 uint32_t mask_flags; /* master MTD flags to mask out for this partition */ 44 - struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only) */ 45 44 }; 46 45 47 46 #define MTDPART_OFS_RETAIN (-3) ··· 55 56 /** 56 57 * struct mtd_part_parser_data - used to pass data to MTD partition parsers. 57 58 * @origin: for RedBoot, start address of MTD device 58 - * @of_node: for OF parsers, device node containing partitioning information 59 59 */ 60 60 struct mtd_part_parser_data { 61 61 unsigned long origin; 62 - struct device_node *of_node; 63 62 }; 64 63 65 64 ··· 69 72 struct list_head list; 70 73 struct module *owner; 71 74 const char *name; 72 - int (*parse_fn)(struct mtd_info *, struct mtd_partition **, 75 + int (*parse_fn)(struct mtd_info *, const struct mtd_partition **, 73 76 struct mtd_part_parser_data *); 77 + void (*cleanup)(const struct mtd_partition *pparts, int nr_parts); 74 78 }; 75 79 76 - extern void register_mtd_parser(struct mtd_part_parser *parser); 80 + /* Container for passing around a set of parsed partitions */ 81 + struct mtd_partitions { 82 + const struct mtd_partition *parts; 83 + int nr_parts; 84 + const struct mtd_part_parser *parser; 85 + }; 86 + 87 + extern int __register_mtd_parser(struct mtd_part_parser *parser, 88 + struct module *owner); 89 + #define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE) 90 + 77 91 extern void deregister_mtd_parser(struct mtd_part_parser *parser); 92 + 93 + /* 94 + * module_mtd_part_parser() - Helper macro for MTD partition parsers that don't 95 + * do anything special in module init/exit. Each driver may only use this macro 96 + * once, and calling it replaces module_init() and module_exit(). 97 + */ 98 + #define module_mtd_part_parser(__mtd_part_parser) \ 99 + module_driver(__mtd_part_parser, register_mtd_parser, \ 100 + deregister_mtd_parser) 78 101 79 102 int mtd_is_partition(const struct mtd_info *mtd); 80 103 int mtd_add_partition(struct mtd_info *master, const char *name,
+2 -2
include/linux/mtd/sh_flctl.h
··· 143 143 struct dma_chan; 144 144 145 145 struct sh_flctl { 146 - struct mtd_info mtd; 147 146 struct nand_chip chip; 148 147 struct platform_device *pdev; 149 148 struct dev_pm_qos_request pm_qos; 150 149 void __iomem *reg; 150 + resource_size_t fifo; 151 151 152 152 uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */ 153 153 int read_bytes; ··· 186 186 187 187 static inline struct sh_flctl *mtd_to_flctl(struct mtd_info *mtdinfo) 188 188 { 189 - return container_of(mtdinfo, struct sh_flctl, mtd); 189 + return container_of(mtd_to_nand(mtdinfo), struct sh_flctl, chip); 190 190 } 191 191 192 192 #endif /* __SH_FLCTL_H__ */
+14 -5
include/linux/mtd/spi-nor.h
··· 12 12 13 13 #include <linux/bitops.h> 14 14 #include <linux/mtd/cfi.h> 15 + #include <linux/mtd/mtd.h> 15 16 16 17 /* 17 18 * Manufacturer IDs ··· 118 117 SNOR_F_USE_FSR = BIT(0), 119 118 }; 120 119 121 - struct mtd_info; 122 - 123 120 /** 124 121 * struct spi_nor - Structure for defining a the SPI NOR layer 125 122 * @mtd: point to a mtd_info structure 126 123 * @lock: the lock for the read/write/erase/lock/unlock operations 127 124 * @dev: point to a spi device, or a spi nor controller device. 128 - * @flash_node: point to a device node describing this flash instance. 129 125 * @page_size: the page size of the SPI NOR 130 126 * @addr_width: number of address bytes 131 127 * @erase_opcode: the opcode for erasing a sector ··· 142 144 * @read: [DRIVER-SPECIFIC] read data from the SPI NOR 143 145 * @write: [DRIVER-SPECIFIC] write data to the SPI NOR 144 146 * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR 145 - * at the offset @offs 147 + * at the offset @offs; if not provided by the driver, 148 + * spi-nor will send the erase opcode via write_reg() 146 149 * @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR 147 150 * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR 148 151 * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is ··· 154 155 struct mtd_info mtd; 155 156 struct mutex lock; 156 157 struct device *dev; 157 - struct device_node *flash_node; 158 158 u32 page_size; 159 159 u8 addr_width; 160 160 u8 erase_opcode; ··· 182 184 183 185 void *priv; 184 186 }; 187 + 188 + static inline void spi_nor_set_flash_node(struct spi_nor *nor, 189 + struct device_node *np) 190 + { 191 + mtd_set_of_node(&nor->mtd, np); 192 + } 193 + 194 + static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) 195 + { 196 + return mtd_get_of_node(&nor->mtd); 197 + } 185 198 186 199 /** 187 200 * spi_nor_scan() - scan the SPI NOR