Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
omap-bandgap.h
Go to the documentation of this file.
1 /*
2  * OMAP4 Bandgap temperature sensor driver
3  *
4  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5  * Contact:
6  * Eduardo Valentin <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 #ifndef __OMAP_BANDGAP_H
24 #define __OMAP_BANDGAP_H
25 
26 #include <linux/mutex.h>
27 #include <linux/types.h>
28 #include <linux/err.h>
29 
30 /* TEMP_SENSOR OMAP4430 */
31 #define OMAP4430_BGAP_TSHUT_SHIFT 11
32 #define OMAP4430_BGAP_TSHUT_MASK (1 << 11)
33 
34 /* TEMP_SENSOR OMAP4430 */
35 #define OMAP4430_BGAP_TEMPSOFF_SHIFT 12
36 #define OMAP4430_BGAP_TEMPSOFF_MASK (1 << 12)
37 #define OMAP4430_SINGLE_MODE_SHIFT 10
38 #define OMAP4430_SINGLE_MODE_MASK (1 << 10)
39 #define OMAP4430_BGAP_TEMP_SENSOR_SOC_SHIFT 9
40 #define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK (1 << 9)
41 #define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 8
42 #define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 8)
43 #define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0
44 #define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK (0xff << 0)
45 
46 #define OMAP4430_ADC_START_VALUE 0
47 #define OMAP4430_ADC_END_VALUE 127
48 #define OMAP4430_MAX_FREQ 32768
49 #define OMAP4430_MIN_FREQ 32768
50 #define OMAP4430_MIN_TEMP -40000
51 #define OMAP4430_MAX_TEMP 125000
52 #define OMAP4430_HYST_VAL 5000
53 
54 /* TEMP_SENSOR OMAP4460 */
55 #define OMAP4460_BGAP_TEMPSOFF_SHIFT 13
56 #define OMAP4460_BGAP_TEMPSOFF_MASK (1 << 13)
57 #define OMAP4460_BGAP_TEMP_SENSOR_SOC_SHIFT 11
58 #define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK (1 << 11)
59 #define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10
60 #define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 10)
61 #define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0
62 #define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)
63 
64 /* BANDGAP_CTRL */
65 #define OMAP4460_SINGLE_MODE_SHIFT 31
66 #define OMAP4460_SINGLE_MODE_MASK (1 << 31)
67 #define OMAP4460_MASK_HOT_SHIFT 1
68 #define OMAP4460_MASK_HOT_MASK (1 << 1)
69 #define OMAP4460_MASK_COLD_SHIFT 0
70 #define OMAP4460_MASK_COLD_MASK (1 << 0)
71 
72 /* BANDGAP_COUNTER */
73 #define OMAP4460_COUNTER_SHIFT 0
74 #define OMAP4460_COUNTER_MASK (0xffffff << 0)
75 
76 /* BANDGAP_THRESHOLD */
77 #define OMAP4460_T_HOT_SHIFT 16
78 #define OMAP4460_T_HOT_MASK (0x3ff << 16)
79 #define OMAP4460_T_COLD_SHIFT 0
80 #define OMAP4460_T_COLD_MASK (0x3ff << 0)
81 
82 /* TSHUT_THRESHOLD */
83 #define OMAP4460_TSHUT_HOT_SHIFT 16
84 #define OMAP4460_TSHUT_HOT_MASK (0x3ff << 16)
85 #define OMAP4460_TSHUT_COLD_SHIFT 0
86 #define OMAP4460_TSHUT_COLD_MASK (0x3ff << 0)
87 
88 /* BANDGAP_STATUS */
89 #define OMAP4460_CLEAN_STOP_SHIFT 3
90 #define OMAP4460_CLEAN_STOP_MASK (1 << 3)
91 #define OMAP4460_BGAP_ALERT_SHIFT 2
92 #define OMAP4460_BGAP_ALERT_MASK (1 << 2)
93 #define OMAP4460_HOT_FLAG_SHIFT 1
94 #define OMAP4460_HOT_FLAG_MASK (1 << 1)
95 #define OMAP4460_COLD_FLAG_SHIFT 0
96 #define OMAP4460_COLD_FLAG_MASK (1 << 0)
97 
98 /* TEMP_SENSOR OMAP5430 */
99 #define OMAP5430_BGAP_TEMP_SENSOR_SOC_SHIFT 12
100 #define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK (1 << 12)
101 #define OMAP5430_BGAP_TEMPSOFF_SHIFT 11
102 #define OMAP5430_BGAP_TEMPSOFF_MASK (1 << 11)
103 #define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10
104 #define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 10)
105 #define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0
106 #define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)
107 
108 /* BANDGAP_CTRL */
109 #define OMAP5430_MASK_HOT_CORE_SHIFT 5
110 #define OMAP5430_MASK_HOT_CORE_MASK (1 << 5)
111 #define OMAP5430_MASK_COLD_CORE_SHIFT 4
112 #define OMAP5430_MASK_COLD_CORE_MASK (1 << 4)
113 #define OMAP5430_MASK_HOT_MM_SHIFT 3
114 #define OMAP5430_MASK_HOT_MM_MASK (1 << 3)
115 #define OMAP5430_MASK_COLD_MM_SHIFT 2
116 #define OMAP5430_MASK_COLD_MM_MASK (1 << 2)
117 #define OMAP5430_MASK_HOT_MPU_SHIFT 1
118 #define OMAP5430_MASK_HOT_MPU_MASK (1 << 1)
119 #define OMAP5430_MASK_COLD_MPU_SHIFT 0
120 #define OMAP5430_MASK_COLD_MPU_MASK (1 << 0)
121 
122 /* BANDGAP_COUNTER */
123 #define OMAP5430_REPEAT_MODE_SHIFT 31
124 #define OMAP5430_REPEAT_MODE_MASK (1 << 31)
125 #define OMAP5430_COUNTER_SHIFT 0
126 #define OMAP5430_COUNTER_MASK (0xffffff << 0)
127 
128 /* BANDGAP_THRESHOLD */
129 #define OMAP5430_T_HOT_SHIFT 16
130 #define OMAP5430_T_HOT_MASK (0x3ff << 16)
131 #define OMAP5430_T_COLD_SHIFT 0
132 #define OMAP5430_T_COLD_MASK (0x3ff << 0)
133 
134 /* TSHUT_THRESHOLD */
135 #define OMAP5430_TSHUT_HOT_SHIFT 16
136 #define OMAP5430_TSHUT_HOT_MASK (0x3ff << 16)
137 #define OMAP5430_TSHUT_COLD_SHIFT 0
138 #define OMAP5430_TSHUT_COLD_MASK (0x3ff << 0)
139 
140 /* BANDGAP_STATUS */
141 #define OMAP5430_BGAP_ALERT_SHIFT 31
142 #define OMAP5430_BGAP_ALERT_MASK (1 << 31)
143 #define OMAP5430_HOT_CORE_FLAG_SHIFT 5
144 #define OMAP5430_HOT_CORE_FLAG_MASK (1 << 5)
145 #define OMAP5430_COLD_CORE_FLAG_SHIFT 4
146 #define OMAP5430_COLD_CORE_FLAG_MASK (1 << 4)
147 #define OMAP5430_HOT_MM_FLAG_SHIFT 3
148 #define OMAP5430_HOT_MM_FLAG_MASK (1 << 3)
149 #define OMAP5430_COLD_MM_FLAG_SHIFT 2
150 #define OMAP5430_COLD_MM_FLAG_MASK (1 << 2)
151 #define OMAP5430_HOT_MPU_FLAG_SHIFT 1
152 #define OMAP5430_HOT_MPU_FLAG_MASK (1 << 1)
153 #define OMAP5430_COLD_MPU_FLAG_SHIFT 0
154 #define OMAP5430_COLD_MPU_FLAG_MASK (1 << 0)
155 
156 /* Offsets from the base of temperature sensor registers */
157 
158 /* 4430 - All goes relative to OPP_BGAP */
159 #define OMAP4430_FUSE_OPP_BGAP 0x0
160 #define OMAP4430_TEMP_SENSOR_CTRL_OFFSET 0xCC
161 
162 /* 4460 - All goes relative to OPP_BGAP */
163 #define OMAP4460_FUSE_OPP_BGAP 0x0
164 #define OMAP4460_TEMP_SENSOR_CTRL_OFFSET 0xCC
165 #define OMAP4460_BGAP_CTRL_OFFSET 0x118
166 #define OMAP4460_BGAP_COUNTER_OFFSET 0x11C
167 #define OMAP4460_BGAP_THRESHOLD_OFFSET 0x120
168 #define OMAP4460_BGAP_TSHUT_OFFSET 0x124
169 #define OMAP4460_BGAP_STATUS_OFFSET 0x128
170 
171 /* 5430 - All goes relative to OPP_BGAP_GPU */
172 #define OMAP5430_FUSE_OPP_BGAP_GPU 0x0
173 #define OMAP5430_TEMP_SENSOR_GPU_OFFSET 0x150
174 #define OMAP5430_BGAP_COUNTER_GPU_OFFSET 0x1C0
175 #define OMAP5430_BGAP_THRESHOLD_GPU_OFFSET 0x1A8
176 #define OMAP5430_BGAP_TSHUT_GPU_OFFSET 0x1B4
177 
178 #define OMAP5430_FUSE_OPP_BGAP_MPU 0x4
179 #define OMAP5430_TEMP_SENSOR_MPU_OFFSET 0x14C
180 #define OMAP5430_BGAP_CTRL_OFFSET 0x1A0
181 #define OMAP5430_BGAP_COUNTER_MPU_OFFSET 0x1BC
182 #define OMAP5430_BGAP_THRESHOLD_MPU_OFFSET 0x1A4
183 #define OMAP5430_BGAP_TSHUT_MPU_OFFSET 0x1B0
184 #define OMAP5430_BGAP_STATUS_OFFSET 0x1C8
185 
186 #define OMAP5430_FUSE_OPP_BGAP_CORE 0x8
187 #define OMAP5430_TEMP_SENSOR_CORE_OFFSET 0x154
188 #define OMAP5430_BGAP_COUNTER_CORE_OFFSET 0x1C4
189 #define OMAP5430_BGAP_THRESHOLD_CORE_OFFSET 0x1AC
190 #define OMAP5430_BGAP_TSHUT_CORE_OFFSET 0x1B8
191 
192 #define OMAP4460_TSHUT_HOT 900 /* 122 deg C */
193 #define OMAP4460_TSHUT_COLD 895 /* 100 deg C */
194 #define OMAP4460_T_HOT 800 /* 73 deg C */
195 #define OMAP4460_T_COLD 795 /* 71 deg C */
196 #define OMAP4460_MAX_FREQ 1500000
197 #define OMAP4460_MIN_FREQ 1000000
198 #define OMAP4460_MIN_TEMP -40000
199 #define OMAP4460_MAX_TEMP 123000
200 #define OMAP4460_HYST_VAL 5000
201 #define OMAP4460_ADC_START_VALUE 530
202 #define OMAP4460_ADC_END_VALUE 932
203 
204 #define OMAP5430_MPU_TSHUT_HOT 915
205 #define OMAP5430_MPU_TSHUT_COLD 900
206 #define OMAP5430_MPU_T_HOT 800
207 #define OMAP5430_MPU_T_COLD 795
208 #define OMAP5430_MPU_MAX_FREQ 1500000
209 #define OMAP5430_MPU_MIN_FREQ 1000000
210 #define OMAP5430_MPU_MIN_TEMP -40000
211 #define OMAP5430_MPU_MAX_TEMP 125000
212 #define OMAP5430_MPU_HYST_VAL 5000
213 #define OMAP5430_ADC_START_VALUE 532
214 #define OMAP5430_ADC_END_VALUE 934
215 
216 
217 #define OMAP5430_GPU_TSHUT_HOT 915
218 #define OMAP5430_GPU_TSHUT_COLD 900
219 #define OMAP5430_GPU_T_HOT 800
220 #define OMAP5430_GPU_T_COLD 795
221 #define OMAP5430_GPU_MAX_FREQ 1500000
222 #define OMAP5430_GPU_MIN_FREQ 1000000
223 #define OMAP5430_GPU_MIN_TEMP -40000
224 #define OMAP5430_GPU_MAX_TEMP 125000
225 #define OMAP5430_GPU_HYST_VAL 5000
226 
227 #define OMAP5430_CORE_TSHUT_HOT 915
228 #define OMAP5430_CORE_TSHUT_COLD 900
229 #define OMAP5430_CORE_T_HOT 800
230 #define OMAP5430_CORE_T_COLD 795
231 #define OMAP5430_CORE_MAX_FREQ 1500000
232 #define OMAP5430_CORE_MIN_FREQ 1000000
233 #define OMAP5430_CORE_MIN_TEMP -40000
234 #define OMAP5430_CORE_MAX_TEMP 125000
235 #define OMAP5430_CORE_HYST_VAL 5000
236 
248 
252 
255 
258 
262 
266 
272 
274 };
275 
286  int max_temp;
287  int min_temp;
288  int hyst_val;
293 };
294 
295 struct omap_bandgap_data;
296 
309 struct omap_bandgap {
310  struct device *dev;
311  void __iomem *base;
313  struct clk *fclock;
314  struct clk *div_clk;
315  const int *conv_table;
316  struct mutex bg_mutex; /* Mutex for irq and PM */
317  int irq;
320 };
321 
336 };
337 
344 };
345 
367  char *domain;
369  /* for hotspot extrapolation */
370  const int slope;
371  const int constant;
372  const int slope_pcb;
373  const int constant_pcb;
374  void *data;
375  int (*register_cooling)(struct omap_bandgap *bg_ptr, int id);
376  int (*unregister_cooling)(struct omap_bandgap *bg_ptr, int id);
377 };
378 
390 #define OMAP_BANDGAP_FEATURE_TSHUT (1 << 0)
391 #define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG (1 << 1)
392 #define OMAP_BANDGAP_FEATURE_TALERT (1 << 2)
393 #define OMAP_BANDGAP_FEATURE_MODE_CONFIG (1 << 3)
394 #define OMAP_BANDGAP_FEATURE_COUNTER (1 << 4)
395 #define OMAP_BANDGAP_FEATURE_POWER_SWITCH (1 << 5)
396 #define OMAP_BANDGAP_HAS(b, f) \
397  ((b)->conf->features & OMAP_BANDGAP_FEATURE_ ## f)
398  unsigned int features;
399  const int *conv_table;
400  char *fclock_name;
401  char *div_ck_name;
403  int (*report_temperature)(struct omap_bandgap *bg_ptr, int id);
404  int (*expose_sensor)(struct omap_bandgap *bg_ptr, int id, char *domain);
405  int (*remove_sensor)(struct omap_bandgap *bg_ptr, int id);
406 
407  /* this needs to be at the end */
409 };
410 
411 int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id, int *thot);
412 int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val);
413 int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id, int *tcold);
414 int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val);
415 int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,
416  int *interval);
417 int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr, int id,
418  u32 interval);
419 int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
420  int *temperature);
421 int omap_bandgap_set_sensor_data(struct omap_bandgap *bg_ptr, int id,
422  void *data);
423 void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id);
424 
425 #ifdef CONFIG_OMAP4_THERMAL
426 extern const struct omap_bandgap_data omap4430_data;
427 extern const struct omap_bandgap_data omap4460_data;
428 extern const struct omap_bandgap_data omap4470_data;
429 #else
430 #define omap4430_data NULL
431 #define omap4460_data NULL
432 #define omap4470_data NULL
433 #endif
434 
435 #ifdef CONFIG_OMAP5_THERMAL
436 extern const struct omap_bandgap_data omap5430_data;
437 #else
438 #define omap5430_data NULL
439 #endif
440 
441 #endif