Skip to contentSkip to conversation

iio: adc: add driver for Texas Instruments TLA2528 adc

PATCH Superseded Maxime Chevallier 5 participants 10 messages Nov 4 – Nov 7

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover iio: adc: add driver for Texas Instruments TLA2528 adc

Hi everyone,

This is V3 for the TLA2528 ADC driver.

It takes all reviews from Jonathan, Matti, Rodolfo and Victor into account, thanks again everyone for that :)

Matti, I've not put your review tag as I've reworked things quite a bit, sorry about that.

Maxime

V3:
- Require channels to be described
- Use guard()
- Add Datasheet link
- Drop the unused registers
- Use named initializers in the id table
- Collect Conor's Ack

V2: https://lore.kernel.org/r/[email protected]
- Describe AVDD and DVDD in the bindings instead of vref.
- Add gpio-controller
- Allow describing individual ADC channels
- Switch to regmap with caching
- Reset the chip at probe time
- Small cleanups following all the reviews
- Moved MAINTAINERS to patch 1

V1: https://lore.kernel.org/linux-iio/[email protected]/

Maxime Chevallier (2):
dt-bindings: iio: adc: add Texas Instruments TLA2528
iio: adc: add driver for Texas Instruments TLA2528 adc

 .../bindings/iio/adc/ti,tla2528.yaml          |  91 ++++++++
 MAINTAINERS                                   |   7 +
 drivers/iio/adc/Kconfig                       |  12 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/ti-tla2528.c                  | 215 ++++++++++++++++++
 5 files changed, 326 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
 create mode 100644 drivers/iio/adc/ti-tla2528.c
Signature · 1 line
2.56.0
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: adc: add Texas Instruments TLA2528

The TI TLA2528 is a simple 8-channel, 12-bit ADC and GPIO chip accessible over i2c. The ADC part has an AVDD supply that doubles as a reference.

---
 .../bindings/iio/adc/ti,tla2528.yaml          | 91 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml new file +91 -0
new file mode 100644
index 000000000000..7a50a5026c1e
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,tla2528.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments TLA2528 8-channel 12-bit I2C ADC
+
+maintainers:
+  - Maxime Chevallier <[email protected]>
+
+description:
+  Each of the 8 input pins can be configured as an analog input, a digital
+  input or a digital output.
+
+properties:
+  compatible:
+    const: ti,tla2528
+
+  reg:
+    maxItems: 1
+
+  avdd-supply:
+    description: Analog supply, also used as the ADC reference voltage.
+
+  dvdd-supply: true
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  "#io-channel-cells":
+    const: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^channel@[0-7]$":
+    type: object
+    $ref: adc.yaml
+    description: Represents an analog input.
+
+    properties:
+      reg:
+        description: AIN pin number
+        minimum: 0
+        maximum: 7
+
+    required:
+      - reg
+
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - dvdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@17 {
+            compatible = "ti,tla2528";
+            reg = <0x17>;
+            avdd-supply = <&reg_adc_supply>;
+            dvdd-supply = <&reg_adc_supply>;
+            #io-channel-cells = <1>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            channel@0 {
+                reg = <0>;
+            };
+
+            channel@3 {
+                reg = <3>;
+            };
+        };
+    };
+...
MAINTAINERS +6 -0
index 93abbb315065..9ccb33ada3d5 100644
@@ -27758,6 +27758,12 @@ F:	include/dt-bindings/soc/ti,sci_pm_domain.h
 F:	include/linux/soc/ti/ti_sci_inta_msi.h
 F:	include/linux/soc/ti/ti_sci_protocol.h
 
+TEXAS INSTRUMENTS' TLA2528 ADC DRIVER
+M:	Maxime Chevallier <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
+
 TEXAS INSTRUMENTS' TMP117 TEMPERATURE SENSOR DRIVER
 M:	Puranjay Mohan <[email protected]>
 L:	[email protected]
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528

On Wed, 4 Nov 2026 13:57:24 +0100
Maxime Chevallier <[email protected]> wrote:

...

MAINTAINERS F: include/dt-bindings/soc/ti,sci_pm_domain.h · line 27763

Quoted 3 lines
MAINTAINERS +3 -0
+TEXAS INSTRUMENTS' TLA2528 ADC DRIVER
+M:	Maxime Chevallier <[email protected]>
+L:	[email protected]

No need for a list entry since get_maintainer can find it through the path.

Quoted 3 lines
MAINTAINERS +3 -0
+S:	Supported
+F:	Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
+
Signature · 2 lines
Kind regards,
Joshua Crofts
#3 lore raw

PATCH v3 2/2 iio: adc: add driver for Texas Instruments TLA2528 adc

In reply to Maxime Chevallier

Add a new driver for the TI TLA2528 ADC chip. It has 8 12-bit channels, that can also be configured as 16-bit averaging channels.

This is a very simple driver, allowing reading raw values for each channel. GPIO mode isn't supported for now, as well as buffered mode and the 16-bit averaging mode.

---
 MAINTAINERS                  |   1 +
 drivers/iio/adc/Kconfig      |  12 ++
 drivers/iio/adc/Makefile     |   1 +
 drivers/iio/adc/ti-tla2528.c | 215 +++++++++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+)
 create mode 100644 drivers/iio/adc/ti-tla2528.c
MAINTAINERS +1 -0
index 9ccb33ada3d5..c41db7fa7e26 100644
@@ -27763,6 +27763,7 @@ M:	Maxime Chevallier <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
+F:	drivers/iio/adc/ti-tla2528.c
 
 TEXAS INSTRUMENTS' TMP117 TEMPERATURE SENSOR DRIVER
 M:	Puranjay Mohan <[email protected]>
drivers/iio/adc/Kconfig +12 -0
index a802d8ee4dd9..8633267d6056 100644
@@ -2016,6 +2016,18 @@ config TI_LMP92064
 	  This driver can also be built as a module. If so, the module will be called
 	  ti-lmp92064.
 
+config TI_TLA2528
+	tristate "Texas Instruments TLA2528 ADC driver"
+	depends on I2C
+	select REGMAP_I2C
+	select IIO_ADC_HELPER
+	help
+	  Say yes here to build support for Texas Instruments TLA2528
+	  12-Bit 8-Channel ADC.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ti-tla2528.
+
 config TI_TLC4541
 	tristate "Texas Instruments TLC4541 ADC driver"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index 9e82c21dbd37..b98cded4d0c7 100644
@@ -171,6 +171,7 @@ obj-$(CONFIG_TI_ADS8344) += ti-ads8344.o
 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_TI_LMP92064) += ti-lmp92064.o
+obj-$(CONFIG_TI_TLA2528) += ti-tla2528.o
 obj-$(CONFIG_TI_TLC4541) += ti-tlc4541.o
 obj-$(CONFIG_TI_TSC2046) += ti-tsc2046.o
 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
drivers/iio/adc/ti-tla2528.c new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
2.56.0
#4 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] iio: adc: ti-tla2528: uninitialized stack read in tla2528_read() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: adc: ti-tla2528: uninitialized stack read in tla2528_read() --

commit 533ebab68a73de725d753757faa2921e38e9ba64
Author: Maxime Chevallier <[email protected]>

iio: adc: add driver for Texas Instruments TLA2528 adc

This commit adds an IIO ADC driver for the Texas Instruments TLA2528 8-channel 12-bit I2C ADC, supporting direct-mode raw channel reads and scale reporting.

Quoted 6 lines
drivers/iio/adc/ti-tla2528.c new file +0 -0
new file mode 100644
index 0000000000000..ec754ec43d7c0
@@ -0,0 +1,215 @@

[ ... ]

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+static int tla2528_read(struct tla2528 *tla2528, u8 channel, int *val)
+{
+	__be16 data;
+	int ret;
+
+	guard(mutex)(&tla2528->lock);
+
+	ret = regmap_update_bits(tla2528->regmap, TLA2528_CHANNEL_SEL_ADR,
+				 TLA2528_CHANNEL_SEL_MANUAL_CHID, channel);
+	if (ret)

drivers/iio/adc/ti-tla2528.c line 80

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+		return ret;
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;
+
+	*val = be16_to_cpu(data) >> 4;
+
+	return 0;
+}

[Severity: Medium]
As reported by Sashiko on v2 [1], in drivers/iio/adc/ti-tla2528.c, can tla2528_read() return uninitialized stack memory from data to user-space when tla2528_read_raw() reads a channel?

i2c_master_recv() calls i2c_transfer_buffer_flags(), which calls i2c_transfer() for 1 message:

drivers/i2c/i2c-core-base.c:i2c_transfer_buffer_flags() {
	...
	ret = i2c_transfer(client->adapter, &msg, 1);

	/*
	 * If everything went ok (i.e. 1 msg transferred), return #bytes
	 * transferred, else error code.
	 */
	return (ret == 1) ? count : ret;
}

If the adapter's master_xfer callback returns 0 messages transferred (or fewer than sizeof(data) bytes are received), i2c_master_recv() returns a non-negative value other than sizeof(data) without populating data.

Since tla2528_read() only checks for ret < 0, should it also return -EIO when ret != sizeof(data)?

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw
In reply to Maxime Chevallier

On Wed, 4 Nov 2026 13:57:25 +0100
Maxime Chevallier <[email protected]> wrote:

...

Quoted 11 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
new file mode 100644
index 000000000000..ec754ec43d7c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Texas Instruments TLA2528 ADC
+ *
+ * Copyright (C) 2020-2021 Rodolfo Giometti <[email protected]>

drivers/iio/adc/ti-tla2528.c line 15

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+ * Copyright (C) 2025 Maxime Chevallier <[email protected]>
+ * Datasheet: https://www.ti.com/lit/gpn/tla2528
+ */
+
+#include <linux/bits.h>
+#include <linux/cleanup.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>

Remove mod_devicetable.h, now i2c.h supplies this. See Uwe Kleine-Konig's work on this.

drivers/iio/adc/ti-tla2528.c line 25

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <linux/iio/adc-helpers.h>
+#include <linux/iio/iio.h>
+

+ #include <asm/byteorder.h> for be16_to_cpu()

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+#define TLA2528_OP_WRITE_REG		0x08
+#define TLA2528_OP_READ_REG		0x10
+
+#define TLA2528_GENERAL_CFG_ADR		0x01
+#define TLA2528_GENERAL_CFG_RST		BIT(0)

drivers/iio/adc/ti-tla2528.c line 40

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+#define TLA2528_CHANNEL_SEL_ADR		0x11
+#define TLA2528_CHANNEL_SEL_MANUAL_CHID	GENMASK(3, 0)
+#define TLA2528_AUTO_SEQ_CH_SEL_ADR	0x12
+
+#define TLA2528_NUM_CHANNELS		8
+
+struct tla2528 {
+	struct i2c_client *client;
+	struct regmap *regmap;
+	int vref_mv;

Slight nit, but _mV so we emphasize this is a SI unit.

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+
+	/* Protects manual channel selection */
+	struct mutex lock;
+};
+

...

Quoted 6 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+static int tla2528_read(struct tla2528 *tla2528, u8 channel, int *val)
+{
+	__be16 data;
+	int ret;
+

drivers/iio/adc/ti-tla2528.c line 75

Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+	guard(mutex)(&tla2528->lock);
+
+	ret = regmap_update_bits(tla2528->regmap, TLA2528_CHANNEL_SEL_ADR,
+				 TLA2528_CHANNEL_SEL_MANUAL_CHID, channel);
+	if (ret)
+		return ret;
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;

As rare as short reads may be, perhaps add a check whether the expected amount of bits have been returned from the device?

Signature · 2 lines
Kind regards,
Joshua Crofts
#6 lore raw
Quoted 2 lines · Joshua Crofts

On Wed, 4 Nov 2026 13:57:25 +0100
Maxime Chevallier <[email protected]> wrote:

...

Quoted 7 lines

drivers/iio/adc/ti-tla2528.c line 24

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <linux/iio/adc-helpers.h>
+#include <linux/iio/iio.h>

+ #include <asm/byteorder.h> for be16_to_cpu()

Yep, but please before linux/iio/* block.

...

Quoted 10 lines
Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+static int tla2528_read(struct tla2528 *tla2528, u8 channel, int *val)
+{
+	__be16 data;
+	int ret;
+
+	guard(mutex)(&tla2528->lock);
+
+	ret = regmap_update_bits(tla2528->regmap, TLA2528_CHANNEL_SEL_ADR,
+				 TLA2528_CHANNEL_SEL_MANUAL_CHID, channel);
+	if (ret)
Quoted 8 lines

drivers/iio/adc/ti-tla2528.c line 75

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+		return ret;
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;

As rare as short reads may be, perhaps add a check whether the expected amount of bits have been returned from the device?

Bits? You probably mistyped bytes?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 37 lines · On Wed, 4 Nov 2026 17:41:30 +0200 Andy Shevchenko…
Quoted 2 lines · Joshua Crofts

On Wed, 4 Nov 2026 13:57:25 +0100
Maxime Chevallier <[email protected]> wrote:

...

Quoted 7 lines

drivers/iio/adc/ti-tla2528.c line 24

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <linux/iio/adc-helpers.h>
+#include <linux/iio/iio.h>  

+ #include <asm/byteorder.h> for be16_to_cpu()

Yep, but please before linux/iio/* block.

...

Quoted 10 lines
Quoted 10 lines
drivers/iio/adc/ti-tla2528.c new file +10 -0
+static int tla2528_read(struct tla2528 *tla2528, u8 channel, int *val)
+{
+	__be16 data;
+	int ret;
+
+	guard(mutex)(&tla2528->lock);
+
+	ret = regmap_update_bits(tla2528->regmap, TLA2528_CHANNEL_SEL_ADR,
+				 TLA2528_CHANNEL_SEL_MANUAL_CHID, channel);
+	if (ret)
Quoted 8 lines

drivers/iio/adc/ti-tla2528.c line 75

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +5 -0
+		return ret;
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;  

As rare as short reads may be, perhaps add a check whether the expected amount of bits have been returned from the device?

Quoted 1 line

Bits? You probably mistyped bytes?

Ugh yes, I was in between meetings and rushed my reply. Thanks for catching this!

Signature · 2 lines
Kind regards,
Joshua Crofts
#8 lore raw
In reply to Joshua Crofts

Hi Joshua,

On 11/4/26 14:56, Joshua Crofts wrote:

[...]

Quoted 11 lines
Quoted 11 lines
drivers/iio/adc/ti-tla2528.c new file +11 -0
+static int tla2528_read(struct tla2528 *tla2528, u8 channel, int *val)
+{
+	__be16 data;
+	int ret;
+
+	guard(mutex)(&tla2528->lock);
+
+	ret = regmap_update_bits(tla2528->regmap, TLA2528_CHANNEL_SEL_ADR,
+				 TLA2528_CHANNEL_SEL_MANUAL_CHID, channel);
+	if (ret)
+		return ret;
Quoted 8 lines

drivers/iio/adc/ti-tla2528.c line 75

Quoted 5 lines
drivers/iio/adc/ti-tla2528.c new file +4 -0
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;

As rare as short reads may be, perhaps add a check whether the expected amount of bits have been returned from the device?

True yes, I'll address that. Got a sashiko review about that too :/

I'll also address the other comments in V4, thanks a lot for reviewing,

Maxime

maintainer
#9 lore raw
Quoted 2 lines

I'll also address the other comments in V4, thanks a lot for reviewing,

FWIW I took another look through and nothing to add, so should be good for v4! :)

Jonathan

Quoted 2 lines

Maxime