* [PATCH v1 0/2] Add MAX14001/MAX14002 support
@ 2025-08-21 13:36 Marilene Andrade Garcia
2025-08-21 13:38 ` [PATCH v1 1/2] dt-bindings: iio: adc: Add MAX14001 Marilene Andrade Garcia
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Marilene Andrade Garcia @ 2025-08-21 13:36 UTC (permalink / raw)
To: linux-iio, linux-kernel, devicetree
Cc: Marilene Andrade Garcia, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marcelo Schmitt, Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos,
Dragos Bogdan
Hello maintainers,
This patch series adds basic support for the Analog Devices
MAX14001/MAX14002, configurable, isolated 10-bit ADCs for multi-range
binary inputs. Besides the implemented ADC readings, these devices have
more features, like a binary comparator; a filtered reading that can
provide the average of the last 2, 4, or 8 ADC readings; and an inrush
comparator that triggers the inrush current. There is also a fault feature
that can diagnose seven possible fault conditions.
To keep the commits simple and organized, these initial driver support
patches aim to upstream only the features related to reading two registers,
one that contains the latest ADC reading, and another one that contains
the latest filtered ADC readings. Though, _raw and _mean_raw are providing
the same results in this initial version since the data averaging config
interface is not implemented yet. For this, IIO_CHAN_INFO_AVERAGE_RAW was
used to return the filtered average of ADC readings. An additional patch
documenting the in_voltageY_mean_raw interface can be added on v2 if that
would be desirable. The idea is to use in_voltageY_mean_raw to return the
filtered average value, and also to set how many ADC readings (0, 2, 4,
or 8) are included in the mean calculation. I would also like to know if
you have any feedback on using IIO_CHAN_INFO_AVERAGE_RAW in this way.
The changes were tested using the Raspberry Pi modified kernel version
rpi-6.6 on Raspberry Pi 5 hardware. For testing, the MAX14001PMB evaluation
board was used, which contains two MAX14001 devices. According to the
board’s circuit configuration, one device measures current and the other
measures voltage. Due to the evaluation board’s circuitry, the devices
also receive an offset that allows them to measure negative values. None
of these evaluation board-specific characteristics were included in the
driver code (neither the offset nor the current channel capability).
However, they were considered in the calculation of the values read by the
devices. Should the code that applies these board configuration parameters
be added as an additional driver file inside the IIO subsystem, or should
it remain only in a user application file?
The code was developed during the GSoC program as part of the Analog
Devices Mentorship. Many thanks to my mentors Marcelo Schmitt, Ceclan
Dumitru, Jonathan Santos and Dragos Bogdan for their guidance, reviews,
and explanations about the IIO subsystem code.
I intend to keep sending patches to cover all the features of the device.
Thank you for your time,
Best regards,
Marilene Andrade Garcia.
Marilene Andrade Garcia (2):
dt-bindings: iio: adc: Add MAX14001
iio: adc: Add basic support for MAX14001
.../bindings/iio/adc/adi,max14001.yaml | 78 +++++++
MAINTAINERS | 8 +
drivers/iio/adc/Kconfig | 10 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/max14001.c | 213 ++++++++++++++++++
5 files changed, 310 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
create mode 100644 drivers/iio/adc/max14001.c
base-commit: 7c680c4dbbb5365ad78ce661886ce1668ff40f9c
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v1 1/2] dt-bindings: iio: adc: Add MAX14001
2025-08-21 13:36 [PATCH v1 0/2] Add MAX14001/MAX14002 support Marilene Andrade Garcia
@ 2025-08-21 13:38 ` Marilene Andrade Garcia
2025-08-21 13:39 ` [PATCH v1 2/2] iio: adc: Add basic support for MAX14001 Marilene Andrade Garcia
2025-08-21 18:06 ` [PATCH v1 0/2] Add MAX14001/MAX14002 support Conor Dooley
2 siblings, 0 replies; 8+ messages in thread
From: Marilene Andrade Garcia @ 2025-08-21 13:38 UTC (permalink / raw)
To: linux-iio, linux-kernel, devicetree
Cc: Marilene Andrade Garcia, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marcelo Schmitt, Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos,
Dragos Bogdan
Add device-tree documentation for MAX14001/MAX14002 ADCs.
The MAX14001/MAX14002 are isolated, single-channel analog-to-digital
converters with programmable voltage comparators and inrush current
control optimized for configurable binary input applications.
Signed-off-by: Marilene Andrade Garcia <marilene.agarcia@gmail.com>
---
.../bindings/iio/adc/adi,max14001.yaml | 78 +++++++++++++++++++
MAINTAINERS | 7 ++
2 files changed, 85 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml b/Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
new file mode 100644
index 000000000000..3b2a2e788a17
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2025 Marilene Andrade Garcia
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,max14001.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX14001-MAX14002 10-bit ADCs
+
+maintainers:
+ - Marilene Andrade Garcia <marilene.agarcia@gmail.com>
+
+description:
+ Bindings for the Analog Devices MAX14001-MAX14002 Configurable,
+ Isolated 10-bit ADCs for Multi-Range Binary Inputs.
+
+ Datasheet can be found here
+ https://www.analog.com/media/en/technical-documentation/data-sheets/MAX14001-MAX14002.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+ compatible:
+ enum:
+ - adi,max14001
+ - adi,max14002
+
+ reg:
+ maxItems: 1
+
+ vdd-supply:
+ description:
+ Isolated DC-DC power supply input voltage.
+
+ vddl-supply:
+ description:
+ Logic power supply.
+
+ vrefin-supply:
+ description:
+ ADC voltage reference supply.
+
+ interrupts:
+ items:
+ - description: |
+ Interrupt for signaling when conversion results exceed the configured
+ upper threshold for ADC readings or fall below the lower threshold for
+ them. Interrupt source must be attached to COUT pin.
+ - description: |
+ Alert output that asserts low during a number of different error
+ conditions. The interrupt source must be attached to FAULT pin.
+
+ spi-max-frequency:
+ maximum: 5000000
+
+required:
+ - compatible
+ - reg
+ - vdd-supply
+ - vddl-supply
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ spi {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ max14001: adc@0 {
+ compatible = "adi,max14001";
+ reg = <0>;
+ spi-max-frequency = <5000000>;
+ vdd-supply = <&vdd>;
+ vddl-supply = <&vddl>;
+ };
+ };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index af1c8d2bfb3d..0aeab5dbd39d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14984,6 +14984,13 @@ W: https://ez.analog.com/linux-software-drivers
F: Documentation/devicetree/bindings/iio/adc/maxim,max11205.yaml
F: drivers/iio/adc/max11205.c
+MAXIM MAX14001/MAX14002 DRIVER
+M: Marilene Andrade Garcia <marilene.agarcia@gmail.com>
+L: linux-iio@vger.kernel.org
+S: Maintained
+W: https://ez.analog.com/linux-software-drivers
+F: Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
+
MAXIM MAX17040 FAMILY FUEL GAUGE DRIVERS
R: Iskren Chernev <iskren.chernev@gmail.com>
R: Krzysztof Kozlowski <krzk@kernel.org>
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 2/2] iio: adc: Add basic support for MAX14001
2025-08-21 13:36 [PATCH v1 0/2] Add MAX14001/MAX14002 support Marilene Andrade Garcia
2025-08-21 13:38 ` [PATCH v1 1/2] dt-bindings: iio: adc: Add MAX14001 Marilene Andrade Garcia
@ 2025-08-21 13:39 ` Marilene Andrade Garcia
2025-08-22 6:52 ` kernel test robot
2025-08-25 11:16 ` Jonathan Cameron
2025-08-21 18:06 ` [PATCH v1 0/2] Add MAX14001/MAX14002 support Conor Dooley
2 siblings, 2 replies; 8+ messages in thread
From: Marilene Andrade Garcia @ 2025-08-21 13:39 UTC (permalink / raw)
To: linux-iio, linux-kernel, devicetree
Cc: Marilene Andrade Garcia, Jonathan Cameron, David Lechner,
Nuno Sá, Andy Shevchenko, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marcelo Schmitt, Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos,
Dragos Bogdan
The MAX14001/MAX14002 are configurable, isolated 10-bit ADCs for
multi-range binary inputs. Besides the ADC readings, the MAX14001/MAX14002
offers more features, like a binary comparator, a filtered reading that
can provide the average of the last 2, 4, or 8 ADC readings, and an inrush
comparator that triggers the inrush current. There is also a fault feature
that can diagnose seven possible fault conditions. And an option to select
an external or internal ADC voltage reference.
Add basic support for MAX14001/MAX14002 with the following features:
- Raw ADC reading.
- Filtered ADC average reading with the default configuration.
Signed-off-by: Marilene Andrade Garcia <marilene.agarcia@gmail.com>
---
MAINTAINERS | 1 +
drivers/iio/adc/Kconfig | 10 ++
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/max14001.c | 213 +++++++++++++++++++++++++++++++++++++
4 files changed, 225 insertions(+)
create mode 100644 drivers/iio/adc/max14001.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 0aeab5dbd39d..ea5d6d9ba5eb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14990,6 +14990,7 @@ L: linux-iio@vger.kernel.org
S: Maintained
W: https://ez.analog.com/linux-software-drivers
F: Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml
+F: drivers/iio/adc/max14001.c
MAXIM MAX17040 FAMILY FUEL GAUGE DRIVERS
R: Iskren Chernev <iskren.chernev@gmail.com>
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 6de2abad0197..12688c9780e1 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -976,6 +976,16 @@ config MAX1363
To compile this driver as a module, choose M here: the module will be
called max1363.
+config MAX14001
+ tristate "Analog Devices MAX14001/MAX14002 ADCs driver"
+ depends on SPI
+ help
+ Say yes here to build support for Analog Devices MAX14001/MAX14002
+ Configurable, Isolated 10-bit ADCs for Multi-Range Binary Inputs.
+
+ To compile this driver as a module, choose M here: the module will be
+ called max14001.
+
config MAX34408
tristate "Maxim max34408/max344089 ADC driver"
depends on I2C
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 1c6ca5fd4b6d..05b930a1bce5 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -86,6 +86,7 @@ obj-$(CONFIG_MAX11205) += max11205.o
obj-$(CONFIG_MAX11410) += max11410.o
obj-$(CONFIG_MAX1241) += max1241.o
obj-$(CONFIG_MAX1363) += max1363.o
+obj-$(CONFIG_MAX14001) += max14001.o
obj-$(CONFIG_MAX34408) += max34408.o
obj-$(CONFIG_MAX77541_ADC) += max77541-adc.o
obj-$(CONFIG_MAX9611) += max9611.o
diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c
new file mode 100644
index 000000000000..fb79f3b81e0c
--- /dev/null
+++ b/drivers/iio/adc/max14001.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MAX14001/MAX14002 SPI ADC driver
+ *
+ * Copyright (c) 2025 Marilene Andrade Garcia <marilene.agarcia@gmail.com>
+ *
+ * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX14001-MAX14002.pdf
+ */
+
+#include <asm/unaligned.h>
+#include <linux/bitfield.h>
+#include <linux/bitrev.h>
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/iio/iio.h>
+#include <linux/regulator/consumer.h>
+
+/* MAX14001 registers definition */
+#define MAX14001_REG_ADC 0x00
+#define MAX14001_REG_FADC 0x01
+#define MAX14001_REG_FLAGS 0x02
+#define MAX14001_REG_FLTEN 0x03
+#define MAX14001_REG_THL 0x04
+#define MAX14001_REG_THU 0x05
+#define MAX14001_REG_INRR 0x06
+#define MAX14001_REG_INRT 0x07
+#define MAX14001_REG_INRP 0x08
+#define MAX14001_REG_CFG 0x09
+#define MAX14001_REG_ENBL 0x0A
+#define MAX14001_REG_ACT 0x0B
+#define MAX14001_REG_WEN 0x0C
+
+/* MAX14001 CONTROL values*/
+#define MAX14001_REG_WRITE 0x1
+#define MAX14001_REG_READ 0x0
+
+/* MAX14001 MASKS */
+#define MAX14001_MASK_ADDR GENMASK(15, 11)
+#define MAX14001_MASK_WR BIT(10)
+#define MAX14001_MASK_DATA GENMASK(9, 0)
+
+enum max14001_chip_model {
+ max14001,
+ max14002,
+};
+
+struct max14001_chip_info {
+ const char *name;
+};
+
+struct max14001_state {
+ const struct max14001_chip_info *chip_info;
+ struct spi_device *spi;
+ int vref_mv;
+
+ __be16 rx_buffer __aligned(IIO_DMA_MINALIGN);
+ __be16 tx_buffer;
+};
+
+static struct max14001_chip_info max14001_chip_info_tbl[] = {
+ [max14001] = {
+ .name = "max14001",
+ },
+ [max14002] = {
+ .name = "max14002",
+ },
+};
+
+static int max14001_spi_read(struct max14001_state *st, u16 reg, int *val)
+{
+ struct spi_transfer xfer[] = {
+ {
+ .tx_buf = &st->tx_buffer,
+ .len = sizeof(st->tx_buffer),
+ .cs_change = 1,
+ },
+ {
+ .rx_buf = &st->rx_buffer,
+ .len = sizeof(st->rx_buffer),
+ },
+ };
+ int ret;
+
+ st->tx_buffer = FIELD_PREP(MAX14001_MASK_ADDR, reg) |
+ FIELD_PREP(MAX14001_MASK_WR, MAX14001_REG_READ);
+ st->tx_buffer = bitrev16(st->tx_buffer);
+
+ ret = spi_sync_transfer(st->spi, xfer, ARRAY_SIZE(xfer));
+ if (ret < 0)
+ return ret;
+
+ st->rx_buffer = bitrev16(be16_to_cpu(st->rx_buffer));
+ *val = FIELD_GET(MAX14001_MASK_DATA, st->rx_buffer);
+
+ return 0;
+}
+
+static int max14001_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ struct max14001_state *st = iio_priv(indio_dev);
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ ret = max14001_spi_read(st, MAX14001_REG_ADC, val);
+ if (ret < 0)
+ return ret;
+
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_AVERAGE_RAW:
+ ret = max14001_spi_read(st, MAX14001_REG_FADC, val);
+ if (ret < 0)
+ return ret;
+
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ *val = st->vref_mv;
+ *val2 = 10;
+
+ return IIO_VAL_FRACTIONAL_LOG2;
+ }
+
+ return -EINVAL;
+}
+
+static const struct iio_info max14001_info = {
+ .read_raw = max14001_read_raw,
+};
+
+static const struct iio_chan_spec max14001_channel[] = {
+ {
+ .type = IIO_VOLTAGE,
+ .indexed = 1,
+ .channel = 0,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ }
+};
+
+static int max14001_probe(struct spi_device *spi)
+{
+ struct device *dev = &spi->dev;
+ struct max14001_state *st;
+ struct iio_dev *indio_dev;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ st = iio_priv(indio_dev);
+ st->spi = spi;
+ st->chip_info = spi_get_device_match_data(spi);
+ if (!st->chip_info)
+ return dev_err_probe(dev, -ENODEV, "Failed to get match data\n");
+
+ indio_dev->name = st->chip_info->name;
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->info = &max14001_info;
+ indio_dev->channels = max14001_channel;
+ indio_dev->num_channels = ARRAY_SIZE(max14001_channel);
+
+ ret = devm_regulator_get_enable(dev, "vdd");
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to enable specified Vdd supply\n");
+
+ ret = devm_regulator_get_enable(dev, "vddl");
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to enable specified Vddl supply\n");
+
+ ret = devm_regulator_get_enable_read_voltage(dev, "vrefin");
+ if (ret < 0)
+ st->vref_mv = 1250000 / 1000;
+ else
+ st->vref_mv = ret / 1000;
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct spi_device_id max14001_id_table[] = {
+ { "max14001", (kernel_ulong_t)&max14001_chip_info_tbl[max14001] },
+ { "max14002", (kernel_ulong_t)&max14001_chip_info_tbl[max14002] },
+ {}
+};
+MODULE_DEVICE_TABLE(spi, max14001_id_table);
+
+static const struct of_device_id max14001_of_match[] = {
+ { .compatible = "adi,max14001",
+ .data = &max14001_chip_info_tbl[max14001], },
+ { .compatible = "adi,max14002",
+ .data = &max14001_chip_info_tbl[max14002], },
+ { }
+};
+MODULE_DEVICE_TABLE(of, max14001_of_match);
+
+static struct spi_driver max14001_driver = {
+ .driver = {
+ .name = "max14001",
+ .of_match_table = max14001_of_match,
+ },
+ .probe = max14001_probe,
+ .id_table = max14001_id_table,
+};
+module_spi_driver(max14001_driver);
+
+MODULE_AUTHOR("Marilene Andrade Garcia <marilene.agarcia@gmail.com>");
+MODULE_DESCRIPTION("Analog Devices MAX14001/MAX14002 ADCs driver");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v1 0/2] Add MAX14001/MAX14002 support
2025-08-21 13:36 [PATCH v1 0/2] Add MAX14001/MAX14002 support Marilene Andrade Garcia
2025-08-21 13:38 ` [PATCH v1 1/2] dt-bindings: iio: adc: Add MAX14001 Marilene Andrade Garcia
2025-08-21 13:39 ` [PATCH v1 2/2] iio: adc: Add basic support for MAX14001 Marilene Andrade Garcia
@ 2025-08-21 18:06 ` Conor Dooley
2025-08-21 19:24 ` Marcelo Schmitt
2 siblings, 1 reply; 8+ messages in thread
From: Conor Dooley @ 2025-08-21 18:06 UTC (permalink / raw)
To: Marilene Andrade Garcia
Cc: linux-iio, linux-kernel, devicetree, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marcelo Schmitt, Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos,
Dragos Bogdan, Kim Seer Paller
[-- Attachment #1: Type: text/plain, Size: 2950 bytes --]
On Thu, Aug 21, 2025 at 10:36:06AM -0300, Marilene Andrade Garcia wrote:
> Hello maintainers,
>
> This patch series adds basic support for the Analog Devices
> MAX14001/MAX14002, configurable, isolated 10-bit ADCs for multi-range
> binary inputs. Besides the implemented ADC readings, these devices have
> more features, like a binary comparator; a filtered reading that can
> provide the average of the last 2, 4, or 8 ADC readings; and an inrush
> comparator that triggers the inrush current. There is also a fault feature
> that can diagnose seven possible fault conditions.
>
> To keep the commits simple and organized, these initial driver support
> patches aim to upstream only the features related to reading two registers,
> one that contains the latest ADC reading, and another one that contains
> the latest filtered ADC readings. Though, _raw and _mean_raw are providing
> the same results in this initial version since the data averaging config
> interface is not implemented yet. For this, IIO_CHAN_INFO_AVERAGE_RAW was
> used to return the filtered average of ADC readings. An additional patch
> documenting the in_voltageY_mean_raw interface can be added on v2 if that
> would be desirable. The idea is to use in_voltageY_mean_raw to return the
> filtered average value, and also to set how many ADC readings (0, 2, 4,
> or 8) are included in the mean calculation. I would also like to know if
> you have any feedback on using IIO_CHAN_INFO_AVERAGE_RAW in this way.
>
> The changes were tested using the Raspberry Pi modified kernel version
> rpi-6.6 on Raspberry Pi 5 hardware. For testing, the MAX14001PMB evaluation
> board was used, which contains two MAX14001 devices. According to the
> board’s circuit configuration, one device measures current and the other
> measures voltage. Due to the evaluation board’s circuitry, the devices
> also receive an offset that allows them to measure negative values. None
> of these evaluation board-specific characteristics were included in the
> driver code (neither the offset nor the current channel capability).
> However, they were considered in the calculation of the values read by the
> devices. Should the code that applies these board configuration parameters
> be added as an additional driver file inside the IIO subsystem, or should
> it remain only in a user application file?
>
> The code was developed during the GSoC program as part of the Analog
> Devices Mentorship. Many thanks to my mentors Marcelo Schmitt, Ceclan
> Dumitru, Jonathan Santos and Dragos Bogdan for their guidance, reviews,
> and explanations about the IIO subsystem code.
>
> I intend to keep sending patches to cover all the features of the device.
Something gone wrong here? There's already a v9 from another ADI
employee on the list:
https://lore.kernel.org/all/20230710042723.46084-2-kimseer.paller@analog.com/
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 0/2] Add MAX14001/MAX14002 support
2025-08-21 18:06 ` [PATCH v1 0/2] Add MAX14001/MAX14002 support Conor Dooley
@ 2025-08-21 19:24 ` Marcelo Schmitt
2025-08-22 16:25 ` Conor Dooley
0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Schmitt @ 2025-08-21 19:24 UTC (permalink / raw)
To: Conor Dooley
Cc: Marilene Andrade Garcia, linux-iio, linux-kernel, devicetree,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Marcelo Schmitt,
Ceclan Dumitru, Jonathan Santos, Dragos Bogdan, Kim Seer Paller
On 08/21, Conor Dooley wrote:
> On Thu, Aug 21, 2025 at 10:36:06AM -0300, Marilene Andrade Garcia wrote:
> > Hello maintainers,
> >
> > This patch series adds basic support for the Analog Devices
> > MAX14001/MAX14002, configurable, isolated 10-bit ADCs for multi-range
...
>
> Something gone wrong here? There's already a v9 from another ADI
> employee on the list:
> https://lore.kernel.org/all/20230710042723.46084-2-kimseer.paller@analog.com/
Yes, my procedure for finding parts for GSoC projects failed to find that set.
From quick read of v9 thread, the reason for that not being applied was lack
of detailed comments about device data transfer handling?
Anyway, I guess the only thing left to do now is see what can be taken from
Marilene's set and applied on top of Kim's one.
I'm sorry for this unfortunate situation.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 2/2] iio: adc: Add basic support for MAX14001
2025-08-21 13:39 ` [PATCH v1 2/2] iio: adc: Add basic support for MAX14001 Marilene Andrade Garcia
@ 2025-08-22 6:52 ` kernel test robot
2025-08-25 11:16 ` Jonathan Cameron
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-08-22 6:52 UTC (permalink / raw)
To: Marilene Andrade Garcia, linux-iio, linux-kernel, devicetree
Cc: llvm, oe-kbuild-all, Marilene Andrade Garcia, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Lars-Peter Clausen,
Michael Hennerich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos, Dragos Bogdan
Hi Marilene,
kernel test robot noticed the following build errors:
[auto build test ERROR on 7c680c4dbbb5365ad78ce661886ce1668ff40f9c]
url: https://github.com/intel-lab-lkp/linux/commits/Marilene-Andrade-Garcia/dt-bindings-iio-adc-Add-MAX14001/20250821-225647
base: 7c680c4dbbb5365ad78ce661886ce1668ff40f9c
patch link: https://lore.kernel.org/r/2919a00f86c1188b83446853bcb9740138d70f44.1755778212.git.marilene.agarcia%40gmail.com
patch subject: [PATCH v1 2/2] iio: adc: Add basic support for MAX14001
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250822/202508221427.TaHJJwvG-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250822/202508221427.TaHJJwvG-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508221427.TaHJJwvG-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/iio/adc/max14001.c:10:10: fatal error: 'asm/unaligned.h' file not found
10 | #include <asm/unaligned.h>
| ^~~~~~~~~~~~~~~~~
1 error generated.
vim +10 drivers/iio/adc/max14001.c
> 10 #include <asm/unaligned.h>
11 #include <linux/bitfield.h>
12 #include <linux/bitrev.h>
13 #include <linux/module.h>
14 #include <linux/spi/spi.h>
15 #include <linux/iio/iio.h>
16 #include <linux/regulator/consumer.h>
17
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 0/2] Add MAX14001/MAX14002 support
2025-08-21 19:24 ` Marcelo Schmitt
@ 2025-08-22 16:25 ` Conor Dooley
0 siblings, 0 replies; 8+ messages in thread
From: Conor Dooley @ 2025-08-22 16:25 UTC (permalink / raw)
To: Marcelo Schmitt
Cc: Marilene Andrade Garcia, linux-iio, linux-kernel, devicetree,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Marcelo Schmitt,
Ceclan Dumitru, Jonathan Santos, Dragos Bogdan, Kim Seer Paller
[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]
On Thu, Aug 21, 2025 at 04:24:11PM -0300, Marcelo Schmitt wrote:
> On 08/21, Conor Dooley wrote:
> > On Thu, Aug 21, 2025 at 10:36:06AM -0300, Marilene Andrade Garcia wrote:
> > > Hello maintainers,
> > >
> > > This patch series adds basic support for the Analog Devices
> > > MAX14001/MAX14002, configurable, isolated 10-bit ADCs for multi-range
> ...
> >
> > Something gone wrong here? There's already a v9 from another ADI
> > employee on the list:
> > https://lore.kernel.org/all/20230710042723.46084-2-kimseer.paller@analog.com/
>
> Yes, my procedure for finding parts for GSoC projects failed to find that set.
> From quick read of v9 thread, the reason for that not being applied was lack
> of detailed comments about device data transfer handling?
> Anyway, I guess the only thing left to do now is see what can be taken from
> Marilene's set and applied on top of Kim's one.
>
> I'm sorry for this unfortunate situation.
Eek, saving grace I suppose is that the experience of writing the driver
is the most important thing to get out of GSoC?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 2/2] iio: adc: Add basic support for MAX14001
2025-08-21 13:39 ` [PATCH v1 2/2] iio: adc: Add basic support for MAX14001 Marilene Andrade Garcia
2025-08-22 6:52 ` kernel test robot
@ 2025-08-25 11:16 ` Jonathan Cameron
1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2025-08-25 11:16 UTC (permalink / raw)
To: Marilene Andrade Garcia
Cc: linux-iio, linux-kernel, devicetree, David Lechner, Nuno Sá,
Andy Shevchenko, Lars-Peter Clausen, Michael Hennerich,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Marcelo Schmitt,
Marcelo Schmitt, Ceclan Dumitru, Jonathan Santos, Dragos Bogdan
On Thu, 21 Aug 2025 10:39:07 -0300
Marilene Andrade Garcia <marilene.agarcia@gmail.com> wrote:
> The MAX14001/MAX14002 are configurable, isolated 10-bit ADCs for
> multi-range binary inputs. Besides the ADC readings, the MAX14001/MAX14002
> offers more features, like a binary comparator, a filtered reading that
> can provide the average of the last 2, 4, or 8 ADC readings, and an inrush
> comparator that triggers the inrush current. There is also a fault feature
> that can diagnose seven possible fault conditions. And an option to select
> an external or internal ADC voltage reference.
>
> Add basic support for MAX14001/MAX14002 with the following features:
> - Raw ADC reading.
> - Filtered ADC average reading with the default configuration.
>
> Signed-off-by: Marilene Andrade Garcia <marilene.agarcia@gmail.com>
Given the discussion on the cover letter, perhaps this will need to be
merged with the earlier set. I'll do a quick review anyway!
Fairly minor comments inline. This is in a pretty good state for a v1.
Thanks,
Jonathan
> ---
> MAINTAINERS | 1 +
> drivers/iio/adc/Kconfig | 10 ++
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/max14001.c | 213 +++++++++++++++++++++++++++++++++++++
> 4 files changed, 225 insertions(+)
> create mode 100644 drivers/iio/adc/max14001.c
> diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c
> new file mode 100644
> index 000000000000..fb79f3b81e0c
> --- /dev/null
> +++ b/drivers/iio/adc/max14001.c
> @@ -0,0 +1,213 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * MAX14001/MAX14002 SPI ADC driver
> + *
> + * Copyright (c) 2025 Marilene Andrade Garcia <marilene.agarcia@gmail.com>
> + *
> + * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX14001-MAX14002.pdf
> + */
> +
> +#include <asm/unaligned.h>
As per build bot this doesn't work on modern kernels. linux/unaligned.
> +#include <linux/bitfield.h>
> +#include <linux/bitrev.h>
> +#include <linux/module.h>
various headers missing. Please follow approximate include what you use principles.
There are some headers that are obviously going to be included by another one
because they cannot stand alone, so for those you can include just the parent.
E.g. mutex.h not mutex_types.h but in most other cases all includes with definitions
that are used in this file should be here.
> +#include <linux/spi/spi.h>
> +#include <linux/iio/iio.h>
> +#include <linux/regulator/consumer.h>
> +
> +/* MAX14001 registers definition */
> +#define MAX14001_REG_ADC 0x00
> +#define MAX14001_REG_FADC 0x01
> +#define MAX14001_REG_FLAGS 0x02
> +#define MAX14001_REG_FLTEN 0x03
> +#define MAX14001_REG_THL 0x04
> +#define MAX14001_REG_THU 0x05
> +#define MAX14001_REG_INRR 0x06
> +#define MAX14001_REG_INRT 0x07
> +#define MAX14001_REG_INRP 0x08
> +#define MAX14001_REG_CFG 0x09
> +#define MAX14001_REG_ENBL 0x0A
> +#define MAX14001_REG_ACT 0x0B
> +#define MAX14001_REG_WEN 0x0C
> +
> +/* MAX14001 CONTROL values*/
Missing space before */
They are going in the WR field below I'd rename that MASK_W
then you can just 1 and 0 with their boolean meaning and
not bother with these defines.
> +#define MAX14001_REG_WRITE 0x1
> +#define MAX14001_REG_READ 0x0
> +
> +/* MAX14001 MASKS */
The comment isn't very useful. Masks of what? These seems to be
SPI message related. Also no point in prefixing comments
with MAX14001 when the naming makes that clear.
> +#define MAX14001_MASK_ADDR GENMASK(15, 11)
> +#define MAX14001_MASK_WR BIT(10)
> +#define MAX14001_MASK_DATA GENMASK(9, 0)
> +
> +enum max14001_chip_model {
> + max14001,
> + max14002,
> +};
> +
> +struct max14001_chip_info {
> + const char *name;
> +};
> +
> +struct max14001_state {
> + const struct max14001_chip_info *chip_info;
> + struct spi_device *spi;
> + int vref_mv;
> +
> + __be16 rx_buffer __aligned(IIO_DMA_MINALIGN);
> + __be16 tx_buffer;
I'd add a comment on these to mention they are also bit
reversed after we've flipped the bytes to be in the right order.
> +};
> +
> +static struct max14001_chip_info max14001_chip_info_tbl[] = {
> + [max14001] = {
> + .name = "max14001",
> + },
> + [max14002] = {
> + .name = "max14002",
> + },
> +};
> +
> +static int max14001_spi_read(struct max14001_state *st, u16 reg, int *val)
The register map is large enough I'd consider using a custom regmap
as then we can take advantage of caching and the field manipulation
functions that we get from regmap.
> +{
> + struct spi_transfer xfer[] = {
> + {
> + .tx_buf = &st->tx_buffer,
> + .len = sizeof(st->tx_buffer),
> + .cs_change = 1,
> + },
> + {
> + .rx_buf = &st->rx_buffer,
> + .len = sizeof(st->rx_buffer),
> + },
> + };
> + int ret;
> +
No locking? Given use of shared buffers I would suggest you need
a mutex here, the bus lock won't be enough.
> + st->tx_buffer = FIELD_PREP(MAX14001_MASK_ADDR, reg) |
> + FIELD_PREP(MAX14001_MASK_WR, MAX14001_REG_READ);
> + st->tx_buffer = bitrev16(st->tx_buffer);
> +
> + ret = spi_sync_transfer(st->spi, xfer, ARRAY_SIZE(xfer));
> + if (ret < 0)
> + return ret;
> +
> + st->rx_buffer = bitrev16(be16_to_cpu(st->rx_buffer));
> + *val = FIELD_GET(MAX14001_MASK_DATA, st->rx_buffer);
> +
> + return 0;
> +}
> +static const struct spi_device_id max14001_id_table[] = {
> + { "max14001", (kernel_ulong_t)&max14001_chip_info_tbl[max14001] },
> + { "max14002", (kernel_ulong_t)&max14001_chip_info_tbl[max14002] },
> + {}
Trivial but for consistency
{ }
which is the preferred style in IIO. There isn't any general agreement
across the kernel so I picked a choice at random a while back as any choice
is better than a mix like we have here.
> +};
> +MODULE_DEVICE_TABLE(spi, max14001_id_table);
> +
> +static const struct of_device_id max14001_of_match[] = {
> + { .compatible = "adi,max14001",
> + .data = &max14001_chip_info_tbl[max14001], },
> + { .compatible = "adi,max14002",
> + .data = &max14001_chip_info_tbl[max14002], },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, max14001_of_match);
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-08-25 11:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 13:36 [PATCH v1 0/2] Add MAX14001/MAX14002 support Marilene Andrade Garcia
2025-08-21 13:38 ` [PATCH v1 1/2] dt-bindings: iio: adc: Add MAX14001 Marilene Andrade Garcia
2025-08-21 13:39 ` [PATCH v1 2/2] iio: adc: Add basic support for MAX14001 Marilene Andrade Garcia
2025-08-22 6:52 ` kernel test robot
2025-08-25 11:16 ` Jonathan Cameron
2025-08-21 18:06 ` [PATCH v1 0/2] Add MAX14001/MAX14002 support Conor Dooley
2025-08-21 19:24 ` Marcelo Schmitt
2025-08-22 16:25 ` Conor Dooley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).