From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795915501; b=4tV2Jpt5t3XTwvB30Y8sE02GN0TmB0R11ANJwv3GEsG41yvO0JExA186IXtsLVaGwFYq n2DCMn01LEW6N1PAkxbD2uM67QRp/P1DgykJqKiopfT4+y5n7Z5wj5QeGfLlVnf6aywue KF71TQU593BaWRVjiMg/REhlS/YiJ2qlhlhTnd6nzEX5610O9EN46ECJvZkf4c0frSoRL z9RVezh0uIQxOSpXfLt+D6N+mKceeGqN99BhrCr+50fHEvBGTO6tCm4BXjlEUPiqr2Ogz ffqHMl7HzOQmgLjKHfHwQBX4oU3H/GgVa4yOrRLy/UVbGZQx3rOXHGmKPr3J4++6jdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795915501; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=HdrGvd78M4fG8yfF3BHlifj6muXqJSAVUt9SwrKNb2k=; b=SCWB/5bMUfQ8i2yRHatIXzJaR6ir3LfGnJ47iZYmr0TCy1O+1TI041dNvpefFq81/yNy F0PADB3AAmns060kR4QDW04pvDT7kvyA1S7P0tIAINqoj+mCeuoVUcYUjtnNUXvnm4h1l jU/Y7/kGF/+eJJWw+vGP+rz2iiHvWn10UrsB4O52TYlIrd1qxo+TfgrDeV2KgtI1dzIB0 Yc0MllKHtT2BYYeFNGjTD8KKXYIuDlxAJeOauhC4a/ELzAjdb/nYY0xS3joLdPoXoIM8Y 0Cj+ytiBPwXts93f7Ch5Tp0Bz2AtiD0UdbBYAJvIo2uHGqTPHtRxjuKrHp3ym0m03WA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hMIAyrO6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ACF6606A31C; Sun, 29 Nov 2026 01:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hMIAyrO6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C83F1F00896; Sun, 29 Nov 2026 01:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795915501; bh=HdrGvd78M4fG8yfF3BHlifj6muXqJSAVUt9SwrKNb2k=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=hMIAyrO6ny6hTEnD9oRFpqOBeGvTW7Fr+vUv1ViBz2GxwDGkQvWc3xmSmzMP+Y7O+ JiJbQ5IC9+7U3hitmC7QtuQ0QaMKSxSRVVhvR1oZwJiZNsCAGACRTIVEft/CL1a2w2 YdO4wlfabkuc6NLD01JjD0+5BMpB84cgi1H73L2aeuqdlCsNFSQ2BCftqUvhBeVYlj cEuXd6C0lgwY1DqtteioM6YN9qtoFxox2gSi55bQBYHB5yuc+OO8cJC6o7Ou6+2sWV aduYiInCAMXwKh3RKnqDlaaqTQ0UIIqS9gDAudFLZXz9eNOsDjtLU+rA7DBbXpl3FF 26PewLGibwAbQ== Date: Sun, 29 Nov 2026 01:24:56 +0000 From: Jonathan Cameron To: "Luca Weiss" Cc: "David Lechner" , Nuno =?UTF-8?B?U8Oh?= , "Andy Shevchenko" , "Rafael J. Wysocki" , "Zhang Rui" , "Lukasz Luba" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Laxman Dewangan" , "Bjorn Andersson" , "Konrad Dybcio" , "Hans de Goede" , "Jens Reidel" , "Casey Connolly" , "Val Packett" , "Daniel Lezcano" , <~postmarketos/upstreaming@lists.sr.ht>, , , , , , Subject: Re: [PATCH v4 1/5] iio: adc: qcom-spmi-adc5: Add battery thermal channels Message-ID: <20261129012456.526c5670@jic23-hlaptop> In-Reply-To: References: <20261117-bat-temp-adc-v4-0-14d5d309ebfa@fairphone.com> <20261117-bat-temp-adc-v4-1-14d5d309ebfa@fairphone.com> <20261122031305.0fdc69cd@jic23-hlaptop> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 23 Nov 2026 10:17:21 +0100 "Luca Weiss" wrote: > Hi Jonathan, > > On Sun Nov 22, 2026 at 4:13 AM CET, Jonathan Cameron wrote: > > On Tue, 17 Nov 2026 09:23:11 +0100 > > Luca Weiss wrote: > > > >> Add the BAT_THERM channels with millivolt as output, which can then be > >> used along with information regarding the NTC in the battery, to get the > >> actual battery temperature. > >> > >> A static lookup table in the ADC driver won't work since different > >> devices have different Ohm and Beta values in their battery NTCs, for > >> example a NTC can be 10kOhm & B=3435K. > >> > >> Signed-off-by: Luca Weiss > > Given this is independent of the following elements other than > > the dtsi changes, do you want me to pick it up now? > > > > You may need to use numeric values in dtsi until the header > > catches up then chase with a patch flipping to the defines next cycle. > > That's how we normally avoid that dependency slowing things down. > > Sounds good from my side. Thank you! > > I think realistically, there's no other option than what's implemented > in this patch, even if PATCH 2/5 (dt-bindings change for generic-adc) is > not reviewed yet. But I hope the dt maintainers will be okay with that > as well. > I'm going to hold off on this until patch 2 discussion resolves. J > Regards > Luca > > > > > Thanks, > > > > Jonathan > > > >> --- > >> drivers/iio/adc/qcom-spmi-adc5.c | 6 ++++++ > >> drivers/iio/adc/qcom-vadc-common.c | 16 ++++++++++++++++ > >> include/linux/iio/adc/qcom-vadc-common.h | 3 +++ > >> 3 files changed, 25 insertions(+) > >> > >> diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c > >> index d57ba8526e0c..24ac84580570 100644 > >> --- a/drivers/iio/adc/qcom-spmi-adc5.c > >> +++ b/drivers/iio/adc/qcom-spmi-adc5.c > >> @@ -542,6 +542,12 @@ static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = { > >> SCALE_HW_CALIB_DEFAULT) > >> [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm", 0, > >> SCALE_HW_CALIB_XOTHERM) > >> + [ADC5_BAT_THERM_30K_PU] = ADC5_CHAN_VOLT("bat_therm_30k_pu", 0, > >> + SCALE_HW_CALIB_THERM_VOLT) > >> + [ADC5_BAT_THERM_100K_PU] = ADC5_CHAN_VOLT("bat_therm_100k_pu", 0, > >> + SCALE_HW_CALIB_THERM_VOLT) > >> + [ADC5_BAT_THERM_400K_PU] = ADC5_CHAN_VOLT("bat_therm_400k_pu", 0, > >> + SCALE_HW_CALIB_THERM_VOLT) > >> [ADC5_BAT_ID_100K_PU] = ADC5_CHAN_TEMP("bat_id", 0, > >> SCALE_HW_CALIB_DEFAULT) > >> [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 0, > >> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c > >> index b03cf584b165..101b3c724f8d 100644 > >> --- a/drivers/iio/adc/qcom-vadc-common.c > >> +++ b/drivers/iio/adc/qcom-vadc-common.c > >> @@ -309,6 +309,10 @@ static int qcom_vadc_scale_hw_calib_therm( > >> const struct u32_fract *prescale, > >> const struct adc5_data *data, > >> u16 adc_code, int *result_mdec); > >> +static int qcom_vadc_scale_hw_calib_therm_volt( > >> + const struct u32_fract *prescale, > >> + const struct adc5_data *data, > >> + u16 adc_code, int *result_mV); > >> static int qcom_vadc7_scale_hw_calib_therm( > >> const struct u32_fract *prescale, > >> const struct adc5_data *data, > >> @@ -333,6 +337,7 @@ static int qcom_vadc7_scale_hw_calib_die_temp( > >> static const struct qcom_adc5_scale_type scale_adc5_fn[] = { > >> [SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt}, > >> [SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm}, > >> + [SCALE_HW_CALIB_THERM_VOLT] = {qcom_vadc_scale_hw_calib_therm_volt}, > >> [SCALE_HW_CALIB_XOTHERM] = {qcom_vadc_scale_hw_calib_therm}, > >> [SCALE_HW_CALIB_THERM_100K_PU_PM7] = { > >> qcom_vadc7_scale_hw_calib_therm}, > >> @@ -583,6 +588,17 @@ static int qcom_vadc_scale_hw_calib_therm( > >> voltage, result_mdec); > >> } > >> > >> +static int qcom_vadc_scale_hw_calib_therm_volt( > >> + const struct u32_fract *prescale, > >> + const struct adc5_data *data, > >> + u16 adc_code, int *result_mV) > >> +{ > >> + *result_mV = qcom_vadc_scale_code_voltage_factor(adc_code, > >> + prescale, data, MICRO / MILLI); > >> + > >> + return 0; > >> +} > >> + > >> static int qcom_vadc_scale_hw_calib_die_temp( > >> const struct u32_fract *prescale, > >> const struct adc5_data *data, > >> diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h > >> index 3bf4c49726a7..7586016ff14d 100644 > >> --- a/include/linux/iio/adc/qcom-vadc-common.h > >> +++ b/include/linux/iio/adc/qcom-vadc-common.h > >> @@ -93,6 +93,8 @@ struct vadc_linear_graph { > >> * voltage (uV) with hardware applied offset/slope values to adc code. > >> * @SCALE_HW_CALIB_THERM_100K_PULLUP: Returns temperature in millidegC using > >> * lookup table. The hardware applies offset/slope to adc code. > >> + * @SCALE_HW_CALIB_THERM_VOLT: Returns voltage in mV of a temperature channel. > >> + * The hardware applies offset/slope to adc code. > >> * @SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using > >> * 100k pullup. The hardware applies offset/slope to adc code. > >> * @SCALE_HW_CALIB_THERM_100K_PU_PM7: Returns temperature in millidegC using > >> @@ -114,6 +116,7 @@ enum vadc_scale_fn_type { > >> SCALE_PMI_CHG_TEMP, > >> SCALE_HW_CALIB_DEFAULT, > >> SCALE_HW_CALIB_THERM_100K_PULLUP, > >> + SCALE_HW_CALIB_THERM_VOLT, > >> SCALE_HW_CALIB_XOTHERM, > >> SCALE_HW_CALIB_THERM_100K_PU_PM7, > >> SCALE_HW_CALIB_PMIC_THERM, > >> > > >