OSDN Git Service

mtd: rawnand: gpmi: convert driver to nand_scan()
authorMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 20 Jul 2018 15:15:00 +0000 (17:15 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 31 Jul 2018 07:45:58 +0000 (09:45 +0200)
Two helpers have been added to the core to do all kind of controller
side configuration/initialization between the detection phase and the
final NAND scan. Implement these hooks so that we can convert the driver
to just use nand_scan() instead of the nand_scan_ident() +
nand_scan_tail() pair.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

index 6294d01..1c1ebbc 100644 (file)
@@ -744,9 +744,9 @@ static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this)
         * [2] Allocate a read/write data buffer.
         *     The gpmi_alloc_dma_buffer can be called twice.
         *     We allocate a PAGE_SIZE length buffer if gpmi_alloc_dma_buffer
-        *     is called before the nand_scan_ident; and we allocate a buffer
-        *     of the real NAND page size when the gpmi_alloc_dma_buffer is
-        *     called after the nand_scan_ident.
+        *     is called before the NAND identification; and we allocate a
+        *     buffer of the real NAND page size when the gpmi_alloc_dma_buffer
+        *     is called after.
         */
        this->data_buffer_dma = kzalloc(mtd->writesize ?: PAGE_SIZE,
                                        GFP_DMA | GFP_KERNEL);
@@ -1865,6 +1865,34 @@ static int gpmi_init_last(struct gpmi_nand_data *this)
        return 0;
 }
 
+static int gpmi_nand_attach_chip(struct nand_chip *chip)
+{
+       struct gpmi_nand_data *this = nand_get_controller_data(chip);
+       int ret;
+
+       if (chip->bbt_options & NAND_BBT_USE_FLASH) {
+               chip->bbt_options |= NAND_BBT_NO_OOB;
+
+               if (of_property_read_bool(this->dev->of_node,
+                                         "fsl,no-blockmark-swap"))
+                       this->swap_block_mark = false;
+       }
+       dev_dbg(this->dev, "Blockmark swapping %sabled\n",
+               this->swap_block_mark ? "en" : "dis");
+
+       ret = gpmi_init_last(this);
+       if (ret)
+               return ret;
+
+       chip->options |= NAND_SKIP_BBTSCAN;
+
+       return 0;
+}
+
+static const struct nand_controller_ops gpmi_nand_controller_ops = {
+       .attach_chip = gpmi_nand_attach_chip,
+};
+
 static int gpmi_nand_init(struct gpmi_nand_data *this)
 {
        struct nand_chip *chip = &this->nand;
@@ -1905,26 +1933,8 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
        if (ret)
                goto err_out;
 
-       ret = nand_scan_ident(mtd, GPMI_IS_MX6(this) ? 2 : 1, NULL);
-       if (ret)
-               goto err_out;
-
-       if (chip->bbt_options & NAND_BBT_USE_FLASH) {
-               chip->bbt_options |= NAND_BBT_NO_OOB;
-
-               if (of_property_read_bool(this->dev->of_node,
-                                               "fsl,no-blockmark-swap"))
-                       this->swap_block_mark = false;
-       }
-       dev_dbg(this->dev, "Blockmark swapping %sabled\n",
-               this->swap_block_mark ? "en" : "dis");
-
-       ret = gpmi_init_last(this);
-       if (ret)
-               goto err_out;
-
-       chip->options |= NAND_SKIP_BBTSCAN;
-       ret = nand_scan_tail(mtd);
+       chip->dummy_controller.ops = &gpmi_nand_controller_ops;
+       ret = nand_scan(mtd, GPMI_IS_MX6(this) ? 2 : 1);
        if (ret)
                goto err_out;