FAILED: patch "[PATCH] iio: adc: ti-ads1100: Fix incorrect reading when datarate changed in single mode" failed to apply to 6.6-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 38dbf24dfbd0a73b89fa2871a7148429aef05531
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 38dbf24dfbd0a73b89fa2871a7148429aef05531 Mon Sep 17 00:00:00 2001
From: Jakub Szczudlo <[email protected]>
Date: Tue, 4 Aug 2026 21:28:38 +0200
Subject: [PATCH] iio: adc: ti-ads1100: Fix incorrect reading when datarate
changed in single mode
When device is suspended and it is in single mode then changing datarate doesn't make it actually wait for new measurement, so to be sure that read after change is correct, functions that changes datarate and gain will wait for a new data.
--- drivers/iio/adc/ti-ads1100.c | 107 +++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-)
drivers/iio/adc/ti-ads1100.c +103 -4
@@ -15,10 +15,12 @@#include <linux/module.h> #include <linux/init.h> #include <linux/i2c.h> +#include <linux/iopoll.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <linux/time.h> #include <linux/units.h> #include <linux/iio/iio.h>
@@ -43,6 +45,9 @@static const int ads1100_data_rate[] = {128 ,32 ,16 ,8 };static const int ads1100_data_rate_bits[] = {12 ,14 ,15 ,16 }; +/* Timeout based on the minimum sample rate of 8 SPS (7500ms) */ +#define ADS1100_MAX_DRDY_TIMEOUT_US (7500 * USEC_PER_MSEC) +struct ads1100_data {struct i2c_client *client;struct regulator *reg_vdd;
@@ -123,10 +128,86 @@ static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val)return 0 ; } +static int ads1100_conversion_busy (struct ads1100_data *data) +{ +u8 buffer[3 ]; +int ret; + + ret =i2c_master_recv (data->client, (char *)&buffer,sizeof (buffer)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C read fail: %d\n" , ret); +return ret; + } + +return FIELD_GET (ADS1100_CFG_ST_BSY , buffer[2 ]); +} + +static int ads1100_wait_single_conversion (struct ads1100_data *data) +{ +int data_rate_index =FIELD_GET (ADS1100_DR_MASK , data->config); +int data_rate_Hz = ads1100_data_rate[data_rate_index]; +unsigned long poll_us =DIV_ROUND_CLOSEST (USEC_PER_SEC , data_rate_Hz) /4 ; +int busy; +int ret; + + ret =readx_poll_timeout (ads1100_conversion_busy, data, + busy, busy <=0 , + poll_us,ADS1100_MAX_DRDY_TIMEOUT_US ); +if (busy <0 ) +return busy; + +return ret; +} + +static int ads1100_start_single_conversion (struct ads1100_data *data) +{ +u8 config = data->config |ADS1100_CFG_SC ; +int ret; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } +/* Need to wait because of change from continuous to single mode */ + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + + config |=ADS1100_CFG_ST_BSY ; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } + +/* No need to cache it, it's status bit */ + data->config = config & ~ADS1100_CFG_ST_BSY ; + +return 0 ; +} + +static int ads1100_poll_data_ready (struct ads1100_data *data) +{ +int ret; + + ret =ads1100_start_single_conversion (data); +if (ret) +return ret; + + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + +return ads1100_set_config_bits (data,ADS1100_CFG_SC ,ADS1100_CONTINUOUS ); +} +static int ads1100_set_scale (struct ads1100_data *data,int val,int val2) {int microvolts;int gain; +int ret;/* With Vdd between 2.7 and 5V, the scale is always below 1 */ if (val)
@@ -135,6 +216,11 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)if (!val2)return -EINVAL ; +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (&data->client->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret) +return ret; + microvolts =regulator_get_voltage (data->reg_vdd);/* * val2 is in 'micro' units, n = val2 / 1000000
@@ -149,22 +235,35 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)ads1100_set_config_bits (data,ADS1100_PGA_MASK ,ffs (gain) -1 ); -return 0 ; +return ads1100_poll_data_ready (data); }static int ads1100_set_data_rate (struct ads1100_data *data,int chan,int rate) {unsigned int i;unsigned int size; +int ret; size = data->supports_data_rate ?ARRAY_SIZE (ads1100_data_rate) :1 ;for (i =0 ; i < size; i++) {if (ads1100_data_rate[i] == rate) -return ads1100_set_config_bits (data,ADS1100_DR_MASK , -FIELD_PREP (ADS1100_DR_MASK , i)); +break ; } -return -EINVAL ; +if (i == size) +return -EINVAL ; + +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (&data->client->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret) +return ret; + + ret =ads1100_set_config_bits (data,ADS1100_DR_MASK , +FIELD_PREP (ADS1100_DR_MASK , i)); +if (ret) +return ret; + +return ads1100_poll_data_ready (data); }static int ads1100_get_vdd_millivolts (struct ads1100_data *data)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 iio: adc: ti-ads1100: Fix incorrect reading when datarate changed in single mode
From: Jakub Szczudlo <[email protected]>
[ Upstream commit 38dbf24dfbd0a73b89fa2871a7148429aef05531 ]
When device is suspended and it is in single mode then changing datarate doesn't make it actually wait for new measurement, so to be sure that read after change is correct, functions that changes datarate and gain will wait for a new data.
--- drivers/iio/adc/ti-ads1100.c | 121 +++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 6 deletions(-)
drivers/iio/adc/ti-ads1100.c +115 -6
@@ -14,10 +14,12 @@#include <linux/module.h> #include <linux/init.h> #include <linux/i2c.h> +#include <linux/iopoll.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <linux/time.h> #include <linux/units.h> #include <linux/iio/iio.h>
@@ -42,6 +44,9 @@static const int ads1100_data_rate[] = {128 ,32 ,16 ,8 };static const int ads1100_data_rate_bits[] = {12 ,14 ,15 ,16 }; +/* Timeout based on the minimum sample rate of 8 SPS (7500ms) */ +#define ADS1100_MAX_DRDY_TIMEOUT_US (7500 * USEC_PER_MSEC) +struct ads1100_data {struct i2c_client *client;struct regulator *reg_vdd;
@@ -123,10 +128,86 @@ static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val)return 0 ; } +static int ads1100_conversion_busy (struct ads1100_data *data) +{ +u8 buffer[3 ]; +int ret; + + ret =i2c_master_recv (data->client, (char *)&buffer,sizeof (buffer)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C read fail: %d\n" , ret); +return ret; + } + +return FIELD_GET (ADS1100_CFG_ST_BSY , buffer[2 ]); +} + +static int ads1100_wait_single_conversion (struct ads1100_data *data) +{ +int data_rate_index =FIELD_GET (ADS1100_DR_MASK , data->config); +int data_rate_Hz = ads1100_data_rate[data_rate_index]; +unsigned long poll_us =DIV_ROUND_CLOSEST (USEC_PER_SEC , data_rate_Hz) /4 ; +int busy; +int ret; + + ret =readx_poll_timeout (ads1100_conversion_busy, data, + busy, busy <=0 , + poll_us,ADS1100_MAX_DRDY_TIMEOUT_US ); +if (busy <0 ) +return busy; + +return ret; +} + +static int ads1100_start_single_conversion (struct ads1100_data *data) +{ +u8 config = data->config |ADS1100_CFG_SC ; +int ret; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } +/* Need to wait because of change from continuous to single mode */ + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + + config |=ADS1100_CFG_ST_BSY ; + + ret =i2c_master_send (data->client, &config,sizeof (config)); +if (ret <0 ) { +dev_err (&data->client->dev,"I2C write fail: %d\n" , ret); +return ret; + } + +/* No need to cache it, it's status bit */ + data->config = config & ~ADS1100_CFG_ST_BSY ; + +return 0 ; +} + +static int ads1100_poll_data_ready (struct ads1100_data *data) +{ +int ret; + + ret =ads1100_start_single_conversion (data); +if (ret) +return ret; + + ret =ads1100_wait_single_conversion (data); +if (ret) +return ret; + +return ads1100_set_config_bits (data,ADS1100_CFG_SC ,ADS1100_CONTINUOUS ); +} +static int ads1100_set_scale (struct ads1100_data *data,int val,int val2) {int microvolts;int gain; +int ret;/* With Vdd between 2.7 and 5V, the scale is always below 1 */ if (val)
@@ -135,6 +216,10 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)if (!val2)return -EINVAL ; + ret =pm_runtime_resume_and_get (&data->client->dev); +if (ret) +return ret; + microvolts =regulator_get_voltage (data->reg_vdd);/* * val2 is in 'micro' units, n = val2 / 1000000
@@ -144,27 +229,51 @@ static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)* bitshift so everything fits in 32-bits yields this formula. */ gain =DIV_ROUND_CLOSEST (microvolts,BIT (15 )) *MILLI / val2; -if (gain <BIT (0 ) || gain >BIT (3 )) -return -EINVAL ; +if (gain <BIT (0 ) || gain >BIT (3 )) { + ret = -EINVAL ; + goto out; + }ads1100_set_config_bits (data,ADS1100_PGA_MASK ,ffs (gain) -1 ); -return 0 ; + ret =ads1100_poll_data_ready (data); +out: +pm_runtime_mark_last_busy (&data->client->dev); +pm_runtime_put_autosuspend (&data->client->dev); + +return ret; }static int ads1100_set_data_rate (struct ads1100_data *data,int chan,int rate) {unsigned int i;unsigned int size; +int ret; size = data->supports_data_rate ?ARRAY_SIZE (ads1100_data_rate) :1 ;for (i =0 ; i < size; i++) {if (ads1100_data_rate[i] == rate) -return ads1100_set_config_bits (data,ADS1100_DR_MASK , -FIELD_PREP (ADS1100_DR_MASK , i)); +break ; } -return -EINVAL ; +if (i == size) +return -EINVAL ; + + ret =pm_runtime_resume_and_get (&data->client->dev); +if (ret) +return ret; + + ret =ads1100_set_config_bits (data,ADS1100_DR_MASK , +FIELD_PREP (ADS1100_DR_MASK , i)); +if (ret) + goto out; + + ret =ads1100_poll_data_ready (data); +out: +pm_runtime_mark_last_busy (&data->client->dev); +pm_runtime_put_autosuspend (&data->client->dev); + +return ret; }static int ads1100_get_vdd_millivolts (struct ads1100_data *data)
Signature · 1 line
2.53.0