From nobody Tue Apr 7 06:14:32 2026 Received: from TWMBX01.aspeed.com (mail.aspeedtech.com [211.20.114.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10C5131F9B5; Mon, 16 Mar 2026 03:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.20.114.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773630063; cv=none; b=LL/9Hc5QAPtMeldYtsauUxJZAIM2h3fLPkinw9Y56sZxSvrCej/hhhJGUocJOW7DAMAaxBi3fQ93aQkQMASHCMbgZl+hpLYEIG0qmK4QGh4znVJ3v52fgcRRH6JK1H4J8nBkXLopgPbN4o+/TLtbCwdBa+Xc6q5hqf/8S8Q0mi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773630063; c=relaxed/simple; bh=NDFWhGINrDRsy3G0bfBO0q4ZxiMyFTtoWTFlKzGT8bg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Kh1McPR++DruoOf8k6gLAsrUDL46OLKGFl1cmzs55To87/nzoOGH+vNPwWxkA50oCy6uVK6ZBpGxaweehYXaCpwRS0BwNpdGg0uA+ieHzHHTQ5RGCN9vnWLu/eBnMH9j/ktEzMUdAC1YjlVFU2sTAtiUtbXqfFogvfJJDEcDcCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com; spf=pass smtp.mailfrom=aspeedtech.com; arc=none smtp.client-ip=211.20.114.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aspeedtech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aspeedtech.com Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Mon, 16 Mar 2026 11:00:48 +0800 Received: from [127.0.1.1] (192.168.10.13) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server id 15.2.1748.10 via Frontend Transport; Mon, 16 Mar 2026 11:00:48 +0800 From: Billy Tsai Date: Mon, 16 Mar 2026 11:00:48 +0800 Subject: [PATCH v2 3/3] iio: adc: aspeed: Reserve battery sensing channel for on-demand use Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260316-adc-v2-3-21475a217b09@aspeedtech.com> References: <20260316-adc-v2-0-21475a217b09@aspeedtech.com> In-Reply-To: <20260316-adc-v2-0-21475a217b09@aspeedtech.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , "Andy Shevchenko" , Joel Stanley , Andrew Jeffery CC: , , , , , Billy Tsai X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773630047; l=3044; i=billy_tsai@aspeedtech.com; s=20251118; h=from:subject:message-id; bh=NDFWhGINrDRsy3G0bfBO0q4ZxiMyFTtoWTFlKzGT8bg=; b=8+JasgxeNNHI5TmBibZAQ6o3VSNdAtCoMXPHE46zCX4x1ALdv0eCR3VXkTeVQYfJuIc07K160 P2qmexYd5iSCsN5gia0/OnQHF3m7pxjNAjBii10chq1nZ31mI2AqNnB X-Developer-Key: i=billy_tsai@aspeedtech.com; a=ed25519; pk=/A8qvgZ6CPfnwKgT6/+k+nvXOkN477MshEGJvVdzeeQ= For controllers with battery sensing capability (AST2600/AST2700), the last channel uses a different circuit design optimized for battery voltage measurement. This channel should not be enabled by default along with other channels to avoid potential interference and power efficiency issues. This ensures optimal power efficiency for normal ADC operations while maintaining full functionality when battery sensing is needed. Signed-off-by: Billy Tsai --- drivers/iio/adc/aspeed_adc.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index 81a2dd752541..ab173d8542c6 100644 --- a/drivers/iio/adc/aspeed_adc.c +++ b/drivers/iio/adc/aspeed_adc.c @@ -148,6 +148,13 @@ struct aspeed_adc_data { =20 static inline unsigned int aspeed_adc_get_active_channels(const struct asp= eed_adc_data *data) { + /* + * For controllers with battery sensing capability, the last channel + * is reserved for battery sensing and should not be included in + * normal channel operations. + */ + if (data->model_data->bat_sense_sup) + return data->model_data->num_channels - 1; return data->model_data->num_channels; } =20 @@ -315,9 +322,26 @@ static int aspeed_adc_read_raw(struct iio_dev *indio_d= ev, =20 switch (mask) { case IIO_CHAN_INFO_RAW: + adc_engine_control_reg_val =3D readl(data->base + ASPEED_REG_ENGINE_CONT= ROL); + /* + * For battery sensing capable controllers, we need to enable + * the specific channel before reading. This is required because + * the battery channel may not be enabled by default. + */ + if (data->model_data->bat_sense_sup && + chan->channel =3D=3D ASPEED_ADC_BATTERY_CHANNEL) { + u32 ctrl_reg =3D adc_engine_control_reg_val & ~ASPEED_ADC_CTRL_CHANNEL; + + ctrl_reg |=3D ASPEED_ADC_CTRL_CHANNEL_ENABLE(chan->channel); + writel(ctrl_reg, data->base + ASPEED_REG_ENGINE_CONTROL); + /* + * After enable a new channel need to wait some time for adc stable + * Experiment result is 1ms. + */ + mdelay(1); + } + if (data->battery_sensing && chan->channel =3D=3D ASPEED_ADC_BATTERY_CHA= NNEL) { - adc_engine_control_reg_val =3D - readl(data->base + ASPEED_REG_ENGINE_CONTROL); writel(adc_engine_control_reg_val | FIELD_PREP(ASPEED_ADC_CH7_MODE, ASPEED_ADC_CH7_BAT) | @@ -331,11 +355,11 @@ static int aspeed_adc_read_raw(struct iio_dev *indio_= dev, *val =3D readw(data->base + chan->address); *val =3D (*val * data->battery_mode_gain.mult) / data->battery_mode_gain.div; - /* Restore control register value */ - writel(adc_engine_control_reg_val, - data->base + ASPEED_REG_ENGINE_CONTROL); } else *val =3D readw(data->base + chan->address); + /* Restore control register value */ + writel(adc_engine_control_reg_val, + data->base + ASPEED_REG_ENGINE_CONTROL); return IIO_VAL_INT; =20 case IIO_CHAN_INFO_OFFSET: --=20 2.34.1