From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: linux-iio@vger.kernel.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Chris Healy <cphealy@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/6] iio: imx7d_adc: Use imx7d_adc_resume() in imx7d_adc_probe()
Date: Wed, 3 Apr 2019 00:03:24 -0700 [thread overview]
Message-ID: <20190403070325.1077-6-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190403070325.1077-1-andrew.smirnov@gmail.com>
Initialization sequence performed in imx7d_adc_resume() is exactley
the same as what's being done in imx7d_adc_probe(). Make use of the
former in the latter to avoid code duplication.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/iio/adc/imx7d_adc.c | 86 +++++++++++++++----------------------
1 file changed, 35 insertions(+), 51 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 8bba92611d54..c2fa0ab923ee 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -434,6 +434,33 @@ static void imx7d_adc_power_down(struct imx7d_adc *info)
writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG);
}
+static int imx7d_adc_resume(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct imx7d_adc *info = iio_priv(indio_dev);
+ int ret;
+
+ ret = regulator_enable(info->vref);
+ if (ret) {
+ dev_err(info->dev,
+ "Can't enable adc reference top voltage, err = %d\n",
+ ret);
+ return ret;
+ }
+
+ ret = clk_prepare_enable(info->clk);
+ if (ret) {
+ dev_err(info->dev,
+ "Could not prepare or enable clock.\n");
+ regulator_disable(info->vref);
+ return ret;
+ }
+
+ imx7d_adc_hw_init(info);
+
+ return 0;
+}
+
static int imx7d_adc_probe(struct platform_device *pdev)
{
struct imx7d_adc *info;
@@ -479,14 +506,6 @@ static int imx7d_adc_probe(struct platform_device *pdev)
return ret;
}
- ret = regulator_enable(info->vref);
- if (ret) {
- dev_err(dev,
- "Can't enable adc reference top voltage, err = %d\n",
- ret);
- return ret;
- }
-
platform_set_drvdata(pdev, indio_dev);
init_completion(&info->completion);
@@ -498,38 +517,30 @@ static int imx7d_adc_probe(struct platform_device *pdev)
indio_dev->channels = imx7d_adc_iio_channels;
indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels);
- ret = clk_prepare_enable(info->clk);
- if (ret) {
- dev_err(dev, "Could not prepare or enable the clock.\n");
- goto error_adc_clk_enable;
- }
-
ret = devm_request_irq(dev, irq,
imx7d_adc_isr, 0,
dev_name(dev), info);
if (ret < 0) {
dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
- goto error_iio_device_register;
+ return ret;
}
imx7d_adc_feature_config(info);
- imx7d_adc_hw_init(info);
+
+ ret = imx7d_adc_resume(&indio_dev->dev);
+ if (ret)
+ return ret;
ret = devm_iio_device_register(dev, indio_dev);
if (ret) {
imx7d_adc_power_down(info);
+ clk_disable_unprepare(info->clk);
+ regulator_disable(info->vref);
dev_err(&pdev->dev, "Couldn't register the device.\n");
- goto error_iio_device_register;
+ return ret;
}
return 0;
-
-error_iio_device_register:
- clk_disable_unprepare(info->clk);
-error_adc_clk_enable:
- regulator_disable(info->vref);
-
- return ret;
}
static int imx7d_adc_remove(struct platform_device *pdev)
@@ -558,33 +569,6 @@ static int __maybe_unused imx7d_adc_suspend(struct device *dev)
return 0;
}
-static int __maybe_unused imx7d_adc_resume(struct device *dev)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct imx7d_adc *info = iio_priv(indio_dev);
- int ret;
-
- ret = regulator_enable(info->vref);
- if (ret) {
- dev_err(info->dev,
- "Can't enable adc reference top voltage, err = %d\n",
- ret);
- return ret;
- }
-
- ret = clk_prepare_enable(info->clk);
- if (ret) {
- dev_err(info->dev,
- "Could not prepare or enable clock.\n");
- regulator_disable(info->vref);
- return ret;
- }
-
- imx7d_adc_hw_init(info);
-
- return 0;
-}
-
static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_resume);
static struct platform_driver imx7d_adc_driver = {
--
2.20.1
next prev parent reply other threads:[~2019-04-03 7:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-03 7:03 [PATCH 0/6] i.MX7D ADC improvements Andrey Smirnov
2019-04-03 7:03 ` [PATCH 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
2019-04-07 11:02 ` Jonathan Cameron
2019-04-03 7:03 ` [PATCH 2/6] iio: imx7d_adc: Replace pr_err with dev_err Andrey Smirnov
2019-04-07 11:03 ` Jonathan Cameron
2019-04-03 7:03 ` [PATCH 3/6] iio: imx7d_adc: Use devm_iio_device_register() Andrey Smirnov
2019-04-07 11:07 ` Jonathan Cameron
2019-04-14 1:04 ` Andrey Smirnov
2019-04-03 7:03 ` [PATCH 4/6] iio: imx7d_adc: Use devm_platform_ioremap_resource() Andrey Smirnov
2019-04-07 11:09 ` Jonathan Cameron
2019-04-03 7:03 ` Andrey Smirnov [this message]
2019-04-07 11:15 ` [PATCH 5/6] iio: imx7d_adc: Use imx7d_adc_resume() in imx7d_adc_probe() Jonathan Cameron
2019-04-14 1:05 ` Andrey Smirnov
2019-04-03 7:03 ` [PATCH 6/6] iio: imx7d_adc: Drop imx7d_adc_remove() Andrey Smirnov
2019-04-07 11:16 ` Jonathan Cameron
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=20190403070325.1077-6-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=cphealy@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).