* [PATCH v2 0/6] i.MX7D ADC improvements
@ 2019-04-14 18:34 Andrey Smirnov
2019-04-14 18:34 ` [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:34 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Everyone:
This series is a number of small improvements I made to i.MX7D ADC
driver. Hopefully each patch is self-explanatory.
Feedback is welcome!
Thanks,
Andrey Smirnov
Changes [v1]:
- Renamed imx7d_adc_resume() to imx7d_adc_enable()
- Renamed imx7d_adc_suspend() to imx7d_adc_disable()
- Reordered the series to have "iio: imx7d_adc: Use
devm_iio_device_register()" as the last patch to avoid
concurrency problems during removal
[v1] lore.kernel.org/lkml/20190403070325.1077-1-andrew.smirnov@gmail.com
Andrey Smirnov (6):
iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe()
iio: imx7d_adc: Replace pr_err with dev_err
iio: imx7d_adc: Use devm_platform_ioremap_resource()
iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume()
iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend()
iio: imx7d_adc: Use devm_iio_device_register()
drivers/iio/adc/imx7d_adc.c | 175 +++++++++++++++---------------------
1 file changed, 74 insertions(+), 101 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe()
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
@ 2019-04-14 18:34 ` Andrey Smirnov
2019-04-22 10:34 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 2/6] iio: imx7d_adc: Replace pr_err with dev_err Andrey Smirnov
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:34 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Use a local "struct device *dev" in imx7d_adc_probe() for brevity. No
functional change intended.
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 | 37 ++++++++++++++++++-------------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index ad6764fb2a23..3bbd657409d5 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -438,51 +438,51 @@ static int imx7d_adc_probe(struct platform_device *pdev)
struct imx7d_adc *info;
struct iio_dev *indio_dev;
struct resource *mem;
+ struct device *dev = &pdev->dev;
int irq;
int ret;
- indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*info));
if (!indio_dev) {
dev_err(&pdev->dev, "Failed allocating iio device\n");
return -ENOMEM;
}
info = iio_priv(indio_dev);
- info->dev = &pdev->dev;
+ info->dev = dev;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- info->regs = devm_ioremap_resource(&pdev->dev, mem);
+ info->regs = devm_ioremap_resource(dev, mem);
if (IS_ERR(info->regs)) {
ret = PTR_ERR(info->regs);
- dev_err(&pdev->dev,
- "Failed to remap adc memory, err = %d\n", ret);
+ dev_err(dev, "Failed to remap adc memory, err = %d\n", ret);
return ret;
}
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
- dev_err(&pdev->dev, "No irq resource?\n");
+ dev_err(dev, "No irq resource?\n");
return irq;
}
- info->clk = devm_clk_get(&pdev->dev, "adc");
+ info->clk = devm_clk_get(dev, "adc");
if (IS_ERR(info->clk)) {
ret = PTR_ERR(info->clk);
- dev_err(&pdev->dev, "Failed getting clock, err = %d\n", ret);
+ dev_err(dev, "Failed getting clock, err = %d\n", ret);
return ret;
}
- info->vref = devm_regulator_get(&pdev->dev, "vref");
+ info->vref = devm_regulator_get(dev, "vref");
if (IS_ERR(info->vref)) {
ret = PTR_ERR(info->vref);
- dev_err(&pdev->dev,
+ dev_err(dev,
"Failed getting reference voltage, err = %d\n", ret);
return ret;
}
ret = regulator_enable(info->vref);
if (ret) {
- dev_err(&pdev->dev,
+ dev_err(dev,
"Can't enable adc reference top voltage, err = %d\n",
ret);
return ret;
@@ -492,8 +492,8 @@ static int imx7d_adc_probe(struct platform_device *pdev)
init_completion(&info->completion);
- indio_dev->name = dev_name(&pdev->dev);
- indio_dev->dev.parent = &pdev->dev;
+ indio_dev->name = dev_name(dev);
+ indio_dev->dev.parent = dev;
indio_dev->info = &imx7d_adc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = imx7d_adc_iio_channels;
@@ -501,16 +501,15 @@ static int imx7d_adc_probe(struct platform_device *pdev)
ret = clk_prepare_enable(info->clk);
if (ret) {
- dev_err(&pdev->dev,
- "Could not prepare or enable the clock.\n");
+ dev_err(dev, "Could not prepare or enable the clock.\n");
goto error_adc_clk_enable;
}
- ret = devm_request_irq(info->dev, irq,
- imx7d_adc_isr, 0,
- dev_name(&pdev->dev), info);
+ ret = devm_request_irq(dev, irq,
+ imx7d_adc_isr, 0,
+ dev_name(dev), info);
if (ret < 0) {
- dev_err(&pdev->dev, "Failed requesting irq, irq = %d\n", irq);
+ dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
goto error_iio_device_register;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/6] iio: imx7d_adc: Replace pr_err with dev_err
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
2019-04-14 18:34 ` [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
@ 2019-04-14 18:35 ` Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 3/6] iio: imx7d_adc: Use devm_platform_ioremap_resource() Andrey Smirnov
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:35 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Replace combination of pr_err()/dev_name() with an equivalent call for
dev_err().
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 | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 3bbd657409d5..72cfe9834bcb 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -388,8 +388,9 @@ static irqreturn_t imx7d_adc_isr(int irq, void *dev_id)
* timeout flags.
*/
if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT) {
- pr_err("%s: ADC got conversion time out interrupt: 0x%08x\n",
- dev_name(info->dev), status);
+ dev_err(info->dev,
+ "ADC got conversion time out interrupt: 0x%08x\n",
+ status);
status &= ~IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT;
writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 3/6] iio: imx7d_adc: Use devm_platform_ioremap_resource()
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
2019-04-14 18:34 ` [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 2/6] iio: imx7d_adc: Replace pr_err with dev_err Andrey Smirnov
@ 2019-04-14 18:35 ` Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume() Andrey Smirnov
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:35 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Use devm_platform_ioremap_resource() to be able to drop a bit of
explicit boilerplate code.
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 | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 72cfe9834bcb..147ee8575ad0 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -438,7 +438,6 @@ static int imx7d_adc_probe(struct platform_device *pdev)
{
struct imx7d_adc *info;
struct iio_dev *indio_dev;
- struct resource *mem;
struct device *dev = &pdev->dev;
int irq;
int ret;
@@ -452,8 +451,7 @@ static int imx7d_adc_probe(struct platform_device *pdev)
info = iio_priv(indio_dev);
info->dev = dev;
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- info->regs = devm_ioremap_resource(dev, mem);
+ info->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(info->regs)) {
ret = PTR_ERR(info->regs);
dev_err(dev, "Failed to remap adc memory, err = %d\n", ret);
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume()
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
` (2 preceding siblings ...)
2019-04-14 18:35 ` [PATCH v2 3/6] iio: imx7d_adc: Use devm_platform_ioremap_resource() Andrey Smirnov
@ 2019-04-14 18:35 ` Andrey Smirnov
2019-04-22 10:07 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend() Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register() Andrey Smirnov
5 siblings, 1 reply; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:35 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Initialization sequence performed in imx7d_adc_resume() is exactly the
same as the one being done in imx7d_adc_probe(). Make use of the
former in the latter to avoid code duplication. Rename
imx7d_adc_resume() to imx7d_adc_enable() for clarity while at it.
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 | 88 +++++++++++++++----------------------
1 file changed, 36 insertions(+), 52 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 147ee8575ad0..0922ee08546b 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_enable(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_enable(&indio_dev->dev);
+ if (ret)
+ return ret;
ret = iio_device_register(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)
@@ -560,34 +571,7 @@ 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 SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_enable);
static struct platform_driver imx7d_adc_driver = {
.probe = imx7d_adc_probe,
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend()
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
` (3 preceding siblings ...)
2019-04-14 18:35 ` [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume() Andrey Smirnov
@ 2019-04-14 18:35 ` Andrey Smirnov
2019-04-22 10:08 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register() Andrey Smirnov
5 siblings, 1 reply; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:35 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Since imx7d_adc_remove() does exactly the same thing as
imx7d_adc_suspend() we can use the latter together with
devm_add_action_or_reset() to simplify the former. Rename
imx7d_adc_suspend() to imx7d_adc_disable() for clarity while at it.
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 | 46 +++++++++++++++++++------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 0922ee08546b..c5b0dc7d0e49 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -461,6 +461,24 @@ static int imx7d_adc_enable(struct device *dev)
return 0;
}
+static int imx7d_adc_disable(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct imx7d_adc *info = iio_priv(indio_dev);
+
+ imx7d_adc_power_down(info);
+
+ clk_disable_unprepare(info->clk);
+ regulator_disable(info->vref);
+
+ return 0;
+}
+
+static void __imx7d_adc_disable(void *data)
+{
+ imx7d_adc_disable(data);
+}
+
static int imx7d_adc_probe(struct platform_device *pdev)
{
struct imx7d_adc *info;
@@ -531,11 +549,13 @@ static int imx7d_adc_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = devm_add_action_or_reset(dev, __imx7d_adc_disable,
+ &indio_dev->dev);
+ if (ret)
+ return ret;
+
ret = iio_device_register(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");
return ret;
}
@@ -546,32 +566,14 @@ static int imx7d_adc_probe(struct platform_device *pdev)
static int imx7d_adc_remove(struct platform_device *pdev)
{
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
- struct imx7d_adc *info = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- imx7d_adc_power_down(info);
-
- clk_disable_unprepare(info->clk);
- regulator_disable(info->vref);
-
return 0;
}
-static int __maybe_unused imx7d_adc_suspend(struct device *dev)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct imx7d_adc *info = iio_priv(indio_dev);
-
- imx7d_adc_power_down(info);
-
- clk_disable_unprepare(info->clk);
- regulator_disable(info->vref);
-
- return 0;
-}
-static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_enable);
+static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable, imx7d_adc_enable);
static struct platform_driver imx7d_adc_driver = {
.probe = imx7d_adc_probe,
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register()
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
` (4 preceding siblings ...)
2019-04-14 18:35 ` [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend() Andrey Smirnov
@ 2019-04-14 18:35 ` Andrey Smirnov
2019-04-22 10:09 ` Jonathan Cameron
5 siblings, 1 reply; 11+ messages in thread
From: Andrey Smirnov @ 2019-04-14 18:35 UTC (permalink / raw)
To: linux-iio
Cc: Andrey Smirnov, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, Chris Healy,
linux-kernel
Use devm_iio_device_register() and drop imx7d_adc_remove().
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 | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index c5b0dc7d0e49..958a34dd88ac 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -554,7 +554,7 @@ static int imx7d_adc_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = iio_device_register(indio_dev);
+ ret = devm_iio_device_register(dev, indio_dev);
if (ret) {
dev_err(&pdev->dev, "Couldn't register the device.\n");
return ret;
@@ -563,21 +563,10 @@ static int imx7d_adc_probe(struct platform_device *pdev)
return 0;
}
-static int imx7d_adc_remove(struct platform_device *pdev)
-{
- struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-
- iio_device_unregister(indio_dev);
-
- return 0;
-}
-
-
static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable, imx7d_adc_enable);
static struct platform_driver imx7d_adc_driver = {
.probe = imx7d_adc_probe,
- .remove = imx7d_adc_remove,
.driver = {
.name = "imx7d_adc",
.of_match_table = imx7d_adc_match,
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume()
2019-04-14 18:35 ` [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume() Andrey Smirnov
@ 2019-04-22 10:07 ` Jonathan Cameron
0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-04-22 10:07 UTC (permalink / raw)
To: Andrey Smirnov
Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Chris Healy, linux-kernel
On Sun, 14 Apr 2019 11:35:02 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> Initialization sequence performed in imx7d_adc_resume() is exactly the
> same as the one being done in imx7d_adc_probe(). Make use of the
> former in the latter to avoid code duplication. Rename
> imx7d_adc_resume() to imx7d_adc_enable() for clarity while at it.
>
> 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
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/adc/imx7d_adc.c | 88 +++++++++++++++----------------------
> 1 file changed, 36 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
> index 147ee8575ad0..0922ee08546b 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_enable(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_enable(&indio_dev->dev);
> + if (ret)
> + return ret;
>
> ret = iio_device_register(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)
> @@ -560,34 +571,7 @@ 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 SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_enable);
>
> static struct platform_driver imx7d_adc_driver = {
> .probe = imx7d_adc_probe,
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend()
2019-04-14 18:35 ` [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend() Andrey Smirnov
@ 2019-04-22 10:08 ` Jonathan Cameron
0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-04-22 10:08 UTC (permalink / raw)
To: Andrey Smirnov
Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Chris Healy, linux-kernel
On Sun, 14 Apr 2019 11:35:03 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> Since imx7d_adc_remove() does exactly the same thing as
> imx7d_adc_suspend() we can use the latter together with
> devm_add_action_or_reset() to simplify the former. Rename
> imx7d_adc_suspend() to imx7d_adc_disable() for clarity while at it.
>
> 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
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to see if they can find anything we missed.
Thanks,
Jonathan
> ---
> drivers/iio/adc/imx7d_adc.c | 46 +++++++++++++++++++------------------
> 1 file changed, 24 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
> index 0922ee08546b..c5b0dc7d0e49 100644
> --- a/drivers/iio/adc/imx7d_adc.c
> +++ b/drivers/iio/adc/imx7d_adc.c
> @@ -461,6 +461,24 @@ static int imx7d_adc_enable(struct device *dev)
> return 0;
> }
>
> +static int imx7d_adc_disable(struct device *dev)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct imx7d_adc *info = iio_priv(indio_dev);
> +
> + imx7d_adc_power_down(info);
> +
> + clk_disable_unprepare(info->clk);
> + regulator_disable(info->vref);
> +
> + return 0;
> +}
> +
> +static void __imx7d_adc_disable(void *data)
> +{
> + imx7d_adc_disable(data);
> +}
> +
> static int imx7d_adc_probe(struct platform_device *pdev)
> {
> struct imx7d_adc *info;
> @@ -531,11 +549,13 @@ static int imx7d_adc_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + ret = devm_add_action_or_reset(dev, __imx7d_adc_disable,
> + &indio_dev->dev);
> + if (ret)
> + return ret;
> +
> ret = iio_device_register(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");
> return ret;
> }
> @@ -546,32 +566,14 @@ static int imx7d_adc_probe(struct platform_device *pdev)
> static int imx7d_adc_remove(struct platform_device *pdev)
> {
> struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> - struct imx7d_adc *info = iio_priv(indio_dev);
>
> iio_device_unregister(indio_dev);
>
> - imx7d_adc_power_down(info);
> -
> - clk_disable_unprepare(info->clk);
> - regulator_disable(info->vref);
> -
> return 0;
> }
>
> -static int __maybe_unused imx7d_adc_suspend(struct device *dev)
> -{
> - struct iio_dev *indio_dev = dev_get_drvdata(dev);
> - struct imx7d_adc *info = iio_priv(indio_dev);
> -
> - imx7d_adc_power_down(info);
> -
> - clk_disable_unprepare(info->clk);
> - regulator_disable(info->vref);
> -
> - return 0;
> -}
>
> -static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_suspend, imx7d_adc_enable);
> +static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable, imx7d_adc_enable);
>
> static struct platform_driver imx7d_adc_driver = {
> .probe = imx7d_adc_probe,
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register()
2019-04-14 18:35 ` [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register() Andrey Smirnov
@ 2019-04-22 10:09 ` Jonathan Cameron
0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-04-22 10:09 UTC (permalink / raw)
To: Andrey Smirnov
Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Chris Healy, linux-kernel
On Sun, 14 Apr 2019 11:35:04 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> Use devm_iio_device_register() and drop imx7d_adc_remove().
>
> 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
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to poke at it.
Thanks,
Jonathan
> ---
> drivers/iio/adc/imx7d_adc.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
> index c5b0dc7d0e49..958a34dd88ac 100644
> --- a/drivers/iio/adc/imx7d_adc.c
> +++ b/drivers/iio/adc/imx7d_adc.c
> @@ -554,7 +554,7 @@ static int imx7d_adc_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> - ret = iio_device_register(indio_dev);
> + ret = devm_iio_device_register(dev, indio_dev);
> if (ret) {
> dev_err(&pdev->dev, "Couldn't register the device.\n");
> return ret;
> @@ -563,21 +563,10 @@ static int imx7d_adc_probe(struct platform_device *pdev)
> return 0;
> }
>
> -static int imx7d_adc_remove(struct platform_device *pdev)
> -{
> - struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> -
> - iio_device_unregister(indio_dev);
> -
> - return 0;
> -}
> -
> -
> static SIMPLE_DEV_PM_OPS(imx7d_adc_pm_ops, imx7d_adc_disable, imx7d_adc_enable);
>
> static struct platform_driver imx7d_adc_driver = {
> .probe = imx7d_adc_probe,
> - .remove = imx7d_adc_remove,
> .driver = {
> .name = "imx7d_adc",
> .of_match_table = imx7d_adc_match,
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe()
2019-04-14 18:34 ` [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
@ 2019-04-22 10:34 ` Jonathan Cameron
0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2019-04-22 10:34 UTC (permalink / raw)
To: Andrey Smirnov
Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, Chris Healy, linux-kernel
On Sun, 14 Apr 2019 11:34:59 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> Use a local "struct device *dev" in imx7d_adc_probe() for brevity. No
> functional change intended.
>
> 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
I applied some of these from V1. Please be sure to only send updates
of patches that were not applied.
Thanks
Jonathan
> ---
> drivers/iio/adc/imx7d_adc.c | 37 ++++++++++++++++++-------------------
> 1 file changed, 18 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
> index ad6764fb2a23..3bbd657409d5 100644
> --- a/drivers/iio/adc/imx7d_adc.c
> +++ b/drivers/iio/adc/imx7d_adc.c
> @@ -438,51 +438,51 @@ static int imx7d_adc_probe(struct platform_device *pdev)
> struct imx7d_adc *info;
> struct iio_dev *indio_dev;
> struct resource *mem;
> + struct device *dev = &pdev->dev;
> int irq;
> int ret;
>
> - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*info));
> if (!indio_dev) {
> dev_err(&pdev->dev, "Failed allocating iio device\n");
> return -ENOMEM;
> }
>
> info = iio_priv(indio_dev);
> - info->dev = &pdev->dev;
> + info->dev = dev;
>
> mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - info->regs = devm_ioremap_resource(&pdev->dev, mem);
> + info->regs = devm_ioremap_resource(dev, mem);
> if (IS_ERR(info->regs)) {
> ret = PTR_ERR(info->regs);
> - dev_err(&pdev->dev,
> - "Failed to remap adc memory, err = %d\n", ret);
> + dev_err(dev, "Failed to remap adc memory, err = %d\n", ret);
> return ret;
> }
>
> irq = platform_get_irq(pdev, 0);
> if (irq < 0) {
> - dev_err(&pdev->dev, "No irq resource?\n");
> + dev_err(dev, "No irq resource?\n");
> return irq;
> }
>
> - info->clk = devm_clk_get(&pdev->dev, "adc");
> + info->clk = devm_clk_get(dev, "adc");
> if (IS_ERR(info->clk)) {
> ret = PTR_ERR(info->clk);
> - dev_err(&pdev->dev, "Failed getting clock, err = %d\n", ret);
> + dev_err(dev, "Failed getting clock, err = %d\n", ret);
> return ret;
> }
>
> - info->vref = devm_regulator_get(&pdev->dev, "vref");
> + info->vref = devm_regulator_get(dev, "vref");
> if (IS_ERR(info->vref)) {
> ret = PTR_ERR(info->vref);
> - dev_err(&pdev->dev,
> + dev_err(dev,
> "Failed getting reference voltage, err = %d\n", ret);
> return ret;
> }
>
> ret = regulator_enable(info->vref);
> if (ret) {
> - dev_err(&pdev->dev,
> + dev_err(dev,
> "Can't enable adc reference top voltage, err = %d\n",
> ret);
> return ret;
> @@ -492,8 +492,8 @@ static int imx7d_adc_probe(struct platform_device *pdev)
>
> init_completion(&info->completion);
>
> - indio_dev->name = dev_name(&pdev->dev);
> - indio_dev->dev.parent = &pdev->dev;
> + indio_dev->name = dev_name(dev);
> + indio_dev->dev.parent = dev;
> indio_dev->info = &imx7d_adc_iio_info;
> indio_dev->modes = INDIO_DIRECT_MODE;
> indio_dev->channels = imx7d_adc_iio_channels;
> @@ -501,16 +501,15 @@ static int imx7d_adc_probe(struct platform_device *pdev)
>
> ret = clk_prepare_enable(info->clk);
> if (ret) {
> - dev_err(&pdev->dev,
> - "Could not prepare or enable the clock.\n");
> + dev_err(dev, "Could not prepare or enable the clock.\n");
> goto error_adc_clk_enable;
> }
>
> - ret = devm_request_irq(info->dev, irq,
> - imx7d_adc_isr, 0,
> - dev_name(&pdev->dev), info);
> + ret = devm_request_irq(dev, irq,
> + imx7d_adc_isr, 0,
> + dev_name(dev), info);
> if (ret < 0) {
> - dev_err(&pdev->dev, "Failed requesting irq, irq = %d\n", irq);
> + dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
> goto error_iio_device_register;
> }
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2019-04-22 10:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-14 18:34 [PATCH v2 0/6] i.MX7D ADC improvements Andrey Smirnov
2019-04-14 18:34 ` [PATCH v2 1/6] iio: imx7d_adc: Add local struct device pointer in imx7d_adc_probe() Andrey Smirnov
2019-04-22 10:34 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 2/6] iio: imx7d_adc: Replace pr_err with dev_err Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 3/6] iio: imx7d_adc: Use devm_platform_ioremap_resource() Andrey Smirnov
2019-04-14 18:35 ` [PATCH v2 4/6] iio: imx7d_adc: Simplify imx7d_adc_probe() with imx7d_adc_resume() Andrey Smirnov
2019-04-22 10:07 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 5/6] iio: imx7d_adc: Simplify imx7d_adc_remove() with imx7d_adc_suspend() Andrey Smirnov
2019-04-22 10:08 ` Jonathan Cameron
2019-04-14 18:35 ` [PATCH v2 6/6] iio: imx7d_adc: Use devm_iio_device_register() Andrey Smirnov
2019-04-22 10:09 ` Jonathan Cameron
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).