* [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state()
@ 2026-11-09 16:58 Archit Anant
2026-11-09 16:58 ` [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks Archit Anant
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
Remove the unnecessary ads1015_set_power_state() helper and
use runtime PM helpers directly at the call sites.
Use PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND() to manage the
runtime PM reference in __ads1015_read_info_raw(), ensuring
it is automatically released on function exit, including
error paths.
For event configuration and buffer operations, retain
explicit reference management as the runtime PM reference
must remain held beyond the lifetime of the respective
function.
Mark the device as last busy before putting it into
autosuspend.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 59 +++++++++++++++---------------------
1 file changed, 24 insertions(+), 35 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 9fd07ee21ede8..2e6bf45871340 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -366,30 +366,6 @@ static const struct iio_chan_spec tla2024_channels[] = {
IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
};
-
-#ifdef CONFIG_PM
-static int ads1015_set_power_state(struct ads1015_data *data, bool on)
-{
- int ret;
- struct device *dev = regmap_get_device(data->regmap);
-
- if (on)
- ret = pm_runtime_resume_and_get(dev);
- else
- ret = pm_runtime_put_autosuspend(dev);
-
- return ret < 0 ? ret : 0;
-}
-
-#else /* !CONFIG_PM */
-
-static int ads1015_set_power_state(struct ads1015_data *data, bool on)
-{
- return 0;
-}
-
-#endif /* !CONFIG_PM */
-
static
int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
{
@@ -532,26 +508,26 @@ static int ads1015_read_avail(struct iio_dev *indio_dev,
static int __ads1015_read_info_raw(struct ads1015_data *data,
struct iio_chan_spec const *chan, int *val)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
if (ads1015_event_channel_enabled(data) &&
data->event_channel != chan->address)
return -EBUSY;
- ret = ads1015_set_power_state(data, true);
- if (ret < 0)
+ PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev, guard);
+ ret = PM_RUNTIME_ACQUIRE_ERR(&guard);
+ if (ret)
return ret;
ret = ads1015_get_adc_result(data, chan->address, val);
- if (ret < 0) {
- ads1015_set_power_state(data, false);
+ if (ret < 0)
return ret;
- }
*val = sign_extend32(*val >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
- return ads1015_set_power_state(data, false);
+ return 0;
}
static int ads1015_read_raw(struct iio_dev *indio_dev,
@@ -709,6 +685,7 @@ static int ads1015_enable_event_config(struct ads1015_data *data,
{
int low_thresh = data->thresh_data[chan->address].low_thresh;
int high_thresh = data->thresh_data[chan->address].high_thresh;
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
unsigned int val;
@@ -735,7 +712,7 @@ static int ads1015_enable_event_config(struct ads1015_data *data,
if (ret)
return ret;
- ret = ads1015_set_power_state(data, true);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
return ret;
@@ -744,7 +721,8 @@ static int ads1015_enable_event_config(struct ads1015_data *data,
ret = ads1015_get_adc_result(data, chan->address, &val);
if (ret) {
ads1015_event_channel_disable(data, chan->address);
- ads1015_set_power_state(data, false);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
}
return ret;
@@ -753,6 +731,7 @@ static int ads1015_enable_event_config(struct ads1015_data *data,
static int ads1015_disable_event_config(struct ads1015_data *data,
const struct iio_chan_spec *chan, int comp_mode)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
if (!ads1015_event_channel_enabled(data))
@@ -774,7 +753,10 @@ static int ads1015_disable_event_config(struct ads1015_data *data,
ads1015_event_channel_disable(data, chan->address);
- return ads1015_set_power_state(data, false);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+
+ return 0;
}
static int ads1015_write_event_config(struct iio_dev *indio_dev,
@@ -830,17 +812,24 @@ static irqreturn_t ads1015_event_handler(int irq, void *priv)
static int ads1015_buffer_preenable(struct iio_dev *indio_dev)
{
struct ads1015_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
/* Prevent from enabling both buffer and event at a time */
if (ads1015_event_channel_enabled(data))
return -EBUSY;
- return ads1015_set_power_state(iio_priv(indio_dev), true);
+ return pm_runtime_resume_and_get(dev);
}
static int ads1015_buffer_postdisable(struct iio_dev *indio_dev)
{
- return ads1015_set_power_state(iio_priv(indio_dev), false);
+ struct ads1015_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
+
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+
+ return 0;
}
static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
@ 2026-11-09 16:58 ` Archit Anant
2026-11-09 18:49 ` Andy Shevchenko
2026-11-09 16:58 ` [PATCH v6 08/11] iio: adc: ti-ads1015: use devm_mutex_init() Archit Anant
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Andy Shevchenko
The devm_iio_triggered_buffer_setup() function returns 0 on
success and a negative error code on failure.
Use a simple boolean check instead of explicitly checking
for a negative return value.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
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 2e6bf45871340..1924c1b2abeea 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -1012,7 +1012,7 @@ static int ads1015_probe(struct i2c_client *client)
ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
ads1015_trigger_handler,
&ads1015_buffer_setup_ops);
- if (ret < 0)
+ if (ret)
return dev_err_probe(dev, ret,
"iio triggered buffer setup failed\n");
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 08/11] iio: adc: ti-ads1015: use devm_mutex_init()
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
2026-11-09 16:58 ` [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks Archit Anant
@ 2026-11-09 16:58 ` Archit Anant
2026-11-09 16:58 ` [PATCH v6 09/11] iio: adc: ti-ads1015: use managed runtime PM setup Archit Anant
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
Convert mutex_init() to devm_mutex_init(). This ensures that the
mutex is automatically destroyed when the device is unbound, and
simplifies error handling.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 1924c1b2abeea..a65da3742bec2 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -970,7 +970,9 @@ static int ads1015_probe(struct i2c_client *client)
data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
- mutex_init(&data->lock);
+ ret = devm_mutex_init(dev, &data->lock);
+ if (ret)
+ return ret;
indio_dev->name = ADS1015_DRV_NAME;
indio_dev->modes = INDIO_DIRECT_MODE;
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 09/11] iio: adc: ti-ads1015: use managed runtime PM setup
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
2026-11-09 16:58 ` [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks Archit Anant
2026-11-09 16:58 ` [PATCH v6 08/11] iio: adc: ti-ads1015: use devm_mutex_init() Archit Anant
@ 2026-11-09 16:58 ` Archit Anant
2026-11-09 16:58 ` [PATCH v6 10/11] iio: adc: ti-ads1015: inline ads1015_set_conv_mode() Archit Anant
2026-11-09 16:58 ` [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET Archit Anant
4 siblings, 0 replies; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
Use devm_pm_runtime_set_active_enabled() to combine setting the device
active and enabling runtime PM.
Previously, probe explicitly called pm_runtime_set_active() followed by
devm_pm_runtime_enable(). The managed helper changes the teardown
semantics by associating runtime PM enablement with the device-managed
lifetime.
The runtime suspend and resume callbacks only update the conversion-mode
bits through regmap. They do not manipulate runtime-PM usage counts or
other shared resources such as regulators or clocks, so this change does
not introduce an additional runtime-PM reference or resource-balance
operation in this driver.
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index a65da3742bec2..93a8318e950e2 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -1064,12 +1064,9 @@ static int ads1015_probe(struct i2c_client *client)
data->conv_invalid = true;
- ret = pm_runtime_set_active(dev);
- if (ret)
- return ret;
pm_runtime_set_autosuspend_delay(dev, ADS1015_SLEEP_DELAY_MS);
pm_runtime_use_autosuspend(dev);
- ret = devm_pm_runtime_enable(dev);
+ ret = devm_pm_runtime_set_active_enabled(dev);
if (ret)
return ret;
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 10/11] iio: adc: ti-ads1015: inline ads1015_set_conv_mode()
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
` (2 preceding siblings ...)
2026-11-09 16:58 ` [PATCH v6 09/11] iio: adc: ti-ads1015: use managed runtime PM setup Archit Anant
@ 2026-11-09 16:58 ` Archit Anant
2026-11-09 16:58 ` [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET Archit Anant
4 siblings, 0 replies; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
The ads1015_set_conv_mode() helper function is a single-line wrapper
around regmap_update_bits().
Since the function is simple and only called during initialization and
power management state transitions, the wrapper is unnecessary. Remove
it and inline the regmap_update_bits() logic directly at the call sites
to improve code readability and traceabilty.
Where applicable, introduce a local 'map' pointer to keep the
inlined function calls concise.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 93a8318e950e2..2c3ba1b91aac4 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -932,21 +932,16 @@ static void ads1015_get_channels_config(struct i2c_client *client)
}
}
-static int ads1015_set_conv_mode(struct ads1015_data *data, int mode)
-{
- return regmap_update_bits(data->regmap, ADS1015_CFG_REG,
- ADS1015_CFG_MOD_MASK,
- mode << ADS1015_CFG_MOD_SHIFT);
-}
-
static void ads1015_power_down(void *p)
{
struct ads1015_data *data = p;
+ struct regmap *map = data->regmap;
int ret;
- ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
+ ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
+ ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
if (ret)
- dev_warn(regmap_get_device(data->regmap),
+ dev_warn(regmap_get_device(map),
"Failed to power down (%pe)\n", ERR_PTR(ret));
}
@@ -956,6 +951,7 @@ static int ads1015_probe(struct i2c_client *client)
struct device *dev = &client->dev;
struct iio_dev *indio_dev;
struct ads1015_data *data;
+ struct regmap *map;
int ret;
int i;
@@ -1007,8 +1003,9 @@ 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))
- return dev_err_probe(dev, PTR_ERR(data->regmap),
+ map = data->regmap;
+ if (IS_ERR(map))
+ return dev_err_probe(dev, PTR_ERR(map),
"Failed to allocate register map\n");
ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
@@ -1041,7 +1038,7 @@ static int ads1015_probe(struct i2c_client *client)
return -EINVAL;
}
- ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG,
+ ret = regmap_update_bits(map, ADS1015_CFG_REG,
cfg_comp_mask, cfg_comp);
if (ret)
return ret;
@@ -1054,7 +1051,8 @@ static int ads1015_probe(struct i2c_client *client)
return ret;
}
- ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
+ ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
+ ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
if (ret)
return ret;
@@ -1077,17 +1075,21 @@ static int ads1015_runtime_suspend(struct device *dev)
{
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct ads1015_data *data = iio_priv(indio_dev);
+ struct regmap *map = data->regmap;
- return ads1015_set_conv_mode(data, ADS1015_SINGLESHOT);
+ return regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
+ ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
}
static int ads1015_runtime_resume(struct device *dev)
{
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct ads1015_data *data = iio_priv(indio_dev);
+ struct regmap *map = data->regmap;
int ret;
- ret = ads1015_set_conv_mode(data, ADS1015_CONTINUOUS);
+ ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
+ ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
if (!ret)
data->conv_invalid = true;
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
` (3 preceding siblings ...)
2026-11-09 16:58 ` [PATCH v6 10/11] iio: adc: ti-ads1015: inline ads1015_set_conv_mode() Archit Anant
@ 2026-11-09 16:58 ` Archit Anant
2026-11-09 19:43 ` Andy Shevchenko
4 siblings, 1 reply; 8+ messages in thread
From: Archit Anant @ 2026-11-09 16:58 UTC (permalink / raw)
To: jic23
Cc: dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1, Andy Shevchenko
The driver currently uses custom _SHIFT macros and manual bitwise
operations to read and write to the configuration register.
Modernize the bitwise logic by replacing all manual shifts with the
standard FIELD_PREP() and FIELD_GET() macros from <linux/bitfield.h>.
This improves readability and prevents potential bitwise errors.
Remove the now-unused _SHIFT macros from the top of the file.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Archit Anant <architanant5@gmail.com>
---
drivers/iio/adc/ti-ads1015.c | 79 ++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 35 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 2c3ba1b91aac4..8f7ec61314363 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -11,6 +11,7 @@
* * 0x4B - ADDR connected to SCL
*/
+#include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/i2c.h>
@@ -38,15 +39,6 @@
#define ADS1015_LO_THRESH_REG 0x02
#define ADS1015_HI_THRESH_REG 0x03
-#define ADS1015_CFG_COMP_QUE_SHIFT 0
-#define ADS1015_CFG_COMP_LAT_SHIFT 2
-#define ADS1015_CFG_COMP_POL_SHIFT 3
-#define ADS1015_CFG_COMP_MODE_SHIFT 4
-#define ADS1015_CFG_DR_SHIFT 5
-#define ADS1015_CFG_MOD_SHIFT 8
-#define ADS1015_CFG_PGA_SHIFT 9
-#define ADS1015_CFG_MUX_SHIFT 12
-
#define ADS1015_CFG_COMP_QUE_MASK GENMASK(1, 0)
#define ADS1015_CFG_COMP_LAT_MASK BIT(2)
#define ADS1015_CFG_COMP_POL_MASK BIT(3)
@@ -382,17 +374,24 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
pga = data->channel_data[chan].pga;
dr = data->channel_data[chan].data_rate;
- mask = ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
- ADS1015_CFG_DR_MASK;
- cfg = chan << ADS1015_CFG_MUX_SHIFT | pga << ADS1015_CFG_PGA_SHIFT |
- dr << ADS1015_CFG_DR_SHIFT;
if (ads1015_event_channel_enabled(data)) {
- mask |= ADS1015_CFG_COMP_QUE_MASK | ADS1015_CFG_COMP_MODE_MASK;
- cfg |= data->thresh_data[chan].comp_queue <<
- ADS1015_CFG_COMP_QUE_SHIFT |
- data->comp_mode <<
- ADS1015_CFG_COMP_MODE_SHIFT;
+ mask = ADS1015_CFG_COMP_QUE_MASK | ADS1015_CFG_COMP_MODE_MASK |
+ ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
+ ADS1015_CFG_DR_MASK;
+ cfg = FIELD_PREP(ADS1015_CFG_MUX_MASK, chan) |
+ FIELD_PREP(ADS1015_CFG_PGA_MASK, pga) |
+ FIELD_PREP(ADS1015_CFG_DR_MASK, dr) |
+ FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK,
+ data->thresh_data[chan].comp_queue) |
+ FIELD_PREP(ADS1015_CFG_COMP_MODE_MASK,
+ data->comp_mode);
+ } else {
+ mask = ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
+ ADS1015_CFG_DR_MASK;
+ cfg = FIELD_PREP(ADS1015_CFG_MUX_MASK, chan) |
+ FIELD_PREP(ADS1015_CFG_PGA_MASK, pga) |
+ FIELD_PREP(ADS1015_CFG_DR_MASK, dr);
}
cfg = (old & ~mask) | (cfg & mask);
@@ -403,7 +402,7 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
data->conv_invalid = true;
}
if (data->conv_invalid) {
- dr_old = (old & ADS1015_CFG_DR_MASK) >> ADS1015_CFG_DR_SHIFT;
+ dr_old = FIELD_GET(ADS1015_CFG_DR_MASK, old);
conv_time = DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr_old]);
conv_time += DIV_ROUND_UP(USEC_PER_SEC, data_rate[dr]);
conv_time += conv_time / 10; /* 10% internal clock inaccuracy */
@@ -731,7 +730,9 @@ static int ads1015_enable_event_config(struct ads1015_data *data,
static int ads1015_disable_event_config(struct ads1015_data *data,
const struct iio_chan_spec *chan, int comp_mode)
{
- struct device *dev = regmap_get_device(data->regmap);
+ struct regmap *map = data->regmap;
+ struct device *dev = regmap_get_device(map);
+ unsigned int val;
int ret;
if (!ads1015_event_channel_enabled(data))
@@ -744,10 +745,9 @@ static int ads1015_disable_event_config(struct ads1015_data *data,
comp_mode == ADS1015_CFG_COMP_MODE_WINDOW)
return 0;
- ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG,
- ADS1015_CFG_COMP_QUE_MASK,
- ADS1015_CFG_COMP_DISABLE <<
- ADS1015_CFG_COMP_QUE_SHIFT);
+ val = FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK, ADS1015_CFG_COMP_DISABLE);
+ ret = regmap_update_bits(map, ADS1015_CFG_REG,
+ ADS1015_CFG_COMP_QUE_MASK, val);
if (ret)
return ret;
@@ -936,10 +936,12 @@ static void ads1015_power_down(void *p)
{
struct ads1015_data *data = p;
struct regmap *map = data->regmap;
+ unsigned int val;
int ret;
- ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
- ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
+ val = FIELD_PREP(ADS1015_CFG_MOD_MASK, ADS1015_SINGLESHOT);
+ ret = regmap_update_bits(map, ADS1015_CFG_REG,
+ ADS1015_CFG_MOD_MASK, val);
if (ret)
dev_warn(regmap_get_device(map),
"Failed to power down (%pe)\n", ERR_PTR(ret));
@@ -951,6 +953,7 @@ static int ads1015_probe(struct i2c_client *client)
struct device *dev = &client->dev;
struct iio_dev *indio_dev;
struct ads1015_data *data;
+ unsigned int cfg_mode;
struct regmap *map;
int ret;
int i;
@@ -1020,19 +1023,20 @@ static int ads1015_probe(struct i2c_client *client)
unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK |
ADS1015_CFG_COMP_LAT_MASK | ADS1015_CFG_COMP_POL_MASK;
unsigned int cfg_comp =
- ADS1015_CFG_COMP_DISABLE << ADS1015_CFG_COMP_QUE_SHIFT |
- 1 << ADS1015_CFG_COMP_LAT_SHIFT;
+ FIELD_PREP(ADS1015_CFG_COMP_QUE_MASK,
+ ADS1015_CFG_COMP_DISABLE) |
+ FIELD_PREP(ADS1015_CFG_COMP_LAT_MASK, 1);
switch (irq_trig) {
case IRQF_TRIGGER_FALLING:
case IRQF_TRIGGER_LOW:
- cfg_comp |= ADS1015_CFG_COMP_POL_LOW <<
- ADS1015_CFG_COMP_POL_SHIFT;
+ cfg_comp |= FIELD_PREP(ADS1015_CFG_COMP_POL_MASK,
+ ADS1015_CFG_COMP_POL_LOW);
break;
case IRQF_TRIGGER_HIGH:
case IRQF_TRIGGER_RISING:
- cfg_comp |= ADS1015_CFG_COMP_POL_HIGH <<
- ADS1015_CFG_COMP_POL_SHIFT;
+ cfg_comp |= FIELD_PREP(ADS1015_CFG_COMP_POL_MASK,
+ ADS1015_CFG_COMP_POL_HIGH);
break;
default:
return -EINVAL;
@@ -1051,8 +1055,9 @@ static int ads1015_probe(struct i2c_client *client)
return ret;
}
+ cfg_mode = FIELD_PREP(ADS1015_CFG_MOD_MASK, ADS1015_CONTINUOUS);
ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
- ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
+ cfg_mode);
if (ret)
return ret;
@@ -1076,9 +1081,11 @@ static int ads1015_runtime_suspend(struct device *dev)
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct ads1015_data *data = iio_priv(indio_dev);
struct regmap *map = data->regmap;
+ unsigned int val;
+ val = FIELD_PREP(ADS1015_CFG_MOD_MASK, ADS1015_SINGLESHOT);
return regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
- ADS1015_SINGLESHOT << ADS1015_CFG_MOD_SHIFT);
+ val);
}
static int ads1015_runtime_resume(struct device *dev)
@@ -1086,10 +1093,12 @@ static int ads1015_runtime_resume(struct device *dev)
struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
struct ads1015_data *data = iio_priv(indio_dev);
struct regmap *map = data->regmap;
+ unsigned int val;
int ret;
+ val = FIELD_PREP(ADS1015_CFG_MOD_MASK, ADS1015_CONTINUOUS);
ret = regmap_update_bits(map, ADS1015_CFG_REG, ADS1015_CFG_MOD_MASK,
- ADS1015_CONTINUOUS << ADS1015_CFG_MOD_SHIFT);
+ val);
if (!ret)
data->conv_invalid = true;
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks
2026-11-09 16:58 ` [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks Archit Anant
@ 2026-11-09 18:49 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-11-09 18:49 UTC (permalink / raw)
To: Archit Anant
Cc: jic23, dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
On Mon, Nov 09, 2026 at 10:28:01PM +0530, Archit Anant wrote:
> The devm_iio_triggered_buffer_setup() function returns 0 on
> success and a negative error code on failure.
>
> Use a simple boolean check instead of explicitly checking
> for a negative return value.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET
2026-11-09 16:58 ` [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET Archit Anant
@ 2026-11-09 19:43 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-11-09 19:43 UTC (permalink / raw)
To: Archit Anant
Cc: jic23, dlechner, andy, nuno.sa, u.kleine-koenig, linux-iio,
linux-kernel, joshua.crofts1
On Mon, Nov 09, 2026 at 10:28:05PM +0530, Archit Anant wrote:
> The driver currently uses custom _SHIFT macros and manual bitwise
> operations to read and write to the configuration register.
>
> Modernize the bitwise logic by replacing all manual shifts with the
> standard FIELD_PREP() and FIELD_GET() macros from <linux/bitfield.h>.
> This improves readability and prevents potential bitwise errors.
>
> Remove the now-unused _SHIFT macros from the top of the file.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
...
> + mask = ADS1015_CFG_MUX_MASK | ADS1015_CFG_PGA_MASK |
> + ADS1015_CFG_DR_MASK;
Indentation is broken here.
> + cfg = FIELD_PREP(ADS1015_CFG_MUX_MASK, chan) |
> + FIELD_PREP(ADS1015_CFG_PGA_MASK, pga) |
> + FIELD_PREP(ADS1015_CFG_DR_MASK, dr);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-09 19:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 16:58 [PATCH v6 06/11] iio: adc: ti-ads1015: Remove ads1015_set_power_state() Archit Anant
2026-11-09 16:58 ` [PATCH v6 07/11] iio: adc: ti-ads1015: drop unneeded < 0 error checks Archit Anant
2026-11-09 18:49 ` Andy Shevchenko
2026-11-09 16:58 ` [PATCH v6 08/11] iio: adc: ti-ads1015: use devm_mutex_init() Archit Anant
2026-11-09 16:58 ` [PATCH v6 09/11] iio: adc: ti-ads1015: use managed runtime PM setup Archit Anant
2026-11-09 16:58 ` [PATCH v6 10/11] iio: adc: ti-ads1015: inline ads1015_set_conv_mode() Archit Anant
2026-11-09 16:58 ` [PATCH v6 11/11] iio: adc: ti-ads1015: Replace custom shift macros with FIELD_PREP/GET Archit Anant
2026-11-09 19:43 ` Andy Shevchenko
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®