mtd: plat_nand: add platform probe/remove callbacks
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 12 May 2009 20:46:58 +0000 (13:46 -0700)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 5 Jun 2009 17:11:13 +0000 (18:11 +0100)
Add optional probe and remove callbacks to the plat_nand driver.

Some platforms may require additional setup, such as configuring the
memory controller, before the nand device can be accessed.  This patch
provides an optional callback to handle this setup as well as a callback
to teardown the setup.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Tested-by: Alexander Clouter <alex@digriz.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/nand/plat_nand.c
include/linux/mtd/nand.h

index 47a2105b9671ba66adbf9b555748a0a2e427b3b0..22e0ce788419f7f17b9488fe2ca0107743d0c9d7 100644 (file)
@@ -72,6 +72,13 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, data);
 
+       /* Handle any platform specific setup */
+       if (pdata->ctrl.probe) {
+               res = pdata->ctrl.probe(pdev);
+               if (res)
+                       goto out;
+       }
+
        /* Scan to find existance of the device */
        if (nand_scan(&data->mtd, 1)) {
                res = -ENXIO;
@@ -101,6 +108,8 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
 
        nand_release(&data->mtd);
 out:
+       if (pdata->ctrl.remove)
+               pdata->ctrl.remove(pdev);
        platform_set_drvdata(pdev, NULL);
        iounmap(data->io_base);
        kfree(data);
@@ -113,15 +122,15 @@ out:
 static int __devexit plat_nand_remove(struct platform_device *pdev)
 {
        struct plat_nand_data *data = platform_get_drvdata(pdev);
-#ifdef CONFIG_MTD_PARTITIONS
        struct platform_nand_data *pdata = pdev->dev.platform_data;
-#endif
 
        nand_release(&data->mtd);
 #ifdef CONFIG_MTD_PARTITIONS
        if (data->parts && data->parts != pdata->chip.partitions)
                kfree(data->parts);
 #endif
+       if (pdata->ctrl.remove)
+               pdata->ctrl.remove(pdev);
        iounmap(data->io_base);
        kfree(data);
 
index 0e35375ea7953fbd8c012b8941fe56f045b7522c..7f2d69356554e3cfe639200713fc525be38087fc 100644 (file)
@@ -577,8 +577,13 @@ struct platform_nand_chip {
        void                    *priv;
 };
 
+/* Keep gcc happy */
+struct platform_device;
+
 /**
  * struct platform_nand_ctrl - controller level device structure
+ * @probe:             platform specific function to probe/setup hardware
+ * @remove:            platform specific function to remove/teardown hardware
  * @hwcontrol:         platform specific hardware control structure
  * @dev_ready:         platform specific function to read ready/busy pin
  * @select_chip:       platform specific chip select function
@@ -591,6 +596,8 @@ struct platform_nand_chip {
  * All fields are optional and depend on the hardware driver requirements
  */
 struct platform_nand_ctrl {
+       int             (*probe)(struct platform_device *pdev);
+       void            (*remove)(struct platform_device *pdev);
        void            (*hwcontrol)(struct mtd_info *mtd, int cmd);
        int             (*dev_ready)(struct mtd_info *mtd);
        void            (*select_chip)(struct mtd_info *mtd, int chip);