iio: adc: Add support for MAX8907 ADC cell
Subsystems (4)
v2 cover iio: adc: Add support for MAX8907 ADC cell
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/[email protected]/
- patch 4 of the series requires this patch
("leds: Add driver for MAX8907 LED cell")
https://lore.kernel.org/lkml/[email protected]/
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
---
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 | 169 ++++++++++++++++++ drivers/mfd/max8907.c | 75 ++++++++ include/linux/mfd/max8907.h | 53 ++++++ 6 files changed, 311 insertions(+) create mode 100644 drivers/iio/adc/max8907-adc.c
Signature · 1 line
2.53.0
PATCH v2 1/4 regulator: dt-bindings: maxim,max8907: Document io-channel-cells property
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.
--- Documentation/devicetree/bindings/regulator/maxim,max8907.yaml | 3 +++ 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/regulator/maxim,max8907.yaml +3 -0
@@ -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.
Signature · 1 line
2.53.0
Re: [PATCH v2 1/4] regulator: dt-bindings: maxim,max8907: Document io-channel-cells property
Quoted 8 lines · On Sun, 15 Nov 2026 11:11:17 +0200 Svyatoslav Ryhel <[email protected]> wrote:
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 <[email protected]>Acked-by Conor Dooley <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>
(as this will all I think go through MFD in the end).
Quoted 18 lines
--- Documentation/devicetree/bindings/regulator/maxim,max8907.yaml | 3 +++ 1 file changed, 3 insertions(+)Documentation/devicetree/bindings/regulator/maxim,max8907.yaml +3
-0@@ -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.
PATCH v2 2/4 mfd: max8907: Add ADC client support
In reply to Svyatoslav RyhelThe Maxim MAX8907 has an 8-channel ADC at a fixed location. Add client support for it along with its regmap and interrupts.
--- drivers/mfd/max8907.c | 74 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/max8907.h | 53 ++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
drivers/mfd/max8907.c +74 -0
@@ -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;
@@ -233,6 +289,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);
@@ -251,6 +319,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)
include/linux/mfd/max8907.h +53 -0
82 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 2/4] mfd: max8907: Add ADC client support
Quoted 4 lines · On Sun, 15 Nov 2026 11:11:18 +0200 Svyatoslav Ryhel <[email protected]> wrote:
The Maxim MAX8907 has an 8-channel ADC at a fixed location. Add client support for it along with its regmap and interrupts.
Signed-off-by Svyatoslav Ryhel <[email protected]>
It is a bit of a shame the coupling between MFD and ADC drives is made via those registers having to be visible in both, but I don't see a clean way around it so:
PATCH v2 3/4 iio: adc: Add support for MAX8907 ADC cell
In reply to Svyatoslav RyhelThe 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.
--- drivers/iio/adc/Kconfig | 10 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/max8907-adc.c | 169 ++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 drivers/iio/adc/max8907-adc.c
drivers/iio/adc/Kconfig +10 -0
@@ -1176,6 +1176,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
drivers/iio/adc/Makefile +1 -0
@@ -99,6 +99,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
drivers/iio/adc/max8907-adc.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 3 lines · Svyatoslav Ryhel
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.
...
drivers/iio/adc/Kconfig config MAX77541_ADC · line 1180
Quoted 2 lines
drivers/iio/adc/Kconfig +2
-0+config MAX8907_ADC + tristate "Maxim MAX8907 ADC driver"
Make MODULE_DESCRIPTION() to use the same text.
drivers/iio/adc/Kconfig config MAX77541_ADC · line 1187
Quoted 7 lines
drivers/iio/adc/Kconfig +7
-0+ 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.
...
IWYU, please. + bits.h, types.h, et cetera.
drivers/iio/adc/max8907-adc.c line 5
Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +3
-0+#include <linux/iio/iio.h> +#include <linux/module.h> +#include <linux/mfd/max8907.h>
It's better to move to a separate group, as this is related to the certain HW. But since it's a single header I'm not too picky about it.
drivers/iio/adc/max8907-adc.c line 8
Quoted 3 lines
drivers/iio/adc/max8907-adc.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/regmap.h>
Should be also a group for asm/byteorder.h.
Quoted 2 lines
drivers/iio/adc/max8907-adc.c new file +2
-0+#define MAX8907_TO_REG (n) ((n) & 0xff) +#define MAX8907_TO_MEASURE (n) (((n) >> 8) & 0xff)
...
drivers/iio/adc/max8907-adc.c line 17
Quoted 2 lines
drivers/iio/adc/max8907-adc.c new file +2
-0+enum { +TDIE ,THM ,ISNS ,VMBATT ,VBBATT ,VCHG ,AUX2 ,AUX1
Leave trailing comma, but what is this? Is it HW related or pure Linux abstraction? In other words, is the order strict? Looking at the code below I think you have to initialise all of them to make the order strict.
Quoted 1 line
+};
...
drivers/iio/adc/max8907-adc.c line 28
Quoted 9 lines
drivers/iio/adc/max8907-adc.c new file +9
-0+static const u32 max8907_default_ref[] = { + [TDIE ] =4096 , + [THM ] =4096 , + [ISNS ] =4096 , + [VMBATT ] =8192 , + [VBBATT ] =8192 , + [VCHG ] =8192 , + [AUX2 ] =2500 , + [AUX1] 4096,
Funny thing, actually we used to have an interesting case in the kernel, id est 113ec87b0f26 ("pinctrl: npcm8xx: Fix incorrect struct npcm8xx_pincfg assignment").
Quoted 1 line
+};
...
drivers/iio/adc/max8907-adc.c line 109
Quoted 13 lines
drivers/iio/adc/max8907-adc.c new file +13
-0+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 ),0 ,1000 );
0? This makes it a tough loop. Needs a comment why.
Quoted 8 lines
drivers/iio/adc/max8907-adc.c new file +8
-0+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 ); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 4/4 mfd: max8907: Add ADC cell
In reply to Svyatoslav RyhelAdd the ADC cell name to the list of MAX8907 cells.
--- drivers/mfd/max8907.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/max8907.c +1 -0
@@ -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" , },
Signature · 1 line
2.53.0