Devicetree
 help / color / mirror / Atom feed
* [PATCH v3 0/2] iio: adc: add driver for Texas Instruments TLA2528 adc
@ 2026-11-04 12:57 Maxime Chevallier
  2026-11-04 12:57 ` [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528 Maxime Chevallier
  2026-11-04 12:57 ` [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
  0 siblings, 2 replies; 9+ messages in thread
From: Maxime Chevallier @ 2026-11-04 12:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Maxime Chevallier, Matti Vaittinen, Rodolfo Giometti,
	Marcelo Schmitt, Antoniu Miclaus, Angelo Dureghello,
	Tobias Sperling, Eason Yang, Marilene Andrade Garcia,
	Cosmin Tanislav, duje, herve.codina, thomas.petazzoni, linux-iio,
	devicetree, linux-kernel

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/20261030164705.297354-1-maxime.chevallier@bootlin.com
  - 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/20251223155534.220504-1-maxime.chevallier@bootlin.com/

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

-- 
2.56.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528
  2026-11-04 12:57 [PATCH v3 0/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
@ 2026-11-04 12:57 ` Maxime Chevallier
  2026-11-04 13:58   ` Joshua Crofts
  2026-11-04 12:57 ` [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
  1 sibling, 1 reply; 9+ messages in thread
From: Maxime Chevallier @ 2026-11-04 12:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Maxime Chevallier, Matti Vaittinen, Rodolfo Giometti,
	Marcelo Schmitt, Antoniu Miclaus, Angelo Dureghello,
	Tobias Sperling, Eason Yang, Marilene Andrade Garcia,
	Cosmin Tanislav, duje, herve.codina, thomas.petazzoni, linux-iio,
	devicetree, linux-kernel, Conor Dooley

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.

Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 .../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

diff --git a/Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml b/Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
new file mode 100644
index 000000000000..7a50a5026c1e
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
@@ -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 <maxime.chevallier@bootlin.com>
+
+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>;
+            };
+        };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..9ccb33ada3d5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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 <maxime.chevallier@bootlin.com>
+L:	linux-iio@vger.kernel.org
+S:	Supported
+F:	Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
+
 TEXAS INSTRUMENTS' TMP117 TEMPERATURE SENSOR DRIVER
 M:	Puranjay Mohan <puranjay@kernel.org>
 L:	linux-iio@vger.kernel.org
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 12:57 [PATCH v3 0/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
  2026-11-04 12:57 ` [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528 Maxime Chevallier
@ 2026-11-04 12:57 ` Maxime Chevallier
  2026-11-04 13:05   ` sashiko-bot
  2026-11-04 13:56   ` Joshua Crofts
  1 sibling, 2 replies; 9+ messages in thread
From: Maxime Chevallier @ 2026-11-04 12:57 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Maxime Chevallier, Matti Vaittinen, Rodolfo Giometti,
	Marcelo Schmitt, Antoniu Miclaus, Angelo Dureghello,
	Tobias Sperling, Eason Yang, Marilene Andrade Garcia,
	Cosmin Tanislav, duje, herve.codina, thomas.petazzoni, linux-iio,
	devicetree, linux-kernel

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.

Co-developed-by: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 9ccb33ada3d5..c41db7fa7e26 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27763,6 +27763,7 @@ M:	Maxime Chevallier <maxime.chevallier@bootlin.com>
 L:	linux-iio@vger.kernel.org
 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 <puranjay@kernel.org>
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a802d8ee4dd9..8633267d6056 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -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
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 9e82c21dbd37..b98cded4d0c7 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -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
diff --git a/drivers/iio/adc/ti-tla2528.c b/drivers/iio/adc/ti-tla2528.c
new file mode 100644
index 000000000000..ec754ec43d7c
--- /dev/null
+++ b/drivers/iio/adc/ti-tla2528.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Texas Instruments TLA2528 ADC
+ *
+ * Copyright (C) 2020-2021 Rodolfo Giometti <giometti@enneenne.com>
+ * Copyright (C) 2025 Maxime Chevallier <maxime.chevallier@bootlin.com>
+ * 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>
+#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>
+
+#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)
+#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;
+
+	/* Protects manual channel selection */
+	struct mutex lock;
+};
+
+static bool tla2528_volatile_reg(struct device *dev, unsigned int reg)
+{
+	return reg == TLA2528_GENERAL_CFG_ADR;
+}
+
+static const struct regmap_config tla2528_regmap_config = {
+	.reg_bits = 16,
+	.val_bits = 8,
+	.read_flag_mask = TLA2528_OP_READ_REG,
+	.write_flag_mask = TLA2528_OP_WRITE_REG,
+	.max_register = TLA2528_AUTO_SEQ_CH_SEL_ADR,
+	.volatile_reg = tla2528_volatile_reg,
+	.cache_type = REGCACHE_MAPLE,
+};
+
+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;
+
+	ret = i2c_master_recv(tla2528->client, (char *)&data, sizeof(data));
+	if (ret < 0)
+		return ret;
+
+	*val = be16_to_cpu(data) >> 4;
+
+	return 0;
+}
+
+static int tla2528_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct tla2528 *tla2528 = iio_priv(indio_dev);
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = tla2528_read(tla2528, chan->channel, val);
+		if (ret < 0)
+			return ret;
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = tla2528->vref_mv;
+		*val2 = 12;
+
+		return IIO_VAL_FRACTIONAL_LOG2;
+
+	default:
+		return -EINVAL;
+	}
+}
+
+#define TLA2528_CHAN(chan) {					\
+	.type = IIO_VOLTAGE,					\
+	.channel = (chan),					\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
+	.indexed = 1,						\
+}
+
+static const struct iio_chan_spec tla2528_chan_template = TLA2528_CHAN(0);
+
+static const struct iio_info tla2528_info = {
+	.read_raw = tla2528_read_raw,
+};
+
+static int tla2528_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct iio_chan_spec *channels;
+	struct iio_dev *indio_dev;
+	struct tla2528 *tla2528;
+	int ret;
+
+	/*
+	 * We're reading the data with raw i2c reads, without passing an
+	 * address like we would for smbus-style accesses.
+	 */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return -EOPNOTSUPP;
+
+	if (i2c_check_quirks(client->adapter, I2C_AQ_NO_CLK_STRETCH))
+		return dev_err_probe(dev, -EOPNOTSUPP,
+				     "adapter does not support clock stretching\n");
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*tla2528));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	tla2528 = iio_priv(indio_dev);
+	tla2528->client = client;
+
+	tla2528->regmap = devm_regmap_init_i2c(client, &tla2528_regmap_config);
+	if (IS_ERR(tla2528->regmap))
+		return PTR_ERR(tla2528->regmap);
+
+	ret = devm_mutex_init(dev, &tla2528->lock);
+	if (ret)
+		return ret;
+
+	ret = devm_regulator_get_enable(dev, "dvdd");
+	if (ret)
+		return ret;
+
+	ret = devm_regulator_get_enable_read_voltage(dev, "avdd");
+	if (ret < 0)
+		return ret;
+
+	tla2528->vref_mv = ret / (MICRO / MILLI);
+
+	ret = devm_iio_adc_device_alloc_chaninfo_se(dev, &tla2528_chan_template,
+						    TLA2528_NUM_CHANNELS - 1,
+						    &channels);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to get ADC channels\n");
+
+	indio_dev->channels = channels;
+	indio_dev->num_channels = ret;
+
+	indio_dev->name = "tla2528";
+	indio_dev->info = &tla2528_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = regmap_write(tla2528->regmap, TLA2528_GENERAL_CFG_ADR,
+			   TLA2528_GENERAL_CFG_RST);
+	if (ret)
+		return ret;
+
+	fsleep(5 * USEC_PER_MSEC);
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct i2c_device_id tla2528_id[] = {
+	{ .name = "tla2528" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, tla2528_id);
+
+static const struct of_device_id tla2528_of_match[] = {
+	{ .compatible = "ti,tla2528" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, tla2528_of_match);
+
+static struct i2c_driver tla2528_driver = {
+	.driver = {
+		.name = "tla2528",
+		.of_match_table = tla2528_of_match,
+	},
+	.probe = tla2528_probe,
+	.id_table = tla2528_id,
+};
+module_i2c_driver(tla2528_driver);
+
+MODULE_AUTHOR("Maxime Chevallier <maxime.chevallier@bootlin.com>");
+MODULE_AUTHOR("Rodolfo Giometti <giometti@enneenne.com>");
+MODULE_DESCRIPTION("Texas Instruments TLA2528 ADC driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_DRIVER");
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 12:57 ` [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
@ 2026-11-04 13:05   ` sashiko-bot
  2026-11-04 13:56   ` Joshua Crofts
  1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-04 13:05 UTC (permalink / raw)
  To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt

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 <maxime.chevallier@bootlin.com>

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.

> diff --git a/drivers/iio/adc/ti-tla2528.c b/drivers/iio/adc/ti-tla2528.c
> new file mode 100644
> index 0000000000000..ec754ec43d7c0
> --- /dev/null
> +++ b/drivers/iio/adc/ti-tla2528.c
> @@ -0,0 +1,215 @@

[ ... ]

> +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;
> +
> +	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/20261030164705.297354-3-maxime.chevallier@bootlin.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104125726.1754980-1-maxime.chevallier@bootlin.com?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 12:57 ` [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
  2026-11-04 13:05   ` sashiko-bot
@ 2026-11-04 13:56   ` Joshua Crofts
  2026-11-04 15:41     ` Andy Shevchenko
  2026-11-04 18:06     ` Maxime Chevallier
  1 sibling, 2 replies; 9+ messages in thread
From: Joshua Crofts @ 2026-11-04 13:56 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen,
	Rodolfo Giometti, Marcelo Schmitt, Antoniu Miclaus,
	Angelo Dureghello, Tobias Sperling, Eason Yang,
	Marilene Andrade Garcia, Cosmin Tanislav, duje, herve.codina,
	thomas.petazzoni, linux-iio, devicetree, linux-kernel

On Wed,  4 Nov 2026 13:57:25 +0100
Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:

...

> diff --git a/drivers/iio/adc/ti-tla2528.c b/drivers/iio/adc/ti-tla2528.c
> new file mode 100644
> index 000000000000..ec754ec43d7c
> --- /dev/null
> +++ b/drivers/iio/adc/ti-tla2528.c
> @@ -0,0 +1,215 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for Texas Instruments TLA2528 ADC
> + *
> + * Copyright (C) 2020-2021 Rodolfo Giometti <giometti@enneenne.com>
> + * Copyright (C) 2025 Maxime Chevallier <maxime.chevallier@bootlin.com>
> + * 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.

> +#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()

> +#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)
> +#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.

> +
> +	/* Protects manual channel selection */
> +	struct mutex lock;
> +};
> +

...

> +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;
> +
> +	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?

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528
  2026-11-04 12:57 ` [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528 Maxime Chevallier
@ 2026-11-04 13:58   ` Joshua Crofts
  0 siblings, 0 replies; 9+ messages in thread
From: Joshua Crofts @ 2026-11-04 13:58 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen,
	Rodolfo Giometti, Marcelo Schmitt, Antoniu Miclaus,
	Angelo Dureghello, Tobias Sperling, Eason Yang,
	Marilene Andrade Garcia, Cosmin Tanislav, duje, herve.codina,
	thomas.petazzoni, linux-iio, devicetree, linux-kernel,
	Conor Dooley

On Wed,  4 Nov 2026 13:57:24 +0100
Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:

...

> +TEXAS INSTRUMENTS' TLA2528 ADC DRIVER
> +M:	Maxime Chevallier <maxime.chevallier@bootlin.com>
> +L:	linux-iio@vger.kernel.org

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

> +S:	Supported
> +F:	Documentation/devicetree/bindings/iio/adc/ti,tla2528.yaml
> +

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 13:56   ` Joshua Crofts
@ 2026-11-04 15:41     ` Andy Shevchenko
  2026-11-04 15:45       ` Joshua Crofts
  2026-11-04 18:06     ` Maxime Chevallier
  1 sibling, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2026-11-04 15:41 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Maxime Chevallier, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Matti Vaittinen, Rodolfo Giometti, Marcelo Schmitt,
	Antoniu Miclaus, Angelo Dureghello, Tobias Sperling, Eason Yang,
	Marilene Andrade Garcia, Cosmin Tanislav, duje, herve.codina,
	thomas.petazzoni, linux-iio, devicetree, linux-kernel

On Wed, Nov 04, 2026 at 02:56:41PM +0100, Joshua Crofts wrote:
> On Wed,  4 Nov 2026 13:57:25 +0100
> Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:

...

> > +#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.

...

> > +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;
> > +
> > +	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?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 15:41     ` Andy Shevchenko
@ 2026-11-04 15:45       ` Joshua Crofts
  0 siblings, 0 replies; 9+ messages in thread
From: Joshua Crofts @ 2026-11-04 15:45 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Maxime Chevallier, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Matti Vaittinen, Rodolfo Giometti, Marcelo Schmitt,
	Antoniu Miclaus, Angelo Dureghello, Tobias Sperling, Eason Yang,
	Marilene Andrade Garcia, Cosmin Tanislav, duje, herve.codina,
	thomas.petazzoni, linux-iio, devicetree, linux-kernel

On Wed, 4 Nov 2026 17:41:30 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Wed, Nov 04, 2026 at 02:56:41PM +0100, Joshua Crofts wrote:
> > On Wed,  4 Nov 2026 13:57:25 +0100
> > Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:  
> 
> ...
> 
> > > +#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.
> 
> ...
> 
> > > +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;
> > > +
> > > +	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?

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

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc
  2026-11-04 13:56   ` Joshua Crofts
  2026-11-04 15:41     ` Andy Shevchenko
@ 2026-11-04 18:06     ` Maxime Chevallier
  1 sibling, 0 replies; 9+ messages in thread
From: Maxime Chevallier @ 2026-11-04 18:06 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen,
	Rodolfo Giometti, Marcelo Schmitt, Antoniu Miclaus,
	Angelo Dureghello, Tobias Sperling, Eason Yang,
	Marilene Andrade Garcia, Cosmin Tanislav, duje, herve.codina,
	thomas.petazzoni, linux-iio, devicetree, linux-kernel

Hi Joshua,

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

[...]

>> +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;
>> +
>> +	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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-04 18:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 12:57 [PATCH v3 0/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
2026-11-04 12:57 ` [PATCH v3 1/2] dt-bindings: iio: adc: add Texas Instruments TLA2528 Maxime Chevallier
2026-11-04 13:58   ` Joshua Crofts
2026-11-04 12:57 ` [PATCH v3 2/2] iio: adc: add driver for Texas Instruments TLA2528 adc Maxime Chevallier
2026-11-04 13:05   ` sashiko-bot
2026-11-04 13:56   ` Joshua Crofts
2026-11-04 15:41     ` Andy Shevchenko
2026-11-04 15:45       ` Joshua Crofts
2026-11-04 18:06     ` Maxime Chevallier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox