Skip to content

Commit 125521a

Browse files
committed
Pull thermal control material for 5.17-rc1 from Daniel Lezcano: - Fix PM issue on the iMX driver when suspend/resume is happening by implementing PM runtime support (Oleksij Rempel) - Add 'const' annotation to the thermal_cooling_ops in the Intel powerclamp driver (Rikard Falkeborn) - Add TSU driver and bindings for the RZ/G2L platform (Biju Das) - Fix missing ADC bit set on iMX8MP to enable the sensor (Paul Gerber) - Fix missing check when calling reset_control_deassert() (Biju Das) * tag 'thermal-v5.17-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux: thermal/drivers/rz2gl: Add error check for reset_control_deassert() thermal/drivers/imx8mm: Enable ADC when enabling monitor thermal/drivers: Add TSU driver for RZ/G2L dt-bindings: thermal: Document Renesas RZ/G2L TSU thermal/drivers/intel_powerclamp: Constify static thermal_cooling_device_ops thermal/drivers/imx: Implement runtime PM support
2 parents 3f0bb49 + 8ee1c0f commit 125521a

File tree

7 files changed

+423
-55
lines changed

7 files changed

+423
-55
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/thermal/rzg2l-thermal.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Renesas RZ/G2L Thermal Sensor Unit
8+
9+
description:
10+
On RZ/G2L SoCs, the thermal sensor unit (TSU) measures the
11+
temperature(Tj) inside the LSI.
12+
13+
maintainers:
14+
- Biju Das <biju.das.jz@bp.renesas.com>
15+
16+
properties:
17+
compatible:
18+
items:
19+
- enum:
20+
- renesas,r9a07g044-tsu # RZ/G2{L,LC}
21+
- const: renesas,rzg2l-tsu
22+
23+
reg:
24+
maxItems: 1
25+
26+
clocks:
27+
maxItems: 1
28+
29+
power-domains:
30+
maxItems: 1
31+
32+
resets:
33+
maxItems: 1
34+
35+
"#thermal-sensor-cells":
36+
const: 1
37+
38+
required:
39+
- compatible
40+
- reg
41+
- clocks
42+
- power-domains
43+
- resets
44+
- "#thermal-sensor-cells"
45+
46+
additionalProperties: false
47+
48+
examples:
49+
- |
50+
#include <dt-bindings/clock/r9a07g044-cpg.h>
51+
52+
tsu: thermal@10059400 {
53+
compatible = "renesas,r9a07g044-tsu",
54+
"renesas,rzg2l-tsu";
55+
reg = <0x10059400 0x400>;
56+
clocks = <&cpg CPG_MOD R9A07G044_TSU_PCLK>;
57+
resets = <&cpg R9A07G044_TSU_PRESETN>;
58+
power-domains = <&cpg>;
59+
#thermal-sensor-cells = <1>;
60+
};
61+
62+
thermal-zones {
63+
cpu-thermal {
64+
polling-delay-passive = <250>;
65+
polling-delay = <1000>;
66+
thermal-sensors = <&tsu 0>;
67+
68+
trips {
69+
sensor_crit: sensor-crit {
70+
temperature = <125000>;
71+
hysteresis = <1000>;
72+
type = "critical";
73+
};
74+
};
75+
};
76+
};

drivers/thermal/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,15 @@ config RCAR_GEN3_THERMAL
354354
Enable this to plug the R-Car Gen3 or RZ/G2 thermal sensor driver into
355355
the Linux thermal framework.
356356

357+
config RZG2L_THERMAL
358+
tristate "Renesas RZ/G2L thermal driver"
359+
depends on ARCH_RENESAS || COMPILE_TEST
360+
depends on HAS_IOMEM
361+
depends on OF
362+
help
363+
Enable this to plug the RZ/G2L thermal sensor driver into the Linux
364+
thermal framework.
365+
357366
config KIRKWOOD_THERMAL
358367
tristate "Temperature sensor on Marvell Kirkwood SoCs"
359368
depends on MACH_KIRKWOOD || COMPILE_TEST

drivers/thermal/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ obj-$(CONFIG_SUN8I_THERMAL) += sun8i_thermal.o
3737
obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o
3838
obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o
3939
obj-$(CONFIG_RCAR_GEN3_THERMAL) += rcar_gen3_thermal.o
40+
obj-$(CONFIG_RZG2L_THERMAL) += rzg2l_thermal.o
4041
obj-$(CONFIG_KIRKWOOD_THERMAL) += kirkwood_thermal.o
4142
obj-y += samsung/
4243
obj-$(CONFIG_DOVE_THERMAL) += dove_thermal.o

drivers/thermal/imx8mm_thermal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define TPS 0x4
2222
#define TRITSR 0x20 /* TMU immediate temp */
2323

24+
#define TER_ADC_PD BIT(30)
2425
#define TER_EN BIT(31)
2526
#define TRITSR_TEMP0_VAL_MASK 0xff
2627
#define TRITSR_TEMP1_VAL_MASK 0xff0000
@@ -113,6 +114,8 @@ static void imx8mm_tmu_enable(struct imx8mm_tmu *tmu, bool enable)
113114

114115
val = readl_relaxed(tmu->base + TER);
115116
val = enable ? (val | TER_EN) : (val & ~TER_EN);
117+
if (tmu->socdata->version == TMU_VER2)
118+
val = enable ? (val & ~TER_ADC_PD) : (val | TER_ADC_PD);
116119
writel_relaxed(val, tmu->base + TER);
117120
}
118121

drivers/thermal/imx_thermal.c

Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/regmap.h>
1616
#include <linux/thermal.h>
1717
#include <linux/nvmem-consumer.h>
18+
#include <linux/pm_runtime.h>
1819

1920
#define REG_SET 0x4
2021
#define REG_CLR 0x8
@@ -194,6 +195,7 @@ static struct thermal_soc_data thermal_imx7d_data = {
194195
};
195196

196197
struct imx_thermal_data {
198+
struct device *dev;
197199
struct cpufreq_policy *policy;
198200
struct thermal_zone_device *tz;
199201
struct thermal_cooling_device *cdev;
@@ -252,44 +254,15 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
252254
const struct thermal_soc_data *soc_data = data->socdata;
253255
struct regmap *map = data->tempmon;
254256
unsigned int n_meas;
255-
bool wait, run_measurement;
256257
u32 val;
258+
int ret;
257259

258-
run_measurement = !data->irq_enabled;
259-
if (!run_measurement) {
260-
/* Check if a measurement is currently in progress */
261-
regmap_read(map, soc_data->temp_data, &val);
262-
wait = !(val & soc_data->temp_valid_mask);
263-
} else {
264-
/*
265-
* Every time we measure the temperature, we will power on the
266-
* temperature sensor, enable measurements, take a reading,
267-
* disable measurements, power off the temperature sensor.
268-
*/
269-
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
270-
soc_data->power_down_mask);
271-
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
272-
soc_data->measure_temp_mask);
273-
274-
wait = true;
275-
}
276-
277-
/*
278-
* According to the temp sensor designers, it may require up to ~17us
279-
* to complete a measurement.
280-
*/
281-
if (wait)
282-
usleep_range(20, 50);
260+
ret = pm_runtime_resume_and_get(data->dev);
261+
if (ret < 0)
262+
return ret;
283263

284264
regmap_read(map, soc_data->temp_data, &val);
285265

286-
if (run_measurement) {
287-
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
288-
soc_data->measure_temp_mask);
289-
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
290-
soc_data->power_down_mask);
291-
}
292-
293266
if ((val & soc_data->temp_valid_mask) == 0) {
294267
dev_dbg(&tz->device, "temp measurement never finished\n");
295268
return -EAGAIN;
@@ -328,31 +301,25 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
328301
enable_irq(data->irq);
329302
}
330303

304+
pm_runtime_put(data->dev);
305+
331306
return 0;
332307
}
333308

334309
static int imx_change_mode(struct thermal_zone_device *tz,
335310
enum thermal_device_mode mode)
336311
{
337312
struct imx_thermal_data *data = tz->devdata;
338-
struct regmap *map = data->tempmon;
339-
const struct thermal_soc_data *soc_data = data->socdata;
340313

341314
if (mode == THERMAL_DEVICE_ENABLED) {
342-
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
343-
soc_data->power_down_mask);
344-
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
345-
soc_data->measure_temp_mask);
315+
pm_runtime_get(data->dev);
346316

347317
if (!data->irq_enabled) {
348318
data->irq_enabled = true;
349319
enable_irq(data->irq);
350320
}
351321
} else {
352-
regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
353-
soc_data->measure_temp_mask);
354-
regmap_write(map, soc_data->sensor_ctrl + REG_SET,
355-
soc_data->power_down_mask);
322+
pm_runtime_put(data->dev);
356323

357324
if (data->irq_enabled) {
358325
disable_irq(data->irq);
@@ -393,6 +360,11 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
393360
int temp)
394361
{
395362
struct imx_thermal_data *data = tz->devdata;
363+
int ret;
364+
365+
ret = pm_runtime_resume_and_get(data->dev);
366+
if (ret < 0)
367+
return ret;
396368

397369
/* do not allow changing critical threshold */
398370
if (trip == IMX_TRIP_CRITICAL)
@@ -406,6 +378,8 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
406378

407379
imx_set_alarm_temp(data, temp);
408380

381+
pm_runtime_put(data->dev);
382+
409383
return 0;
410384
}
411385

@@ -681,6 +655,8 @@ static int imx_thermal_probe(struct platform_device *pdev)
681655
if (!data)
682656
return -ENOMEM;
683657

658+
data->dev = &pdev->dev;
659+
684660
map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "fsl,tempmon");
685661
if (IS_ERR(map)) {
686662
ret = PTR_ERR(map);
@@ -800,6 +776,16 @@ static int imx_thermal_probe(struct platform_device *pdev)
800776
data->socdata->power_down_mask);
801777
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
802778
data->socdata->measure_temp_mask);
779+
/* After power up, we need a delay before first access can be done. */
780+
usleep_range(20, 50);
781+
782+
/* the core was configured and enabled just before */
783+
pm_runtime_set_active(&pdev->dev);
784+
pm_runtime_enable(data->dev);
785+
786+
ret = pm_runtime_resume_and_get(data->dev);
787+
if (ret < 0)
788+
goto disable_runtime_pm;
803789

804790
data->irq_enabled = true;
805791
ret = thermal_zone_device_enable(data->tz);
@@ -814,10 +800,15 @@ static int imx_thermal_probe(struct platform_device *pdev)
814800
goto thermal_zone_unregister;
815801
}
816802

803+
pm_runtime_put(data->dev);
804+
817805
return 0;
818806

819807
thermal_zone_unregister:
820808
thermal_zone_device_unregister(data->tz);
809+
disable_runtime_pm:
810+
pm_runtime_put_noidle(data->dev);
811+
pm_runtime_disable(data->dev);
821812
clk_disable:
822813
clk_disable_unprepare(data->thermal_clk);
823814
legacy_cleanup:
@@ -829,13 +820,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
829820
static int imx_thermal_remove(struct platform_device *pdev)
830821
{
831822
struct imx_thermal_data *data = platform_get_drvdata(pdev);
832-
struct regmap *map = data->tempmon;
833823

834-
/* Disable measurements */
835-
regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
836-
data->socdata->power_down_mask);
837-
if (!IS_ERR(data->thermal_clk))
838-
clk_disable_unprepare(data->thermal_clk);
824+
pm_runtime_put_noidle(data->dev);
825+
pm_runtime_disable(data->dev);
839826

840827
thermal_zone_device_unregister(data->tz);
841828
imx_thermal_unregister_legacy_cooling(data);
@@ -858,29 +845,79 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev)
858845
ret = thermal_zone_device_disable(data->tz);
859846
if (ret)
860847
return ret;
848+
849+
return pm_runtime_force_suspend(data->dev);
850+
}
851+
852+
static int __maybe_unused imx_thermal_resume(struct device *dev)
853+
{
854+
struct imx_thermal_data *data = dev_get_drvdata(dev);
855+
int ret;
856+
857+
ret = pm_runtime_force_resume(data->dev);
858+
if (ret)
859+
return ret;
860+
/* Enabled thermal sensor after resume */
861+
return thermal_zone_device_enable(data->tz);
862+
}
863+
864+
static int __maybe_unused imx_thermal_runtime_suspend(struct device *dev)
865+
{
866+
struct imx_thermal_data *data = dev_get_drvdata(dev);
867+
const struct thermal_soc_data *socdata = data->socdata;
868+
struct regmap *map = data->tempmon;
869+
int ret;
870+
871+
ret = regmap_write(map, socdata->sensor_ctrl + REG_CLR,
872+
socdata->measure_temp_mask);
873+
if (ret)
874+
return ret;
875+
876+
ret = regmap_write(map, socdata->sensor_ctrl + REG_SET,
877+
socdata->power_down_mask);
878+
if (ret)
879+
return ret;
880+
861881
clk_disable_unprepare(data->thermal_clk);
862882

863883
return 0;
864884
}
865885

866-
static int __maybe_unused imx_thermal_resume(struct device *dev)
886+
static int __maybe_unused imx_thermal_runtime_resume(struct device *dev)
867887
{
868888
struct imx_thermal_data *data = dev_get_drvdata(dev);
889+
const struct thermal_soc_data *socdata = data->socdata;
890+
struct regmap *map = data->tempmon;
869891
int ret;
870892

871893
ret = clk_prepare_enable(data->thermal_clk);
872894
if (ret)
873895
return ret;
874-
/* Enabled thermal sensor after resume */
875-
ret = thermal_zone_device_enable(data->tz);
896+
897+
ret = regmap_write(map, socdata->sensor_ctrl + REG_CLR,
898+
socdata->power_down_mask);
899+
if (ret)
900+
return ret;
901+
902+
ret = regmap_write(map, socdata->sensor_ctrl + REG_SET,
903+
socdata->measure_temp_mask);
876904
if (ret)
877905
return ret;
878906

907+
/*
908+
* According to the temp sensor designers, it may require up to ~17us
909+
* to complete a measurement.
910+
*/
911+
usleep_range(20, 50);
912+
879913
return 0;
880914
}
881915

882-
static SIMPLE_DEV_PM_OPS(imx_thermal_pm_ops,
883-
imx_thermal_suspend, imx_thermal_resume);
916+
static const struct dev_pm_ops imx_thermal_pm_ops = {
917+
SET_SYSTEM_SLEEP_PM_OPS(imx_thermal_suspend, imx_thermal_resume)
918+
SET_RUNTIME_PM_OPS(imx_thermal_runtime_suspend,
919+
imx_thermal_runtime_resume, NULL)
920+
};
884921

885922
static struct platform_driver imx_thermal = {
886923
.driver = {

drivers/thermal/intel/intel_powerclamp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
641641
}
642642

643643
/* bind to generic thermal layer as cooling device*/
644-
static struct thermal_cooling_device_ops powerclamp_cooling_ops = {
644+
static const struct thermal_cooling_device_ops powerclamp_cooling_ops = {
645645
.get_max_state = powerclamp_get_max_state,
646646
.get_cur_state = powerclamp_get_cur_state,
647647
.set_cur_state = powerclamp_set_cur_state,

0 commit comments

Comments
 (0)