* [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop
2026-07-21 12:24 [PATCH v2 0/4] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
@ 2026-07-21 12:24 ` Binbin Zhou
2026-07-21 12:24 ` [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id Binbin Zhou
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Binbin Zhou @ 2026-07-21 12:24 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd,
Binbin Zhou, stable, Sashiko
The registration loop in loongson2_thermal_probe() incorrectly uses
dev_err_probe() when the sensor is not present (-ENODEV). In that case,
the driver should continue to the next sensor index rather than treating
it as a fatal error.
Fix this by correctly handling -ENODEV and only returning on other
errors. Also add a final check to ensure at least one thermal zone was
registered.
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/cover.1783670011.git.zhoubinbin@loongson.cn?part=2
Fixes: e7e3a7c35791 ("thermal/drivers/loongson-2: Add thermal management support")
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
drivers/thermal/loongson2_thermal.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
index ea4dd2fb1f47..d7d221c3136d 100644
--- a/drivers/thermal/loongson2_thermal.c
+++ b/drivers/thermal/loongson2_thermal.c
@@ -161,16 +161,18 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
-
if (!IS_ERR(tzd))
break;
- if (PTR_ERR(tzd) != -ENODEV)
+ if (PTR_ERR(tzd) == -ENODEV)
continue;
- return dev_err_probe(dev, PTR_ERR(tzd), "failed to register");
+ return dev_err_probe(dev, PTR_ERR(tzd), "failed to register sensor %d", i);
}
+ if (IS_ERR(tzd))
+ return dev_err_probe(dev, -ENODEV, "No thermal sensor registered\n");
+
ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
IRQF_ONESHOT, "loongson2_thermal", tzd);
if (ret < 0)
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id
2026-07-21 12:24 [PATCH v2 0/4] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
2026-07-21 12:24 ` [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop Binbin Zhou
@ 2026-07-21 12:24 ` Binbin Zhou
2026-07-21 15:39 ` Conor Dooley
2026-07-21 12:26 ` [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
2026-07-21 12:26 ` [PATCH v2 4/4] thermal/drivers/loongson2: Add support " Binbin Zhou
3 siblings, 1 reply; 7+ messages in thread
From: Binbin Zhou @ 2026-07-21 12:24 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd,
Binbin Zhou
The Loongson-2K0300 SoC exposes its chip ID registers through a syscon
interface. Add the specific compatible `loongson,ls2k0300-chipid-syscon`
to the allowed list of syscon bindings so that it can be referenced from
the thermal node via a phandle.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
Documentation/devicetree/bindings/mfd/syscon.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml b/Documentation/devicetree/bindings/mfd/syscon.yaml
index e22867088063..c5b2e28f6ced 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -76,6 +76,7 @@ select:
- hpe,gxp-sysreg
- loongson,ls1b-syscon
- loongson,ls1c-syscon
+ - loongson,ls2k0300-cphipid-syscon
- lsi,axxia-syscon
- marvell,armada-3700-cpu-misc
- marvell,armada-3700-nb-pm
@@ -189,6 +190,7 @@ properties:
- hpe,gxp-sysreg
- loongson,ls1b-syscon
- loongson,ls1c-syscon
+ - loongson,ls2k0300-cphipid-syscon
- lsi,axxia-syscon
- marvell,armada-3700-cpu-misc
- marvell,armada-3700-nb-pm
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id
2026-07-21 12:24 ` [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id Binbin Zhou
@ 2026-07-21 15:39 ` Conor Dooley
0 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2026-07-21 15:39 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd
[-- Attachment #1: Type: text/plain, Size: 1544 bytes --]
On Tue, Jul 21, 2026 at 08:24:21PM +0800, Binbin Zhou wrote:
> The Loongson-2K0300 SoC exposes its chip ID registers through a syscon
> interface. Add the specific compatible `loongson,ls2k0300-chipid-syscon`
> to the allowed list of syscon bindings so that it can be referenced from
> the thermal node via a phandle.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
> Documentation/devicetree/bindings/mfd/syscon.yaml | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml b/Documentation/devicetree/bindings/mfd/syscon.yaml
> index e22867088063..c5b2e28f6ced 100644
> --- a/Documentation/devicetree/bindings/mfd/syscon.yaml
> +++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
> @@ -76,6 +76,7 @@ select:
> - hpe,gxp-sysreg
> - loongson,ls1b-syscon
> - loongson,ls1c-syscon
> + - loongson,ls2k0300-cphipid-syscon
You've spelt both of these wrong, "cphip" instead of "chip".
pw-bot: changes-requested
Thanks,
Conor.
> - lsi,axxia-syscon
> - marvell,armada-3700-cpu-misc
> - marvell,armada-3700-nb-pm
> @@ -189,6 +190,7 @@ properties:
> - hpe,gxp-sysreg
> - loongson,ls1b-syscon
> - loongson,ls1c-syscon
> + - loongson,ls2k0300-cphipid-syscon
> - lsi,axxia-syscon
> - marvell,armada-3700-cpu-misc
> - marvell,armada-3700-nb-pm
> --
> 2.52.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300
2026-07-21 12:24 [PATCH v2 0/4] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
2026-07-21 12:24 ` [PATCH v2 1/4] thermal/drivers/loongson2: Correct thermal sensor registration loop Binbin Zhou
2026-07-21 12:24 ` [PATCH v2 2/4] dt-bindings: mfd: syscon: Allow syscon compatible for Loongson-2K0300 chip id Binbin Zhou
@ 2026-07-21 12:26 ` Binbin Zhou
2026-07-21 15:39 ` Conor Dooley
2026-07-21 12:26 ` [PATCH v2 4/4] thermal/drivers/loongson2: Add support " Binbin Zhou
3 siblings, 1 reply; 7+ messages in thread
From: Binbin Zhou @ 2026-07-21 12:26 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd,
Binbin Zhou
Add a new compatible string `loongson,ls2k0300-thermal` for the thermal
sensor found on the Loongson-2K0300 SoC.
The hardware differs from existing SoCs in that it requires a phandle to
a syscon node that provides the CHIP ID register, used as a compensation
source in the temperature calculation.
Update the binding to make `loongson,chipid` required for this new
compatible, and clarify the register region requirements for each
variant.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
.../thermal/loongson,ls2k-thermal.yaml | 73 ++++++++++++++-----
1 file changed, 55 insertions(+), 18 deletions(-)
diff --git a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
index 79e691b08341..d312e27737a2 100644
--- a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
@@ -10,13 +10,11 @@ maintainers:
- zhanghongchen <zhanghongchen@loongson.cn>
- Yinbo Zhu <zhuyinbo@loongson.cn>
-allOf:
- - $ref: /schemas/thermal/thermal-sensor.yaml#
-
properties:
compatible:
oneOf:
- enum:
+ - loongson,ls2k0300-thermal
- loongson,ls2k1000-thermal
- loongson,ls2k2000-thermal
- items:
@@ -34,28 +32,56 @@ properties:
'#thermal-sensor-cells':
const: 1
+ loongson,chipid:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the syscon with the Loongson-2K0300 CHIP ID.
+
required:
- compatible
- reg
- interrupts
-if:
- properties:
- compatible:
- contains:
- enum:
- - loongson,ls2k2000-thermal
+allOf:
+ - $ref: /schemas/thermal/thermal-sensor.yaml#
+
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: loongson,ls2k0300-thermal
+ then:
+ properties:
+ reg:
+ items:
+ - description: Thermal base register region
+ required:
+ - loongson,chipid
-then:
- properties:
- reg:
- minItems: 2
- maxItems: 2
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: loongson,ls2k1000-thermal
+ then:
+ properties:
+ loongson,chipid: false
+ reg:
+ items:
+ - description: Thermal base register region
-else:
- properties:
- reg:
- maxItems: 1
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: loongson,ls2k2000-thermal
+ then:
+ properties:
+ loongson,chipid: false
+ reg:
+ items:
+ - description: Thermal base register region
+ - description: Thermal data output register region
unevaluatedProperties: false
@@ -69,3 +95,14 @@ examples:
interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
#thermal-sensor-cells = <1>;
};
+
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ thermal-sensor@16001500 {
+ compatible = "loongson,ls2k0300-thermal";
+ reg = <0x16001500 0x30>;
+ interrupt-parent = <&liointc1>;
+ interrupts = <20 IRQ_TYPE_LEVEL_HIGH>;
+ loongson,chipid = <&chipid>;
+ #thermal-sensor-cells = <1>;
+ };
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300
2026-07-21 12:26 ` [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
@ 2026-07-21 15:39 ` Conor Dooley
0 siblings, 0 replies; 7+ messages in thread
From: Conor Dooley @ 2026-07-21 15:39 UTC (permalink / raw)
To: Binbin Zhou
Cc: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd
[-- Attachment #1: Type: text/plain, Size: 75 bytes --]
Acked-by: Conor Dooley <conor.dooley@microchip.com>
pw-bot: not-applicable
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 4/4] thermal/drivers/loongson2: Add support for Loongson-2K0300
2026-07-21 12:24 [PATCH v2 0/4] thermal: loongson2: Add support for Loongson-2K0300 SoC Binbin Zhou
` (2 preceding siblings ...)
2026-07-21 12:26 ` [PATCH v2 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Add compatible for Loongson-2K0300 Binbin Zhou
@ 2026-07-21 12:26 ` Binbin Zhou
3 siblings, 0 replies; 7+ messages in thread
From: Binbin Zhou @ 2026-07-21 12:26 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Yinbo Zhu, zhanghongchen,
Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba
Cc: Huacai Chen, Xuerui Wang, loongarch, devicetree, linux-pm, mfd,
Binbin Zhou
Add support for the thermal sensor found on the Loongson-2K0300 SoC.
The Loongson-2K0300 thermal sensor uses a 10-bit ADC and requires
per-chip calibration. The calibration offset is stored in the CHIP ID
registers, which are accessed via syscon. The driver reads this offset
and applies it when converting the raw ADC value to millicelsius.
To handle old fuse versions that cannot be calibrated correctly, the
driver includes a fallback formula and a validity check. Once invalid
data is detected, the driver falls back to the old formula for future
reads and warns the user.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
drivers/thermal/loongson2_thermal.c | 112 +++++++++++++++++++++++++---
1 file changed, 100 insertions(+), 12 deletions(-)
diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
index d7d221c3136d..e8d11e592a1f 100644
--- a/drivers/thermal/loongson2_thermal.c
+++ b/drivers/thermal/loongson2_thermal.c
@@ -2,9 +2,11 @@
/*
* Author: zhanghongchen <zhanghongchen@loongson.cn>
* Yinbo Zhu <zhuyinbo@loongson.cn>
- * Copyright (C) 2022-2023 Loongson Technology Corporation Limited
+ * Binbin Zhou <zhoubinbin@loongson.cn>
+ * Copyright (C) 2022-2026 Loongson Technology Corporation Limited
*/
+#include <linux/bitfield.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/minmax.h>
@@ -14,6 +16,9 @@
#include <linux/property.h>
#include <linux/thermal.h>
#include <linux/units.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+#include <linux/syscore_ops.h>
#include "thermal_hwmon.h"
@@ -23,28 +28,48 @@
#define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
#define LOONGSON2_THSENS_STATUS_REG 0x10
#define LOONGSON2_THSENS_OUT_REG 0x14
+#define LOONGSON2_THSENS_CFG_REG 0x18
#define LOONGSON2_THSENS_INT_LO BIT(0)
#define LOONGSON2_THSENS_INT_HIGH BIT(1)
#define LOONGSON2_THSENS_INT_EN (LOONGSON2_THSENS_INT_LO | \
LOONGSON2_THSENS_INT_HIGH)
-#define LOONGSON2_THSENS_OUT_MASK 0xFF
+#define LOONGSON2_THSENS_OUT_8B_MASK 0xFF
+#define LOONGSON2_THSENS_OUT_10B_MASK GENMASK(10, 0)
+
+#define LS2K0300_CHIP_ID0 0x10
+#define LS2K0300_CHIP_ID1 0x14
+#define LS2K0300_EXTERN_ID BIT(4)
+#define LS2K0300_ID0_VAL_MASK GENMASK(31, 20)
+#define LS2K0300_ID1_VAL_MASK GENMASK(15, 0)
+
+#define LS2K0300_COMP_VAL_MASK GENMASK(14, 0)
+#define LS2K0300_COMP_SIGN_BIT BIT(15)
+
+#define LS2K0300_LOWEST_VALID_TEMP (-55000)
+#define LS2K0300_HIGHEST_VALID_TEMP (125000)
/*
* This flag is used to indicate the temperature reading
* method of the Loongson-2K2000
*/
#define LS2K2000_THSENS_OUT_FLAG BIT(0)
+#define LS2K0300_CHIP_ID_FLAG BIT(1)
+#define LS2K0300_OLD_FUSE_FLAG BIT(2)
struct loongson2_thermal_chip_data {
unsigned int thermal_sensor_sel;
unsigned int flags;
+ const struct thermal_zone_device_ops *thermal_ops;
};
struct loongson2_thermal_data {
+ int calib_offset;
+ struct device *dev;
void __iomem *ctrl_reg;
void __iomem *temp_reg;
- const struct loongson2_thermal_chip_data *chip_data;
+ struct regmap *regmap_cfg;
+ struct loongson2_thermal_chip_data *chip_data;
};
static void loongson2_set_ctrl_regs(struct loongson2_thermal_data *data,
@@ -71,13 +96,55 @@ static int loongson2_thermal_set(struct loongson2_thermal_data *data,
return 0;
}
+static int loongson2_2k0300_get_temp(struct thermal_zone_device *tz, int *temp)
+{
+ struct loongson2_thermal_data *tdata = thermal_zone_device_priv(tz);
+ int calib_data, calib_offset, temp_mc, raw_adc;
+ u32 chip_id0, chip_id1;
+
+ writel(0xff03, tdata->ctrl_reg + LOONGSON2_THSENS_CFG_REG);
+ raw_adc = FIELD_GET(LOONGSON2_THSENS_OUT_10B_MASK,
+ readl(tdata->ctrl_reg + LOONGSON2_THSENS_OUT_REG));
+
+ if (tdata->chip_data->flags & LS2K0300_OLD_FUSE_FLAG) {
+ *temp = raw_adc * 569 - 394700;
+ return 0;
+ }
+
+ regmap_read(tdata->regmap_cfg, LS2K0300_CHIP_ID0, &chip_id0);
+ regmap_read(tdata->regmap_cfg, LS2K0300_CHIP_ID1, &chip_id1);
+
+ if (chip_id0 & LS2K0300_EXTERN_ID) {
+ calib_data = FIELD_GET(LS2K0300_ID1_VAL_MASK, chip_id1);
+ calib_offset = FIELD_GET(LS2K0300_COMP_VAL_MASK, calib_data);
+ if (calib_data & LS2K0300_COMP_SIGN_BIT)
+ calib_offset = -calib_offset;
+ } else {
+ calib_data = FIELD_GET(LS2K0300_ID0_VAL_MASK, chip_id0);
+ calib_offset = FIELD_GET(LS2K0300_COMP_VAL_MASK, calib_data);
+ }
+
+ tdata->calib_offset = calib_offset;
+ temp_mc = (raw_adc + calib_offset) * 570 - 394700;
+
+ /* For old fuse which can not read right thermal data */
+ if (temp_mc < LS2K0300_LOWEST_VALID_TEMP || temp_mc > LS2K0300_HIGHEST_VALID_TEMP) {
+ dev_warn_once(tdata->dev, "It's an old fuse, thermal %d is not right\n", temp_mc);
+ tdata->chip_data->flags |= LS2K0300_OLD_FUSE_FLAG;
+ temp_mc = raw_adc * 569 - 394700;
+ }
+ *temp = temp_mc;
+
+ return 0;
+}
+
static int loongson2_2k1000_get_temp(struct thermal_zone_device *tz, int *temp)
{
int val;
struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
val = readl(data->ctrl_reg + LOONGSON2_THSENS_OUT_REG);
- *temp = ((val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
+ *temp = ((val & LOONGSON2_THSENS_OUT_8B_MASK) - HECTO) * KILO;
return 0;
}
@@ -112,6 +179,11 @@ static int loongson2_thermal_set_trips(struct thermal_zone_device *tz, int low,
return loongson2_thermal_set(data, low/MILLI, high/MILLI, true);
}
+static const struct thermal_zone_device_ops loongson2_2k0300_of_thermal_ops = {
+ .get_temp = loongson2_2k0300_get_temp,
+ .set_trips = loongson2_thermal_set_trips,
+};
+
static const struct thermal_zone_device_ops loongson2_2k1000_of_thermal_ops = {
.get_temp = loongson2_2k1000_get_temp,
.set_trips = loongson2_thermal_set_trips,
@@ -124,7 +196,6 @@ static const struct thermal_zone_device_ops loongson2_2k2000_of_thermal_ops = {
static int loongson2_thermal_probe(struct platform_device *pdev)
{
- const struct thermal_zone_device_ops *thermal_ops;
struct device *dev = &pdev->dev;
struct loongson2_thermal_data *data;
struct thermal_zone_device *tzd;
@@ -134,7 +205,8 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
if (!data)
return -ENOMEM;
- data->chip_data = device_get_match_data(dev);
+ data->dev = dev;
+ data->chip_data = (struct loongson2_thermal_chip_data *)device_get_match_data(dev);
data->ctrl_reg = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(data->ctrl_reg))
@@ -145,10 +217,14 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
data->temp_reg = devm_platform_ioremap_resource(pdev, 1);
if (IS_ERR(data->temp_reg))
return PTR_ERR(data->temp_reg);
+ }
- thermal_ops = &loongson2_2k2000_of_thermal_ops;
- } else {
- thermal_ops = &loongson2_2k1000_of_thermal_ops;
+ /* The chip id register is needed for Loongson-2K0300 */
+ if (data->chip_data->flags & LS2K0300_CHIP_ID_FLAG) {
+ 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);
}
irq = platform_get_irq(pdev, 0);
@@ -160,7 +236,7 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
loongson2_thermal_set(data, 0, 0, false);
for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
- tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
+ tzd = devm_thermal_of_zone_register(dev, i, data, data->chip_data->thermal_ops);
if (!IS_ERR(tzd))
break;
@@ -183,17 +259,29 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
return 0;
}
-static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
+static struct loongson2_thermal_chip_data loongson2_thermal_ls2k0300_data = {
+ .thermal_sensor_sel = 0,
+ .flags = LS2K0300_CHIP_ID_FLAG,
+ .thermal_ops = &loongson2_2k0300_of_thermal_ops,
+};
+
+static struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
.thermal_sensor_sel = 0,
.flags = 0,
+ .thermal_ops = &loongson2_2k1000_of_thermal_ops,
};
-static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k2000_data = {
+static struct loongson2_thermal_chip_data loongson2_thermal_ls2k2000_data = {
.thermal_sensor_sel = 0,
.flags = LS2K2000_THSENS_OUT_FLAG,
+ .thermal_ops = &loongson2_2k2000_of_thermal_ops,
};
static const struct of_device_id of_loongson2_thermal_match[] = {
+ {
+ .compatible = "loongson,ls2k0300-thermal",
+ .data = &loongson2_thermal_ls2k0300_data,
+ },
{
.compatible = "loongson,ls2k1000-thermal",
.data = &loongson2_thermal_ls2k1000_data,
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread