Skip to contentSkip to conversation

iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm

PATCH New Wanhui Fu 1 participant 4 messages Nov 23 IIO

lore
Share & tools
lore

Wanhui Fu

author
#0 lore raw

v2 cover iio: adc: twl6030-gpadc: convert probe/remove cleanup to devm

This series converts twl6030-gpadc's probe error
handling and remove path to devm cleanup, and
deletes redundant dev_err() messages in probe.

- Patch 1 registers twl6030_gpadc_disable_irq() with devm_add_action_or_reset().
- Patch 2 converts iio_device_register() to devm_iio_device_register().
- Patch 3 deletes redundant dev_err() messages in probe.

Compile-tested only.

Changes in v2:
- Use devm_add_action_or_reset() instead of a
goto error path. Thanks, Jonathan!
- Convert to devm_iio_device_register() and drop remove(). Thanks, Jonathan!
- Drop redundant dev_err() messages after twl_i2c_write_u8(). Thanks, Andreas!

Wanhui Fu (3):
iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ
iio: adc: twl6030-gpadc: switch to devm_iio_device_register()
iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe

 drivers/iio/adc/twl6030-gpadc.c | 41 ++++++++++++---------------------
 1 file changed, 15 insertions(+), 26 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/3 iio: adc: twl6030-gpadc: use devm_add_action_or_reset() to disable IRQ

Register twl6030_gpadc_disable_irq() via devm_add_action_or_reset() and remove the manual call from twl6030_gpadc_remove().

Modify twl6030_gpadc_enable_irq() and twl6030_gpadc_disable_irq() to not take a mask argument, since the mask is always the same.

Fixes 1696f36482e7 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")
---
 drivers/iio/adc/twl6030-gpadc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +10 -4
index e7fd371b3404..786059cf7513 100644
@@ -360,8 +360,9 @@ static inline int twl6030_gpadc_read(u8 reg, u8 *val)
 	return twl_i2c_read(TWL6030_MODULE_GPADC, val, reg, 2);
 }
 
-static int twl6030_gpadc_enable_irq(u8 mask)
+static int twl6030_gpadc_enable_irq(void)
 {
+	u8 mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
 	int ret;
 
 	ret = twl6030_interrupt_unmask(mask, REG_INT_MSK_LINE_B);
@@ -373,8 +374,10 @@ static int twl6030_gpadc_enable_irq(u8 mask)
 	return ret;
 }
 
-static void twl6030_gpadc_disable_irq(u8 mask)
+static void twl6030_gpadc_disable_irq(void *data)
 {
+	u8 mask = TWL6030_GPADC_RT_SW1_EOC_MASK;
+
 	twl6030_interrupt_mask(mask, REG_INT_MSK_LINE_B);
 	twl6030_interrupt_mask(mask, REG_INT_MSK_STS_B);
 }
@@ -921,12 +924,16 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = twl6030_gpadc_enable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK);
+	ret = twl6030_gpadc_enable_irq();
 	if (ret < 0) {
 		dev_err(dev, "failed to enable GPADC interrupt\n");
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, twl6030_gpadc_disable_irq, NULL);
+	if (ret)
+		return ret;
+
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
 					TWL6030_REG_TOGGLE1);
 	if (ret < 0) {
@@ -967,7 +974,6 @@ static void twl6030_gpadc_remove(struct platform_device *pdev)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 
-	twl6030_gpadc_disable_irq(TWL6030_GPADC_RT_SW1_EOC_MASK);
 	iio_device_unregister(indio_dev);
 }
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v2 2/3 iio: adc: twl6030-gpadc: switch to devm_iio_device_register()

In reply to Wanhui Fu

Convert iio_device_register() to devm_iio_device_register(). This allows dropping the now-empty twl6030_gpadc_remove() and the unused platform_set_drvdata() call.

---
 drivers/iio/adc/twl6030-gpadc.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +1 -10
index 786059cf7513..591c7b3322c7 100644
@@ -904,7 +904,6 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	gpadc->dev = dev;
 	gpadc->pdata = pdata;
 
-	platform_set_drvdata(pdev, indio_dev);
 	mutex_init(&gpadc->lock);
 	init_completion(&gpadc->irq_complete);
 
@@ -967,14 +966,7 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 	indio_dev->channels = pdata->iio_channels;
 	indio_dev->num_channels = pdata->nchannels;
 
-	return iio_device_register(indio_dev);
-}
-
-static void twl6030_gpadc_remove(struct platform_device *pdev)
-{
-	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-
-	iio_device_unregister(indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static int twl6030_gpadc_suspend(struct device *pdev)
@@ -1006,7 +998,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(twl6030_gpadc_pm_ops, twl6030_gpadc_suspend,
 
 static struct platform_driver twl6030_gpadc_driver = {
 	.probe		= twl6030_gpadc_probe,
-	.remove		= twl6030_gpadc_remove,
 	.driver		= {
 		.name	= DRIVER_NAME,
 		.pm	= pm_sleep_ptr(&twl6030_gpadc_pm_ops),
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 3/3 iio: adc: twl6030-gpadc: delete redundant dev_err() messages in probe

In reply to Wanhui Fu

twl_i2c_write() already logs error messages on I2C transfer failures, so remove redundant dev_err() to simplify the probe function.

---
 drivers/iio/adc/twl6030-gpadc.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +4 -12
index 591c7b3322c7..6e20e5a31211 100644
@@ -935,30 +935,22 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
 					TWL6030_REG_TOGGLE1);
-	if (ret < 0) {
-		dev_err(dev, "failed to enable GPADC module\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
 				VBAT_MEAS | BB_MEAS | VAC_MEAS,
 				TWL6030_MISC1);
-	if (ret < 0) {
-		dev_err(dev, "failed to wire up inputs\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	indio_dev->name = DRIVER_NAME;
 	indio_dev->info = &twl6030_gpadc_iio_info;
Signature · 1 line
2.25.1