Merge tag 'for-linus-20121219' of git://git.infradead.org/linux-mtd
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / mtd / nand / mxc_nand.c
index 9f10778a65243f6e8580051cd849e2c9cc144e32..45204e41a028c66bb1b7c510842f5af704234f6a 100644 (file)
 
 #include <asm/mach/flash.h>
 #include <linux/platform_data/mtd-mxc_nand.h>
-#include <mach/hardware.h>
 
 #define DRIVER_NAME "mxc_nand"
 
-#define nfc_is_v21()           (cpu_is_mx25() || cpu_is_mx35())
-#define nfc_is_v1()            (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21())
-#define nfc_is_v3_2a()         cpu_is_mx51()
-#define nfc_is_v3_2b()         cpu_is_mx53()
-
 /* Addresses for NFC registers */
 #define NFC_V1_V2_BUF_SIZE             (host->regs + 0x00)
 #define NFC_V1_V2_BUF_ADDR             (host->regs + 0x04)
@@ -1284,6 +1278,53 @@ static const struct mxc_nand_devtype_data imx53_nand_devtype_data = {
        .ppb_shift = 8,
 };
 
+static inline int is_imx21_nfc(struct mxc_nand_host *host)
+{
+       return host->devtype_data == &imx21_nand_devtype_data;
+}
+
+static inline int is_imx27_nfc(struct mxc_nand_host *host)
+{
+       return host->devtype_data == &imx27_nand_devtype_data;
+}
+
+static inline int is_imx25_nfc(struct mxc_nand_host *host)
+{
+       return host->devtype_data == &imx25_nand_devtype_data;
+}
+
+static inline int is_imx51_nfc(struct mxc_nand_host *host)
+{
+       return host->devtype_data == &imx51_nand_devtype_data;
+}
+
+static inline int is_imx53_nfc(struct mxc_nand_host *host)
+{
+       return host->devtype_data == &imx53_nand_devtype_data;
+}
+
+static struct platform_device_id mxcnd_devtype[] = {
+       {
+               .name = "imx21-nand",
+               .driver_data = (kernel_ulong_t) &imx21_nand_devtype_data,
+       }, {
+               .name = "imx27-nand",
+               .driver_data = (kernel_ulong_t) &imx27_nand_devtype_data,
+       }, {
+               .name = "imx25-nand",
+               .driver_data = (kernel_ulong_t) &imx25_nand_devtype_data,
+       }, {
+               .name = "imx51-nand",
+               .driver_data = (kernel_ulong_t) &imx51_nand_devtype_data,
+       }, {
+               .name = "imx53-nand",
+               .driver_data = (kernel_ulong_t) &imx53_nand_devtype_data,
+       }, {
+               /* sentinel */
+       }
+};
+MODULE_DEVICE_TABLE(platform, mxcnd_devtype);
+
 #ifdef CONFIG_OF_MTD
 static const struct of_device_id mxcnd_dt_ids[] = {
        {
@@ -1338,32 +1379,6 @@ static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
 }
 #endif
 
-static int __init mxcnd_probe_pdata(struct mxc_nand_host *host)
-{
-       struct mxc_nand_platform_data *pdata = host->dev->platform_data;
-
-       if (!pdata)
-               return -ENODEV;
-
-       host->pdata = *pdata;
-
-       if (nfc_is_v1()) {
-               if (cpu_is_mx21())
-                       host->devtype_data = &imx21_nand_devtype_data;
-               else
-                       host->devtype_data = &imx27_nand_devtype_data;
-       } else if (nfc_is_v21()) {
-               host->devtype_data = &imx25_nand_devtype_data;
-       } else if (nfc_is_v3_2a()) {
-               host->devtype_data = &imx51_nand_devtype_data;
-       } else if (nfc_is_v3_2b()) {
-               host->devtype_data = &imx53_nand_devtype_data;
-       } else
-               BUG();
-
-       return 0;
-}
-
 static int mxcnd_probe(struct platform_device *pdev)
 {
        struct nand_chip *this;
@@ -1405,8 +1420,16 @@ static int mxcnd_probe(struct platform_device *pdev)
                return PTR_ERR(host->clk);
 
        err = mxcnd_probe_dt(host);
-       if (err > 0)
-               err = mxcnd_probe_pdata(host);
+       if (err > 0) {
+               struct mxc_nand_platform_data *pdata = pdev->dev.platform_data;
+               if (pdata) {
+                       host->pdata = *pdata;
+                       host->devtype_data = (struct mxc_nand_devtype_data *)
+                                               pdev->id_entry->driver_data;
+               } else {
+                       err = -ENODEV;
+               }
+       }
        if (err < 0)
                return err;
 
@@ -1495,7 +1518,7 @@ static int mxcnd_probe(struct platform_device *pdev)
        }
 
        /* first scan to find the device and get the page size */
-       if (nand_scan_ident(mtd, nfc_is_v21() ? 4 : 1, NULL)) {
+       if (nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL)) {
                err = -ENXIO;
                goto escan;
        }
@@ -1509,7 +1532,7 @@ static int mxcnd_probe(struct platform_device *pdev)
                this->ecc.layout = host->devtype_data->ecclayout_4k;
 
        if (this->ecc.mode == NAND_ECC_HW) {
-               if (nfc_is_v1())
+               if (is_imx21_nfc(host) || is_imx27_nfc(host))
                        this->ecc.strength = 1;
                else
                        this->ecc.strength = (host->eccsize == 4) ? 4 : 8;
@@ -1557,6 +1580,7 @@ static struct platform_driver mxcnd_driver = {
                   .owner = THIS_MODULE,
                   .of_match_table = of_match_ptr(mxcnd_dt_ids),
        },
+       .id_table = mxcnd_devtype,
        .probe = mxcnd_probe,
        .remove = mxcnd_remove,
 };