aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-08 12:52:41 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-08 12:52:41 -0500
commit9f24a81e2e5daf8820c8654afcd8512e797c41f2 (patch)
treef23d098e3dcf544db3a7846ae2d95870f112da39 /drivers
parent564e741171e92aaf095db403c5e9ed3b160e27e9 (diff)
parent6269e9f790e8d442b3e1529bf3b3de452dd4ac92 (diff)
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal
Pull thermal soc updates from Eduardo Valentin: "Specifics: - mediatek thermal now supports MT8183 - broadcom thermal now supports Stingray - qoirq now supports multiple sensors - fixes on different drivers: rcar, tsens, tegra Some new drivers are still pending further review and I chose to leave them for the next merge window while still sending this material" * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal: thermal: rcar_gen3_thermal: Register hwmon sysfs interface thermal/qcom/tsens-common : fix possible object reference leak thermal: tegra: add get_trend ops thermal: tegra: fix memory allocation thermal: tegra: remove unnecessary warnings thermal: mediatek: add support for MT8183 dt-bindings: thermal: add binding document for mt8183 thermal controller thermal: mediatek: add flag for bank selection thermal: mediatek: add thermal controller offset thermal: mediatek: add calibration item thermal: mediatek: add common index of vts settings. thermal: mediatek: fix register index error thermal: qoriq: add multiple sensors support thermal: broadcom: Add Stingray thermal driver dt-bindings: thermal: Add binding document for SR thermal
Diffstat (limited to 'drivers')
-rw-r--r--drivers/thermal/Kconfig3
-rw-r--r--drivers/thermal/broadcom/Kconfig9
-rw-r--r--drivers/thermal/broadcom/Makefile1
-rw-r--r--drivers/thermal/broadcom/sr-thermal.c121
-rw-r--r--drivers/thermal/mtk_thermal.c316
-rw-r--r--drivers/thermal/qcom/tsens-common.c33
-rw-r--r--drivers/thermal/qoriq_thermal.c104
-rw-r--r--drivers/thermal/rcar_gen3_thermal.c19
-rw-r--r--drivers/thermal/tegra/soctherm.c38
9 files changed, 514 insertions, 130 deletions
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 58bb7d72dc2b..653aa27a25a4 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -344,7 +344,8 @@ source "drivers/thermal/intel/Kconfig"
344endmenu 344endmenu
345 345
346menu "Broadcom thermal drivers" 346menu "Broadcom thermal drivers"
347depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST 347depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || ARCH_BCM_IPROC || \
348 COMPILE_TEST
348source "drivers/thermal/broadcom/Kconfig" 349source "drivers/thermal/broadcom/Kconfig"
349endmenu 350endmenu
350 351
diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig
index c106a15bf7f9..dc9a9bdde3ed 100644
--- a/drivers/thermal/broadcom/Kconfig
+++ b/drivers/thermal/broadcom/Kconfig
@@ -22,3 +22,12 @@ config BCM_NS_THERMAL
22 BCM4708, BCM4709, BCM5301x, BCM95852X, etc). It contains DMU (Device 22 BCM4708, BCM4709, BCM5301x, BCM95852X, etc). It contains DMU (Device
23 Management Unit) block with a thermal sensor that allows checking CPU 23 Management Unit) block with a thermal sensor that allows checking CPU
24 temperature. 24 temperature.
25
26config BCM_SR_THERMAL
27 tristate "Stingray thermal driver"
28 depends on ARCH_BCM_IPROC || COMPILE_TEST
29 default ARCH_BCM_IPROC
30 help
31 Support for the Stingray family of SoCs. Its different blocks like
32 iHost, CRMU and NITRO has thermal sensor that allows checking its
33 temperature.
diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile
index fae10ecafaef..79df69eb2b8c 100644
--- a/drivers/thermal/broadcom/Makefile
+++ b/drivers/thermal/broadcom/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o 1obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o
2obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o 2obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o
3obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o 3obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
4obj-$(CONFIG_BCM_SR_THERMAL) += sr-thermal.o
diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c
new file mode 100644
index 000000000000..2284cbecedf3
--- /dev/null
+++ b/drivers/thermal/broadcom/sr-thermal.c
@@ -0,0 +1,121 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2018 Broadcom
4 */
5
6#include <linux/acpi.h>
7#include <linux/module.h>
8#include <linux/of_address.h>
9#include <linux/platform_device.h>
10#include <linux/thermal.h>
11
12/*
13 * In stingray thermal IO memory,
14 * Total Number of available TMONs MASK is at offset 0
15 * temperature registers BASE is at 4 byte offset.
16 * Each TMON temperature register size is 4.
17 */
18#define SR_TMON_TEMP_BASE(id) ((id) * 0x4)
19
20#define SR_TMON_MAX_LIST 6
21
22struct sr_tmon {
23 struct thermal_zone_device *tz;
24 unsigned int crit_temp;
25 unsigned int tmon_id;
26 struct sr_thermal *priv;
27};
28
29struct sr_thermal {
30 void __iomem *regs;
31 unsigned int max_crit_temp;
32 struct sr_tmon tmon[SR_TMON_MAX_LIST];
33};
34
35static int sr_get_temp(void *data, int *temp)
36{
37 struct sr_tmon *tmon = data;
38 struct sr_thermal *sr_thermal = tmon->priv;
39
40 *temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
41
42 return 0;
43}
44
45static const struct thermal_zone_of_device_ops sr_tz_ops = {
46 .get_temp = sr_get_temp,
47};
48
49static int sr_thermal_probe(struct platform_device *pdev)
50{
51 struct device *dev = &pdev->dev;
52 struct sr_thermal *sr_thermal;
53 struct sr_tmon *tmon;
54 struct resource *res;
55 u32 sr_tmon_list = 0;
56 unsigned int i;
57 int ret;
58
59 sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL);
60 if (!sr_thermal)
61 return -ENOMEM;
62
63 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
64 sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start,
65 resource_size(res),
66 MEMREMAP_WB);
67 if (IS_ERR(sr_thermal->regs)) {
68 dev_err(dev, "failed to get io address\n");
69 return PTR_ERR(sr_thermal->regs);
70 }
71
72 ret = device_property_read_u32(dev, "brcm,tmon-mask", &sr_tmon_list);
73 if (ret)
74 return ret;
75
76 tmon = sr_thermal->tmon;
77 for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) {
78 if (!(sr_tmon_list & BIT(i)))
79 continue;
80
81 /* Flush temperature registers */
82 writel(0, sr_thermal->regs + SR_TMON_TEMP_BASE(i));
83 tmon->tmon_id = i;
84 tmon->priv = sr_thermal;
85 tmon->tz = devm_thermal_zone_of_sensor_register(dev, i, tmon,
86 &sr_tz_ops);
87 if (IS_ERR(tmon->tz))
88 return PTR_ERR(tmon->tz);
89
90 dev_dbg(dev, "thermal sensor %d registered\n", i);
91 }
92 platform_set_drvdata(pdev, sr_thermal);
93
94 return 0;
95}
96
97static const struct of_device_id sr_thermal_of_match[] = {
98 { .compatible = "brcm,sr-thermal", },
99 {},
100};
101MODULE_DEVICE_TABLE(of, sr_thermal_of_match);
102
103static const struct acpi_device_id sr_thermal_acpi_ids[] = {
104 { .id = "BRCM0500" },
105 { /* sentinel */ }
106};
107MODULE_DEVICE_TABLE(acpi, sr_thermal_acpi_ids);
108
109static struct platform_driver sr_thermal_driver = {
110 .probe = sr_thermal_probe,
111 .driver = {
112 .name = "sr-thermal",
113 .of_match_table = sr_thermal_of_match,
114 .acpi_match_table = ACPI_PTR(sr_thermal_acpi_ids),
115 },
116};
117module_platform_driver(sr_thermal_driver);
118
119MODULE_AUTHOR("Pramod Kumar <pramod.kumar@broadcom.com>");
120MODULE_DESCRIPTION("Stingray thermal driver");
121MODULE_LICENSE("GPL v2");
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 0691f260f6ea..5c07a61447d3 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -71,6 +71,15 @@
71 71
72#define TEMP_SPARE0 0x0f0 72#define TEMP_SPARE0 0x0f0
73 73
74#define TEMP_ADCPNP0_1 0x148
75#define TEMP_ADCPNP1_1 0x14c
76#define TEMP_ADCPNP2_1 0x150
77#define TEMP_MSR0_1 0x190
78#define TEMP_MSR1_1 0x194
79#define TEMP_MSR2_1 0x198
80#define TEMP_ADCPNP3_1 0x1b4
81#define TEMP_MSR3_1 0x1B8
82
74#define PTPCORESEL 0x400 83#define PTPCORESEL 0x400
75 84
76#define TEMP_MONCTL1_PERIOD_UNIT(x) ((x) & 0x3ff) 85#define TEMP_MONCTL1_PERIOD_UNIT(x) ((x) & 0x3ff)
@@ -105,24 +114,42 @@
105/* The number of sensing points per bank */ 114/* The number of sensing points per bank */
106#define MT8173_NUM_SENSORS_PER_ZONE 4 115#define MT8173_NUM_SENSORS_PER_ZONE 4
107 116
117/* The number of controller in the MT8173 */
118#define MT8173_NUM_CONTROLLER 1
119
120/* The calibration coefficient of sensor */
121#define MT8173_CALIBRATION 165
122
108/* 123/*
109 * Layout of the fuses providing the calibration data 124 * Layout of the fuses providing the calibration data
110 * These macros could be used for MT8173, MT2701, and MT2712. 125 * These macros could be used for MT8183, MT8173, MT2701, and MT2712.
126 * MT8183 has 6 sensors and needs 6 VTS calibration data.
111 * MT8173 has 5 sensors and needs 5 VTS calibration data. 127 * MT8173 has 5 sensors and needs 5 VTS calibration data.
112 * MT2701 has 3 sensors and needs 3 VTS calibration data. 128 * MT2701 has 3 sensors and needs 3 VTS calibration data.
113 * MT2712 has 4 sensors and needs 4 VTS calibration data. 129 * MT2712 has 4 sensors and needs 4 VTS calibration data.
114 */ 130 */
115#define MT8173_CALIB_BUF0_VALID BIT(0) 131#define CALIB_BUF0_VALID BIT(0)
116#define MT8173_CALIB_BUF1_ADC_GE(x) (((x) >> 22) & 0x3ff) 132#define CALIB_BUF1_ADC_GE(x) (((x) >> 22) & 0x3ff)
117#define MT8173_CALIB_BUF0_VTS_TS1(x) (((x) >> 17) & 0x1ff) 133#define CALIB_BUF0_VTS_TS1(x) (((x) >> 17) & 0x1ff)
118#define MT8173_CALIB_BUF0_VTS_TS2(x) (((x) >> 8) & 0x1ff) 134#define CALIB_BUF0_VTS_TS2(x) (((x) >> 8) & 0x1ff)
119#define MT8173_CALIB_BUF1_VTS_TS3(x) (((x) >> 0) & 0x1ff) 135#define CALIB_BUF1_VTS_TS3(x) (((x) >> 0) & 0x1ff)
120#define MT8173_CALIB_BUF2_VTS_TS4(x) (((x) >> 23) & 0x1ff) 136#define CALIB_BUF2_VTS_TS4(x) (((x) >> 23) & 0x1ff)
121#define MT8173_CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff) 137#define CALIB_BUF2_VTS_TS5(x) (((x) >> 5) & 0x1ff)
122#define MT8173_CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f) 138#define CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff)
123#define MT8173_CALIB_BUF0_O_SLOPE(x) (((x) >> 26) & 0x3f) 139#define CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f)
124#define MT8173_CALIB_BUF0_O_SLOPE_SIGN(x) (((x) >> 7) & 0x1) 140#define CALIB_BUF0_O_SLOPE(x) (((x) >> 26) & 0x3f)
125#define MT8173_CALIB_BUF1_ID(x) (((x) >> 9) & 0x1) 141#define CALIB_BUF0_O_SLOPE_SIGN(x) (((x) >> 7) & 0x1)
142#define CALIB_BUF1_ID(x) (((x) >> 9) & 0x1)
143
144enum {
145 VTS1,
146 VTS2,
147 VTS3,
148 VTS4,
149 VTS5,
150 VTSABB,
151 MAX_NUM_VTS,
152};
126 153
127/* MT2701 thermal sensors */ 154/* MT2701 thermal sensors */
128#define MT2701_TS1 0 155#define MT2701_TS1 0
@@ -138,6 +165,12 @@
138/* The number of sensing points per bank */ 165/* The number of sensing points per bank */
139#define MT2701_NUM_SENSORS_PER_ZONE 3 166#define MT2701_NUM_SENSORS_PER_ZONE 3
140 167
168/* The number of controller in the MT2701 */
169#define MT2701_NUM_CONTROLLER 1
170
171/* The calibration coefficient of sensor */
172#define MT2701_CALIBRATION 165
173
141/* MT2712 thermal sensors */ 174/* MT2712 thermal sensors */
142#define MT2712_TS1 0 175#define MT2712_TS1 0
143#define MT2712_TS2 1 176#define MT2712_TS2 1
@@ -153,11 +186,44 @@
153/* The number of sensing points per bank */ 186/* The number of sensing points per bank */
154#define MT2712_NUM_SENSORS_PER_ZONE 4 187#define MT2712_NUM_SENSORS_PER_ZONE 4
155 188
189/* The number of controller in the MT2712 */
190#define MT2712_NUM_CONTROLLER 1
191
192/* The calibration coefficient of sensor */
193#define MT2712_CALIBRATION 165
194
156#define MT7622_TEMP_AUXADC_CHANNEL 11 195#define MT7622_TEMP_AUXADC_CHANNEL 11
157#define MT7622_NUM_SENSORS 1 196#define MT7622_NUM_SENSORS 1
158#define MT7622_NUM_ZONES 1 197#define MT7622_NUM_ZONES 1
159#define MT7622_NUM_SENSORS_PER_ZONE 1 198#define MT7622_NUM_SENSORS_PER_ZONE 1
160#define MT7622_TS1 0 199#define MT7622_TS1 0
200#define MT7622_NUM_CONTROLLER 1
201
202/* The calibration coefficient of sensor */
203#define MT7622_CALIBRATION 165
204
205/* MT8183 thermal sensors */
206#define MT8183_TS1 0
207#define MT8183_TS2 1
208#define MT8183_TS3 2
209#define MT8183_TS4 3
210#define MT8183_TS5 4
211#define MT8183_TSABB 5
212
213/* AUXADC channel is used for the temperature sensors */
214#define MT8183_TEMP_AUXADC_CHANNEL 11
215
216/* The total number of temperature sensors in the MT8183 */
217#define MT8183_NUM_SENSORS 6
218
219/* The number of sensing points per bank */
220#define MT8183_NUM_SENSORS_PER_ZONE 6
221
222/* The number of controller in the MT8183 */
223#define MT8183_NUM_CONTROLLER 2
224
225/* The calibration coefficient of sensor */
226#define MT8183_CALIBRATION 153
161 227
162struct mtk_thermal; 228struct mtk_thermal;
163 229
@@ -175,9 +241,14 @@ struct mtk_thermal_data {
175 s32 num_banks; 241 s32 num_banks;
176 s32 num_sensors; 242 s32 num_sensors;
177 s32 auxadc_channel; 243 s32 auxadc_channel;
244 const int *vts_index;
178 const int *sensor_mux_values; 245 const int *sensor_mux_values;
179 const int *msr; 246 const int *msr;
180 const int *adcpnp; 247 const int *adcpnp;
248 const int cali_val;
249 const int num_controller;
250 const int *controller_offset;
251 bool need_switch_bank;
181 struct thermal_bank_cfg bank_data[]; 252 struct thermal_bank_cfg bank_data[];
182}; 253};
183 254
@@ -194,12 +265,33 @@ struct mtk_thermal {
194 s32 adc_ge; 265 s32 adc_ge;
195 s32 degc_cali; 266 s32 degc_cali;
196 s32 o_slope; 267 s32 o_slope;
197 s32 vts[MT8173_NUM_SENSORS]; 268 s32 vts[MAX_NUM_VTS];
198 269
199 const struct mtk_thermal_data *conf; 270 const struct mtk_thermal_data *conf;
200 struct mtk_thermal_bank banks[]; 271 struct mtk_thermal_bank banks[];
201}; 272};
202 273
274/* MT8183 thermal sensor data */
275static const int mt8183_bank_data[MT8183_NUM_SENSORS] = {
276 MT8183_TS1, MT8183_TS2, MT8183_TS3, MT8183_TS4, MT8183_TS5, MT8183_TSABB
277};
278
279static const int mt8183_msr[MT8183_NUM_SENSORS_PER_ZONE] = {
280 TEMP_MSR0_1, TEMP_MSR1_1, TEMP_MSR2_1, TEMP_MSR1, TEMP_MSR0, TEMP_MSR3_1
281};
282
283static const int mt8183_adcpnp[MT8183_NUM_SENSORS_PER_ZONE] = {
284 TEMP_ADCPNP0_1, TEMP_ADCPNP1_1, TEMP_ADCPNP2_1,
285 TEMP_ADCPNP1, TEMP_ADCPNP0, TEMP_ADCPNP3_1
286};
287
288static const int mt8183_mux_values[MT8183_NUM_SENSORS] = { 0, 1, 2, 3, 4, 0 };
289static const int mt8183_tc_offset[MT8183_NUM_CONTROLLER] = {0x0, 0x100};
290
291static const int mt8183_vts_index[MT8183_NUM_SENSORS] = {
292 VTS1, VTS2, VTS3, VTS4, VTS5, VTSABB
293};
294
203/* MT8173 thermal sensor data */ 295/* MT8173 thermal sensor data */
204static const int mt8173_bank_data[MT8173_NUM_ZONES][3] = { 296static const int mt8173_bank_data[MT8173_NUM_ZONES][3] = {
205 { MT8173_TS2, MT8173_TS3 }, 297 { MT8173_TS2, MT8173_TS3 },
@@ -217,6 +309,11 @@ static const int mt8173_adcpnp[MT8173_NUM_SENSORS_PER_ZONE] = {
217}; 309};
218 310
219static const int mt8173_mux_values[MT8173_NUM_SENSORS] = { 0, 1, 2, 3, 16 }; 311static const int mt8173_mux_values[MT8173_NUM_SENSORS] = { 0, 1, 2, 3, 16 };
312static const int mt8173_tc_offset[MT8173_NUM_CONTROLLER] = { 0x0, };
313
314static const int mt8173_vts_index[MT8173_NUM_SENSORS] = {
315 VTS1, VTS2, VTS3, VTS4, VTSABB
316};
220 317
221/* MT2701 thermal sensor data */ 318/* MT2701 thermal sensor data */
222static const int mt2701_bank_data[MT2701_NUM_SENSORS] = { 319static const int mt2701_bank_data[MT2701_NUM_SENSORS] = {
@@ -232,6 +329,11 @@ static const int mt2701_adcpnp[MT2701_NUM_SENSORS_PER_ZONE] = {
232}; 329};
233 330
234static const int mt2701_mux_values[MT2701_NUM_SENSORS] = { 0, 1, 16 }; 331static const int mt2701_mux_values[MT2701_NUM_SENSORS] = { 0, 1, 16 };
332static const int mt2701_tc_offset[MT2701_NUM_CONTROLLER] = { 0x0, };
333
334static const int mt2701_vts_index[MT2701_NUM_SENSORS] = {
335 VTS1, VTS2, VTS3
336};
235 337
236/* MT2712 thermal sensor data */ 338/* MT2712 thermal sensor data */
237static const int mt2712_bank_data[MT2712_NUM_SENSORS] = { 339static const int mt2712_bank_data[MT2712_NUM_SENSORS] = {
@@ -247,12 +349,19 @@ static const int mt2712_adcpnp[MT2712_NUM_SENSORS_PER_ZONE] = {
247}; 349};
248 350
249static const int mt2712_mux_values[MT2712_NUM_SENSORS] = { 0, 1, 2, 3 }; 351static const int mt2712_mux_values[MT2712_NUM_SENSORS] = { 0, 1, 2, 3 };
352static const int mt2712_tc_offset[MT2712_NUM_CONTROLLER] = { 0x0, };
353
354static const int mt2712_vts_index[MT2712_NUM_SENSORS] = {
355 VTS1, VTS2, VTS3, VTS4
356};
250 357
251/* MT7622 thermal sensor data */ 358/* MT7622 thermal sensor data */
252static const int mt7622_bank_data[MT7622_NUM_SENSORS] = { MT7622_TS1, }; 359static const int mt7622_bank_data[MT7622_NUM_SENSORS] = { MT7622_TS1, };
253static const int mt7622_msr[MT7622_NUM_SENSORS_PER_ZONE] = { TEMP_MSR0, }; 360static const int mt7622_msr[MT7622_NUM_SENSORS_PER_ZONE] = { TEMP_MSR0, };
254static const int mt7622_adcpnp[MT7622_NUM_SENSORS_PER_ZONE] = { TEMP_ADCPNP0, }; 361static const int mt7622_adcpnp[MT7622_NUM_SENSORS_PER_ZONE] = { TEMP_ADCPNP0, };
255static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, }; 362static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
363static const int mt7622_vts_index[MT7622_NUM_SENSORS] = { VTS1 };
364static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] = { 0x0, };
256 365
257/** 366/**
258 * The MT8173 thermal controller has four banks. Each bank can read up to 367 * The MT8173 thermal controller has four banks. Each bank can read up to
@@ -271,6 +380,11 @@ static const struct mtk_thermal_data mt8173_thermal_data = {
271 .auxadc_channel = MT8173_TEMP_AUXADC_CHANNEL, 380 .auxadc_channel = MT8173_TEMP_AUXADC_CHANNEL,
272 .num_banks = MT8173_NUM_ZONES, 381 .num_banks = MT8173_NUM_ZONES,
273 .num_sensors = MT8173_NUM_SENSORS, 382 .num_sensors = MT8173_NUM_SENSORS,
383 .vts_index = mt8173_vts_index,
384 .cali_val = MT8173_CALIBRATION,
385 .num_controller = MT8173_NUM_CONTROLLER,
386 .controller_offset = mt8173_tc_offset,
387 .need_switch_bank = true,
274 .bank_data = { 388 .bank_data = {
275 { 389 {
276 .num_sensors = 2, 390 .num_sensors = 2,
@@ -305,6 +419,11 @@ static const struct mtk_thermal_data mt2701_thermal_data = {
305 .auxadc_channel = MT2701_TEMP_AUXADC_CHANNEL, 419 .auxadc_channel = MT2701_TEMP_AUXADC_CHANNEL,
306 .num_banks = 1, 420 .num_banks = 1,
307 .num_sensors = MT2701_NUM_SENSORS, 421 .num_sensors = MT2701_NUM_SENSORS,
422 .vts_index = mt2701_vts_index,
423 .cali_val = MT2701_CALIBRATION,
424 .num_controller = MT2701_NUM_CONTROLLER,
425 .controller_offset = mt2701_tc_offset,
426 .need_switch_bank = true,
308 .bank_data = { 427 .bank_data = {
309 { 428 {
310 .num_sensors = 3, 429 .num_sensors = 3,
@@ -330,6 +449,11 @@ static const struct mtk_thermal_data mt2712_thermal_data = {
330 .auxadc_channel = MT2712_TEMP_AUXADC_CHANNEL, 449 .auxadc_channel = MT2712_TEMP_AUXADC_CHANNEL,
331 .num_banks = 1, 450 .num_banks = 1,
332 .num_sensors = MT2712_NUM_SENSORS, 451 .num_sensors = MT2712_NUM_SENSORS,
452 .vts_index = mt2712_vts_index,
453 .cali_val = MT2712_CALIBRATION,
454 .num_controller = MT2712_NUM_CONTROLLER,
455 .controller_offset = mt2712_tc_offset,
456 .need_switch_bank = true,
333 .bank_data = { 457 .bank_data = {
334 { 458 {
335 .num_sensors = 4, 459 .num_sensors = 4,
@@ -349,6 +473,11 @@ static const struct mtk_thermal_data mt7622_thermal_data = {
349 .auxadc_channel = MT7622_TEMP_AUXADC_CHANNEL, 473 .auxadc_channel = MT7622_TEMP_AUXADC_CHANNEL,
350 .num_banks = MT7622_NUM_ZONES, 474 .num_banks = MT7622_NUM_ZONES,
351 .num_sensors = MT7622_NUM_SENSORS, 475 .num_sensors = MT7622_NUM_SENSORS,
476 .vts_index = mt7622_vts_index,
477 .cali_val = MT7622_CALIBRATION,
478 .num_controller = MT7622_NUM_CONTROLLER,
479 .controller_offset = mt7622_tc_offset,
480 .need_switch_bank = true,
352 .bank_data = { 481 .bank_data = {
353 { 482 {
354 .num_sensors = 1, 483 .num_sensors = 1,
@@ -361,6 +490,39 @@ static const struct mtk_thermal_data mt7622_thermal_data = {
361}; 490};
362 491
363/** 492/**
493 * The MT8183 thermal controller has one bank for the current SW framework.
494 * The MT8183 has a total of 6 temperature sensors.
495 * There are two thermal controller to control the six sensor.
496 * The first one bind 2 sensor, and the other bind 4 sensors.
497 * The thermal core only gets the maximum temperature of all sensor, so
498 * the bank concept wouldn't be necessary here. However, the SVS (Smart
499 * Voltage Scaling) unit makes its decisions based on the same bank
500 * data, and this indeed needs the temperatures of the individual banks
501 * for making better decisions.
502 */
503
504static const struct mtk_thermal_data mt8183_thermal_data = {
505 .auxadc_channel = MT8183_TEMP_AUXADC_CHANNEL,
506 .num_banks = MT8183_NUM_SENSORS_PER_ZONE,
507 .num_sensors = MT8183_NUM_SENSORS,
508 .vts_index = mt8183_vts_index,
509 .cali_val = MT8183_CALIBRATION,
510 .num_controller = MT8183_NUM_CONTROLLER,
511 .controller_offset = mt8183_tc_offset,
512 .need_switch_bank = false,
513 .bank_data = {
514 {
515 .num_sensors = 6,
516 .sensors = mt8183_bank_data,
517 },
518 },
519
520 .msr = mt8183_msr,
521 .adcpnp = mt8183_adcpnp,
522 .sensor_mux_values = mt8183_mux_values,
523};
524
525/**
364 * raw_to_mcelsius - convert a raw ADC value to mcelsius 526 * raw_to_mcelsius - convert a raw ADC value to mcelsius
365 * @mt: The thermal controller 527 * @mt: The thermal controller
366 * @raw: raw ADC value 528 * @raw: raw ADC value
@@ -375,7 +537,7 @@ static int raw_to_mcelsius(struct mtk_thermal *mt, int sensno, s32 raw)
375 raw &= 0xfff; 537 raw &= 0xfff;
376 538
377 tmp = 203450520 << 3; 539 tmp = 203450520 << 3;
378 tmp /= 165 + mt->o_slope; 540 tmp /= mt->conf->cali_val + mt->o_slope;
379 tmp /= 10000 + mt->adc_ge; 541 tmp /= 10000 + mt->adc_ge;
380 tmp *= raw - mt->vts[sensno] - 3350; 542 tmp *= raw - mt->vts[sensno] - 3350;
381 tmp >>= 3; 543 tmp >>= 3;
@@ -395,12 +557,14 @@ static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank)
395 struct mtk_thermal *mt = bank->mt; 557 struct mtk_thermal *mt = bank->mt;
396 u32 val; 558 u32 val;
397 559
398 mutex_lock(&mt->lock); 560 if (mt->conf->need_switch_bank) {
561 mutex_lock(&mt->lock);
399 562
400 val = readl(mt->thermal_base + PTPCORESEL); 563 val = readl(mt->thermal_base + PTPCORESEL);
401 val &= ~0xf; 564 val &= ~0xf;
402 val |= bank->id; 565 val |= bank->id;
403 writel(val, mt->thermal_base + PTPCORESEL); 566 writel(val, mt->thermal_base + PTPCORESEL);
567 }
404} 568}
405 569
406/** 570/**
@@ -413,7 +577,8 @@ static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank)
413{ 577{
414 struct mtk_thermal *mt = bank->mt; 578 struct mtk_thermal *mt = bank->mt;
415 579
416 mutex_unlock(&mt->lock); 580 if (mt->conf->need_switch_bank)
581 mutex_unlock(&mt->lock);
417} 582}
418 583
419/** 584/**
@@ -431,7 +596,8 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
431 u32 raw; 596 u32 raw;
432 597
433 for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) { 598 for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
434 raw = readl(mt->thermal_base + conf->msr[i]); 599 raw = readl(mt->thermal_base +
600 conf->msr[conf->bank_data[bank->id].sensors[i]]);
435 601
436 temp = raw_to_mcelsius(mt, 602 temp = raw_to_mcelsius(mt,
437 conf->bank_data[bank->id].sensors[i], 603 conf->bank_data[bank->id].sensors[i],
@@ -478,19 +644,23 @@ static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
478}; 644};
479 645
480static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, 646static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
481 u32 apmixed_phys_base, u32 auxadc_phys_base) 647 u32 apmixed_phys_base, u32 auxadc_phys_base,
648 int ctrl_id)
482{ 649{
483 struct mtk_thermal_bank *bank = &mt->banks[num]; 650 struct mtk_thermal_bank *bank = &mt->banks[num];
484 const struct mtk_thermal_data *conf = mt->conf; 651 const struct mtk_thermal_data *conf = mt->conf;
485 int i; 652 int i;
486 653
654 int offset = mt->conf->controller_offset[ctrl_id];
655 void __iomem *controller_base = mt->thermal_base + offset;
656
487 bank->id = num; 657 bank->id = num;
488 bank->mt = mt; 658 bank->mt = mt;
489 659
490 mtk_thermal_get_bank(bank); 660 mtk_thermal_get_bank(bank);
491 661
492 /* bus clock 66M counting unit is 12 * 15.15ns * 256 = 46.540us */ 662 /* bus clock 66M counting unit is 12 * 15.15ns * 256 = 46.540us */
493 writel(TEMP_MONCTL1_PERIOD_UNIT(12), mt->thermal_base + TEMP_MONCTL1); 663 writel(TEMP_MONCTL1_PERIOD_UNIT(12), controller_base + TEMP_MONCTL1);
494 664
495 /* 665 /*
496 * filt interval is 1 * 46.540us = 46.54us, 666 * filt interval is 1 * 46.540us = 46.54us,
@@ -498,21 +668,21 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
498 */ 668 */
499 writel(TEMP_MONCTL2_FILTER_INTERVAL(1) | 669 writel(TEMP_MONCTL2_FILTER_INTERVAL(1) |
500 TEMP_MONCTL2_SENSOR_INTERVAL(429), 670 TEMP_MONCTL2_SENSOR_INTERVAL(429),
501 mt->thermal_base + TEMP_MONCTL2); 671 controller_base + TEMP_MONCTL2);
502 672
503 /* poll is set to 10u */ 673 /* poll is set to 10u */
504 writel(TEMP_AHBPOLL_ADC_POLL_INTERVAL(768), 674 writel(TEMP_AHBPOLL_ADC_POLL_INTERVAL(768),
505 mt->thermal_base + TEMP_AHBPOLL); 675 controller_base + TEMP_AHBPOLL);
506 676
507 /* temperature sampling control, 1 sample */ 677 /* temperature sampling control, 1 sample */
508 writel(0x0, mt->thermal_base + TEMP_MSRCTL0); 678 writel(0x0, controller_base + TEMP_MSRCTL0);
509 679
510 /* exceed this polling time, IRQ would be inserted */ 680 /* exceed this polling time, IRQ would be inserted */
511 writel(0xffffffff, mt->thermal_base + TEMP_AHBTO); 681 writel(0xffffffff, controller_base + TEMP_AHBTO);
512 682
513 /* number of interrupts per event, 1 is enough */ 683 /* number of interrupts per event, 1 is enough */
514 writel(0x0, mt->thermal_base + TEMP_MONIDET0); 684 writel(0x0, controller_base + TEMP_MONIDET0);
515 writel(0x0, mt->thermal_base + TEMP_MONIDET1); 685 writel(0x0, controller_base + TEMP_MONIDET1);
516 686
517 /* 687 /*
518 * The MT8173 thermal controller does not have its own ADC. Instead it 688 * The MT8173 thermal controller does not have its own ADC. Instead it
@@ -527,55 +697,56 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
527 * this value will be stored to TEMP_PNPMUXADDR (TEMP_SPARE0) 697 * this value will be stored to TEMP_PNPMUXADDR (TEMP_SPARE0)
528 * automatically by hw 698 * automatically by hw
529 */ 699 */
530 writel(BIT(conf->auxadc_channel), mt->thermal_base + TEMP_ADCMUX); 700 writel(BIT(conf->auxadc_channel), controller_base + TEMP_ADCMUX);
531 701
532 /* AHB address for auxadc mux selection */ 702 /* AHB address for auxadc mux selection */
533 writel(auxadc_phys_base + AUXADC_CON1_CLR_V, 703 writel(auxadc_phys_base + AUXADC_CON1_CLR_V,
534 mt->thermal_base + TEMP_ADCMUXADDR); 704 controller_base + TEMP_ADCMUXADDR);
535 705
536 /* AHB address for pnp sensor mux selection */ 706 /* AHB address for pnp sensor mux selection */
537 writel(apmixed_phys_base + APMIXED_SYS_TS_CON1, 707 writel(apmixed_phys_base + APMIXED_SYS_TS_CON1,
538 mt->thermal_base + TEMP_PNPMUXADDR); 708 controller_base + TEMP_PNPMUXADDR);
539 709
540 /* AHB value for auxadc enable */ 710 /* AHB value for auxadc enable */
541 writel(BIT(conf->auxadc_channel), mt->thermal_base + TEMP_ADCEN); 711 writel(BIT(conf->auxadc_channel), controller_base + TEMP_ADCEN);
542 712
543 /* AHB address for auxadc enable (channel 0 immediate mode selected) */ 713 /* AHB address for auxadc enable (channel 0 immediate mode selected) */
544 writel(auxadc_phys_base + AUXADC_CON1_SET_V, 714 writel(auxadc_phys_base + AUXADC_CON1_SET_V,
545 mt->thermal_base + TEMP_ADCENADDR); 715 controller_base + TEMP_ADCENADDR);
546 716
547 /* AHB address for auxadc valid bit */ 717 /* AHB address for auxadc valid bit */
548 writel(auxadc_phys_base + AUXADC_DATA(conf->auxadc_channel), 718 writel(auxadc_phys_base + AUXADC_DATA(conf->auxadc_channel),
549 mt->thermal_base + TEMP_ADCVALIDADDR); 719 controller_base + TEMP_ADCVALIDADDR);
550 720
551 /* AHB address for auxadc voltage output */ 721 /* AHB address for auxadc voltage output */
552 writel(auxadc_phys_base + AUXADC_DATA(conf->auxadc_channel), 722 writel(auxadc_phys_base + AUXADC_DATA(conf->auxadc_channel),
553 mt->thermal_base + TEMP_ADCVOLTADDR); 723 controller_base + TEMP_ADCVOLTADDR);
554 724
555 /* read valid & voltage are at the same register */ 725 /* read valid & voltage are at the same register */
556 writel(0x0, mt->thermal_base + TEMP_RDCTRL); 726 writel(0x0, controller_base + TEMP_RDCTRL);
557 727
558 /* indicate where the valid bit is */ 728 /* indicate where the valid bit is */
559 writel(TEMP_ADCVALIDMASK_VALID_HIGH | TEMP_ADCVALIDMASK_VALID_POS(12), 729 writel(TEMP_ADCVALIDMASK_VALID_HIGH | TEMP_ADCVALIDMASK_VALID_POS(12),
560 mt->thermal_base + TEMP_ADCVALIDMASK); 730 controller_base + TEMP_ADCVALIDMASK);
561 731
562 /* no shift */ 732 /* no shift */
563 writel(0x0, mt->thermal_base + TEMP_ADCVOLTAGESHIFT); 733 writel(0x0, controller_base + TEMP_ADCVOLTAGESHIFT);
564 734
565 /* enable auxadc mux write transaction */ 735 /* enable auxadc mux write transaction */
566 writel(TEMP_ADCWRITECTRL_ADC_MUX_WRITE, 736 writel(TEMP_ADCWRITECTRL_ADC_MUX_WRITE,
567 mt->thermal_base + TEMP_ADCWRITECTRL); 737 controller_base + TEMP_ADCWRITECTRL);
568 738
569 for (i = 0; i < conf->bank_data[num].num_sensors; i++) 739 for (i = 0; i < conf->bank_data[num].num_sensors; i++)
570 writel(conf->sensor_mux_values[conf->bank_data[num].sensors[i]], 740 writel(conf->sensor_mux_values[conf->bank_data[num].sensors[i]],
571 mt->thermal_base + conf->adcpnp[i]); 741 mt->thermal_base +
742 conf->adcpnp[conf->bank_data[num].sensors[i]]);
572 743
573 writel((1 << conf->bank_data[num].num_sensors) - 1, 744 writel((1 << conf->bank_data[num].num_sensors) - 1,
574 mt->thermal_base + TEMP_MONCTL0); 745 controller_base + TEMP_MONCTL0);
575 746
576 writel(TEMP_ADCWRITECTRL_ADC_PNP_WRITE | 747 writel(TEMP_ADCWRITECTRL_ADC_PNP_WRITE |
577 TEMP_ADCWRITECTRL_ADC_MUX_WRITE, 748 TEMP_ADCWRITECTRL_ADC_MUX_WRITE,
578 mt->thermal_base + TEMP_ADCWRITECTRL); 749 controller_base + TEMP_ADCWRITECTRL);
579 750
580 mtk_thermal_put_bank(bank); 751 mtk_thermal_put_bank(bank);
581} 752}
@@ -627,19 +798,40 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
627 goto out; 798 goto out;
628 } 799 }
629 800
630 if (buf[0] & MT8173_CALIB_BUF0_VALID) { 801 if (buf[0] & CALIB_BUF0_VALID) {
631 mt->adc_ge = MT8173_CALIB_BUF1_ADC_GE(buf[1]); 802 mt->adc_ge = CALIB_BUF1_ADC_GE(buf[1]);
632 mt->vts[MT8173_TS1] = MT8173_CALIB_BUF0_VTS_TS1(buf[0]); 803
633 mt->vts[MT8173_TS2] = MT8173_CALIB_BUF0_VTS_TS2(buf[0]); 804 for (i = 0; i < mt->conf->num_sensors; i++) {
634 mt->vts[MT8173_TS3] = MT8173_CALIB_BUF1_VTS_TS3(buf[1]); 805 switch (mt->conf->vts_index[i]) {
635 mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]); 806 case VTS1:
636 mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]); 807 mt->vts[VTS1] = CALIB_BUF0_VTS_TS1(buf[0]);
637 mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]); 808 break;
638 if (MT8173_CALIB_BUF1_ID(buf[1]) & 809 case VTS2:
639 MT8173_CALIB_BUF0_O_SLOPE_SIGN(buf[0])) 810 mt->vts[VTS2] = CALIB_BUF0_VTS_TS2(buf[0]);
640 mt->o_slope = -MT8173_CALIB_BUF0_O_SLOPE(buf[0]); 811 break;
812 case VTS3:
813 mt->vts[VTS3] = CALIB_BUF1_VTS_TS3(buf[1]);
814 break;
815 case VTS4:
816 mt->vts[VTS4] = CALIB_BUF2_VTS_TS4(buf[2]);
817 break;
818 case VTS5:
819 mt->vts[VTS5] = CALIB_BUF2_VTS_TS5(buf[2]);
820 break;
821 case VTSABB:
822 mt->vts[VTSABB] = CALIB_BUF2_VTS_TSABB(buf[2]);
823 break;
824 default:
825 break;
826 }
827 }
828
829 mt->degc_cali = CALIB_BUF0_DEGC_CALI(buf[0]);
830 if (CALIB_BUF1_ID(buf[1]) &
831 CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
832 mt->o_slope = -CALIB_BUF0_O_SLOPE(buf[0]);
641 else 833 else
642 mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]); 834 mt->o_slope = CALIB_BUF0_O_SLOPE(buf[0]);
643 } else { 835 } else {
644 dev_info(dev, "Device not calibrated, using default calibration values\n"); 836 dev_info(dev, "Device not calibrated, using default calibration values\n");
645 } 837 }
@@ -666,6 +858,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
666 { 858 {
667 .compatible = "mediatek,mt7622-thermal", 859 .compatible = "mediatek,mt7622-thermal",
668 .data = (void *)&mt7622_thermal_data, 860 .data = (void *)&mt7622_thermal_data,
861 },
862 {
863 .compatible = "mediatek,mt8183-thermal",
864 .data = (void *)&mt8183_thermal_data,
669 }, { 865 }, {
670 }, 866 },
671}; 867};
@@ -673,7 +869,7 @@ MODULE_DEVICE_TABLE(of, mtk_thermal_of_match);
673 869
674static int mtk_thermal_probe(struct platform_device *pdev) 870static int mtk_thermal_probe(struct platform_device *pdev)
675{ 871{
676 int ret, i; 872 int ret, i, ctrl_id;
677 struct device_node *auxadc, *apmixedsys, *np = pdev->dev.of_node; 873 struct device_node *auxadc, *apmixedsys, *np = pdev->dev.of_node;
678 struct mtk_thermal *mt; 874 struct mtk_thermal *mt;
679 struct resource *res; 875 struct resource *res;
@@ -753,9 +949,10 @@ static int mtk_thermal_probe(struct platform_device *pdev)
753 goto err_disable_clk_auxadc; 949 goto err_disable_clk_auxadc;
754 } 950 }
755 951
756 for (i = 0; i < mt->conf->num_banks; i++) 952 for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
757 mtk_thermal_init_bank(mt, i, apmixed_phys_base, 953 for (i = 0; i < mt->conf->num_banks; i++)
758 auxadc_phys_base); 954 mtk_thermal_init_bank(mt, i, apmixed_phys_base,
955 auxadc_phys_base, ctrl_id);
759 956
760 platform_set_drvdata(pdev, mt); 957 platform_set_drvdata(pdev, mt);
761 958
@@ -797,6 +994,7 @@ static struct platform_driver mtk_thermal_driver = {
797 994
798module_platform_driver(mtk_thermal_driver); 995module_platform_driver(mtk_thermal_driver);
799 996
997MODULE_AUTHOR("Michael Kao <michael.kao@mediatek.com>");
800MODULE_AUTHOR("Louis Yu <louis.yu@mediatek.com>"); 998MODULE_AUTHOR("Louis Yu <louis.yu@mediatek.com>");
801MODULE_AUTHOR("Dawei Chien <dawei.chien@mediatek.com>"); 999MODULE_AUTHOR("Dawei Chien <dawei.chien@mediatek.com>");
802MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 1000MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index 78652cac7f3d..f80c73f11740 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -144,13 +144,17 @@ int __init init_common(struct tsens_device *tmdev)
144 tmdev->tm_offset = 0; 144 tmdev->tm_offset = 0;
145 res = platform_get_resource(op, IORESOURCE_MEM, 1); 145 res = platform_get_resource(op, IORESOURCE_MEM, 1);
146 srot_base = devm_ioremap_resource(&op->dev, res); 146 srot_base = devm_ioremap_resource(&op->dev, res);
147 if (IS_ERR(srot_base)) 147 if (IS_ERR(srot_base)) {
148 return PTR_ERR(srot_base); 148 ret = PTR_ERR(srot_base);
149 goto err_put_device;
150 }
149 151
150 tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, srot_base, 152 tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, srot_base,
151 &tsens_srot_config); 153 &tsens_srot_config);
152 if (IS_ERR(tmdev->srot_map)) 154 if (IS_ERR(tmdev->srot_map)) {
153 return PTR_ERR(tmdev->srot_map); 155 ret = PTR_ERR(tmdev->srot_map);
156 goto err_put_device;
157 }
154 158
155 } else { 159 } else {
156 /* old DTs where SROT and TM were in a contiguous 2K block */ 160 /* old DTs where SROT and TM were in a contiguous 2K block */
@@ -159,22 +163,31 @@ int __init init_common(struct tsens_device *tmdev)
159 163
160 res = platform_get_resource(op, IORESOURCE_MEM, 0); 164 res = platform_get_resource(op, IORESOURCE_MEM, 0);
161 tm_base = devm_ioremap_resource(&op->dev, res); 165 tm_base = devm_ioremap_resource(&op->dev, res);
162 if (IS_ERR(tm_base)) 166 if (IS_ERR(tm_base)) {
163 return PTR_ERR(tm_base); 167 ret = PTR_ERR(tm_base);
168 goto err_put_device;
169 }
164 170
165 tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config); 171 tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config);
166 if (IS_ERR(tmdev->tm_map)) 172 if (IS_ERR(tmdev->tm_map)) {
167 return PTR_ERR(tmdev->tm_map); 173 ret = PTR_ERR(tmdev->tm_map);
174 goto err_put_device;
175 }
168 176
169 if (tmdev->srot_map) { 177 if (tmdev->srot_map) {
170 ret = regmap_read(tmdev->srot_map, ctrl_offset, &code); 178 ret = regmap_read(tmdev->srot_map, ctrl_offset, &code);
171 if (ret) 179 if (ret)
172 return ret; 180 goto err_put_device;
173 if (!(code & TSENS_EN)) { 181 if (!(code & TSENS_EN)) {
174 dev_err(tmdev->dev, "tsens device is not enabled\n"); 182 dev_err(tmdev->dev, "tsens device is not enabled\n");
175 return -ENODEV; 183 ret = -ENODEV;
184 goto err_put_device;
176 } 185 }
177 } 186 }
178 187
179 return 0; 188 return 0;
189
190err_put_device:
191 put_device(&op->dev);
192 return ret;
180} 193}
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 18c711b19514..3b5f5b3fb1bc 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -59,14 +59,21 @@ struct qoriq_tmu_regs {
59 u32 ttr3cr; /* Temperature Range 3 Control Register */ 59 u32 ttr3cr; /* Temperature Range 3 Control Register */
60}; 60};
61 61
62struct qoriq_tmu_data;
63
62/* 64/*
63 * Thermal zone data 65 * Thermal zone data
64 */ 66 */
67struct qoriq_sensor {
68 struct thermal_zone_device *tzd;
69 struct qoriq_tmu_data *qdata;
70 int id;
71};
72
65struct qoriq_tmu_data { 73struct qoriq_tmu_data {
66 struct thermal_zone_device *tz;
67 struct qoriq_tmu_regs __iomem *regs; 74 struct qoriq_tmu_regs __iomem *regs;
68 int sensor_id;
69 bool little_endian; 75 bool little_endian;
76 struct qoriq_sensor *sensor[SITES_MAX];
70}; 77};
71 78
72static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr) 79static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr)
@@ -87,48 +94,50 @@ static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr)
87 94
88static int tmu_get_temp(void *p, int *temp) 95static int tmu_get_temp(void *p, int *temp)
89{ 96{
97 struct qoriq_sensor *qsensor = p;
98 struct qoriq_tmu_data *qdata = qsensor->qdata;
90 u32 val; 99 u32 val;
91 struct qoriq_tmu_data *data = p;
92 100
93 val = tmu_read(data, &data->regs->site[data->sensor_id].tritsr); 101 val = tmu_read(qdata, &qdata->regs->site[qsensor->id].tritsr);
94 *temp = (val & 0xff) * 1000; 102 *temp = (val & 0xff) * 1000;
95 103
96 return 0; 104 return 0;
97} 105}
98 106
99static int qoriq_tmu_get_sensor_id(void) 107static const struct thermal_zone_of_device_ops tmu_tz_ops = {
100{ 108 .get_temp = tmu_get_temp,
101 int ret, id; 109};
102 struct of_phandle_args sensor_specs;
103 struct device_node *np, *sensor_np;
104
105 np = of_find_node_by_name(NULL, "thermal-zones");
106 if (!np)
107 return -ENODEV;
108
109 sensor_np = of_get_next_child(np, NULL);
110 ret = of_parse_phandle_with_args(sensor_np, "thermal-sensors",
111 "#thermal-sensor-cells",
112 0, &sensor_specs);
113 if (ret) {
114 of_node_put(np);
115 of_node_put(sensor_np);
116 return ret;
117 }
118 110
119 if (sensor_specs.args_count >= 1) { 111static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev)
120 id = sensor_specs.args[0]; 112{
121 WARN(sensor_specs.args_count > 1, 113 struct qoriq_tmu_data *qdata = platform_get_drvdata(pdev);
122 "%pOFn: too many cells in sensor specifier %d\n", 114 int id, sites = 0;
123 sensor_specs.np, sensor_specs.args_count); 115
124 } else { 116 for (id = 0; id < SITES_MAX; id++) {
125 id = 0; 117 qdata->sensor[id] = devm_kzalloc(&pdev->dev,
118 sizeof(struct qoriq_sensor), GFP_KERNEL);
119 if (!qdata->sensor[id])
120 return -ENOMEM;
121
122 qdata->sensor[id]->id = id;
123 qdata->sensor[id]->qdata = qdata;
124 qdata->sensor[id]->tzd = devm_thermal_zone_of_sensor_register(
125 &pdev->dev, id, qdata->sensor[id], &tmu_tz_ops);
126 if (IS_ERR(qdata->sensor[id]->tzd)) {
127 if (PTR_ERR(qdata->sensor[id]->tzd) == -ENODEV)
128 continue;
129 else
130 return PTR_ERR(qdata->sensor[id]->tzd);
131 }
132
133 sites |= 0x1 << (15 - id);
126 } 134 }
127 135
128 of_node_put(np); 136 /* Enable monitoring */
129 of_node_put(sensor_np); 137 if (sites != 0)
138 tmu_write(qdata, sites | TMR_ME | TMR_ALPF, &qdata->regs->tmr);
130 139
131 return id; 140 return 0;
132} 141}
133 142
134static int qoriq_tmu_calibration(struct platform_device *pdev) 143static int qoriq_tmu_calibration(struct platform_device *pdev)
@@ -178,16 +187,11 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
178 tmu_write(data, TMR_DISABLE, &data->regs->tmr); 187 tmu_write(data, TMR_DISABLE, &data->regs->tmr);
179} 188}
180 189
181static const struct thermal_zone_of_device_ops tmu_tz_ops = {
182 .get_temp = tmu_get_temp,
183};
184
185static int qoriq_tmu_probe(struct platform_device *pdev) 190static int qoriq_tmu_probe(struct platform_device *pdev)
186{ 191{
187 int ret; 192 int ret;
188 struct qoriq_tmu_data *data; 193 struct qoriq_tmu_data *data;
189 struct device_node *np = pdev->dev.of_node; 194 struct device_node *np = pdev->dev.of_node;
190 u32 site;
191 195
192 if (!np) { 196 if (!np) {
193 dev_err(&pdev->dev, "Device OF-Node is NULL"); 197 dev_err(&pdev->dev, "Device OF-Node is NULL");
@@ -203,13 +207,6 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
203 207
204 data->little_endian = of_property_read_bool(np, "little-endian"); 208 data->little_endian = of_property_read_bool(np, "little-endian");
205 209
206 data->sensor_id = qoriq_tmu_get_sensor_id();
207 if (data->sensor_id < 0) {
208 dev_err(&pdev->dev, "Failed to get sensor id\n");
209 ret = -ENODEV;
210 goto err_iomap;
211 }
212
213 data->regs = of_iomap(np, 0); 210 data->regs = of_iomap(np, 0);
214 if (!data->regs) { 211 if (!data->regs) {
215 dev_err(&pdev->dev, "Failed to get memory region\n"); 212 dev_err(&pdev->dev, "Failed to get memory region\n");
@@ -223,20 +220,13 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
223 if (ret < 0) 220 if (ret < 0)
224 goto err_tmu; 221 goto err_tmu;
225 222
226 data->tz = devm_thermal_zone_of_sensor_register(&pdev->dev, 223 ret = qoriq_tmu_register_tmu_zone(pdev);
227 data->sensor_id, 224 if (ret < 0) {
228 data, &tmu_tz_ops); 225 dev_err(&pdev->dev, "Failed to register sensors\n");
229 if (IS_ERR(data->tz)) { 226 ret = -ENODEV;
230 ret = PTR_ERR(data->tz); 227 goto err_iomap;
231 dev_err(&pdev->dev,
232 "Failed to register thermal zone device %d\n", ret);
233 goto err_tmu;
234 } 228 }
235 229
236 /* Enable monitoring */
237 site = 0x1 << (15 - data->sensor_id);
238 tmu_write(data, site | TMR_ME | TMR_ALPF, &data->regs->tmr);
239
240 return 0; 230 return 0;
241 231
242err_tmu: 232err_tmu:
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index 75786cc8e2f9..88fa41cf16e8 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -19,6 +19,7 @@
19#include <linux/thermal.h> 19#include <linux/thermal.h>
20 20
21#include "thermal_core.h" 21#include "thermal_core.h"
22#include "thermal_hwmon.h"
22 23
23/* Register offsets */ 24/* Register offsets */
24#define REG_GEN3_IRQSTR 0x04 25#define REG_GEN3_IRQSTR 0x04
@@ -337,6 +338,13 @@ static int rcar_gen3_thermal_remove(struct platform_device *pdev)
337 return 0; 338 return 0;
338} 339}
339 340
341static void rcar_gen3_hwmon_action(void *data)
342{
343 struct thermal_zone_device *zone = data;
344
345 thermal_remove_hwmon_sysfs(zone);
346}
347
340static int rcar_gen3_thermal_probe(struct platform_device *pdev) 348static int rcar_gen3_thermal_probe(struct platform_device *pdev)
341{ 349{
342 struct rcar_gen3_thermal_priv *priv; 350 struct rcar_gen3_thermal_priv *priv;
@@ -429,6 +437,17 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
429 if (ret < 0) 437 if (ret < 0)
430 goto error_unregister; 438 goto error_unregister;
431 439
440 tsc->zone->tzp->no_hwmon = false;
441 ret = thermal_add_hwmon_sysfs(tsc->zone);
442 if (ret)
443 goto error_unregister;
444
445 ret = devm_add_action(dev, rcar_gen3_hwmon_action, zone);
446 if (ret) {
447 rcar_gen3_hwmon_action(zone);
448 goto error_unregister;
449 }
450
432 dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret); 451 dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret);
433 } 452 }
434 453
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index 45b41b885f49..70043a28eb7a 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -488,9 +488,41 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
488 return 0; 488 return 0;
489} 489}
490 490
491static int tegra_thermctl_get_trend(void *data, int trip,
492 enum thermal_trend *trend)
493{
494 struct tegra_thermctl_zone *zone = data;
495 struct thermal_zone_device *tz = zone->tz;
496 int trip_temp, temp, last_temp, ret;
497
498 if (!tz)
499 return -EINVAL;
500
501 ret = tz->ops->get_trip_temp(zone->tz, trip, &trip_temp);
502 if (ret)
503 return ret;
504
505 temp = READ_ONCE(tz->temperature);
506 last_temp = READ_ONCE(tz->last_temperature);
507
508 if (temp > trip_temp) {
509 if (temp >= last_temp)
510 *trend = THERMAL_TREND_RAISING;
511 else
512 *trend = THERMAL_TREND_STABLE;
513 } else if (temp < trip_temp) {
514 *trend = THERMAL_TREND_DROPPING;
515 } else {
516 *trend = THERMAL_TREND_STABLE;
517 }
518
519 return 0;
520}
521
491static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = { 522static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {
492 .get_temp = tegra_thermctl_get_temp, 523 .get_temp = tegra_thermctl_get_temp,
493 .set_trip_temp = tegra_thermctl_set_trip_temp, 524 .set_trip_temp = tegra_thermctl_set_trip_temp,
525 .get_trend = tegra_thermctl_get_trend,
494}; 526};
495 527
496static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp) 528static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp)
@@ -569,7 +601,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
569set_throttle: 601set_throttle:
570 ret = get_hot_temp(tz, &trip, &temperature); 602 ret = get_hot_temp(tz, &trip, &temperature);
571 if (ret) { 603 if (ret) {
572 dev_warn(dev, "throttrip: %s: missing hot temperature\n", 604 dev_info(dev, "throttrip: %s: missing hot temperature\n",
573 sg->name); 605 sg->name);
574 return 0; 606 return 0;
575 } 607 }
@@ -600,7 +632,7 @@ set_throttle:
600 } 632 }
601 633
602 if (i == THROTTLE_SIZE) 634 if (i == THROTTLE_SIZE)
603 dev_warn(dev, "throttrip: %s: missing throttle cdev\n", 635 dev_info(dev, "throttrip: %s: missing throttle cdev\n",
604 sg->name); 636 sg->name);
605 637
606 return 0; 638 return 0;
@@ -1329,7 +1361,7 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
1329 } 1361 }
1330 1362
1331 tegra->thermctl_tzs = devm_kcalloc(&pdev->dev, 1363 tegra->thermctl_tzs = devm_kcalloc(&pdev->dev,
1332 soc->num_ttgs, sizeof(*z), 1364 soc->num_ttgs, sizeof(z),
1333 GFP_KERNEL); 1365 GFP_KERNEL);
1334 if (!tegra->thermctl_tzs) 1366 if (!tegra->thermctl_tzs)
1335 return -ENOMEM; 1367 return -ENOMEM;