6baf7dd801fb1abe7ec92212cb8c478a12e8bec1
[openwrt.git] / target / linux / imx6 / patches-4.3 / 045-imx-thermal-use-cpu-temperature-grade-info-for-thresholds
1 --- a/drivers/thermal/imx_thermal.c
2 +++ b/drivers/thermal/imx_thermal.c
3 @@ -55,6 +55,7 @@
4  #define TEMPSENSE2_PANIC_VALUE_SHIFT   16
5  #define TEMPSENSE2_PANIC_VALUE_MASK    0xfff0000
6  
7 +#define OCOTP_MEM0                     0x0480
8  #define OCOTP_ANA1                     0x04e0
9  
10  /* The driver supports 1 passive trip point and 1 critical trip point */
11 @@ -64,12 +65,6 @@ enum imx_thermal_trip {
12         IMX_TRIP_NUM,
13  };
14  
15 -/*
16 - * It defines the temperature in millicelsius for passive trip point
17 - * that will trigger cooling action when crossed.
18 - */
19 -#define IMX_TEMP_PASSIVE               85000
20 -
21  #define IMX_POLLING_DELAY              2000 /* millisecond */
22  #define IMX_PASSIVE_DELAY              1000
23  
24 @@ -100,12 +95,14 @@ struct imx_thermal_data {
25         u32 c1, c2; /* See formula in imx_get_sensor_data() */
26         int temp_passive;
27         int temp_critical;
28 +       unsigned long temp_max;
29         int alarm_temp;
30         int last_temp;
31         bool irq_enabled;
32         int irq;
33         struct clk *thermal_clk;
34         const struct thermal_soc_data *socdata;
35 +       const char *temp_grade;
36  };
37  
38  static void imx_set_panic_temp(struct imx_thermal_data *data,
39 @@ -285,10 +282,12 @@ static int imx_set_trip_temp(struct ther
40  {
41         struct imx_thermal_data *data = tz->devdata;
42  
43 +       /* do not allow changing critical threshold */
44         if (trip == IMX_TRIP_CRITICAL)
45                 return -EPERM;
46  
47 -       if (temp > IMX_TEMP_PASSIVE)
48 +       /* do not allow passive to be set higher than critical */
49 +       if (temp < 0 || temp > data->temp_critical)
50                 return -EINVAL;
51  
52         data->temp_passive = temp;
53 @@ -404,17 +403,39 @@ static int imx_get_sensor_data(struct pl
54         data->c1 = temp64;
55         data->c2 = n1 * data->c1 + 1000 * t1;
56  
57 -       /*
58 -        * Set the default passive cooling trip point,
59 -        * can be changed from userspace.
60 -        */
61 -       data->temp_passive = IMX_TEMP_PASSIVE;
62 +       /* use OTP for thermal grade */
63 +       ret = regmap_read(map, OCOTP_MEM0, &val);
64 +       if (ret) {
65 +               dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret);
66 +               return ret;
67 +       }
68 +
69 +       /* The maximum die temp is specified by the Temperature Grade */
70 +       switch ((val >> 6) & 0x3) {
71 +       case 0: /* Commercial (0 to 95C) */
72 +               data->temp_grade = "Commercial";
73 +               data->temp_max = 95000;
74 +               break;
75 +       case 1: /* Extended Commercial (-20 to 105C) */
76 +               data->temp_grade = "Extended Commercial";
77 +               data->temp_max = 105000;
78 +               break;
79 +       case 2: /* Industrial (-40 to 105C) */
80 +               data->temp_grade = "Industrial";
81 +               data->temp_max = 105000;
82 +               break;
83 +       case 3: /* Automotive (-40 to 125C) */
84 +               data->temp_grade = "Automotive";
85 +               data->temp_max = 125000;
86 +               break;
87 +       }
88  
89         /*
90 -        * The maximum die temperature set to 20 C higher than
91 -        * IMX_TEMP_PASSIVE.
92 +        * Set the critical trip point at 5C under max
93 +        * Set the passive trip point at 10C under max (can change via sysfs)
94          */
95 -       data->temp_critical = 1000 * 20 + data->temp_passive;
96 +       data->temp_critical = data->temp_max - (1000 * 5);
97 +       data->temp_passive = data->temp_max - (1000 * 10);
98  
99         return 0;
100  }
101 @@ -559,6 +580,11 @@ static int imx_thermal_probe(struct plat
102                 return ret;
103         }
104  
105 +       dev_info(&pdev->dev, "%s CPU temperature grade - max:%ldC"
106 +                " critical:%ldC passive:%ldC\n", data->temp_grade,
107 +                data->temp_max / 1000, data->temp_critical / 1000,
108 +                data->temp_passive / 1000);
109 +
110         /* Enable measurements at ~ 10 Hz */
111         regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ);
112         measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */