All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	"Andy Shevchenko" <andy@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"David Jander" <david@protonic.nl>
Subject: Re: [PATCH v2 7/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits
Date: Tue, 27 Jan 2026 12:46:13 +0200	[thread overview]
Message-ID: <aXiXdVg6WuyiwBWa@smile.fi.intel.com> (raw)
In-Reply-To: <20260127060939.3914006-8-o.rempel@pengutronix.de>

On Tue, Jan 27, 2026 at 07:09:38AM +0100, Oleksij Rempel wrote:
> Parse optional maxim,rfs-ohms values to derive the per-channel output
> current scale (mA per step) for the IIO current ABI.
> 
> Select per-variant parameters to match the shared register map while
> handling different data widths and full-scale current calculations.
> 
> Behavior changes:
> - If maxim,rfs-ohms is present, IIO_CHAN_INFO_SCALE becomes available
>   and reports mA/step derived from Rfs.
> - If maxim,rfs-ohms is missing, SCALE is not exposed to keep older DTs
>   working without requiring updates.
> - RAW writes are now limited to the representable sign-magnitude range
>   of the detected variant to avoid silent truncation (e.g. +/-31 on
>   DS440x).

...

> +struct ds4424_chip_info {
> +	int vref_mv;

_mV ?

> +	int scale_denom;
> +	u8 result_mask;
> +};

...

> +static int ds4424_setup_channels(struct i2c_client *client,
> +				 struct ds4424_data *data,
> +				 struct iio_dev *indio_dev)
> +{
> +	struct iio_chan_spec *channels;
> +	size_t channels_size;
> +
> +	channels_size = indio_dev->num_channels * sizeof(ds4424_channels[0]);
> +	/* Use a local non-const pointer for modification */
> +	channels = devm_kmemdup(&client->dev, ds4424_channels, channels_size,
> +				GFP_KERNEL);

Why not devm_kmemdup_array()?

> +	if (!channels)
> +		return -ENOMEM;
> +
> +	if (data->has_rfs) {
> +		for (unsigned int i = 0; i < indio_dev->num_channels; i++)
> +			channels[i].info_mask_separate |=
> +				BIT(IIO_CHAN_INFO_SCALE);
> +	}
> +
> +	indio_dev->channels = channels;
> +
> +	return 0;
> +}

...

> +static int ds4424_parse_rfs(struct i2c_client *client,
> +			    struct ds4424_data *data,
> +			    struct iio_dev *indio_dev)
> +{
> +	struct device *dev = &client->dev;
> +	int count, ret;

Can count be negative?

> +	if (!device_property_present(dev, "maxim,rfs-ohms")) {
> +		dev_info_once(dev, "maxim,rfs-ohms missing, scale not supported\n");
> +		return 0;
> +	}
> +
> +	count = device_property_count_u32(dev, "maxim,rfs-ohms");
> +	if (count != indio_dev->num_channels)
> +		return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms must have %u entries\n",
> +				     indio_dev->num_channels);
> +
> +	ret = device_property_read_u32_array(dev, "maxim,rfs-ohms",
> +					     data->rfs_ohms,
> +					     indio_dev->num_channels);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to read maxim,rfs-ohms property\n");
> +
> +	for (unsigned int i = 0; i < indio_dev->num_channels; i++) {
> +		if (!data->rfs_ohms[i])
> +			return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms entry %d is zero\n",

%u

> +					     i);

I would leave it on the same line.

> +	}
> +
> +	data->has_rfs = true;
> +
> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-01-27 10:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  6:09 [PATCH v2 0/8] iio: dac: ds4424: add DS4402/DS4404 support and scale Oleksij Rempel
2026-01-27  6:09 ` [PATCH v2 1/8] dt-bindings: iio: dac: maxim,ds4424: add ds4402/ds4404 Oleksij Rempel
2026-01-27  6:09 ` [PATCH v2 2/8] dt-bindings: iio: dac: maxim,ds4424: add maxim,rfs-ohms property Oleksij Rempel
2026-01-27 19:49   ` Conor Dooley
2026-01-27 19:55     ` Conor Dooley
2026-01-28  8:01       ` David Jander
2026-01-28 17:00         ` Conor Dooley
2026-01-27  6:09 ` [PATCH v2 3/8] iio: dac: ds4424: add DS4402/DS4404 device IDs Oleksij Rempel
2026-01-27 10:27   ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 4/8] iio: dac: ds4424: sort headers alphabetically Oleksij Rempel
2026-01-27 10:30   ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 5/8] iio: dac: ds4424: convert to regmap Oleksij Rempel
2026-01-27 10:39   ` Andy Shevchenko
2026-02-01 14:42   ` Sander Vanheule
2026-02-01 16:16     ` Oleksij Rempel
2026-02-01 17:24       ` Sander Vanheule
2026-02-03 10:10       ` Andy Shevchenko
2026-02-03 10:13         ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 6/8] iio: dac: ds4424: fix -128 rejection and refactor raw access Oleksij Rempel
2026-01-27 10:42   ` Andy Shevchenko
2026-01-27 10:49     ` Oleksij Rempel
2026-01-27 10:51       ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 7/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits Oleksij Rempel
2026-01-27 10:46   ` Andy Shevchenko [this message]
2026-01-27  6:09 ` [PATCH v2 8/8] iio: dac: ds4424: ratelimit read errors and use device context Oleksij Rempel
2026-01-27 10:47   ` Andy Shevchenko

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=aXiXdVg6WuyiwBWa@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=david@protonic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=o.rempel@pengutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.