MLK-11019-2: mxs-sdma: add im7d dma-apbh clock
authorAdrian Alonso <aalonso@freescale.com>
Fri, 29 May 2015 20:23:55 +0000 (15:23 -0500)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:47:29 +0000 (14:47 -0500)
* iMX7D dma-apbh support add additional clock dependency
* Add clock for mxs-dma support dma_apbh_bch dma_apbh_io

Signed-off-by: Adrian Alonso <aalonso@freescale.com>
Signed-off-by: Fugang Duan <B38611@freescale.com>
(cherry picked from commit: aea75669daac9101592de2cfbadc7aaacbc7d887)

drivers/dma/mxs-dma.c

index fb2c7bf..4a85d32 100644 (file)
@@ -135,6 +135,7 @@ enum mxs_dma_devtype {
 enum mxs_dma_id {
        IMX23_DMA,
        IMX28_DMA,
+       IMX7D_DMA,
 };
 
 struct mxs_dma_engine {
@@ -142,6 +143,7 @@ struct mxs_dma_engine {
        enum mxs_dma_devtype            type;
        void __iomem                    *base;
        struct clk                      *clk;
+       struct clk                      *clk_io;
        struct dma_device               dma_device;
        struct device_dma_parameters    dma_parms;
        struct mxs_dma_chan             mxs_chans[MXS_DMA_CHANNELS];
@@ -167,6 +169,9 @@ static struct mxs_dma_type mxs_dma_types[] = {
        }, {
                .id = IMX28_DMA,
                .type = MXS_DMA_APBX,
+       }, {
+               .id = IMX7D_DMA,
+               .type = MXS_DMA_APBH,
        }
 };
 
@@ -183,6 +188,9 @@ static const struct platform_device_id mxs_dma_ids[] = {
        }, {
                .name = "imx28-dma-apbx",
                .driver_data = (kernel_ulong_t) &mxs_dma_types[3],
+       }, {
+               .name = "imx7d-dma-apbh",
+               .driver_data = (kernel_ulong_t) &mxs_dma_types[4],
        }, {
                /* end of list */
        }
@@ -193,6 +201,7 @@ static const struct of_device_id mxs_dma_dt_ids[] = {
        { .compatible = "fsl,imx23-dma-apbx", .data = &mxs_dma_ids[1], },
        { .compatible = "fsl,imx28-dma-apbh", .data = &mxs_dma_ids[2], },
        { .compatible = "fsl,imx28-dma-apbx", .data = &mxs_dma_ids[3], },
+       { .compatible = "fsl,imx7d-dma-apbh", .data = &mxs_dma_ids[4], },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, mxs_dma_dt_ids);
@@ -437,6 +446,12 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
        if (ret)
                goto err_clk;
 
+       if (mxs_dma->dev_id == IMX7D_DMA) {
+               ret = clk_prepare_enable(mxs_dma->clk_io);
+               if (ret)
+                       goto err_clk_unprepare;
+       }
+
        mxs_dma_reset_chan(chan);
 
        dma_async_tx_descriptor_init(&mxs_chan->desc, chan);
@@ -447,6 +462,8 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
 
        return 0;
 
+err_clk_unprepare:
+       clk_disable_unprepare(mxs_dma->clk);
 err_clk:
        free_irq(mxs_chan->chan_irq, mxs_dma);
 err_irq:
@@ -468,6 +485,9 @@ static void mxs_dma_free_chan_resources(struct dma_chan *chan)
        dma_free_coherent(mxs_dma->dma_device.dev, CCW_BLOCK_SIZE,
                        mxs_chan->ccw, mxs_chan->ccw_phys);
 
+       if (mxs_dma->dev_id == IMX7D_DMA)
+               clk_disable_unprepare(mxs_dma->clk_io);
+
        clk_disable_unprepare(mxs_dma->clk);
 }
 
@@ -698,6 +718,12 @@ static int mxs_dma_init(struct mxs_dma_engine *mxs_dma)
        if (ret)
                return ret;
 
+       if (mxs_dma->dev_id == IMX7D_DMA) {
+               ret = clk_prepare_enable(mxs_dma->clk_io);
+               if (ret)
+                       goto err_out;
+       }
+
        ret = stmp_reset_block(mxs_dma->base);
        if (ret)
                goto err_out;
@@ -800,9 +826,19 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
        if (IS_ERR(mxs_dma->base))
                return PTR_ERR(mxs_dma->base);
 
-       mxs_dma->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(mxs_dma->clk))
-               return PTR_ERR(mxs_dma->clk);
+       if (mxs_dma->dev_id == IMX7D_DMA) {
+               mxs_dma->clk = devm_clk_get(&pdev->dev, "dma_apbh_bch");
+               if (IS_ERR(mxs_dma->clk))
+                       return PTR_ERR(mxs_dma->clk);
+               mxs_dma->clk_io = devm_clk_get(&pdev->dev, "dma_apbh_io");
+               if (IS_ERR(mxs_dma->clk_io))
+                       return PTR_ERR(mxs_dma->clk_io);
+
+       } else {
+               mxs_dma->clk = devm_clk_get(&pdev->dev, NULL);
+               if (IS_ERR(mxs_dma->clk))
+                       return PTR_ERR(mxs_dma->clk);
+       }
 
        dma_cap_set(DMA_SLAVE, mxs_dma->dma_device.cap_mask);
        dma_cap_set(DMA_CYCLIC, mxs_dma->dma_device.cap_mask);
@@ -874,6 +910,9 @@ static int mxs_dma_runtime_suspend(struct device *dev)
 {
        struct mxs_dma_engine *mxs_dma = dev_get_drvdata(dev);
 
+       if (mxs_dma->dev_id == IMX7D_DMA)
+               clk_disable(mxs_dma->clk_io);
+
        clk_disable(mxs_dma->clk);
        return 0;
 }
@@ -884,11 +923,20 @@ static int mxs_dma_runtime_resume(struct device *dev)
        int ret;
 
        ret = clk_enable(mxs_dma->clk);
-       if (ret < 0) {
-               dev_err(dev, "clk_enable failed: %d\n", ret);
-               return ret;
+       if (ret < 0)
+               goto err_out;
+
+       if (mxs_dma->dev_id == IMX7D_DMA) {
+               ret = clk_enable(mxs_dma->clk_io);
+               if (ret < 0)
+                       goto err_out;
        }
+
        return 0;
+
+err_out:
+       dev_err(dev, "clk_enable failed: %d\n", ret);
+       return ret;
 }
 
 static int mxs_dma_pm_suspend(struct device *dev)