* [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell
@ 2026-11-23 15:07 Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property Svyatoslav Ryhel
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 15:07 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, Svyatoslav Ryhel
Cc: linux-kernel, devicetree, linux-iio, mfd
The MAX8907 PMIC has a dedicated ADC cell, which provides 8 ADC channels
with information about different parts of the power system, including the
battery, charger/plug, jack and thermal readings.
This patchset has 2 dependencies:
- patch 1 of the series requires this patch
("regulator: dt-bindings: maxim,max8907: Convert to DT schema")
https://lore.kernel.org/lkml/20261027114634.79706-2-clamor95@gmail.com/
- patch 4 of the series requires this patch
("leds: Add driver for MAX8907 LED cell")
https://lore.kernel.org/lkml/20261027115006.86032-1-clamor95@gmail.com/
Or to be sspecific, part that adds max8907-leds to max8907_cells
---
Changes in v2:
- remove unused register fields
- add prefixes to used register bits and macros
- default reference values indexed off the enum
- swap data array to __be16
- set bulk read size with sizeof
- return directly last regmap_update_bits in the max8907_adc_init()
- added comment for iio_device_set_parent()
- MAX8907_MASK_RST_CFG_INT_REF_EN > MAX8907_MASK_INT_REF_EN
- dropped kernel.h
Changes in v3:
- explicitly assign values to channel naming enum
- add missing headers
- loosen regmap_read_poll_timeout() loop
- rename module description
---
Svyatoslav Ryhel (4):
regulator: dt-bindings: maxim,max8907: Document io-channel-cells
property
mfd: max8907: Add ADC client support
iio: adc: Add support for MAX8907 ADC cell
mfd: max8907: Add ADC cell
.../bindings/regulator/maxim,max8907.yaml | 3 +
drivers/iio/adc/Kconfig | 10 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/max8907-adc.c | 181 ++++++++++++++++++
drivers/mfd/max8907.c | 75 ++++++++
include/linux/mfd/max8907.h | 53 +++++
6 files changed, 323 insertions(+)
create mode 100644 drivers/iio/adc/max8907-adc.c
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
@ 2026-11-23 15:07 ` Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 2/4] mfd: max8907: Add ADC client support Svyatoslav Ryhel
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 15:07 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, Svyatoslav Ryhel
Cc: linux-kernel, devicetree, linux-iio, mfd
The Maxim MAX8907 has a built-in 8-channel ADC. It does not require any
Device Tree-based configuration and is folded into the main PMIC
node. Document the io-channel-cells property in PMIC's node to be able to
request channel data in the Device Tree using the phandle of the PMIC.
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
Documentation/devicetree/bindings/regulator/maxim,max8907.yaml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/devicetree/bindings/regulator/maxim,max8907.yaml b/Documentation/devicetree/bindings/regulator/maxim,max8907.yaml
index ee1a305d1c210..ccdeb9ba21e26 100644
--- a/Documentation/devicetree/bindings/regulator/maxim,max8907.yaml
+++ b/Documentation/devicetree/bindings/regulator/maxim,max8907.yaml
@@ -27,6 +27,9 @@ properties:
system-power-controller: true
+ "#io-channel-cells":
+ const: 1
+
mbatt-supply:
description:
The input supply for MBATT, BBAT, SDBY, VRTC.
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 2/4] mfd: max8907: Add ADC client support
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property Svyatoslav Ryhel
@ 2026-11-23 15:07 ` Svyatoslav Ryhel
2026-11-23 18:54 ` Andy Shevchenko
2026-11-23 15:07 ` [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 4/4] mfd: max8907: Add " Svyatoslav Ryhel
3 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 15:07 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, Svyatoslav Ryhel
Cc: linux-kernel, devicetree, linux-iio, mfd
The Maxim MAX8907 has an 8-channel ADC at a fixed location. Add client
support for it along with its regmap and interrupts.
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/mfd/max8907.c | 74 +++++++++++++++++++++++++++++++++++++
include/linux/mfd/max8907.h | 53 ++++++++++++++++++++++++++
2 files changed, 127 insertions(+)
diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index b511c57026188..103294c76b97d 100644
--- a/drivers/mfd/max8907.c
+++ b/drivers/mfd/max8907.c
@@ -113,6 +113,48 @@ static const struct regmap_config max8907_regmap_rtc_config = {
.cache_type = REGCACHE_MAPLE,
};
+static bool max8907_adc_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case MAX8907_REG_TSC_STA_INT:
+ case MAX8907_REG_AUX1_MSB ... MAX8907_REG_TDIE_LSB:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool max8907_adc_is_precious_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case MAX8907_REG_TSC_STA_INT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool max8907_adc_is_writeable_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case MAX8907_REG_TSC_STA_INT:
+ case MAX8907_REG_AUX1_MSB ... MAX8907_REG_TDIE_LSB:
+ return false;
+ default:
+ return true;
+ }
+}
+
+static const struct regmap_config max8907_regmap_adc_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .volatile_reg = max8907_adc_is_volatile_reg,
+ .precious_reg = max8907_adc_is_precious_reg,
+ .writeable_reg = max8907_adc_is_writeable_reg,
+ .max_register = MAX8907_REG_TDIE_MEASURE,
+ .cache_type = REGCACHE_MAPLE,
+};
+
static const struct regmap_irq max8907_chg_irqs[] = {
{ .reg_offset = 0, .mask = 1 << 0, },
{ .reg_offset = 0, .mask = 1 << 1, },
@@ -175,6 +217,20 @@ static const struct regmap_irq_chip max8907_rtc_irq_chip = {
.num_irqs = ARRAY_SIZE(max8907_rtc_irqs),
};
+static const struct regmap_irq max8907_adc_irqs[] = {
+ { .reg_offset = 0, .mask = BIT(0), },
+ { .reg_offset = 0, .mask = BIT(1), },
+};
+
+static const struct regmap_irq_chip max8907_adc_irq_chip = {
+ .name = "max8907 adc",
+ .status_base = MAX8907_REG_TSC_STA_INT,
+ .mask_base = MAX8907_REG_TSC_INT_MASK,
+ .num_regs = 1,
+ .irqs = max8907_adc_irqs,
+ .num_irqs = ARRAY_SIZE(max8907_adc_irqs),
+};
+
static int max8907_power_off(struct sys_off_data *data)
{
struct max8907 *max8907 = data->cb_data;
@@ -227,6 +283,18 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
return dev_err_probe(dev, PTR_ERR(max8907->regmap_rtc),
"RTC regmap init failed\n");
+ max8907->i2c_adc = devm_i2c_new_dummy_device(dev, i2c->adapter, MAX8907_ADC_I2C_ADDR);
+ if (IS_ERR(max8907->i2c_adc))
+ return PTR_ERR(max8907->i2c_adc);
+
+ i2c_set_clientdata(max8907->i2c_adc, max8907);
+
+ max8907->regmap_adc = devm_regmap_init_i2c(max8907->i2c_adc,
+ &max8907_regmap_adc_config);
+ if (IS_ERR(max8907->regmap_adc))
+ return dev_err_probe(dev, PTR_ERR(max8907->regmap_adc),
+ "ADC regmap init failed\n");
+
ret = devm_regmap_add_irq_chip(dev, max8907->regmap_gen, max8907->i2c_gen->irq,
IRQF_ONESHOT | IRQF_SHARED, -1, &max8907_chg_irq_chip,
&max8907->irqc_chg);
@@ -245,6 +313,12 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
if (ret)
return dev_err_probe(dev, ret, "Failed to add rtc irq chip\n");
+ ret = devm_regmap_add_irq_chip(dev, max8907->regmap_adc, max8907->i2c_gen->irq,
+ IRQF_ONESHOT | IRQF_SHARED, -1, &max8907_adc_irq_chip,
+ &max8907->irqc_adc);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to add adc irq chip\n");
+
ret = devm_mfd_add_devices(dev, -1, max8907_cells, ARRAY_SIZE(max8907_cells),
NULL, 0, NULL);
if (ret)
diff --git a/include/linux/mfd/max8907.h b/include/linux/mfd/max8907.h
index 9865ae52877fd..ac4532d172331 100644
--- a/include/linux/mfd/max8907.h
+++ b/include/linux/mfd/max8907.h
@@ -153,6 +153,51 @@
#define MAX8907_REG_MPL_CNTL 0x1E
/* ADC and Touch Screen Controller register map */
+#define MAX8907_REG_TSC_STA_INT 0x00
+#define MAX8907_REG_TSC_INT_MASK 0x01
+#define MAX8907_REG_TSC_CNFG1 0x02
+#define MAX8907_REG_TSC_CNFG2 0x03
+#define MAX8907_REG_TSC_CNFG3 0x04
+#define MAX8907_REG_ADC_RES_CNFG1 0x06
+#define MAX8907_REG_ADC_AVG_CNFG1 0x07
+#define MAX8907_REG_ADC_ACQ_CNFG1 0x08
+#define MAX8907_REG_ADC_ACQ_CNFG2 0x09
+#define MAX8907_REG_ADC_SCHED 0x10
+#define MAX8907_REG_X_MSB 0x50
+#define MAX8907_REG_X_LSB 0x51
+#define MAX8907_REG_Y_MSB 0x52
+#define MAX8907_REG_Y_LSB 0x53
+#define MAX8907_REG_Z1_MSB 0x54
+#define MAX8907_REG_Z1_LSB 0x55
+#define MAX8907_REG_Z2_MSB 0x56
+#define MAX8907_REG_Z2_LSB 0x57
+#define MAX8907_REG_AUX1_MSB 0x60
+#define MAX8907_REG_AUX1_LSB 0x61
+#define MAX8907_REG_AUX2_MSB 0x62
+#define MAX8907_REG_AUX2_LSB 0x63
+#define MAX8907_REG_VCHG_MSB 0x64
+#define MAX8907_REG_VCHG_LSB 0x65
+#define MAX8907_REG_VBBATT_MSB 0x66
+#define MAX8907_REG_VBBATT_LSB 0x67
+#define MAX8907_REG_VMBATT_MSB 0x68
+#define MAX8907_REG_VMBATT_LSB 0x69
+#define MAX8907_REG_ISNS_MSB 0x6A
+#define MAX8907_REG_ISNS_LSB 0x6B
+#define MAX8907_REG_THM_MSB 0x6C
+#define MAX8907_REG_THM_LSB 0x6D
+#define MAX8907_REG_TDIE_MSB 0x6E
+#define MAX8907_REG_TDIE_LSB 0x6F
+
+#define MAX8907_REG_AUX1_MEASURE 0xC0
+#define MAX8907_REG_AUX2_MEASURE 0xC8
+#define MAX8907_REG_VCHG_MEASURE 0xD0
+#define MAX8907_REG_VBBATT_MEASURE 0xD8
+#define MAX8907_REG_VMBATT_MEASURE 0xE0
+#define MAX8907_REG_ISNS_MEASURE 0xE8
+#define MAX8907_REG_THM_MEASURE 0xF0
+#define MAX8907_REG_TDIE_MEASURE 0xF8
+
+/* Regulator stride */
#define MAX8907_CTL 0
#define MAX8907_SEQCNT 1
#define MAX8907_VOUT 2
@@ -166,6 +211,8 @@
#define MAX8907_MASK_OUT5V_EN 0x01
#define MAX8907_MASK_SOFT_RESET 0x20
#define MAX8907_MASK_POWER_OFF 0x40
+#define MAX8907_MASK_INT_REF_EN 0x01
+#define MAX8907_MASK_NREF_OK 0x10
/* Regulator IDs */
#define MAX8907_MBATT 0
@@ -226,6 +273,9 @@ enum {
MAX8907_IRQ_RTC_ALARM1 = 0,
MAX8907_IRQ_RTC_ALARM0,
+
+ MAX8907_IRQ_TSC_STICK = 0,
+ MAX8907_IRQ_TSC_NSTICK,
};
struct regmap_irq_chips_data;
@@ -235,11 +285,14 @@ struct max8907 {
struct mutex irq_lock;
struct i2c_client *i2c_gen;
struct i2c_client *i2c_rtc;
+ struct i2c_client *i2c_adc;
struct regmap *regmap_gen;
struct regmap *regmap_rtc;
+ struct regmap *regmap_adc;
struct regmap_irq_chip_data *irqc_chg;
struct regmap_irq_chip_data *irqc_on_off;
struct regmap_irq_chip_data *irqc_rtc;
+ struct regmap_irq_chip_data *irqc_adc;
};
#endif
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 2/4] mfd: max8907: Add ADC client support Svyatoslav Ryhel
@ 2026-11-23 15:07 ` Svyatoslav Ryhel
2026-11-23 19:01 ` Andy Shevchenko
2026-11-23 15:07 ` [PATCH v3 4/4] mfd: max8907: Add " Svyatoslav Ryhel
3 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 15:07 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, Svyatoslav Ryhel
Cc: linux-kernel, devicetree, linux-iio, mfd
The MAX8907 PMIC has a dedicated ADC cell, which provides 8 ADC channels
with information about different parts of the power system, including the
battery, charger/plug, jack and thermal readings.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/iio/adc/Kconfig | 10 ++
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/max8907-adc.c | 181 ++++++++++++++++++++++++++++++++++
3 files changed, 192 insertions(+)
create mode 100644 drivers/iio/adc/max8907-adc.c
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 1d6ed49041ab5..a5d0f8727af70 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -1194,6 +1194,16 @@ config MAX77541_ADC
To compile this driver as a module, choose M here:
the module will be called max77541-adc.
+config MAX8907_ADC
+ tristate "Maxim MAX8907 ADC driver"
+ depends on MFD_MAX8907
+ help
+ Say yes here to build support for 8 channel 12-bit ADC
+ interface found in the Maxim MAX8907 PMIC.
+
+ To compile this driver as a module, choose M here:
+ the module will be called max8907-adc.
+
config MAX9611
tristate "Maxim max9611/max9612 ADC driver"
depends on I2C
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 769965295dccb..af89115978316 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -100,6 +100,7 @@ obj-$(CONFIG_MAX14001) += max14001.o
obj-$(CONFIG_MAX34408) += max34408.o
obj-$(CONFIG_MAX40080) += max40080.o
obj-$(CONFIG_MAX77541_ADC) += max77541-adc.o
+obj-$(CONFIG_MAX8907_ADC) += max8907-adc.o
obj-$(CONFIG_MAX9611) += max9611.o
obj-$(CONFIG_MCP320X) += mcp320x.o
obj-$(CONFIG_MCP3422) += mcp3422.o
diff --git a/drivers/iio/adc/max8907-adc.c b/drivers/iio/adc/max8907-adc.c
new file mode 100644
index 0000000000000..895b313a6e01f
--- /dev/null
+++ b/drivers/iio/adc/max8907-adc.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/bits.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#include <asm/byteorder.h>
+
+#include <linux/mfd/max8907.h>
+
+#define MAX8907_ADC_SCHED_AUTOSCH_ENABLE BIT(1)
+#define MAX8907_ADC_SCHED_AUTOSCH_TIME BIT(0)
+
+#define MAX8907_TO_REG(n) ((n) & 0xff)
+#define MAX8907_TO_MEASURE(n) (((n) >> 8) & 0xff)
+
+enum {
+ TDIE = 0,
+ THM = 1,
+ ISNS = 2,
+ VMBATT = 3,
+ VBBATT = 4,
+ VCHG = 5,
+ AUX2 = 6,
+ AUX1 = 7,
+};
+
+static const u32 max8907_default_ref[] = {
+ [TDIE] = 4096,
+ [THM] = 4096,
+ [ISNS] = 4096,
+ [VMBATT] = 8192,
+ [VBBATT] = 8192,
+ [VCHG] = 8192,
+ [AUX2] = 2500,
+ [AUX1] = 4096,
+};
+
+#define MAX8907_CHAN(_type, _idname, _datasheet_name) { \
+ .type = (_type), \
+ .address = MAX8907_REG_##_idname##_MSB | \
+ MAX8907_REG_##_idname##_MEASURE << 8, \
+ .indexed = 1, \
+ .channel = (_idname), \
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ .scan_index = (_idname), \
+ .scan_type = { \
+ .format = IIO_SCAN_FORMAT_UNSIGNED_INT, \
+ .realbits = 12, \
+ .storagebits = 16, \
+ .endianness = IIO_CPU, \
+ }, \
+ .datasheet_name = (_datasheet_name), \
+}
+
+static const struct iio_chan_spec max8907_adc_channels[] = {
+ MAX8907_CHAN(IIO_VOLTAGE, TDIE, "tdiode"),
+ MAX8907_CHAN(IIO_VOLTAGE, THM, "thermistor"),
+ MAX8907_CHAN(IIO_CURRENT, ISNS, "isense"),
+ MAX8907_CHAN(IIO_VOLTAGE, VMBATT, "vmbatt"),
+ MAX8907_CHAN(IIO_VOLTAGE, VBBATT, "vbbatt"),
+ MAX8907_CHAN(IIO_VOLTAGE, VCHG, "vcharge"),
+ MAX8907_CHAN(IIO_VOLTAGE, AUX2, "aux2"),
+ MAX8907_CHAN(IIO_VOLTAGE, AUX1, "aux1"),
+};
+
+static int max8907_adc_read(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ struct regmap **regmap = iio_priv(indio_dev);
+ __be16 data;
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ ret = regmap_write(*regmap, MAX8907_TO_MEASURE(chan->address), 0);
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_read(*regmap, MAX8907_TO_REG(chan->address), &data, sizeof(data));
+ if (ret)
+ return ret;
+
+ *val = be16_to_cpu(data) >> 4;
+
+ return IIO_VAL_INT;
+
+ case IIO_CHAN_INFO_SCALE:
+ *val = max8907_default_ref[chan->channel];
+ *val2 = chan->scan_type.realbits;
+
+ return IIO_VAL_FRACTIONAL_LOG2;
+
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info max8907_adc_info = {
+ .read_raw = &max8907_adc_read,
+};
+
+static int max8907_adc_init(struct regmap *regmap)
+{
+ u32 value;
+ int ret;
+
+ /* Enable internal voltage reference. Exact purpose of bits is not known. */
+ ret = regmap_update_bits(regmap, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
+ if (ret)
+ return ret;
+
+ /* Check for internal reference IRQ */
+ ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
+ !(value & MAX8907_MASK_NREF_OK), 10, 1000);
+ if (ret)
+ return ret;
+
+ return regmap_update_bits(regmap, MAX8907_REG_ADC_SCHED,
+ MAX8907_ADC_SCHED_AUTOSCH_ENABLE |
+ MAX8907_ADC_SCHED_AUTOSCH_TIME,
+ MAX8907_ADC_SCHED_AUTOSCH_ENABLE);
+}
+
+static int max8907_adc_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct max8907 *max8907 = dev_get_drvdata(dev->parent);
+ struct iio_dev *indio_dev;
+ struct regmap **regmap;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*regmap));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ regmap = iio_priv(indio_dev);
+
+ *regmap = max8907->regmap_adc;
+
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->channels = max8907_adc_channels;
+ indio_dev->num_channels = ARRAY_SIZE(max8907_adc_channels);
+ indio_dev->name = dev_name(dev);
+ indio_dev->info = &max8907_adc_info;
+
+ /*
+ * The ADC does not require a dedicated node; hence, the PMIC is set as
+ * the iio_dev parent to enable the use of the PMIC node phandle in the
+ * Device Tree bindings.
+ */
+ iio_device_set_parent(indio_dev, dev->parent);
+
+ ret = regmap_set_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
+ MAX8907_MASK_INT_REF_EN);
+ if (ret)
+ return ret;
+
+ ret = max8907_adc_init(max8907->regmap_adc);
+ if (ret)
+ return ret;
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+
+static struct platform_driver max8907_adc_driver = {
+ .driver.name = "max8907-adc",
+ .probe = max8907_adc_probe,
+};
+module_platform_driver(max8907_adc_driver);
+
+MODULE_ALIAS("platform:max8907-adc");
+MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
+MODULE_DESCRIPTION("Maxim MAX8907 ADC driver");
+MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 4/4] mfd: max8907: Add ADC cell
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
` (2 preceding siblings ...)
2026-11-23 15:07 ` [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
@ 2026-11-23 15:07 ` Svyatoslav Ryhel
3 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 15:07 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, Svyatoslav Ryhel
Cc: linux-kernel, devicetree, linux-iio, mfd
Add the ADC cell name to the list of MAX8907 cells.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/mfd/max8907.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index 103294c76b97d..ac7b41ad400ed 100644
--- a/drivers/mfd/max8907.c
+++ b/drivers/mfd/max8907.c
@@ -20,6 +20,7 @@
#include <linux/slab.h>
static const struct mfd_cell max8907_cells[] = {
+ { .name = "max8907-adc", },
{ .name = "max8907-leds", },
{ .name = "max8907-regulator", },
{ .name = "max8907-rtc", },
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/4] mfd: max8907: Add ADC client support
2026-11-23 15:07 ` [PATCH v3 2/4] mfd: max8907: Add ADC client support Svyatoslav Ryhel
@ 2026-11-23 18:54 ` Andy Shevchenko
2026-11-23 19:10 ` Svyatoslav Ryhel
0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-11-23 18:54 UTC (permalink / raw)
To: Svyatoslav Ryhel
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, linux-kernel, devicetree, linux-iio,
mfd
On Mon, Nov 23, 2026 at 05:07:23PM +0200, Svyatoslav Ryhel wrote:
> The Maxim MAX8907 has an 8-channel ADC at a fixed location. Add client
> support for it along with its regmap and interrupts.
...
> +static const struct regmap_irq max8907_adc_irqs[] = {
> + { .reg_offset = 0, .mask = BIT(0), },
> + { .reg_offset = 0, .mask = BIT(1), },
When {} on the same line, the inner trailing comma is not needed (if we ever
need to extend this we would need to change a line anyway, so there is no
benefit of having a trailing comma).
If it's just this, no need to resend. Just a hint for the future.
> +};
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
2026-11-23 15:07 ` [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
@ 2026-11-23 19:01 ` Andy Shevchenko
2026-11-23 19:24 ` Svyatoslav Ryhel
0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2026-11-23 19:01 UTC (permalink / raw)
To: Svyatoslav Ryhel
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, linux-kernel, devicetree, linux-iio,
mfd
On Mon, Nov 23, 2026 at 05:07:24PM +0200, Svyatoslav Ryhel wrote:
> The MAX8907 PMIC has a dedicated ADC cell, which provides 8 ADC channels
> with information about different parts of the power system, including the
> battery, charger/plug, jack and thermal readings.
...
> +#define MAX8907_CHAN(_type, _idname, _datasheet_name) { \
> + .type = (_type), \
> + .address = MAX8907_REG_##_idname##_MSB | \
> + MAX8907_REG_##_idname##_MEASURE << 8, \
> + .indexed = 1, \
> + .channel = (_idname), \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> + BIT(IIO_CHAN_INFO_SCALE), \
> + .scan_index = (_idname), \
Using () means that you expect an expression as a possible input. In such
a case the macro is buggy as it will evaluate it twice for _idname. The
simple solution is to drop these parentheses and expect that this macro
won't ever be used with the expressions in the parameters.
> + .scan_type = { \
> + .format = IIO_SCAN_FORMAT_UNSIGNED_INT, \
> + .realbits = 12, \
> + .storagebits = 16, \
> + .endianness = IIO_CPU, \
> + }, \
> + .datasheet_name = (_datasheet_name), \
> +}
...
> +static int max8907_adc_read(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + struct regmap **regmap = iio_priv(indio_dev);
Then logically better to go further and have
struct regmap *map = *regmap;
> + __be16 data;
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> + ret = regmap_write(*regmap, MAX8907_TO_MEASURE(chan->address), 0);
> + if (ret)
> + return ret;
> +
> + ret = regmap_bulk_read(*regmap, MAX8907_TO_REG(chan->address), &data, sizeof(data));
This is a bit too long.
ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
&data, sizeof(data));
> + if (ret)
> + return ret;
> +
> + *val = be16_to_cpu(data) >> 4;
> +
> + return IIO_VAL_INT;
> +
> + case IIO_CHAN_INFO_SCALE:
> + *val = max8907_default_ref[chan->channel];
> + *val2 = chan->scan_type.realbits;
> +
> + return IIO_VAL_FRACTIONAL_LOG2;
> +
> + default:
> + return -EINVAL;
> + }
> +}
...
> +static int max8907_adc_init(struct regmap *regmap)
Why not name it 'map'?
> +{
> + u32 value;
> + int ret;
> +
> + /* Enable internal voltage reference. Exact purpose of bits is not known. */
> + ret = regmap_update_bits(regmap, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
ret = regmap_update_bits(map, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
> + if (ret)
> + return ret;
> +
> + /* Check for internal reference IRQ */
Please, make style of one-line comments consistent ("all or none" are with or
without period, same for the first letter — capital or small).
> + ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
> + !(value & MAX8907_MASK_NREF_OK), 10, 1000);
ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
!(value & MAX8907_MASK_NREF_OK),
10, 1 * USEC_PER_MSEC);
> + if (ret)
> + return ret;
> +
> + return regmap_update_bits(regmap, MAX8907_REG_ADC_SCHED,
> + MAX8907_ADC_SCHED_AUTOSCH_ENABLE |
> + MAX8907_ADC_SCHED_AUTOSCH_TIME,
> + MAX8907_ADC_SCHED_AUTOSCH_ENABLE);
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/4] mfd: max8907: Add ADC client support
2026-11-23 18:54 ` Andy Shevchenko
@ 2026-11-23 19:10 ` Svyatoslav Ryhel
0 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 19:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, linux-kernel, devicetree, linux-iio,
mfd
пн, 23 лист. 2026 р. о 20:54 Andy Shevchenko <andriy.shevchenko@intel.com> пише:
>
> On Mon, Nov 23, 2026 at 05:07:23PM +0200, Svyatoslav Ryhel wrote:
> > The Maxim MAX8907 has an 8-channel ADC at a fixed location. Add client
> > support for it along with its regmap and interrupts.
>
> ...
>
> > +static const struct regmap_irq max8907_adc_irqs[] = {
> > + { .reg_offset = 0, .mask = BIT(0), },
> > + { .reg_offset = 0, .mask = BIT(1), },
>
> When {} on the same line, the inner trailing comma is not needed (if we ever
> need to extend this we would need to change a line anyway, so there is no
> benefit of having a trailing comma).
>
> If it's just this, no need to resend. Just a hint for the future.
>
Thank you, I must have overlooked.
> > +};
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
2026-11-23 19:01 ` Andy Shevchenko
@ 2026-11-23 19:24 ` Svyatoslav Ryhel
2026-11-23 19:54 ` Andy Shevchenko
0 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-23 19:24 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, linux-kernel, devicetree, linux-iio,
mfd
пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <andriy.shevchenko@intel.com> пише:
>
> On Mon, Nov 23, 2026 at 05:07:24PM +0200, Svyatoslav Ryhel wrote:
> > The MAX8907 PMIC has a dedicated ADC cell, which provides 8 ADC channels
> > with information about different parts of the power system, including the
> > battery, charger/plug, jack and thermal readings.
>
> ...
>
> > +#define MAX8907_CHAN(_type, _idname, _datasheet_name) { \
> > + .type = (_type), \
> > + .address = MAX8907_REG_##_idname##_MSB | \
> > + MAX8907_REG_##_idname##_MEASURE << 8, \
> > + .indexed = 1, \
> > + .channel = (_idname), \
> > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> > + BIT(IIO_CHAN_INFO_SCALE), \
> > + .scan_index = (_idname), \
>
> Using () means that you expect an expression as a possible input. In such
> a case the macro is buggy as it will evaluate it twice for _idname. The
> simple solution is to drop these parentheses and expect that this macro
> won't ever be used with the expressions in the parameters.
>
You have a point but current state should not cause issues as well.
> > + .scan_type = { \
> > + .format = IIO_SCAN_FORMAT_UNSIGNED_INT, \
> > + .realbits = 12, \
> > + .storagebits = 16, \
> > + .endianness = IIO_CPU, \
> > + }, \
> > + .datasheet_name = (_datasheet_name), \
> > +}
>
> ...
>
> > +static int max8907_adc_read(struct iio_dev *indio_dev,
> > + struct iio_chan_spec const *chan,
> > + int *val, int *val2, long mask)
> > +{
> > + struct regmap **regmap = iio_priv(indio_dev);
>
> Then logically better to go further and have
>
> struct regmap *map = *regmap;
>
This is matter of taste, I was inspired by MAX77541 ADC which uses
exactly this approach.
> > + __be16 data;
> > + int ret;
> > +
> > + switch (mask) {
> > + case IIO_CHAN_INFO_RAW:
> > + ret = regmap_write(*regmap, MAX8907_TO_MEASURE(chan->address), 0);
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_bulk_read(*regmap, MAX8907_TO_REG(chan->address), &data, sizeof(data));
>
> This is a bit too long.
>
101 char, yeah 1 char too long, though maybe it is not wort resending
for a single char too long?
> ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
> &data, sizeof(data));
>
> > + if (ret)
> > + return ret;
> > +
> > + *val = be16_to_cpu(data) >> 4;
> > +
> > + return IIO_VAL_INT;
> > +
> > + case IIO_CHAN_INFO_SCALE:
> > + *val = max8907_default_ref[chan->channel];
> > + *val2 = chan->scan_type.realbits;
> > +
> > + return IIO_VAL_FRACTIONAL_LOG2;
> > +
> > + default:
> > + return -EINVAL;
> > + }
> > +}
>
> ...
>
> > +static int max8907_adc_init(struct regmap *regmap)
>
> Why not name it 'map'?
>
Because regmap is more explicit and is used consistently across the driver.
> > +{
> > + u32 value;
> > + int ret;
> > +
> > + /* Enable internal voltage reference. Exact purpose of bits is not known. */
> > + ret = regmap_update_bits(regmap, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
>
> ret = regmap_update_bits(map, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
>
which map? bitmap? statemap? or maybe geographical map?
> > + if (ret)
> > + return ret;
> > +
> > + /* Check for internal reference IRQ */
>
> Please, make style of one-line comments consistent ("all or none" are with or
> without period, same for the first letter — capital or small).
>
First comment has 2 sentences, that is why it has periods. Second only
one, so it does not need period. "same for the first letter — capital
or small" - have you even checked the patch?
> > + ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
> > + !(value & MAX8907_MASK_NREF_OK), 10, 1000);
>
> ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
> !(value & MAX8907_MASK_NREF_OK),
> 10, 1 * USEC_PER_MSEC);
>
hmm, replace 1000 (4 chars, pretty readable) with USEC_PER_MSEC (12
chars and twice wrapped line and needs tinkering or looking into
units.h), I don't think so.
> > + if (ret)
> > + return ret;
> > +
> > + return regmap_update_bits(regmap, MAX8907_REG_ADC_SCHED,
> > + MAX8907_ADC_SCHED_AUTOSCH_ENABLE |
> > + MAX8907_ADC_SCHED_AUTOSCH_TIME,
> > + MAX8907_ADC_SCHED_AUTOSCH_ENABLE);
> > +}
>
> --
> With Best Regards,
> Andy Shevchenko
>
I would like to hear what Jonathan has to say.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
2026-11-23 19:24 ` Svyatoslav Ryhel
@ 2026-11-23 19:54 ` Andy Shevchenko
0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-11-23 19:54 UTC (permalink / raw)
To: Svyatoslav Ryhel
Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Lee Jones, linux-kernel, devicetree, linux-iio,
mfd
On Mon, Nov 23, 2026 at 09:24:30PM +0200, Svyatoslav Ryhel wrote:
> пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <andriy.shevchenko@intel.com> пише:
> > On Mon, Nov 23, 2026 at 05:07:24PM +0200, Svyatoslav Ryhel wrote:
...
> > > +#define MAX8907_CHAN(_type, _idname, _datasheet_name) { \
> > > + .type = (_type), \
> > > + .address = MAX8907_REG_##_idname##_MSB | \
> > > + MAX8907_REG_##_idname##_MEASURE << 8, \
> > > + .indexed = 1, \
> > > + .channel = (_idname), \
> > > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> > > + BIT(IIO_CHAN_INFO_SCALE), \
> > > + .scan_index = (_idname), \
> >
> > Using () means that you expect an expression as a possible input. In such
> > a case the macro is buggy as it will evaluate it twice for _idname. The
> > simple solution is to drop these parentheses and expect that this macro
> > won't ever be used with the expressions in the parameters.
> You have a point but current state should not cause issues as well.
I know, but I saw Sashiko's complain somewhere else on a similar situation.
It might or might not complain, better to be prepared.
> > > + .scan_type = { \
> > > + .format = IIO_SCAN_FORMAT_UNSIGNED_INT, \
> > > + .realbits = 12, \
> > > + .storagebits = 16, \
> > > + .endianness = IIO_CPU, \
> > > + }, \
> > > + .datasheet_name = (_datasheet_name), \
> > > +}
...
> > > + struct regmap **regmap = iio_priv(indio_dev);
> >
> > Then logically better to go further and have
> >
> > struct regmap *map = *regmap;
>
> This is matter of taste, I was inspired by MAX77541 ADC which uses
> exactly this approach.
Not really, however it's very unlikely to happen IRL. When you dereference
something the compiler is in its right to do it as many times as you used in
the code. Hence theoretically (in this driver) somebody might replace the
pointer and two consequent regmap calls will get different regmap.
...
> > > + ret = regmap_bulk_read(*regmap, MAX8907_TO_REG(chan->address), &data, sizeof(data));
> >
> > This is a bit too long.
>
> 101 char, yeah 1 char too long, though maybe it is not wort resending
> for a single char too long?
IIO is tending to follow documentation in majority of the drivers and cases
which is 80 limit.
> > ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
> > &data, sizeof(data));
...
> > > +static int max8907_adc_init(struct regmap *regmap)
> >
> > Why not name it 'map'?
>
> Because regmap is more explicit and is used consistently across the driver.
And messes with the data type name :-)
...
> > ret = regmap_update_bits(map, MAX8907_REG_TSC_CNFG1, GENMASK(1, 0), BIT(1));
>
> which map? bitmap? statemap? or maybe geographical map?
Read the name of the call. This is really silly question here.
> > > + if (ret)
> > > + return ret;
...
> > > + /* Check for internal reference IRQ */
> >
> > Please, make style of one-line comments consistent ("all or none" are with or
> > without period, same for the first letter — capital or small).
>
> First comment has 2 sentences, that is why it has periods. Second only
> one, so it does not need period. "same for the first letter — capital
> or small" - have you even checked the patch?
Then make the style equal. Two sentences can be written differently.
And please, stop being rude. Yes, I read the patch, The second part is
unrelated, I am sorry for mentioning it.
...
> > > + ret = regmap_read_poll_timeout(regmap, MAX8907_REG_TSC_STA_INT, value,
> > > + !(value & MAX8907_MASK_NREF_OK), 10, 1000);
> >
> > ret = regmap_read_poll_timeout(map, MAX8907_REG_TSC_STA_INT, value,
> > !(value & MAX8907_MASK_NREF_OK),
> > 10, 1 * USEC_PER_MSEC);
> >
>
> hmm, replace 1000 (4 chars, pretty readable) with USEC_PER_MSEC (12
> chars and twice wrapped line and needs tinkering or looking into
> units.h), I don't think so.
Because the point is missed? We have tons of much longer multipliers that kill
two birds with one stone:
- avoiding possible typos when many 0:s are in them (one can be missed or too many)
- hinting reader of the units of the used values without even looking into the docs
- (and reading 1...MSEC is quite natural, without counting 0:s and thinking how
many of them and what 1000 microseconds, after spending time on the
documentation, means in practice)
Please, use multipliers where it's makes code better to understand for
unprepared reader.
...
> I would like to hear what Jonathan has to say.
OK.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-23 19:54 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 15:07 [PATCH v3 0/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 2/4] mfd: max8907: Add ADC client support Svyatoslav Ryhel
2026-11-23 18:54 ` Andy Shevchenko
2026-11-23 19:10 ` Svyatoslav Ryhel
2026-11-23 15:07 ` [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell Svyatoslav Ryhel
2026-11-23 19:01 ` Andy Shevchenko
2026-11-23 19:24 ` Svyatoslav Ryhel
2026-11-23 19:54 ` Andy Shevchenko
2026-11-23 15:07 ` [PATCH v3 4/4] mfd: max8907: Add " Svyatoslav Ryhel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®