Skip to content

Commit 75a29ec

Browse files
committed
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
Pull thermal management fixes from Zhang Rui: "Specifics: - several fixes and cleanups on Rockchip thermal drivers. - add the missing support of RK3368 SoCs in Rockchip driver. - small fixes on of-thermal, power_allocator, rcar driver, IMX, and QCOM drivers, and also compilation fixes, on thermal.h, when thermal is not selected" * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux: imx: thermal: use CPU temperature grade info for thresholds thermal: fix thermal_zone_bind_cooling_device prototype Revert "thermal: qcom_spmi: allow compile test" thermal: rcar_thermal: remove redundant operation thermal: of-thermal: Reduce log level for message when can't fine thermal zone thermal: power_allocator: Use temperature reading from tz thermal: rockchip: Support the RK3368 SoCs in thermal driver thermal: rockchip: consistently use int for temperatures thermal: rockchip: Add the sort mode for adc value increment or decrement thermal: rockchip: improve the conversion function thermal: rockchip: trivial: fix typo in commit thermal: rockchip: better to compatible the driver for different SoCs dt-bindings: rockchip-thermal: Support the RK3368 SoCs compatible
2 parents 081f369 + a2291ba commit 75a29ec

File tree

8 files changed

+316
-152
lines changed

8 files changed

+316
-152
lines changed

Documentation/devicetree/bindings/thermal/rockchip-thermal.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
* Temperature Sensor ADC (TSADC) on rockchip SoCs
22

33
Required properties:
4-
- compatible : "rockchip,rk3288-tsadc"
4+
- compatible : should be "rockchip,<name>-tsadc"
5+
"rockchip,rk3288-tsadc": found on RK3288 SoCs
6+
"rockchip,rk3368-tsadc": found on RK3368 SoCs
57
- reg : physical base address of the controller and length of memory mapped
68
region.
79
- interrupts : The interrupt number to the cpu. The interrupt specifier format

drivers/thermal/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ endmenu
382382

383383
config QCOM_SPMI_TEMP_ALARM
384384
tristate "Qualcomm SPMI PMIC Temperature Alarm"
385-
depends on OF && (SPMI || COMPILE_TEST) && IIO
385+
depends on OF && SPMI && IIO
386386
select REGMAP_SPMI
387387
help
388388
This enables a thermal sysfs driver for Qualcomm plug-and-play (QPNP)

drivers/thermal/imx_thermal.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define TEMPSENSE2_PANIC_VALUE_SHIFT 16
5656
#define TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000
5757

58+
#define OCOTP_MEM0 0x0480
5859
#define OCOTP_ANA1 0x04e0
5960

6061
/* The driver supports 1 passive trip point and 1 critical trip point */
@@ -64,12 +65,6 @@ enum imx_thermal_trip {
6465
IMX_TRIP_NUM,
6566
};
6667

67-
/*
68-
* It defines the temperature in millicelsius for passive trip point
69-
* that will trigger cooling action when crossed.
70-
*/
71-
#define IMX_TEMP_PASSIVE 85000
72-
7368
#define IMX_POLLING_DELAY 2000 /* millisecond */
7469
#define IMX_PASSIVE_DELAY 1000
7570

@@ -100,12 +95,14 @@ struct imx_thermal_data {
10095
u32 c1, c2; /* See formula in imx_get_sensor_data() */
10196
int temp_passive;
10297
int temp_critical;
98+
int temp_max;
10399
int alarm_temp;
104100
int last_temp;
105101
bool irq_enabled;
106102
int irq;
107103
struct clk *thermal_clk;
108104
const struct thermal_soc_data *socdata;
105+
const char *temp_grade;
109106
};
110107

111108
static void imx_set_panic_temp(struct imx_thermal_data *data,
@@ -285,10 +282,12 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
285282
{
286283
struct imx_thermal_data *data = tz->devdata;
287284

285+
/* do not allow changing critical threshold */
288286
if (trip == IMX_TRIP_CRITICAL)
289287
return -EPERM;
290288

291-
if (temp < 0 || temp > IMX_TEMP_PASSIVE)
289+
/* do not allow passive to be set higher than critical */
290+
if (temp < 0 || temp > data->temp_critical)
292291
return -EINVAL;
293292

294293
data->temp_passive = temp;
@@ -404,17 +403,39 @@ static int imx_get_sensor_data(struct platform_device *pdev)
404403
data->c1 = temp64;
405404
data->c2 = n1 * data->c1 + 1000 * t1;
406405

407-
/*
408-
* Set the default passive cooling trip point,
409-
* can be changed from userspace.
410-
*/
411-
data->temp_passive = IMX_TEMP_PASSIVE;
406+
/* use OTP for thermal grade */
407+
ret = regmap_read(map, OCOTP_MEM0, &val);
408+
if (ret) {
409+
dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret);
410+
return ret;
411+
}
412+
413+
/* The maximum die temp is specified by the Temperature Grade */
414+
switch ((val >> 6) & 0x3) {
415+
case 0: /* Commercial (0 to 95C) */
416+
data->temp_grade = "Commercial";
417+
data->temp_max = 95000;
418+
break;
419+
case 1: /* Extended Commercial (-20 to 105C) */
420+
data->temp_grade = "Extended Commercial";
421+
data->temp_max = 105000;
422+
break;
423+
case 2: /* Industrial (-40 to 105C) */
424+
data->temp_grade = "Industrial";
425+
data->temp_max = 105000;
426+
break;
427+
case 3: /* Automotive (-40 to 125C) */
428+
data->temp_grade = "Automotive";
429+
data->temp_max = 125000;
430+
break;
431+
}
412432

413433
/*
414-
* The maximum die temperature set to 20 C higher than
415-
* IMX_TEMP_PASSIVE.
434+
* Set the critical trip point at 5C under max
435+
* Set the passive trip point at 10C under max (can change via sysfs)
416436
*/
417-
data->temp_critical = 1000 * 20 + data->temp_passive;
437+
data->temp_critical = data->temp_max - (1000 * 5);
438+
data->temp_passive = data->temp_max - (1000 * 10);
418439

419440
return 0;
420441
}
@@ -551,6 +572,11 @@ static int imx_thermal_probe(struct platform_device *pdev)
551572
return ret;
552573
}
553574

575+
dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC"
576+
" critical:%dC passive:%dC\n", data->temp_grade,
577+
data->temp_max / 1000, data->temp_critical / 1000,
578+
data->temp_passive / 1000);
579+
554580
/* Enable measurements at ~ 10 Hz */
555581
regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ);
556582
measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */

drivers/thermal/of-thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ void of_thermal_destroy_zones(void)
964964

965965
np = of_find_node_by_name(NULL, "thermal-zones");
966966
if (!np) {
967-
pr_err("unable to find thermal zones\n");
967+
pr_debug("unable to find thermal zones\n");
968968
return;
969969
}
970970

drivers/thermal/power_allocator.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
174174
/**
175175
* pid_controller() - PID controller
176176
* @tz: thermal zone we are operating in
177-
* @current_temp: the current temperature in millicelsius
178177
* @control_temp: the target temperature in millicelsius
179178
* @max_allocatable_power: maximum allocatable power for this thermal zone
180179
*
@@ -191,7 +190,6 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
191190
* Return: The power budget for the next period.
192191
*/
193192
static u32 pid_controller(struct thermal_zone_device *tz,
194-
int current_temp,
195193
int control_temp,
196194
u32 max_allocatable_power)
197195
{
@@ -211,7 +209,7 @@ static u32 pid_controller(struct thermal_zone_device *tz,
211209
true);
212210
}
213211

214-
err = control_temp - current_temp;
212+
err = control_temp - tz->temperature;
215213
err = int_to_frac(err);
216214

217215
/* Calculate the proportional term */
@@ -332,7 +330,6 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
332330
}
333331

334332
static int allocate_power(struct thermal_zone_device *tz,
335-
int current_temp,
336333
int control_temp)
337334
{
338335
struct thermal_instance *instance;
@@ -418,8 +415,7 @@ static int allocate_power(struct thermal_zone_device *tz,
418415
i++;
419416
}
420417

421-
power_range = pid_controller(tz, current_temp, control_temp,
422-
max_allocatable_power);
418+
power_range = pid_controller(tz, control_temp, max_allocatable_power);
423419

424420
divvy_up_power(weighted_req_power, max_power, num_actors,
425421
total_weighted_req_power, power_range, granted_power,
@@ -444,8 +440,8 @@ static int allocate_power(struct thermal_zone_device *tz,
444440
trace_thermal_power_allocator(tz, req_power, total_req_power,
445441
granted_power, total_granted_power,
446442
num_actors, power_range,
447-
max_allocatable_power, current_temp,
448-
control_temp - current_temp);
443+
max_allocatable_power, tz->temperature,
444+
control_temp - tz->temperature);
449445

450446
kfree(req_power);
451447
unlock:
@@ -612,7 +608,7 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
612608
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
613609
{
614610
int ret;
615-
int switch_on_temp, control_temp, current_temp;
611+
int switch_on_temp, control_temp;
616612
struct power_allocator_params *params = tz->governor_data;
617613

618614
/*
@@ -622,15 +618,9 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
622618
if (trip != params->trip_max_desired_temperature)
623619
return 0;
624620

625-
ret = thermal_zone_get_temp(tz, &current_temp);
626-
if (ret) {
627-
dev_warn(&tz->device, "Failed to get temperature: %d\n", ret);
628-
return ret;
629-
}
630-
631621
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
632622
&switch_on_temp);
633-
if (!ret && (current_temp < switch_on_temp)) {
623+
if (!ret && (tz->temperature < switch_on_temp)) {
634624
tz->passive = 0;
635625
reset_pid_controller(params);
636626
allow_maximum_power(tz);
@@ -648,7 +638,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
648638
return ret;
649639
}
650640

651-
return allocate_power(tz, current_temp, control_temp);
641+
return allocate_power(tz, control_temp);
652642
}
653643

654644
static struct thermal_governor thermal_gov_power_allocator = {

drivers/thermal/rcar_thermal.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,24 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
361361
/*
362362
* platform functions
363363
*/
364+
static int rcar_thermal_remove(struct platform_device *pdev)
365+
{
366+
struct rcar_thermal_common *common = platform_get_drvdata(pdev);
367+
struct device *dev = &pdev->dev;
368+
struct rcar_thermal_priv *priv;
369+
370+
rcar_thermal_for_each_priv(priv, common) {
371+
if (rcar_has_irq_support(priv))
372+
rcar_thermal_irq_disable(priv);
373+
thermal_zone_device_unregister(priv->zone);
374+
}
375+
376+
pm_runtime_put(dev);
377+
pm_runtime_disable(dev);
378+
379+
return 0;
380+
}
381+
364382
static int rcar_thermal_probe(struct platform_device *pdev)
365383
{
366384
struct rcar_thermal_common *common;
@@ -377,6 +395,8 @@ static int rcar_thermal_probe(struct platform_device *pdev)
377395
if (!common)
378396
return -ENOMEM;
379397

398+
platform_set_drvdata(pdev, common);
399+
380400
INIT_LIST_HEAD(&common->head);
381401
spin_lock_init(&common->lock);
382402
common->dev = dev;
@@ -454,43 +474,16 @@ static int rcar_thermal_probe(struct platform_device *pdev)
454474
rcar_thermal_common_write(common, ENR, enr_bits);
455475
}
456476

457-
platform_set_drvdata(pdev, common);
458-
459477
dev_info(dev, "%d sensor probed\n", i);
460478

461479
return 0;
462480

463481
error_unregister:
464-
rcar_thermal_for_each_priv(priv, common) {
465-
if (rcar_has_irq_support(priv))
466-
rcar_thermal_irq_disable(priv);
467-
thermal_zone_device_unregister(priv->zone);
468-
}
469-
470-
pm_runtime_put(dev);
471-
pm_runtime_disable(dev);
482+
rcar_thermal_remove(pdev);
472483

473484
return ret;
474485
}
475486

476-
static int rcar_thermal_remove(struct platform_device *pdev)
477-
{
478-
struct rcar_thermal_common *common = platform_get_drvdata(pdev);
479-
struct device *dev = &pdev->dev;
480-
struct rcar_thermal_priv *priv;
481-
482-
rcar_thermal_for_each_priv(priv, common) {
483-
if (rcar_has_irq_support(priv))
484-
rcar_thermal_irq_disable(priv);
485-
thermal_zone_device_unregister(priv->zone);
486-
}
487-
488-
pm_runtime_put(dev);
489-
pm_runtime_disable(dev);
490-
491-
return 0;
492-
}
493-
494487
static const struct of_device_id rcar_thermal_dt_ids[] = {
495488
{ .compatible = "renesas,rcar-thermal", },
496489
{},

0 commit comments

Comments
 (0)