* [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup
@ 2026-11-09 16:51 Archit Anant
2026-11-09 16:51 ` [PATCH v6 01/11] iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS() Archit Anant
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
This series modernizes the ti-ads1015 driver by updating its runtime PM
handling, error handling, resource management, and register bitfield
operations.
This series builds on top of Stepan Ionichev's devm error path fix [1] and:
- Replaces SET_RUNTIME_PM_OPS() with DEFINE_RUNTIME_DEV_PM_OPS().
- Sorts the driver headers alphabetically.
- Returns -ENODATA when match data is missing.
- Uses a local device pointer in probe.
- Converts suitable error paths to dev_err_probe().
- Drops unnecessary '< 0' error checks for functions returning 0 or an
error.
- Converts mutex initialization to devm_mutex_init().
- Transitions runtime PM setup to devm_pm_runtime_set_active_enabled().
- Removes the unnecessary ads1015_set_power_state() helper and uses
runtime PM helpers directly at the call sites.
- Inlines the redundant ads1015_set_conv_mode() helper.
- Replaces custom shift macros with FIELD_PREP()/FIELD_GET().
[1] https://lore.kernel.org/all/20260529183708.17819-1-sozdayvek@gmail.com/
---
Changes in v6:
- Added a patch to remove the unnecessary ads1015_set_power_state() helper.
- Incorporated review feedback into the existing patches, including the FIELD_PREP()/FIELD_GET() conversion.
Changes in v5:
https://lore.kernel.org/linux-iio/20260827172100.39176-1-architanant5@gmail.com/
Archit Anant (11):
iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS()
iio: adc: ti-ads1015: Sort headers alphabetically
iio: adc: ti-ads1015: use local device pointer in probe
iio: adc: ti-ads1015: return -ENODATA when match data is missing
iio: adc: ti-ads1015: use dev_err_probe() for error handling
iio: adc: ti-ads1015: Remove ads1015_set_power_state()
iio: adc: ti-ads1015: drop unneeded < 0 error checks
iio: adc: ti-ads1015: use devm_mutex_init()
iio: adc: ti-ads1015: use managed runtime PM setup
iio: adc: ti-ads1015: inline ads1015_set_conv_mode()
iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET
drivers/iio/adc/ti-ads1015.c | 237 +++++++++++++++++------------------
1 file changed, 115 insertions(+), 122 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 01/11] iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS()
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
@ 2026-11-09 16:51 ` Archit Anant
2026-11-09 16:51 ` [PATCH v6 02/11] iio: adc: ti-ads1015: Sort headers alphabetically Archit Anant
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
Replace the deprecated SET_RUNTIME_PM_OPS() with
DEFINE_RUNTIME_DEV_PM_OPS().
This also configures the system sleep PM operations to use the
runtime suspend and resume callbacks, ensuring that the device
is properly suspended and resumed during system sleep transitions.
The new macro also handles dropping unused functions when
CONFIG_PM is disabled, eliminating the need for explicit
preprocessor conditionals.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 0f9244107c6dd..7211cefc731d1 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -1089,7 +1089,6 @@ static int ads1015_probe(struct i2c_client *client)
return devm_iio_device_register(&client->dev, indio_dev);
}
-#ifdef CONFIG_PM
static int ads1015_runtime_suspend(struct device *dev)
{
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
@@ -1110,12 +1109,11 @@ static int ads1015_runtime_resume(struct device *dev)
return ret;
}
-#endif
-static const struct dev_pm_ops ads1015_pm_ops = {
- SET_RUNTIME_PM_OPS(ads1015_runtime_suspend,
- ads1015_runtime_resume, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(ads1015_pm_ops,
+ ads1015_runtime_suspend,
+ ads1015_runtime_resume,
+ NULL);
static const struct ads1015_chip_data ads1015_data = {
.channels = ads1015_channels,
@@ -1170,7 +1168,7 @@ static struct i2c_driver ads1015_driver = {
.driver = {
.name = ADS1015_DRV_NAME,
.of_match_table = ads1015_of_match,
- .pm = &ads1015_pm_ops,
+ .pm = pm_ptr(&ads1015_pm_ops),
},
.probe = ads1015_probe,
.id_table = ads1015_id,
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 02/11] iio: adc: ti-ads1015: Sort headers alphabetically
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
2026-11-09 16:51 ` [PATCH v6 01/11] iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS() Archit Anant
@ 2026-11-09 16:51 ` Archit Anant
2026-11-09 16:51 ` [PATCH v6 03/11] iio: adc: ti-ads1015: use local device pointer in probe Archit Anant
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
Reorder include headers alphabetically to comply with the preferred
coding style and improve maintainability.
Drop the redundant linux/iio/types.h include, as its definitions
are already provided through linux/iio/iio.h.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 7211cefc731d1..3c2f27f41093c 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -11,24 +11,23 @@
* * 0x4B - ADDR connected to SCL
*/
-#include <linux/module.h>
#include <linux/cleanup.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/irq.h>
-#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm_runtime.h>
#include <linux/property.h>
#include <linux/regmap.h>
-#include <linux/pm_runtime.h>
-#include <linux/mutex.h>
-#include <linux/delay.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/events.h>
#include <linux/iio/iio.h>
-#include <linux/iio/types.h>
#include <linux/iio/sysfs.h>
-#include <linux/iio/events.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/triggered_buffer.h>
#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
#define ADS1015_DRV_NAME "ads1015"
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 03/11] iio: adc: ti-ads1015: use local device pointer in probe
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
2026-11-09 16:51 ` [PATCH v6 01/11] iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS() Archit Anant
2026-11-09 16:51 ` [PATCH v6 02/11] iio: adc: ti-ads1015: Sort headers alphabetically Archit Anant
@ 2026-11-09 16:51 ` Archit Anant
2026-11-09 16:51 ` [PATCH v6 04/11] iio: adc: ti-ads1015: return -ENODATA when match data is missing Archit Anant
2026-11-09 16:51 ` [PATCH v6 05/11] iio: adc: ti-ads1015: use dev_err_probe() for error handling Archit Anant
4 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
Introduce a local device pointer 'dev' in ads1015_probe()
to avoid accessing &client->dev repeatedly.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 3c2f27f41093c..af3ba6b75c410 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -966,6 +966,7 @@ static void ads1015_power_down(void *p)
static int ads1015_probe(struct i2c_client *client)
{
const struct ads1015_chip_data *chip;
+ struct device *dev = &client->dev;
struct iio_dev *indio_dev;
struct ads1015_data *data;
int ret;
@@ -975,7 +976,7 @@ static int ads1015_probe(struct i2c_client *client)
if (!chip)
return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n");
- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
@@ -1022,7 +1023,7 @@ static int ads1015_probe(struct i2c_client *client)
return PTR_ERR(data->regmap);
}
- ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL,
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
ads1015_trigger_handler,
&ads1015_buffer_setup_ops);
if (ret < 0) {
@@ -1058,7 +1059,7 @@ static int ads1015_probe(struct i2c_client *client)
if (ret)
return ret;
- ret = devm_request_threaded_irq(&client->dev, client->irq,
+ ret = devm_request_threaded_irq(dev, client->irq,
NULL, ads1015_event_handler,
irq_trig | IRQF_ONESHOT,
client->name, indio_dev);
@@ -1070,22 +1071,22 @@ static int ads1015_probe(struct i2c_client *client)
if (ret)
return ret;
- ret = devm_add_action_or_reset(&client->dev, ads1015_power_down, data);
+ ret = devm_add_action_or_reset(dev, ads1015_power_down, data);
if (ret)
return ret;
data->conv_invalid = true;
- ret = pm_runtime_set_active(&client->dev);
+ ret = pm_runtime_set_active(dev);
if (ret)
return ret;
- pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS);
- pm_runtime_use_autosuspend(&client->dev);
- ret = devm_pm_runtime_enable(&client->dev);
+ pm_runtime_set_autosuspend_delay(dev, ADS1015_SLEEP_DELAY_MS);
+ pm_runtime_use_autosuspend(dev);
+ ret = devm_pm_runtime_enable(dev);
if (ret)
return ret;
- return devm_iio_device_register(&client->dev, indio_dev);
+ return devm_iio_device_register(dev, indio_dev);
}
static int ads1015_runtime_suspend(struct device *dev)
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 04/11] iio: adc: ti-ads1015: return -ENODATA when match data is missing
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
` (2 preceding siblings ...)
2026-11-09 16:51 ` [PATCH v6 03/11] iio: adc: ti-ads1015: use local device pointer in probe Archit Anant
@ 2026-11-09 16:51 ` Archit Anant
2026-11-09 16:51 ` [PATCH v6 05/11] iio: adc: ti-ads1015: use dev_err_probe() for error handling Archit Anant
4 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
When i2c_get_match_data() returns NULL, it indicates that driver match
data is absent rather than an invalid argument being provided.
Return -ENODATA instead of -EINVAL to more accurately reflect the failure.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index af3ba6b75c410..d18a2ac1205ff 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -974,7 +974,7 @@ static int ads1015_probe(struct i2c_client *client)
chip = i2c_get_match_data(client);
if (!chip)
- return dev_err_probe(&client->dev, -EINVAL, "Unknown chip\n");
+ return dev_err_probe(dev, -ENODATA, "Unknown chip\n");
indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev)
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 05/11] iio: adc: ti-ads1015: use dev_err_probe() for error handling
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
` (3 preceding siblings ...)
2026-11-09 16:51 ` [PATCH v6 04/11] iio: adc: ti-ads1015: return -ENODATA when match data is missing Archit Anant
@ 2026-11-09 16:51 ` Archit Anant
4 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-11-09 16:51 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Archit Anant
Simplify the error handling paths in ads1015_probe() and
ads1015_client_get_channels_config() by converting dev_err()
calls that are immediately followed by a return statement
over to the modern dev_err_probe() helper.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index d18a2ac1205ff..9fd07ee21ede8 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -896,18 +896,16 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
if (!fwnode_property_read_u32(node, "ti,gain", &pval)) {
pga = pval;
- if (pga > 5) {
- dev_err(dev, "invalid gain on %pfw\n", node);
- return -EINVAL;
- }
+ if (pga > 5)
+ return dev_err_probe(dev, -EINVAL,
+ "invalid gain on %pfw\n", node);
}
if (!fwnode_property_read_u32(node, "ti,datarate", &pval)) {
data_rate = pval;
- if (data_rate > 7) {
- dev_err(dev, "invalid data_rate on %pfw\n", node);
- return -EINVAL;
- }
+ if (data_rate > 7)
+ return dev_err_probe(dev, -EINVAL,
+ "invalid data_rate on %pfw\n", node);
}
if (fwnode_property_present(node, "label")) {
@@ -1018,18 +1016,16 @@ static int ads1015_probe(struct i2c_client *client)
data->regmap = devm_regmap_init_i2c(client, chip->has_comparator ?
&ads1015_regmap_config :
&tla2024_regmap_config);
- if (IS_ERR(data->regmap)) {
- dev_err(&client->dev, "Failed to allocate register map\n");
- return PTR_ERR(data->regmap);
- }
+ if (IS_ERR(data->regmap))
+ return dev_err_probe(dev, PTR_ERR(data->regmap),
+ "Failed to allocate register map\n");
ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
ads1015_trigger_handler,
&ads1015_buffer_setup_ops);
- if (ret < 0) {
- dev_err(&client->dev, "iio triggered buffer setup failed\n");
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(dev, ret,
+ "iio triggered buffer setup failed\n");
if (client->irq && chip->has_comparator) {
unsigned long irq_trig = irq_get_trigger_type(client->irq);
--
2.39.5
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-09 16:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 16:51 [PATCH v6 00/11] iio: adc: ti-ads1015: modernize resource management and driver setup Archit Anant
2026-11-09 16:51 ` [PATCH v6 01/11] iio: adc: ti-ads1015: use DEFINE_RUNTIME_DEV_PM_OPS() Archit Anant
2026-11-09 16:51 ` [PATCH v6 02/11] iio: adc: ti-ads1015: Sort headers alphabetically Archit Anant
2026-11-09 16:51 ` [PATCH v6 03/11] iio: adc: ti-ads1015: use local device pointer in probe Archit Anant
2026-11-09 16:51 ` [PATCH v6 04/11] iio: adc: ti-ads1015: return -ENODATA when match data is missing Archit Anant
2026-11-09 16:51 ` [PATCH v6 05/11] iio: adc: ti-ads1015: use dev_err_probe() for error handling Archit Anant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®