All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cosmo Chou <chou.cosmo@gmail.com>
To: andrew@codeconstruct.com.au, openbmc@lists.ozlabs.org
Cc: chou.cosmo@gmail.com, cosmo.chou@quantatw.com,
	Billy Tsai <billy_tsai@aspeedtech.com>
Subject: [PATCH linux dev-6.18 2/4] iio: adc: Enable multiple consecutive channels based on model data
Date: Wed,  5 Aug 2026 14:13:07 +0800	[thread overview]
Message-ID: <20260805061310.1740724-3-chou.cosmo@gmail.com> (raw)
In-Reply-To: <20260805061310.1740724-1-chou.cosmo@gmail.com>

From: Billy Tsai <billy_tsai@aspeedtech.com>

Add helpers to generate channel masks and enable multiple ADC channels
according to the device model's channel count.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/aspeed_adc.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c
index 8eebaa3dc534..3ff24474f394 100644
--- a/drivers/iio/adc/aspeed_adc.c
+++ b/drivers/iio/adc/aspeed_adc.c
@@ -123,6 +123,24 @@ struct aspeed_adc_data {
 	struct adc_gain		battery_mode_gain;
 };
 
+/*
+ * 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 > 16)
+		return GENMASK(15, 0);
+
+	return BIT(num_channels) - 1;
+}
+
+static inline unsigned int aspeed_adc_get_active_channels(const struct aspeed_adc_data *data)
+{
+	return data->model_data->num_channels;
+}
+
 #define ASPEED_CHAN(_idx, _data_reg_addr) {			\
 	.type = IIO_VOLTAGE,					\
 	.indexed = 1,						\
@@ -617,7 +635,9 @@ static int aspeed_adc_probe(struct platform_device *pdev)
 	/* 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;
+	FIELD_MODIFY(ASPEED_ADC_CTRL_CHANNEL, &adc_engine_control_reg_val,
+		     aspeed_adc_channels_mask(aspeed_adc_get_active_channels(data)));
+
 	writel(adc_engine_control_reg_val,
 	       data->base + ASPEED_REG_ENGINE_CONTROL);
 
-- 
2.53.0



  parent reply	other threads:[~2026-08-05  6:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  6:13 [PATCH linux dev-6.18 0/4] iio: adc: aspeed: Backport battery sensing patches Cosmo Chou
2026-08-05  6:13 ` [PATCH linux dev-6.18 1/4] iio: adc: Add battery channel definition for ADC Cosmo Chou
2026-08-05  6:13 ` Cosmo Chou [this message]
2026-08-05  6:13 ` [PATCH linux dev-6.18 3/4] iio: adc: aspeed: Replace mdelay() with fsleep() for ADC stabilization delay Cosmo Chou
2026-08-05  6:13 ` [PATCH linux dev-6.18 4/4] iio: adc: aspeed: Reserve battery sensing channel for on-demand use Cosmo Chou

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=20260805061310.1740724-3-chou.cosmo@gmail.com \
    --to=chou.cosmo@gmail.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=billy_tsai@aspeedtech.com \
    --cc=cosmo.chou@quantatw.com \
    --cc=openbmc@lists.ozlabs.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.