Commit aac6834d authored by Maíra Canal's avatar Maíra Canal Committed by Jonathan Cameron

iio: adc: ad7266: convert probe to full device-managed

Convert probe functions to device-managed variants, with exception of
the regulator, which required a devm_add_action_or_reset() hook
registration.
Reviewed-by: default avatarMarcelo Schmitt <marcelo.schmitt1@gmail.com>
Reviewed-by: default avatarNuno Sá <nuno.sa@analog.com>
Signed-off-by: default avatarMaíra Canal <maira.canal@usp.br>
Link: https://lore.kernel.org/r/20220407115621.10781-1-maira.canal@usp.brSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 74f582ec
...@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = { ...@@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2", "ad0", "ad1", "ad2",
}; };
static void ad7266_reg_disable(void *reg)
{
regulator_disable(reg);
}
static int ad7266_probe(struct spi_device *spi) static int ad7266_probe(struct spi_device *spi)
{ {
struct ad7266_platform_data *pdata = spi->dev.platform_data; struct ad7266_platform_data *pdata = spi->dev.platform_data;
...@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi) ...@@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi)
if (ret) if (ret)
return ret; return ret;
ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
if (ret)
return ret;
ret = regulator_get_voltage(st->reg); ret = regulator_get_voltage(st->reg);
if (ret < 0) if (ret < 0)
goto error_disable_reg; return ret;
st->vref_mv = ret / 1000; st->vref_mv = ret / 1000;
} else { } else {
...@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi) ...@@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi)
GPIOD_OUT_LOW); GPIOD_OUT_LOW);
if (IS_ERR(st->gpios[i])) { if (IS_ERR(st->gpios[i])) {
ret = PTR_ERR(st->gpios[i]); ret = PTR_ERR(st->gpios[i]);
goto error_disable_reg; return ret;
} }
} }
} }
...@@ -433,7 +442,6 @@ static int ad7266_probe(struct spi_device *spi) ...@@ -433,7 +442,6 @@ static int ad7266_probe(struct spi_device *spi)
st->mode = AD7266_MODE_DIFF; st->mode = AD7266_MODE_DIFF;
} }
spi_set_drvdata(spi, indio_dev);
st->spi = spi; st->spi = spi;
indio_dev->name = spi_get_device_id(spi)->name; indio_dev->name = spi_get_device_id(spi)->name;
...@@ -459,35 +467,12 @@ static int ad7266_probe(struct spi_device *spi) ...@@ -459,35 +467,12 @@ static int ad7266_probe(struct spi_device *spi)
spi_message_add_tail(&st->single_xfer[1], &st->single_msg); spi_message_add_tail(&st->single_xfer[1], &st->single_msg);
spi_message_add_tail(&st->single_xfer[2], &st->single_msg); spi_message_add_tail(&st->single_xfer[2], &st->single_msg);
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time,
&ad7266_trigger_handler, &iio_triggered_buffer_setup_ops); &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops);
if (ret) if (ret)
goto error_disable_reg; return ret;
ret = iio_device_register(indio_dev);
if (ret)
goto error_buffer_cleanup;
return 0;
error_buffer_cleanup:
iio_triggered_buffer_cleanup(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
return ret;
}
static void ad7266_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad7266_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev); return devm_iio_device_register(&spi->dev, indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
} }
static const struct spi_device_id ad7266_id[] = { static const struct spi_device_id ad7266_id[] = {
...@@ -502,7 +487,6 @@ static struct spi_driver ad7266_driver = { ...@@ -502,7 +487,6 @@ static struct spi_driver ad7266_driver = {
.name = "ad7266", .name = "ad7266",
}, },
.probe = ad7266_probe, .probe = ad7266_probe,
.remove = ad7266_remove,
.id_table = ad7266_id, .id_table = ad7266_id,
}; };
module_spi_driver(ad7266_driver); module_spi_driver(ad7266_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment