From: Satendra Singh Thakur <sst2005@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: satendrasingh.thakur@hcl.com,
Satendra Singh Thakur <sst2005@gmail.com>,
Andy Gross <agross@kernel.org>,
Dan Williams <dan.j.williams@intel.com>,
Vinod Koul <vkoul@kernel.org>,
linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/9] probe/dma/qcom-bam: removed redundant code from qcom bam dma controller's probe function
Date: Sun, 15 Sep 2019 13:00:20 +0530 [thread overview]
Message-ID: <20190915073021.23738-1-sst2005@gmail.com> (raw)
In-Reply-To: <20190915072644.23329-1-sst2005@gmail.com>
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
next prev parent reply other threads:[~2019-09-15 7:30 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-15 7:00 [PATCH 0/9] added helper macros to remove duplicate code from probe functions of the platform drivers Satendra Singh Thakur
2019-09-15 7:00 ` Satendra Singh Thakur
2019-09-15 7:26 ` [PATCH 1/9] probe/dma : added helper macros to remove redundant/duplicate code from probe functions of the dma controller drivers Satendra Singh Thakur
2019-09-15 7:26 ` Satendra Singh Thakur
2019-09-15 7:29 ` [PATCH 2/9] probe/dma/jz4740: removed redundant code from jz4740 dma controller's probe function Satendra Singh Thakur
2019-09-15 7:29 ` [PATCH 3/9] probe/dma/zx: removed redundant code from zx " Satendra Singh Thakur
2019-09-15 7:29 ` Satendra Singh Thakur
2019-09-15 7:30 ` Satendra Singh Thakur [this message]
2019-09-15 7:30 ` [PATCH 5/9] probe/dma/mtk-hs: removed redundant code from mediatek hs " Satendra Singh Thakur
2019-09-15 7:30 ` Satendra Singh Thakur
2019-09-15 7:30 ` Satendra Singh Thakur
2019-09-15 7:31 ` [PATCH 6/9] probe/dma/sun6i: removed redundant code from sun6i " Satendra Singh Thakur
2019-09-15 7:31 ` Satendra Singh Thakur
2019-09-15 7:32 ` [PATCH 7/9] probe/dma/sun4i: removed redundant code from sun4i " Satendra Singh Thakur
2019-09-15 7:32 ` Satendra Singh Thakur
2019-09-15 7:32 ` [PATCH 8/9] probe/dma/axi: removed redundant code from axi " Satendra Singh Thakur
2019-09-15 7:32 ` [PATCH 9/9] probe/dma/owl: removed redundant code from owl " Satendra Singh Thakur
2019-09-15 7:32 ` Satendra Singh Thakur
2019-09-18 10:27 ` [PATCH 0/9] added helper macros to remove duplicate code from probe functions of the platform drivers Vinod Koul
2019-09-18 10:27 ` Vinod Koul
2019-09-21 14:57 ` Satendra Singh Thakur
2019-09-21 14:57 ` Satendra Singh Thakur
2019-09-24 19:27 ` Vinod Koul
2019-09-24 19:27 ` Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190915073021.23738-1-sst2005@gmail.com \
--to=sst2005@gmail.com \
--cc=agross@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=satendrasingh.thakur@hcl.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.