* [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support
@ 2024-04-20 1:45 Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment Binbin Zhou
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Binbin Zhou @ 2024-04-20 1:45 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch, Binbin Zhou
Hi all:
This patchset introduce the Loongson-2K0500 and Loongson-2K2000
temperature sensors.
The temperature sensors of Loongson-2K series CPUs are similar, except
that the temperature reading method of the Loongson-2K2000 is
different.
Specifically, the temperature output register of the Loongson-2K2000 is
defined in the chip configuration domain. We need to define it in dts
and calculate it using different calculation methods.
Thanks.
---
V3:
- Collect Acked-by and Reviewed-by tag, thanks.
patch(1/4):
- Several code stlye adjustments, such as line breaks.
patch(3/4):
- If-else statement goes before unevaluatedProperties.
Link to V2:
https://lore.kernel.org/all/cover.1713147645.git.zhoubinbin@loongson.cn/
V2:
patch(2/4):
- Add Acked-by tag from Rob, thanks.
patch(3/4):
- Add "minItems: 2" to the reg attribute of Loongson-2K2000.
Link to V1:
https://lore.kernel.org/all/cover.1712733065.git.zhoubinbin@loongson.cn/
Binbin Zhou (4):
thermal: loongson2: Trivial code style adjustment
dt-bindings: thermal: loongson,ls2k-thermal: Add Loongson-2K0500
compatible
dt-bindings: thermal: loongson,ls2k-thermal: Fix incorrect compatible
definition
thermal: loongson2: Add Loongson-2K2000 support
.../thermal/loongson,ls2k-thermal.yaml | 24 +++-
drivers/thermal/loongson2_thermal.c | 111 +++++++++++-------
2 files changed, 93 insertions(+), 42 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment
2024-04-20 1:45 [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support Binbin Zhou
@ 2024-04-20 1:45 ` Binbin Zhou
2024-04-22 9:44 ` Daniel Lezcano
2024-04-20 1:45 ` [PATCH v3 2/4] dt-bindings: thermal: loongson,ls2k-thermal: Add Loongson-2K0500 compatible Binbin Zhou
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Binbin Zhou @ 2024-04-20 1:45 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch, Binbin Zhou
Here are some minor code style adjustment. Such as fix whitespace code
style; align function call arguments to opening parenthesis, and add
devm_thermal_add_hwmon_sysfs() return value checking.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
---
drivers/thermal/loongson2_thermal.c | 69 +++++++++++++++--------------
1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
index 0f475fe46bc9..7de01fbea801 100644
--- a/drivers/thermal/loongson2_thermal.c
+++ b/drivers/thermal/loongson2_thermal.c
@@ -14,47 +14,51 @@
#include <linux/property.h>
#include <linux/thermal.h>
#include <linux/units.h>
+
#include "thermal_hwmon.h"
-#define LOONGSON2_MAX_SENSOR_SEL_NUM 3
+#define LOONGSON2_MAX_SENSOR_SEL_NUM 3
-#define LOONGSON2_THSENS_CTRL_HI_REG 0x0
-#define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
-#define LOONGSON2_THSENS_STATUS_REG 0x10
-#define LOONGSON2_THSENS_OUT_REG 0x14
+#define LOONGSON2_THSENS_CTRL_HI_REG 0x0
+#define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
+#define LOONGSON2_THSENS_STATUS_REG 0x10
+#define LOONGSON2_THSENS_OUT_REG 0x14
-#define LOONGSON2_THSENS_INT_LO BIT(0)
-#define LOONGSON2_THSENS_INT_HIGH BIT(1)
-#define LOONGSON2_THSENS_OUT_MASK 0xFF
+#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
struct loongson2_thermal_chip_data {
- unsigned int thermal_sensor_sel;
+ unsigned int thermal_sensor_sel;
};
struct loongson2_thermal_data {
- void __iomem *regs;
+ void __iomem *regs;
const struct loongson2_thermal_chip_data *chip_data;
};
-static int loongson2_thermal_set(struct loongson2_thermal_data *data,
- int low, int high, bool enable)
+static void loongson2_set_ctrl_regs(struct loongson2_thermal_data *data,
+ int ctrl_data, bool low, bool enable)
{
- u64 reg_ctrl = 0;
- int reg_off = data->chip_data->thermal_sensor_sel * 2;
-
- low = clamp(-40, low, high);
- high = clamp(125, low, high);
+ int reg_ctrl = 0;
+ int reg_off = data->chip_data->thermal_sensor_sel * 2;
+ int ctrl_reg = low ? LOONGSON2_THSENS_CTRL_LOW_REG : LOONGSON2_THSENS_CTRL_HI_REG;
- low += HECTO;
- high += HECTO;
-
- reg_ctrl = low;
+ reg_ctrl = ctrl_data + HECTO;
reg_ctrl |= enable ? 0x100 : 0;
- writew(reg_ctrl, data->regs + LOONGSON2_THSENS_CTRL_LOW_REG + reg_off);
+ writew(reg_ctrl, data->regs + ctrl_reg + reg_off);
+}
- reg_ctrl = high;
- reg_ctrl |= enable ? 0x100 : 0;
- writew(reg_ctrl, data->regs + LOONGSON2_THSENS_CTRL_HI_REG + reg_off);
+static int loongson2_thermal_set(struct loongson2_thermal_data *data,
+ int low, int high, bool enable)
+{
+ /* Set low temperature threshold */
+ loongson2_set_ctrl_regs(data, clamp(-40, low, high), true, enable);
+
+ /* Set high temperature threshold */
+ loongson2_set_ctrl_regs(data, clamp(125, low, high), false, enable);
return 0;
}
@@ -75,8 +79,7 @@ static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
struct thermal_zone_device *tzd = dev;
struct loongson2_thermal_data *data = thermal_zone_device_priv(tzd);
- writeb(LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH, data->regs +
- LOONGSON2_THSENS_STATUS_REG);
+ writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
thermal_zone_device_update(tzd, THERMAL_EVENT_UNSPECIFIED);
@@ -116,14 +119,13 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
if (irq < 0)
return irq;
- writeb(LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH, data->regs +
- LOONGSON2_THSENS_STATUS_REG);
+ writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
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,
- &loongson2_of_thermal_ops);
+ &loongson2_of_thermal_ops);
if (!IS_ERR(tzd))
break;
@@ -135,13 +137,11 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
}
ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
- IRQF_ONESHOT, "loongson2_thermal", tzd);
+ IRQF_ONESHOT, "loongson2_thermal", tzd);
if (ret < 0)
return dev_err_probe(dev, ret, "failed to request alarm irq\n");
- devm_thermal_add_hwmon_sysfs(dev, tzd);
-
- return 0;
+ return devm_thermal_add_hwmon_sysfs(dev, tzd);
}
static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
@@ -167,4 +167,5 @@ static struct platform_driver loongson2_thermal_driver = {
module_platform_driver(loongson2_thermal_driver);
MODULE_DESCRIPTION("Loongson2 thermal driver");
+MODULE_AUTHOR("Loongson Technology Corporation Limited");
MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/4] dt-bindings: thermal: loongson,ls2k-thermal: Add Loongson-2K0500 compatible
2024-04-20 1:45 [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment Binbin Zhou
@ 2024-04-20 1:45 ` Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Fix incorrect compatible definition Binbin Zhou
2024-04-20 1:46 ` [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support Binbin Zhou
3 siblings, 0 replies; 9+ messages in thread
From: Binbin Zhou @ 2024-04-20 1:45 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch, Binbin Zhou, Rob Herring
The thermal on the Loongson-2K0500 shares the design with the
Loongson-2K1000. Define corresponding compatible string, having the
loongson,ls2k1000-thermal as a fallback.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
---
.../devicetree/bindings/thermal/loongson,ls2k-thermal.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
index b634f57cd011..9748a479dcd4 100644
--- a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
@@ -20,6 +20,7 @@ properties:
- loongson,ls2k1000-thermal
- items:
- enum:
+ - loongson,ls2k0500-thermal
- loongson,ls2k2000-thermal
- const: loongson,ls2k1000-thermal
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Fix incorrect compatible definition
2024-04-20 1:45 [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 2/4] dt-bindings: thermal: loongson,ls2k-thermal: Add Loongson-2K0500 compatible Binbin Zhou
@ 2024-04-20 1:45 ` Binbin Zhou
2024-04-20 1:46 ` [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support Binbin Zhou
3 siblings, 0 replies; 9+ messages in thread
From: Binbin Zhou @ 2024-04-20 1:45 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch, Binbin Zhou, Krzysztof Kozlowski
The temperature output register of the Loongson-2K2000 is defined in the
chip configuration domain, which is different from the Loongson-2K1000,
so it can't be fallbacked.
We need to use two groups of registers to describe it: the first group
is the high and low temperature threshold setting register; the second
group is the temperature output register.
It is true that this fix will cause ABI corruption, but it is necessary
otherwise the Loongson-2K2000 temperature sensor will not work properly.
Fixes: 72684d99a854 ("thermal: dt-bindings: add loongson-2 thermal")
Cc: Yinbo Zhu <zhuyinbo@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
---
.../thermal/loongson,ls2k-thermal.yaml | 23 +++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
index 9748a479dcd4..ca81c8afba79 100644
--- a/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
@@ -18,14 +18,15 @@ properties:
oneOf:
- enum:
- loongson,ls2k1000-thermal
+ - loongson,ls2k2000-thermal
- items:
- enum:
- loongson,ls2k0500-thermal
- - loongson,ls2k2000-thermal
- const: loongson,ls2k1000-thermal
reg:
- maxItems: 1
+ minItems: 1
+ maxItems: 2
interrupts:
maxItems: 1
@@ -39,6 +40,24 @@ required:
- interrupts
- '#thermal-sensor-cells'
+if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - loongson,ls2k2000-thermal
+
+then:
+ properties:
+ reg:
+ minItems: 2
+ maxItems: 2
+
+else:
+ properties:
+ reg:
+ maxItems: 1
+
unevaluatedProperties: false
examples:
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support
2024-04-20 1:45 [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support Binbin Zhou
` (2 preceding siblings ...)
2024-04-20 1:45 ` [PATCH v3 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Fix incorrect compatible definition Binbin Zhou
@ 2024-04-20 1:46 ` Binbin Zhou
2024-04-22 10:42 ` Daniel Lezcano
3 siblings, 1 reply; 9+ messages in thread
From: Binbin Zhou @ 2024-04-20 1:46 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch, Binbin Zhou
The Loongson-2K2000 and Loongson-2K1000 have similar thermal sensors,
except that the temperature is read differently.
In particular, the temperature output registers of the Loongson-2K2000
are defined in the chip configuration domain and are read in a different
way.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
---
drivers/thermal/loongson2_thermal.c | 50 +++++++++++++++++++++++------
1 file changed, 40 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
index 7de01fbea801..8ecd8ed465ec 100644
--- a/drivers/thermal/loongson2_thermal.c
+++ b/drivers/thermal/loongson2_thermal.c
@@ -30,12 +30,20 @@
LOONGSON2_THSENS_INT_HIGH)
#define LOONGSON2_THSENS_OUT_MASK 0xFF
+/*
+ * This flag is used to indicate the temperature reading
+ * method of the Loongson-2K2000
+ */
+#define LS2K2000_THSENS_OUT_FLAG BIT(0)
+
struct loongson2_thermal_chip_data {
unsigned int thermal_sensor_sel;
+ unsigned int flags;
};
struct loongson2_thermal_data {
- void __iomem *regs;
+ void __iomem *ctrl_reg;
+ void __iomem *temp_reg;
const struct loongson2_thermal_chip_data *chip_data;
};
@@ -48,7 +56,7 @@ static void loongson2_set_ctrl_regs(struct loongson2_thermal_data *data,
reg_ctrl = ctrl_data + HECTO;
reg_ctrl |= enable ? 0x100 : 0;
- writew(reg_ctrl, data->regs + ctrl_reg + reg_off);
+ writew(reg_ctrl, data->ctrl_reg + ctrl_reg + reg_off);
}
static int loongson2_thermal_set(struct loongson2_thermal_data *data,
@@ -65,11 +73,16 @@ static int loongson2_thermal_set(struct loongson2_thermal_data *data,
static int loongson2_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
- u32 reg_val;
+ int val;
struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
- reg_val = readl(data->regs + LOONGSON2_THSENS_OUT_REG);
- *temp = ((reg_val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
+ if (data->chip_data->flags) {
+ val = readl(data->temp_reg);
+ *temp = ((val & 0xffff) * 820 / 0x4000 - 311) * KILO;
+ } else {
+ val = readl(data->ctrl_reg + LOONGSON2_THSENS_OUT_REG);
+ *temp = ((val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
+ }
return 0;
}
@@ -79,7 +92,7 @@ static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
struct thermal_zone_device *tzd = dev;
struct loongson2_thermal_data *data = thermal_zone_device_priv(tzd);
- writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
+ writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
thermal_zone_device_update(tzd, THERMAL_EVENT_UNSPECIFIED);
@@ -111,15 +124,22 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
data->chip_data = device_get_match_data(dev);
- data->regs = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(data->regs))
- return PTR_ERR(data->regs);
+ data->ctrl_reg = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(data->ctrl_reg))
+ return PTR_ERR(data->ctrl_reg);
+
+ /* The temperature output register is separate for Loongson-2K2000 */
+ if (data->chip_data->flags) {
+ data->temp_reg = devm_platform_ioremap_resource(pdev, 1);
+ if (IS_ERR(data->temp_reg))
+ return PTR_ERR(data->temp_reg);
+ }
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
- writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
+ writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
loongson2_thermal_set(data, 0, 0, false);
@@ -146,6 +166,12 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
.thermal_sensor_sel = 0,
+ .flags = 0,
+};
+
+static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k2000_data = {
+ .thermal_sensor_sel = 0,
+ .flags = LS2K2000_THSENS_OUT_FLAG,
};
static const struct of_device_id of_loongson2_thermal_match[] = {
@@ -153,6 +179,10 @@ static const struct of_device_id of_loongson2_thermal_match[] = {
.compatible = "loongson,ls2k1000-thermal",
.data = &loongson2_thermal_ls2k1000_data,
},
+ {
+ .compatible = "loongson,ls2k2000-thermal",
+ .data = &loongson2_thermal_ls2k2000_data,
+ },
{ /* end */ }
};
MODULE_DEVICE_TABLE(of, of_loongson2_thermal_match);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment
2024-04-20 1:45 ` [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment Binbin Zhou
@ 2024-04-22 9:44 ` Daniel Lezcano
2024-04-22 11:04 ` Binbin Zhou
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Lezcano @ 2024-04-22 9:44 UTC (permalink / raw)
To: Binbin Zhou, Binbin Zhou, Huacai Chen, Rafael J . Wysocki,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch
On 20/04/2024 03:45, Binbin Zhou wrote:
> Here are some minor code style adjustment. Such as fix whitespace code
> style; align function call arguments to opening parenthesis, and add
> devm_thermal_add_hwmon_sysfs() return value checking.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> Acked-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
[ ... ]
> }
>
> ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
> - IRQF_ONESHOT, "loongson2_thermal", tzd);
> + IRQF_ONESHOT, "loongson2_thermal", tzd);
> if (ret < 0)
> return dev_err_probe(dev, ret, "failed to request alarm irq\n");
>
> - devm_thermal_add_hwmon_sysfs(dev, tzd);
> -
> - return 0;
> + return devm_thermal_add_hwmon_sysfs(dev, tzd);
You may not want to do this change. If the devm_thermal_add_hwmon_sysfs
function fails, that does not jeopardize the initialization of this driver.
> }
>
> static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
> @@ -167,4 +167,5 @@ static struct platform_driver loongson2_thermal_driver = {
> module_platform_driver(loongson2_thermal_driver);
>
> MODULE_DESCRIPTION("Loongson2 thermal driver");
> +MODULE_AUTHOR("Loongson Technology Corporation Limited");
> MODULE_LICENSE("GPL");
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support
2024-04-20 1:46 ` [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support Binbin Zhou
@ 2024-04-22 10:42 ` Daniel Lezcano
2024-04-22 11:08 ` Binbin Zhou
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Lezcano @ 2024-04-22 10:42 UTC (permalink / raw)
To: Binbin Zhou, Binbin Zhou, Huacai Chen, Rafael J . Wysocki,
Amit Kucheria, Zhang Rui, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch
On 20/04/2024 03:46, Binbin Zhou wrote:
> The Loongson-2K2000 and Loongson-2K1000 have similar thermal sensors,
> except that the temperature is read differently.
>
> In particular, the temperature output registers of the Loongson-2K2000
> are defined in the chip configuration domain and are read in a different
> way.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> Acked-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> drivers/thermal/loongson2_thermal.c | 50 +++++++++++++++++++++++------
> 1 file changed, 40 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> index 7de01fbea801..8ecd8ed465ec 100644
> --- a/drivers/thermal/loongson2_thermal.c
> +++ b/drivers/thermal/loongson2_thermal.c
> @@ -30,12 +30,20 @@
> LOONGSON2_THSENS_INT_HIGH)
> #define LOONGSON2_THSENS_OUT_MASK 0xFF
>
> +/*
> + * This flag is used to indicate the temperature reading
> + * method of the Loongson-2K2000
> + */
> +#define LS2K2000_THSENS_OUT_FLAG BIT(0)
> +
> struct loongson2_thermal_chip_data {
> unsigned int thermal_sensor_sel;
> + unsigned int flags;
> };
>
> struct loongson2_thermal_data {
> - void __iomem *regs;
> + void __iomem *ctrl_reg;
> + void __iomem *temp_reg;
> const struct loongson2_thermal_chip_data *chip_data;
> };
>
> @@ -48,7 +56,7 @@ static void loongson2_set_ctrl_regs(struct loongson2_thermal_data *data,
>
> reg_ctrl = ctrl_data + HECTO;
> reg_ctrl |= enable ? 0x100 : 0;
> - writew(reg_ctrl, data->regs + ctrl_reg + reg_off);
> + writew(reg_ctrl, data->ctrl_reg + ctrl_reg + reg_off);
> }
>
> static int loongson2_thermal_set(struct loongson2_thermal_data *data,
> @@ -65,11 +73,16 @@ static int loongson2_thermal_set(struct loongson2_thermal_data *data,
>
> static int loongson2_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
> {
> - u32 reg_val;
> + int val;
> struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
>
> - reg_val = readl(data->regs + LOONGSON2_THSENS_OUT_REG);
> - *temp = ((reg_val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
> + if (data->chip_data->flags) {
> + val = readl(data->temp_reg);
> + *temp = ((val & 0xffff) * 820 / 0x4000 - 311) * KILO;
> + } else {
> + val = readl(data->ctrl_reg + LOONGSON2_THSENS_OUT_REG);
> + *temp = ((val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
> + }
Why not use a different ops. That will keep the code cleaner for the
next sensor versions.
For example:
static int loongson2_2k2000_get_temp(...)
{
}
static int loongson2_2k1000_get_temp(...)
{
}
static struct thermal_zone_device_ops loongson2_of_thermal_ops = {
.get_temp = loongson2_2k1000_get_temp,
.set_trips = loongson2_thermal_set_trips,
};
loongson2_thermal_probe
{
...
if (data->chip_data->flags & LS2K2000_THSENS_OUT_FLAG)
loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp;
...
}
> return 0;
> }
> @@ -79,7 +92,7 @@ static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
> struct thermal_zone_device *tzd = dev;
> struct loongson2_thermal_data *data = thermal_zone_device_priv(tzd);
>
> - writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
> + writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
>
> thermal_zone_device_update(tzd, THERMAL_EVENT_UNSPECIFIED);
>
> @@ -111,15 +124,22 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
>
> data->chip_data = device_get_match_data(dev);
>
> - data->regs = devm_platform_ioremap_resource(pdev, 0);
> - if (IS_ERR(data->regs))
> - return PTR_ERR(data->regs);
> + data->ctrl_reg = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(data->ctrl_reg))
> + return PTR_ERR(data->ctrl_reg);
> +
> + /* The temperature output register is separate for Loongson-2K2000 */
> + if (data->chip_data->flags) {
> + data->temp_reg = devm_platform_ioremap_resource(pdev, 1);
> + if (IS_ERR(data->temp_reg))
> + return PTR_ERR(data->temp_reg);
> + }
>
> irq = platform_get_irq(pdev, 0);
> if (irq < 0)
> return irq;
>
> - writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
> + writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
>
> loongson2_thermal_set(data, 0, 0, false);
>
> @@ -146,6 +166,12 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
>
> static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
> .thermal_sensor_sel = 0,
> + .flags = 0,
> +};
> +
> +static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k2000_data = {
> + .thermal_sensor_sel = 0,
> + .flags = LS2K2000_THSENS_OUT_FLAG,
> };
>
> static const struct of_device_id of_loongson2_thermal_match[] = {
> @@ -153,6 +179,10 @@ static const struct of_device_id of_loongson2_thermal_match[] = {
> .compatible = "loongson,ls2k1000-thermal",
> .data = &loongson2_thermal_ls2k1000_data,
> },
> + {
> + .compatible = "loongson,ls2k2000-thermal",
> + .data = &loongson2_thermal_ls2k2000_data,
> + },
> { /* end */ }
> };
> MODULE_DEVICE_TABLE(of, of_loongson2_thermal_match);
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment
2024-04-22 9:44 ` Daniel Lezcano
@ 2024-04-22 11:04 ` Binbin Zhou
0 siblings, 0 replies; 9+ messages in thread
From: Binbin Zhou @ 2024-04-22 11:04 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Amit Kucheria,
Zhang Rui, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch
On Mon, Apr 22, 2024 at 5:44 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 20/04/2024 03:45, Binbin Zhou wrote:
> > Here are some minor code style adjustment. Such as fix whitespace code
> > style; align function call arguments to opening parenthesis, and add
> > devm_thermal_add_hwmon_sysfs() return value checking.
> >
> > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > Acked-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
>
> [ ... ]
>
> > }
> >
> > ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
> > - IRQF_ONESHOT, "loongson2_thermal", tzd);
> > + IRQF_ONESHOT, "loongson2_thermal", tzd);
> > if (ret < 0)
> > return dev_err_probe(dev, ret, "failed to request alarm irq\n");
> >
> > - devm_thermal_add_hwmon_sysfs(dev, tzd);
> > -
> > - return 0;
> > + return devm_thermal_add_hwmon_sysfs(dev, tzd);
>
> You may not want to do this change. If the devm_thermal_add_hwmon_sysfs
> function fails, that does not jeopardize the initialization of this driver.
>
Hi Daniel:
Okay, it would seem to make more sense not to make the change.
I'll remove the change in the next version.
Thanks.
Binbin
>
> > }
> >
> > static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
> > @@ -167,4 +167,5 @@ static struct platform_driver loongson2_thermal_driver = {
> > module_platform_driver(loongson2_thermal_driver);
> >
> > MODULE_DESCRIPTION("Loongson2 thermal driver");
> > +MODULE_AUTHOR("Loongson Technology Corporation Limited");
> > MODULE_LICENSE("GPL");
>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support
2024-04-22 10:42 ` Daniel Lezcano
@ 2024-04-22 11:08 ` Binbin Zhou
0 siblings, 0 replies; 9+ messages in thread
From: Binbin Zhou @ 2024-04-22 11:08 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Binbin Zhou, Huacai Chen, Rafael J . Wysocki, Amit Kucheria,
Zhang Rui, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Huacai Chen, loongson-kernel, linux-pm, devicetree, Yinbo Zhu,
WANG Xuerui, loongarch
On Mon, Apr 22, 2024 at 6:42 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 20/04/2024 03:46, Binbin Zhou wrote:
> > The Loongson-2K2000 and Loongson-2K1000 have similar thermal sensors,
> > except that the temperature is read differently.
> >
> > In particular, the temperature output registers of the Loongson-2K2000
> > are defined in the chip configuration domain and are read in a different
> > way.
> >
> > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> > Acked-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> > drivers/thermal/loongson2_thermal.c | 50 +++++++++++++++++++++++------
> > 1 file changed, 40 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
> > index 7de01fbea801..8ecd8ed465ec 100644
> > --- a/drivers/thermal/loongson2_thermal.c
> > +++ b/drivers/thermal/loongson2_thermal.c
> > @@ -30,12 +30,20 @@
> > LOONGSON2_THSENS_INT_HIGH)
> > #define LOONGSON2_THSENS_OUT_MASK 0xFF
> >
> > +/*
> > + * This flag is used to indicate the temperature reading
> > + * method of the Loongson-2K2000
> > + */
> > +#define LS2K2000_THSENS_OUT_FLAG BIT(0)
> > +
> > struct loongson2_thermal_chip_data {
> > unsigned int thermal_sensor_sel;
> > + unsigned int flags;
> > };
> >
> > struct loongson2_thermal_data {
> > - void __iomem *regs;
> > + void __iomem *ctrl_reg;
> > + void __iomem *temp_reg;
> > const struct loongson2_thermal_chip_data *chip_data;
> > };
> >
> > @@ -48,7 +56,7 @@ static void loongson2_set_ctrl_regs(struct loongson2_thermal_data *data,
> >
> > reg_ctrl = ctrl_data + HECTO;
> > reg_ctrl |= enable ? 0x100 : 0;
> > - writew(reg_ctrl, data->regs + ctrl_reg + reg_off);
> > + writew(reg_ctrl, data->ctrl_reg + ctrl_reg + reg_off);
> > }
> >
> > static int loongson2_thermal_set(struct loongson2_thermal_data *data,
> > @@ -65,11 +73,16 @@ static int loongson2_thermal_set(struct loongson2_thermal_data *data,
> >
> > static int loongson2_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
> > {
> > - u32 reg_val;
> > + int val;
> > struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
> >
> > - reg_val = readl(data->regs + LOONGSON2_THSENS_OUT_REG);
> > - *temp = ((reg_val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
> > + if (data->chip_data->flags) {
> > + val = readl(data->temp_reg);
> > + *temp = ((val & 0xffff) * 820 / 0x4000 - 311) * KILO;
> > + } else {
> > + val = readl(data->ctrl_reg + LOONGSON2_THSENS_OUT_REG);
> > + *temp = ((val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
> > + }
>
> Why not use a different ops. That will keep the code cleaner for the
> next sensor versions.
>
> For example:
>
> static int loongson2_2k2000_get_temp(...)
> {
> }
>
> static int loongson2_2k1000_get_temp(...)
> {
> }
>
> static struct thermal_zone_device_ops loongson2_of_thermal_ops = {
> .get_temp = loongson2_2k1000_get_temp,
> .set_trips = loongson2_thermal_set_trips,
> };
>
>
> loongson2_thermal_probe
> {
> ...
>
> if (data->chip_data->flags & LS2K2000_THSENS_OUT_FLAG)
> loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp;
> ...
>
> }
Hi Daniel:
Thanks for your advice.
I'll use a different ops to keep the code cleaner in the next version,
Thanks.
Binbin
>
> > return 0;
> > }
> > @@ -79,7 +92,7 @@ static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
> > struct thermal_zone_device *tzd = dev;
> > struct loongson2_thermal_data *data = thermal_zone_device_priv(tzd);
> >
> > - writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
> > + writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
> >
> > thermal_zone_device_update(tzd, THERMAL_EVENT_UNSPECIFIED);
> >
> > @@ -111,15 +124,22 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
> >
> > data->chip_data = device_get_match_data(dev);
> >
> > - data->regs = devm_platform_ioremap_resource(pdev, 0);
> > - if (IS_ERR(data->regs))
> > - return PTR_ERR(data->regs);
> > + data->ctrl_reg = devm_platform_ioremap_resource(pdev, 0);
> > + if (IS_ERR(data->ctrl_reg))
> > + return PTR_ERR(data->ctrl_reg);
> > +
> > + /* The temperature output register is separate for Loongson-2K2000 */
> > + if (data->chip_data->flags) {
> > + data->temp_reg = devm_platform_ioremap_resource(pdev, 1);
> > + if (IS_ERR(data->temp_reg))
> > + return PTR_ERR(data->temp_reg);
> > + }
> >
> > irq = platform_get_irq(pdev, 0);
> > if (irq < 0)
> > return irq;
> >
> > - writeb(LOONGSON2_THSENS_INT_EN, data->regs + LOONGSON2_THSENS_STATUS_REG);
> > + writeb(LOONGSON2_THSENS_INT_EN, data->ctrl_reg + LOONGSON2_THSENS_STATUS_REG);
> >
> > loongson2_thermal_set(data, 0, 0, false);
> >
> > @@ -146,6 +166,12 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
> >
> > static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
> > .thermal_sensor_sel = 0,
> > + .flags = 0,
> > +};
> > +
> > +static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k2000_data = {
> > + .thermal_sensor_sel = 0,
> > + .flags = LS2K2000_THSENS_OUT_FLAG,
> > };
> >
> > static const struct of_device_id of_loongson2_thermal_match[] = {
> > @@ -153,6 +179,10 @@ static const struct of_device_id of_loongson2_thermal_match[] = {
> > .compatible = "loongson,ls2k1000-thermal",
> > .data = &loongson2_thermal_ls2k1000_data,
> > },
> > + {
> > + .compatible = "loongson,ls2k2000-thermal",
> > + .data = &loongson2_thermal_ls2k2000_data,
> > + },
> > { /* end */ }
> > };
> > MODULE_DEVICE_TABLE(of, of_loongson2_thermal_match);
>
> --
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-04-22 11:08 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-20 1:45 [PATCH v3 0/4] thermal: loongson2: Add Loongson-2K0500 and Loongson-2K2000 thermal support Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 1/4] thermal: loongson2: Trivial code style adjustment Binbin Zhou
2024-04-22 9:44 ` Daniel Lezcano
2024-04-22 11:04 ` Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 2/4] dt-bindings: thermal: loongson,ls2k-thermal: Add Loongson-2K0500 compatible Binbin Zhou
2024-04-20 1:45 ` [PATCH v3 3/4] dt-bindings: thermal: loongson,ls2k-thermal: Fix incorrect compatible definition Binbin Zhou
2024-04-20 1:46 ` [PATCH v3 4/4] thermal: loongson2: Add Loongson-2K2000 support Binbin Zhou
2024-04-22 10:42 ` Daniel Lezcano
2024-04-22 11:08 ` Binbin Zhou
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.