Commit c0683bfd authored by Stefan Popa's avatar Stefan Popa Committed by Jonathan Cameron

staging: iio: adc: ad7606: Use devm functions in probe

Switch to devm version of request_irq, iio_triggered_buffer_setup,
iio_device_register. To avoid potential ordering issues in probe,
devm_add_action_or_reset() is used for the regulator_disable(). This
simplifies the code and decreases the chance of bugs.
Signed-off-by: default avatarStefan Popa <stefan.popa@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 557e585c
...@@ -418,6 +418,13 @@ static const struct iio_info ad7606_info_range = { ...@@ -418,6 +418,13 @@ static const struct iio_info ad7606_info_range = {
.attrs = &ad7606_attribute_group_range, .attrs = &ad7606_attribute_group_range,
}; };
static void ad7606_regulator_disable(void *data)
{
struct ad7606_state *st = data;
regulator_disable(st->reg);
}
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
const char *name, unsigned int id, const char *name, unsigned int id,
const struct ad7606_bus_ops *bops) const struct ad7606_bus_ops *bops)
...@@ -431,6 +438,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -431,6 +438,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return -ENOMEM; return -ENOMEM;
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
dev_set_drvdata(dev, indio_dev);
st->dev = dev; st->dev = dev;
mutex_init(&st->lock); mutex_init(&st->lock);
...@@ -451,11 +459,15 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -451,11 +459,15 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return ret; return ret;
} }
ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
if (ret)
return ret;
st->chip_info = &ad7606_chip_info_tbl[id]; st->chip_info = &ad7606_chip_info_tbl[id];
ret = ad7606_request_gpios(st); ret = ad7606_request_gpios(st);
if (ret) if (ret)
goto error_disable_reg; return ret;
indio_dev->dev.parent = dev; indio_dev->dev.parent = dev;
if (st->gpio_os) { if (st->gpio_os) {
...@@ -480,50 +492,21 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -480,50 +492,21 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
if (ret) if (ret)
dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
ret = request_irq(irq, ad7606_interrupt, IRQF_TRIGGER_FALLING, name, ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
indio_dev); name, indio_dev);
if (ret)
goto error_disable_reg;
ret = iio_triggered_buffer_setup(indio_dev, &ad7606_trigger_handler,
NULL, NULL);
if (ret) if (ret)
goto error_free_irq; return ret;
ret = iio_device_register(indio_dev); ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
&ad7606_trigger_handler,
NULL, NULL);
if (ret) if (ret)
goto error_unregister_ring; return ret;
dev_set_drvdata(dev, indio_dev);
return 0;
error_unregister_ring:
iio_triggered_buffer_cleanup(indio_dev);
error_free_irq:
free_irq(irq, indio_dev);
error_disable_reg: return devm_iio_device_register(dev, indio_dev);
regulator_disable(st->reg);
return ret;
} }
EXPORT_SYMBOL_GPL(ad7606_probe); EXPORT_SYMBOL_GPL(ad7606_probe);
int ad7606_remove(struct device *dev, int irq)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ad7606_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
free_irq(irq, indio_dev);
regulator_disable(st->reg);
return 0;
}
EXPORT_SYMBOL_GPL(ad7606_remove);
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int ad7606_suspend(struct device *dev) static int ad7606_suspend(struct device *dev)
......
...@@ -85,7 +85,6 @@ struct ad7606_bus_ops { ...@@ -85,7 +85,6 @@ struct ad7606_bus_ops {
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
const char *name, unsigned int id, const char *name, unsigned int id,
const struct ad7606_bus_ops *bops); const struct ad7606_bus_ops *bops);
int ad7606_remove(struct device *dev, int irq);
enum ad7606_supported_device_ids { enum ad7606_supported_device_ids {
ID_AD7605_4, ID_AD7605_4,
......
...@@ -72,11 +72,6 @@ static int ad7606_par_probe(struct platform_device *pdev) ...@@ -72,11 +72,6 @@ static int ad7606_par_probe(struct platform_device *pdev)
&ad7606_par8_bops); &ad7606_par8_bops);
} }
static int ad7606_par_remove(struct platform_device *pdev)
{
return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
}
static const struct platform_device_id ad7606_driver_ids[] = { static const struct platform_device_id ad7606_driver_ids[] = {
{ {
.name = "ad7605-4", .name = "ad7605-4",
...@@ -98,7 +93,6 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids); ...@@ -98,7 +93,6 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
static struct platform_driver ad7606_driver = { static struct platform_driver ad7606_driver = {
.probe = ad7606_par_probe, .probe = ad7606_par_probe,
.remove = ad7606_par_remove,
.id_table = ad7606_driver_ids, .id_table = ad7606_driver_ids,
.driver = { .driver = {
.name = "ad7606", .name = "ad7606",
......
...@@ -49,11 +49,6 @@ static int ad7606_spi_probe(struct spi_device *spi) ...@@ -49,11 +49,6 @@ static int ad7606_spi_probe(struct spi_device *spi)
&ad7606_spi_bops); &ad7606_spi_bops);
} }
static int ad7606_spi_remove(struct spi_device *spi)
{
return ad7606_remove(&spi->dev, spi->irq);
}
static const struct spi_device_id ad7606_id[] = { static const struct spi_device_id ad7606_id[] = {
{"ad7605-4", ID_AD7605_4}, {"ad7605-4", ID_AD7605_4},
{"ad7606-8", ID_AD7606_8}, {"ad7606-8", ID_AD7606_8},
...@@ -69,7 +64,6 @@ static struct spi_driver ad7606_driver = { ...@@ -69,7 +64,6 @@ static struct spi_driver ad7606_driver = {
.pm = AD7606_PM_OPS, .pm = AD7606_PM_OPS,
}, },
.probe = ad7606_spi_probe, .probe = ad7606_spi_probe,
.remove = ad7606_spi_remove,
.id_table = ad7606_id, .id_table = ad7606_id,
}; };
module_spi_driver(ad7606_driver); module_spi_driver(ad7606_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