2 * OMAP4 Bandgap temperature sensor driver
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
6 * Eduardo Valentin <eduardo.valentin@ti.com>
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.
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.
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
23 #ifndef __OMAP_BANDGAP_H
24 #define __OMAP_BANDGAP_H
26 #include <linux/mutex.h>
27 #include <linux/types.h>
28 #include <linux/err.h>
30 /* TEMP_SENSOR OMAP4430 */
31 #define OMAP4430_BGAP_TSHUT_SHIFT 11
32 #define OMAP4430_BGAP_TSHUT_MASK (1 << 11)
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)
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
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)
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)
73 #define OMAP4460_COUNTER_SHIFT 0
74 #define OMAP4460_COUNTER_MASK (0xffffff << 0)
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)
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)
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)
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)
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)
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)
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)
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)
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)
156 /* Offsets from the base of temperature sensor registers */
158 /* 4430 - All goes relative to OPP_BGAP */
159 #define OMAP4430_FUSE_OPP_BGAP 0x0
160 #define OMAP4430_TEMP_SENSOR_CTRL_OFFSET 0xCC
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
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
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
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
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
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 540
214 #define OMAP5430_ADC_END_VALUE 945
216 #define OMAP5430_GPU_TSHUT_HOT 915
217 #define OMAP5430_GPU_TSHUT_COLD 900
218 #define OMAP5430_GPU_T_HOT 800
219 #define OMAP5430_GPU_T_COLD 795
220 #define OMAP5430_GPU_MAX_FREQ 1500000
221 #define OMAP5430_GPU_MIN_FREQ 1000000
222 #define OMAP5430_GPU_MIN_TEMP -40000
223 #define OMAP5430_GPU_MAX_TEMP 125000
224 #define OMAP5430_GPU_HYST_VAL 5000
226 #define OMAP5430_CORE_TSHUT_HOT 915
227 #define OMAP5430_CORE_TSHUT_COLD 900
228 #define OMAP5430_CORE_T_HOT 800
229 #define OMAP5430_CORE_T_COLD 795
230 #define OMAP5430_CORE_MAX_FREQ 1500000
231 #define OMAP5430_CORE_MIN_FREQ 1000000
232 #define OMAP5430_CORE_MIN_TEMP -40000
233 #define OMAP5430_CORE_MAX_TEMP 125000
234 #define OMAP5430_CORE_HYST_VAL 5000
237 * The register offsets and bit fields might change across
238 * OMAP versions hence populating them in this structure.
241 struct temp_sensor_registers {
242 u32 temp_sensor_ctrl;
243 u32 bgap_tempsoff_mask;
259 u32 threshold_thot_mask;
260 u32 threshold_tcold_mask;
267 u32 status_clean_stop_mask;
268 u32 status_bgap_alert_mask;
270 u32 status_cold_mask;
276 * The thresholds and limits for temperature sensors.
278 struct temp_sensor_data {
294 struct omap_bandgap_data;
297 * struct omap_bandgap - bandgap device structure
298 * @dev: device pointer
299 * @conf: platform data with sensor data
300 * @fclock: pointer to functional clock of temperature sensor
301 * @div_clk: pointer to parent clock of temperature sensor fclk
302 * @conv_table: Pointer to adc to temperature conversion table
303 * @bg_mutex: Mutex for sysfs, irq and PM
304 * @irq: MPU Irq number for thermal alert
305 * @tshut_gpio: GPIO where Tshut signal is routed
306 * @clk_rate: Holds current clock rate
308 struct omap_bandgap {
311 struct omap_bandgap_data *conf;
314 const int *conv_table;
315 struct mutex bg_mutex; /* Mutex for irq and PM */
322 * struct temp_sensor_regval - temperature sensor register values
323 * @bg_mode_ctrl: temp sensor control register value
324 * @bg_ctrl: bandgap ctrl register value
325 * @bg_counter: bandgap counter value
326 * @bg_threshold: bandgap threshold register value
327 * @tshut_threshold: bandgap tshut register value
329 struct temp_sensor_regval {
338 * struct omap_temp_sensor - bandgap temperature sensor platform data
339 * @ts_data: pointer to struct with thresholds, limits of temperature sensor
340 * @registers: pointer to the list of register offsets and bitfields
341 * @regval: temperature sensor register values
342 * @domain: the name of the domain where the sensor is located
343 * @cooling_data: description on how the zone should be cooled off.
344 * @slope: sensor gradient slope info for hotspot extrapolation
345 * @const: sensor gradient const info for hotspot extrapolation
346 * @slope_pcb: sensor gradient slope info for hotspot extrapolation
347 * with no external influence
348 * @const_pcb: sensor gradient const info for hotspot extrapolation
349 * with no external influence
350 * @data: private data
351 * @register_cooling: function to describe how this sensor is going to be cooled
352 * @unregister_cooling: function to release cooling data
354 struct omap_temp_sensor {
355 struct temp_sensor_data *ts_data;
356 struct temp_sensor_registers *registers;
357 struct temp_sensor_regval regval;
359 /* for hotspot extrapolation */
363 const int constant_pcb;
365 int (*register_cooling)(struct omap_bandgap *bg_ptr, int id);
366 int (*unregister_cooling)(struct omap_bandgap *bg_ptr, int id);
370 * struct omap_bandgap_data - bandgap platform data structure
371 * @features: a bitwise flag set to describe the device features
372 * @conv_table: Pointer to adc to temperature conversion table
373 * @fclock_name: clock name of the functional clock
374 * @div_ck_nme: clock name of the clock divisor
375 * @sensor_count: count of temperature sensor device in scm
376 * @sensors: array of sensors present in this bandgap instance
377 * @expose_sensor: callback to export sensor to thermal API
379 struct omap_bandgap_data {
380 #define OMAP_BANDGAP_FEATURE_TSHUT (1 << 0)
381 #define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG (1 << 1)
382 #define OMAP_BANDGAP_FEATURE_TALERT (1 << 2)
383 #define OMAP_BANDGAP_FEATURE_MODE_CONFIG (1 << 3)
384 #define OMAP_BANDGAP_FEATURE_COUNTER (1 << 4)
385 #define OMAP_BANDGAP_FEATURE_POWER_SWITCH (1 << 5)
386 #define OMAP_BANDGAP_FEATURE_CLK_CTRL (1 << 6)
387 #define OMAP_BANDGAP_HAS(b, f) \
388 ((b)->conf->features & OMAP_BANDGAP_FEATURE_ ## f)
389 unsigned int features;
390 const int *conv_table;
394 int (*report_temperature)(struct omap_bandgap *bg_ptr, int id);
395 int (*expose_sensor)(struct omap_bandgap *bg_ptr, int id, char *domain);
396 int (*remove_sensor)(struct omap_bandgap *bg_ptr, int id);
398 /* this needs to be at the end */
399 struct omap_temp_sensor sensors[];
402 int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id, int *thot);
403 int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val);
404 int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id, int *tcold);
405 int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val);
406 int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,
408 int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr, int id,
410 int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
412 int omap_bandgap_set_sensor_data(struct omap_bandgap *bg_ptr, int id,
414 void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id);
416 #ifdef CONFIG_OMAP4_THERMAL
417 extern const struct omap_bandgap_data omap4430_data;
418 extern const struct omap_bandgap_data omap4460_data;
419 extern const struct omap_bandgap_data omap4470_data;
421 #define omap4430_data NULL
422 #define omap4460_data NULL
423 #define omap4470_data NULL
426 #ifdef CONFIG_OMAP5_THERMAL
427 extern const struct omap_bandgap_data omap5430_data;
429 #define omap5430_data NULL