Skip to contentSkip to conversation

iio: adc: add LTC2309 support

PATCH In review Liam Beguin 3 participants 7 messages Aug 29, 2023 – Sep 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover iio: adc: add LTC2309 support

The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface.

This implements support for all single-ended and differential channels, in unipolar mode only.

---
Changes in v3:
- fix comments, kerneldoc, and i2c_device_id
- drop DRIVER_NAME
- drop datasheet_name
- drop unused i2c clientdata
- rework .read_raw() locking, adding utility function
- remove reundant parent assignment
- use dev_err_probe
- update devm_regulator_get_optional() error handling
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- reduce critical section scope to i2c accesses only
- fixup .probe() commit
- fix unbalanced regulator
- rename refcomp to vref
- update lltc,2497.yaml instead of duplicating bindings
- commit dt-bindings before driver
- fix checkpatch --strict warnings
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Liam Beguin (2):
dt-bindings: iio: adc: add lltc,ltc2309 bindings
iio: adc: add ltc2309 support

 .../devicetree/bindings/iio/adc/lltc,ltc2497.yaml  |  20 +-
 drivers/iio/adc/Kconfig                            |  10 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/ltc2309.c                          | 249 +++++++++++++++++++++
 4 files changed, 275 insertions(+), 5 deletions(-)

---
base-commit: a5e505a99ca748583dbe558b691be1b26f05d678
change-id: 20230823-ltc2309-1945e1e94931

Best regards,

Signature · 1 line
Liam Beguin <[email protected]>
#1 lore raw

PATCH v3 1/2 dt-bindings: iio: adc: add lltc,ltc2309 bindings

Add devicetree bindings for the Linear Technology LTC2309 ADC driver.

---
 .../devicetree/bindings/iio/adc/lltc,ltc2497.yaml    | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/iio/adc/lltc,ltc2497.yaml +15 -5
index 875f394576c2..5cc6a9684077 100644
@@ -4,21 +4,31 @@
 $id: http://devicetree.org/schemas/iio/adc/lltc,ltc2497.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Linear Technology / Analog Devices LTC2497 ADC
+title: Linear Technology / Analog Devices LTC2497 and LTC2309 ADC
 
 maintainers:
   - Michael Hennerich <[email protected]>
+  - Liam Beguin <[email protected]>
 
 description: |
-  16bit ADC supporting up to 16 single ended or 8 differential inputs.
-  I2C interface.
+  LTC2309:
+    low noise, low power, 8-channel, 12-bit successive approximation ADC with an
+    I2C compatible serial interface.
 
-  https://www.analog.com/media/en/technical-documentation/data-sheets/2497fb.pdf
-  https://www.analog.com/media/en/technical-documentation/data-sheets/2499fe.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/2309fd.pdf
+
+  LTC2497:
+  LTC2499:
+    16bit ADC supporting up to 16 single ended or 8 differential inputs.
+    I2C interface.
+
+    https://www.analog.com/media/en/technical-documentation/data-sheets/2497fb.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/2499fe.pdf
 
 properties:
   compatible:
     enum:
+      - lltc,ltc2309
       - lltc,ltc2497
       - lltc,ltc2499
 
Signature · 1 line
2.39.0
#2 lore raw

PATCH v3 2/2 iio: adc: add ltc2309 support

In reply to Liam Beguin

The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface.

This implements support for all single-ended and differential channels, in unipolar mode only.

---
 drivers/iio/adc/Kconfig   |  10 ++
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/ltc2309.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 260 insertions(+)
drivers/iio/adc/Kconfig +10 -0
index dc14bde31ac1..6ec18e02faf9 100644
@@ -607,6 +607,16 @@ config LPC32XX_ADC
 	  activate only one via device tree selection.  Provides direct access
 	  via sysfs.
 
+config LTC2309
+	tristate "Linear Technology LTC2309 ADC driver"
+	depends on I2C
+	help
+	  Say yes here to build support for Linear Technology LTC2309, a low
+	  noise, low power, 8-channel, 12-bit SAR ADC
+
+	  This driver can also be built as a module. If so, the module will
+	  be called ltc2309.
+
 config LTC2471
 	tristate "Linear Technology LTC2471 and LTC2473 ADC driver"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index eb6e891790fb..fbd86184ec94 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_LTC2309) += ltc2309.o
 obj-$(CONFIG_LTC2471) += ltc2471.o
 obj-$(CONFIG_LTC2485) += ltc2485.o
 obj-$(CONFIG_LTC2496) += ltc2496.o ltc2497-core.o
drivers/iio/adc/ltc2309.c new file +249 -0

249 lines not on this page · raw message

Signature · 1 line
2.39.0
#3 lore raw

Re: [PATCH v3 2/2] iio: adc: add ltc2309 support

kernel test robot noticed the following build warnings:

Hi Liam,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a5e505a99ca748583dbe558b691be1b26f05d678]

url:    https://github.com/intel-lab-lkp/linux/commits/Liam-Beguin/dt-bindings-iio-adc-add-lltc-ltc2309-bindings/20230829-104615
base:   a5e505a99ca748583dbe558b691be1b26f05d678
patch link:    https://lore.kernel.org/r/20230828-ltc2309-v3-2-338b3a8fab8b%40gmail.com
patch subject: [PATCH v3 2/2] iio: adc: add ltc2309 support
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230829/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/iio/adc/ltc2309.c:42: warning: Function parameter or member 'vref_mv' not described in 'ltc2309'

vim +42 drivers/iio/adc/ltc2309.c

    27	
    28	/**
    29	 * struct ltc2309 - internal device data structure
    30	 * @dev:	Device reference
    31	 * @client:	I2C reference
    32	 * @vref:	External reference source
    33	 * @lock:	Lock to serialize data access
    34	 * @vref_mv	Internal voltage reference
    35	 */
    36	struct ltc2309 {
    37		struct device		*dev;
    38		struct i2c_client	*client;
    39		struct regulator	*vref;
    40		struct mutex		lock; /* serialize data access */
    41		int			vref_mv;
  > 42	};
    43	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#4 lore raw

Re: [PATCH v3 2/2] iio: adc: add ltc2309 support

In reply to Liam Beguin
Quoted 6 lines · On Mon, 28 Aug 2023 22:41:35 -0400 Liam Beguin <[email protected]> wrote:

The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface.

This implements support for all single-ended and differential channels, in unipolar mode only.

Hi Liam,

A few really small editorial bits in here. I'll fix them whilst applying. Series applied to the togreg branch of iio.git

Note I will be rebasing the tree on rc1 once available and in the meantime this will only be pushed out as testing.

Thanks,

Jonathan

Quoted 7 lines

+/**
+ * struct ltc2309 - internal device data structure
+ * @dev: Device reference
+ * @client: I2C reference
+ * @vref: External reference source
+ * @lock: Lock to serialize data access
+ * @vref_mv Internal voltage reference

Missing : which is what the bot picked up on.

drivers/iio/adc/ltc2309.c line 162

Quoted 13 lines

+ */

drivers/iio/adc/ltc2309.c new file +11 -0
+struct ltc2309 {
+	struct device		*dev;
+	struct i2c_client	*client;
+	struct regulator	*vref;
+	struct mutex		lock; /* serialize data access */
+	int			vref_mv;
+};
 
+
+void ltc2309_regulator_disable(void *regulator)
+{
+	struct regulator *r = (struct regulator *)regulator;

Never any need to explicitly cast from a void * to any other pointer type. (C spec says it is always fine to do this :)

Given type is obvious from use, can just do

	regulator_disable(regulator);

and lose the local variable.

Quoted 3 lines
drivers/iio/adc/ltc2309.c new file +3 -0
+
+	regulator_disable(r);
+}

..

drivers/iio/adc/ltc2309.c line 233

Quoted 10 lines
drivers/iio/adc/ltc2309.c new file +10 -0
+
+static const struct of_device_id ltc2309_of_match[] = {
+	{ .compatible = "lltc,ltc2309" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ltc2309_of_match);
+
+static const struct i2c_device_id ltc2309_id[] = {
+	{ "ltc2309" },
+	{}

Trivial but space between { and } for consistency.

maintainer
#5 lore raw

Re: [PATCH v3 2/2] iio: adc: add ltc2309 support

Quoted 8 lines · On Sun, 3 Sep 2023 12:43:41 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Mon, 28 Aug 2023 22:41:35 -0400 Liam Beguin <[email protected]> wrote:

The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface.

This implements support for all single-ended and differential channels, in unipolar mode only.

Quoted 8 lines
Quoted 1 line

Hi Liam,

A few really small editorial bits in here. I'll fix them whilst applying. Series applied to the togreg branch of iio.git

Note I will be rebasing the tree on rc1 once available and in the meantime this will only be pushed out as testing.

A couple more static analysis reports came in (unreachable return in one pace and a missing static. I've fixed up in my tree.

Thanks,

Jonathan

Quoted 57 lines

Thanks,

Jonathan

Quoted 7 lines

+/**
+ * struct ltc2309 - internal device data structure
+ * @dev: Device reference
+ * @client: I2C reference
+ * @vref: External reference source
+ * @lock: Lock to serialize data access
+ * @vref_mv Internal voltage reference

Missing : which is what the bot picked up on.

drivers/iio/adc/ltc2309.c line 162

Quoted 13 lines

+ */

drivers/iio/adc/ltc2309.c new file +11 -0
+struct ltc2309 {
+	struct device		*dev;
+	struct i2c_client	*client;
+	struct regulator	*vref;
+	struct mutex		lock; /* serialize data access */
+	int			vref_mv;
+};  
 
+
+void ltc2309_regulator_disable(void *regulator)
+{
+	struct regulator *r = (struct regulator *)regulator;  

Never any need to explicitly cast from a void * to any other pointer type. (C spec says it is always fine to do this :)

Given type is obvious from use, can just do

	regulator_disable(regulator);

and lose the local variable.

Quoted 3 lines
drivers/iio/adc/ltc2309.c new file +3 -0
+
+	regulator_disable(r);
+}  

..

drivers/iio/adc/ltc2309.c line 233

Quoted 10 lines
drivers/iio/adc/ltc2309.c new file +10 -0
+
+static const struct of_device_id ltc2309_of_match[] = {
+	{ .compatible = "lltc,ltc2309" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ltc2309_of_match);
+
+static const struct i2c_device_id ltc2309_id[] = {
+	{ "ltc2309" },
+	{}  

Trivial but space between { and } for consistency.

#6 lore raw

Re: [PATCH v3 2/2] iio: adc: add ltc2309 support

Hi Jonathan,

Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Sun, 3 Sep 2023 12:43:41 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 6 lines · On Mon, 28 Aug 2023 22:41:35 -0400 Liam Beguin <[email protected]> wrote:

The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface.

This implements support for all single-ended and differential channels, in unipolar mode only.

Hi Liam,

Quoted 8 lines
Quoted 5 lines

A few really small editorial bits in here. I'll fix them whilst applying. Series applied to the togreg branch of iio.git

Note I will be rebasing the tree on rc1 once available and in the meantime this will only be pushed out as testing.

A couple more static analysis reports came in (unreachable return in one pace and a missing static. I've fixed up in my tree.

My apologies for the delay, I was away for a few days.

Thanks for making those changes, I'll go over the comments and the reports, and if there's anything left, I'll send an update.

Quoted 3 lines

Thanks,

Jonathan

Thanks again for your time,

Liam

Quoted 59 lines
Quoted 58 lines

Thanks,

Jonathan

Quoted 7 lines

+/**
+ * struct ltc2309 - internal device data structure
+ * @dev: Device reference
+ * @client: I2C reference
+ * @vref: External reference source
+ * @lock: Lock to serialize data access
+ * @vref_mv Internal voltage reference

Missing : which is what the bot picked up on.

drivers/iio/adc/ltc2309.c line 162

Quoted 13 lines

+ */

drivers/iio/adc/ltc2309.c new file +11 -0
+struct ltc2309 {
+	struct device		*dev;
+	struct i2c_client	*client;
+	struct regulator	*vref;
+	struct mutex		lock; /* serialize data access */
+	int			vref_mv;
+};  
 
+
+void ltc2309_regulator_disable(void *regulator)
+{
+	struct regulator *r = (struct regulator *)regulator;  

Never any need to explicitly cast from a void * to any other pointer type. (C spec says it is always fine to do this :)

Given type is obvious from use, can just do

	regulator_disable(regulator);

and lose the local variable.

Quoted 3 lines
drivers/iio/adc/ltc2309.c new file +3 -0
+
+	regulator_disable(r);
+}  

..

drivers/iio/adc/ltc2309.c line 233

Quoted 10 lines
drivers/iio/adc/ltc2309.c new file +10 -0
+
+static const struct of_device_id ltc2309_of_match[] = {
+	{ .compatible = "lltc,ltc2309" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ltc2309_of_match);
+
+static const struct i2c_device_id ltc2309_id[] = {
+	{ "ltc2309" },
+	{}  

Trivial but space between { and } for consistency.