iio: adc: ti-ads1298 & Kconfig
cover iio: adc: ti-ads1298 & Kconfig
These patches improve the ti-ads1298 driver in two ways:
1- Safe usage guarantee for device communication
Wrap calls to ads1298_reg_access() and ads1298_write_raw() with iio_device_claim_direct() / iio_device_release_direct() so that configuration operations cannot interrupt an ongoing buffered capture.
2- Add kfifo dependency for module compilation
The driver now selects CONFIG_IIO_KFIFO_BUFFER in its Kconfig, just like other IIO ADC drivers, to ensure the kfifo buffer API is available when building ti-ads1298 as a module.
Arthur-Prince (2):
iio: adc: ti-ads1298
iio: adc: Kconfig
drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/ti-ads1298.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/2 iio: adc: ti-ads1298: Add safe usage guarantee for device communication
Add safe usage guarantee for device communication in ads1298_reg_access/ ads1298_write_raw (ti-ads1298) that prevent simultaneous read/write operations.
--- drivers/iio/adc/ti-ads1298.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
drivers/iio/adc/ti-ads1298.c +21 -4
@@ -355,9 +355,19 @@ static int ads1298_write_raw(struct iio_dev *indio_dev, {struct ads1298_private *priv =iio_priv (indio_dev); +int ret; +switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ : -return ads1298_set_samp_freq (priv, val); + ret =iio_device_claim_direct_mode (indio_dev); +if (ret) +return ret; + + ret =ads1298_set_samp_freq (priv, val); + +iio_device_release_direct_mode (indio_dev); + +return ret;default :return -EINVAL ; }
@@ -417,10 +427,17 @@ static int ads1298_reg_access(struct iio_dev *indio_dev, unsigned int reg, {struct ads1298_private *priv =iio_priv (indio_dev); +int ret; + ret =iio_device_claim_direct_mode (indio_dev); +if (ret) +return ret;if (readval) -return regmap_read (priv->regmap, reg, readval); - -return regmap_write (priv->regmap, reg, writeval); + ret =regmap_read (priv->regmap, reg, readval); +else + ret =regmap_write (priv->regmap, reg, writeval); + +iio_device_release_direct_mode (indio_dev); +return ret; }static void ads1298_rdata_unmark_busy (struct ads1298_private *priv)
Signature · 1 line
2.45.2
Jonathan Cameron
maintainerRe: [PATCH 1/2] iio: adc: ti-ads1298: Add safe usage guarantee for device communication
Quoted 7 lines · On Wed, 23 Apr 2025 15:46:25 -0300 Arthur-Prince <[email protected]>…
Add safe usage guarantee for device communication in ads1298_reg_access/
ads1298_write_raw(ti-ads1298) that prevent simultaneous read/write operations.Signed-off-by Arthur-Prince <[email protected]>Co-developed-by Mariana Valério <[email protected]>Signed-off-by Mariana Valério <[email protected]>
Two different things seem to be going on in here...
Quoted 14 lines
--- drivers/iio/adc/ti-ads1298.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)drivers/iio/adc/ti-ads1298.c +2
-0@@ -355,9 +355,19 @@ static int ads1298_write_raw(struct iio_dev *indio_dev, {struct ads1298_private *priv =iio_priv (indio_dev); +int ret; +
drivers/iio/adc/ti-ads1298.c static int ads1298_write_raw(struct iio_dev *indio_dev, · line 368
Quoted 10 lines
drivers/iio/adc/ti-ads1298.c +7
-1switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ : -return ads1298_set_samp_freq (priv, val); + ret =iio_device_claim_direct_mode (indio_dev); +if (ret) +return ret; + + ret =ads1298_set_samp_freq (priv, val); + +iio_device_release_direct_mode (indio_dev);
This prevents changing the sampling frequency. Some drivers prevent this whilst in buffered mode, but why is that necessary here?
drivers/iio/adc/ti-ads1298.c static int ads1298_reg_access(struct iio_dev *indio_dev, unsigned int reg, · line 431
Quoted 11 lines
drivers/iio/adc/ti-ads1298.c +4
-0+ +return ret;default :return -EINVAL ; }@@ -417,10 +427,17 @@ static int ads1298_reg_access(struct iio_dev *indio_dev, unsigned int reg, {struct ads1298_private *priv =iio_priv (indio_dev); +int ret; + ret =iio_device_claim_direct_mode (indio_dev);
For this one it's a debug interface. If the issue is people shooting themselves in the foot then we don't normally prevent that for these.
If there is something fundamental about regmap implementation that makes these accesses have side effects unconnected to what is being written then that needs calling out.
Quoted 15 lines
drivers/iio/adc/ti-ads1298.c +8
-3+if (ret) +return ret;if (readval) -return regmap_read (priv->regmap, reg, readval); - -return regmap_write (priv->regmap, reg, writeval); + ret =regmap_read (priv->regmap, reg, readval); +else + ret =regmap_write (priv->regmap, reg, writeval); + +iio_device_release_direct_mode (indio_dev); +return ret; }static void ads1298_rdata_unmark_busy (struct ads1298_private *priv)
PATCH 2/2 iio: adc: Kconfig: add kfifo dependency to fix module build
In reply to Arthur-PrinceAdd dependency to Kconfig’s ti-ads1298 because compiling it as a module failed with an undefined kfifo symbol. Building the full kernel passed since kfifo was enabled globally. Selecting IIO_KFIFO_BUFFER in ti-ads1298’s Kconfig, as done by other IIO ADC drivers, now ensures kfifo buffer support is included for module builds.
--- drivers/iio/adc/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/iio/adc/Kconfig +1 -0
@@ -1492,6 +1492,7 @@ config TI_ADS1298 tristate "Texas Instruments ADS1298" depends on SPI select IIO_BUFFER + select IIO_KFIFO_BUF help If you say yes here you get support for Texas Instruments ADS1298 medical ADC chips
Signature · 1 line
2.45.2
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: adc: Kconfig: add kfifo dependency to fix module build
Quoted 9 lines · On Wed, 23 Apr 2025 15:46:26 -0300 Arthur-Prince <[email protected]>…
Add dependency to Kconfig’s ti-ads1298 because compiling it as a module failed with an undefined kfifo symbol. Building the full kernel passed since kfifo was enabled globally. Selecting
IIO_KFIFO_BUFFERin ti-ads1298’sKconfig, as done by other IIO ADC drivers, now ensures kfifo buffer support is included for module builds.Signed-off-by Arthur-Prince <[email protected]>Co-developed-by Mariana Valério <[email protected]>Signed-off-by Mariana Valério <[email protected]>
Fixes tag?
Otherwise looks good.
Quoted 16 lines
--- drivers/iio/adc/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/iio/adc/Kconfig +1
-0@@ -1492,6 +1492,7 @@ config TI_ADS1298 tristate "Texas Instruments ADS1298" depends on SPI select IIO_BUFFER + select IIO_KFIFO_BUF help If you say yes here you get support for Texas Instruments ADS1298 medical ADC chips