lkml.org 
[lkml]   [2019]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/9] probe/dma/qcom-bam: removed redundant code from qcom bam dma controller's probe function
Date
1. In order to remove duplicate code, following functions:
platform_get_resource
devm_kzalloc
devm_ioremap_resource
devm_clk_get
platform_get_irq
clk_prepare_enable
are replaced with a macro devm_platform_probe_helper_clk.

2. Renamed variables regs and bamclk so that helper macro can
be applied.

3. This patch depends on the file include/linux/probe-helper.h
which is pushed in previous patch [01/09].

Signed-off-by: Satendra Singh Thakur <satendrasingh.thakur@hcl.com>
Signed-off-by: Satendra Singh Thakur <sst2005@gmail.com>
---
drivers/dma/qcom/bam_dma.c | 71 ++++++++++++++++----------------------
1 file changed, 29 insertions(+), 42 deletions(-)

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index 8e90a405939d..06c136ca8e40 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -41,6 +41,7 @@
#include <linux/clk.h>
#include <linux/dmaengine.h>
#include <linux/pm_runtime.h>
+#include <linux/probe-helper.h>

#include "../dmaengine.h"
#include "../virt-dma.h"
@@ -378,7 +379,7 @@ static inline struct bam_chan *to_bam_chan(struct dma_chan *common)
}

struct bam_device {
- void __iomem *regs;
+ void __iomem *base;
struct device *dev;
struct dma_device common;
struct device_dma_parameters dma_parms;
@@ -392,7 +393,7 @@ struct bam_device {

const struct reg_offset_data *layout;

- struct clk *bamclk;
+ struct clk *clk;
int irq;

/* dma start transaction tasklet */
@@ -410,7 +411,7 @@ static inline void __iomem *bam_addr(struct bam_device *bdev, u32 pipe,
{
const struct reg_offset_data r = bdev->layout[reg];

- return bdev->regs + r.base_offset +
+ return bdev->base + r.base_offset +
r.pipe_mult * pipe +
r.evnt_mult * pipe +
r.ee_mult * bdev->ee;
@@ -1209,41 +1210,41 @@ static int bam_dma_probe(struct platform_device *pdev)
{
struct bam_device *bdev;
const struct of_device_id *match;
- struct resource *iores;
int ret, i;
-
- bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
- if (!bdev)
- return -ENOMEM;
+ /*
+ * This macro internally combines following functions:
+ * devm_kzalloc, platform_get_resource, devm_ioremap_resource,
+ * devm_clk_get, platform_get_irq, clk_prepare_enable
+ */
+ ret = devm_platform_probe_helper_clk(pdev, bdev, "bam_clk");
+ bdev->controlled_remotely = of_property_read_bool(pdev->dev.of_node,
+ "qcom,controlled-remotely");
+ if (ret < 0) {
+ if (IS_ERR(bdev->clk)) {
+ if (!bdev->controlled_remotely)
+ return ret;
+ bdev->clk = NULL;
+ } else
+ return ret;
+ }

bdev->dev = &pdev->dev;

match = of_match_node(bam_of_match, pdev->dev.of_node);
if (!match) {
dev_err(&pdev->dev, "Unsupported BAM module\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto err_disable_clk;
}

bdev->layout = match->data;

- iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- bdev->regs = devm_ioremap_resource(&pdev->dev, iores);
- if (IS_ERR(bdev->regs))
- return PTR_ERR(bdev->regs);
-
- bdev->irq = platform_get_irq(pdev, 0);
- if (bdev->irq < 0)
- return bdev->irq;
-
ret = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &bdev->ee);
if (ret) {
dev_err(bdev->dev, "Execution environment unspecified\n");
- return ret;
+ goto err_disable_clk;
}

- bdev->controlled_remotely = of_property_read_bool(pdev->dev.of_node,
- "qcom,controlled-remotely");
-
if (bdev->controlled_remotely) {
ret = of_property_read_u32(pdev->dev.of_node, "num-channels",
&bdev->num_channels);
@@ -1256,20 +1257,6 @@ static int bam_dma_probe(struct platform_device *pdev)
dev_err(bdev->dev, "num-ees unspecified in dt\n");
}

- bdev->bamclk = devm_clk_get(bdev->dev, "bam_clk");
- if (IS_ERR(bdev->bamclk)) {
- if (!bdev->controlled_remotely)
- return PTR_ERR(bdev->bamclk);
-
- bdev->bamclk = NULL;
- }
-
- ret = clk_prepare_enable(bdev->bamclk);
- if (ret) {
- dev_err(bdev->dev, "failed to prepare/enable clock\n");
- return ret;
- }
-
ret = bam_init(bdev);
if (ret)
goto err_disable_clk;
@@ -1359,7 +1346,7 @@ static int bam_dma_probe(struct platform_device *pdev)
err_tasklet_kill:
tasklet_kill(&bdev->task);
err_disable_clk:
- clk_disable_unprepare(bdev->bamclk);
+ clk_disable_unprepare(bdev->clk);

return ret;
}
@@ -1393,7 +1380,7 @@ static int bam_dma_remove(struct platform_device *pdev)

tasklet_kill(&bdev->task);

- clk_disable_unprepare(bdev->bamclk);
+ clk_disable_unprepare(bdev->clk);

return 0;
}
@@ -1402,7 +1389,7 @@ static int __maybe_unused bam_dma_runtime_suspend(struct device *dev)
{
struct bam_device *bdev = dev_get_drvdata(dev);

- clk_disable(bdev->bamclk);
+ clk_disable(bdev->clk);

return 0;
}
@@ -1412,7 +1399,7 @@ static int __maybe_unused bam_dma_runtime_resume(struct device *dev)
struct bam_device *bdev = dev_get_drvdata(dev);
int ret;

- ret = clk_enable(bdev->bamclk);
+ ret = clk_enable(bdev->clk);
if (ret < 0) {
dev_err(dev, "clk_enable failed: %d\n", ret);
return ret;
@@ -1428,7 +1415,7 @@ static int __maybe_unused bam_dma_suspend(struct device *dev)
if (!bdev->controlled_remotely)
pm_runtime_force_suspend(dev);

- clk_unprepare(bdev->bamclk);
+ clk_unprepare(bdev->clk);

return 0;
}
@@ -1438,7 +1425,7 @@ static int __maybe_unused bam_dma_resume(struct device *dev)
struct bam_device *bdev = dev_get_drvdata(dev);
int ret;

- ret = clk_prepare(bdev->bamclk);
+ ret = clk_prepare(bdev->clk);
if (ret)
return ret;

--
2.17.1
\
 
 \ /
  Last update: 2019-09-15 09:30    [W:0.096 / U:4.612 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site