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>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@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>,
Guillaume Stols <gstols@baylibre.com>,
Olivier Moysan <olivier.moysan@foss.st.com>,
Dumitru Ceclan <mitrutzceclan@gmail.com>,
Trevor Gamblin <tgamblin@baylibre.com>,
Matteo Martelli <matteomartelli3@gmail.com>,
Alisa-Dariana Roman <alisadariana@gmail.com>,
Ramona Alexandra Nechita <ramona.nechita@analog.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-renesas-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev
Subject: Re: [PATCH v4 04/10] iio: adc: rzg2l_adc: Use adc-helpers
Date: Sun, 2 Mar 2025 03:40:42 +0000 [thread overview]
Message-ID: <20250302034042.59d83f53@jic23-huawei> (raw)
In-Reply-To: <5658fbdd886cc7ada278a42c63a140bc14d1277d.1740421248.git.mazziesaccount@gmail.com>
On Mon, 24 Feb 2025 20:33:29 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> The new devm_iio_adc_device_alloc_chaninfo() -helper is intended to help
> drivers avoid open-coding the for_each_node -loop for getting the
> channel IDs. The helper provides standard way to detect the ADC channel
> nodes (by the node name), and a standard way to convert the "reg",
> "diff-channels", "single-channel" and the "common-mode-channel" to
> channel identification numbers used in the struct iio_chan_spec.
Needs an update to reflecting naming and functionality simplifications.
> Furthermore, the helper checks the ID is in range of 0 ... num-channels.
>
> The original driver treated all found child nodes as channel nodes. The
> new helper requires channel nodes to be named channel[@N]. This should
> help avoid problems with devices which may contain also other but ADC
> child nodes. Quick grep from arch/* with the rzg2l_adc's compatible
> string didn't reveal any in-tree .dts with channel nodes named
> othervice. Also, same grep shows all the .dts seem to have channel IDs
otherwise
(othervice does sound cool though ;)
> between 0..num of channels.
>
> Use the new helper.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
> ---
> Revision history:
> v3 => v4:
> - Adapt to 'drop diff-channel support' changes to ADC-helpers
> - select ADC helpers in the Kconfig
> - Rebased to 6.14-rc3 => channel type can no longer come from the
> template.
>
> v2 => v3:
> - New patch
>
> I picked the rzg2l_adc in this series because it has a straightforward
> approach for populating the struct iio_chan_spec. Only other member
> in the stuct besides the .channel, which can't use a 'template' -data,
> is the .datasheet_name. This makes the rzg2l_adc well suited for example
> user of this new helper. I hope this patch helps to evaluate whether these
> helpers are worth the hassle.
This doesn't seem to match driver. It is messing with channel type.
>
> The change is compile tested only!! Testing before applying is highly
> appreciated (as always!).
> ---
> drivers/iio/adc/Kconfig | 1 +
> drivers/iio/adc/rzg2l_adc.c | 38 +++++++++++++++++--------------------
> 2 files changed, 18 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 37b70a65da6f..e4933de0c366 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -1222,6 +1222,7 @@ config RICHTEK_RTQ6056
> config RZG2L_ADC
> tristate "Renesas RZ/G2L ADC driver"
> depends on ARCH_RZG2L || COMPILE_TEST
> + select IIO_ADC_HELPER
> help
> Say yes here to build support for the ADC found in Renesas
> RZ/G2L family.
> diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
> index 883c167c0670..51c87b1bdc98 100644
> --- a/drivers/iio/adc/rzg2l_adc.c
> +++ b/drivers/iio/adc/rzg2l_adc.c
> @@ -11,6 +11,7 @@
> #include <linux/cleanup.h>
> #include <linux/completion.h>
> #include <linux/delay.h>
> +#include <linux/iio/adc-helpers.h>
> #include <linux/iio/iio.h>
> #include <linux/interrupt.h>
> #include <linux/io.h>
> @@ -324,21 +325,30 @@ static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +static const struct iio_chan_spec rzg2l_adc_chan_template = {
> + .indexed = 1,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +};
> +
> static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc)
> {
> const struct rzg2l_adc_hw_params *hw_params = adc->hw_params;
> struct iio_chan_spec *chan_array;
> struct rzg2l_adc_data *data;
> - unsigned int channel;
> int num_channels;
> - int ret;
> u8 i;
>
> data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> - num_channels = device_get_child_node_count(&pdev->dev);
> + num_channels = devm_iio_adc_device_alloc_chaninfo_se(&pdev->dev,
> + &rzg2l_adc_chan_template,
> + hw_params->num_channels - 1,
> + &chan_array);
> + if (num_channels < 0)
> + return num_channels;
> +
> if (!num_channels)
> return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n");
>
> @@ -346,26 +356,11 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l
> return dev_err_probe(&pdev->dev, -EINVAL,
> "num of channel children out of range\n");
>
> - chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array),
> - GFP_KERNEL);
> - if (!chan_array)
> - return -ENOMEM;
> -
> - i = 0;
> - device_for_each_child_node_scoped(&pdev->dev, fwnode) {
> - ret = fwnode_property_read_u32(fwnode, "reg", &channel);
> - if (ret)
> - return ret;
> -
> - if (channel >= hw_params->num_channels)
> - return -EINVAL;
> + for (i = 0; i < num_channels; i++) {
> + int channel = chan_array[i].channel;
>
> - chan_array[i].type = rzg2l_adc_channels[channel].type;
> - chan_array[i].indexed = 1;
> - chan_array[i].channel = channel;
> - chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
> chan_array[i].datasheet_name = rzg2l_adc_channels[channel].name;
> - i++;
> + chan_array[i].type = rzg2l_adc_channels[channel].type;
> }
>
> data->num_channels = num_channels;
> @@ -626,3 +621,4 @@ module_platform_driver(rzg2l_adc_driver);
> MODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>");
> MODULE_DESCRIPTION("Renesas RZ/G2L ADC driver");
> MODULE_LICENSE("GPL v2");
> +MODULE_IMPORT_NS("IIO_DRIVER");
next prev parent reply other threads:[~2025-03-02 3:42 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 18:32 [PATCH v4 00/10] Support ROHM BD79124 ADC Matti Vaittinen
2025-02-24 18:32 ` [PATCH v4 01/10] dt-bindings: ROHM BD79124 ADC/GPO Matti Vaittinen
2025-02-24 18:32 ` [PATCH v4 02/10] property: Add device_get_child_node_count_named() Matti Vaittinen
2025-02-25 9:40 ` Heikki Krogerus
2025-02-25 10:07 ` Matti Vaittinen
2025-02-25 10:21 ` Andy Shevchenko
2025-02-25 10:29 ` Matti Vaittinen
2025-02-25 10:39 ` Andy Shevchenko
2025-02-25 10:52 ` Matti Vaittinen
2025-02-25 13:29 ` Matti Vaittinen
2025-02-25 13:59 ` Andy Shevchenko
2025-02-26 14:04 ` Matti Vaittinen
2025-02-26 14:11 ` Andy Shevchenko
2025-02-27 8:01 ` Matti Vaittinen
2025-02-27 14:49 ` Andy Shevchenko
2025-02-27 15:05 ` Matti Vaittinen
2025-02-28 16:59 ` Rob Herring
2025-03-02 12:21 ` Matti Vaittinen
2025-02-25 10:56 ` Matti Vaittinen
2025-02-28 17:07 ` Rob Herring
2025-02-28 18:51 ` Andy Shevchenko
2025-03-02 12:22 ` Matti Vaittinen
2025-02-24 18:33 ` [PATCH v4 03/10] iio: adc: add helpers for parsing ADC nodes Matti Vaittinen
2025-02-26 0:26 ` David Lechner
2025-02-26 6:28 ` Matti Vaittinen
2025-02-26 16:10 ` David Lechner
2025-02-27 7:46 ` Matti Vaittinen
2025-03-02 3:20 ` Jonathan Cameron
2025-03-02 12:54 ` Matti Vaittinen
2025-03-04 23:59 ` Jonathan Cameron
2025-03-02 3:35 ` Jonathan Cameron
2025-03-02 13:00 ` Matti Vaittinen
2025-03-02 3:48 ` Jonathan Cameron
2025-03-02 13:01 ` Matti Vaittinen
2025-02-24 18:33 ` [PATCH v4 04/10] iio: adc: rzg2l_adc: Use adc-helpers Matti Vaittinen
2025-03-02 3:40 ` Jonathan Cameron [this message]
2025-03-02 13:06 ` Matti Vaittinen
2025-02-24 18:33 ` [PATCH v4 05/10] iio: adc: sun20i-gpadc: " Matti Vaittinen
2025-03-02 3:42 ` Jonathan Cameron
2025-02-24 18:34 ` [PATCH v4 06/10] iio: adc: ti-ads7924 Drop unnecessary function parameters Matti Vaittinen
2025-03-02 3:46 ` Jonathan Cameron
2025-03-03 7:33 ` Matti Vaittinen
2025-02-24 18:34 ` [PATCH v4 07/10] iio: adc: ti-ads7924: Respect device tree config Matti Vaittinen
2025-02-26 0:09 ` David Lechner
2025-02-26 6:39 ` Matti Vaittinen
2025-03-02 3:27 ` Jonathan Cameron
2025-03-02 13:10 ` Matti Vaittinen
2025-03-03 14:57 ` Hugo Villeneuve
2025-02-24 18:34 ` [PATCH v4 08/10] iio: adc: Support ROHM BD79124 ADC Matti Vaittinen
2025-03-02 4:10 ` Jonathan Cameron
2025-03-02 13:15 ` Matti Vaittinen
2025-02-24 18:34 ` [PATCH v4 09/10] MAINTAINERS: Add IIO ADC helpers Matti Vaittinen
2025-02-24 18:34 ` [PATCH v4 10/10] MAINTAINERS: Add ROHM BD79124 ADC/GPO Matti Vaittinen
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=20250302034042.59d83f53@jic23-huawei \
--to=jic23@kernel.org \
--cc=alisadariana@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djrscally@gmail.com \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=gstols@baylibre.com \
--cc=heikki.krogerus@linux.intel.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-acpi@vger.kernel.org \
--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=matteomartelli3@gmail.com \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
--cc=mitrutzceclan@gmail.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=rafael@kernel.org \
--cc=ramona.nechita@analog.com \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=samuel@sholland.org \
--cc=tgamblin@baylibre.com \
--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