Commit a91db95479e75c70ec49676e9a347787b054d651

Authored by Tim Harvey
Committed by Stefano Babic
1 parent 70caa8e21d

thermal: imx_thermal: use CPU temperature grade for trip points

Replace the hard-coded values for min/max/passive with values derived from
the CPU temperature grade.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>

Showing 1 changed file with 19 additions and 10 deletions Side-by-side Diff

drivers/thermal/imx_thermal.c
... ... @@ -12,15 +12,13 @@
12 12 #include <fuse.h>
13 13 #include <asm/io.h>
14 14 #include <asm/arch/clock.h>
  15 +#include <asm/arch/sys_proto.h>
15 16 #include <dm.h>
16 17 #include <errno.h>
17 18 #include <malloc.h>
18 19 #include <thermal.h>
19 20 #include <imx_thermal.h>
20 21  
21   -#define TEMPERATURE_MIN -40
22   -#define TEMPERATURE_HOT 80
23   -#define TEMPERATURE_MAX 125
24 22 #define FACTOR0 10000000
25 23 #define FACTOR1 15976
26 24 #define FACTOR2 4297157
27 25  
... ... @@ -34,14 +32,21 @@
34 32 #define MISC0_REFTOP_SELBIASOFF (1 << 3)
35 33 #define TEMPSENSE1_MEASURE_FREQ 0xffff
36 34  
  35 +struct thermal_data {
  36 + unsigned int fuse;
  37 + int passive;
  38 + int minc;
  39 + int maxc;
  40 +};
  41 +
37 42 static int read_cpu_temperature(struct udevice *dev)
38 43 {
39 44 int temperature;
40 45 unsigned int reg, n_meas;
41 46 const struct imx_thermal_plat *pdata = dev_get_platdata(dev);
42 47 struct anatop_regs *anatop = (struct anatop_regs *)pdata->regs;
43   - unsigned int *priv = dev_get_priv(dev);
44   - u32 fuse = *priv;
  48 + struct thermal_data *priv = dev_get_priv(dev);
  49 + u32 fuse = priv->fuse;
45 50 int t1, n1;
46 51 u32 c1, c2;
47 52 u64 temp64;
48 53  
... ... @@ -119,11 +124,12 @@
119 124  
120 125 int imx_thermal_get_temp(struct udevice *dev, int *temp)
121 126 {
  127 + struct thermal_data *priv = dev_get_priv(dev);
122 128 int cpu_tmp = 0;
123 129  
124 130 cpu_tmp = read_cpu_temperature(dev);
125   - while (cpu_tmp > TEMPERATURE_MIN && cpu_tmp < TEMPERATURE_MAX) {
126   - if (cpu_tmp >= TEMPERATURE_HOT) {
  131 + while (cpu_tmp > priv->minc && cpu_tmp < priv->maxc) {
  132 + if (cpu_tmp >= priv->passive) {
127 133 printf("CPU Temperature is %d C, too hot to boot, waiting...\n",
128 134 cpu_tmp);
129 135 udelay(5000000);
... ... @@ -147,7 +153,7 @@
147 153 unsigned int fuse = ~0;
148 154  
149 155 const struct imx_thermal_plat *pdata = dev_get_platdata(dev);
150   - unsigned int *priv = dev_get_priv(dev);
  156 + struct thermal_data *priv = dev_get_priv(dev);
151 157  
152 158 /* Read Temperature calibration data fuse */
153 159 fuse_read(pdata->fuse_bank, pdata->fuse_word, &fuse);
... ... @@ -158,7 +164,10 @@
158 164 return -EPERM;
159 165 }
160 166  
161   - *priv = fuse;
  167 + /* set passive cooling temp to max - 20C */
  168 + get_cpu_temp_grade(&priv->minc, &priv->maxc);
  169 + priv->passive = priv->maxc - 20;
  170 + priv->fuse = fuse;
162 171  
163 172 enable_thermal_clk();
164 173  
... ... @@ -170,7 +179,7 @@
170 179 .id = UCLASS_THERMAL,
171 180 .ops = &imx_thermal_ops,
172 181 .probe = imx_thermal_probe,
173   - .priv_auto_alloc_size = sizeof(unsigned int),
  182 + .priv_auto_alloc_size = sizeof(struct thermal_data),
174 183 .flags = DM_FLAG_PRE_RELOC,
175 184 };