]> Pileus Git - ~andy/linux/blob - drivers/staging/omap-thermal/omap-bandgap.h
Merge branch 'dmaengine' of git://git.linaro.org/people/rmk/linux-arm
[~andy/linux] / drivers / staging / omap-thermal / omap-bandgap.h
1 /*
2  * OMAP4 Bandgap temperature sensor driver
3  *
4  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5  * Contact:
6  *   Eduardo Valentin <eduardo.valentin@ti.com>
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
237 /**
238  * The register offsets and bit fields might change across
239  * OMAP versions hence populating them in this structure.
240  */
241
242 struct temp_sensor_registers {
243         u32     temp_sensor_ctrl;
244         u32     bgap_tempsoff_mask;
245         u32     bgap_soc_mask;
246         u32     bgap_eocz_mask;
247         u32     bgap_dtemp_mask;
248
249         u32     bgap_mask_ctrl;
250         u32     mask_hot_mask;
251         u32     mask_cold_mask;
252
253         u32     bgap_mode_ctrl;
254         u32     mode_ctrl_mask;
255
256         u32     bgap_counter;
257         u32     counter_mask;
258
259         u32     bgap_threshold;
260         u32     threshold_thot_mask;
261         u32     threshold_tcold_mask;
262
263         u32     tshut_threshold;
264         u32     tshut_hot_mask;
265         u32     tshut_cold_mask;
266
267         u32     bgap_status;
268         u32     status_clean_stop_mask;
269         u32     status_bgap_alert_mask;
270         u32     status_hot_mask;
271         u32     status_cold_mask;
272
273         u32     bgap_efuse;
274 };
275
276 /**
277  * The thresholds and limits for temperature sensors.
278  */
279 struct temp_sensor_data {
280         u32     tshut_hot;
281         u32     tshut_cold;
282         u32     t_hot;
283         u32     t_cold;
284         u32     min_freq;
285         u32     max_freq;
286         int     max_temp;
287         int     min_temp;
288         int     hyst_val;
289         u32     adc_start_val;
290         u32     adc_end_val;
291         u32     update_int1;
292         u32     update_int2;
293 };
294
295 struct omap_bandgap_data;
296
297 /**
298  * struct omap_bandgap - bandgap device structure
299  * @dev: device pointer
300  * @conf: platform data with sensor data
301  * @fclock: pointer to functional clock of temperature sensor
302  * @div_clk: pointer to parent clock of temperature sensor fclk
303  * @conv_table: Pointer to adc to temperature conversion table
304  * @bg_mutex: Mutex for sysfs, irq and PM
305  * @irq: MPU Irq number for thermal alert
306  * @tshut_gpio: GPIO where Tshut signal is routed
307  * @clk_rate: Holds current clock rate
308  */
309 struct omap_bandgap {
310         struct device                   *dev;
311         void __iomem                    *base;
312         struct omap_bandgap_data        *conf;
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;
318         int                             tshut_gpio;
319         u32                             clk_rate;
320 };
321
322 /**
323  * struct temp_sensor_regval - temperature sensor register values
324  * @bg_mode_ctrl: temp sensor control register value
325  * @bg_ctrl: bandgap ctrl register value
326  * @bg_counter: bandgap counter value
327  * @bg_threshold: bandgap threshold register value
328  * @tshut_threshold: bandgap tshut register value
329  */
330 struct temp_sensor_regval {
331         u32                     bg_mode_ctrl;
332         u32                     bg_ctrl;
333         u32                     bg_counter;
334         u32                     bg_threshold;
335         u32                     tshut_threshold;
336 };
337
338 /**
339  * struct thermal_cooling_conf - description on how to cool a thermal zone
340  * @freq_clip_count: size of freq_data
341  */
342 struct thermal_cooling_conf {
343         int freq_clip_count;
344 };
345
346 /**
347  * struct omap_temp_sensor - bandgap temperature sensor platform data
348  * @ts_data: pointer to struct with thresholds, limits of temperature sensor
349  * @registers: pointer to the list of register offsets and bitfields
350  * @regval: temperature sensor register values
351  * @domain: the name of the domain where the sensor is located
352  * @cooling_data: description on how the zone should be cooled off.
353  * @slope: sensor gradient slope info for hotspot extrapolation
354  * @const: sensor gradient const info for hotspot extrapolation
355  * @slope_pcb: sensor gradient slope info for hotspot extrapolation
356  *             with no external influence
357  * @const_pcb: sensor gradient const info for hotspot extrapolation
358  *             with no external influence
359  * @data: private data
360  * @register_cooling: function to describe how this sensor is going to be cooled
361  * @unregister_cooling: function to release cooling data
362  */
363 struct omap_temp_sensor {
364         struct temp_sensor_data         *ts_data;
365         struct temp_sensor_registers    *registers;
366         struct temp_sensor_regval       regval;
367         char                            *domain;
368         struct thermal_cooling_conf     cooling_data;
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
379 /**
380  * struct omap_bandgap_data - bandgap platform data structure
381  * @features: a bitwise flag set to describe the device features
382  * @conv_table: Pointer to adc to temperature conversion table
383  * @fclock_name: clock name of the functional clock
384  * @div_ck_nme: clock name of the clock divisor
385  * @sensor_count: count of temperature sensor device in scm
386  * @sensors: array of sensors present in this bandgap instance
387  * @expose_sensor: callback to export sensor to thermal API
388  */
389 struct omap_bandgap_data {
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;
402         int                             sensor_count;
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 */
408         struct omap_temp_sensor         sensors[];
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