Skip to contentSkip to conversation

iio: adc: Add support for MAX8907 ADC cell

PATCH In review Svyatoslav Ryhel 2 participants 10 messages Nov 23

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

v3 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

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
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 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
index ee1a305d1c210..ccdeb9ba21e26 100644
@@ -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
#2 lore raw

PATCH v3 2/4 mfd: max8907: Add ADC client support

In reply to Svyatoslav Ryhel

The 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
index b511c57026188..103294c76b97d 100644
@@ -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)
include/linux/mfd/max8907.h +53 -0

82 lines not on this page · raw message

Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH v3 2/4] mfd: max8907: Add ADC client support

Quoted 2 lines · Svyatoslav Ryhel

The 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 static const struct regmap_irq_chip max8907_rtc_irq_chip = { · line 222

Quoted 3 lines
drivers/mfd/max8907.c +3 -0
+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.

Quoted 1 line

+};

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v3 2/4] mfd: max8907: Add ADC client support

пн, 23 лист. 2026 р. о 20:54 Andy Shevchenko <[email protected]> пише:

Quoted 11 lines · Svyatoslav Ryhel
Quoted 2 lines

The 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 static const struct regmap_irq_chip max8907_rtc_irq_chip = { · line 222

Quoted 3 lines
drivers/mfd/max8907.c +3 -0
+static const struct regmap_irq max8907_adc_irqs[] = {
+     { .reg_offset = 0, .mask = BIT(0), },
+     { .reg_offset = 0, .mask = BIT(1), },
Quoted 6 lines

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.

Quoted 7 lines
Quoted 1 line

+};

--
With Best Regards,
Andy Shevchenko

#5 lore raw

PATCH v3 3/4 iio: adc: Add support for MAX8907 ADC cell

In reply to 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       |  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
drivers/iio/adc/Kconfig +10 -0
index 1d6ed49041ab5..a5d0f8727af70 100644
@@ -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
drivers/iio/adc/Makefile +1 -0
index 769965295dccb..af89115978316 100644
@@ -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
drivers/iio/adc/max8907-adc.c new file +181 -0

181 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw
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/max8907-adc.c line 51

Quoted 9 lines
drivers/iio/adc/max8907-adc.c new file +9 -0
+#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.

Quoted 8 lines
drivers/iio/adc/max8907-adc.c new file +8 -0
+	.scan_type = {						\
+		.format = IIO_SCAN_FORMAT_UNSIGNED_INT,		\
+		.realbits = 12,					\
+		.storagebits = 16,				\
+		.endianness = IIO_CPU,				\
+	},							\
+	.datasheet_name = (_datasheet_name),			\
+}

...

drivers/iio/adc/max8907-adc.c line 76

Quoted 5 lines
drivers/iio/adc/max8907-adc.c new file +5 -0
+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;

drivers/iio/adc/max8907-adc.c line 86

Quoted 10 lines
drivers/iio/adc/max8907-adc.c new file +10 -0
+	__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));
Quoted 17 lines
drivers/iio/adc/max8907-adc.c new file +17 -0
+		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;
+	}
+}

...

Quoted 1 line

+static int max8907_adc_init(struct regmap *regmap)

Why not name it 'map'?

drivers/iio/adc/max8907-adc.c line 115

Quoted 6 lines
drivers/iio/adc/max8907-adc.c new file +6 -0
+{
+	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));

drivers/iio/adc/max8907-adc.c line 119

Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +4 -0
+	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).

drivers/iio/adc/max8907-adc.c line 121

Quoted 2 lines
drivers/iio/adc/max8907-adc.c new file +2 -0
+	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);
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
#7 lore raw

пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <[email protected]> пише:

Quoted 18 lines · Svyatoslav Ryhel
Quoted 3 lines

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/max8907-adc.c line 51

Quoted 9 lines
drivers/iio/adc/max8907-adc.c new file +9 -0
+#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),                                \
Quoted 5 lines

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.

Quoted 19 lines
Quoted 8 lines
drivers/iio/adc/max8907-adc.c new file +8 -0
+     .scan_type = {                                          \
+             .format = IIO_SCAN_FORMAT_UNSIGNED_INT,         \
+             .realbits = 12,                                 \
+             .storagebits = 16,                              \
+             .endianness = IIO_CPU,                          \
+     },                                                      \
+     .datasheet_name = (_datasheet_name),                    \
+}

...

drivers/iio/adc/max8907-adc.c line 76

Quoted 5 lines
drivers/iio/adc/max8907-adc.c new file +5 -0
+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

Quoted 2 lines
        struct regmap *map = *regmap;

This is matter of taste, I was inspired by MAX77541 ADC which uses exactly this approach.

Quoted 4 lines
Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +4 -0
+     __be16 data;
+     int ret;
+
+     switch (mask) {
Quoted 9 lines

drivers/iio/adc/max8907-adc.c line 86

Quoted 6 lines
drivers/iio/adc/max8907-adc.c new file +6 -0
+     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?

Quoted 23 lines
                ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
                                       &data, sizeof(data));
Quoted 17 lines
drivers/iio/adc/max8907-adc.c new file +17 -0
+             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;
+     }
+}

...

Quoted 4 lines
Quoted 1 line

+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.

Quoted 9 lines

drivers/iio/adc/max8907-adc.c line 115

Quoted 6 lines
drivers/iio/adc/max8907-adc.c new file +6 -0
+{
+     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?

Quoted 8 lines

drivers/iio/adc/max8907-adc.c line 119

Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +4 -0
+     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?

Quoted 7 lines

drivers/iio/adc/max8907-adc.c line 121

Quoted 2 lines
drivers/iio/adc/max8907-adc.c new file +2 -0
+     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.

Quoted 4 lines
Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +4 -0
+     if (ret)
+             return ret;
+
+     return regmap_update_bits(regmap, MAX8907_REG_ADC_SCHED,
Quoted 9 lines

drivers/iio/adc/max8907-adc.c line 129

Quoted 4 lines
drivers/iio/adc/max8907-adc.c new file +4 -0
+                               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.

#8 lore raw
Quoted 2 lines · Svyatoslav Ryhel

пн, 23 лист. 2026 р. о 21:01 Andy Shevchenko <[email protected]> пише:

Quoted 1 line · Svyatoslav Ryhel

...

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/iio/adc/max8907-adc.c new file +9 -0
+#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),                                \
Quoted 6 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/iio/adc/max8907-adc.c new file +8 -0
+     .scan_type = {                                          \
+             .format = IIO_SCAN_FORMAT_UNSIGNED_INT,         \
+             .realbits = 12,                                 \
+             .storagebits = 16,                              \
+             .endianness = IIO_CPU,                          \
+     },                                                      \
+     .datasheet_name = (_datasheet_name),                    \
+}

...

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+ 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.

...

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+ 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.

Quoted 2 lines
Quoted 2 lines
                ret = regmap_bulk_read(map, MAX8907_TO_REG(chan->address),
                                       &data, sizeof(data));

...

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+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 :-)

...

Quoted 3 lines
Quoted 1 line
        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.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+     if (ret)
+             return ret;

...

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+ /* 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.

...

Quoted 11 lines
Quoted 7 lines

drivers/iio/adc/max8907-adc.c line 121

Quoted 2 lines
drivers/iio/adc/max8907-adc.c new file +2 -0
+     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.

...

Quoted 1 line

I would like to hear what Jonathan has to say.

OK.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

PATCH v3 4/4 mfd: max8907: Add ADC cell

In reply to Svyatoslav Ryhel

Add 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
index 103294c76b97d..ac7b41ad400ed 100644
@@ -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