From: Jonathan Cameron <jic23@kernel.org>
To: Dileep Kumar Nagavarapu <dileepkumar.nagavarapu@amd.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Michal Simek" <michal.simek@amd.com>,
"Conall O'Griofa" <conall.ogriofa@amd.com>,
linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, git@amd.com,
"Sai Krishna Potthuri" <sai.krishna.potthuri@amd.com>
Subject: Re: [PATCH v4 12/15] iio: adc: xilinx-xadc: Add helper functions for the device setup
Date: Mon, 19 Oct 2026 00:21:49 +0100 [thread overview]
Message-ID: <20261019002149.7f90c78f@jic23-hlaptop> (raw)
In-Reply-To: <20261005094205.1045874-13-dileepkumar.nagavarapu@amd.com>
On Mon, 5 Oct 2026 15:12:02 +0530
Dileep Kumar Nagavarapu <dileepkumar.nagavarapu@amd.com> wrote:
> Refactor the platform driver probe function by extracting device
> setup and configuration logic into reusable helper functions:
> xadc_device_setup(): handles IIO device allocation and basic setup
> xadc_device_configure(): handles device tree parsing and bipolar mask
> configuration
>
> Move the bipolar channel mask calculation immediately after
> xadc_parse_dt(), as the channel information used to build
> the mask is populated there and remains unchanged before it is consumed.
>
> This refactoring reduces code duplication and prepares for sharing the
> common setup logic between platform and I2C drivers.
>
> Co-developed-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> Signed-off-by: Dileep Kumar Nagavarapu <dileepkumar.nagavarapu@amd.com>
> ---
> drivers/iio/adc/xilinx-xadc-core.c | 105 +++++++++++++++++++----------
> 1 file changed, 71 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
> index 92cd38cd1834..d95a84e7e561 100644
> --- a/drivers/iio/adc/xilinx-xadc-core.c
> +++ b/drivers/iio/adc/xilinx-xadc-core.c
> @@ -933,6 +933,33 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
> }
> }
>
> +static int xadc_setup_buffer_and_triggers(struct iio_dev *indio_dev, int irq)
> +{
> + struct device *dev = indio_dev->dev.parent;
> + struct xadc *xadc = iio_priv(indio_dev);
> + int ret;
> +
> + if (!(xadc->ops->flags & XADC_FLAGS_BUFFERED))
> + return 0;
> +
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, &iio_pollfunc_store_time,
> + &xadc_trigger_handler, &xadc_buffer_ops);
> + if (ret)
> + return ret;
> +
> + if (irq > 0) {
Unless it gets modified in later patches, flip this to reduce indent a bit + early exit
in the simple case of no irq.
if (irq <= 0)
return 0;
xadc->convst_...
> + xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst");
> + if (IS_ERR(xadc->convst_trigger))
> + return PTR_ERR(xadc->convst_trigger);
> +
> + xadc->samplerate_trigger = xadc_alloc_trigger(indio_dev, "samplerate");
> + if (IS_ERR(xadc->samplerate_trigger))
> + return PTR_ERR(xadc->samplerate_trigger);
> + }
> +
> + return 0;
> +}
> +static struct iio_dev *xadc_device_setup(struct device *dev, int size, const struct xadc_ops **ops)
> +{
> + struct iio_dev *indio_dev;
> +
> + *ops = device_get_match_data(dev);
> + if (!*ops)
> + return ERR_PTR(-ENODEV);
Having this in here seems more complex to me than moving it
to the caller and passing (*ops)->type in as a parameter
for this function.
Whilst I appreciate the aim of reducing repetition, I'm not
totally convinced this helper has the right balance of
saving code to readability.
> +
> + indio_dev = devm_iio_device_alloc(dev, size);
> + if (!indio_dev)
> + return ERR_PTR(-ENOMEM);
> +
> + indio_dev->name = xadc_type_names[(*ops)->type];
> + indio_dev->info = &xadc_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> +
> + return indio_dev;
> +}
>
next prev parent reply other threads:[~2026-10-18 23:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 9:41 [PATCH v4 00/15] iio: adc: xilinx-xadc: Add I2C interface support for System Management Wizard Dileep Kumar Nagavarapu
2026-10-05 9:41 ` [PATCH v4 01/15] iio: adc: xilinx-xadc: Correct write edge in CFG Dileep Kumar Nagavarapu
2026-10-05 9:41 ` [PATCH v4 02/15] iio: adc: xilinx-xadc: Fix coding style issues Dileep Kumar Nagavarapu
2026-10-05 9:41 ` [PATCH v4 03/15] iio: adc: xilinx-xadc: Use kernel integer types Dileep Kumar Nagavarapu
2026-10-05 9:41 ` [PATCH v4 04/15] iio: adc: xilinx-xadc: Drop unnecessary masking and dead code Dileep Kumar Nagavarapu
2026-10-18 23:05 ` Jonathan Cameron
2026-10-05 9:41 ` [PATCH v4 05/15] iio: adc: xilinx-xadc: Use bitfield helpers and bit macros Dileep Kumar Nagavarapu
2026-10-18 23:11 ` Jonathan Cameron
2026-10-05 9:41 ` [PATCH v4 06/15] iio: adc: xilinx-xadc: Use guard()/scoped_guard() for spinlock locking Dileep Kumar Nagavarapu
2026-10-05 13:13 ` Joshua Crofts
2026-10-18 22:58 ` Jonathan Cameron
2026-10-05 9:41 ` [PATCH v4 07/15] iio: adc: xilinx-xadc: Simplify common coding patterns Dileep Kumar Nagavarapu
2026-10-18 23:14 ` Jonathan Cameron
2026-10-05 9:41 ` [PATCH v4 08/15] iio: adc: xilinx-xadc: Add unit suffixes to macro names Dileep Kumar Nagavarapu
2026-10-05 9:41 ` [PATCH v4 09/15] iio: adc: xilinx-xadc: Drop unused header files Dileep Kumar Nagavarapu
2026-10-05 12:56 ` Joshua Crofts
2026-10-18 23:15 ` Jonathan Cameron
2026-10-05 9:42 ` [PATCH v4 10/15] iio: adc: xilinx-xadc: Add clarifying comments Dileep Kumar Nagavarapu
2026-10-05 13:09 ` Joshua Crofts
2026-10-05 9:42 ` [PATCH v4 11/15] iio: adc: xilinx-xadc: Refine Zynq read/write error handling on timeout/interrupt Dileep Kumar Nagavarapu
2026-10-05 9:42 ` [PATCH v4 12/15] iio: adc: xilinx-xadc: Add helper functions for the device setup Dileep Kumar Nagavarapu
2026-10-18 23:21 ` Jonathan Cameron [this message]
2026-10-05 9:42 ` [PATCH v4 13/15] iio: adc: xilinx-xadc: Split driver into core and platform files Dileep Kumar Nagavarapu
2026-10-05 9:42 ` [PATCH v4 14/15] iio: adc: xilinx-xadc: Add .setup_channels() to struct xadc_ops Dileep Kumar Nagavarapu
2026-10-05 9:42 ` [PATCH v4 15/15] iio: adc: xilinx-xadc: Add I2C interface support Dileep Kumar Nagavarapu
2026-10-18 23:35 ` Jonathan Cameron
2026-10-05 9:58 ` [PATCH v4 00/15] iio: adc: xilinx-xadc: Add I2C interface support for System Management Wizard Joshua Crofts
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=20261019002149.7f90c78f@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conall.ogriofa@amd.com \
--cc=dileepkumar.nagavarapu@amd.com \
--cc=dlechner@baylibre.com \
--cc=git@amd.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=nuno.sa@analog.com \
--cc=sai.krishna.potthuri@amd.com \
/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