From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Hugo Villeneuve <hvilleneuve@dimonoff.com>,
Nuno Sa <nuno.sa@analog.com>,
David Lechner <dlechner@baylibre.com>,
Javier Carrasco <javier.carrasco.cruz@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev
Subject: Re: [PATCH v3 9/9] iio: adc: ti-ads7924: Respect device tree config
Date: Sat, 1 Mar 2025 03:06:25 +0000 [thread overview]
Message-ID: <20250301030625.54c43d37@jic23-huawei> (raw)
In-Reply-To: <3279aa9348e7149bfbd433daaa201f2eb5873e1f.1739967040.git.mazziesaccount@gmail.com>
On Wed, 19 Feb 2025 14:32:23 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> The ti-ads7924 driver ignores the device-tree ADC channel specification
> and always exposes all 4 channels to users whether they are present in
> the device-tree or not. Additionally, the "reg" values in the channel
> nodes are ignored, although an error is printed if they are out of range.
>
> Register only the channels described in the device-tree, and use the reg
> property as a channel ID.
No to this one in it's current form. The nodes are just there to provide
the labels. Maybe it is fine if we fallback to registering them all if
none are provided.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
> ---
> Revision history:
> v2 => v3: New patch
>
> Please note that this is potentially breaking existing users if they
> have wrong values in the device-tree. I believe the device-tree should
> ideally be respected, and if it says device X has only one channel, then
> we should believe it and not register 4. Well, we don't live in the
> ideal world, so even though I believe this is TheRightThingToDo - it may
> cause havoc because correct device-tree has not been required from the
> day 1. So, please review and test and apply at your own risk :)
>
> As a side note, this might warrant a fixes tag but the adc-helper -stuff
> is hardly worth to be backported... (And I've already exceeded my time
> budget with this series - hence I'll leave crafting backportable fix to
> TI people ;) )
>
> This has only been compile tested! All testing is highly appreciated.
> ---
> drivers/iio/adc/ti-ads7924.c | 80 +++++++++++++++++-------------------
> 1 file changed, 37 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
> index b1f745f75dbe..a5b8f7c81b8a 100644
> --- a/drivers/iio/adc/ti-ads7924.c
> +++ b/drivers/iio/adc/ti-ads7924.c
> @@ -22,6 +22,7 @@
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
>
> +#include <linux/iio/adc-helpers.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/types.h>
>
> @@ -119,15 +120,12 @@
> #define ADS7924_TOTAL_CONVTIME_US (ADS7924_PWRUPTIME_US + ADS7924_ACQTIME_US + \
> ADS7924_CONVTIME_US)
>
> -#define ADS7924_V_CHAN(_chan, _addr) { \
> - .type = IIO_VOLTAGE, \
> - .indexed = 1, \
> - .channel = _chan, \
> - .address = _addr, \
> - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> - .datasheet_name = "AIN"#_chan, \
> -}
> +static const struct iio_chan_spec ads7924_chan_template = {
> + .type = IIO_VOLTAGE,
> + .indexed = 1,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> +};
>
> struct ads7924_data {
> struct device *dev;
> @@ -182,13 +180,6 @@ static const struct regmap_config ads7924_regmap_config = {
> .writeable_reg = ads7924_is_writeable_reg,
> };
>
> -static const struct iio_chan_spec ads7924_channels[] = {
> - ADS7924_V_CHAN(0, ADS7924_DATA0_U_REG),
> - ADS7924_V_CHAN(1, ADS7924_DATA1_U_REG),
> - ADS7924_V_CHAN(2, ADS7924_DATA2_U_REG),
> - ADS7924_V_CHAN(3, ADS7924_DATA3_U_REG),
> -};
> -
> static int ads7924_get_adc_result(struct ads7924_data *data,
> struct iio_chan_spec const *chan, int *val)
> {
> @@ -251,32 +242,38 @@ static const struct iio_info ads7924_info = {
> .read_raw = ads7924_read_raw,
> };
>
> -static int ads7924_get_channels_config(struct device *dev)
> +static const struct iio_adc_props ads7924_chan_props = {
> + .required = IIO_ADC_CHAN_PROP_TYPE_REG,
> +};
> +
> +static int ads7924_get_channels_config(struct iio_dev *indio_dev,
> + struct device *dev)
> {
> - struct fwnode_handle *node;
> - int num_channels = 0;
> + struct iio_chan_spec *chan_array;
> + int num_channels = 0, i;
>
> - device_for_each_child_node(dev, node) {
> - u32 pval;
> - unsigned int channel;
> + num_channels = devm_iio_adc_device_alloc_chaninfo(dev,
> + &ads7924_chan_template, &chan_array,
> + &ads7924_chan_props);
>
> - if (fwnode_property_read_u32(node, "reg", &pval)) {
> - dev_err(dev, "invalid reg on %pfw\n", node);
> - continue;
> - }
> + if (num_channels < 0)
> + return num_channels;
>
> - channel = pval;
> - if (channel >= ADS7924_CHANNELS) {
> - dev_err(dev, "invalid channel index %d on %pfw\n",
> - channel, node);
> - continue;
> - }
> + if (!num_channels)
> + return -EINVAL;
> +
> + for (i = 0; i < num_channels; i++) {
> + static const char * const datasheet_names[] = {
> + "AIN0", "AIN1", "AIN2", "AIN3"
> + };
> + int ch_id = chan_array[i].channel;
>
> - num_channels++;
> + chan_array[i].address = ADS7924_DATA0_U_REG + ch_id;
> + chan_array[i].datasheet_name = datasheet_names[ch_id];
> }
>
> - if (!num_channels)
> - return -EINVAL;
> + indio_dev->channels = chan_array;
> + indio_dev->num_channels = num_channels;
>
> return 0;
> }
> @@ -370,18 +367,15 @@ static int ads7924_probe(struct i2c_client *client)
>
> mutex_init(&data->lock);
>
> - indio_dev->name = "ads7924";
> - indio_dev->modes = INDIO_DIRECT_MODE;
> -
> - indio_dev->channels = ads7924_channels;
> - indio_dev->num_channels = ARRAY_SIZE(ads7924_channels);
> - indio_dev->info = &ads7924_info;
> -
> - ret = ads7924_get_channels_config(dev);
> + ret = ads7924_get_channels_config(indio_dev, dev);
> if (ret < 0)
> return dev_err_probe(dev, ret,
> "failed to get channels configuration\n");
>
> + indio_dev->name = "ads7924";
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->info = &ads7924_info;
> +
> data->regmap = devm_regmap_init_i2c(client, &ads7924_regmap_config);
> if (IS_ERR(data->regmap))
> return dev_err_probe(dev, PTR_ERR(data->regmap),
prev parent reply other threads:[~2025-03-01 3:06 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 12:29 [PATCH v3 0/9] Support ROHM BD79124 ADC Matti Vaittinen
2025-02-19 12:30 ` [PATCH v3 1/9] dt-bindings: ROHM BD79124 ADC/GPO Matti Vaittinen
2025-02-19 12:30 ` [PATCH v3 2/9] iio: adc: add helpers for parsing ADC nodes Matti Vaittinen
2025-02-19 20:41 ` Andy Shevchenko
2025-02-20 7:13 ` Matti Vaittinen
2025-02-20 12:41 ` Andy Shevchenko
2025-02-20 13:40 ` Matti Vaittinen
2025-02-20 14:04 ` Andy Shevchenko
2025-02-20 14:21 ` Matti Vaittinen
2025-02-20 14:56 ` Andy Shevchenko
2025-02-21 10:10 ` Matti Vaittinen
2025-02-21 16:41 ` Andy Shevchenko
2025-02-22 14:34 ` Matti Vaittinen
2025-02-22 17:48 ` Jonathan Cameron
2025-02-23 16:13 ` Jonathan Cameron
2025-02-24 13:45 ` Matti Vaittinen
2025-02-19 12:30 ` [PATCH v3 3/9] iio: adc: Support ROHM BD79124 ADC Matti Vaittinen
2025-02-23 16:28 ` Jonathan Cameron
2025-02-24 6:14 ` Matti Vaittinen
2025-03-02 2:44 ` Jonathan Cameron
2025-02-19 12:30 ` [PATCH v3 4/9] MAINTAINERS: Add IIO ADC helpers Matti Vaittinen
2025-02-19 12:31 ` [PATCH v3 5/9] MAINTAINERS: Add ROHM BD79124 ADC/GPO Matti Vaittinen
2025-02-19 12:31 ` [PATCH v3 6/9] iio: adc: rzg2l_adc: Use adc-helpers Matti Vaittinen
2025-02-19 13:36 ` Matti Vaittinen
2025-02-20 16:07 ` kernel test robot
2025-02-23 16:30 ` Jonathan Cameron
2025-02-24 5:40 ` Matti Vaittinen
2025-02-19 12:31 ` [PATCH v3 7/9] iio: adc: sun20i-gpadc: " Matti Vaittinen
2025-02-20 16:17 ` kernel test robot
2025-02-19 12:32 ` [PATCH v3 8/9] iio: adc: ti-ads7924 Drop unnecessary function parameters Matti Vaittinen
2025-02-19 12:32 ` [PATCH v3 9/9] iio: adc: ti-ads7924: Respect device tree config Matti Vaittinen
2025-03-01 3:06 ` Jonathan Cameron [this message]
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=20250301030625.54c43d37@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=hvilleneuve@dimonoff.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=wens@csie.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