mtd: merge for-4.4 development into -next development
authorBrian Norris <computersforpeace@gmail.com>
Wed, 9 Dec 2015 17:59:45 +0000 (09:59 -0800)
committerBrian Norris <computersforpeace@gmail.com>
Wed, 9 Dec 2015 18:00:34 +0000 (10:00 -0800)
A few MAINTAINERS updates, and some DT binding/documentation fixups.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
102 files changed:
Documentation/DocBook/mtdnand.tmpl
Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt
Documentation/devicetree/bindings/mtd/mtk-quadspi.txt [new file with mode: 0644]
Documentation/devicetree/bindings/mtd/partition.txt
Documentation/mtd/nand_ecc.txt
arch/arm/mach-ep93xx/snappercl15.c
arch/arm/mach-ep93xx/ts72xx.c
arch/arm/mach-imx/mach-qong.c
arch/arm/mach-ixp4xx/ixdp425-setup.c
arch/arm/mach-omap1/board-nand.c
arch/arm/mach-orion5x/ts78xx-setup.c
arch/arm/mach-pxa/balloon3.c
arch/arm/mach-pxa/em-x270.c
arch/arm/mach-pxa/palmtx.c
arch/blackfin/mach-bf537/boards/stamp.c
arch/blackfin/mach-bf561/boards/acvilon.c
arch/cris/arch-v32/drivers/mach-a3/nandflash.c
arch/cris/arch-v32/drivers/mach-fs/nandflash.c
arch/mips/alchemy/devboards/db1200.c
arch/mips/alchemy/devboards/db1300.c
arch/mips/alchemy/devboards/db1550.c
arch/mips/pnx833x/common/platform.c
arch/mips/rb532/devices.c
arch/sh/boards/mach-migor/setup.c
drivers/mtd/Kconfig
drivers/mtd/afs.c
drivers/mtd/ar7part.c
drivers/mtd/bcm47xxpart.c
drivers/mtd/bcm63xxpart.c
drivers/mtd/chips/Kconfig
drivers/mtd/cmdlinepart.c
drivers/mtd/devices/m25p80.c
drivers/mtd/devices/mtd_dataflash.c
drivers/mtd/devices/spear_smi.c
drivers/mtd/devices/st_spi_fsm.c
drivers/mtd/maps/lantiq-flash.c
drivers/mtd/maps/physmap_of.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdpart.c
drivers/mtd/nand/ams-delta.c
drivers/mtd/nand/atmel_nand.c
drivers/mtd/nand/au1550nd.c
drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
drivers/mtd/nand/bf5xx_nand.c
drivers/mtd/nand/brcmnand/brcmnand.c
drivers/mtd/nand/cafe_nand.c
drivers/mtd/nand/cmx270_nand.c
drivers/mtd/nand/cs553x_nand.c
drivers/mtd/nand/davinci_nand.c
drivers/mtd/nand/diskonchip.c
drivers/mtd/nand/docg4.c
drivers/mtd/nand/fsl_elbc_nand.c
drivers/mtd/nand/fsl_ifc_nand.c
drivers/mtd/nand/fsl_upm.c
drivers/mtd/nand/fsmc_nand.c
drivers/mtd/nand/gpio.c
drivers/mtd/nand/gpmi-nand/gpmi-nand.c
drivers/mtd/nand/hisi504_nand.c
drivers/mtd/nand/jz4740_nand.c
drivers/mtd/nand/lpc32xx_mlc.c
drivers/mtd/nand/lpc32xx_slc.c
drivers/mtd/nand/mpc5121_nfc.c
drivers/mtd/nand/mxc_nand.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nand_bbt.c
drivers/mtd/nand/nand_bch.c
drivers/mtd/nand/nand_ecc.c
drivers/mtd/nand/nandsim.c
drivers/mtd/nand/ndfc.c
drivers/mtd/nand/nuc900_nand.c
drivers/mtd/nand/omap2.c
drivers/mtd/nand/orion_nand.c
drivers/mtd/nand/pasemi_nand.c
drivers/mtd/nand/plat_nand.c
drivers/mtd/nand/pxa3xx_nand.c
drivers/mtd/nand/r852.c
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sh_flctl.c
drivers/mtd/nand/sharpsl.c
drivers/mtd/nand/sm_common.c
drivers/mtd/nand/socrates_nand.c
drivers/mtd/nand/sunxi_nand.c
drivers/mtd/nand/tmio_nand.c
drivers/mtd/nand/txx9ndfmc.c
drivers/mtd/nand/vf610_nfc.c
drivers/mtd/nand/xway_nand.c
drivers/mtd/ofpart.c
drivers/mtd/onenand/omap2.c
drivers/mtd/redboot.c
drivers/mtd/sm_ftl.c
drivers/mtd/spi-nor/Kconfig
drivers/mtd/spi-nor/Makefile
drivers/mtd/spi-nor/fsl-quadspi.c
drivers/mtd/spi-nor/mtk-quadspi.c [new file with mode: 0644]
drivers/mtd/spi-nor/nxp-spifi.c
drivers/mtd/spi-nor/spi-nor.c
drivers/staging/mt29f_spinand/mt29f_spinand.c
include/linux/mtd/map.h
include/linux/mtd/mtd.h
include/linux/mtd/nand.h
include/linux/mtd/partitions.h
include/linux/mtd/spi-nor.h

index 7da8f04..403a7ab 100644 (file)
@@ -235,7 +235,7 @@ static void board_hwcontrol(struct mtd_info *mtd, int cmd)
                <programlisting>
 static void board_hwcontrol(struct mtd_info *mtd, int cmd)
 {
-       struct nand_chip *this = (struct nand_chip *) mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        switch(cmd){
                case NAND_CTL_SETCLE: this->IO_ADDR_W |= CLE_ADRR_BIT;  break;
                case NAND_CTL_CLRCLE: this->IO_ADDR_W &amp;= ~CLE_ADRR_BIT; break;
@@ -399,7 +399,7 @@ static void board_select_chip (struct mtd_info *mtd, int chip)
                <programlisting>
 static void board_select_chip (struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *this = (struct nand_chip *) mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        
        /* Deselect all chips */
        this->IO_ADDR_R &amp;= ~BOARD_NAND_ADDR_MASK;
index 2bee681..2c91c03 100644 (file)
@@ -1,15 +1,61 @@
-* MTD SPI driver for ST M25Pxx (and similar) serial flash chips
+* SPI NOR flash: ST M25Pxx (and similar) serial flash chips
 
 Required properties:
 - #address-cells, #size-cells : Must be present if the device has sub-nodes
   representing partitions.
 - compatible : May include a device-specific string consisting of the
-               manufacturer and name of the chip. Bear in mind the DT binding
-               is not Linux-only, but in case of Linux, see the "m25p_ids"
-               table in drivers/mtd/devices/m25p80.c for the list of supported
-               chips.
+               manufacturer and name of the chip. A list of supported chip
+               names follows.
                Must also include "jedec,spi-nor" for any SPI NOR flash that can
                be identified by the JEDEC READ ID opcode (0x9F).
+
+               Supported chip names:
+                 at25df321a
+                 at25df641
+                 at26df081a
+                 mr25h256
+                 mx25l4005a
+                 mx25l1606e
+                 mx25l6405d
+                 mx25l12805d
+                 mx25l25635e
+                 n25q064
+                 n25q128a11
+                 n25q128a13
+                 n25q512a
+                 s25fl256s1
+                 s25fl512s
+                 s25sl12801
+                 s25fl008k
+                 s25fl064k
+                 sst25vf040b
+                 m25p40
+                 m25p80
+                 m25p16
+                 m25p32
+                 m25p64
+                 m25p128
+                 w25x80
+                 w25x32
+                 w25q32
+                 w25q32dw
+                 w25q80bl
+                 w25q128
+                 w25q256
+
+               The following chip names have been used historically to
+               designate quirky versions of flash chips that do not support the
+               JEDEC READ ID opcode (0x9F):
+                 m25p05-nonjedec
+                 m25p10-nonjedec
+                 m25p20-nonjedec
+                 m25p40-nonjedec
+                 m25p80-nonjedec
+                 m25p16-nonjedec
+                 m25p32-nonjedec
+                 m25p64-nonjedec
+                 m25p128-nonjedec
+
 - reg : Chip-Select number
 - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at
 
diff --git a/Documentation/devicetree/bindings/mtd/mtk-quadspi.txt b/Documentation/devicetree/bindings/mtd/mtk-quadspi.txt
new file mode 100644 (file)
index 0000000..fb314f0
--- /dev/null
@@ -0,0 +1,41 @@
+* Serial NOR flash controller for MTK MT81xx (and similar)
+
+Required properties:
+- compatible:    should be "mediatek,mt8173-nor";
+- reg:                   physical base address and length of the controller's register
+- clocks:        the phandle of the clocks needed by the nor controller
+- clock-names:           the names of the clocks
+                 the clocks should be named "spi" and "sf". "spi" is used for spi bus,
+                 and "sf" is used for controller, these are the clocks witch
+                 hardware needs to enabling nor flash and nor flash controller.
+                 See Documentation/devicetree/bindings/clock/clock-bindings.txt for details.
+- #address-cells: should be <1>
+- #size-cells:   should be <0>
+
+The SPI flash must be a child of the nor_flash node and must have a
+compatible property. Also see jedec,spi-nor.txt.
+
+Required properties:
+- compatible:    May include a device-specific string consisting of the manufacturer
+                 and name of the chip. Must also include "jedec,spi-nor" for any
+                 SPI NOR flash that can be identified by the JEDEC READ ID opcode (0x9F).
+- reg :                  Chip-Select number
+
+Example:
+
+nor_flash: spi@1100d000 {
+       compatible = "mediatek,mt8173-nor";
+       reg = <0 0x1100d000 0 0xe0>;
+       clocks = <&pericfg CLK_PERI_SPI>,
+                <&topckgen CLK_TOP_SPINFI_IFR_SEL>;
+       clock-names = "spi", "sf";
+       #address-cells = <1>;
+       #size-cells = <0>;
+       status = "disabled";
+
+       flash@0 {
+               compatible = "jedec,spi-nor";
+               reg = <0>;
+       };
+};
+
index 1c63e40..81a224d 100644 (file)
@@ -32,6 +32,8 @@ Optional properties:
   partition should only be mounted read-only. This is usually used for flash
   partitions containing early-boot firmware images or data which should not be
   clobbered.
+- lock : Do not unlock the partition at initialization time (not supported on
+  all devices)
 
 Examples:
 
index e129b24..f8c3284 100644 (file)
@@ -107,7 +107,7 @@ for (i = 0; i < 256; i++)
     if (i & 0x01)
        rp1 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp1;
     else
-       rp0 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp1;
+       rp0 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp0;
     if (i & 0x02)
        rp3 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp3;
     else
@@ -127,7 +127,7 @@ for (i = 0; i < 256; i++)
     if (i & 0x20)
       rp11 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp11;
     else
-    rp10 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp10;
+      rp10 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp10;
     if (i & 0x40)
       rp13 = bit7 ^ bit6 ^ bit5 ^ bit4 ^ bit3 ^ bit2 ^ bit1 ^ bit0 ^ rp13;
     else
@@ -158,7 +158,7 @@ the values in any order. So instead of calculating all the bits
 individually, let us try to rearrange things.
 For the column parity this is easy. We can just xor the bytes and in the
 end filter out the relevant bits. This is pretty nice as it will bring
-all cp calculation out of the if loop.
+all cp calculation out of the for loop.
 
 Similarly we can first xor the bytes for the various rows.
 This leads to:
@@ -271,11 +271,11 @@ to write our code in such a way that we process data in 32 bit chunks.
 Of course this means some modification as the row parity is byte by
 byte. A quick analysis:
 for the column parity we use the par variable. When extending to 32 bits
-we can in the end easily calculate p0 and p1 from it.
+we can in the end easily calculate rp0 and rp1 from it.
 (because par now consists of 4 bytes, contributing to rp1, rp0, rp1, rp0
-respectively)
+respectively, from MSB to LSB)
 also rp2 and rp3 can be easily retrieved from par as rp3 covers the
-first two bytes and rp2 the last two bytes.
+first two MSBs and rp2 covers the last two LSBs.
 
 Note that of course now the loop is executed only 64 times (256/4).
 And note that care must taken wrt byte ordering. The way bytes are
@@ -387,11 +387,11 @@ Analysis 2
 
 The code (of course) works, and hurray: we are a little bit faster than
 the linux driver code (about 15%). But wait, don't cheer too quickly.
-THere is more to be gained.
+There is more to be gained.
 If we look at e.g. rp14 and rp15 we see that we either xor our data with
 rp14 or with rp15. However we also have par which goes over all data.
 This means there is no need to calculate rp14 as it can be calculated from
-rp15 through rp14 = par ^ rp15;
+rp15 through rp14 = par ^ rp15, because par = rp14 ^ rp15;
 (or if desired we can avoid calculating rp15 and calculate it from
 rp14).  That is why some places refer to inverse parity.
 Of course the same thing holds for rp4/5, rp6/7, rp8/9, rp10/11 and rp12/13.
@@ -419,12 +419,12 @@ with
         if (i & 0x20) rp15 ^= cur;
 
         and outside the loop added:
-    rp4  = par ^ rp5;
-    rp6  = par ^ rp7;
-    rp8  = par ^ rp9;
-    rp10  = par ^ rp11;
-    rp12  = par ^ rp13;
-    rp14  = par ^ rp15;
+        rp4  = par ^ rp5;
+        rp6  = par ^ rp7;
+        rp8  = par ^ rp9;
+        rp10  = par ^ rp11;
+        rp12  = par ^ rp13;
+        rp14  = par ^ rp15;
 
 And after that the code takes about 30% more time, although the number of
 statements is reduced. This is also reflected in the assembly code.
@@ -524,12 +524,12 @@ THe code within the for loop was changed to:
 
         cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur;
         cur = *bp++; tmppar ^= cur; rp6 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp4 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp10 ^= tmppar;
+        cur = *bp++; tmppar ^= cur; rp4 ^= cur;
+        cur = *bp++; tmppar ^= cur; rp10 ^= tmppar;
 
-           cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; rp8 ^= cur;
+        cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur; rp8 ^= cur;
         cur = *bp++; tmppar ^= cur; rp6 ^= cur; rp8 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp8 ^= cur;
+        cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp8 ^= cur;
         cur = *bp++; tmppar ^= cur; rp8 ^= cur;
 
         cur = *bp++; tmppar ^= cur; rp4 ^= cur; rp6 ^= cur;
@@ -537,7 +537,7 @@ THe code within the for loop was changed to:
         cur = *bp++; tmppar ^= cur; rp4 ^= cur;
         cur = *bp++; tmppar ^= cur;
 
-           par ^= tmppar;
+        par ^= tmppar;
         if ((i & 0x1) == 0) rp12 ^= tmppar;
         if ((i & 0x2) == 0) rp14 ^= tmppar;
     }
@@ -548,8 +548,8 @@ to rp12 and rp14.
 
 While making the changes I also found that I could exploit that tmppar
 contains the running parity for this iteration. So instead of having:
-rp4 ^= cur; rp6 = cur;
-I removed the rp6 = cur; statement and did rp6 ^= tmppar; on next
+rp4 ^= cur; rp6 ^= cur;
+I removed the rp6 ^= cur; statement and did rp6 ^= tmppar; on next
 statement. A similar change was done for rp8 and rp10
 
 
@@ -593,22 +593,22 @@ The new code now looks like:
 
         cur = *bp++; tmppar ^= cur; rp4_6 ^= cur;
         cur = *bp++; tmppar ^= cur; rp6 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp4 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp10 ^= tmppar;
+        cur = *bp++; tmppar ^= cur; rp4 ^= cur;
+        cur = *bp++; tmppar ^= cur; rp10 ^= tmppar;
 
-           notrp8 = tmppar;
-           cur = *bp++; tmppar ^= cur; rp4_6 ^= cur;
+        notrp8 = tmppar;
+        cur = *bp++; tmppar ^= cur; rp4_6 ^= cur;
         cur = *bp++; tmppar ^= cur; rp6 ^= cur;
-           cur = *bp++; tmppar ^= cur; rp4 ^= cur;
+        cur = *bp++; tmppar ^= cur; rp4 ^= cur;
         cur = *bp++; tmppar ^= cur;
-           rp8 = rp8 ^ tmppar ^ notrp8;
+        rp8 = rp8 ^ tmppar ^ notrp8;
 
         cur = *bp++; tmppar ^= cur; rp4_6 ^= cur;
         cur = *bp++; tmppar ^= cur; rp6 ^= cur;
         cur = *bp++; tmppar ^= cur; rp4 ^= cur;
         cur = *bp++; tmppar ^= cur;
 
-           par ^= tmppar;
+        par ^= tmppar;
         if ((i & 0x1) == 0) rp12 ^= tmppar;
         if ((i & 0x2) == 0) rp14 ^= tmppar;
     }
@@ -700,7 +700,7 @@ Conclusion
 The gain when calculating the ecc is tremendous. Om my development hardware
 a speedup of a factor of 18 for ecc calculation was achieved. On a test on an
 embedded system with a MIPS core a factor 7 was obtained.
-On  a test with a Linksys NSLU2 (ARMv5TE processor) the speedup was a factor
+On a test with a Linksys NSLU2 (ARMv5TE processor) the speedup was a factor
 5 (big endian mode, gcc 4.1.2, -O3)
 For correction not much gain could be obtained (as bitflips are rare). Then
 again there are also much less cycles spent there.
index c490426..b2db791 100644 (file)
@@ -49,7 +49,7 @@
 static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                      unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        static u16 nand_state = SNAPPERCL15_NAND_WPN;
        u16 set;
 
@@ -76,7 +76,7 @@ static void snappercl15_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 
 static int snappercl15_nand_dev_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY);
 }
index 61f4b5d..45b81a2 100644 (file)
@@ -74,7 +74,7 @@ static void __init ts72xx_map_io(void)
 static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
                                  int cmd, unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (ctrl & NAND_CTRL_CHANGE) {
                void __iomem *addr = chip->IO_ADDR_R;
@@ -96,7 +96,7 @@ static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
 
 static int ts72xx_nand_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        void __iomem *addr = chip->IO_ADDR_R;
 
        addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE);
index a213e7b..5c27646 100644 (file)
@@ -131,7 +131,7 @@ static void qong_init_nor_mtd(void)
  */
 static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
 
        if (cmd == NAND_CMD_NONE)
                return;
index e7b8bef..333b0f9 100644 (file)
@@ -76,7 +76,7 @@ static struct mtd_partition ixdp425_partitions[] = {
 static void
 ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int offset = (int)this->priv;
 
        if (ctrl & NAND_CTRL_CHANGE) {
index 4d08353..7684f92 100644 (file)
@@ -22,7 +22,7 @@
 
 void omap1_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long mask;
 
        if (cmd == NAND_CMD_NONE)
index 1b704d3..96cf6b5 100644 (file)
@@ -176,7 +176,7 @@ static void ts78xx_ts_rtc_unload(void)
 static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                        unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        if (ctrl & NAND_CTRL_CHANGE) {
                unsigned char bits;
@@ -200,7 +200,7 @@ static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd)
 static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd,
                        const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        void __iomem *io_base = chip->IO_ADDR_W;
        unsigned long off = ((unsigned long)buf & 3);
        int sz;
@@ -227,7 +227,7 @@ static void ts78xx_ts_nand_write_buf(struct mtd_info *mtd,
 static void ts78xx_ts_nand_read_buf(struct mtd_info *mtd,
                        uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        void __iomem *io_base = chip->IO_ADDR_R;
        unsigned long off = ((unsigned long)buf & 3);
        int sz;
index a727282..7734ec4 100644 (file)
@@ -572,7 +572,7 @@ static inline void balloon3_i2c_init(void) {}
 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
 static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0;
 
        if (ctrl & NAND_CTRL_CHANGE) {
index 9d7072b..38600a7 100644 (file)
@@ -289,7 +289,7 @@ static void nand_cs_off(void)
 static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat,
                                 unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
 
        dsb();
index 83f830d..d787dd1 100644 (file)
@@ -250,7 +250,7 @@ static inline void palmtx_keys_init(void) {}
 static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd,
                                 unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        char __iomem *nandaddr = this->IO_ADDR_W;
 
        if (cmd == NAND_CMD_NONE)
index 88a19fc..c181543 100644 (file)
@@ -404,7 +404,7 @@ static struct mtd_partition bfin_plat_nand_partitions[] = {
 #define BFIN_NAND_PLAT_ALE 1
 static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        if (cmd == NAND_CMD_NONE)
                return;
index 6ab9515..37f8f25 100644 (file)
@@ -267,7 +267,7 @@ static struct mtd_partition bfin_plat_nand_partitions[] = {
 static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                    unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        if (cmd == NAND_CMD_NONE)
                return;
index 7fb5212..db953cf 100644 (file)
@@ -52,7 +52,7 @@ static void crisv32_hwcontrol(struct mtd_info *mtd, int cmd,
 {
        unsigned long flags;
        reg_pio_rw_dout dout;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        local_irq_save(flags);
 
index e032384..22a6467 100644 (file)
@@ -51,7 +51,7 @@ static void crisv32_hwcontrol(struct mtd_info *mtd, int cmd,
 {
        unsigned long flags;
        reg_gio_rw_pa_dout dout;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        local_irq_save(flags);
 
index 8c13675..992442a 100644 (file)
@@ -200,7 +200,7 @@ static struct i2c_board_info db1200_i2c_devs[] __initdata = {
 static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                 unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
 
        ioaddr &= 0xffffff00;
index b580770..d3c087f 100644 (file)
@@ -150,7 +150,7 @@ static void __init db1300_gpio_config(void)
 static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                 unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
 
        ioaddr &= 0xffffff00;
index 5740bcf..b518f02 100644 (file)
@@ -128,7 +128,7 @@ static struct i2c_board_info db1550_i2c_devs[] __initdata = {
 static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                 unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
 
        ioaddr &= 0xffffff00;
index b4b774b..3cd3577 100644 (file)
@@ -180,7 +180,7 @@ static struct platform_device pnx833x_sata_device = {
 static void
 pnx833x_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
 
        if (cmd == NAND_CMD_NONE)
index 9bd7a2d..0966adc 100644 (file)
@@ -148,7 +148,7 @@ static int rb532_dev_ready(struct mtd_info *mtd)
 
 static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned char orbits, nandbits;
 
        if (ctrl & NAND_CTRL_CHANGE) {
index 29b7c0d..8673f91 100644 (file)
@@ -167,7 +167,7 @@ static struct mtd_partition migor_nand_flash_partitions[] = {
 static void migor_nand_flash_cmd_ctl(struct mtd_info *mtd, int cmd,
                                     unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (cmd == NAND_CMD_NONE)
                return;
index a03ad29..42cc953 100644 (file)
@@ -112,7 +112,7 @@ config MTD_CMDLINE_PARTS
 
 config MTD_AFS_PARTS
        tristate "ARM Firmware Suite partition parsing"
-       depends on ARM
+       depends on (ARM || ARM64)
        ---help---
          The ARM Firmware Suite allows the user to divide flash devices into
          multiple 'images'. Each such image has a header containing its name
index 96a33e3..e02dae3 100644 (file)
@@ -34,7 +34,9 @@
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
 
-struct footer_struct {
+#define AFSV1_FOOTER_MAGIC 0xA0FFFF9F
+
+struct footer_v1 {
        u32 image_info_base;    /* Address of first word of ImageFooter  */
        u32 image_start;        /* Start of area reserved by this footer */
        u32 signature;          /* 'Magic' number proves it's a footer   */
@@ -42,7 +44,7 @@ struct footer_struct {
        u32 checksum;           /* Just this structure                   */
 };
 
-struct image_info_struct {
+struct image_info_v1 {
        u32 bootFlags;          /* Boot flags, compression etc.          */
        u32 imageNumber;        /* Unique number, selects for boot etc.  */
        u32 loadAddress;        /* Address program should be loaded to   */
@@ -67,10 +69,10 @@ static u32 word_sum(void *words, int num)
 }
 
 static int
-afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
-               u_int off, u_int mask)
+afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
+                  u_int off, u_int mask)
 {
-       struct footer_struct fs;
+       struct footer_v1 fs;
        u_int ptr = off + mtd->erasesize - sizeof(fs);
        size_t sz;
        int ret;
@@ -85,25 +87,23 @@ afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
                return ret;
        }
 
-       ret = 1;
-
        /*
         * Does it contain the magic number?
         */
-       if (fs.signature != 0xa0ffff9f)
-               ret = 0;
+       if (fs.signature != AFSV1_FOOTER_MAGIC)
+               return 0;
 
        /*
         * Check the checksum.
         */
        if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
-               ret = 0;
+               return 0;
 
        /*
         * Don't touch the SIB.
         */
        if (fs.type == 2)
-               ret = 0;
+               return 0;
 
        *iis_start = fs.image_info_base & mask;
        *img_start = fs.image_start & mask;
@@ -113,20 +113,20 @@ afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
         * be located after the footer structure.
         */
        if (*iis_start >= ptr)
-               ret = 0;
+               return 0;
 
        /*
         * Check the start of this image.  The image
         * data can not be located after this block.
         */
        if (*img_start > off)
-               ret = 0;
+               return 0;
 
-       return ret;
+       return 1;
 }
 
 static int
-afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr)
+afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
 {
        size_t sz;
        int ret, i;
@@ -182,24 +182,23 @@ static int parse_afs_partitions(struct mtd_info *mtd,
         * the strings.
         */
        for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) {
-               struct image_info_struct iis;
+               struct image_info_v1 iis;
                u_int iis_ptr, img_ptr;
 
-               ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask);
-               if (ret < 0)
-                       break;
-               if (ret == 0)
-                       continue;
-
-               ret = afs_read_iis(mtd, &iis, iis_ptr);
+               ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
                if (ret < 0)
                        break;
-               if (ret == 0)
-                       continue;
-
-               sz += sizeof(struct mtd_partition);
-               sz += strlen(iis.name) + 1;
-               idx += 1;
+               if (ret) {
+                       ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
+                       if (ret < 0)
+                               break;
+                       if (ret == 0)
+                               continue;
+
+                       sz += sizeof(struct mtd_partition);
+                       sz += strlen(iis.name) + 1;
+                       idx += 1;
+               }
        }
 
        if (!sz)
@@ -215,18 +214,18 @@ static int parse_afs_partitions(struct mtd_info *mtd,
         * Identify the partitions
         */
        for (idx = off = 0; off < mtd->size; off += mtd->erasesize) {
-               struct image_info_struct iis;
+               struct image_info_v1 iis;
                u_int iis_ptr, img_ptr;
 
                /* Read the footer. */
-               ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask);
+               ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
                if (ret < 0)
                        break;
                if (ret == 0)
                        continue;
 
                /* Read the image info block */
-               ret = afs_read_iis(mtd, &iis, iis_ptr);
+               ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
                if (ret < 0)
                        break;
                if (ret == 0)
@@ -257,25 +256,10 @@ static int parse_afs_partitions(struct mtd_info *mtd,
 }
 
 static struct mtd_part_parser afs_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = parse_afs_partitions,
        .name = "afs",
 };
-
-static int __init afs_parser_init(void)
-{
-       register_mtd_parser(&afs_parser);
-       return 0;
-}
-
-static void __exit afs_parser_exit(void)
-{
-       deregister_mtd_parser(&afs_parser);
-}
-
-module_init(afs_parser_init);
-module_exit(afs_parser_exit);
-
+module_mtd_part_parser(afs_parser);
 
 MODULE_AUTHOR("ARM Ltd");
 MODULE_DESCRIPTION("ARM Firmware Suite partition parser");
index 7c9172a..9203b96 100644 (file)
@@ -132,24 +132,10 @@ static int create_mtd_partitions(struct mtd_info *master,
 }
 
 static struct mtd_part_parser ar7_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = create_mtd_partitions,
        .name = "ar7part",
 };
-
-static int __init ar7_parser_init(void)
-{
-       register_mtd_parser(&ar7_parser);
-       return 0;
-}
-
-static void __exit ar7_parser_exit(void)
-{
-       deregister_mtd_parser(&ar7_parser);
-}
-
-module_init(ar7_parser_init);
-module_exit(ar7_parser_exit);
+module_mtd_part_parser(ar7_parser);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR( "Felix Fietkau <nbd@openwrt.org>, "
index c0720c1..92a6dd1 100644 (file)
@@ -313,24 +313,10 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 };
 
 static struct mtd_part_parser bcm47xxpart_mtd_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = bcm47xxpart_parse,
        .name = "bcm47xxpart",
 };
-
-static int __init bcm47xxpart_init(void)
-{
-       register_mtd_parser(&bcm47xxpart_mtd_parser);
-       return 0;
-}
-
-static void __exit bcm47xxpart_exit(void)
-{
-       deregister_mtd_parser(&bcm47xxpart_mtd_parser);
-}
-
-module_init(bcm47xxpart_init);
-module_exit(bcm47xxpart_exit);
+module_mtd_part_parser(bcm47xxpart_mtd_parser);
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("MTD partitioning for BCM47XX flash memories");
index b2443f7..cf02135 100644 (file)
@@ -214,24 +214,10 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 };
 
 static struct mtd_part_parser bcm63xx_cfe_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = bcm63xx_parse_cfe_partitions,
        .name = "bcm63xxpart",
 };
-
-static int __init bcm63xx_cfe_parser_init(void)
-{
-       register_mtd_parser(&bcm63xx_cfe_parser);
-       return 0;
-}
-
-static void __exit bcm63xx_cfe_parser_exit(void)
-{
-       deregister_mtd_parser(&bcm63xx_cfe_parser);
-}
-
-module_init(bcm63xx_cfe_parser_init);
-module_exit(bcm63xx_cfe_parser_exit);
+module_mtd_part_parser(bcm63xx_cfe_parser);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Daniel Dickinson <openwrt@cshore.neomailbox.net>");
index 54479c4..3b3dabc 100644 (file)
@@ -67,6 +67,10 @@ endchoice
 config MTD_CFI_GEOMETRY
        bool "Specific CFI Flash geometry selection"
        depends on MTD_CFI_ADV_OPTIONS
+       select MTD_MAP_BANK_WIDTH_1 if  !(MTD_MAP_BANK_WIDTH_2 || \
+                MTD_MAP_BANK_WIDTH_4  || MTD_MAP_BANK_WIDTH_8 || \
+                MTD_MAP_BANK_WIDTH_16 || MTD_MAP_BANK_WIDTH_32)
+       select MTD_CFI_I1 if !(MTD_CFI_I2 || MTD_CFI_I4 || MTD_CFI_I8)
        help
          This option does not affect the code directly, but will enable
          some other configuration options which would allow you to reduce
index 08f6298..4204898 100644 (file)
@@ -382,7 +382,6 @@ static int __init mtdpart_setup(char *s)
 __setup("mtdparts=", mtdpart_setup);
 
 static struct mtd_part_parser cmdline_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = parse_cmdline_partitions,
        .name = "cmdlinepart",
 };
index fe9ceb7..c9c3b7f 100644 (file)
@@ -152,22 +152,6 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
        return 0;
 }
 
-static int m25p80_erase(struct spi_nor *nor, loff_t offset)
-{
-       struct m25p *flash = nor->priv;
-
-       dev_dbg(nor->dev, "%dKiB at 0x%08x\n",
-               flash->spi_nor.mtd.erasesize / 1024, (u32)offset);
-
-       /* Set up command buffer. */
-       flash->command[0] = nor->erase_opcode;
-       m25p_addr2cmd(nor, offset, flash->command);
-
-       spi_write(flash->spi, flash->command, m25p_cmdsz(nor));
-
-       return 0;
-}
-
 /*
  * board specific setup should have ensured the SPI clock used here
  * matches what the READ command supports, at least until this driver
@@ -175,12 +159,11 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)
  */
 static int m25p_probe(struct spi_device *spi)
 {
-       struct mtd_part_parser_data     ppdata;
        struct flash_platform_data      *data;
        struct m25p *flash;
        struct spi_nor *nor;
        enum read_mode mode = SPI_NOR_NORMAL;
-       char *flash_name = NULL;
+       char *flash_name;
        int ret;
 
        data = dev_get_platdata(&spi->dev);
@@ -194,12 +177,11 @@ static int m25p_probe(struct spi_device *spi)
        /* install the hooks */
        nor->read = m25p80_read;
        nor->write = m25p80_write;
-       nor->erase = m25p80_erase;
        nor->write_reg = m25p80_write_reg;
        nor->read_reg = m25p80_read_reg;
 
        nor->dev = &spi->dev;
-       nor->flash_node = spi->dev.of_node;
+       spi_nor_set_flash_node(nor, spi->dev.of_node);
        nor->priv = flash;
 
        spi_set_drvdata(spi, flash);
@@ -220,6 +202,8 @@ static int m25p_probe(struct spi_device *spi)
         */
        if (data && data->type)
                flash_name = data->type;
+       else if (!strcmp(spi->modalias, "spi-nor"))
+               flash_name = NULL; /* auto-detect */
        else
                flash_name = spi->modalias;
 
@@ -227,11 +211,8 @@ static int m25p_probe(struct spi_device *spi)
        if (ret)
                return ret;
 
-       ppdata.of_node = spi->dev.of_node;
-
-       return mtd_device_parse_register(&nor->mtd, NULL, &ppdata,
-                       data ? data->parts : NULL,
-                       data ? data->nr_parts : 0);
+       return mtd_device_register(&nor->mtd, data ? data->parts : NULL,
+                                  data ? data->nr_parts : 0);
 }
 
 
@@ -256,15 +237,22 @@ static int m25p_remove(struct spi_device *spi)
  * keep them available as module aliases for existing platforms.
  */
 static const struct spi_device_id m25p_ids[] = {
+       /*
+        * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
+        * hack around the fact that the SPI core does not provide uevent
+        * matching for .of_match_table
+        */
+       {"spi-nor"},
+
        /*
         * Entries not used in DTs that should be safe to drop after replacing
-        * them with "nor-jedec" in platform data.
+        * them with "spi-nor" in platform data.
         */
        {"s25sl064a"},  {"w25x16"},     {"m25p10"},     {"m25px64"},
 
        /*
-        * Entries that were used in DTs without "nor-jedec" fallback and should
-        * be kept for backward compatibility.
+        * Entries that were used in DTs without "jedec,spi-nor" fallback and
+        * should be kept for backward compatibility.
         */
        {"at25df321a"}, {"at25df641"},  {"at26df081a"},
        {"mr25h256"},
index e4a8871..f9e9bd1 100644 (file)
@@ -624,7 +624,6 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages,
 {
        struct dataflash                *priv;
        struct mtd_info                 *device;
-       struct mtd_part_parser_data     ppdata;
        struct flash_platform_data      *pdata = dev_get_platdata(&spi->dev);
        char                            *otp_tag = "";
        int                             err = 0;
@@ -656,6 +655,7 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages,
        device->priv = priv;
 
        device->dev.parent = &spi->dev;
+       mtd_set_of_node(device, spi->dev.of_node);
 
        if (revision >= 'c')
                otp_tag = otp_setup(device, revision);
@@ -665,8 +665,7 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages,
                        pagesize, otp_tag);
        spi_set_drvdata(spi, priv);
 
-       ppdata.of_node = spi->dev.of_node;
-       err = mtd_device_parse_register(device, NULL, &ppdata,
+       err = mtd_device_register(device,
                        pdata ? pdata->parts : NULL,
                        pdata ? pdata->nr_parts : 0);
 
index 64c7458..dd50698 100644 (file)
@@ -810,7 +810,6 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
                                 u32 bank, struct device_node *np)
 {
        struct spear_smi *dev = platform_get_drvdata(pdev);
-       struct mtd_part_parser_data ppdata = {};
        struct spear_smi_flash_info *flash_info;
        struct spear_smi_plat_data *pdata;
        struct spear_snor_flash *flash;
@@ -855,6 +854,7 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
                flash->mtd.name = flash_devices[flash_index].name;
 
        flash->mtd.dev.parent = &pdev->dev;
+       mtd_set_of_node(&flash->mtd, np);
        flash->mtd.type = MTD_NORFLASH;
        flash->mtd.writesize = 1;
        flash->mtd.flags = MTD_CAP_NORFLASH;
@@ -881,10 +881,8 @@ static int spear_smi_setup_banks(struct platform_device *pdev,
                count = flash_info->nr_partitions;
        }
 #endif
-       ppdata.of_node = np;
 
-       ret = mtd_device_parse_register(&flash->mtd, NULL, &ppdata, parts,
-                                       count);
+       ret = mtd_device_register(&flash->mtd, parts, count);
        if (ret) {
                dev_err(&dev->pdev->dev, "Err MTD partition=%d\n", ret);
                return ret;
index 3060025..5454b41 100644 (file)
@@ -2025,7 +2025,6 @@ boot_device_fail:
 static int stfsm_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
-       struct mtd_part_parser_data ppdata;
        struct flash_info *info;
        struct resource *res;
        struct stfsm *fsm;
@@ -2035,7 +2034,6 @@ static int stfsm_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "No DT found\n");
                return -EINVAL;
        }
-       ppdata.of_node = np;
 
        fsm = devm_kzalloc(&pdev->dev, sizeof(*fsm), GFP_KERNEL);
        if (!fsm)
@@ -2106,6 +2104,7 @@ static int stfsm_probe(struct platform_device *pdev)
 
        fsm->mtd.name           = info->name;
        fsm->mtd.dev.parent     = &pdev->dev;
+       mtd_set_of_node(&fsm->mtd, np);
        fsm->mtd.type           = MTD_NORFLASH;
        fsm->mtd.writesize      = 4;
        fsm->mtd.writebufsize   = fsm->mtd.writesize;
@@ -2124,7 +2123,7 @@ static int stfsm_probe(struct platform_device *pdev)
                (long long)fsm->mtd.size, (long long)(fsm->mtd.size >> 20),
                fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10));
 
-       return mtd_device_parse_register(&fsm->mtd, NULL, &ppdata, NULL, 0);
+       return mtd_device_register(&fsm->mtd, NULL, 0);
 }
 
 static int stfsm_remove(struct platform_device *pdev)
index 9385205..c8febb3 100644 (file)
@@ -110,7 +110,6 @@ ltq_copy_to(struct map_info *map, unsigned long to,
 static int
 ltq_mtd_probe(struct platform_device *pdev)
 {
-       struct mtd_part_parser_data ppdata;
        struct ltq_mtd *ltq_mtd;
        struct cfi_private *cfi;
        int err;
@@ -161,13 +160,13 @@ ltq_mtd_probe(struct platform_device *pdev)
        }
 
        ltq_mtd->mtd->dev.parent = &pdev->dev;
+       mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
 
        cfi = ltq_mtd->map->fldrv_priv;
        cfi->addr_unlock1 ^= 1;
        cfi->addr_unlock2 ^= 1;
 
-       ppdata.of_node = pdev->dev.of_node;
-       err = mtd_device_parse_register(ltq_mtd->mtd, NULL, &ppdata, NULL, 0);
+       err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
        if (err) {
                dev_err(&pdev->dev, "failed to add partitions\n");
                goto err_destroy;
index e46b4e9..70c4531 100644 (file)
@@ -166,7 +166,6 @@ static int of_flash_probe(struct platform_device *dev)
        int reg_tuple_size;
        struct mtd_info **mtd_list = NULL;
        resource_size_t res_size;
-       struct mtd_part_parser_data ppdata;
        bool map_indirect;
        const char *mtd_name = NULL;
 
@@ -310,13 +309,14 @@ static int of_flash_probe(struct platform_device *dev)
        if (err)
                goto err_out;
 
-       ppdata.of_node = dp;
+       info->cmtd->dev.parent = &dev->dev;
+       mtd_set_of_node(info->cmtd, dp);
        part_probe_types = of_get_probes(dp);
        if (!part_probe_types) {
                err = -ENOMEM;
                goto err_out;
        }
-       mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
+       mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
                        NULL, 0);
        of_free_probes(part_probe_types);
 
index 95c13b2..62f83b0 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/err.h>
 #include <linux/ioctl.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/proc_fs.h>
 #include <linux/idr.h>
 #include <linux/backing-dev.h>
@@ -454,6 +455,7 @@ int add_mtd_device(struct mtd_info *mtd)
        mtd->dev.devt = MTD_DEVT(i);
        dev_set_name(&mtd->dev, "mtd%d", i);
        dev_set_drvdata(&mtd->dev, mtd);
+       of_node_get(mtd_get_of_node(mtd));
        error = device_register(&mtd->dev);
        if (error)
                goto fail_added;
@@ -476,6 +478,7 @@ int add_mtd_device(struct mtd_info *mtd)
        return 0;
 
 fail_added:
+       of_node_put(mtd_get_of_node(mtd));
        idr_remove(&mtd_idr, i);
 fail_locked:
        mutex_unlock(&mtd_table_mutex);
@@ -517,6 +520,7 @@ int del_mtd_device(struct mtd_info *mtd)
                device_unregister(&mtd->dev);
 
                idr_remove(&mtd_idr, mtd->index);
+               of_node_put(mtd_get_of_node(mtd));
 
                module_put(THIS_MODULE);
                ret = 0;
index f8ba153..c32b127 100644 (file)
@@ -48,9 +48,12 @@ struct mtd_part {
 
 /*
  * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
- * the pointer to that structure with this macro.
+ * the pointer to that structure.
  */
-#define PART(x)  ((struct mtd_part *)(x))
+static inline struct mtd_part *mtd_to_part(const struct mtd_info *mtd)
+{
+       return container_of(mtd, struct mtd_part, mtd);
+}
 
 
 /*
@@ -61,7 +64,7 @@ struct mtd_part {
 static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
                size_t *retlen, u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        struct mtd_ecc_stats stats;
        int res;
 
@@ -80,7 +83,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
 static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
                size_t *retlen, void **virt, resource_size_t *phys)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
 
        return part->master->_point(part->master, from + part->offset, len,
                                    retlen, virt, phys);
@@ -88,7 +91,7 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
 
 static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
 
        return part->master->_unpoint(part->master, from + part->offset, len);
 }
@@ -98,7 +101,7 @@ static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
                                            unsigned long offset,
                                            unsigned long flags)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
 
        offset += part->offset;
        return part->master->_get_unmapped_area(part->master, len, offset,
@@ -108,7 +111,7 @@ static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
 static int part_read_oob(struct mtd_info *mtd, loff_t from,
                struct mtd_oob_ops *ops)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        int res;
 
        if (from >= mtd->size)
@@ -146,7 +149,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
 static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_read_user_prot_reg(part->master, from, len,
                                                 retlen, buf);
 }
@@ -154,7 +157,7 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
 static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
                                   size_t *retlen, struct otp_info *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_get_user_prot_info(part->master, len, retlen,
                                                 buf);
 }
@@ -162,7 +165,7 @@ static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_read_fact_prot_reg(part->master, from, len,
                                                 retlen, buf);
 }
@@ -170,7 +173,7 @@ static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
 static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
                                   size_t *retlen, struct otp_info *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_get_fact_prot_info(part->master, len, retlen,
                                                 buf);
 }
@@ -178,7 +181,7 @@ static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
 static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
                size_t *retlen, const u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_write(part->master, to + part->offset, len,
                                    retlen, buf);
 }
@@ -186,7 +189,7 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
                size_t *retlen, const u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_panic_write(part->master, to + part->offset, len,
                                          retlen, buf);
 }
@@ -194,7 +197,7 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 static int part_write_oob(struct mtd_info *mtd, loff_t to,
                struct mtd_oob_ops *ops)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
 
        if (to >= mtd->size)
                return -EINVAL;
@@ -206,7 +209,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
 static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_write_user_prot_reg(part->master, from, len,
                                                  retlen, buf);
 }
@@ -214,21 +217,21 @@ static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
 static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_lock_user_prot_reg(part->master, from, len);
 }
 
 static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
                unsigned long count, loff_t to, size_t *retlen)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_writev(part->master, vecs, count,
                                     to + part->offset, retlen);
 }
 
 static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        int ret;
 
        instr->addr += part->offset;
@@ -244,7 +247,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
 void mtd_erase_callback(struct erase_info *instr)
 {
        if (instr->mtd->_erase == part_erase) {
-               struct mtd_part *part = PART(instr->mtd);
+               struct mtd_part *part = mtd_to_part(instr->mtd);
 
                if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
                        instr->fail_addr -= part->offset;
@@ -257,57 +260,57 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
 
 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_lock(part->master, ofs + part->offset, len);
 }
 
 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_unlock(part->master, ofs + part->offset, len);
 }
 
 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_is_locked(part->master, ofs + part->offset, len);
 }
 
 static void part_sync(struct mtd_info *mtd)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        part->master->_sync(part->master);
 }
 
 static int part_suspend(struct mtd_info *mtd)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return part->master->_suspend(part->master);
 }
 
 static void part_resume(struct mtd_info *mtd)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        part->master->_resume(part->master);
 }
 
 static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        ofs += part->offset;
        return part->master->_block_isreserved(part->master, ofs);
 }
 
 static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        ofs += part->offset;
        return part->master->_block_isbad(part->master, ofs);
 }
 
 static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        int res;
 
        ofs += part->offset;
@@ -558,7 +561,7 @@ static ssize_t mtd_partition_offset_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
        struct mtd_info *mtd = dev_get_drvdata(dev);
-       struct mtd_part *part = PART(mtd);
+       struct mtd_part *part = mtd_to_part(mtd);
        return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset);
 }
 
@@ -596,11 +599,10 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
        if (length <= 0)
                return -EINVAL;
 
+       memset(&part, 0, sizeof(part));
        part.name = name;
        part.size = length;
        part.offset = offset;
-       part.mask_flags = 0;
-       part.ecclayout = NULL;
 
        new = allocate_partition(master, &part, -1, offset);
        if (IS_ERR(new))
@@ -704,13 +706,17 @@ static struct mtd_part_parser *get_partition_parser(const char *name)
 
 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
 
-void register_mtd_parser(struct mtd_part_parser *p)
+int __register_mtd_parser(struct mtd_part_parser *p, struct module *owner)
 {
+       p->owner = owner;
+
        spin_lock(&part_parser_lock);
        list_add(&p->list, &part_parsers);
        spin_unlock(&part_parser_lock);
+
+       return 0;
 }
-EXPORT_SYMBOL_GPL(register_mtd_parser);
+EXPORT_SYMBOL_GPL(__register_mtd_parser);
 
 void deregister_mtd_parser(struct mtd_part_parser *p)
 {
@@ -811,6 +817,6 @@ uint64_t mtd_get_device_size(const struct mtd_info *mtd)
        if (!mtd_is_partition(mtd))
                return mtd->size;
 
-       return PART(mtd)->master->size;
+       return mtd_to_part(mtd)->master->size;
 }
 EXPORT_SYMBOL_GPL(mtd_get_device_size);
index 842f8fe..b2b49c4 100644 (file)
@@ -64,7 +64,7 @@ static struct mtd_partition partition_info[] = {
 
 static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *io_base = this->priv;
 
        writew(0, io_base + OMAP_MPUIO_IO_CNTL);
@@ -77,7 +77,7 @@ static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte)
 static u_char ams_delta_read_byte(struct mtd_info *mtd)
 {
        u_char res;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *io_base = this->priv;
 
        gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE, 0);
index 583cdd9..edd191a 100644 (file)
@@ -128,7 +128,7 @@ struct atmel_nand_host {
 
        struct atmel_nfc        *nfc;
 
-       struct atmel_nand_caps  *caps;
+       const struct atmel_nand_caps    *caps;
        bool                    has_pmecc;
        u8                      pmecc_corr_cap;
        u16                     pmecc_sector_size;
@@ -182,7 +182,7 @@ static void atmel_nand_disable(struct atmel_nand_host *host)
  */
 static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        if (ctrl & NAND_CTRL_CHANGE) {
@@ -205,7 +205,7 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
  */
 static int atmel_nand_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        return gpio_get_value(host->board.rdy_pin) ^
@@ -215,7 +215,7 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 /* Set up for hardware ready pin and enable pin. */
 static int atmel_nand_set_enable_ready_pins(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
        int res = 0;
 
@@ -267,7 +267,7 @@ static int atmel_nand_set_enable_ready_pins(struct mtd_info *mtd)
  */
 static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
 {
-       struct nand_chip        *nand_chip = mtd->priv;
+       struct nand_chip        *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) {
@@ -280,7 +280,7 @@ static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
 
 static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
 {
-       struct nand_chip        *nand_chip = mtd->priv;
+       struct nand_chip        *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        if (host->nfc && host->nfc->use_nfc_sram && host->nfc->data_in_sram) {
@@ -293,14 +293,14 @@ static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
 
 static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len)
 {
-       struct nand_chip        *nand_chip = mtd->priv;
+       struct nand_chip        *nand_chip = mtd_to_nand(mtd);
 
        __raw_writesb(nand_chip->IO_ADDR_W, buf, len);
 }
 
 static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
 {
-       struct nand_chip        *nand_chip = mtd->priv;
+       struct nand_chip        *nand_chip = mtd_to_nand(mtd);
 
        __raw_writesw(nand_chip->IO_ADDR_W, buf, len / 2);
 }
@@ -352,7 +352,7 @@ static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len,
        dma_addr_t dma_src_addr, dma_dst_addr, phys_addr;
        struct dma_async_tx_descriptor *tx = NULL;
        dma_cookie_t cookie;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
        void *p = buf;
        int err = -EIO;
@@ -425,7 +425,7 @@ err_buf:
 
 static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
 
        if (use_dma && len > mtd->oobsize)
@@ -441,7 +441,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 
 static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
 
        if (use_dma && len > mtd->oobsize)
@@ -533,7 +533,7 @@ static int pmecc_data_alloc(struct atmel_nand_host *host)
 
 static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        int i;
        uint32_t value;
@@ -550,7 +550,7 @@ static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector)
 
 static void pmecc_substitute(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        int16_t __iomem *alpha_to = host->pmecc_alpha_to;
        int16_t __iomem *index_of = host->pmecc_index_of;
@@ -592,7 +592,7 @@ static void pmecc_substitute(struct mtd_info *mtd)
 
 static void pmecc_get_sigma(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        int16_t *lmu = host->pmecc_lmu;
@@ -750,7 +750,7 @@ static void pmecc_get_sigma(struct mtd_info *mtd)
 
 static int pmecc_err_location(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        unsigned long end_time;
        const int cap = host->pmecc_corr_cap;
@@ -802,7 +802,7 @@ static int pmecc_err_location(struct mtd_info *mtd)
 static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
                int sector_num, int extra_bytes, int err_nbr)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        int i = 0;
        int byte_pos, bit_pos, sector_size, pos;
@@ -848,7 +848,7 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
 static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
        u8 *ecc)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        int i, err_nbr;
        uint8_t *buf_pos;
@@ -992,7 +992,7 @@ static int atmel_nand_pmecc_write_page(struct mtd_info *mtd,
 
 static void atmel_pmecc_core_init(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        uint32_t val = 0;
        struct nand_ecclayout *ecc_layout;
@@ -1308,7 +1308,7 @@ err:
 static int atmel_nand_calculate(struct mtd_info *mtd,
                const u_char *dat, unsigned char *ecc_code)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        unsigned int ecc_value;
 
@@ -1412,7 +1412,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
 static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
                u_char *read_ecc, u_char *isnull)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
        unsigned int ecc_status;
        unsigned int ecc_word, ecc_bit;
@@ -1478,7 +1478,7 @@ static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
  */
 static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        if (host->board.need_reset_workaround)
@@ -1771,7 +1771,7 @@ static int nfc_send_command(struct atmel_nand_host *host,
 static int nfc_device_ready(struct mtd_info *mtd)
 {
        u32 status, mask;
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        status = nfc_read_status(host);
@@ -1787,7 +1787,7 @@ static int nfc_device_ready(struct mtd_info *mtd)
 
 static void nfc_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_chip->priv;
 
        if (chip == -1)
@@ -1799,7 +1799,7 @@ static void nfc_select_chip(struct mtd_info *mtd, int chip)
 static int nfc_make_addr(struct mtd_info *mtd, int command, int column,
                int page_addr, unsigned int *addr1234, unsigned int *cycle0)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        int acycle = 0;
        unsigned char addr_bytes[8];
@@ -1839,7 +1839,7 @@ static int nfc_make_addr(struct mtd_info *mtd, int command, int column,
 static void nfc_nand_command(struct mtd_info *mtd, unsigned int command,
                                int column, int page_addr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
        unsigned long timeout;
        unsigned int nfc_addr_cmd = 0;
@@ -2026,7 +2026,7 @@ static int nfc_sram_write_page(struct mtd_info *mtd, struct nand_chip *chip,
 
 static int nfc_sram_init(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = chip->priv;
        int res = 0;
 
@@ -2093,7 +2093,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
        struct mtd_info *mtd;
        struct nand_chip *nand_chip;
        struct resource *mem;
-       struct mtd_part_parser_data ppdata = {};
        int res, irq;
 
        /* Allocate memory for the device structure (and zero it) */
@@ -2117,6 +2116,7 @@ static int atmel_nand_probe(struct platform_device *pdev)
        nand_chip = &host->nand_chip;
        host->dev = &pdev->dev;
        if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+               nand_set_flash_node(nand_chip, pdev->dev.of_node);
                /* Only when CONFIG_OF is enabled of_node can be parsed */
                res = atmel_of_init_port(host, pdev->dev.of_node);
                if (res)
@@ -2259,9 +2259,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
        }
 
        mtd->name = "atmel_nand";
-       ppdata.of_node = pdev->dev.of_node;
-       res = mtd_device_parse_register(mtd, NULL, &ppdata,
-                       host->board.parts, host->board.num_parts);
+       res = mtd_device_register(mtd, host->board.parts,
+                                 host->board.num_parts);
        if (!res)
                return res;
 
@@ -2304,11 +2303,11 @@ static int atmel_nand_remove(struct platform_device *pdev)
        return 0;
 }
 
-static struct atmel_nand_caps at91rm9200_caps = {
+static const struct atmel_nand_caps at91rm9200_caps = {
        .pmecc_correct_erase_page = false,
 };
 
-static struct atmel_nand_caps sama5d4_caps = {
+static const struct atmel_nand_caps sama5d4_caps = {
        .pmecc_correct_erase_page = true,
 };
 
index 08a130f..73fceb8 100644 (file)
@@ -39,7 +39,7 @@ struct au1550nd_ctx {
  */
 static u_char au_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u_char ret = readb(this->IO_ADDR_R);
        wmb(); /* drain writebuffer */
        return ret;
@@ -54,7 +54,7 @@ static u_char au_read_byte(struct mtd_info *mtd)
  */
 static void au_write_byte(struct mtd_info *mtd, u_char byte)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        writeb(byte, this->IO_ADDR_W);
        wmb(); /* drain writebuffer */
 }
@@ -67,7 +67,7 @@ static void au_write_byte(struct mtd_info *mtd, u_char byte)
  */
 static u_char au_read_byte16(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R));
        wmb(); /* drain writebuffer */
        return ret;
@@ -82,7 +82,7 @@ static u_char au_read_byte16(struct mtd_info *mtd)
  */
 static void au_write_byte16(struct mtd_info *mtd, u_char byte)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        writew(le16_to_cpu((u16) byte), this->IO_ADDR_W);
        wmb(); /* drain writebuffer */
 }
@@ -95,7 +95,7 @@ static void au_write_byte16(struct mtd_info *mtd, u_char byte)
  */
 static u16 au_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u16 ret = readw(this->IO_ADDR_R);
        wmb(); /* drain writebuffer */
        return ret;
@@ -112,7 +112,7 @@ static u16 au_read_word(struct mtd_info *mtd)
 static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        for (i = 0; i < len; i++) {
                writeb(buf[i], this->IO_ADDR_W);
@@ -131,7 +131,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        for (i = 0; i < len; i++) {
                buf[i] = readb(this->IO_ADDR_R);
@@ -150,7 +150,7 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
        len >>= 1;
 
@@ -172,7 +172,7 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
 static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
        len >>= 1;
 
@@ -198,7 +198,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
 static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
 {
        struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        switch (cmd) {
 
@@ -268,7 +268,7 @@ static void au1550_select_chip(struct mtd_info *mtd, int chip)
 static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
 {
        struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int ce_override = 0, i;
        unsigned long flags = 0;
 
index 592befc..e5b2e48 100644 (file)
@@ -89,7 +89,7 @@ static int bcm47xxnflash_ops_bcm4706_poll(struct bcma_drv_cc *cc)
 static void bcm47xxnflash_ops_bcm4706_read(struct mtd_info *mtd, uint8_t *buf,
                                           int len)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
 
        u32 ctlcode;
@@ -139,7 +139,7 @@ static void bcm47xxnflash_ops_bcm4706_read(struct mtd_info *mtd, uint8_t *buf,
 static void bcm47xxnflash_ops_bcm4706_write(struct mtd_info *mtd,
                                            const uint8_t *buf, int len)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
        struct bcma_drv_cc *cc = b47n->cc;
 
@@ -173,7 +173,7 @@ static void bcm47xxnflash_ops_bcm4706_write(struct mtd_info *mtd,
 static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                               unsigned int ctrl)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
        u32 code = 0;
 
@@ -199,7 +199,7 @@ static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd,
 
 static int bcm47xxnflash_ops_bcm4706_dev_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
 
        return !!(bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_CTL) & NCTL_READY);
@@ -216,7 +216,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd,
                                              unsigned command, int column,
                                              int page_addr)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
        struct bcma_drv_cc *cc = b47n->cc;
        u32 ctlcode;
@@ -312,7 +312,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd,
 
 static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
        struct bcma_drv_cc *cc = b47n->cc;
        u32 tmp = 0;
@@ -341,7 +341,7 @@ static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct mtd_info *mtd)
 static void bcm47xxnflash_ops_bcm4706_read_buf(struct mtd_info *mtd,
                                               uint8_t *buf, int len)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
 
        switch (b47n->curr_command) {
@@ -357,7 +357,7 @@ static void bcm47xxnflash_ops_bcm4706_read_buf(struct mtd_info *mtd,
 static void bcm47xxnflash_ops_bcm4706_write_buf(struct mtd_info *mtd,
                                                const uint8_t *buf, int len)
 {
-       struct nand_chip *nand_chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct bcm47xxnflash *b47n = (struct bcm47xxnflash *)nand_chip->priv;
 
        switch (b47n->curr_command) {
index 61bd216..d9da5ed 100644 (file)
@@ -304,7 +304,7 @@ static int bf5xx_nand_correct_data_256(struct mtd_info *mtd, u_char *dat,
 static int bf5xx_nand_correct_data(struct mtd_info *mtd, u_char *dat,
                                        u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret;
 
        ret = bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc);
@@ -329,7 +329,7 @@ static int bf5xx_nand_calculate_ecc(struct mtd_info *mtd,
                const u_char *dat, u_char *ecc_code)
 {
        struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 ecc0, ecc1;
        u32 code[2];
        u8 *p;
@@ -466,7 +466,7 @@ static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
                                uint8_t *buf, int is_read)
 {
        struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned short val;
 
        dev_dbg(info->device, " mtd->%p, buf->%p, is_read %d\n",
@@ -532,7 +532,7 @@ static void bf5xx_nand_dma_read_buf(struct mtd_info *mtd,
                                        uint8_t *buf, int len)
 {
        struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        dev_dbg(info->device, "mtd->%p, buf->%p, int %d\n", mtd, buf, len);
 
@@ -546,7 +546,7 @@ static void bf5xx_nand_dma_write_buf(struct mtd_info *mtd,
                                const uint8_t *buf, int len)
 {
        struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        dev_dbg(info->device, "mtd->%p, buf->%p, len %d\n", mtd, buf, len);
 
@@ -685,7 +685,7 @@ static int bf5xx_nand_remove(struct platform_device *pdev)
 
 static int bf5xx_nand_scan(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret;
 
        ret = nand_scan_ident(mtd, 1, NULL);
index 12c6190..190a99a 100644 (file)
@@ -134,7 +134,7 @@ struct brcmnand_controller {
        dma_addr_t              dma_pa;
 
        /* in-memory cache of the FLASH_CACHE, used only for some commands */
-       u32                     flash_cache[FC_WORDS];
+       u8                      flash_cache[FC_BYTES];
 
        /* Controller revision details */
        const u16               *reg_offsets;
@@ -176,7 +176,6 @@ struct brcmnand_cfg {
 
 struct brcmnand_host {
        struct list_head        node;
-       struct device_node      *of_node;
 
        struct nand_chip        chip;
        struct mtd_info         mtd;
@@ -874,7 +873,7 @@ static struct nand_ecclayout *brcmstb_choose_ecc_layout(
 
 static void brcmnand_wp(struct mtd_info *mtd, int wp)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct brcmnand_host *host = chip->priv;
        struct brcmnand_controller *ctrl = host->ctrl;
 
@@ -1040,7 +1039,7 @@ static void brcmnand_cmd_ctrl(struct mtd_info *mtd, int dat,
 
 static int brcmnand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct brcmnand_host *host = chip->priv;
        struct brcmnand_controller *ctrl = host->ctrl;
        unsigned long timeo = msecs_to_jiffies(100);
@@ -1114,7 +1113,7 @@ static int brcmnand_low_level_op(struct brcmnand_host *host,
 static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
                             int column, int page_addr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct brcmnand_host *host = chip->priv;
        struct brcmnand_controller *ctrl = host->ctrl;
        u64 addr = (u64)page_addr << chip->page_shift;
@@ -1188,6 +1187,8 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 
        if (native_cmd == CMD_PARAMETER_READ ||
                        native_cmd == CMD_PARAMETER_CHANGE_COL) {
+               /* Copy flash cache word-wise */
+               u32 *flash_cache = (u32 *)ctrl->flash_cache;
                int i;
 
                brcmnand_soc_data_bus_prepare(ctrl->soc);
@@ -1197,7 +1198,11 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
                 * SECTOR_SIZE_1K may invalidate it
                 */
                for (i = 0; i < FC_WORDS; i++)
-                       ctrl->flash_cache[i] = brcmnand_read_fc(ctrl, i);
+                       /*
+                        * Flash cache is big endian for parameter pages, at
+                        * least on STB SoCs
+                        */
+                       flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
                brcmnand_soc_data_bus_unprepare(ctrl->soc);
 
@@ -1214,7 +1219,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 
 static uint8_t brcmnand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct brcmnand_host *host = chip->priv;
        struct brcmnand_controller *ctrl = host->ctrl;
        uint8_t ret = 0;
@@ -1250,8 +1255,7 @@ static uint8_t brcmnand_read_byte(struct mtd_info *mtd)
                if (host->last_byte > 0 && offs == 0)
                        chip->cmdfunc(mtd, NAND_CMD_RNDOUT, addr, -1);
 
-               ret = ctrl->flash_cache[offs >> 2] >>
-                                       (24 - ((offs & 0x03) << 3));
+               ret = ctrl->flash_cache[offs];
                break;
        case NAND_CMD_GET_FEATURES:
                if (host->last_byte >= ONFI_SUBFEATURE_PARAM_LEN) {
@@ -1282,7 +1286,7 @@ static void brcmnand_write_buf(struct mtd_info *mtd, const uint8_t *buf,
                                   int len)
 {
        int i;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct brcmnand_host *host = chip->priv;
 
        switch (host->last_cmd) {
@@ -1400,6 +1404,8 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
        /* Clear error addresses */
        brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0);
        brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0);
+       brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0);
+       brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0);
 
        brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
                        (host->cs << 16) | ((addr >> 32) & 0xffff));
@@ -1546,16 +1552,6 @@ static int brcmnand_read_oob_raw(struct mtd_info *mtd, struct nand_chip *chip,
        return 0;
 }
 
-static int brcmnand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
-                                uint32_t data_offs, uint32_t readlen,
-                                uint8_t *bufpoi, int page)
-{
-       struct brcmnand_host *host = chip->priv;
-
-       return brcmnand_read(mtd, chip, host->last_addr + data_offs,
-                       readlen >> FC_SHIFT, (u32 *)bufpoi, NULL);
-}
-
 static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
                          u64 addr, const u32 *buf, u8 *oob)
 {
@@ -1816,7 +1812,7 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
 
        memset(cfg, 0, sizeof(*cfg));
 
-       ret = of_property_read_u32(chip->flash_node,
+       ret = of_property_read_u32(nand_get_flash_node(chip),
                                   "brcm,nand-oob-sector-size",
                                   &oob_sector);
        if (ret) {
@@ -1905,16 +1901,14 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
        return 0;
 }
 
-static int brcmnand_init_cs(struct brcmnand_host *host)
+static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
 {
        struct brcmnand_controller *ctrl = host->ctrl;
-       struct device_node *dn = host->of_node;
        struct platform_device *pdev = host->pdev;
        struct mtd_info *mtd;
        struct nand_chip *chip;
        int ret;
        u16 cfg_offs;
-       struct mtd_part_parser_data ppdata = { .of_node = dn };
 
        ret = of_property_read_u32(dn, "reg", &host->cs);
        if (ret) {
@@ -1925,7 +1919,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
        mtd = &host->mtd;
        chip = &host->chip;
 
-       chip->flash_node = dn;
+       nand_set_flash_node(chip, dn);
        chip->priv = host;
        mtd->priv = chip;
        mtd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "brcmnand.%d",
@@ -1945,7 +1939,6 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
 
        chip->ecc.mode = NAND_ECC_HW;
        chip->ecc.read_page = brcmnand_read_page;
-       chip->ecc.read_subpage = brcmnand_read_subpage;
        chip->ecc.write_page = brcmnand_write_page;
        chip->ecc.read_page_raw = brcmnand_read_page_raw;
        chip->ecc.write_page_raw = brcmnand_write_page_raw;
@@ -1993,7 +1986,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
        if (nand_scan_tail(mtd))
                return -ENXIO;
 
-       return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       return mtd_device_register(mtd, NULL, 0);
 }
 
 static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,
@@ -2068,7 +2061,7 @@ static int brcmnand_resume(struct device *dev)
 
        list_for_each_entry(host, &ctrl->host_list, node) {
                struct mtd_info *mtd = &host->mtd;
-               struct nand_chip *chip = mtd->priv;
+               struct nand_chip *chip = mtd_to_nand(mtd);
 
                brcmnand_save_restore_cs_config(host, 1);
 
@@ -2238,15 +2231,18 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
                        struct brcmnand_host *host;
 
                        host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
-                       if (!host)
+                       if (!host) {
+                               of_node_put(child);
                                return -ENOMEM;
+                       }
                        host->pdev = pdev;
                        host->ctrl = ctrl;
-                       host->of_node = child;
 
-                       ret = brcmnand_init_cs(host);
-                       if (ret)
+                       ret = brcmnand_init_cs(host, child);
+                       if (ret) {
+                               devm_kfree(dev, host);
                                continue; /* Try all chip-selects */
+                       }
 
                        list_add_tail(&host->node, &ctrl->host_list);
                }
index 9de78d2..77c92f1 100644 (file)
@@ -101,7 +101,8 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
 
 static int cafe_device_ready(struct mtd_info *mtd)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
        int result = !!(cafe_readl(cafe, NAND_STATUS) & 0x40000000);
        uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
 
@@ -117,7 +118,8 @@ static int cafe_device_ready(struct mtd_info *mtd)
 
 static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
 
        if (usedma)
                memcpy(cafe->dmabuf + cafe->datalen, buf, len);
@@ -132,7 +134,8 @@ static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 
 static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
 
        if (usedma)
                memcpy(buf, cafe->dmabuf + cafe->datalen, len);
@@ -146,7 +149,8 @@ static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 
 static uint8_t cafe_read_byte(struct mtd_info *mtd)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
        uint8_t d;
 
        cafe_read_buf(mtd, &d, 1);
@@ -158,7 +162,8 @@ static uint8_t cafe_read_byte(struct mtd_info *mtd)
 static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
                              int column, int page_addr)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
        int adrbytes = 0;
        uint32_t ctl1;
        uint32_t doneint = 0x80000000;
@@ -313,7 +318,8 @@ static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
 
 static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
 
        cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr);
 
@@ -328,7 +334,8 @@ static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
 static irqreturn_t cafe_nand_interrupt(int irq, void *id)
 {
        struct mtd_info *mtd = id;
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
        uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
        cafe_writel(cafe, irqs & ~0x90000000, NAND_IRQ);
        if (!irqs)
@@ -377,7 +384,7 @@ static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
 static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
                               uint8_t *buf, int oob_required, int page)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct cafe_priv *cafe = chip->priv;
        unsigned int max_bitflips = 0;
 
        cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
@@ -519,7 +526,7 @@ static int cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
                                          const uint8_t *buf, int oob_required,
                                          int page)
 {
-       struct cafe_priv *cafe = mtd->priv;
+       struct cafe_priv *cafe = chip->priv;
 
        chip->write_buf(mtd, buf, mtd->writesize);
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -604,7 +611,8 @@ static int cafe_nand_probe(struct pci_dev *pdev,
        cafe = (void *)(&mtd[1]);
 
        mtd->dev.parent = &pdev->dev;
-       mtd->priv = cafe;
+       mtd->priv = &cafe->nand;
+       cafe->nand.priv = cafe;
 
        cafe->pdev = pdev;
        cafe->mmio = pci_iomap(pdev, 0, 0);
@@ -792,7 +800,8 @@ static int cafe_nand_probe(struct pci_dev *pdev,
 static void cafe_nand_remove(struct pci_dev *pdev)
 {
        struct mtd_info *mtd = pci_get_drvdata(pdev);
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
 
        /* Disable NAND IRQ in global IRQ mask register */
        cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
@@ -819,7 +828,8 @@ static int cafe_nand_resume(struct pci_dev *pdev)
 {
        uint32_t ctrl;
        struct mtd_info *mtd = pci_get_drvdata(pdev);
-       struct cafe_priv *cafe = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct cafe_priv *cafe = chip->priv;
 
        /* Start off by resetting the NAND controller completely */
        cafe_writel(cafe, 1, NAND_RESET);
index 66ec95e..43bded6 100644 (file)
@@ -53,7 +53,7 @@ static struct mtd_partition partition_info[] = {
 
 static u_char cmx270_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        return (readl(this->IO_ADDR_R) >> 16);
 }
@@ -61,7 +61,7 @@ static u_char cmx270_read_byte(struct mtd_info *mtd)
 static void cmx270_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        for (i=0; i<len; i++)
                writel((*buf++ << 16), this->IO_ADDR_W);
@@ -70,7 +70,7 @@ static void cmx270_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 static void cmx270_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        for (i=0; i<len; i++)
                *buf++ = readl(this->IO_ADDR_R) >> 16;
@@ -94,7 +94,7 @@ static void nand_cs_off(void)
 static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
                             unsigned int ctrl)
 {
-       struct nand_chip* this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned int nandaddr = (unsigned int)this->IO_ADDR_W;
 
        dsb();
index aec6045..8904d68 100644 (file)
@@ -97,7 +97,7 @@
 
 static void cs553x_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        while (unlikely(len > 0x800)) {
                memcpy_fromio(buf, this->IO_ADDR_R, 0x800);
@@ -109,7 +109,7 @@ static void cs553x_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 
 static void cs553x_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        while (unlikely(len > 0x800)) {
                memcpy_toio(this->IO_ADDR_R, buf, 0x800);
@@ -121,13 +121,13 @@ static void cs553x_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 
 static unsigned char cs553x_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        return readb(this->IO_ADDR_R);
 }
 
 static void cs553x_write_byte(struct mtd_info *mtd, u_char byte)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i = 100000;
 
        while (i && readb(this->IO_ADDR_R + MM_NAND_STS) & CS_NAND_CTLR_BUSY) {
@@ -140,7 +140,7 @@ static void cs553x_write_byte(struct mtd_info *mtd, u_char byte)
 static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd,
                             unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *mmio_base = this->IO_ADDR_R;
        if (ctrl & NAND_CTRL_CHANGE) {
                unsigned char ctl = (ctrl & ~NAND_CTRL_CHANGE ) ^ 0x01;
@@ -152,7 +152,7 @@ static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd,
 
 static int cs553x_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *mmio_base = this->IO_ADDR_R;
        unsigned char foo = readb(mmio_base + MM_NAND_STS);
 
@@ -161,7 +161,7 @@ static int cs553x_device_ready(struct mtd_info *mtd)
 
 static void cs_enable_hwecc(struct mtd_info *mtd, int mode)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *mmio_base = this->IO_ADDR_R;
 
        writeb(0x07, mmio_base + MM_NAND_ECC_CTL);
@@ -170,7 +170,7 @@ static void cs_enable_hwecc(struct mtd_info *mtd, int mode)
 static int cs_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
 {
        uint32_t ecc;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        void __iomem *mmio_base = this->IO_ADDR_R;
 
        ecc = readl(mmio_base + MM_NAND_STS);
@@ -337,7 +337,7 @@ static void __exit cs553x_cleanup(void)
                if (!mtd)
                        continue;
 
-               this = cs553x_mtd[i]->priv;
+               this = mtd_to_nand(cs553x_mtd[i]);
                mmio_base = this->IO_ADDR_R;
 
                /* Release resources, unregister device */
index c72313d..b5978d5 100644 (file)
@@ -106,7 +106,7 @@ static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd,
 {
        struct davinci_nand_info        *info = to_davinci_nand(mtd);
        uint32_t                        addr = info->current_cs;
-       struct nand_chip                *nand = mtd->priv;
+       struct nand_chip                *nand = mtd_to_nand(mtd);
 
        /* Did the control lines change? */
        if (ctrl & NAND_CTRL_CHANGE) {
@@ -192,7 +192,7 @@ static int nand_davinci_calculate_1bit(struct mtd_info *mtd,
 static int nand_davinci_correct_1bit(struct mtd_info *mtd, u_char *dat,
                                     u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint32_t eccNand = read_ecc[0] | (read_ecc[1] << 8) |
                                          (read_ecc[2] << 16);
        uint32_t eccCalc = calc_ecc[0] | (calc_ecc[1] << 8) |
@@ -447,7 +447,7 @@ correct:
  */
 static void nand_davinci_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0)
                ioread32_rep(chip->IO_ADDR_R, buf, len >> 2);
@@ -460,7 +460,7 @@ static void nand_davinci_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void nand_davinci_write_buf(struct mtd_info *mtd,
                const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0)
                iowrite32_rep(chip->IO_ADDR_R, buf, len >> 2);
@@ -684,6 +684,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
 
        info->mtd.priv          = &info->chip;
        info->mtd.dev.parent    = &pdev->dev;
+       nand_set_flash_node(&info->chip, pdev->dev.of_node);
 
        info->chip.IO_ADDR_R    = vaddr;
        info->chip.IO_ADDR_W    = vaddr;
@@ -839,13 +840,8 @@ syndrome_done:
        if (pdata->parts)
                ret = mtd_device_parse_register(&info->mtd, NULL, NULL,
                                        pdata->parts, pdata->nr_parts);
-       else {
-               struct mtd_part_parser_data     ppdata;
-
-               ppdata.of_node = pdev->dev.of_node;
-               ret = mtd_device_parse_register(&info->mtd, NULL, &ppdata,
-                                               NULL, 0);
-       }
+       else
+               ret = mtd_device_register(&info->mtd, NULL, 0);
        if (ret < 0)
                goto err;
 
index 0802158..5f7bcc8 100644 (file)
@@ -299,7 +299,7 @@ static inline int DoC_WaitReady(struct doc_priv *doc)
 
 static void doc2000_write_byte(struct mtd_info *mtd, u_char datum)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -311,7 +311,7 @@ static void doc2000_write_byte(struct mtd_info *mtd, u_char datum)
 
 static u_char doc2000_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        u_char ret;
@@ -326,7 +326,7 @@ static u_char doc2000_read_byte(struct mtd_info *mtd)
 
 static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -343,7 +343,7 @@ static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 
 static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -358,7 +358,7 @@ static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 
 static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -379,7 +379,7 @@ static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len)
 
 static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        uint16_t ret;
 
@@ -425,7 +425,7 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
 
 static void __init doc2000_count_chips(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        uint16_t mfrid;
        int i;
@@ -461,7 +461,7 @@ static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this)
 
 static void doc2001_write_byte(struct mtd_info *mtd, u_char datum)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -472,7 +472,7 @@ static void doc2001_write_byte(struct mtd_info *mtd, u_char datum)
 
 static u_char doc2001_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -486,7 +486,7 @@ static u_char doc2001_read_byte(struct mtd_info *mtd)
 
 static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -499,7 +499,7 @@ static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 
 static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -516,7 +516,7 @@ static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 
 static u_char doc2001plus_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        u_char ret;
@@ -531,7 +531,7 @@ static u_char doc2001plus_read_byte(struct mtd_info *mtd)
 
 static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -549,7 +549,7 @@ static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int le
 
 static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -580,7 +580,7 @@ static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 
 static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int floor = 0;
@@ -607,7 +607,7 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
 
 static void doc200x_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int floor = 0;
@@ -638,7 +638,7 @@ static void doc200x_select_chip(struct mtd_info *mtd, int chip)
 static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd,
                              unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -661,7 +661,7 @@ static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd,
 
 static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -767,7 +767,7 @@ static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int colu
 
 static int doc200x_dev_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -807,7 +807,7 @@ static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
 
 static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -826,7 +826,7 @@ static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode)
 
 static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -846,7 +846,7 @@ static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode)
 /* This code is only called on write */
 static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsigned char *ecc_code)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        int i;
@@ -907,7 +907,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
                                u_char *read_ecc, u_char *isnull)
 {
        int i, ret = 0;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
        uint8_t calc_ecc[6];
@@ -1007,7 +1007,7 @@ static struct nand_ecclayout doc200x_oobinfo = {
    mh1_page in the DOC private structure. */
 static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const char *id, int findmirror)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        unsigned offs;
        int ret;
@@ -1050,7 +1050,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch
 
 static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        int ret = 0;
        u_char *buf;
@@ -1152,7 +1152,7 @@ static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partitio
 /* This is a stripped-down copy of the code in inftlmount.c */
 static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        int ret = 0;
        u_char *buf;
@@ -1272,7 +1272,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partiti
 static int __init nftl_scan_bbt(struct mtd_info *mtd)
 {
        int ret, numparts;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        struct mtd_partition parts[2];
 
@@ -1307,7 +1307,7 @@ static int __init nftl_scan_bbt(struct mtd_info *mtd)
 static int __init inftl_scan_bbt(struct mtd_info *mtd)
 {
        int ret, numparts;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
        struct mtd_partition parts[5];
 
@@ -1360,7 +1360,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
 
 static inline int __init doc2000_init(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
 
        this->read_byte = doc2000_read_byte;
@@ -1376,7 +1376,7 @@ static inline int __init doc2000_init(struct mtd_info *mtd)
 
 static inline int __init doc2001_init(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
 
        this->read_byte = doc2001_read_byte;
@@ -1406,7 +1406,7 @@ static inline int __init doc2001_init(struct mtd_info *mtd)
 
 static inline int __init doc2001plus_init(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct doc_priv *doc = this->priv;
 
        this->read_byte = doc2001plus_read_byte;
@@ -1523,7 +1523,7 @@ static int __init doc_probe(unsigned long physadr)
        for (mtd = doclist; mtd; mtd = doc->nextdoc) {
                unsigned char oldval;
                unsigned char newval;
-               nand = mtd->priv;
+               nand = mtd_to_nand(mtd);
                doc = nand->priv;
                /* Use the alias resolution register to determine if this is
                   in fact the same DOC aliased to a new address.  If writes
@@ -1643,7 +1643,7 @@ static void release_nanddoc(void)
        struct doc_priv *doc;
 
        for (mtd = doclist; mtd; mtd = nextmtd) {
-               nand = mtd->priv;
+               nand = mtd_to_nand(mtd);
                doc = nand->priv;
 
                nextmtd = doc->nextdoc;
index 408cf69..da93d7f 100644 (file)
@@ -242,7 +242,7 @@ static inline void write_nop(void __iomem *docptr)
 static void docg4_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        uint16_t *p = (uint16_t *) buf;
        len >>= 1;
 
@@ -253,7 +253,7 @@ static void docg4_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void docg4_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        uint16_t *p = (uint16_t *) buf;
        len >>= 1;
 
@@ -318,7 +318,7 @@ static void docg4_select_chip(struct mtd_info *mtd, int chip)
         * Select among multiple cascaded chips ("floors").  Multiple floors are
         * not yet supported, so the only valid non-negative value is 0.
         */
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -337,7 +337,7 @@ static void reset(struct mtd_info *mtd)
 {
        /* full device reset */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -375,7 +375,7 @@ static int correct_data(struct mtd_info *mtd, uint8_t *buf, int page)
         * Up to four bitflips can be corrected.
         */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
        int i, numerrs, errpos[4];
@@ -464,7 +464,7 @@ static int correct_data(struct mtd_info *mtd, uint8_t *buf, int page)
 
 static uint8_t docg4_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
 
        dev_dbg(doc->dev, "%s\n", __func__);
@@ -545,7 +545,7 @@ static int pageprog(struct mtd_info *mtd)
         * internal buffer out to the flash array, or some such.
         */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
        int retval = 0;
@@ -582,7 +582,7 @@ static void sequence_reset(struct mtd_info *mtd)
 {
        /* common starting sequence for all operations */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -599,7 +599,7 @@ static void read_page_prologue(struct mtd_info *mtd, uint32_t docg4_addr)
 {
        /* first step in reading a page */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -626,7 +626,7 @@ static void write_page_prologue(struct mtd_info *mtd, uint32_t docg4_addr)
 {
        /* first step in writing a page */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
 
@@ -691,7 +691,7 @@ static void docg4_command(struct mtd_info *mtd, unsigned command, int column,
 {
        /* handle standard nand commands */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        uint32_t g4_addr = mtd_to_docg4_address(page_addr, column);
 
@@ -874,7 +874,7 @@ static int docg4_read_oob(struct mtd_info *mtd, struct nand_chip *nand,
 
 static int docg4_erase_block(struct mtd_info *mtd, int page)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
        uint16_t g4_page;
@@ -1016,7 +1016,7 @@ static int __init read_factory_bbt(struct mtd_info *mtd)
         * update the memory-based bbt accordingly.
         */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        uint32_t g4_addr = mtd_to_docg4_address(DOCG4_FACTORY_BBT_PAGE, 0);
        uint8_t *buf;
@@ -1089,7 +1089,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs)
 
        int ret, i;
        uint8_t *buf;
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        struct nand_bbt_descr *bbtd = nand->badblock_pattern;
        int page = (int)(ofs >> nand->page_shift);
@@ -1202,7 +1202,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
         * things as well, such as call nand_set_defaults().
         */
 
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
 
        mtd->size = DOCG4_CHIP_SIZE;
@@ -1261,7 +1261,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 
 static int __init read_id_reg(struct mtd_info *mtd)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct docg4_priv *doc = nand->priv;
        void __iomem *docptr = doc->virtadr;
        uint16_t id1, id2;
@@ -1357,7 +1357,7 @@ static int __init probe_docg4(struct platform_device *pdev)
        iounmap(virtadr);
        if (mtd) {
                /* re-declarations avoid compiler warning */
-               struct nand_chip *nand = mtd->priv;
+               struct nand_chip *nand = mtd_to_nand(mtd);
                struct docg4_priv *doc = nand->priv;
                nand_release(mtd); /* deletes partitions and mtd devices */
                free_bch(doc->bch);
index dcb1f7f..ad6d5da 100644 (file)
@@ -144,7 +144,7 @@ static struct nand_bbt_descr bbt_mirror_descr = {
  */
 static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_lbc_ctrl *ctrl = priv->ctrl;
        struct fsl_lbc_regs __iomem *lbc = ctrl->regs;
@@ -195,7 +195,7 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
  */
 static int fsl_elbc_run_command(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_lbc_ctrl *ctrl = priv->ctrl;
        struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
@@ -300,7 +300,7 @@ static void fsl_elbc_do_read(struct nand_chip *chip, int oob)
 static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
                              int column, int page_addr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_lbc_ctrl *ctrl = priv->ctrl;
        struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
@@ -525,7 +525,7 @@ static void fsl_elbc_select_chip(struct mtd_info *mtd, int chip)
  */
 static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
        unsigned int bufsize = mtd->writesize + mtd->oobsize;
@@ -563,7 +563,7 @@ static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  */
 static u8 fsl_elbc_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
 
@@ -580,7 +580,7 @@ static u8 fsl_elbc_read_byte(struct mtd_info *mtd)
  */
 static void fsl_elbc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
        int avail;
@@ -619,7 +619,7 @@ static int fsl_elbc_wait(struct mtd_info *mtd, struct nand_chip *chip)
 
 static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_elbc_mtd *priv = chip->priv;
        struct fsl_lbc_ctrl *ctrl = priv->ctrl;
        struct fsl_lbc_regs __iomem *lbc = ctrl->regs;
@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
        /* Fill in fsl_elbc_mtd structure */
        priv->mtd.priv = chip;
        priv->mtd.dev.parent = priv->dev;
+       nand_set_flash_node(chip, priv->dev->of_node);
 
        /* set timeout to maximum */
        priv->fmr = 15 << FMR_CWTO_SHIFT;
@@ -823,9 +824,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
        int bank;
        struct device *dev;
        struct device_node *node = pdev->dev.of_node;
-       struct mtd_part_parser_data ppdata;
 
-       ppdata.of_node = pdev->dev.of_node;
        if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
                return -ENODEV;
        lbc = fsl_lbc_ctrl_dev->regs;
@@ -911,7 +910,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
 
        /* First look for RedBoot table or partitions on the command
         * line, these take precedence over device tree information */
-       mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata,
+       mtd_device_parse_register(&priv->mtd, part_probe_types, NULL,
                                  NULL, 0);
 
        printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
index 7f4ac8c..3136842 100644 (file)
@@ -230,7 +230,7 @@ static struct nand_bbt_descr bbt_mirror_descr = {
  */
 static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
        struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
@@ -253,7 +253,7 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
 
 static int is_blank(struct mtd_info *mtd, unsigned int bufnum)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2);
        u32 __iomem *mainarea = (u32 __iomem *)addr;
@@ -292,7 +292,7 @@ static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
  */
 static void fsl_ifc_run_command(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
        struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
@@ -409,7 +409,7 @@ static void fsl_ifc_do_read(struct nand_chip *chip,
 /* cmdfunc send commands to the IFC NAND Machine */
 static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
                             int column, int page_addr) {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
        struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
@@ -624,7 +624,7 @@ static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip)
  */
 static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        unsigned int bufsize = mtd->writesize + mtd->oobsize;
 
@@ -650,7 +650,7 @@ static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  */
 static uint8_t fsl_ifc_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        unsigned int offset;
 
@@ -673,7 +673,7 @@ static uint8_t fsl_ifc_read_byte(struct mtd_info *mtd)
  */
 static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        uint16_t data;
 
@@ -696,7 +696,7 @@ static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd)
  */
 static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
        int avail;
 
@@ -782,7 +782,7 @@ static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
 
 static int fsl_ifc_chip_init_tail(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = chip->priv;
 
        dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
@@ -883,6 +883,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
        /* Fill in fsl_ifc_mtd structure */
        priv->mtd.priv = chip;
        priv->mtd.dev.parent = priv->dev;
+       nand_set_flash_node(chip, priv->dev->of_node);
 
        /* fill in nand_chip structure */
        /* set up function call table */
@@ -1030,9 +1031,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
        int ret;
        int bank;
        struct device_node *node = dev->dev.of_node;
-       struct mtd_part_parser_data ppdata;
 
-       ppdata.of_node = dev->dev.of_node;
        if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
                return -ENODEV;
        ifc = fsl_ifc_ctrl_dev->regs;
@@ -1128,7 +1127,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 
        /* First look for RedBoot table or partitions on the command
         * line, these take precedence over device tree information */
-       mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata,
+       mtd_device_parse_register(&priv->mtd, part_probe_types, NULL,
                                                NULL, 0);
 
        dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
index d326369..68ec128 100644 (file)
@@ -79,7 +79,7 @@ static void fun_wait_rnb(struct fsl_upm_nand *fun)
 
 static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
        u32 mar;
 
@@ -109,7 +109,7 @@ static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 
 static void fun_select_chip(struct mtd_info *mtd, int mchip_nr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
 
        if (mchip_nr == -1) {
@@ -159,7 +159,6 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
 {
        int ret;
        struct device_node *flash_np;
-       struct mtd_part_parser_data ppdata;
 
        fun->chip.IO_ADDR_R = fun->io_base;
        fun->chip.IO_ADDR_W = fun->io_base;
@@ -182,6 +181,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
        if (!flash_np)
                return -ENODEV;
 
+       nand_set_flash_node(&fun->chip, flash_np);
        fun->mtd.name = kasprintf(GFP_KERNEL, "0x%llx.%s", (u64)io_res->start,
                                  flash_np->name);
        if (!fun->mtd.name) {
@@ -193,8 +193,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
        if (ret)
                goto err;
 
-       ppdata.of_node = flash_np;
-       ret = mtd_device_parse_register(&fun->mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(&fun->mtd, NULL, 0);
 err:
        of_node_put(flash_np);
        if (ret)
index 07af3dc..1c6c399 100644 (file)
@@ -329,7 +329,7 @@ struct fsmc_nand_data {
 /* Assert CS signal based on chipnr */
 static void fsmc_select_chip(struct mtd_info *mtd, int chipnr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsmc_nand_data *host;
 
        host = container_of(mtd, struct fsmc_nand_data, mtd);
@@ -358,7 +358,7 @@ static void fsmc_select_chip(struct mtd_info *mtd, int chipnr)
  */
 static void fsmc_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct fsmc_nand_data *host = container_of(mtd,
                                        struct fsmc_nand_data, mtd);
        void __iomem *regs = host->regs_va;
@@ -629,7 +629,7 @@ unmap_dma:
 static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) &&
                        IS_ALIGNED(len, sizeof(uint32_t))) {
@@ -652,7 +652,7 @@ static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 static void fsmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (IS_ALIGNED((uint32_t)buf, sizeof(uint32_t)) &&
                        IS_ALIGNED(len, sizeof(uint32_t))) {
@@ -784,7 +784,7 @@ static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
 {
        struct fsmc_nand_data *host = container_of(mtd,
                                        struct fsmc_nand_data, mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        void __iomem *regs = host->regs_va;
        unsigned int bank = host->bank;
        uint32_t err_idx[8];
@@ -926,7 +926,6 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
 {
        struct fsmc_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
        struct device_node __maybe_unused *np = pdev->dev.of_node;
-       struct mtd_part_parser_data ppdata = {};
        struct fsmc_nand_data *host;
        struct mtd_info *mtd;
        struct nand_chip *nand;
@@ -1016,6 +1015,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
        nand = &host->nand;
        mtd->priv = nand;
        nand->priv = host;
+       nand_set_flash_node(nand, np);
 
        host->mtd.dev.parent = &pdev->dev;
        nand->IO_ADDR_R = host->data_va;
@@ -1033,7 +1033,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
        nand->options = pdata->options;
        nand->select_chip = fsmc_select_chip;
        nand->badblockbits = 7;
-       nand->flash_node = np;
+       nand_set_flash_node(nand, np);
 
        if (pdata->width == FSMC_NAND_BW16)
                nand->options |= NAND_BUSWIDTH_16;
@@ -1175,9 +1175,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
         * Check for partition info passed
         */
        host->mtd.name = "nand";
-       ppdata.of_node = np;
-       ret = mtd_device_parse_register(&host->mtd, NULL, &ppdata,
-                                       host->partitions, host->nr_partitions);
+       ret = mtd_device_register(&host->mtd, host->partitions,
+                                 host->nr_partitions);
        if (ret)
                goto err_probe;
 
index 9ab97f9..d57a07a 100644 (file)
@@ -209,7 +209,6 @@ static int gpio_nand_probe(struct platform_device *pdev)
        struct gpiomtd *gpiomtd;
        struct nand_chip *chip;
        struct resource *res;
-       struct mtd_part_parser_data ppdata = {};
        int ret = 0;
 
        if (!pdev->dev.of_node && !dev_get_platdata(&pdev->dev))
@@ -268,6 +267,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
                chip->dev_ready = gpio_nand_devready;
        }
 
+       nand_set_flash_node(chip, pdev->dev.of_node);
        chip->IO_ADDR_W         = chip->IO_ADDR_R;
        chip->ecc.mode          = NAND_ECC_SOFT;
        chip->options           = gpiomtd->plat.options;
@@ -291,10 +291,8 @@ static int gpio_nand_probe(struct platform_device *pdev)
                gpiomtd->plat.adjust_parts(&gpiomtd->plat,
                                           gpiomtd->mtd_info.size);
 
-       ppdata.of_node = pdev->dev.of_node;
-       ret = mtd_device_parse_register(&gpiomtd->mtd_info, NULL, &ppdata,
-                                       gpiomtd->plat.parts,
-                                       gpiomtd->plat.num_parts);
+       ret = mtd_device_register(&gpiomtd->mtd_info, gpiomtd->plat.parts,
+                                 gpiomtd->plat.num_parts);
        if (!ret)
                return 0;
 
index 2064ada..802adb0 100644 (file)
@@ -140,7 +140,7 @@ static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this)
 {
        struct bch_geometry *geo = &this->bch_geometry;
        struct mtd_info *mtd = &this->mtd;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree;
        unsigned int block_mark_bit_offset;
 
@@ -856,7 +856,7 @@ error_alloc:
 
 static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
        int ret;
 
@@ -890,7 +890,7 @@ static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
 
 static int gpmi_dev_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
 
        return gpmi_is_ready(this, this->current_chip);
@@ -898,7 +898,7 @@ static int gpmi_dev_ready(struct mtd_info *mtd)
 
 static void gpmi_select_chip(struct mtd_info *mtd, int chipnr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
 
        if ((this->current_chip < 0) && (chipnr >= 0))
@@ -911,7 +911,7 @@ static void gpmi_select_chip(struct mtd_info *mtd, int chipnr)
 
 static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
 
        dev_dbg(this->dev, "len is %d\n", len);
@@ -923,7 +923,7 @@ static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 
 static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
 
        dev_dbg(this->dev, "len is %d\n", len);
@@ -935,7 +935,7 @@ static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 
 static uint8_t gpmi_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
        uint8_t *buf = this->data_buffer_dma;
 
@@ -1538,7 +1538,7 @@ static int gpmi_ecc_write_oob_raw(struct mtd_info *mtd, struct nand_chip *chip,
 
 static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct gpmi_nand_data *this = chip->priv;
        int ret = 0;
        uint8_t *block_mark;
@@ -1838,7 +1838,7 @@ static void gpmi_nand_exit(struct gpmi_nand_data *this)
 static int gpmi_init_last(struct gpmi_nand_data *this)
 {
        struct mtd_info *mtd = &this->mtd;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        struct bch_geometry *bch_geo = &this->bch_geometry;
        int ret;
@@ -1888,7 +1888,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 {
        struct mtd_info  *mtd = &this->mtd;
        struct nand_chip *chip = &this->nand;
-       struct mtd_part_parser_data ppdata = {};
        int ret;
 
        /* init current chip */
@@ -1901,6 +1900,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
 
        /* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */
        chip->priv              = this;
+       nand_set_flash_node(chip, this->pdev->dev.of_node);
        chip->select_chip       = gpmi_select_chip;
        chip->cmd_ctrl          = gpmi_cmd_ctrl;
        chip->dev_ready         = gpmi_dev_ready;
@@ -1954,8 +1954,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
        if (ret)
                goto err_out;
 
-       ppdata.of_node = this->pdev->dev.of_node;
-       ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(mtd, NULL, 0);
        if (ret)
                goto err_out;
        return 0;
index 0cb2e88..6358d4a 100644 (file)
@@ -190,7 +190,7 @@ static void wait_controller_finished(struct hinfc_host *host)
 static void hisi_nfc_dma_transfer(struct hinfc_host *host, int todev)
 {
        struct mtd_info *mtd = &host->mtd;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned long val;
        int ret;
 
@@ -357,7 +357,7 @@ static int hisi_nfc_send_cmd_reset(struct hinfc_host *host, int chipselect)
 
 static void hisi_nfc_select_chip(struct mtd_info *mtd, int chipselect)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
 
        if (chipselect < 0)
@@ -368,7 +368,7 @@ static void hisi_nfc_select_chip(struct mtd_info *mtd, int chipselect)
 
 static uint8_t hisi_nfc_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
 
        if (host->command == NAND_CMD_STATUS)
@@ -384,7 +384,7 @@ static uint8_t hisi_nfc_read_byte(struct mtd_info *mtd)
 
 static u16 hisi_nfc_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
 
        host->offset += 2;
@@ -394,7 +394,7 @@ static u16 hisi_nfc_read_word(struct mtd_info *mtd)
 static void
 hisi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
 
        memcpy(host->buffer + host->offset, buf, len);
@@ -403,7 +403,7 @@ hisi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 
 static void hisi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
 
        memcpy(buf, host->buffer + host->offset, len);
@@ -412,7 +412,7 @@ static void hisi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 
 static void set_addr(struct mtd_info *mtd, int column, int page_addr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
        unsigned int command = host->command;
 
@@ -448,7 +448,7 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr)
 static void hisi_nfc_cmdfunc(struct mtd_info *mtd, unsigned command, int column,
                int page_addr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct hinfc_host *host = chip->priv;
        int is_cache_invalid = 1;
        unsigned int flag = 0;
@@ -704,7 +704,6 @@ static int hisi_nfc_probe(struct platform_device *pdev)
        struct mtd_info   *mtd;
        struct resource   *res;
        struct device_node *np = dev->of_node;
-       struct mtd_part_parser_data ppdata;
 
        host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
        if (!host)
@@ -742,6 +741,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
        mtd->dev.parent         = &pdev->dev;
 
        chip->priv              = host;
+       nand_set_flash_node(chip, np);
        chip->cmdfunc           = hisi_nfc_cmdfunc;
        chip->select_chip       = hisi_nfc_select_chip;
        chip->read_byte         = hisi_nfc_read_byte;
@@ -805,8 +805,7 @@ static int hisi_nfc_probe(struct platform_device *pdev)
                goto err_res;
        }
 
-       ppdata.of_node = np;
-       ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(mtd, NULL, 0);
        if (ret) {
                dev_err(dev, "Err MTD partition=%d\n", ret);
                goto err_mtd;
index 5a99a93..5a06fba 100644 (file)
@@ -82,7 +82,7 @@ static inline struct jz_nand *mtd_to_jz_nand(struct mtd_info *mtd)
 static void jz_nand_select_chip(struct mtd_info *mtd, int chipnr)
 {
        struct jz_nand *nand = mtd_to_jz_nand(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint32_t ctrl;
        int banknr;
 
@@ -104,7 +104,7 @@ static void jz_nand_select_chip(struct mtd_info *mtd, int chipnr)
 static void jz_nand_cmd_ctrl(struct mtd_info *mtd, int dat, unsigned int ctrl)
 {
        struct jz_nand *nand = mtd_to_jz_nand(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint32_t reg;
        void __iomem *bank_base = nand->bank_base[nand->selected_bank];
 
index 3475109..3738856 100644 (file)
@@ -275,7 +275,7 @@ static void lpc32xx_nand_setup(struct lpc32xx_nand_host *host)
 static void lpc32xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                                  unsigned int ctrl)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = nand_chip->priv;
 
        if (cmd != NAND_CMD_NONE) {
@@ -291,7 +291,7 @@ static void lpc32xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  */
 static int lpc32xx_nand_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = nand_chip->priv;
 
        if ((readb(MLC_ISR(host->io_base)) &
@@ -389,7 +389,7 @@ static void lpc32xx_dma_complete_func(void *completion)
 static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len,
                            enum dma_transfer_direction dir)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
        struct dma_async_tx_descriptor *desc;
        int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
@@ -647,7 +647,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        struct nand_chip *nand_chip;
        struct resource *rc;
        int res;
-       struct mtd_part_parser_data ppdata = {};
 
        /* Allocate memory for the device structure (and zero it) */
        host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
@@ -682,6 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        host->pdata = dev_get_platdata(&pdev->dev);
 
        nand_chip->priv = host;         /* link the private data structures */
+       nand_set_flash_node(nand_chip, pdev->dev.of_node);
        mtd->priv = nand_chip;
        mtd->dev.parent = &pdev->dev;
 
@@ -786,9 +786,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
        mtd->name = DRV_NAME;
 
-       ppdata.of_node = pdev->dev.of_node;
-       res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts,
-                                       host->ncfg->num_parts);
+       res = mtd_device_register(mtd, host->ncfg->parts,
+                                 host->ncfg->num_parts);
        if (!res)
                return res;
 
index 4f3d4eb..fcd9fac 100644 (file)
@@ -260,7 +260,7 @@ static void lpc32xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
        unsigned int ctrl)
 {
        uint32_t tmp;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
 
        /* Does CE state need to be changed? */
@@ -284,7 +284,7 @@ static void lpc32xx_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  */
 static int lpc32xx_nand_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
        int rdy = 0;
 
@@ -339,7 +339,7 @@ static int lpc32xx_nand_ecc_calculate(struct mtd_info *mtd,
  */
 static uint8_t lpc32xx_nand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
 
        return (uint8_t)readl(SLC_DATA(host->io_base));
@@ -350,7 +350,7 @@ static uint8_t lpc32xx_nand_read_byte(struct mtd_info *mtd)
  */
 static void lpc32xx_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
 
        /* Direct device read with no ECC */
@@ -363,7 +363,7 @@ static void lpc32xx_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  */
 static void lpc32xx_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
 
        /* Direct device write with no ECC */
@@ -428,7 +428,7 @@ static void lpc32xx_dma_complete_func(void *completion)
 static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma,
                            void *mem, int len, enum dma_transfer_direction dir)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
        struct dma_async_tx_descriptor *desc;
        int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
@@ -488,7 +488,7 @@ out1:
 static int lpc32xx_xfer(struct mtd_info *mtd, uint8_t *buf, int eccsubpages,
                        int read)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct lpc32xx_nand_host *host = chip->priv;
        int i, status = 0;
        unsigned long timeout;
@@ -763,7 +763,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        struct mtd_info *mtd;
        struct nand_chip *chip;
        struct resource *rc;
-       struct mtd_part_parser_data ppdata = {};
        int res;
 
        rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -803,6 +802,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        mtd = &host->mtd;
        chip = &host->nand_chip;
        chip->priv = host;
+       nand_set_flash_node(chip, pdev->dev.of_node);
        mtd->priv = chip;
        mtd->owner = THIS_MODULE;
        mtd->dev.parent = &pdev->dev;
@@ -908,9 +908,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        }
 
        mtd->name = "nxp_lpc3220_slc";
-       ppdata.of_node = pdev->dev.of_node;
-       res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts,
-                                       host->ncfg->num_parts);
+       res = mtd_device_register(mtd, host->ncfg->parts,
+                                 host->ncfg->num_parts);
        if (!res)
                return res;
 
index d6bbde4..642c486 100644 (file)
@@ -135,7 +135,7 @@ static void mpc5121_nfc_done(struct mtd_info *mtd);
 /* Read NFC register */
 static inline u16 nfc_read(struct mtd_info *mtd, uint reg)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
 
        return in_be16(prv->regs + reg);
@@ -144,7 +144,7 @@ static inline u16 nfc_read(struct mtd_info *mtd, uint reg)
 /* Write NFC register */
 static inline void nfc_write(struct mtd_info *mtd, uint reg, u16 val)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
 
        out_be16(prv->regs + reg, val);
@@ -214,7 +214,7 @@ static inline void mpc5121_nfc_send_read_status(struct mtd_info *mtd)
 static irqreturn_t mpc5121_nfc_irq(int irq, void *data)
 {
        struct mtd_info *mtd = data;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
 
        nfc_set(mtd, NFC_CONFIG1, NFC_INT_MASK);
@@ -226,7 +226,7 @@ static irqreturn_t mpc5121_nfc_irq(int irq, void *data)
 /* Wait for operation complete */
 static void mpc5121_nfc_done(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
        int rv;
 
@@ -246,7 +246,7 @@ static void mpc5121_nfc_done(struct mtd_info *mtd)
 /* Do address cycle(s) */
 static void mpc5121_nfc_addr_cycle(struct mtd_info *mtd, int column, int page)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u32 pagemask = chip->pagemask;
 
        if (column != -1) {
@@ -281,7 +281,7 @@ static void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
 /* Init external chip select logic on ADS5121 board */
 static int ads5121_chipselect_init(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
        struct device_node *dn;
 
@@ -303,7 +303,7 @@ static int ads5121_chipselect_init(struct mtd_info *mtd)
 /* Control chips select signal on ADS5121 board */
 static void ads5121_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = nand->priv;
        u8 v;
 
@@ -333,7 +333,7 @@ static int mpc5121_nfc_dev_ready(struct mtd_info *mtd)
 static void mpc5121_nfc_command(struct mtd_info *mtd, unsigned command,
                                                        int column, int page)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
 
        prv->column = (column >= 0) ? column : 0;
@@ -406,7 +406,7 @@ static void mpc5121_nfc_command(struct mtd_info *mtd, unsigned command,
 static void mpc5121_nfc_copy_spare(struct mtd_info *mtd, uint offset,
                                                u8 *buffer, uint size, int wr)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = nand->priv;
        uint o, s, sbsize, blksize;
 
@@ -458,7 +458,7 @@ static void mpc5121_nfc_copy_spare(struct mtd_info *mtd, uint offset,
 static void mpc5121_nfc_buf_copy(struct mtd_info *mtd, u_char *buf, int len,
                                                                        int wr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
        uint c = prv->column;
        uint l;
@@ -536,7 +536,7 @@ static u16 mpc5121_nfc_read_word(struct mtd_info *mtd)
  */
 static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
        struct mpc512x_reset_module *rm;
        struct device_node *rmnode;
@@ -615,7 +615,7 @@ out:
 /* Free driver resources */
 static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mpc5121_nfc_prv *prv = chip->priv;
 
        if (prv->clk)
@@ -639,7 +639,6 @@ static int mpc5121_nfc_probe(struct platform_device *op)
        int resettime = 0;
        int retval = 0;
        int rev, len;
-       struct mtd_part_parser_data ppdata;
 
        /*
         * Check SoC revision. This driver supports only NFC
@@ -661,6 +660,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
        mtd->priv = chip;
        mtd->dev.parent = dev;
        chip->priv = prv;
+       nand_set_flash_node(chip, dn);
        prv->dev = dev;
 
        /* Read NFC configuration from Reset Config Word */
@@ -703,7 +703,6 @@ static int mpc5121_nfc_probe(struct platform_device *op)
        }
 
        mtd->name = "MPC5121 NAND";
-       ppdata.of_node = dn;
        chip->dev_ready = mpc5121_nfc_dev_ready;
        chip->cmdfunc = mpc5121_nfc_command;
        chip->read_byte = mpc5121_nfc_read_byte;
@@ -815,7 +814,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
        dev_set_drvdata(dev, mtd);
 
        /* Register device in MTD */
-       retval = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       retval = mtd_device_register(mtd, NULL, 0);
        if (retval) {
                dev_err(dev, "Error adding MTD device!\n");
                goto error;
index 136e73a..b291258 100644 (file)
@@ -532,7 +532,7 @@ static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islas
 
 static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        uint32_t tmp;
 
@@ -548,7 +548,7 @@ static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
 
 static void send_page_v2(struct mtd_info *mtd, unsigned int ops)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        /* NANDFC buffer 0 is used for page read/write */
@@ -562,7 +562,7 @@ static void send_page_v2(struct mtd_info *mtd, unsigned int ops)
 
 static void send_page_v1(struct mtd_info *mtd, unsigned int ops)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        int bufs, i;
 
@@ -663,7 +663,7 @@ static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
 static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
                                 u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        /*
@@ -684,7 +684,7 @@ static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
 static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
                                 u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        u32 ecc_stat, err;
        int no_subpages = 1;
@@ -722,7 +722,7 @@ static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
 
 static u_char mxc_nand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        uint8_t ret;
 
@@ -746,7 +746,7 @@ static u_char mxc_nand_read_byte(struct mtd_info *mtd)
 
 static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        uint16_t ret;
 
@@ -762,7 +762,7 @@ static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
 static void mxc_nand_write_buf(struct mtd_info *mtd,
                                const u_char *buf, int len)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        u16 col = host->buf_start;
        int n = mtd->oobsize + mtd->writesize - col;
@@ -780,7 +780,7 @@ static void mxc_nand_write_buf(struct mtd_info *mtd,
  */
 static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        u16 col = host->buf_start;
        int n = mtd->oobsize + mtd->writesize - col;
@@ -796,7 +796,7 @@ static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  * deselect of the NAND chip */
 static void mxc_nand_select_chip_v1_v3(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        if (chip == -1) {
@@ -817,7 +817,7 @@ static void mxc_nand_select_chip_v1_v3(struct mtd_info *mtd, int chip)
 
 static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        if (chip == -1) {
@@ -850,7 +850,7 @@ static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip)
  */
 static void copy_spare(struct mtd_info *mtd, bool bfrom)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct mxc_nand_host *host = this->priv;
        u16 i, oob_chunk_size;
        u16 num_chunks = mtd->writesize / 512;
@@ -893,7 +893,7 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom)
  */
 static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        /* Write out column address, if necessary */
@@ -979,7 +979,7 @@ static void ecc_8bit_layout_4k(struct nand_ecclayout *layout)
 
 static void preset_v1(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        uint16_t config1 = 0;
 
@@ -1007,7 +1007,7 @@ static void preset_v1(struct mtd_info *mtd)
 
 static void preset_v2(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
        uint16_t config1 = 0;
 
@@ -1053,7 +1053,7 @@ static void preset_v2(struct mtd_info *mtd)
 
 static void preset_v3(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = chip->priv;
        uint32_t config2, config3;
        int i, addr_phases;
@@ -1067,8 +1067,7 @@ static void preset_v3(struct mtd_info *mtd)
 
        /* Blocks to be unlocked */
        for (i = 0; i < NAND_MAX_CHIPS; i++)
-               writel(0x0 |    (0xffff << 16),
-                               NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
+               writel(0xffff << 16, NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
 
        writel(0, NFC_V3_IPC);
 
@@ -1125,7 +1124,7 @@ static void preset_v3(struct mtd_info *mtd)
 static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
                                int column, int page_addr)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct mxc_nand_host *host = nand_chip->priv;
 
        pr_debug("mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
@@ -1524,6 +1523,7 @@ static int mxcnd_probe(struct platform_device *pdev)
        this->chip_delay = 5;
 
        this->priv = host;
+       nand_set_flash_node(this, pdev->dev.of_node),
        this->dev_ready = mxc_nand_dev_ready;
        this->cmdfunc = mxc_nand_command;
        this->read_byte = mxc_nand_read_byte;
@@ -1683,9 +1683,7 @@ static int mxcnd_probe(struct platform_device *pdev)
 
        /* Register the partitions */
        mtd_device_parse_register(mtd, part_probes,
-                       &(struct mtd_part_parser_data){
-                               .of_node = pdev->dev.of_node,
-                       },
+                       NULL,
                        host->pdata.parts,
                        host->pdata.nr_parts);
 
index ece544e..5aec154 100644 (file)
@@ -106,7 +106,7 @@ DEFINE_LED_TRIGGER(nand_led_trigger);
 static int check_offs_len(struct mtd_info *mtd,
                                        loff_t ofs, uint64_t len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret = 0;
 
        /* Start address must align on block boundary */
@@ -132,7 +132,7 @@ static int check_offs_len(struct mtd_info *mtd,
  */
 static void nand_release_device(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Release the controller and the chip */
        spin_lock(&chip->controller->lock);
@@ -150,7 +150,7 @@ static void nand_release_device(struct mtd_info *mtd)
  */
 static uint8_t nand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return readb(chip->IO_ADDR_R);
 }
 
@@ -163,7 +163,7 @@ static uint8_t nand_read_byte(struct mtd_info *mtd)
  */
 static uint8_t nand_read_byte16(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return (uint8_t) cpu_to_le16(readw(chip->IO_ADDR_R));
 }
 
@@ -175,7 +175,7 @@ static uint8_t nand_read_byte16(struct mtd_info *mtd)
  */
 static u16 nand_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return readw(chip->IO_ADDR_R);
 }
 
@@ -188,7 +188,7 @@ static u16 nand_read_word(struct mtd_info *mtd)
  */
 static void nand_select_chip(struct mtd_info *mtd, int chipnr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        switch (chipnr) {
        case -1:
@@ -211,7 +211,7 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr)
  */
 static void nand_write_byte(struct mtd_info *mtd, uint8_t byte)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        chip->write_buf(mtd, &byte, 1);
 }
@@ -225,7 +225,7 @@ static void nand_write_byte(struct mtd_info *mtd, uint8_t byte)
  */
 static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint16_t word = byte;
 
        /*
@@ -257,7 +257,7 @@ static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte)
  */
 static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        iowrite8_rep(chip->IO_ADDR_W, buf, len);
 }
@@ -272,7 +272,7 @@ static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  */
 static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        ioread8_rep(chip->IO_ADDR_R, buf, len);
 }
@@ -287,7 +287,7 @@ static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  */
 static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
 
        iowrite16_rep(chip->IO_ADDR_W, p, len >> 1);
@@ -303,7 +303,7 @@ static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
  */
 static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
 
        ioread16_rep(chip->IO_ADDR_R, p, len >> 1);
@@ -320,7 +320,7 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
 {
        int page, chipnr, res = 0, i = 0;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 bad;
 
        if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
@@ -380,7 +380,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
  */
 static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_oob_ops ops;
        uint8_t buf[2] = { 0, 0 };
        int ret = 0, res, i = 0;
@@ -430,7 +430,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 */
 static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int res, ret = 0;
 
        if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) {
@@ -471,7 +471,7 @@ static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)
  */
 static int nand_check_wp(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Broken xD cards report WP despite being writable */
        if (chip->options & NAND_BROKEN_XD)
@@ -491,7 +491,7 @@ static int nand_check_wp(struct mtd_info *mtd)
  */
 static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (!chip->bbt)
                return 0;
@@ -512,7 +512,7 @@ static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
                               int allowbbt)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (!chip->bbt)
                return chip->block_bad(mtd, ofs, getchip);
@@ -531,7 +531,7 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
  */
 static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int i;
 
        /* Wait for the device to get ready */
@@ -551,7 +551,7 @@ static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
  */
 void nand_wait_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned long timeo = 400;
 
        if (in_interrupt() || oops_in_progress)
@@ -582,7 +582,7 @@ EXPORT_SYMBOL_GPL(nand_wait_ready);
  */
 static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
 
        timeo = jiffies + msecs_to_jiffies(timeo);
        do {
@@ -605,7 +605,7 @@ static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo)
 static void nand_command(struct mtd_info *mtd, unsigned int command,
                         int column, int page_addr)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
        int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
 
        /* Write out the command to the device */
@@ -708,7 +708,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
 static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
                            int column, int page_addr)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Emulate NAND_CMD_READOOB */
        if (command == NAND_CMD_READOOB) {
@@ -832,7 +832,7 @@ static void panic_nand_get_device(struct nand_chip *chip,
 static int
 nand_get_device(struct mtd_info *mtd, int new_state)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        spinlock_t *lock = &chip->controller->lock;
        wait_queue_head_t *wq = &chip->controller->wq;
        DECLARE_WAITQUEUE(wait, current);
@@ -952,7 +952,7 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
 {
        int ret = 0;
        int status, page;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Submit address of first page to unlock */
        page = ofs >> chip->page_shift;
@@ -987,7 +987,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        int ret = 0;
        int chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
@@ -1050,7 +1050,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        int ret = 0;
        int chipnr, status, page;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
@@ -1655,7 +1655,7 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
  */
 static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("setting READ RETRY mode %d\n", retry_mode);
 
@@ -1680,7 +1680,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
                            struct mtd_oob_ops *ops)
 {
        int chipnr, page, realpage, col, bytes, aligned, oob_required;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret = 0;
        uint32_t readlen = ops->len;
        uint32_t oobreadlen = ops->ooblen;
@@ -2024,7 +2024,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
                            struct mtd_oob_ops *ops)
 {
        int page, realpage, chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_ecc_stats stats;
        int readlen = ops->ooblen;
        int len;
@@ -2472,7 +2472,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
 static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
                              struct mtd_oob_ops *ops)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /*
         * Initialise to all 0xFF, to avoid the possibility of left over OOB
@@ -2532,7 +2532,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
                             struct mtd_oob_ops *ops)
 {
        int chipnr, realpage, page, blockmask, column;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint32_t writelen = ops->len;
 
        uint32_t oobwritelen = ops->ooblen;
@@ -2662,7 +2662,7 @@ err_out:
 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
                            size_t *retlen, const uint8_t *buf)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_oob_ops ops;
        int ret;
 
@@ -2722,7 +2722,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
                             struct mtd_oob_ops *ops)
 {
        int chipnr, page, status, len;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: to = 0x%08x, len = %i\n",
                         __func__, (unsigned int)to, (int)ops->ooblen);
@@ -2847,7 +2847,7 @@ out:
  */
 static int single_erase(struct mtd_info *mtd, int page)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        /* Send commands to erase a block */
        chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
        chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
@@ -2879,7 +2879,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
                    int allowbbt)
 {
        int page, status, pages_per_block, ret, chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        loff_t len;
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
@@ -3094,7 +3094,7 @@ static int nand_suspend(struct mtd_info *mtd)
  */
 static void nand_resume(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (chip->state == FL_PM_SUSPENDED)
                nand_release_device(mtd);
@@ -3266,7 +3266,7 @@ ext_out:
 
 static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
 
        return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
@@ -3985,12 +3985,15 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
                    struct nand_flash_dev *table)
 {
        int i, nand_maf_id, nand_dev_id;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_flash_dev *type;
        int ret;
 
-       if (chip->flash_node) {
-               ret = nand_dt_init(mtd, chip, chip->flash_node);
+       if (nand_get_flash_node(chip)) {
+               /* MTD can automatically handle DT partitions, etc. */
+               mtd_set_of_node(mtd, nand_get_flash_node(chip));
+
+               ret = nand_dt_init(mtd, chip, nand_get_flash_node(chip));
                if (ret)
                        return ret;
        }
@@ -4053,7 +4056,7 @@ EXPORT_SYMBOL(nand_scan_ident);
  */
 static bool nand_ecc_strength_good(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        int corr, ds_corr;
 
@@ -4082,7 +4085,7 @@ static bool nand_ecc_strength_good(struct mtd_info *mtd)
 int nand_scan_tail(struct mtd_info *mtd)
 {
        int i;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        struct nand_buffers *nbuf;
 
@@ -4426,7 +4429,7 @@ EXPORT_SYMBOL(nand_scan);
  */
 void nand_release(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
                nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
index b1d4f81..4b6a708 100644 (file)
@@ -172,7 +172,7 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
                struct nand_bbt_descr *td, int offs)
 {
        int res, ret = 0, i, j, act = 0;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        size_t retlen, len, totlen;
        loff_t from;
        int bits = td->options & NAND_BBT_NRBITS_MSK;
@@ -263,7 +263,7 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
  */
 static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int res = 0, i;
 
        if (td->options & NAND_BBT_PERCHIP) {
@@ -388,7 +388,7 @@ static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td)
 static void read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
                          struct nand_bbt_descr *td, struct nand_bbt_descr *md)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        /* Read the primary version, if available */
        if (td->options & NAND_BBT_VERSION) {
@@ -454,7 +454,7 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
 static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
        struct nand_bbt_descr *bd, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, numblocks, numpages;
        int startblock;
        loff_t from;
@@ -523,7 +523,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
  */
 static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, chips;
        int startblock, block, dir;
        int scanlen = mtd->writesize + mtd->oobsize;
@@ -618,7 +618,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
                     struct nand_bbt_descr *td, struct nand_bbt_descr *md,
                     int chipsel)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct erase_info einfo;
        int i, res, chip = 0;
        int bits, startblock, dir, page, offs, numblocks, sft, sftmsk;
@@ -819,7 +819,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
  */
 static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        return create_bbt(mtd, this->buffers->databuf, bd, -1);
 }
@@ -838,7 +838,7 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b
 static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
 {
        int i, chips, writeops, create, chipsel, res, res2;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct nand_bbt_descr *td = this->bbt_td;
        struct nand_bbt_descr *md = this->bbt_md;
        struct nand_bbt_descr *rd, *rd2;
@@ -962,7 +962,7 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
  */
 static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, j, chips, block, nrblocks, update;
        uint8_t oldval;
 
@@ -1022,7 +1022,7 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
  */
 static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u32 pattern_len;
        u32 bits;
        u32 table_size;
@@ -1074,7 +1074,7 @@ static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
  */
 static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int len, res;
        uint8_t *buf;
        struct nand_bbt_descr *td = this->bbt_td;
@@ -1147,7 +1147,7 @@ err:
  */
 static int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int len, res = 0;
        int chip, chipsel;
        uint8_t *buf;
@@ -1281,7 +1281,7 @@ static int nand_create_badblock_pattern(struct nand_chip *this)
  */
 int nand_default_bbt(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int ret;
 
        /* Is a flash based bad block table requested? */
@@ -1317,7 +1317,7 @@ int nand_default_bbt(struct mtd_info *mtd)
  */
 int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block;
 
        block = (int)(offs >> this->bbt_erase_shift);
@@ -1332,7 +1332,7 @@ int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs)
  */
 int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block, res;
 
        block = (int)(offs >> this->bbt_erase_shift);
@@ -1359,7 +1359,7 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
  */
 int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block, ret = 0;
 
        block = (int)(offs >> this->bbt_erase_shift);
index 3803e0b..e5758d8 100644 (file)
@@ -52,7 +52,7 @@ struct nand_bch_control {
 int nand_bch_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
                           unsigned char *code)
 {
-       const struct nand_chip *chip = mtd->priv;
+       const struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_bch_control *nbc = chip->ecc.priv;
        unsigned int i;
 
@@ -79,7 +79,7 @@ EXPORT_SYMBOL(nand_bch_calculate_ecc);
 int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
                          unsigned char *read_ecc, unsigned char *calc_ecc)
 {
-       const struct nand_chip *chip = mtd->priv;
+       const struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_bch_control *nbc = chip->ecc.priv;
        unsigned int *errloc = nbc->errloc;
        int i, count;
index 97c4c02..e612985 100644 (file)
@@ -424,7 +424,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
                       unsigned char *code)
 {
        __nand_calculate_ecc(buf,
-                       ((struct nand_chip *)mtd->priv)->ecc.size, code);
+                       mtd_to_nand(mtd)->ecc.size, code);
 
        return 0;
 }
@@ -524,7 +524,7 @@ int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
                      unsigned char *read_ecc, unsigned char *calc_ecc)
 {
        return __nand_correct_data(buf, read_ecc, calc_ecc,
-                                  ((struct nand_chip *)mtd->priv)->ecc.size);
+                                  mtd_to_nand(mtd)->ecc.size);
 }
 EXPORT_SYMBOL(nand_correct_data);
 
index b16d70a..eb2a567 100644 (file)
@@ -666,7 +666,7 @@ static char *get_partition_name(int i)
  */
 static int init_nandsim(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nandsim   *ns   = chip->priv;
        int i, ret = 0;
        uint64_t remains;
@@ -1908,7 +1908,7 @@ static void switch_state(struct nandsim *ns)
 
 static u_char ns_nand_read_byte(struct mtd_info *mtd)
 {
-       struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(mtd)->priv;
        u_char outb = 0x00;
 
        /* Sanity and correctness checks */
@@ -1969,7 +1969,7 @@ static u_char ns_nand_read_byte(struct mtd_info *mtd)
 
 static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
 {
-       struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(mtd)->priv;
 
        /* Sanity and correctness checks */
        if (!ns->lines.ce) {
@@ -2123,7 +2123,7 @@ static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
 
 static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask)
 {
-       struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(mtd)->priv;
 
        ns->lines.cle = bitmask & NAND_CLE ? 1 : 0;
        ns->lines.ale = bitmask & NAND_ALE ? 1 : 0;
@@ -2141,7 +2141,7 @@ static int ns_device_ready(struct mtd_info *mtd)
 
 static uint16_t ns_nand_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        NS_DBG("read_word\n");
 
@@ -2150,7 +2150,7 @@ static uint16_t ns_nand_read_word(struct mtd_info *mtd)
 
 static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(mtd)->priv;
 
        /* Check that chip is expecting data input */
        if (!(ns->state & STATE_DATAIN_MASK)) {
@@ -2177,7 +2177,7 @@ static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 
 static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(mtd)->priv;
 
        /* Sanity and correctness checks */
        if (!ns->lines.ce) {
@@ -2198,7 +2198,7 @@ static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
                int i;
 
                for (i = 0; i < len; i++)
-                       buf[i] = ((struct nand_chip *)mtd->priv)->read_byte(mtd);
+                       buf[i] = mtd_to_nand(mtd)->read_byte(mtd);
 
                return;
        }
@@ -2405,7 +2405,7 @@ module_init(ns_init_module);
  */
 static void __exit ns_cleanup_module(void)
 {
-       struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv;
+       struct nandsim *ns = mtd_to_nand(nsmtd)->priv;
        int i;
 
        nandsim_debugfs_remove(ns);
index 4f0d62f..d8a23b0 100644 (file)
@@ -48,7 +48,7 @@ static struct ndfc_controller ndfc_ctrl[NDFC_MAX_CS];
 static void ndfc_select_chip(struct mtd_info *mtd, int chip)
 {
        uint32_t ccr;
-       struct nand_chip *nchip = mtd->priv;
+       struct nand_chip *nchip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = nchip->priv;
 
        ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
@@ -62,7 +62,7 @@ static void ndfc_select_chip(struct mtd_info *mtd, int chip)
 
 static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
 
        if (cmd == NAND_CMD_NONE)
@@ -76,7 +76,7 @@ static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 
 static int ndfc_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
 
        return in_be32(ndfc->ndfcbase + NDFC_STAT) & NDFC_STAT_IS_READY;
@@ -85,7 +85,7 @@ static int ndfc_ready(struct mtd_info *mtd)
 static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode)
 {
        uint32_t ccr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
 
        ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
@@ -97,7 +97,7 @@ static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode)
 static int ndfc_calculate_ecc(struct mtd_info *mtd,
                              const u_char *dat, u_char *ecc_code)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
        uint32_t ecc;
        uint8_t *p = (uint8_t *)&ecc;
@@ -121,7 +121,7 @@ static int ndfc_calculate_ecc(struct mtd_info *mtd,
  */
 static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
        uint32_t *p = (uint32_t *) buf;
 
@@ -131,7 +131,7 @@ static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 
 static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct ndfc_controller *ndfc = chip->priv;
        uint32_t *p = (uint32_t *) buf;
 
@@ -147,7 +147,6 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 {
        struct device_node *flash_np;
        struct nand_chip *chip = &ndfc->chip;
-       struct mtd_part_parser_data ppdata;
        int ret;
 
        chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
@@ -174,8 +173,8 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
        flash_np = of_get_next_child(node, NULL);
        if (!flash_np)
                return -ENODEV;
+       nand_set_flash_node(chip, flash_np);
 
-       ppdata.of_node = flash_np;
        ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
                        dev_name(&ndfc->ofdev->dev), flash_np->name);
        if (!ndfc->mtd.name) {
@@ -187,7 +186,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
        if (ret)
                goto err;
 
-       ret = mtd_device_parse_register(&ndfc->mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(&ndfc->mtd, NULL, 0);
 
 err:
        of_node_put(flash_np);
index f0687f7..8148cd6 100644 (file)
@@ -136,7 +136,7 @@ static int nuc900_nand_devready(struct mtd_info *mtd)
 static void nuc900_nand_command_lp(struct mtd_info *mtd, unsigned int command,
                                   int column, int page_addr)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
        struct nuc900_nand *nand;
 
        nand = container_of(mtd, struct nuc900_nand, mtd);
index 93f664c..944a74e 100644 (file)
@@ -270,7 +270,7 @@ static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  */
 static void omap_read_buf8(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
 
        ioread8_rep(nand->IO_ADDR_R, buf, len);
 }
@@ -306,7 +306,7 @@ static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
  */
 static void omap_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
 
        ioread16_rep(nand->IO_ADDR_R, buf, len / 2);
 }
@@ -955,7 +955,7 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
 {
        struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
                                                        mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
        u32 val;
 
@@ -1001,7 +1001,7 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
  */
 static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
                                                        mtd);
        unsigned long timeo = jiffies;
@@ -1061,7 +1061,7 @@ static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, int mode)
        struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
                                                   mtd);
        enum omap_ecc ecc_opt = info->ecc_opt;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u32 val, wr_mode;
        unsigned int ecc_size1, ecc_size0;
 
@@ -1663,7 +1663,6 @@ static int omap_nand_probe(struct platform_device *pdev)
        unsigned                        sig;
        unsigned                        oob_index;
        struct resource                 *res;
-       struct mtd_part_parser_data     ppdata = {};
 
        pdata = dev_get_platdata(&pdev->dev);
        if (pdata == NULL) {
@@ -1688,6 +1687,7 @@ static int omap_nand_probe(struct platform_device *pdev)
        mtd->dev.parent         = &pdev->dev;
        nand_chip               = &info->nand;
        nand_chip->ecc.priv     = NULL;
+       nand_set_flash_node(nand_chip, pdata->of_node);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
@@ -2037,9 +2037,7 @@ scan_tail:
                goto return_error;
        }
 
-       ppdata.of_node = pdata->of_node;
-       mtd_device_parse_register(mtd, NULL, &ppdata, pdata->parts,
-                                 pdata->nr_parts);
+       mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
 
        platform_set_drvdata(pdev, mtd);
 
@@ -2058,7 +2056,7 @@ return_error:
 static int omap_nand_remove(struct platform_device *pdev)
 {
        struct mtd_info *mtd = platform_get_drvdata(pdev);
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
                                                        mtd);
        if (nand_chip->ecc.priv) {
index ee83749..4ed4f67 100644 (file)
@@ -25,7 +25,7 @@
 
 static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *nc = mtd->priv;
+       struct nand_chip *nc = mtd_to_nand(mtd);
        struct orion_nand_data *board = nc->priv;
        u32 offs;
 
@@ -47,7 +47,7 @@ static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 
 static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        void __iomem *io_base = chip->IO_ADDR_R;
        uint64_t *buf64;
        int i = 0;
@@ -76,7 +76,6 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static int __init orion_nand_probe(struct platform_device *pdev)
 {
        struct mtd_info *mtd;
-       struct mtd_part_parser_data ppdata = {};
        struct nand_chip *nc;
        struct orion_nand_data *board;
        struct resource *res;
@@ -127,6 +126,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
        mtd->dev.parent = &pdev->dev;
 
        nc->priv = board;
+       nand_set_flash_node(nc, pdev->dev.of_node);
        nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
        nc->cmd_ctrl = orion_nand_cmd_ctrl;
        nc->read_buf = orion_nand_read_buf;
@@ -161,9 +161,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
        }
 
        mtd->name = "orion_nand";
-       ppdata.of_node = pdev->dev.of_node;
-       ret = mtd_device_parse_register(mtd, NULL, &ppdata,
-                       board->parts, board->nr_parts);
+       ret = mtd_device_register(mtd, board->parts, board->nr_parts);
        if (ret) {
                nand_release(mtd);
                goto no_dev;
index 83cf021..0ececac 100644 (file)
@@ -45,7 +45,7 @@ static const char driver_name[] = "pasemi-nand";
 
 static void pasemi_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        while (len > 0x800) {
                memcpy_fromio(buf, chip->IO_ADDR_R, 0x800);
@@ -57,7 +57,7 @@ static void pasemi_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 
 static void pasemi_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        while (len > 0x800) {
                memcpy_toio(chip->IO_ADDR_R, buf, 0x800);
@@ -70,7 +70,7 @@ static void pasemi_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
 static void pasemi_hwcontrol(struct mtd_info *mtd, int cmd,
                             unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (cmd == NAND_CMD_NONE)
                return;
@@ -192,7 +192,7 @@ static int pasemi_nand_remove(struct platform_device *ofdev)
        if (!pasemi_nand_mtd)
                return 0;
 
-       chip = pasemi_nand_mtd->priv;
+       chip = mtd_to_nand(pasemi_nand_mtd);
 
        /* Release resources, unregister device */
        nand_release(pasemi_nand_mtd);
index 65b9dbb..06ac6c6 100644 (file)
@@ -30,7 +30,6 @@ struct plat_nand_data {
 static int plat_nand_probe(struct platform_device *pdev)
 {
        struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
-       struct mtd_part_parser_data ppdata;
        struct plat_nand_data *data;
        struct resource *res;
        const char **part_types;
@@ -58,6 +57,7 @@ static int plat_nand_probe(struct platform_device *pdev)
                return PTR_ERR(data->io_base);
 
        data->chip.priv = &data;
+       nand_set_flash_node(&data->chip, pdev->dev.of_node);
        data->mtd.priv = &data->chip;
        data->mtd.dev.parent = &pdev->dev;
 
@@ -94,8 +94,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 
        part_types = pdata->chip.part_probe_types;
 
-       ppdata.of_node = pdev->dev.of_node;
-       err = mtd_device_parse_register(&data->mtd, part_types, &ppdata,
+       err = mtd_device_parse_register(&data->mtd, part_types, NULL,
                                        pdata->chip.partitions,
                                        pdata->chip.nr_partitions);
 
index e453ae9..dc39a98 100644 (file)
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_mtd.h>
-
-#if defined(CONFIG_ARM) && (defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP))
-#define ARCH_HAS_DMA
-#endif
-
 #include <linux/platform_data/mtd-nand-pxa3xx.h>
 
 #define        CHIP_DELAY_TIMEOUT      msecs_to_jiffies(200)
@@ -1118,7 +1113,8 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command,
 static void nand_cmdfunc(struct mtd_info *mtd, unsigned command,
                         int column, int page_addr)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        int exec_cmd;
 
@@ -1166,7 +1162,8 @@ static void nand_cmdfunc_extended(struct mtd_info *mtd,
                                  const unsigned command,
                                  int column, int page_addr)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        int exec_cmd, ext_cmd_type;
 
@@ -1286,7 +1283,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
                struct nand_chip *chip, uint8_t *buf, int oob_required,
                int page)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
 
        chip->read_buf(mtd, buf, mtd->writesize);
@@ -1312,7 +1309,8 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
 
 static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        char retval = 0xFF;
 
@@ -1325,7 +1323,8 @@ static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
 
 static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        u16 retval = 0xFFFF;
 
@@ -1338,7 +1337,8 @@ static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
 
 static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
 
@@ -1349,7 +1349,8 @@ static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
                const uint8_t *buf, int len)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
 
@@ -1364,7 +1365,8 @@ static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
 
 static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
 
        if (info->need_wait) {
@@ -1387,37 +1389,53 @@ static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
        return NAND_STATUS_READY;
 }
 
-static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info)
+static int pxa3xx_nand_config_ident(struct pxa3xx_nand_info *info)
 {
+       struct pxa3xx_nand_host *host = info->host[info->cs];
        struct platform_device *pdev = info->pdev;
        struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
-       struct pxa3xx_nand_host *host = info->host[info->cs];
-       struct mtd_info *mtd = host->mtd;
-       struct nand_chip *chip = mtd->priv;
+       const struct nand_sdr_timings *timings;
 
-       /* configure default flash values */
+       /* Configure default flash values */
+       info->chunk_size = PAGE_CHUNK_SIZE;
        info->reg_ndcr = 0x0; /* enable all interrupts */
        info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
        info->reg_ndcr |= NDCR_RD_ID_CNT(READ_ID_BYTES);
-       info->reg_ndcr |= NDCR_SPARE_EN; /* enable spare by default */
+       info->reg_ndcr |= NDCR_SPARE_EN;
+
+       /* use the common timing to make a try */
+       timings = onfi_async_timing_mode_to_sdr_timings(0);
+       if (IS_ERR(timings))
+               return PTR_ERR(timings);
+
+       pxa3xx_nand_set_sdr_timing(host, timings);
+       return 0;
+}
+
+static void pxa3xx_nand_config_tail(struct pxa3xx_nand_info *info)
+{
+       struct pxa3xx_nand_host *host = info->host[info->cs];
+       struct mtd_info *mtd = host->mtd;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
        info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
        info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0;
        info->reg_ndcr |= (mtd->writesize == 2048) ? NDCR_PAGE_SZ : 0;
-
-       return 0;
 }
 
-static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
+static void pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
 {
+       struct platform_device *pdev = info->pdev;
+       struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
        uint32_t ndcr = nand_readl(info, NDCR);
 
        /* Set an initial chunk size */
        info->chunk_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
        info->reg_ndcr = ndcr &
                ~(NDCR_INT_MASK | NDCR_ND_ARB_EN | NFCV1_NDCR_ARB_CNTL);
+       info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
        info->ndtr0cs0 = nand_readl(info, NDTR0CS0);
        info->ndtr1cs0 = nand_readl(info, NDTR1CS0);
-       return 0;
 }
 
 static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
@@ -1483,32 +1501,6 @@ static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info)
        kfree(info->data_buff);
 }
 
-static int pxa3xx_nand_sensing(struct pxa3xx_nand_host *host)
-{
-       struct pxa3xx_nand_info *info = host->info_data;
-       struct mtd_info *mtd;
-       struct nand_chip *chip;
-       const struct nand_sdr_timings *timings;
-       int ret;
-
-       mtd = info->host[info->cs]->mtd;
-       chip = mtd->priv;
-
-       /* use the common timing to make a try */
-       timings = onfi_async_timing_mode_to_sdr_timings(0);
-       if (IS_ERR(timings))
-               return PTR_ERR(timings);
-
-       pxa3xx_nand_set_sdr_timing(host, timings);
-
-       chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0);
-       ret = chip->waitfunc(mtd, chip);
-       if (ret & NAND_STATUS_FAIL)
-               return -ENODEV;
-
-       return 0;
-}
-
 static int pxa_ecc_init(struct pxa3xx_nand_info *info,
                        struct nand_ecc_ctrl *ecc,
                        int strength, int ecc_stepsize, int page_size)
@@ -1580,34 +1572,22 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,
 
 static int pxa3xx_nand_scan(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = chip->priv;
        struct pxa3xx_nand_info *info = host->info_data;
        struct platform_device *pdev = info->pdev;
        struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
-       struct nand_chip *chip = mtd->priv;
        int ret;
        uint16_t ecc_strength, ecc_step;
 
-       if (pdata->keep_config && !pxa3xx_nand_detect_config(info))
-               goto KEEP_CONFIG;
-
-       /* Set a default chunk size */
-       info->chunk_size = 512;
-
-       ret = pxa3xx_nand_config_flash(info);
-       if (ret)
-               return ret;
-
-       ret = pxa3xx_nand_sensing(host);
-       if (ret) {
-               dev_info(&info->pdev->dev, "There is no chip on cs %d!\n",
-                        info->cs);
-
-               return ret;
+       if (pdata->keep_config) {
+               pxa3xx_nand_detect_config(info);
+       } else {
+               ret = pxa3xx_nand_config_ident(info);
+               if (ret)
+                       return ret;
        }
 
-KEEP_CONFIG:
-       info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
        if (info->reg_ndcr & NDCR_DWIDTH_M)
                chip->options |= NAND_BUSWIDTH_16;
 
@@ -1692,11 +1672,16 @@ KEEP_CONFIG:
                host->row_addr_cycles = 3;
        else
                host->row_addr_cycles = 2;
+
+       if (!pdata->keep_config)
+               pxa3xx_nand_config_tail(info);
+
        return nand_scan_tail(mtd);
 }
 
 static int alloc_nand_resource(struct platform_device *pdev)
 {
+       struct device_node *np = pdev->dev.of_node;
        struct pxa3xx_nand_platform_data *pdata;
        struct pxa3xx_nand_info *info;
        struct pxa3xx_nand_host *host;
@@ -1723,9 +1708,12 @@ static int alloc_nand_resource(struct platform_device *pdev)
                host->mtd = mtd;
                host->cs = cs;
                host->info_data = info;
-               mtd->priv = host;
+               mtd->priv = chip;
                mtd->dev.parent = &pdev->dev;
+               /* FIXME: all chips use the same device tree partitions */
+               nand_set_flash_node(chip, np);
 
+               chip->priv = host;
                chip->ecc.read_page     = pxa3xx_nand_read_page_hwecc;
                chip->ecc.write_page    = pxa3xx_nand_write_page_hwecc;
                chip->controller        = &info->controller;
@@ -1886,7 +1874,6 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)
 static int pxa3xx_nand_probe(struct platform_device *pdev)
 {
        struct pxa3xx_nand_platform_data *pdata;
-       struct mtd_part_parser_data ppdata = {};
        struct pxa3xx_nand_info *info;
        int ret, cs, probe_success, dma_available;
 
@@ -1933,10 +1920,8 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
                        continue;
                }
 
-               ppdata.of_node = pdev->dev.of_node;
-               ret = mtd_device_parse_register(mtd, NULL,
-                                               &ppdata, pdata->parts[cs],
-                                               pdata->nr_parts[cs]);
+               ret = mtd_device_register(mtd, pdata->parts[cs],
+                                         pdata->nr_parts[cs]);
                if (!ret)
                        probe_success = 1;
        }
@@ -1959,12 +1944,18 @@ static int pxa3xx_nand_suspend(struct device *dev)
                return -EAGAIN;
        }
 
+       clk_disable(info->clk);
        return 0;
 }
 
 static int pxa3xx_nand_resume(struct device *dev)
 {
        struct pxa3xx_nand_info *info = dev_get_drvdata(dev);
+       int ret;
+
+       ret = clk_enable(info->clk);
+       if (ret < 0)
+               return ret;
 
        /* We don't want to handle interrupt without calling mtd routine */
        disable_int(info, NDCR_INT_MASK);
index d8bb2be..ca05b20 100644 (file)
@@ -64,7 +64,7 @@ static inline void r852_write_reg_dword(struct r852_device *dev,
 /* returns pointer to our private structure */
 static inline struct r852_device *r852_get_dev(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return chip->priv;
 }
 
@@ -980,7 +980,6 @@ static void r852_remove(struct pci_dev *pci_dev)
 
        /* Stop interrupts */
        r852_disable_irqs(dev);
-       synchronize_irq(dev->irq);
        free_irq(dev->irq, dev);
 
        /* Cleanup */
index 05105ca..e658b29 100644 (file)
@@ -382,7 +382,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
 {
        struct s3c2410_nand_info *info;
        struct s3c2410_nand_mtd *nmtd;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long cur;
 
        nmtd = this->priv;
@@ -634,7 +634,7 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
 
 static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        readsb(this->IO_ADDR_R, buf, len);
 }
 
@@ -656,7 +656,7 @@ static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf,
                                   int len)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        writesb(this->IO_ADDR_W, buf, len);
 }
 
index bcba1a9..57dc525 100644 (file)
@@ -1086,7 +1086,6 @@ static int flctl_probe(struct platform_device *pdev)
        struct sh_flctl_platform_data *pdata;
        int ret;
        int irq;
-       struct mtd_part_parser_data ppdata = {};
 
        flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL);
        if (!flctl)
@@ -1123,6 +1122,7 @@ static int flctl_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, flctl);
        flctl_mtd = &flctl->mtd;
        nand = &flctl->chip;
+       nand_set_flash_node(nand, pdev->dev.of_node);
        flctl_mtd->priv = nand;
        flctl_mtd->dev.parent = &pdev->dev;
        flctl->pdev = pdev;
@@ -1163,9 +1163,7 @@ static int flctl_probe(struct platform_device *pdev)
        if (ret)
                goto err_chip;
 
-       ppdata.of_node = pdev->dev.of_node;
-       ret = mtd_device_parse_register(flctl_mtd, NULL, &ppdata, pdata->parts,
-                       pdata->nr_parts);
+       ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
 
        return 0;
 
index 082b600..84129e5 100644 (file)
@@ -66,7 +66,7 @@ static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd,
                                   unsigned int ctrl)
 {
        struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (ctrl & NAND_CTRL_CHANGE) {
                unsigned char bits = ctrl & 0x07;
index e06b5e5..c514740 100644 (file)
@@ -102,7 +102,7 @@ static struct nand_flash_dev nand_xd_flash_ids[] = {
 
 int sm_register_device(struct mtd_info *mtd, int smartmedia)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret;
 
        chip->options |= NAND_SKIP_BBTSCAN;
index b94f534..2dfb1e0 100644 (file)
@@ -45,7 +45,7 @@ static void socrates_nand_write_buf(struct mtd_info *mtd,
                const uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct socrates_nand_host *host = this->priv;
 
        for (i = 0; i < len; i++) {
@@ -64,7 +64,7 @@ static void socrates_nand_write_buf(struct mtd_info *mtd,
 static void socrates_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
        int i;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct socrates_nand_host *host = this->priv;
        uint32_t val;
 
@@ -105,7 +105,7 @@ static uint16_t socrates_nand_read_word(struct mtd_info *mtd)
 static void socrates_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
                unsigned int ctrl)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct socrates_nand_host *host = nand_chip->priv;
        uint32_t val;
 
@@ -130,7 +130,7 @@ static void socrates_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  */
 static int socrates_nand_device_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct socrates_nand_host *host = nand_chip->priv;
 
        if (in_be32(host->io_base) & FPGA_NAND_BUSY)
@@ -147,7 +147,6 @@ static int socrates_nand_probe(struct platform_device *ofdev)
        struct mtd_info *mtd;
        struct nand_chip *nand_chip;
        int res;
-       struct mtd_part_parser_data ppdata;
 
        /* Allocate memory for the device structure (and zero it) */
        host = devm_kzalloc(&ofdev->dev, sizeof(*host), GFP_KERNEL);
@@ -165,10 +164,10 @@ static int socrates_nand_probe(struct platform_device *ofdev)
        host->dev = &ofdev->dev;
 
        nand_chip->priv = host;         /* link the private data structures */
+       nand_set_flash_node(nand_chip, ofdev->dev.of_node);
        mtd->priv = nand_chip;
        mtd->name = "socrates_nand";
        mtd->dev.parent = &ofdev->dev;
-       ppdata.of_node = ofdev->dev.of_node;
 
        /*should never be accessed directly */
        nand_chip->IO_ADDR_R = (void *)0xdeadbeef;
@@ -200,7 +199,7 @@ static int socrates_nand_probe(struct platform_device *ofdev)
                goto out;
        }
 
-       res = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       res = mtd_device_register(mtd, NULL, 0);
        if (!res)
                return res;
 
index 8247118..4ecd486 100644 (file)
@@ -350,7 +350,7 @@ static int sunxi_nfc_rst(struct sunxi_nfc *nfc)
 
 static int sunxi_nfc_dev_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        struct sunxi_nand_rb *rb;
@@ -388,7 +388,7 @@ static int sunxi_nfc_dev_ready(struct mtd_info *mtd)
 
 static void sunxi_nfc_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        struct sunxi_nand_chip_sel *sel;
@@ -433,7 +433,7 @@ static void sunxi_nfc_select_chip(struct mtd_info *mtd, int chip)
 
 static void sunxi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        int ret;
@@ -466,7 +466,7 @@ static void sunxi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void sunxi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf,
                                int len)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        int ret;
@@ -507,7 +507,7 @@ static uint8_t sunxi_nfc_read_byte(struct mtd_info *mtd)
 static void sunxi_nfc_cmd_ctrl(struct mtd_info *mtd, int dat,
                               unsigned int ctrl)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        int ret;
@@ -541,7 +541,7 @@ static void sunxi_nfc_cmd_ctrl(struct mtd_info *mtd, int dat,
 
 static void sunxi_nfc_hw_ecc_enable(struct mtd_info *mtd)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
        struct sunxi_nand_hw_ecc *data = nand->ecc.priv;
        u32 ecc_ctl;
@@ -556,7 +556,7 @@ static void sunxi_nfc_hw_ecc_enable(struct mtd_info *mtd)
 
 static void sunxi_nfc_hw_ecc_disable(struct mtd_info *mtd)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
 
        writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN,
@@ -577,7 +577,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                                       int *cur_off,
                                       unsigned int *max_bitflips)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        u32 status;
@@ -638,7 +638,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
 static void sunxi_nfc_hw_ecc_read_extra_oob(struct mtd_info *mtd,
                                            u8 *oob, int *cur_off)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        int offset = ((ecc->bytes + 4) * ecc->steps);
        int len = mtd->oobsize - offset;
@@ -665,7 +665,7 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
                                        const u8 *oob, int oob_off,
                                        int *cur_off)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        int ret;
@@ -702,7 +702,7 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
 static void sunxi_nfc_hw_ecc_write_extra_oob(struct mtd_info *mtd,
                                             u8 *oob, int *cur_off)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        int offset = ((ecc->bytes + 4) * ecc->steps);
        int len = mtd->oobsize - offset;
@@ -1031,7 +1031,7 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
                                              struct device_node *np)
 {
        static const u8 strengths[] = { 16, 24, 28, 32, 40, 48, 56, 60, 64 };
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        struct sunxi_nand_hw_ecc *data;
@@ -1189,7 +1189,7 @@ static void sunxi_nand_ecc_cleanup(struct nand_ecc_ctrl *ecc)
 static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
                               struct device_node *np)
 {
-       struct nand_chip *nand = mtd->priv;
+       struct nand_chip *nand = mtd_to_nand(mtd);
        int ret;
 
        if (!ecc->size) {
@@ -1232,7 +1232,6 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
 {
        const struct nand_sdr_timings *timings;
        struct sunxi_nand_chip *chip;
-       struct mtd_part_parser_data ppdata;
        struct mtd_info *mtd;
        struct nand_chip *nand;
        int nsels;
@@ -1330,7 +1329,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
         * in the DT.
         */
        nand->ecc.mode = NAND_ECC_HW;
-       nand->flash_node = np;
+       nand_set_flash_node(nand, np);
        nand->select_chip = sunxi_nfc_select_chip;
        nand->cmd_ctrl = sunxi_nfc_cmd_ctrl;
        nand->read_buf = sunxi_nfc_read_buf;
@@ -1366,8 +1365,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
                return ret;
        }
 
-       ppdata.of_node = np;
-       ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(mtd, NULL, 0);
        if (ret) {
                dev_err(dev, "failed to register mtd device: %d\n", ret);
                nand_release(mtd);
@@ -1393,8 +1391,10 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc)
 
        for_each_child_of_node(np, nand_np) {
                ret = sunxi_nand_chip_init(dev, nfc, nand_np);
-               if (ret)
+               if (ret) {
+                       of_node_put(nand_np);
                        return ret;
+               }
        }
 
        return 0;
index befddf0..6d0cbe9 100644 (file)
@@ -128,7 +128,7 @@ static void tmio_nand_hwcontrol(struct mtd_info *mtd, int cmd,
                                   unsigned int ctrl)
 {
        struct tmio_nand *tmio = mtd_to_tmio(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (ctrl & NAND_CTRL_CHANGE) {
                u8 mode;
index 8572519..ff9afb1 100644 (file)
@@ -79,7 +79,7 @@ struct txx9ndfmc_drvdata {
 
 static struct platform_device *mtd_to_platdev(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct txx9ndfmc_priv *txx9_priv = chip->priv;
        return txx9_priv->dev;
 }
@@ -135,7 +135,7 @@ static void txx9ndfmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void txx9ndfmc_cmd_ctrl(struct mtd_info *mtd, int cmd,
                               unsigned int ctrl)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct txx9ndfmc_priv *txx9_priv = chip->priv;
        struct platform_device *dev = txx9_priv->dev;
        struct txx9ndfmc_platform_data *plat = dev_get_platdata(&dev->dev);
@@ -175,7 +175,7 @@ static int txx9ndfmc_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
                                   uint8_t *ecc_code)
 {
        struct platform_device *dev = mtd_to_platdev(mtd);
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int eccbytes;
        u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR);
 
@@ -195,7 +195,7 @@ static int txx9ndfmc_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
 static int txx9ndfmc_correct_data(struct mtd_info *mtd, unsigned char *buf,
                unsigned char *read_ecc, unsigned char *calc_ecc)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int eccsize;
        int corrected = 0;
        int stat;
@@ -257,7 +257,7 @@ static void txx9ndfmc_initialize(struct platform_device *dev)
 
 static int txx9ndfmc_nand_scan(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret;
 
        ret = nand_scan_ident(mtd, 1, NULL);
@@ -391,7 +391,7 @@ static int __exit txx9ndfmc_remove(struct platform_device *dev)
 
                if (!mtd)
                        continue;
-               chip = mtd->priv;
+               chip = mtd_to_nand(mtd);
                txx9_priv = chip->priv;
 
                nand_release(mtd);
index 8805d63..1c86c6b 100644 (file)
@@ -707,18 +707,18 @@ static int vf610_nfc_probe(struct platform_device *pdev)
        for_each_available_child_of_node(nfc->dev->of_node, child) {
                if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) {
 
-                       if (chip->flash_node) {
+                       if (nand_get_flash_node(chip)) {
                                dev_err(nfc->dev,
                                        "Only one NAND chip supported!\n");
                                err = -EINVAL;
                                goto error;
                        }
 
-                       chip->flash_node = child;
+                       nand_set_flash_node(chip, child);
                }
        }
 
-       if (!chip->flash_node) {
+       if (!nand_get_flash_node(chip)) {
                dev_err(nfc->dev, "NAND chip sub-node missing!\n");
                err = -ENODEV;
                goto err_clk;
@@ -811,14 +811,10 @@ static int vf610_nfc_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, mtd);
 
        /* Register device in MTD */
-       return mtd_device_parse_register(mtd, NULL,
-               &(struct mtd_part_parser_data){
-                       .of_node = chip->flash_node,
-               },
-               NULL, 0);
+       return mtd_device_register(mtd, NULL, 0);
 
 error:
-       of_node_put(chip->flash_node);
+       of_node_put(nand_get_flash_node(chip));
 err_clk:
        clk_disable_unprepare(nfc->clk);
        return err;
index 3b28db4..0cf0ac0 100644 (file)
@@ -89,7 +89,7 @@ static void xway_select_chip(struct mtd_info *mtd, int chip)
 
 static void xway_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
        unsigned long flags;
 
@@ -118,7 +118,7 @@ static int xway_dev_ready(struct mtd_info *mtd)
 
 static unsigned char xway_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        unsigned long nandaddr = (unsigned long) this->IO_ADDR_R;
        unsigned long flags;
        int ret;
index 9ed6038..9046451 100644 (file)
@@ -37,10 +37,8 @@ static int parse_ofpart_partitions(struct mtd_info *master,
        bool dedicated = true;
 
 
-       if (!data)
-               return 0;
-
-       mtd_node = data->of_node;
+       /* Pull of_node from the master device node */
+       mtd_node = mtd_get_of_node(master);
        if (!mtd_node)
                return 0;
 
@@ -141,7 +139,6 @@ ofpart_none:
 }
 
 static struct mtd_part_parser ofpart_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = parse_ofpart_partitions,
        .name = "ofpart",
 };
@@ -157,10 +154,8 @@ static int parse_ofoldpart_partitions(struct mtd_info *master,
        } *part;
        const char *names;
 
-       if (!data)
-               return 0;
-
-       dp = data->of_node;
+       /* Pull of_node from the master device node */
+       dp = mtd_get_of_node(master);
        if (!dp)
                return 0;
 
@@ -203,7 +198,6 @@ static int parse_ofoldpart_partitions(struct mtd_info *master,
 }
 
 static struct mtd_part_parser ofoldpart_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = parse_ofoldpart_partitions,
        .name = "ofoldpart",
 };
index 3e02856..0aacf12 100644 (file)
@@ -614,7 +614,6 @@ static int omap2_onenand_probe(struct platform_device *pdev)
        struct onenand_chip *this;
        int r;
        struct resource *res;
-       struct mtd_part_parser_data ppdata = {};
 
        pdata = dev_get_platdata(&pdev->dev);
        if (pdata == NULL) {
@@ -713,6 +712,7 @@ static int omap2_onenand_probe(struct platform_device *pdev)
        c->mtd.priv = &c->onenand;
 
        c->mtd.dev.parent = &pdev->dev;
+       mtd_set_of_node(&c->mtd, pdata->of_node);
 
        this = &c->onenand;
        if (c->dma_channel >= 0) {
@@ -743,10 +743,8 @@ static int omap2_onenand_probe(struct platform_device *pdev)
        if ((r = onenand_scan(&c->mtd, 1)) < 0)
                goto err_release_regulator;
 
-       ppdata.of_node = pdata->of_node;
-       r = mtd_device_parse_register(&c->mtd, NULL, &ppdata,
-                                     pdata ? pdata->parts : NULL,
-                                     pdata ? pdata->nr_parts : 0);
+       r = mtd_device_register(&c->mtd, pdata ? pdata->parts : NULL,
+                               pdata ? pdata->nr_parts : 0);
        if (r)
                goto err_release_onenand;
 
index 5da911e..11c3447 100644 (file)
@@ -290,28 +290,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
 }
 
 static struct mtd_part_parser redboot_parser = {
-       .owner = THIS_MODULE,
        .parse_fn = parse_redboot_partitions,
        .name = "RedBoot",
 };
+module_mtd_part_parser(redboot_parser);
 
 /* mtd parsers will request the module by parser name */
 MODULE_ALIAS("RedBoot");
-
-static int __init redboot_parser_init(void)
-{
-       register_mtd_parser(&redboot_parser);
-       return 0;
-}
-
-static void __exit redboot_parser_exit(void)
-{
-       deregister_mtd_parser(&redboot_parser);
-}
-
-module_init(redboot_parser_init);
-module_exit(redboot_parser_exit);
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
 MODULE_DESCRIPTION("Parsing code for RedBoot Flash Image System (FIS) tables");
index c23184a..b096f8b 100644 (file)
@@ -206,9 +206,10 @@ static loff_t sm_mkoffset(struct sm_ftl *ftl, int zone, int block, int boffset)
 }
 
 /* Breaks offset into parts */
-static void sm_break_offset(struct sm_ftl *ftl, loff_t offset,
+static void sm_break_offset(struct sm_ftl *ftl, loff_t loffset,
                            int *zone, int *block, int *boffset)
 {
+       u64 offset = loffset;
        *boffset = do_div(offset, ftl->block_size);
        *block = do_div(offset, ftl->max_lba);
        *zone = offset >= ftl->zone_count ? -1 : offset;
index 2fe2a7e..0dc9275 100644 (file)
@@ -7,6 +7,13 @@ menuconfig MTD_SPI_NOR
 
 if MTD_SPI_NOR
 
+config MTD_MT81xx_NOR
+       tristate "Mediatek MT81xx SPI NOR flash controller"
+       help
+         This enables access to SPI NOR flash, using MT81xx SPI NOR flash
+         controller. This controller does not support generic SPI BUS, it only
+         supports SPI NOR Flash.
+
 config MTD_SPI_NOR_USE_4K_SECTORS
        bool "Use small 4096 B erase sectors"
        default y
index e53333e..0bf3a7f 100644 (file)
@@ -1,3 +1,4 @@
 obj-$(CONFIG_MTD_SPI_NOR)      += spi-nor.o
 obj-$(CONFIG_SPI_FSL_QUADSPI)  += fsl-quadspi.o
+obj-$(CONFIG_MTD_MT81xx_NOR)    += mtk-quadspi.o
 obj-$(CONFIG_SPI_NXP_SPIFI)    += nxp-spifi.o
index 7b10ed4..54640f1 100644 (file)
@@ -269,7 +269,7 @@ struct fsl_qspi {
        struct clk *clk, *clk_en;
        struct device *dev;
        struct completion c;
-       struct fsl_qspi_devtype_data *devtype_data;
+       const struct fsl_qspi_devtype_data *devtype_data;
        u32 nor_size;
        u32 nor_num;
        u32 clk_rate;
@@ -927,15 +927,12 @@ static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
 static int fsl_qspi_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
-       struct mtd_part_parser_data ppdata;
        struct device *dev = &pdev->dev;
        struct fsl_qspi *q;
        struct resource *res;
        struct spi_nor *nor;
        struct mtd_info *mtd;
        int ret, i = 0;
-       const struct of_device_id *of_id =
-                       of_match_device(fsl_qspi_dt_ids, &pdev->dev);
 
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -946,7 +943,9 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                return -ENODEV;
 
        q->dev = dev;
-       q->devtype_data = (struct fsl_qspi_devtype_data *)of_id->data;
+       q->devtype_data = of_device_get_match_data(dev);
+       if (!q->devtype_data)
+               return -ENODEV;
        platform_set_drvdata(pdev, q);
 
        /* find the resources */
@@ -1013,7 +1012,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                mtd = &nor->mtd;
 
                nor->dev = dev;
-               nor->flash_node = np;
+               spi_nor_set_flash_node(nor, np);
                nor->priv = q;
 
                /* fill the hooks */
@@ -1038,8 +1037,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                if (ret)
                        goto mutex_failed;
 
-               ppdata.of_node = np;
-               ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+               ret = mtd_device_register(mtd, NULL, 0);
                if (ret)
                        goto mutex_failed;
 
diff --git a/drivers/mtd/spi-nor/mtk-quadspi.c b/drivers/mtd/spi-nor/mtk-quadspi.c
new file mode 100644 (file)
index 0000000..e1dd9fd
--- /dev/null
@@ -0,0 +1,485 @@
+/*
+ * Copyright (c) 2015 MediaTek Inc.
+ * Author: Bayi Cheng <bayi.cheng@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/ioport.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/spi-nor.h>
+
+#define MTK_NOR_CMD_REG                        0x00
+#define MTK_NOR_CNT_REG                        0x04
+#define MTK_NOR_RDSR_REG               0x08
+#define MTK_NOR_RDATA_REG              0x0c
+#define MTK_NOR_RADR0_REG              0x10
+#define MTK_NOR_RADR1_REG              0x14
+#define MTK_NOR_RADR2_REG              0x18
+#define MTK_NOR_WDATA_REG              0x1c
+#define MTK_NOR_PRGDATA0_REG           0x20
+#define MTK_NOR_PRGDATA1_REG           0x24
+#define MTK_NOR_PRGDATA2_REG           0x28
+#define MTK_NOR_PRGDATA3_REG           0x2c
+#define MTK_NOR_PRGDATA4_REG           0x30
+#define MTK_NOR_PRGDATA5_REG           0x34
+#define MTK_NOR_SHREG0_REG             0x38
+#define MTK_NOR_SHREG1_REG             0x3c
+#define MTK_NOR_SHREG2_REG             0x40
+#define MTK_NOR_SHREG3_REG             0x44
+#define MTK_NOR_SHREG4_REG             0x48
+#define MTK_NOR_SHREG5_REG             0x4c
+#define MTK_NOR_SHREG6_REG             0x50
+#define MTK_NOR_SHREG7_REG             0x54
+#define MTK_NOR_SHREG8_REG             0x58
+#define MTK_NOR_SHREG9_REG             0x5c
+#define MTK_NOR_CFG1_REG               0x60
+#define MTK_NOR_CFG2_REG               0x64
+#define MTK_NOR_CFG3_REG               0x68
+#define MTK_NOR_STATUS0_REG            0x70
+#define MTK_NOR_STATUS1_REG            0x74
+#define MTK_NOR_STATUS2_REG            0x78
+#define MTK_NOR_STATUS3_REG            0x7c
+#define MTK_NOR_FLHCFG_REG             0x84
+#define MTK_NOR_TIME_REG               0x94
+#define MTK_NOR_PP_DATA_REG            0x98
+#define MTK_NOR_PREBUF_STUS_REG                0x9c
+#define MTK_NOR_DELSEL0_REG            0xa0
+#define MTK_NOR_DELSEL1_REG            0xa4
+#define MTK_NOR_INTRSTUS_REG           0xa8
+#define MTK_NOR_INTREN_REG             0xac
+#define MTK_NOR_CHKSUM_CTL_REG         0xb8
+#define MTK_NOR_CHKSUM_REG             0xbc
+#define MTK_NOR_CMD2_REG               0xc0
+#define MTK_NOR_WRPROT_REG             0xc4
+#define MTK_NOR_RADR3_REG              0xc8
+#define MTK_NOR_DUAL_REG               0xcc
+#define MTK_NOR_DELSEL2_REG            0xd0
+#define MTK_NOR_DELSEL3_REG            0xd4
+#define MTK_NOR_DELSEL4_REG            0xd8
+
+/* commands for mtk nor controller */
+#define MTK_NOR_READ_CMD               0x0
+#define MTK_NOR_RDSR_CMD               0x2
+#define MTK_NOR_PRG_CMD                        0x4
+#define MTK_NOR_WR_CMD                 0x10
+#define MTK_NOR_PIO_WR_CMD             0x90
+#define MTK_NOR_WRSR_CMD               0x20
+#define MTK_NOR_PIO_READ_CMD           0x81
+#define MTK_NOR_WR_BUF_ENABLE          0x1
+#define MTK_NOR_WR_BUF_DISABLE         0x0
+#define MTK_NOR_ENABLE_SF_CMD          0x30
+#define MTK_NOR_DUAD_ADDR_EN           0x8
+#define MTK_NOR_QUAD_READ_EN           0x4
+#define MTK_NOR_DUAL_ADDR_EN           0x2
+#define MTK_NOR_DUAL_READ_EN           0x1
+#define MTK_NOR_DUAL_DISABLE           0x0
+#define MTK_NOR_FAST_READ              0x1
+
+#define SFLASH_WRBUF_SIZE              128
+
+/* Can shift up to 48 bits (6 bytes) of TX/RX */
+#define MTK_NOR_MAX_RX_TX_SHIFT                6
+/* can shift up to 56 bits (7 bytes) transfer by MTK_NOR_PRG_CMD */
+#define MTK_NOR_MAX_SHIFT              7
+
+/* Helpers for accessing the program data / shift data registers */
+#define MTK_NOR_PRG_REG(n)             (MTK_NOR_PRGDATA0_REG + 4 * (n))
+#define MTK_NOR_SHREG(n)               (MTK_NOR_SHREG0_REG + 4 * (n))
+
+struct mt8173_nor {
+       struct spi_nor nor;
+       struct device *dev;
+       void __iomem *base;     /* nor flash base address */
+       struct clk *spi_clk;
+       struct clk *nor_clk;
+};
+
+static void mt8173_nor_set_read_mode(struct mt8173_nor *mt8173_nor)
+{
+       struct spi_nor *nor = &mt8173_nor->nor;
+
+       switch (nor->flash_read) {
+       case SPI_NOR_FAST:
+               writeb(nor->read_opcode, mt8173_nor->base +
+                      MTK_NOR_PRGDATA3_REG);
+               writeb(MTK_NOR_FAST_READ, mt8173_nor->base +
+                      MTK_NOR_CFG1_REG);
+               break;
+       case SPI_NOR_DUAL:
+               writeb(nor->read_opcode, mt8173_nor->base +
+                      MTK_NOR_PRGDATA3_REG);
+               writeb(MTK_NOR_DUAL_READ_EN, mt8173_nor->base +
+                      MTK_NOR_DUAL_REG);
+               break;
+       case SPI_NOR_QUAD:
+               writeb(nor->read_opcode, mt8173_nor->base +
+                      MTK_NOR_PRGDATA4_REG);
+               writeb(MTK_NOR_QUAD_READ_EN, mt8173_nor->base +
+                      MTK_NOR_DUAL_REG);
+               break;
+       default:
+               writeb(MTK_NOR_DUAL_DISABLE, mt8173_nor->base +
+                      MTK_NOR_DUAL_REG);
+               break;
+       }
+}
+
+static int mt8173_nor_execute_cmd(struct mt8173_nor *mt8173_nor, u8 cmdval)
+{
+       int reg;
+       u8 val = cmdval & 0x1f;
+
+       writeb(cmdval, mt8173_nor->base + MTK_NOR_CMD_REG);
+       return readl_poll_timeout(mt8173_nor->base + MTK_NOR_CMD_REG, reg,
+                                 !(reg & val), 100, 10000);
+}
+
+static int mt8173_nor_do_tx_rx(struct mt8173_nor *mt8173_nor, u8 op,
+                              u8 *tx, int txlen, u8 *rx, int rxlen)
+{
+       int len = 1 + txlen + rxlen;
+       int i, ret, idx;
+
+       if (len > MTK_NOR_MAX_SHIFT)
+               return -EINVAL;
+
+       writeb(len * 8, mt8173_nor->base + MTK_NOR_CNT_REG);
+
+       /* start at PRGDATA5, go down to PRGDATA0 */
+       idx = MTK_NOR_MAX_RX_TX_SHIFT - 1;
+
+       /* opcode */
+       writeb(op, mt8173_nor->base + MTK_NOR_PRG_REG(idx));
+       idx--;
+
+       /* program TX data */
+       for (i = 0; i < txlen; i++, idx--)
+               writeb(tx[i], mt8173_nor->base + MTK_NOR_PRG_REG(idx));
+
+       /* clear out rest of TX registers */
+       while (idx >= 0) {
+               writeb(0, mt8173_nor->base + MTK_NOR_PRG_REG(idx));
+               idx--;
+       }
+
+       ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PRG_CMD);
+       if (ret)
+               return ret;
+
+       /* restart at first RX byte */
+       idx = rxlen - 1;
+
+       /* read out RX data */
+       for (i = 0; i < rxlen; i++, idx--)
+               rx[i] = readb(mt8173_nor->base + MTK_NOR_SHREG(idx));
+
+       return 0;
+}
+
+/* Do a WRSR (Write Status Register) command */
+static int mt8173_nor_wr_sr(struct mt8173_nor *mt8173_nor, u8 sr)
+{
+       writeb(sr, mt8173_nor->base + MTK_NOR_PRGDATA5_REG);
+       writeb(8, mt8173_nor->base + MTK_NOR_CNT_REG);
+       return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WRSR_CMD);
+}
+
+static int mt8173_nor_write_buffer_enable(struct mt8173_nor *mt8173_nor)
+{
+       u8 reg;
+
+       /* the bit0 of MTK_NOR_CFG2_REG is pre-fetch buffer
+        * 0: pre-fetch buffer use for read
+        * 1: pre-fetch buffer use for page program
+        */
+       writel(MTK_NOR_WR_BUF_ENABLE, mt8173_nor->base + MTK_NOR_CFG2_REG);
+       return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg,
+                                 0x01 == (reg & 0x01), 100, 10000);
+}
+
+static int mt8173_nor_write_buffer_disable(struct mt8173_nor *mt8173_nor)
+{
+       u8 reg;
+
+       writel(MTK_NOR_WR_BUF_DISABLE, mt8173_nor->base + MTK_NOR_CFG2_REG);
+       return readb_poll_timeout(mt8173_nor->base + MTK_NOR_CFG2_REG, reg,
+                                 MTK_NOR_WR_BUF_DISABLE == (reg & 0x1), 100,
+                                 10000);
+}
+
+static void mt8173_nor_set_addr(struct mt8173_nor *mt8173_nor, u32 addr)
+{
+       int i;
+
+       for (i = 0; i < 3; i++) {
+               writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR0_REG + i * 4);
+               addr >>= 8;
+       }
+       /* Last register is non-contiguous */
+       writeb(addr & 0xff, mt8173_nor->base + MTK_NOR_RADR3_REG);
+}
+
+static int mt8173_nor_read(struct spi_nor *nor, loff_t from, size_t length,
+                          size_t *retlen, u_char *buffer)
+{
+       int i, ret;
+       int addr = (int)from;
+       u8 *buf = (u8 *)buffer;
+       struct mt8173_nor *mt8173_nor = nor->priv;
+
+       /* set mode for fast read mode ,dual mode or quad mode */
+       mt8173_nor_set_read_mode(mt8173_nor);
+       mt8173_nor_set_addr(mt8173_nor, addr);
+
+       for (i = 0; i < length; i++, (*retlen)++) {
+               ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_READ_CMD);
+               if (ret < 0)
+                       return ret;
+               buf[i] = readb(mt8173_nor->base + MTK_NOR_RDATA_REG);
+       }
+       return 0;
+}
+
+static int mt8173_nor_write_single_byte(struct mt8173_nor *mt8173_nor,
+                                       int addr, int length, u8 *data)
+{
+       int i, ret;
+
+       mt8173_nor_set_addr(mt8173_nor, addr);
+
+       for (i = 0; i < length; i++) {
+               ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_PIO_WR_CMD);
+               if (ret < 0)
+                       return ret;
+               writeb(*data++, mt8173_nor->base + MTK_NOR_WDATA_REG);
+       }
+       return 0;
+}
+
+static int mt8173_nor_write_buffer(struct mt8173_nor *mt8173_nor, int addr,
+                                  const u8 *buf)
+{
+       int i, bufidx, data;
+
+       mt8173_nor_set_addr(mt8173_nor, addr);
+
+       bufidx = 0;
+       for (i = 0; i < SFLASH_WRBUF_SIZE; i += 4) {
+               data = buf[bufidx + 3]<<24 | buf[bufidx + 2]<<16 |
+                      buf[bufidx + 1]<<8 | buf[bufidx];
+               bufidx += 4;
+               writel(data, mt8173_nor->base + MTK_NOR_PP_DATA_REG);
+       }
+       return mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_WR_CMD);
+}
+
+static void mt8173_nor_write(struct spi_nor *nor, loff_t to, size_t len,
+                            size_t *retlen, const u_char *buf)
+{
+       int ret;
+       struct mt8173_nor *mt8173_nor = nor->priv;
+
+       ret = mt8173_nor_write_buffer_enable(mt8173_nor);
+       if (ret < 0)
+               dev_warn(mt8173_nor->dev, "write buffer enable failed!\n");
+
+       while (len >= SFLASH_WRBUF_SIZE) {
+               ret = mt8173_nor_write_buffer(mt8173_nor, to, buf);
+               if (ret < 0)
+                       dev_err(mt8173_nor->dev, "write buffer failed!\n");
+               len -= SFLASH_WRBUF_SIZE;
+               to += SFLASH_WRBUF_SIZE;
+               buf += SFLASH_WRBUF_SIZE;
+               (*retlen) += SFLASH_WRBUF_SIZE;
+       }
+       ret = mt8173_nor_write_buffer_disable(mt8173_nor);
+       if (ret < 0)
+               dev_warn(mt8173_nor->dev, "write buffer disable failed!\n");
+
+       if (len) {
+               ret = mt8173_nor_write_single_byte(mt8173_nor, to, (int)len,
+                                                  (u8 *)buf);
+               if (ret < 0)
+                       dev_err(mt8173_nor->dev, "write single byte failed!\n");
+               (*retlen) += len;
+       }
+}
+
+static int mt8173_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
+{
+       int ret;
+       struct mt8173_nor *mt8173_nor = nor->priv;
+
+       switch (opcode) {
+       case SPINOR_OP_RDSR:
+               ret = mt8173_nor_execute_cmd(mt8173_nor, MTK_NOR_RDSR_CMD);
+               if (ret < 0)
+                       return ret;
+               if (len == 1)
+                       *buf = readb(mt8173_nor->base + MTK_NOR_RDSR_REG);
+               else
+                       dev_err(mt8173_nor->dev, "len should be 1 for read status!\n");
+               break;
+       default:
+               ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, NULL, 0, buf, len);
+               break;
+       }
+       return ret;
+}
+
+static int mt8173_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
+                               int len)
+{
+       int ret;
+       struct mt8173_nor *mt8173_nor = nor->priv;
+
+       switch (opcode) {
+       case SPINOR_OP_WRSR:
+               /* We only handle 1 byte */
+               ret = mt8173_nor_wr_sr(mt8173_nor, *buf);
+               break;
+       default:
+               ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, buf, len, NULL, 0);
+               if (ret)
+                       dev_warn(mt8173_nor->dev, "write reg failure!\n");
+               break;
+       }
+       return ret;
+}
+
+static int __init mtk_nor_init(struct mt8173_nor *mt8173_nor,
+                              struct device_node *flash_node)
+{
+       int ret;
+       struct spi_nor *nor;
+
+       /* initialize controller to accept commands */
+       writel(MTK_NOR_ENABLE_SF_CMD, mt8173_nor->base + MTK_NOR_WRPROT_REG);
+
+       nor = &mt8173_nor->nor;
+       nor->dev = mt8173_nor->dev;
+       nor->priv = mt8173_nor;
+       spi_nor_set_flash_node(nor, flash_node);
+
+       /* fill the hooks to spi nor */
+       nor->read = mt8173_nor_read;
+       nor->read_reg = mt8173_nor_read_reg;
+       nor->write = mt8173_nor_write;
+       nor->write_reg = mt8173_nor_write_reg;
+       nor->mtd.name = "mtk_nor";
+       /* initialized with NULL */
+       ret = spi_nor_scan(nor, NULL, SPI_NOR_DUAL);
+       if (ret)
+               return ret;
+
+       return mtd_device_register(&nor->mtd, NULL, 0);
+}
+
+static int mtk_nor_drv_probe(struct platform_device *pdev)
+{
+       struct device_node *flash_np;
+       struct resource *res;
+       int ret;
+       struct mt8173_nor *mt8173_nor;
+
+       if (!pdev->dev.of_node) {
+               dev_err(&pdev->dev, "No DT found\n");
+               return -EINVAL;
+       }
+
+       mt8173_nor = devm_kzalloc(&pdev->dev, sizeof(*mt8173_nor), GFP_KERNEL);
+       if (!mt8173_nor)
+               return -ENOMEM;
+       platform_set_drvdata(pdev, mt8173_nor);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       mt8173_nor->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(mt8173_nor->base))
+               return PTR_ERR(mt8173_nor->base);
+
+       mt8173_nor->spi_clk = devm_clk_get(&pdev->dev, "spi");
+       if (IS_ERR(mt8173_nor->spi_clk))
+               return PTR_ERR(mt8173_nor->spi_clk);
+
+       mt8173_nor->nor_clk = devm_clk_get(&pdev->dev, "sf");
+       if (IS_ERR(mt8173_nor->nor_clk))
+               return PTR_ERR(mt8173_nor->nor_clk);
+
+       mt8173_nor->dev = &pdev->dev;
+       ret = clk_prepare_enable(mt8173_nor->spi_clk);
+       if (ret)
+               return ret;
+
+       ret = clk_prepare_enable(mt8173_nor->nor_clk);
+       if (ret) {
+               clk_disable_unprepare(mt8173_nor->spi_clk);
+               return ret;
+       }
+       /* only support one attached flash */
+       flash_np = of_get_next_available_child(pdev->dev.of_node, NULL);
+       if (!flash_np) {
+               dev_err(&pdev->dev, "no SPI flash device to configure\n");
+               ret = -ENODEV;
+               goto nor_free;
+       }
+       ret = mtk_nor_init(mt8173_nor, flash_np);
+
+nor_free:
+       if (ret) {
+               clk_disable_unprepare(mt8173_nor->spi_clk);
+               clk_disable_unprepare(mt8173_nor->nor_clk);
+       }
+       return ret;
+}
+
+static int mtk_nor_drv_remove(struct platform_device *pdev)
+{
+       struct mt8173_nor *mt8173_nor = platform_get_drvdata(pdev);
+
+       clk_disable_unprepare(mt8173_nor->spi_clk);
+       clk_disable_unprepare(mt8173_nor->nor_clk);
+       return 0;
+}
+
+static const struct of_device_id mtk_nor_of_ids[] = {
+       { .compatible = "mediatek,mt8173-nor"},
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mtk_nor_of_ids);
+
+static struct platform_driver mtk_nor_driver = {
+       .probe = mtk_nor_drv_probe,
+       .remove = mtk_nor_drv_remove,
+       .driver = {
+               .name = "mtk-nor",
+               .of_match_table = mtk_nor_of_ids,
+       },
+};
+
+module_platform_driver(mtk_nor_driver);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("MediaTek SPI NOR Flash Driver");
index 9e82098..ae428cb 100644 (file)
@@ -271,7 +271,6 @@ static void nxp_spifi_dummy_id_read(struct spi_nor *nor)
 static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,
                                 struct device_node *np)
 {
-       struct mtd_part_parser_data ppdata;
        enum read_mode flash_read;
        u32 ctrl, property;
        u16 mode = 0;
@@ -330,7 +329,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,
        writel(ctrl, spifi->io_base + SPIFI_CTRL);
 
        spifi->nor.dev   = spifi->dev;
-       spifi->nor.flash_node = np;
+       spi_nor_set_flash_node(&spifi->nor, np);
        spifi->nor.priv  = spifi;
        spifi->nor.read  = nxp_spifi_read;
        spifi->nor.write = nxp_spifi_write;
@@ -361,8 +360,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,
                return ret;
        }
 
-       ppdata.of_node = np;
-       ret = mtd_device_parse_register(&spifi->nor.mtd, NULL, &ppdata, NULL, 0);
+       ret = mtd_device_register(&spifi->nor.mtd, NULL, 0);
        if (ret) {
                dev_err(spifi->dev, "mtd device parse failed\n");
                return ret;
index 4988390..3b2460e 100644 (file)
@@ -38,6 +38,7 @@
 #define CHIP_ERASE_2MB_READY_WAIT_JIFFIES      (40UL * HZ)
 
 #define SPI_NOR_MAX_ID_LEN     6
+#define SPI_NOR_MAX_ADDR_WIDTH 4
 
 struct flash_info {
        char            *name;
@@ -312,6 +313,29 @@ static void spi_nor_unlock_and_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
        mutex_unlock(&nor->lock);
 }
 
+/*
+ * Initiate the erasure of a single sector
+ */
+static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
+{
+       u8 buf[SPI_NOR_MAX_ADDR_WIDTH];
+       int i;
+
+       if (nor->erase)
+               return nor->erase(nor, addr);
+
+       /*
+        * Default implementation, if driver doesn't have a specialized HW
+        * control
+        */
+       for (i = nor->addr_width - 1; i >= 0; i--) {
+               buf[i] = addr & 0xff;
+               addr >>= 8;
+       }
+
+       return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width);
+}
+
 /*
  * Erase an address range on the nor chip.  The address range may extend
  * one or more erase sectors.  Return an error is there is a problem erasing.
@@ -371,10 +395,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
                while (len) {
                        write_enable(nor);
 
-                       if (nor->erase(nor, addr)) {
-                               ret = -EIO;
+                       ret = spi_nor_erase_sector(nor, addr);
+                       if (ret)
                                goto erase_err;
-                       }
 
                        addr += mtd->erasesize;
                        len -= mtd->erasesize;
@@ -387,17 +410,13 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 
        write_disable(nor);
 
+erase_err:
        spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
 
-       instr->state = MTD_ERASE_DONE;
+       instr->state = ret ? MTD_ERASE_FAILED : MTD_ERASE_DONE;
        mtd_erase_callback(instr);
 
        return ret;
-
-erase_err:
-       spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
-       instr->state = MTD_ERASE_FAILED;
-       return ret;
 }
 
 static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs,
@@ -715,9 +734,9 @@ static const struct flash_info spi_nor_ids[] = {
        { "mx25l4005a",  INFO(0xc22013, 0, 64 * 1024,   8, SECT_4K) },
        { "mx25l8005",   INFO(0xc22014, 0, 64 * 1024,  16, 0) },
        { "mx25l1606e",  INFO(0xc22015, 0, 64 * 1024,  32, SECT_4K) },
-       { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, 0) },
+       { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
        { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
-       { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, 0) },
+       { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
        { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
        { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
        { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
@@ -856,7 +875,7 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
 
        tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
        if (tmp < 0) {
-               dev_dbg(nor->dev, " error %d reading JEDEC ID\n", tmp);
+               dev_dbg(nor->dev, "error %d reading JEDEC ID\n", tmp);
                return ERR_PTR(tmp);
        }
 
@@ -867,7 +886,7 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
                                return &spi_nor_ids[tmp];
                }
        }
-       dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %2x, %2x\n",
+       dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n",
                id[0], id[1], id[2]);
        return ERR_PTR(-ENODEV);
 }
@@ -1138,7 +1157,7 @@ static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
 static int spi_nor_check(struct spi_nor *nor)
 {
        if (!nor->dev || !nor->read || !nor->write ||
-               !nor->read_reg || !nor->write_reg || !nor->erase) {
+               !nor->read_reg || !nor->write_reg) {
                pr_err("spi-nor: please fill all the necessary fields!\n");
                return -EINVAL;
        }
@@ -1151,7 +1170,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
        const struct flash_info *info = NULL;
        struct device *dev = nor->dev;
        struct mtd_info *mtd = &nor->mtd;
-       struct device_node *np = nor->flash_node;
+       struct device_node *np = spi_nor_get_flash_node(nor);
        int ret;
        int i;
 
@@ -1340,6 +1359,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
                nor->addr_width = 3;
        }
 
+       if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
+               dev_err(dev, "address width is too large: %u\n",
+                       nor->addr_width);
+               return -EINVAL;
+       }
+
        nor->read_dummy = spi_nor_read_dummy_cycles(nor);
 
        dev_info(dev, "%s (%lld Kbytes)\n", info->name,
index 47bb56f..8924a96 100644 (file)
@@ -31,7 +31,7 @@
 
 static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct spinand_info *info = (struct spinand_info *)chip->priv;
        struct spinand_state *state = (struct spinand_state *)info->priv;
 
@@ -744,7 +744,7 @@ static void spinand_reset(struct spi_device *spi_nand)
 static void spinand_cmdfunc(struct mtd_info *mtd, unsigned int command,
                            int column, int page)
 {
-       struct nand_chip *chip = (struct nand_chip *)mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct spinand_info *info = (struct spinand_info *)chip->priv;
        struct spinand_state *state = (struct spinand_state *)info->priv;
 
@@ -850,7 +850,6 @@ static int spinand_probe(struct spi_device *spi_nand)
        struct nand_chip *chip;
        struct spinand_info *info;
        struct spinand_state *state;
-       struct mtd_part_parser_data ppdata;
 
        info  = devm_kzalloc(&spi_nand->dev, sizeof(struct spinand_info),
                             GFP_KERNEL);
@@ -894,6 +893,7 @@ static int spinand_probe(struct spi_device *spi_nand)
                pr_info("%s: disable ecc failed!\n", __func__);
 #endif
 
+       nand_set_flash_node(chip, spi_nand->dev.of_node);
        chip->priv      = info;
        chip->read_buf  = spinand_read_buf;
        chip->write_buf = spinand_write_buf;
@@ -916,8 +916,7 @@ static int spinand_probe(struct spi_device *spi_nand)
        if (nand_scan(mtd, 1))
                return -ENXIO;
 
-       ppdata.of_node = spi_nand->dev.of_node;
-       return mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
+       return mtd_device_register(mtd, NULL, 0);
 }
 
 /*
index 366cf77..58f3ba7 100644 (file)
 #endif
 
 #ifndef map_bankwidth
+#ifdef CONFIG_MTD
 #warning "No CONFIG_MTD_MAP_BANK_WIDTH_xx selected. No NOR chip support can work"
+#endif
 static inline int map_bankwidth(void *map)
 {
        BUG();
index f17fa75..cc84923 100644 (file)
@@ -254,6 +254,17 @@ struct mtd_info {
        int usecount;
 };
 
+static inline void mtd_set_of_node(struct mtd_info *mtd,
+                                  struct device_node *np)
+{
+       mtd->dev.of_node = np;
+}
+
+static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
+{
+       return mtd->dev.of_node;
+}
+
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
              void **virt, resource_size_t *phys);
index 5a9d1d4..b614ed2 100644 (file)
@@ -276,15 +276,15 @@ struct nand_onfi_params {
        __le16 t_r;
        __le16 t_ccs;
        __le16 src_sync_timing_mode;
-       __le16 src_ssync_features;
+       u8 src_ssync_features;
        __le16 clk_pin_capacitance_typ;
        __le16 io_pin_capacitance_typ;
        __le16 input_pin_capacitance_typ;
        u8 input_pin_capacitance_max;
        u8 driver_strength_support;
        __le16 t_int_r;
-       __le16 t_ald;
-       u8 reserved4[7];
+       __le16 t_adl;
+       u8 reserved4[8];
 
        /* vendor */
        __le16 vendor_revision;
@@ -407,7 +407,7 @@ struct nand_jedec_params {
        __le16 input_pin_capacitance_typ;
        __le16 clk_pin_capacitance_typ;
        u8 driver_strength_support;
-       __le16 t_ald;
+       __le16 t_adl;
        u8 reserved4[36];
 
        /* ECC and endurance block */
@@ -540,6 +540,7 @@ struct nand_buffers {
 
 /**
  * struct nand_chip - NAND Private Flash Chip Data
+ * @mtd:               MTD device registered to the MTD framework
  * @IO_ADDR_R:         [BOARDSPECIFIC] address to read the 8 I/O lines of the
  *                     flash device
  * @IO_ADDR_W:         [BOARDSPECIFIC] address to write the 8 I/O lines of the
@@ -640,6 +641,7 @@ struct nand_buffers {
  */
 
 struct nand_chip {
+       struct mtd_info mtd;
        void __iomem *IO_ADDR_R;
        void __iomem *IO_ADDR_W;
 
@@ -719,6 +721,27 @@ struct nand_chip {
        void *priv;
 };
 
+static inline void nand_set_flash_node(struct nand_chip *chip,
+                                      struct device_node *np)
+{
+       chip->flash_node = np;
+}
+
+static inline struct device_node *nand_get_flash_node(struct nand_chip *chip)
+{
+       return chip->flash_node;
+}
+
+static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
+{
+       return mtd->priv;
+}
+
+static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip)
+{
+       return &chip->mtd;
+}
+
 /*
  * NAND Flash Manufacturer ID Codes
  */
index 6a35e6d..d002d9b 100644 (file)
@@ -41,7 +41,6 @@ struct mtd_partition {
        uint64_t size;                  /* partition size */
        uint64_t offset;                /* offset within the master MTD space */
        uint32_t mask_flags;            /* master MTD flags to mask out for this partition */
-       struct nand_ecclayout *ecclayout;       /* out of band layout for this partition (NAND only) */
 };
 
 #define MTDPART_OFS_RETAIN     (-3)
@@ -56,11 +55,9 @@ struct device_node;
 /**
  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
  * @origin: for RedBoot, start address of MTD device
- * @of_node: for OF parsers, device node containing partitioning information
  */
 struct mtd_part_parser_data {
        unsigned long origin;
-       struct device_node *of_node;
 };
 
 
@@ -76,9 +73,21 @@ struct mtd_part_parser {
                        struct mtd_part_parser_data *);
 };
 
-extern void register_mtd_parser(struct mtd_part_parser *parser);
+extern int __register_mtd_parser(struct mtd_part_parser *parser,
+                                struct module *owner);
+#define register_mtd_parser(parser) __register_mtd_parser(parser, THIS_MODULE)
+
 extern void deregister_mtd_parser(struct mtd_part_parser *parser);
 
+/*
+ * module_mtd_part_parser() - Helper macro for MTD partition parsers that don't
+ * do anything special in module init/exit. Each driver may only use this macro
+ * once, and calling it replaces module_init() and module_exit().
+ */
+#define module_mtd_part_parser(__mtd_part_parser) \
+       module_driver(__mtd_part_parser, register_mtd_parser, \
+                     deregister_mtd_parser)
+
 int mtd_is_partition(const struct mtd_info *mtd);
 int mtd_add_partition(struct mtd_info *master, const char *name,
                      long long offset, long long length);
index c8723b6..fac3f6f 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/bitops.h>
 #include <linux/mtd/cfi.h>
+#include <linux/mtd/mtd.h>
 
 /*
  * Manufacturer IDs
@@ -117,14 +118,11 @@ enum spi_nor_option_flags {
        SNOR_F_USE_FSR          = BIT(0),
 };
 
-struct mtd_info;
-
 /**
  * struct spi_nor - Structure for defining a the SPI NOR layer
  * @mtd:               point to a mtd_info structure
  * @lock:              the lock for the read/write/erase/lock/unlock operations
  * @dev:               point to a spi device, or a spi nor controller device.
- * @flash_node:                point to a device node describing this flash instance.
  * @page_size:         the page size of the SPI NOR
  * @addr_width:                number of address bytes
  * @erase_opcode:      the opcode for erasing a sector
@@ -144,7 +142,8 @@ struct mtd_info;
  * @read:              [DRIVER-SPECIFIC] read data from the SPI NOR
  * @write:             [DRIVER-SPECIFIC] write data to the SPI NOR
  * @erase:             [DRIVER-SPECIFIC] erase a sector of the SPI NOR
- *                     at the offset @offs
+ *                     at the offset @offs; if not provided by the driver,
+ *                     spi-nor will send the erase opcode via write_reg()
  * @flash_lock:                [FLASH-SPECIFIC] lock a region of the SPI NOR
  * @flash_unlock:      [FLASH-SPECIFIC] unlock a region of the SPI NOR
  * @flash_is_locked:   [FLASH-SPECIFIC] check if a region of the SPI NOR is
@@ -155,7 +154,6 @@ struct spi_nor {
        struct mtd_info         mtd;
        struct mutex            lock;
        struct device           *dev;
-       struct device_node      *flash_node;
        u32                     page_size;
        u8                      addr_width;
        u8                      erase_opcode;
@@ -185,6 +183,17 @@ struct spi_nor {
        void *priv;
 };
 
+static inline void spi_nor_set_flash_node(struct spi_nor *nor,
+                                         struct device_node *np)
+{
+       mtd_set_of_node(&nor->mtd, np);
+}
+
+static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
+{
+       return mtd_get_of_node(&nor->mtd);
+}
+
 /**
  * spi_nor_scan() - scan the SPI NOR
  * @nor:       the spi_nor structure