mtd: rawnand: Pass a nand_chip object to chip->select_chip()
[linux-2.6-block.git] / drivers / mtd / nand / raw / plat_nand.c
index 222626df4b96d396a3b7e23da144cc2bf7661ebe..dd9e241b7584f7fcdc924f7250ff59828164ffea 100644 (file)
@@ -23,6 +23,20 @@ struct plat_nand_data {
        void __iomem            *io_base;
 };
 
+static void plat_nand_cmd_ctrl(struct mtd_info *mtd, int dat, unsigned int ctrl)
+{
+       struct platform_nand_data *pdata = dev_get_platdata(mtd->dev.parent);
+
+       pdata->ctrl.cmd_ctrl(mtd_to_nand(mtd), dat, ctrl);
+}
+
+static int plat_nand_dev_ready(struct mtd_info *mtd)
+{
+       struct platform_nand_data *pdata = dev_get_platdata(mtd->dev.parent);
+
+       return pdata->ctrl.dev_ready(mtd_to_nand(mtd));
+}
+
 /*
  * Probe for the NAND device.
  */
@@ -62,8 +76,13 @@ static int plat_nand_probe(struct platform_device *pdev)
 
        data->chip.IO_ADDR_R = data->io_base;
        data->chip.IO_ADDR_W = data->io_base;
-       data->chip.cmd_ctrl = pdata->ctrl.cmd_ctrl;
-       data->chip.dev_ready = pdata->ctrl.dev_ready;
+
+       if (pdata->ctrl.cmd_ctrl)
+               data->chip.cmd_ctrl = plat_nand_cmd_ctrl;
+
+       if (pdata->ctrl.dev_ready)
+               data->chip.dev_ready = plat_nand_dev_ready;
+
        data->chip.select_chip = pdata->ctrl.select_chip;
        data->chip.write_buf = pdata->ctrl.write_buf;
        data->chip.read_buf = pdata->ctrl.read_buf;
@@ -84,7 +103,7 @@ static int plat_nand_probe(struct platform_device *pdev)
        }
 
        /* Scan to find existence of the device */
-       err = nand_scan(mtd, pdata->chip.nr_chips);
+       err = nand_scan(&data->chip, pdata->chip.nr_chips);
        if (err)
                goto out;
 
@@ -97,7 +116,7 @@ static int plat_nand_probe(struct platform_device *pdev)
        if (!err)
                return err;
 
-       nand_release(mtd);
+       nand_release(&data->chip);
 out:
        if (pdata->ctrl.remove)
                pdata->ctrl.remove(pdev);
@@ -112,7 +131,7 @@ static int plat_nand_remove(struct platform_device *pdev)
        struct plat_nand_data *data = platform_get_drvdata(pdev);
        struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
 
-       nand_release(nand_to_mtd(&data->chip));
+       nand_release(&data->chip);
        if (pdata->ctrl.remove)
                pdata->ctrl.remove(pdev);