Skip to content

Commit 0ca4080

Browse files
committed
Merge tag 'thermal-6.6-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more thermal control updates from Rafael Wysocki: "These are mostly updates of thermal control drivers for ARM platforms, new thermal control support for Loongson-2 and a couple of core cleanups made possible by recent changes merged previously. Specifics: - Check if the Tegra BPMP supports the trip points in order to set the .set_trips callback (Mikko Perttunen) - Add new Loongson-2 thermal sensor along with the DT bindings (Yinbo Zhu) - Use IS_ERR_OR_NULL() helper to replace a double test on the TI bandgap sensor (Li Zetao) - Remove redundant platform_set_drvdata() calls, as there are no corresponding calls to platform_get_drvdata(), from a bunch of drivers (Andrei Coardos) - Switch the Mediatek LVTS mode to filtered in order to enable interrupts (Nícolas F. R. A. Prado) - Fix Wvoid-pointer-to-enum-cast warning on the Exynos TMU (Krzysztof Kozlowski) - Remove redundant dev_err_probe(), because the underlying function already called it, from the Mediatek sensor (Chen Jiahao) - Free calibration nvmem after reading it on sun8i (Mark Brown) - Remove useless comment from the sun8i driver (Yangtao Li) - Make tsens_xxxx_nvmem static to fix a sparse warning on QCom tsens (Min-Hua Chen) - Remove error message at probe deferral on imx8mm (Ahmad Fatoum) - Fix parameter check in lvts_debugfs_init() with IS_ERR() on Mediatek LVTS (Minjie Du) - Fix interrupt routine and configuratoin for Mediatek LVTS (Nícolas F. R. A. Prado) - Drop unused .get_trip_type(), .get_trip_temp() and .get_trip_hyst() thermal zone callbacks from the core and rework the .get_trend() one to take a trip point pointer as an argument (Rafael Wysocki)" * tag 'thermal-6.6-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (29 commits) thermal: core: Rework .get_trend() thermal zone callback thermal: core: Drop unused .get_trip_*() callbacks thermal/drivers/tegra-bpmp: Check if BPMP supports trip points thermal: dt-bindings: add loongson-2 thermal thermal/drivers/loongson-2: Add thermal management support thermal/drivers/ti-soc-thermal: Use helper function IS_ERR_OR_NULL() thermal/drivers/generic-adc: Removed unneeded call to platform_set_drvdata() thermal/drivers/max77620_thermal: Removed unneeded call to platform_set_drvdata() thermal/drivers/mediatek/auxadc_thermal: Removed call to platform_set_drvdata() thermal/drivers/sun8i_thermal: Remove unneeded call to platform_set_drvdata() thermal/drivers/broadcom/brcstb_thermal: Removed unneeded platform_set_drvdata() thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode thermal/drivers/k3_bandgap: Remove unneeded call to platform_set_drvdata() thermal/drivers/k3_j72xx_bandgap: Removed unneeded call to platform_set_drvdata() thermal/drivers/broadcom/sr-thermal: Removed call to platform_set_drvdata() thermal/drivers/samsung: Fix Wvoid-pointer-to-enum-cast warning thermal/drivers/db8500: Remove redundant of_match_ptr() thermal/drivers/mediatek: Clean up redundant dev_err_probe() thermal/drivers/sun8i: Free calibration nvmem after reading it thermal/drivers/sun8i: Remove unneeded comments ...
2 parents 2a3a850 + 8289d81 commit 0ca4080

28 files changed

+468
-140
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/thermal/loongson,ls2k-thermal.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Thermal sensors on Loongson-2 SoCs
8+
9+
maintainers:
10+
- zhanghongchen <[email protected]>
11+
- Yinbo Zhu <[email protected]>
12+
13+
properties:
14+
compatible:
15+
oneOf:
16+
- enum:
17+
- loongson,ls2k1000-thermal
18+
- items:
19+
- enum:
20+
- loongson,ls2k2000-thermal
21+
- const: loongson,ls2k1000-thermal
22+
23+
reg:
24+
maxItems: 1
25+
26+
interrupts:
27+
maxItems: 1
28+
29+
required:
30+
- compatible
31+
- reg
32+
- interrupts
33+
34+
additionalProperties: false
35+
36+
examples:
37+
- |
38+
#include <dt-bindings/interrupt-controller/irq.h>
39+
thermal: thermal-sensor@1fe01500 {
40+
compatible = "loongson,ls2k1000-thermal";
41+
reg = <0x1fe01500 0x30>;
42+
interrupt-parent = <&liointc0>;
43+
interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
44+
};

MAINTAINERS

+8
Original file line numberDiff line numberDiff line change
@@ -12390,6 +12390,14 @@ S: Maintained
1239012390
F: Documentation/devicetree/bindings/pinctrl/loongson,ls2k-pinctrl.yaml
1239112391
F: drivers/pinctrl/pinctrl-loongson2.c
1239212392

12393+
LOONGSON-2 SOC SERIES THERMAL DRIVER
12394+
M: zhanghongchen <[email protected]>
12395+
M: Yinbo Zhu <[email protected]>
12396+
12397+
S: Maintained
12398+
F: Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml
12399+
F: drivers/thermal/loongson2_thermal.c
12400+
1239312401
LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI)
1239412402
M: Sathya Prakash <[email protected]>
1239512403
M: Sreekanth Reddy <[email protected]>

drivers/acpi/thermal.c

+18-23
Original file line numberDiff line numberDiff line change
@@ -492,26 +492,22 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
492492
}
493493

494494
static int thermal_get_trend(struct thermal_zone_device *thermal,
495-
int trip_index, enum thermal_trend *trend)
495+
struct thermal_trip *trip,
496+
enum thermal_trend *trend)
496497
{
497498
struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
498499
struct acpi_thermal_trip *acpi_trip;
499-
int t, i;
500+
int t;
500501

501-
if (!tz || trip_index < 0)
502+
if (!tz || !trip)
502503
return -EINVAL;
503504

504-
if (tz->trips.critical.valid)
505-
trip_index--;
506-
507-
if (tz->trips.hot.valid)
508-
trip_index--;
509-
510-
if (trip_index < 0)
505+
acpi_trip = trip->priv;
506+
if (!acpi_trip || !acpi_trip->valid)
511507
return -EINVAL;
512508

513-
acpi_trip = &tz->trips.passive.trip;
514-
if (acpi_trip->valid && !trip_index--) {
509+
switch (trip->type) {
510+
case THERMAL_TRIP_PASSIVE:
515511
t = tz->trips.passive.tc1 * (tz->temperature -
516512
tz->last_temperature) +
517513
tz->trips.passive.tc2 * (tz->temperature -
@@ -524,19 +520,18 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
524520
*trend = THERMAL_TREND_STABLE;
525521

526522
return 0;
527-
}
528-
529-
t = acpi_thermal_temp(tz, tz->temperature);
530523

531-
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
532-
acpi_trip = &tz->trips.active[i].trip;
533-
if (acpi_trip->valid && !trip_index--) {
534-
if (t > acpi_thermal_temp(tz, acpi_trip->temperature)) {
535-
*trend = THERMAL_TREND_RAISING;
536-
return 0;
537-
}
524+
case THERMAL_TRIP_ACTIVE:
525+
t = acpi_thermal_temp(tz, tz->temperature);
526+
if (t <= trip->temperature)
538527
break;
539-
}
528+
529+
*trend = THERMAL_TREND_RAISING;
530+
531+
return 0;
532+
533+
default:
534+
break;
540535
}
541536

542537
return -EINVAL;

drivers/thermal/Kconfig

+12
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,16 @@ config KHADAS_MCU_FAN_THERMAL
510510
If you say yes here you get support for the FAN controlled
511511
by the Microcontroller found on the Khadas VIM boards.
512512

513+
config LOONGSON2_THERMAL
514+
tristate "Loongson-2 SoC series thermal driver"
515+
depends on LOONGARCH || COMPILE_TEST
516+
depends on OF
517+
help
518+
Support for Thermal driver found on Loongson-2 SoC series platforms.
519+
The thermal driver realizes get_temp and set_trips function, which
520+
are used to obtain the temperature of the current node and set the
521+
temperature range to trigger the interrupt. When the input temperature
522+
is higher than the high temperature threshold or lower than the low
523+
temperature threshold, the interrupt will occur.
524+
513525
endif

drivers/thermal/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o
6363
obj-$(CONFIG_AMLOGIC_THERMAL) += amlogic_thermal.o
6464
obj-$(CONFIG_SPRD_THERMAL) += sprd_thermal.o
6565
obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL) += khadas_mcu_fan.o
66+
obj-$(CONFIG_LOONGSON2_THERMAL) += loongson2_thermal.o

drivers/thermal/broadcom/brcmstb_thermal.c

-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ static int brcmstb_thermal_probe(struct platform_device *pdev)
334334
return PTR_ERR(priv->tmon_base);
335335

336336
priv->dev = &pdev->dev;
337-
platform_set_drvdata(pdev, priv);
338337
of_ops = priv->temp_params->of_ops;
339338

340339
thermal = devm_thermal_of_zone_register(&pdev->dev, 0, priv,

drivers/thermal/broadcom/sr-thermal.c

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ static int sr_thermal_probe(struct platform_device *pdev)
9191

9292
dev_dbg(dev, "thermal sensor %d registered\n", i);
9393
}
94-
platform_set_drvdata(pdev, sr_thermal);
9594

9695
return 0;
9796
}

drivers/thermal/db8500_thermal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ MODULE_DEVICE_TABLE(of, db8500_thermal_match);
229229
static struct platform_driver db8500_thermal_driver = {
230230
.driver = {
231231
.name = "db8500-thermal",
232-
.of_match_table = of_match_ptr(db8500_thermal_match),
232+
.of_match_table = db8500_thermal_match,
233233
},
234234
.probe = db8500_thermal_probe,
235235
.suspend = db8500_thermal_suspend,

drivers/thermal/imx8mm_thermal.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ static int imx8mm_tmu_probe_set_calib_v1(struct platform_device *pdev,
178178
int ret;
179179

180180
ret = nvmem_cell_read_u32(&pdev->dev, "calib", &ana0);
181-
if (ret) {
182-
dev_warn(dev, "Failed to read OCOTP nvmem cell (%d).\n", ret);
183-
return ret;
184-
}
181+
if (ret)
182+
return dev_err_probe(dev, ret, "Failed to read OCOTP nvmem cell\n");
185183

186184
writel(FIELD_PREP(TASR_BUF_VREF_MASK,
187185
FIELD_GET(ANA0_BUF_VREF_MASK, ana0)) |

drivers/thermal/k3_bandgap.c

-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ static int k3_bandgap_probe(struct platform_device *pdev)
225225
devm_thermal_add_hwmon_sysfs(dev, data[id].tzd);
226226
}
227227

228-
platform_set_drvdata(pdev, bgp);
229228

230229
return 0;
231230

drivers/thermal/k3_j72xx_bandgap.c

-2
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
502502
writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
503503
K3_VTM_MISC_CTRL_OFFSET);
504504

505-
platform_set_drvdata(pdev, bgp);
506-
507505
print_look_up_table(dev, ref_table);
508506
/*
509507
* Now that the derived_table has the appropriate look up values

drivers/thermal/loongson2_thermal.c

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Author: zhanghongchen <[email protected]>
4+
* Yinbo Zhu <[email protected]>
5+
* Copyright (C) 2022-2023 Loongson Technology Corporation Limited
6+
*/
7+
8+
#include <linux/interrupt.h>
9+
#include <linux/io.h>
10+
#include <linux/minmax.h>
11+
#include <linux/module.h>
12+
#include <linux/of_device.h>
13+
#include <linux/platform_device.h>
14+
#include <linux/thermal.h>
15+
#include <linux/units.h>
16+
#include "thermal_hwmon.h"
17+
18+
#define LOONGSON2_MAX_SENSOR_SEL_NUM 3
19+
20+
#define LOONGSON2_THSENS_CTRL_HI_REG 0x0
21+
#define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
22+
#define LOONGSON2_THSENS_STATUS_REG 0x10
23+
#define LOONGSON2_THSENS_OUT_REG 0x14
24+
25+
#define LOONGSON2_THSENS_INT_LO BIT(0)
26+
#define LOONGSON2_THSENS_INT_HIGH BIT(1)
27+
#define LOONGSON2_THSENS_OUT_MASK 0xFF
28+
29+
struct loongson2_thermal_chip_data {
30+
unsigned int thermal_sensor_sel;
31+
};
32+
33+
struct loongson2_thermal_data {
34+
void __iomem *regs;
35+
const struct loongson2_thermal_chip_data *chip_data;
36+
};
37+
38+
static int loongson2_thermal_set(struct loongson2_thermal_data *data,
39+
int low, int high, bool enable)
40+
{
41+
u64 reg_ctrl = 0;
42+
int reg_off = data->chip_data->thermal_sensor_sel * 2;
43+
44+
low = clamp(-40, low, high);
45+
high = clamp(125, low, high);
46+
47+
low += HECTO;
48+
high += HECTO;
49+
50+
reg_ctrl = low;
51+
reg_ctrl |= enable ? 0x100 : 0;
52+
writew(reg_ctrl, data->regs + LOONGSON2_THSENS_CTRL_LOW_REG + reg_off);
53+
54+
reg_ctrl = high;
55+
reg_ctrl |= enable ? 0x100 : 0;
56+
writew(reg_ctrl, data->regs + LOONGSON2_THSENS_CTRL_HI_REG + reg_off);
57+
58+
return 0;
59+
}
60+
61+
static int loongson2_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
62+
{
63+
u32 reg_val;
64+
struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
65+
66+
reg_val = readl(data->regs + LOONGSON2_THSENS_OUT_REG);
67+
*temp = ((reg_val & LOONGSON2_THSENS_OUT_MASK) - HECTO) * KILO;
68+
69+
return 0;
70+
}
71+
72+
static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
73+
{
74+
struct thermal_zone_device *tzd = dev;
75+
struct loongson2_thermal_data *data = thermal_zone_device_priv(tzd);
76+
77+
writeb(LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH, data->regs +
78+
LOONGSON2_THSENS_STATUS_REG);
79+
80+
thermal_zone_device_update(tzd, THERMAL_EVENT_UNSPECIFIED);
81+
82+
return IRQ_HANDLED;
83+
}
84+
85+
static int loongson2_thermal_set_trips(struct thermal_zone_device *tz, int low, int high)
86+
{
87+
struct loongson2_thermal_data *data = thermal_zone_device_priv(tz);
88+
89+
return loongson2_thermal_set(data, low/MILLI, high/MILLI, true);
90+
}
91+
92+
static const struct thermal_zone_device_ops loongson2_of_thermal_ops = {
93+
.get_temp = loongson2_thermal_get_temp,
94+
.set_trips = loongson2_thermal_set_trips,
95+
};
96+
97+
static int loongson2_thermal_probe(struct platform_device *pdev)
98+
{
99+
struct device *dev = &pdev->dev;
100+
struct loongson2_thermal_data *data;
101+
struct thermal_zone_device *tzd;
102+
int ret, irq, i;
103+
104+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
105+
if (!data)
106+
return -ENOMEM;
107+
108+
data->chip_data = device_get_match_data(dev);
109+
110+
data->regs = devm_platform_ioremap_resource(pdev, 0);
111+
if (IS_ERR(data->regs))
112+
return PTR_ERR(data->regs);
113+
114+
irq = platform_get_irq(pdev, 0);
115+
if (irq < 0)
116+
return irq;
117+
118+
writeb(LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH, data->regs +
119+
LOONGSON2_THSENS_STATUS_REG);
120+
121+
loongson2_thermal_set(data, 0, 0, false);
122+
123+
for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
124+
tzd = devm_thermal_of_zone_register(dev, i, data,
125+
&loongson2_of_thermal_ops);
126+
127+
if (!IS_ERR(tzd))
128+
break;
129+
130+
if (PTR_ERR(tzd) != ENODEV)
131+
continue;
132+
133+
return dev_err_probe(dev, PTR_ERR(tzd), "failed to register");
134+
}
135+
136+
ret = devm_request_threaded_irq(dev, irq, NULL, loongson2_thermal_irq_thread,
137+
IRQF_ONESHOT, "loongson2_thermal", tzd);
138+
if (ret < 0)
139+
return dev_err_probe(dev, ret, "failed to request alarm irq\n");
140+
141+
devm_thermal_add_hwmon_sysfs(dev, tzd);
142+
143+
return 0;
144+
}
145+
146+
static const struct loongson2_thermal_chip_data loongson2_thermal_ls2k1000_data = {
147+
.thermal_sensor_sel = 0,
148+
};
149+
150+
static const struct of_device_id of_loongson2_thermal_match[] = {
151+
{
152+
.compatible = "loongson,ls2k1000-thermal",
153+
.data = &loongson2_thermal_ls2k1000_data,
154+
},
155+
{ /* end */ }
156+
};
157+
MODULE_DEVICE_TABLE(of, of_loongson2_thermal_match);
158+
159+
static struct platform_driver loongson2_thermal_driver = {
160+
.driver = {
161+
.name = "loongson2_thermal",
162+
.of_match_table = of_loongson2_thermal_match,
163+
},
164+
.probe = loongson2_thermal_probe,
165+
};
166+
module_platform_driver(loongson2_thermal_driver);
167+
168+
MODULE_DESCRIPTION("Loongson2 thermal driver");
169+
MODULE_LICENSE("GPL");

drivers/thermal/max77620_thermal.c

-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
139139
return ret;
140140
}
141141

142-
platform_set_drvdata(pdev, mtherm);
143-
144142
return 0;
145143
}
146144

drivers/thermal/mediatek/auxadc_thermal.c

-2
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,6 @@ static int mtk_thermal_probe(struct platform_device *pdev)
12821282
mtk_thermal_init_bank(mt, i, apmixed_phys_base,
12831283
auxadc_phys_base, ctrl_id);
12841284

1285-
platform_set_drvdata(pdev, mt);
1286-
12871285
tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt,
12881286
&mtk_thermal_ops);
12891287
if (IS_ERR(tzdev))

0 commit comments

Comments
 (0)