Skip to content

Commit a2291ba

Browse files
GateworksEduardo Valentin
authored andcommitted
imx: thermal: use CPU temperature grade info for thresholds
The IMX6Q/IMX6DL SoC's have a 2-bit temperature grade stored in OTP which is valid for all IMX6 SoC's (despite the fact that the IMXSDLRM and IMXSXRM do not document this - this has been proven via tests as well as verified by Freescale FAE). Instead of assuming a fixed 85C for passive cooling threshold and 105C for critical use the thermal grade for these configurations. We will set the critical to maxT - 5C and passive to maxT - 10C. Cc: Anson Huang <b20788@freescale.com> Cc: Fabio Estevam <fabio.estevam@freescale.com> Acked-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Jon Nettleton <jon@solid-run.com> Signed-off-by: Tim Harvey <tharvey@gateworks.com> ---- v3: - rebase against linux-soc-thermal.git - added ack's from Shawn and Jon v2: - remove check for IMX6Q and update comments: The OTP values have been tested on IMX6SOLO, IMX6DUALLITE, and IMX6SX and Freescale FAE has shared data with me that the OTP settings are the same and that the reference manuals will reflect this in their next updates. - set critical to max - 5C - set passive to max - 10C - display max temp in info - do not allow passive to be set above critical Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
1 parent c86b3de commit a2291ba

1 file changed

Lines changed: 41 additions & 15 deletions

File tree

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 */

0 commit comments

Comments
 (0)