From: Jonathan Cameron <jic23@kernel.org>
To: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
Cc: robh@kernel.org, krzysztof.kozlowski@linaro.org,
krzk+dt@kernel.org, conor+dt@kernel.org, agross@kernel.org,
andersson@kernel.org, lumag@kernel.org,
dmitry.baryshkov@oss.qualcomm.com, konradybcio@kernel.org,
daniel.lezcano@linaro.org, sboyd@kernel.org, amitk@kernel.org,
thara.gopinath@gmail.com, lee@kernel.org, rafael@kernel.org,
subbaraman.narayanamurthy@oss.qualcomm.com,
david.collins@oss.qualcomm.com,
anjelique.melendez@oss.qualcomm.com,
kamal.wadhwa@oss.qualcomm.com, rui.zhang@intel.com,
lukasz.luba@arm.com, devicetree@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
cros-qcom-dts-watchers@chromium.org, quic_kotarake@quicinc.com,
neil.armstrong@linaro.org, stephan.gerhold@linaro.org
Subject: Re: [PATCH V8 4/4] thermal: qcom: add support for PMIC5 Gen3 ADC thermal monitoring
Date: Sun, 7 Dec 2025 17:04:01 +0000 [thread overview]
Message-ID: <20251207170401.1143fc22@jic23-huawei> (raw)
In-Reply-To: <20251127134036.209905-5-jishnu.prakash@oss.qualcomm.com>
On Thu, 27 Nov 2025 19:10:36 +0530
Jishnu Prakash <jishnu.prakash@oss.qualcomm.com> wrote:
> Add support for ADC_TM part of PMIC5 Gen3.
>
> This is an auxiliary driver under the Gen3 ADC driver, which implements the
> threshold setting and interrupt generating functionalities of QCOM ADC_TM
> drivers, used to support thermal trip points.
>
> Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
> ---
Hi Jishnu
Fresh read threw up a few more comments from me.
See inline
Thanks,
Jonathan
> diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
> new file mode 100644
> index 000000000000..c6cc8ef76f7e
> --- /dev/null
> +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
> +
> +static void tm_handler_work(struct work_struct *work)
> +{
> + struct adc_tm5_gen3_chip *adc_tm5 = container_of(work, struct adc_tm5_gen3_chip,
> + tm_handler_work);
> + struct adc_tm5_gen3_channel_props *chan_prop;
Why not declare in the reduced scope below? Then could probably combine
declaration and assignment for this, and offset.
> + u8 tm_status[2] = { };
> + u8 buf[16] = { };
> + int sdam_index = -1;
> + int i, ret;
> +
> + for (i = 0; i < adc_tm5->nchannels; i++) {
It's considered fine in new kernel code to declare the loop variable
as
for (int i = 0;
> + bool upper_set, lower_set;
> + int temp, offset;
> + u16 code = 0;
> +
> + chan_prop = &adc_tm5->chan_props[i];
> + offset = chan_prop->tm_chan_index;
> +
> + adc5_gen3_mutex_lock(adc_tm5->dev);
> + if (chan_prop->sdam_index != sdam_index) {
> + sdam_index = chan_prop->sdam_index;
> + ret = adc5_gen3_tm_status_check(adc_tm5, sdam_index,
> + tm_status, buf);
> + if (ret) {
> + adc5_gen3_mutex_unlock(adc_tm5->dev);
If you had the guard() below, could perhaps use scoped_guard() here
to avoid need for unlocking in error paths.
That would be at the cost of increased indent however, so may not be worth it
or that may suggest factoring out some of this code as a helper.
> + break;
> + }
> + }
> +
> + upper_set = ((tm_status[0] & BIT(offset)) && chan_prop->high_thr_en);
> + lower_set = ((tm_status[1] & BIT(offset)) && chan_prop->low_thr_en);
> + adc5_gen3_mutex_unlock(adc_tm5->dev);
> +
> + if (!(upper_set || lower_set))
> + continue;
> +
> + code = get_unaligned_le16(&buf[2 * offset]);
> + pr_debug("ADC_TM threshold code:%#x\n", code);
> +
> + ret = adc5_gen3_therm_code_to_temp(adc_tm5->dev,
> + &chan_prop->common_props,
> + code, &temp);
> + if (ret) {
> + dev_err(adc_tm5->dev,
> + "Invalid temperature reading, ret = %d, code=%#x\n",
> + ret, code);
> + continue;
> + }
> +
> + chan_prop->last_temp = temp;
> + chan_prop->last_temp_set = true;
> + thermal_zone_device_update(chan_prop->tzd, THERMAL_TRIP_VIOLATED);
> + }
> +}
> +static int adc_tm5_gen3_set_trip_temp(struct thermal_zone_device *tz,
> + int low_temp, int high_temp)
> +{
> + struct adc_tm5_gen3_channel_props *prop = thermal_zone_device_priv(tz);
> + struct adc_tm5_gen3_chip *adc_tm5;
> + int ret;
> +
> + if (!prop || !prop->chip)
> + return -EINVAL;
> +
> + adc_tm5 = prop->chip;
> +
> + dev_dbg(adc_tm5->dev, "channel:%s, low_temp(mdegC):%d, high_temp(mdegC):%d\n",
> + prop->common_props.label, low_temp, high_temp);
> +
> + adc5_gen3_mutex_lock(adc_tm5->dev);
> + if (high_temp == INT_MAX && low_temp <= -INT_MAX)
How is low temp lower than the min value that fits in an integer?
> + ret = adc_tm5_gen3_disable_channel(prop);
> + else
> + ret = adc_tm5_gen3_configure(prop, low_temp, high_temp);
> + adc5_gen3_mutex_unlock(adc_tm5->dev);
Might be worth a DEFINE_GUARD() so you can do
guard(adc5_gen3)(adc_tm5->dev);
if (high_temp = INT_MAX && low_temp <= -INT_MAX)
return adc_tm5_gen3_disable_channel(prop);
return adc_tm5...
I haven't looked to see if this is useful elsewhere in these drivers.
> +
> + return ret;
> +}
prev parent reply other threads:[~2025-12-07 17:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 13:40 [PATCH V8 0/4] Add support for QCOM SPMI PMIC5 Gen3 ADC Jishnu Prakash
2025-11-27 13:40 ` [PATCH V8 1/4] dt-bindings: iio: adc: Split out QCOM VADC channel properties Jishnu Prakash
2025-11-27 13:40 ` [PATCH V8 2/4] dt-bindings: iio: adc: Add support for QCOM PMIC5 Gen3 ADC Jishnu Prakash
2025-12-05 8:57 ` Krzysztof Kozlowski
2025-11-27 13:40 ` [PATCH V8 3/4] " Jishnu Prakash
2025-12-06 2:22 ` Dmitry Baryshkov
2025-12-07 16:53 ` Jonathan Cameron
2025-11-27 13:40 ` [PATCH V8 4/4] thermal: qcom: add support for PMIC5 Gen3 ADC thermal monitoring Jishnu Prakash
2025-12-06 2:24 ` Dmitry Baryshkov
2025-12-07 17:04 ` Jonathan Cameron [this message]
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=20251207170401.1143fc22@jic23-huawei \
--to=jic23@kernel.org \
--cc=agross@kernel.org \
--cc=amitk@kernel.org \
--cc=andersson@kernel.org \
--cc=anjelique.melendez@oss.qualcomm.com \
--cc=conor+dt@kernel.org \
--cc=cros-qcom-dts-watchers@chromium.org \
--cc=daniel.lezcano@linaro.org \
--cc=david.collins@oss.qualcomm.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=jishnu.prakash@oss.qualcomm.com \
--cc=kamal.wadhwa@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lee@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=lumag@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=quic_kotarake@quicinc.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=sboyd@kernel.org \
--cc=stephan.gerhold@linaro.org \
--cc=subbaraman.narayanamurthy@oss.qualcomm.com \
--cc=thara.gopinath@gmail.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;
as well as URLs for NNTP newsgroup(s).