mtd: nand: import nand_hw_control_init()
authorMarc Gonzalez <marc_gonzalez@sigmadesigns.com>
Wed, 27 Jul 2016 09:23:52 +0000 (11:23 +0200)
committerBoris Brezillon <boris.brezillon@free-electrons.com>
Fri, 23 Sep 2016 07:35:16 +0000 (09:35 +0200)
The code to initialize a struct nand_hw_control is duplicated across
several drivers. Factorize it using an inline function.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
14 files changed:
drivers/mtd/nand/bf5xx_nand.c
drivers/mtd/nand/brcmnand/brcmnand.c
drivers/mtd/nand/docg4.c
drivers/mtd/nand/fsl_elbc_nand.c
drivers/mtd/nand/fsl_ifc_nand.c
drivers/mtd/nand/jz4780_nand.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/ndfc.c
drivers/mtd/nand/pxa3xx_nand.c
drivers/mtd/nand/qcom_nandc.c
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sunxi_nand.c
drivers/mtd/nand/txx9ndfmc.c
include/linux/mtd/nand.h

index 37da4236ab908099217184bd310a567365396192..3962f55bd03492aef64b235f596c921cb8fe8681 100644 (file)
@@ -761,8 +761,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, info);
 
-       spin_lock_init(&info->controller.lock);
-       init_waitqueue_head(&info->controller.wq);
+       nand_hw_control_init(&info->controller);
 
        info->device     = &pdev->dev;
        info->platform   = plat;
index 8eb2c64df38c333c3da874cac51b9695ac534de8..82ec36bb8296d45fa91ba7db998124fbb2644da7 100644 (file)
@@ -2370,8 +2370,7 @@ int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc)
 
        init_completion(&ctrl->done);
        init_completion(&ctrl->dma_done);
-       spin_lock_init(&ctrl->controller.lock);
-       init_waitqueue_head(&ctrl->controller.wq);
+       nand_hw_control_init(&ctrl->controller);
        INIT_LIST_HEAD(&ctrl->host_list);
 
        /* NAND register range */
index 47316998017f3e160a0eaf64783f26d2b1808ad9..7af2a3cd949eee9377a22a510cc15605cd1adf74 100644 (file)
@@ -1249,8 +1249,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
        nand->options = NAND_BUSWIDTH_16 | NAND_NO_SUBPAGE_WRITE;
        nand->IO_ADDR_R = nand->IO_ADDR_W = doc->virtadr + DOC_IOSPACE_DATA;
        nand->controller = &nand->hwcontrol;
-       spin_lock_init(&nand->controller->lock);
-       init_waitqueue_head(&nand->controller->wq);
+       nand_hw_control_init(nand->controller);
 
        /* methods */
        nand->cmdfunc = docg4_command;
index 60a88f24c6b3279be38a5870dbb5957cfa5f4114..113f76e599372d3d09526bdb4f95a3620ea45681 100644 (file)
@@ -879,8 +879,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
                }
                elbc_fcm_ctrl->counter++;
 
-               spin_lock_init(&elbc_fcm_ctrl->controller.lock);
-               init_waitqueue_head(&elbc_fcm_ctrl->controller.wq);
+               nand_hw_control_init(&elbc_fcm_ctrl->controller);
                fsl_lbc_ctrl_dev->nand = elbc_fcm_ctrl;
        } else {
                elbc_fcm_ctrl = fsl_lbc_ctrl_dev->nand;
index 4e9e5fd8faf30c22d5fa9159fe6a979228131954..0a177b1bfe3e77600b9fc9c943f6f961d195cd4f 100644 (file)
@@ -987,8 +987,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
                ifc_nand_ctrl->addr = NULL;
                fsl_ifc_ctrl_dev->nand = ifc_nand_ctrl;
 
-               spin_lock_init(&ifc_nand_ctrl->controller.lock);
-               init_waitqueue_head(&ifc_nand_ctrl->controller.wq);
+               nand_hw_control_init(&ifc_nand_ctrl->controller);
        } else {
                ifc_nand_ctrl = fsl_ifc_ctrl_dev->nand;
        }
index 175f67da25af01912b7b8f5d45f0ff3ada5d5a68..a39bb70175eea230cab2c3797f4750f075cfa755 100644 (file)
@@ -368,9 +368,8 @@ static int jz4780_nand_probe(struct platform_device *pdev)
        nfc->dev = dev;
        nfc->num_banks = num_banks;
 
-       spin_lock_init(&nfc->controller.lock);
+       nand_hw_control_init(&nfc->controller);
        INIT_LIST_HEAD(&nfc->chips);
-       init_waitqueue_head(&nfc->controller.wq);
 
        ret = jz4780_nand_init_chips(nfc, pdev);
        if (ret) {
index 77533f7f242937ae72e43a78e6256fb68982552f..53ea79628ddeb2fb6ca7fb5ed86d8abef0120fd3 100644 (file)
@@ -3191,8 +3191,7 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
 
        if (!chip->controller) {
                chip->controller = &chip->hwcontrol;
-               spin_lock_init(&chip->controller->lock);
-               init_waitqueue_head(&chip->controller->wq);
+               nand_hw_control_init(chip->controller);
        }
 
 }
index 218c789ca7ab7539418d132df412a99dc45ac981..28e6118362f7ea8348d2bcdb1e74ee804f0b682a 100644 (file)
@@ -218,8 +218,7 @@ static int ndfc_probe(struct platform_device *ofdev)
        ndfc = &ndfc_ctrl[cs];
        ndfc->chip_select = cs;
 
-       spin_lock_init(&ndfc->ndfc_control.lock);
-       init_waitqueue_head(&ndfc->ndfc_control.wq);
+       nand_hw_control_init(&ndfc->ndfc_control);
        ndfc->ofdev = ofdev;
        dev_set_drvdata(&ofdev->dev, ndfc);
 
index 436dd6dc11f4a810e838059c3ed0c5254a7cb07e..b121bf4ed73a2d50aca1935cffe2e6bf3639c26d 100644 (file)
@@ -1810,8 +1810,7 @@ static int alloc_nand_resource(struct platform_device *pdev)
                chip->cmdfunc           = nand_cmdfunc;
        }
 
-       spin_lock_init(&chip->controller->lock);
-       init_waitqueue_head(&chip->controller->wq);
+       nand_hw_control_init(chip->controller);
        info->clk = devm_clk_get(&pdev->dev, NULL);
        if (IS_ERR(info->clk)) {
                dev_err(&pdev->dev, "failed to get nand clock\n");
index de7d28e62d4e5aeee107894b8f9a11c66f63ed66..57d483ac5765a8aa889da61042aa5c75b64404a0 100644 (file)
@@ -1957,8 +1957,7 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
        INIT_LIST_HEAD(&nandc->desc_list);
        INIT_LIST_HEAD(&nandc->host_list);
 
-       spin_lock_init(&nandc->controller.lock);
-       init_waitqueue_head(&nandc->controller.wq);
+       nand_hw_control_init(&nandc->controller);
 
        return 0;
 }
index d9309cf0ce2ec3cd6b76f3d61c4fb0433d32b213..b1734d76cbc1013c822bd90d7d894d80c8f4e767 100644 (file)
@@ -977,8 +977,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, info);
 
-       spin_lock_init(&info->controller.lock);
-       init_waitqueue_head(&info->controller.wq);
+       nand_hw_control_init(&info->controller);
 
        /* get the clock source and enable it */
 
index e414b31b71c17111e923825ec8c178a3c40e8948..8b5dadc9cd26a423171b5ebfaa0f7b94ba0e3cd6 100644 (file)
@@ -2175,8 +2175,7 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        nfc->dev = dev;
-       spin_lock_init(&nfc->controller.lock);
-       init_waitqueue_head(&nfc->controller.wq);
+       nand_hw_control_init(&nfc->controller);
        INIT_LIST_HEAD(&nfc->chips);
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
index 04d63f56baa47508575ec88f7fd603196602cf6e..0a14fda2e41bf5ba8b9aec33eaf7e6cba56b70af 100644 (file)
@@ -303,8 +303,7 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)
        dev_info(&dev->dev, "CLK:%ldMHz HOLD:%d SPW:%d\n",
                 (gbusclk + 500000) / 1000000, hold, spw);
 
-       spin_lock_init(&drvdata->hw_control.lock);
-       init_waitqueue_head(&drvdata->hw_control.wq);
+       nand_hw_control_init(&drvdata->hw_control);
 
        platform_set_drvdata(dev, drvdata);
        txx9ndfmc_initialize(dev);
index 8dd6e01f45c0eb56ce4c068633700b7a386b6c52..f6a2d5e7313c0b7b8570d4238285ef04eaccfac8 100644 (file)
@@ -460,6 +460,13 @@ struct nand_hw_control {
        wait_queue_head_t wq;
 };
 
+static inline void nand_hw_control_init(struct nand_hw_control *nfc)
+{
+       nfc->active = NULL;
+       spin_lock_init(&nfc->lock);
+       init_waitqueue_head(&nfc->wq);
+}
+
 /**
  * struct nand_ecc_ctrl - Control structure for ECC
  * @mode:      ECC mode