Re: [PATCH v2 3/4] iio: adc: Add support for MAX8907 ADC cell
From: Andy Shevchenko
Date: Tue Nov 17 2026 - 02:15:31 EST
On Sun, Nov 15, 2026 at 11:11:19AM +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.
...
> +config MAX8907_ADC
> + tristate "Maxim MAX8907 ADC driver"
Make MODULE_DESCRIPTION() to use the same text.
> + 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.
> +#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.
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
Should be also a group for asm/byteorder.h.
> +#define MAX8907_TO_REG(n) ((n) & 0xff)
> +#define MAX8907_TO_MEASURE(n) (((n) >> 8) & 0xff)
...
> +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.
> +};
...
> +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").
> +};
...
> +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.
> + 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