* [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info
@ 2026-03-31 1:24 Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 1/2] iio: adc: ltc2309: add read delay for ltc2305 Carlos Jones Jr
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Carlos Jones Jr @ 2026-03-31 1:24 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Michael Hennerich, Liam Beguin,
Nuno Sá, Andy Shevchenko, Jorge Marques
Cc: linux-iio, linux-kernel
This series adds missing read delay support for the LTC2305 and optimizes
the chip_info structure for better memory safety and efficiency.
The LTC2305 requires a 1.6μs delay between I2C channel selection and
data read operations - a timing requirement identified by the hardware
designer that wasn't captured in the initial LTC2305 support
(commit 8625d418d24b ("iio: adc: ltc2309: add support for ltc2305")).
Additionally, the chip_info structure is enhanced with __counted_by_ptr()
annotation for improved bounds checking and reorganized to minimize
padding.
Changes in v2:
- Split into two logical patches as suggested by Andy Shevchenko:
* Patch 1: Read delay functionality
* Patch 2: Structure optimization
- No code changes from v1, only reorganization
Link to v1:
https://lore.kernel.org/linux-iio/20260327034159.15545-1-carlosjr.jones@analog.com/
Carlos Jones Jr (2):
iio: adc: ltc2309: add read delay for ltc2305
iio: adc: ltc2309: Optimize chip_info structure layout
drivers/iio/adc/ltc2309.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] iio: adc: ltc2309: add read delay for ltc2305
2026-03-31 1:24 [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Carlos Jones Jr
@ 2026-03-31 1:24 ` Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 2/2] iio: adc: ltc2309: Optimize chip_info structure layout Carlos Jones Jr
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Carlos Jones Jr @ 2026-03-31 1:24 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Michael Hennerich, Liam Beguin,
Nuno Sá, Andy Shevchenko, Jorge Marques
Cc: linux-iio, linux-kernel
The LTC2305 requires a minimum 1.6μs delay between the I2C write
operation (channel selection) and the subsequent read operation to
allow the chip to process the command and prepare the result. While
not explicitly documented in the datasheet, this timing requirement
was identified by the hardware designer as necessary for reliable
operation.
Add a read_delay_us field to both the ltc2309_chip_info and ltc2309
device structures to support chip-specific timing requirements. Use
fsleep() to implement the delay when non-zero, with LTC2305 set to
2μs (1.6μs requirement rounded up). LTC2309 does not require
additional delay beyond inherent I2C bus timing.
This extends the existing LTC2305 support added in
(commit 8625d418d24b ("iio: adc: ltc2309: add support for ltc2305"))
with the missing inter-transaction delay.
Signed-off-by: Carlos Jones Jr <carlosjr.jones@analog.com>
---
drivers/iio/adc/ltc2309.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iio/adc/ltc2309.c b/drivers/iio/adc/ltc2309.c
index 316256edf150..094966289922 100644
--- a/drivers/iio/adc/ltc2309.c
+++ b/drivers/iio/adc/ltc2309.c
@@ -9,7 +9,9 @@
*
* Copyright (c) 2023, Liam Beguin <liambeguin@gmail.com>
*/
+#include <linux/array_size.h>
#include <linux/bitfield.h>
+#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/kernel.h>
@@ -34,12 +36,14 @@
* @client: I2C reference
* @lock: Lock to serialize data access
* @vref_mv: Internal voltage reference
+ * @read_delay_us: Chip-specific read delay in microseconds
*/
struct ltc2309 {
struct device *dev;
struct i2c_client *client;
struct mutex lock; /* serialize data access */
int vref_mv;
+ unsigned int read_delay_us;
};
/* Order matches expected channel address, See datasheet Table 1. */
@@ -118,12 +122,14 @@ static const struct iio_chan_spec ltc2309_channels[] = {
struct ltc2309_chip_info {
const char *name;
const struct iio_chan_spec *channels;
+ unsigned int read_delay_us;
int num_channels;
};
static const struct ltc2309_chip_info ltc2305_chip_info = {
.name = "ltc2305",
.channels = ltc2305_channels,
+ .read_delay_us = 2,
.num_channels = ARRAY_SIZE(ltc2305_channels),
};
@@ -151,6 +157,9 @@ static int ltc2309_read_raw_channel(struct ltc2309 *ltc2309,
return ret;
}
+ if (ltc2309->read_delay_us)
+ fsleep(ltc2309->read_delay_us);
+
ret = i2c_master_recv(ltc2309->client, (char *)&buf, 2);
if (ret < 0) {
dev_err(ltc2309->dev, "i2c read failed: %pe\n", ERR_PTR(ret));
@@ -206,6 +215,7 @@ static int ltc2309_probe(struct i2c_client *client)
ltc2309->dev = &indio_dev->dev;
ltc2309->client = client;
+ ltc2309->read_delay_us = chip_info->read_delay_us;
indio_dev->name = chip_info->name;
indio_dev->modes = INDIO_DIRECT_MODE;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] iio: adc: ltc2309: Optimize chip_info structure layout
2026-03-31 1:24 [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 1/2] iio: adc: ltc2309: add read delay for ltc2305 Carlos Jones Jr
@ 2026-03-31 1:24 ` Carlos Jones Jr
2026-03-31 7:01 ` [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Andy Shevchenko
2026-03-31 10:44 ` Nuno Sá
3 siblings, 0 replies; 5+ messages in thread
From: Carlos Jones Jr @ 2026-03-31 1:24 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Michael Hennerich, Liam Beguin,
Nuno Sá, Andy Shevchenko, Jorge Marques
Cc: linux-iio, linux-kernel
Improve the ltc2309_chip_info structure with better type safety and
memory efficiency:
- Add __counted_by_ptr() annotation to the channels pointer, linking
it to num_channels for improved bounds checking and kernel hardening
- Reorder structure fields to minimize padding:
* Place read_delay_us before num_channels
* This reduces struct size and eliminates internal gaps
- Reorder field initialization to match the structure definition order
The __counted_by_ptr() attribute enables compile-time and runtime
verification that array accesses to channels[] stay within the bounds
specified by num_channels, improving memory safety.
Signed-off-by: Carlos Jones Jr <carlosjr.jones@analog.com>
---
drivers/iio/adc/ltc2309.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/ltc2309.c b/drivers/iio/adc/ltc2309.c
index 094966289922..87b78d0353f1 100644
--- a/drivers/iio/adc/ltc2309.c
+++ b/drivers/iio/adc/ltc2309.c
@@ -121,22 +121,22 @@ static const struct iio_chan_spec ltc2309_channels[] = {
struct ltc2309_chip_info {
const char *name;
- const struct iio_chan_spec *channels;
unsigned int read_delay_us;
int num_channels;
+ const struct iio_chan_spec *channels __counted_by_ptr(num_channels);
};
static const struct ltc2309_chip_info ltc2305_chip_info = {
.name = "ltc2305",
- .channels = ltc2305_channels,
.read_delay_us = 2,
.num_channels = ARRAY_SIZE(ltc2305_channels),
+ .channels = ltc2305_channels,
};
static const struct ltc2309_chip_info ltc2309_chip_info = {
.name = "ltc2309",
- .channels = ltc2309_channels,
.num_channels = ARRAY_SIZE(ltc2309_channels),
+ .channels = ltc2309_channels,
};
static int ltc2309_read_raw_channel(struct ltc2309 *ltc2309,
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info
2026-03-31 1:24 [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 1/2] iio: adc: ltc2309: add read delay for ltc2305 Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 2/2] iio: adc: ltc2309: Optimize chip_info structure layout Carlos Jones Jr
@ 2026-03-31 7:01 ` Andy Shevchenko
2026-03-31 10:44 ` Nuno Sá
3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-31 7:01 UTC (permalink / raw)
To: Carlos Jones Jr
Cc: Jonathan Cameron, David Lechner, Michael Hennerich, Liam Beguin,
Nuno Sá, Andy Shevchenko, Jorge Marques, linux-iio,
linux-kernel
On Tue, Mar 31, 2026 at 4:25 AM Carlos Jones Jr
<carlosjr.jones@analog.com> wrote:
>
> This series adds missing read delay support for the LTC2305 and optimizes
> the chip_info structure for better memory safety and efficiency.
>
> The LTC2305 requires a 1.6μs delay between I2C channel selection and
> data read operations - a timing requirement identified by the hardware
> designer that wasn't captured in the initial LTC2305 support
> (commit 8625d418d24b ("iio: adc: ltc2309: add support for ltc2305")).
>
> Additionally, the chip_info structure is enhanced with __counted_by_ptr()
> annotation for improved bounds checking and reorganized to minimize
> padding.
Now LGTM,
Reviewed-by: Andy Shevchenko <andy@kernel.org>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info
2026-03-31 1:24 [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Carlos Jones Jr
` (2 preceding siblings ...)
2026-03-31 7:01 ` [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Andy Shevchenko
@ 2026-03-31 10:44 ` Nuno Sá
3 siblings, 0 replies; 5+ messages in thread
From: Nuno Sá @ 2026-03-31 10:44 UTC (permalink / raw)
To: Carlos Jones Jr
Cc: Jonathan Cameron, David Lechner, Michael Hennerich, Liam Beguin,
Nuno Sá, Andy Shevchenko, Jorge Marques, linux-iio,
linux-kernel
On Tue, Mar 31, 2026 at 09:24:55AM +0800, Carlos Jones Jr wrote:
> This series adds missing read delay support for the LTC2305 and optimizes
> the chip_info structure for better memory safety and efficiency.
>
> The LTC2305 requires a 1.6μs delay between I2C channel selection and
> data read operations - a timing requirement identified by the hardware
> designer that wasn't captured in the initial LTC2305 support
> (commit 8625d418d24b ("iio: adc: ltc2309: add support for ltc2305")).
>
> Additionally, the chip_info structure is enhanced with __counted_by_ptr()
> annotation for improved bounds checking and reorganized to minimize
> padding.
>
> Changes in v2:
> - Split into two logical patches as suggested by Andy Shevchenko:
> * Patch 1: Read delay functionality
> * Patch 2: Structure optimization
> - No code changes from v1, only reorganization
>
> Link to v1:
> https://lore.kernel.org/linux-iio/20260327034159.15545-1-carlosjr.jones@analog.com/
>
> Carlos Jones Jr (2):
> iio: adc: ltc2309: add read delay for ltc2305
> iio: adc: ltc2309: Optimize chip_info structure layout
>
> drivers/iio/adc/ltc2309.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> --
> 2.43.0
>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-31 10:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 1:24 [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 1/2] iio: adc: ltc2309: add read delay for ltc2305 Carlos Jones Jr
2026-03-31 1:24 ` [PATCH v2 2/2] iio: adc: ltc2309: Optimize chip_info structure layout Carlos Jones Jr
2026-03-31 7:01 ` [PATCH v2 0/2] iio: adc: ltc2309: Add LTC2305 read delay and optimize chip_info Andy Shevchenko
2026-03-31 10:44 ` Nuno Sá
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox