Devicetree
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Svyatoslav Ryhel <clamor95@gmail.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-iio@vger.kernel.org, mfd@lists.linux.dev
Subject: Re: [PATCH v3 3/4] iio: adc: Add support for MAX8907 ADC cell
Date: Mon, 23 Nov 2026 21:01:07 +0200	[thread overview]
Message-ID: <awSNc2piI26LgyAU@ashevche-desk.local> (raw)
In-Reply-To: <20261123150725.212836-4-clamor95@gmail.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.

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



  reply	other threads:[~2026-11-23 19:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awSNc2piI26LgyAU@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox