Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v8 7/7] thermal/drivers/loongson2: Add Loongson-2K0300 support
Date: Tue, 03 Nov 2026 07:43:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-194729@kernel.org> (raw)
In-Reply-To: <b36f79d7d130f5068620ceb224fcdfb4cde49b16.1793690276.git.zhoubinbin@loongson.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] thermal/drivers/loongson2: missing MFD_SYSCON dependency in Kconfig
- [Medium] thermal: loongson2: missing ADC delay in ls2k0300_thermal_hw_init()
--

commit 10dff186e720aacd669123374d9a7f0a467f16da
Author: Binbin Zhou <zhoubinbin@loongson.cn>

thermal/drivers/loongson2: Add Loongson-2K0300 support

This commit adds thermal sensor support for the Loongson-2K0300 SoC, reading
calibration offsets from the CHIP ID syscon registers and falling back to an
old-fuse slope when the calibrated temperature falls outside the valid range.

> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index d83aaa588c485..0a9d039c9ab8c 100644
> --- a/drivers/thermal/loongson2_thermal.c
> +++ b/drivers/thermal/loongson2_thermal.c

[ ... ]

> @@ -83,6 +118,101 @@ static int loongson2_thermal_set_trips(struct thermal_zone_device *tz, int low,
>  	return 0;
>  }
>  
> +static int ls2k0300_thermal_adc_to_temp_mc(struct loongson2_thermal_data *data, int slope)
> +{
> +	int raw_adc;
> +
> +	raw_adc = FIELD_GET(LOONGSON2_THSENS_OUT_11B_MASK,
> +			    readl(data->ctrl_reg + LOONGSON2_THSENS_OUT_REG));
> +
> +	return (raw_adc + data->calib_offset) * slope - LS2K0300_TEMP_OFFSET;
> +}

[ ... ]

> +static void ls2k0300_thermal_detect_old_fuse(struct device *dev,
> +					     struct loongson2_thermal_data *data)
> +{
> +	int temp;
> +
> +	temp = ls2k0300_thermal_adc_to_temp_mc(data, LS2K0300_TEMP_SLOPE);
> +
> +	if (temp < LOONGSON2_LOWEST_VALID_TEMP ||
> +	    temp > LOONGSON2_HIGHEST_VALID_TEMP) {
> +		dev_warn(dev, "calibrated temperature %d mC out of range [%d, %d], using old fuse formula",
> +			 temp, LOONGSON2_LOWEST_VALID_TEMP, LOONGSON2_HIGHEST_VALID_TEMP);
> +		data->flags = LS2K0300_UNCALIBRATED_FLAG;
> +		data->calib_offset = 0;
> +	}
> +}

[ ... ]

> +static int ls2k0300_thermal_hw_init(struct platform_device *pdev,
> +				    struct loongson2_thermal_data *data)
> +{
> +	struct device *dev = &pdev->dev;
> +	int ret;
> +
> +	data->regmap_cfg = syscon_regmap_lookup_by_phandle(dev->of_node, "loongson,chipid");
> +	if (IS_ERR(data->regmap_cfg))
> +		return PTR_ERR(data->regmap_cfg);

[Severity: Medium]
In drivers/thermal/loongson2_thermal.c, ls2k0300_thermal_hw_init()
unconditionally calls syscon_regmap_lookup_by_phandle(). When
CONFIG_MFD_SYSCON is not enabled, the stub in include/linux/mfd/syscon.h
returns ERR_PTR(-ENOTSUPP), causing loongson2_thermal_probe() to fail at
runtime on Loongson-2K0300.

Neither LOONGSON2_THERMAL in drivers/thermal/Kconfig nor LOONGARCH in
arch/loongarch/Kconfig selects or depends on MFD_SYSCON:

drivers/thermal/Kconfig:
    config LOONGSON2_THERMAL
        tristate "Loongson-2 SoC series thermal driver"
        depends on LOONGARCH || COMPILE_TEST
        depends on OF

Should LOONGSON2_THERMAL select MFD_SYSCON in Kconfig?

> +
> +	ret = ls2k0300_thermal_read_calib(data);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to read calibration data");
> +
> +	writel(LS2K0300_THSENS_INIT_MASK, data->ctrl_reg + LS2K0300_THSENS_CFG_REG);
> +
> +	ls2k0300_thermal_detect_old_fuse(dev, data);

[Severity: Medium]
As reported by Sashiko on v7 [1], in drivers/thermal/loongson2_thermal.c,
ls2k0300_thermal_hw_init() writes LS2K0300_THSENS_INIT_MASK to
LS2K0300_THSENS_CFG_REG and immediately calls
ls2k0300_thermal_detect_old_fuse() without waiting for the sensor ADC to
finish its initial conversion.

If the sensor was not already enabled prior to probe,
ls2k0300_thermal_detect_old_fuse() -> ls2k0300_thermal_adc_to_temp_mc() can
read a reset or stale value of 0 from LOONGSON2_THSENS_OUT_REG. With
raw_adc == 0, any calibration offset of 622 or less produces a temperature
below LOONGSON2_LOWEST_VALID_TEMP (-40000 mC), permanently setting
LS2K0300_UNCALIBRATED_FLAG and clearing data->calib_offset.

Should there be a delay or readiness check after writing
LS2K0300_THSENS_CFG_REG before reading LOONGSON2_THSENS_OUT_REG?

[1] https://lore.kernel.org/r/93002842dcf01ec651a9711075f5967026b95987.1791512067.git.zhoubinbin@loongson.cn

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1793690276.git.zhoubinbin@loongson.cn?part=7

      reply	other threads:[~2026-11-03  7:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  7:23 [PATCH v8 0/7] thermal/drivers/loongson2: Fix trip programming and add Loongson-2K0300 support Binbin Zhou
2026-11-03  7:23 ` [PATCH v8 1/7] thermal/drivers/loongson2: Fix negative trip conversion in set_trips Binbin Zhou
2026-11-03  7:23 ` [PATCH v8 2/7] thermal/drivers/loongson2: Fix clamp() usage for thermal trip points Binbin Zhou
2026-11-03  7:24 ` [PATCH v8 3/7] thermal/drivers/loongson2: Fix Loongson-2K2000 trip point programming Binbin Zhou
2026-11-03  7:41   ` sashiko-bot
2026-11-03  7:25 ` [PATCH v8 4/7] thermal/drivers/loongson2: Simplify thermal sensor registration Binbin Zhou
2026-11-03  7:25 ` [PATCH v8 5/7] thermal/drivers/loongson2: Move per-SoC ops and init into chip data Binbin Zhou
2026-11-03  7:25 ` [PATCH v8 6/7] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-11-03  7:25 ` [PATCH v8 7/7] thermal/drivers/loongson2: Add Loongson-2K0300 support Binbin Zhou
2026-11-03  7:43   ` sashiko-bot [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=sashiko-outbox-194729@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhoubinbin@loongson.cn \
    /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