From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Billy Tsai <billy_tsai@aspeedtech.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Joel Stanley" <joel@jms.id.au>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org,
morris_mao@aspeedtech.com
Subject: Re: [PATCH v2 2/3] iio: adc: Enable multiple consecutive channels based on model data
Date: Mon, 16 Mar 2026 16:25:26 +0200 [thread overview]
Message-ID: <abgS1lOoEO1RTe9X@ashevche-desk.local> (raw)
In-Reply-To: <20260316-adc-v2-2-21475a217b09@aspeedtech.com>
On Mon, Mar 16, 2026 at 11:00:47AM +0800, Billy Tsai wrote:
> Add helpers to generate channel masks and enable multiple ADC channels
> according to the device model's channel count.
...
> +
(1)
> +/*
> + * Enable multiple consecutive channels starting from channel 0.
> + * This creates a bitmask for channels 0 to (num_channels - 1).
> + * For example: num_channels=3 creates mask 0x0007 (channels 0,1,2)
> + */
> +static inline u32 aspeed_adc_channels_mask(unsigned int num_channels)
> +{
> + if (num_channels == 0)
> + return 0;
> + if (num_channels >= 16)
> + return GENMASK(15, 0);
> + return GENMASK(num_channels - 1, 0);
This entire function can be folded into
return BIT(min(num_channels, 16U)) - 1;
Or
if (num_channels > 16)
return GENMASK(15, 0);
return BIT(num_channels) - 1;
> +}
> +/*
> + * Helper function to enable multiple channels in the control register
> + */
> +static inline u32 aspeed_adc_enable_channels(unsigned int num_channels)
> +{
> + return FIELD_PREP(ASPEED_ADC_CTRL_CHANNEL, aspeed_adc_channels_mask(num_channels));
> +}
> +
One of these (see 1 above) new blank lines should be rather added in the previous patch.
> /* Battery sensing is typically on the last channel */
> #define ASPEED_ADC_BATTERY_CHANNEL 7
...
> /* Start all channels in normal mode. */
> - adc_engine_control_reg_val =
> - readl(data->base + ASPEED_REG_ENGINE_CONTROL);
> - adc_engine_control_reg_val |= ASPEED_ADC_CTRL_CHANNEL;
> + adc_engine_control_reg_val = readl(data->base + ASPEED_REG_ENGINE_CONTROL);
> + adc_engine_control_reg_val |=
> + aspeed_adc_enable_channels(aspeed_adc_get_active_channels(data));
Why not FIELD_MODIFY()?
> writel(adc_engine_control_reg_val,
> data->base + ASPEED_REG_ENGINE_CONTROL);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-03-16 14:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 3:00 [PATCH v2 0/3] iio: adc: aspeed: Reserve battery sensing channel for on-demand use Billy Tsai
2026-03-16 3:00 ` [PATCH v2 1/3] iio: adc: Add battery channel definition for ADC Billy Tsai
2026-03-16 3:00 ` [PATCH v2 2/3] iio: adc: Enable multiple consecutive channels based on model data Billy Tsai
2026-03-16 14:25 ` Andy Shevchenko [this message]
2026-03-20 3:33 ` Billy Tsai
2026-03-16 3:00 ` [PATCH v2 3/3] iio: adc: aspeed: Reserve battery sensing channel for on-demand use Billy Tsai
2026-03-16 14:26 ` Andy Shevchenko
2026-03-20 3:41 ` Billy Tsai
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=abgS1lOoEO1RTe9X@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andrew@codeconstruct.com.au \
--cc=andy@kernel.org \
--cc=billy_tsai@aspeedtech.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=joel@jms.id.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=morris_mao@aspeedtech.com \
--cc=nuno.sa@analog.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