* [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions
@ 2020-07-21 11:24 Alexandru Ardelean
2020-07-21 19:33 ` Andy Shevchenko
2020-07-22 7:22 ` [PATCH v2] " Alexandru Ardelean
0 siblings, 2 replies; 5+ messages in thread
From: Alexandru Ardelean @ 2020-07-21 11:24 UTC (permalink / raw)
To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean
The driver pretty much uses device managed functions. The only left-over is
the iio_device_register() function, which also requires an action-or-reset
hook to disable the regulator on the remove and error path.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/iio/frequency/ad9523.c | 60 +++++++++++++---------------------
1 file changed, 22 insertions(+), 38 deletions(-)
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 334e1d779d6d..3d892d4f5f85 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -969,6 +969,13 @@ static int ad9523_setup(struct iio_dev *indio_dev)
return 0;
}
+static void ad9523_reg_disable(void *data)
+{
+ struct regulator *reg = data;
+
+ regulator_disable(reg);
+}
+
static int ad9523_probe(struct spi_device *spi)
{
struct ad9523_platform_data *pdata = spi->dev.platform_data;
@@ -994,21 +1001,22 @@ static int ad9523_probe(struct spi_device *spi)
ret = regulator_enable(st->reg);
if (ret)
return ret;
+
+ ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable,
+ st->reg);
+ if (ret)
+ return ret;
}
st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
GPIOD_OUT_HIGH);
- if (IS_ERR(st->pwrdown_gpio)) {
- ret = PTR_ERR(st->pwrdown_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->pwrdown_gpio))
+ return PTR_ERR(st->pwrdown_gpio);
st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
GPIOD_OUT_LOW);
- if (IS_ERR(st->reset_gpio)) {
- ret = PTR_ERR(st->reset_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->reset_gpio))
+ return PTR_ERR(st->reset_gpio);
if (st->reset_gpio) {
udelay(1);
@@ -1017,10 +1025,8 @@ static int ad9523_probe(struct spi_device *spi)
st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
GPIOD_OUT_HIGH);
- if (IS_ERR(st->sync_gpio)) {
- ret = PTR_ERR(st->sync_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->sync_gpio))
+ return PTR_ERR(st->sync_gpio);
spi_set_drvdata(spi, indio_dev);
st->spi = spi;
@@ -1035,36 +1041,15 @@ static int ad9523_probe(struct spi_device *spi)
ret = ad9523_setup(indio_dev);
if (ret < 0)
- goto error_disable_reg;
-
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_disable_reg;
-
- dev_info(&spi->dev, "probed %s\n", indio_dev->name);
-
- return 0;
+ return ret;
-error_disable_reg:
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ ret = devm_iio_device_register(&spi->dev, indio_dev);
+ if (ret == 0)
+ dev_info(&spi->dev, "probed %s\n", indio_dev->name);
return ret;
}
-static int ad9523_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad9523_state *st = iio_priv(indio_dev);
-
- iio_device_unregister(indio_dev);
-
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
-
- return 0;
-}
-
static const struct spi_device_id ad9523_id[] = {
{"ad9523-1", 9523},
{}
@@ -1076,7 +1061,6 @@ static struct spi_driver ad9523_driver = {
.name = "ad9523",
},
.probe = ad9523_probe,
- .remove = ad9523_remove,
.id_table = ad9523_id,
};
module_spi_driver(ad9523_driver);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions
2020-07-21 11:24 [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions Alexandru Ardelean
@ 2020-07-21 19:33 ` Andy Shevchenko
2020-07-22 7:02 ` Alexandru Ardelean
2020-07-22 7:22 ` [PATCH v2] " Alexandru Ardelean
1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-07-21 19:33 UTC (permalink / raw)
To: Alexandru Ardelean; +Cc: linux-iio, Linux Kernel Mailing List, Jonathan Cameron
On Tue, Jul 21, 2020 at 2:27 PM Alexandru Ardelean
<alexandru.ardelean@analog.com> wrote:
>
> The driver pretty much uses device managed functions. The only left-over is
> the iio_device_register() function, which also requires an action-or-reset
> hook to disable the regulator on the remove and error path.
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
...
> + ret = devm_iio_device_register(&spi->dev, indio_dev);
> + if (ret == 0)
> + dev_info(&spi->dev, "probed %s\n", indio_dev->name);
>
> return ret;
Please, drop this useless spam (I agree here with Greg KH) and use simply
return devm_iio_...(...);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions
2020-07-21 19:33 ` Andy Shevchenko
@ 2020-07-22 7:02 ` Alexandru Ardelean
0 siblings, 0 replies; 5+ messages in thread
From: Alexandru Ardelean @ 2020-07-22 7:02 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Alexandru Ardelean, linux-iio, Linux Kernel Mailing List,
Jonathan Cameron
On Tue, Jul 21, 2020 at 10:34 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Tue, Jul 21, 2020 at 2:27 PM Alexandru Ardelean
> <alexandru.ardelean@analog.com> wrote:
> >
> > The driver pretty much uses device managed functions. The only left-over is
> > the iio_device_register() function, which also requires an action-or-reset
> > hook to disable the regulator on the remove and error path.
> >
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
>
> ...
>
>
> > + ret = devm_iio_device_register(&spi->dev, indio_dev);
> > + if (ret == 0)
>
> > + dev_info(&spi->dev, "probed %s\n", indio_dev->name);
> >
> > return ret;
>
> Please, drop this useless spam (I agree here with Greg KH) and use simply
> return devm_iio_...(...);
I was also a bit undecided whether to keep it.
Will drop.
>
> --
> With Best Regards,
> Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] iio: frequency: ad9523: convert rest of driver to device managed functions
2020-07-21 11:24 [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions Alexandru Ardelean
2020-07-21 19:33 ` Andy Shevchenko
@ 2020-07-22 7:22 ` Alexandru Ardelean
2020-07-26 12:29 ` Jonathan Cameron
1 sibling, 1 reply; 5+ messages in thread
From: Alexandru Ardelean @ 2020-07-22 7:22 UTC (permalink / raw)
To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean
The driver pretty much uses device managed functions. The only left-over is
the iio_device_register() function, which also requires an action-or-reset
hook to disable the regulator on the remove and error path.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
Changelog v1 -> v2:
* removed 'probed' message at the end of probe; mostly log spam
drivers/iio/frequency/ad9523.c | 60 ++++++++++++----------------------
1 file changed, 20 insertions(+), 40 deletions(-)
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 334e1d779d6d..bdb0bc3b12dd 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -969,6 +969,13 @@ static int ad9523_setup(struct iio_dev *indio_dev)
return 0;
}
+static void ad9523_reg_disable(void *data)
+{
+ struct regulator *reg = data;
+
+ regulator_disable(reg);
+}
+
static int ad9523_probe(struct spi_device *spi)
{
struct ad9523_platform_data *pdata = spi->dev.platform_data;
@@ -994,21 +1001,22 @@ static int ad9523_probe(struct spi_device *spi)
ret = regulator_enable(st->reg);
if (ret)
return ret;
+
+ ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable,
+ st->reg);
+ if (ret)
+ return ret;
}
st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
GPIOD_OUT_HIGH);
- if (IS_ERR(st->pwrdown_gpio)) {
- ret = PTR_ERR(st->pwrdown_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->pwrdown_gpio))
+ return PTR_ERR(st->pwrdown_gpio);
st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
GPIOD_OUT_LOW);
- if (IS_ERR(st->reset_gpio)) {
- ret = PTR_ERR(st->reset_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->reset_gpio))
+ return PTR_ERR(st->reset_gpio);
if (st->reset_gpio) {
udelay(1);
@@ -1017,10 +1025,8 @@ static int ad9523_probe(struct spi_device *spi)
st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
GPIOD_OUT_HIGH);
- if (IS_ERR(st->sync_gpio)) {
- ret = PTR_ERR(st->sync_gpio);
- goto error_disable_reg;
- }
+ if (IS_ERR(st->sync_gpio))
+ return PTR_ERR(st->sync_gpio);
spi_set_drvdata(spi, indio_dev);
st->spi = spi;
@@ -1035,34 +1041,9 @@ static int ad9523_probe(struct spi_device *spi)
ret = ad9523_setup(indio_dev);
if (ret < 0)
- goto error_disable_reg;
-
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_disable_reg;
-
- dev_info(&spi->dev, "probed %s\n", indio_dev->name);
-
- return 0;
-
-error_disable_reg:
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
-
- return ret;
-}
-
-static int ad9523_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad9523_state *st = iio_priv(indio_dev);
-
- iio_device_unregister(indio_dev);
-
- if (!IS_ERR(st->reg))
- regulator_disable(st->reg);
+ return ret;
- return 0;
+ return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct spi_device_id ad9523_id[] = {
@@ -1076,7 +1057,6 @@ static struct spi_driver ad9523_driver = {
.name = "ad9523",
},
.probe = ad9523_probe,
- .remove = ad9523_remove,
.id_table = ad9523_id,
};
module_spi_driver(ad9523_driver);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iio: frequency: ad9523: convert rest of driver to device managed functions
2020-07-22 7:22 ` [PATCH v2] " Alexandru Ardelean
@ 2020-07-26 12:29 ` Jonathan Cameron
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-07-26 12:29 UTC (permalink / raw)
To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel
On Wed, 22 Jul 2020 10:22:01 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> The driver pretty much uses device managed functions. The only left-over is
> the iio_device_register() function, which also requires an action-or-reset
> hook to disable the regulator on the remove and error path.
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied.
Thanks,
Jonathan
> ---
>
> Changelog v1 -> v2:
> * removed 'probed' message at the end of probe; mostly log spam
>
> drivers/iio/frequency/ad9523.c | 60 ++++++++++++----------------------
> 1 file changed, 20 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
> index 334e1d779d6d..bdb0bc3b12dd 100644
> --- a/drivers/iio/frequency/ad9523.c
> +++ b/drivers/iio/frequency/ad9523.c
> @@ -969,6 +969,13 @@ static int ad9523_setup(struct iio_dev *indio_dev)
> return 0;
> }
>
> +static void ad9523_reg_disable(void *data)
> +{
> + struct regulator *reg = data;
> +
> + regulator_disable(reg);
> +}
> +
> static int ad9523_probe(struct spi_device *spi)
> {
> struct ad9523_platform_data *pdata = spi->dev.platform_data;
> @@ -994,21 +1001,22 @@ static int ad9523_probe(struct spi_device *spi)
> ret = regulator_enable(st->reg);
> if (ret)
> return ret;
> +
> + ret = devm_add_action_or_reset(&spi->dev, ad9523_reg_disable,
> + st->reg);
> + if (ret)
> + return ret;
> }
>
> st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
> GPIOD_OUT_HIGH);
> - if (IS_ERR(st->pwrdown_gpio)) {
> - ret = PTR_ERR(st->pwrdown_gpio);
> - goto error_disable_reg;
> - }
> + if (IS_ERR(st->pwrdown_gpio))
> + return PTR_ERR(st->pwrdown_gpio);
>
> st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
> GPIOD_OUT_LOW);
> - if (IS_ERR(st->reset_gpio)) {
> - ret = PTR_ERR(st->reset_gpio);
> - goto error_disable_reg;
> - }
> + if (IS_ERR(st->reset_gpio))
> + return PTR_ERR(st->reset_gpio);
>
> if (st->reset_gpio) {
> udelay(1);
> @@ -1017,10 +1025,8 @@ static int ad9523_probe(struct spi_device *spi)
>
> st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
> GPIOD_OUT_HIGH);
> - if (IS_ERR(st->sync_gpio)) {
> - ret = PTR_ERR(st->sync_gpio);
> - goto error_disable_reg;
> - }
> + if (IS_ERR(st->sync_gpio))
> + return PTR_ERR(st->sync_gpio);
>
> spi_set_drvdata(spi, indio_dev);
> st->spi = spi;
> @@ -1035,34 +1041,9 @@ static int ad9523_probe(struct spi_device *spi)
>
> ret = ad9523_setup(indio_dev);
> if (ret < 0)
> - goto error_disable_reg;
> -
> - ret = iio_device_register(indio_dev);
> - if (ret)
> - goto error_disable_reg;
> -
> - dev_info(&spi->dev, "probed %s\n", indio_dev->name);
> -
> - return 0;
> -
> -error_disable_reg:
> - if (!IS_ERR(st->reg))
> - regulator_disable(st->reg);
> -
> - return ret;
> -}
> -
> -static int ad9523_remove(struct spi_device *spi)
> -{
> - struct iio_dev *indio_dev = spi_get_drvdata(spi);
> - struct ad9523_state *st = iio_priv(indio_dev);
> -
> - iio_device_unregister(indio_dev);
> -
> - if (!IS_ERR(st->reg))
> - regulator_disable(st->reg);
> + return ret;
>
> - return 0;
> + return devm_iio_device_register(&spi->dev, indio_dev);
> }
>
> static const struct spi_device_id ad9523_id[] = {
> @@ -1076,7 +1057,6 @@ static struct spi_driver ad9523_driver = {
> .name = "ad9523",
> },
> .probe = ad9523_probe,
> - .remove = ad9523_remove,
> .id_table = ad9523_id,
> };
> module_spi_driver(ad9523_driver);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-26 12:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 11:24 [PATCH] iio: frequency: ad9523: convert rest of driver to device managed functions Alexandru Ardelean
2020-07-21 19:33 ` Andy Shevchenko
2020-07-22 7:02 ` Alexandru Ardelean
2020-07-22 7:22 ` [PATCH v2] " Alexandru Ardelean
2020-07-26 12:29 ` 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).