Merge 3.9-rc5 into staging-next
[deliverable/linux.git] / drivers / staging / ti-soc-thermal / ti-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 __TI_BANDGAP_H
24 #define __TI_BANDGAP_H
25
26 #include <linux/spinlock.h>
27 #include <linux/types.h>
28 #include <linux/err.h>
29
30 /**
31 * DOC: bandgap driver data structure
32 * ==================================
33 *
34 * +----------+----------------+
35 * | struct temp_sensor_regval |
36 * +---------------------------+
37 * * (Array of)
38 * |
39 * |
40 * +-------------------+ +-----------------+
41 * | struct ti_bandgap |-->| struct device * |
42 * +----------+--------+ +-----------------+
43 * |
44 * |
45 * V
46 * +------------------------+
47 * | struct ti_bandgap_data |
48 * +------------------------+
49 * |
50 * |
51 * * (Array of)
52 * +------------+------------------------------------------------------+
53 * | +----------+------------+ +-------------------------+ |
54 * | | struct ti_temp_sensor |-->| struct temp_sensor_data | |
55 * | +-----------------------+ +------------+------------+ |
56 * | | |
57 * | + |
58 * | V |
59 * | +----------+-------------------+ |
60 * | | struct temp_sensor_registers | |
61 * | +------------------------------+ |
62 * | |
63 * +-------------------------------------------------------------------+
64 *
65 * Above is a simple diagram describing how the data structure below
66 * are organized. For each bandgap device there should be a ti_bandgap_data
67 * containing the device instance configuration, as well as, an array of
68 * sensors, representing every sensor instance present in this bandgap.
69 */
70
71 /**
72 * struct temp_sensor_registers - descriptor to access registers and bitfields
73 * @temp_sensor_ctrl: TEMP_SENSOR_CTRL register offset
74 * @bgap_tempsoff_mask: mask to temp_sensor_ctrl.tempsoff
75 * @bgap_soc_mask: mask to temp_sensor_ctrl.soc
76 * @bgap_eocz_mask: mask to temp_sensor_ctrl.eocz
77 * @bgap_dtemp_mask: mask to temp_sensor_ctrl.dtemp
78 * @bgap_mask_ctrl: BANDGAP_MASK_CTRL register offset
79 * @mask_hot_mask: mask to bandgap_mask_ctrl.mask_hot
80 * @mask_cold_mask: mask to bandgap_mask_ctrl.mask_cold
81 * @mask_sidlemode_mask: mask to bandgap_mask_ctrl.mask_sidlemode
82 * @mask_freeze_mask: mask to bandgap_mask_ctrl.mask_free
83 * @mask_clear_mask: mask to bandgap_mask_ctrl.mask_clear
84 * @mask_clear_accum_mask: mask to bandgap_mask_ctrl.mask_clear_accum
85 * @bgap_mode_ctrl: BANDGAP_MODE_CTRL register offset
86 * @mode_ctrl_mask: mask to bandgap_mode_ctrl.mode_ctrl
87 * @bgap_counter: BANDGAP_COUNTER register offset
88 * @counter_mask: mask to bandgap_counter.counter
89 * @bgap_threshold: BANDGAP_THRESHOLD register offset (TALERT thresholds)
90 * @threshold_thot_mask: mask to bandgap_threhold.thot
91 * @threshold_tcold_mask: mask to bandgap_threhold.tcold
92 * @tshut_threshold: TSHUT_THRESHOLD register offset (TSHUT thresholds)
93 * @tshut_efuse_mask: mask to tshut_threshold.tshut_efuse
94 * @tshut_efuse_shift: shift to tshut_threshold.tshut_efuse
95 * @tshut_hot_mask: mask to tshut_threhold.thot
96 * @tshut_cold_mask: mask to tshut_threhold.thot
97 * @bgap_status: BANDGAP_STATUS register offset
98 * @status_clean_stop_mask: mask to bandgap_status.clean_stop
99 * @status_bgap_alert_mask: mask to bandgap_status.bandgap_alert
100 * @status_hot_mask: mask to bandgap_status.hot
101 * @status_cold_mask: mask to bandgap_status.cold
102 * @bgap_cumul_dtemp: BANDGAP_CUMUL_DTEMP register offset
103 * @ctrl_dtemp_0: CTRL_DTEMP0 register offset
104 * @ctrl_dtemp_1: CTRL_DTEMP1 register offset
105 * @ctrl_dtemp_2: CTRL_DTEMP2 register offset
106 * @ctrl_dtemp_3: CTRL_DTEMP3 register offset
107 * @ctrl_dtemp_4: CTRL_DTEMP4 register offset
108 * @bgap_efuse: BANDGAP_EFUSE register offset
109 *
110 * The register offsets and bitfields might change across
111 * OMAP and variants versions. Hence this struct serves as a
112 * descriptor map on how to access the registers and the bitfields.
113 *
114 * This descriptor contains registers of all versions of bandgap chips.
115 * Not all versions will use all registers, depending on the available
116 * features. Please read TRMs for descriptive explanation on each bitfield.
117 */
118
119 struct temp_sensor_registers {
120 u32 temp_sensor_ctrl;
121 u32 bgap_tempsoff_mask;
122 u32 bgap_soc_mask;
123 u32 bgap_eocz_mask; /* not used: but needs revisit */
124 u32 bgap_dtemp_mask;
125
126 u32 bgap_mask_ctrl;
127 u32 mask_hot_mask;
128 u32 mask_cold_mask;
129 u32 mask_sidlemode_mask; /* not used: but may be needed for pm */
130 u32 mask_freeze_mask;
131 u32 mask_clear_mask; /* not used: but needed for trending */
132 u32 mask_clear_accum_mask; /* not used: but needed for trending */
133
134 u32 bgap_mode_ctrl;
135 u32 mode_ctrl_mask;
136
137 u32 bgap_counter;
138 u32 counter_mask;
139
140 u32 bgap_threshold;
141 u32 threshold_thot_mask;
142 u32 threshold_tcold_mask;
143
144 u32 tshut_threshold;
145 u32 tshut_efuse_mask; /* not used */
146 u32 tshut_efuse_shift; /* not used */
147 u32 tshut_hot_mask;
148 u32 tshut_cold_mask;
149
150 u32 bgap_status;
151 u32 status_clean_stop_mask; /* not used: but needed for trending */
152 u32 status_bgap_alert_mask; /* not used */
153 u32 status_hot_mask;
154 u32 status_cold_mask;
155
156 u32 bgap_cumul_dtemp; /* not used: but needed for trending */
157 u32 ctrl_dtemp_0; /* not used: but needed for trending */
158 u32 ctrl_dtemp_1; /* not used: but needed for trending */
159 u32 ctrl_dtemp_2; /* not used: but needed for trending */
160 u32 ctrl_dtemp_3; /* not used: but needed for trending */
161 u32 ctrl_dtemp_4; /* not used: but needed for trending */
162 u32 bgap_efuse;
163 };
164
165 /**
166 * struct temp_sensor_data - The thresholds and limits for temperature sensors.
167 * @tshut_hot: temperature to trigger a thermal reset (initial value)
168 * @tshut_cold: temp to get the plat out of reset due to thermal (init val)
169 * @t_hot: temperature to trigger a thermal alert (high initial value)
170 * @t_cold: temperature to trigger a thermal alert (low initial value)
171 * @min_freq: sensor minimum clock rate
172 * @max_freq: sensor maximum clock rate
173 * @max_temp: sensor maximum temperature
174 * @min_temp: sensor minimum temperature
175 * @hyst_val: temperature hysteresis considered while converting ADC values
176 * @update_int1: update interval
177 * @update_int2: update interval
178 *
179 * This data structure will hold the required thresholds and temperature limits
180 * for a specific temperature sensor, like shutdown temperature, alert
181 * temperature, clock / rate used, ADC conversion limits and update intervals
182 */
183 struct temp_sensor_data {
184 u32 tshut_hot;
185 u32 tshut_cold;
186 u32 t_hot;
187 u32 t_cold;
188 u32 min_freq;
189 u32 max_freq;
190 int max_temp;
191 int min_temp;
192 int hyst_val;
193 u32 update_int1; /* not used */
194 u32 update_int2; /* not used */
195 };
196
197 struct ti_bandgap_data;
198
199 /**
200 * struct temp_sensor_regval - temperature sensor register values and priv data
201 * @bg_mode_ctrl: temp sensor control register value
202 * @bg_ctrl: bandgap ctrl register value
203 * @bg_counter: bandgap counter value
204 * @bg_threshold: bandgap threshold register value
205 * @tshut_threshold: bandgap tshut register value
206 * @data: private data
207 *
208 * Data structure to save and restore bandgap register set context. Only
209 * required registers are shadowed, when needed.
210 */
211 struct temp_sensor_regval {
212 u32 bg_mode_ctrl;
213 u32 bg_ctrl;
214 u32 bg_counter;
215 u32 bg_threshold;
216 u32 tshut_threshold;
217 void *data;
218 };
219
220 /**
221 * struct ti_bandgap - bandgap device structure
222 * @dev: struct device pointer
223 * @base: io memory base address
224 * @conf: struct with bandgap configuration set (# sensors, conv_table, etc)
225 * @regval: temperature sensor register values
226 * @fclock: pointer to functional clock of temperature sensor
227 * @div_clk: pointer to divider clock of temperature sensor fclk
228 * @lock: spinlock for ti_bandgap structure
229 * @irq: MPU IRQ number for thermal alert
230 * @tshut_gpio: GPIO where Tshut signal is routed
231 * @clk_rate: Holds current clock rate
232 *
233 * The bandgap device structure representing the bandgap device instance.
234 * It holds most of the dynamic stuff. Configurations and sensor specific
235 * entries are inside the @conf structure.
236 */
237 struct ti_bandgap {
238 struct device *dev;
239 void __iomem *base;
240 const struct ti_bandgap_data *conf;
241 struct temp_sensor_regval *regval;
242 struct clk *fclock;
243 struct clk *div_clk;
244 spinlock_t lock; /* shields this struct */
245 int irq;
246 int tshut_gpio;
247 u32 clk_rate;
248 };
249
250 /**
251 * struct ti_temp_sensor - bandgap temperature sensor configuration data
252 * @ts_data: pointer to struct with thresholds, limits of temperature sensor
253 * @registers: pointer to the list of register offsets and bitfields
254 * @domain: the name of the domain where the sensor is located
255 * @slope: sensor gradient slope info for hotspot extrapolation equation
256 * @constant: sensor gradient const info for hotspot extrapolation equation
257 * @slope_pcb: sensor gradient slope info for hotspot extrapolation equation
258 * with no external influence
259 * @constant_pcb: sensor gradient const info for hotspot extrapolation equation
260 * with no external influence
261 * @register_cooling: function to describe how this sensor is going to be cooled
262 * @unregister_cooling: function to release cooling data
263 *
264 * Data structure to describe a temperature sensor handled by a bandgap device.
265 * It should provide configuration details on this sensor, such as how to
266 * access the registers affecting this sensor, shadow register buffer, how to
267 * assess the gradient from hotspot, how to cooldown the domain when sensor
268 * reports too hot temperature.
269 */
270 struct ti_temp_sensor {
271 struct temp_sensor_data *ts_data;
272 struct temp_sensor_registers *registers;
273 char *domain;
274 /* for hotspot extrapolation */
275 const int slope;
276 const int constant;
277 const int slope_pcb;
278 const int constant_pcb;
279 int (*register_cooling)(struct ti_bandgap *bgp, int id);
280 int (*unregister_cooling)(struct ti_bandgap *bgp, int id);
281 };
282
283 /**
284 * DOC: ti bandgap feature types
285 *
286 * TI_BANDGAP_FEATURE_TSHUT - used when the thermal shutdown signal output
287 * of a bandgap device instance is routed to the processor. This means
288 * the system must react and perform the shutdown by itself (handle an
289 * IRQ, for instance).
290 *
291 * TI_BANDGAP_FEATURE_TSHUT_CONFIG - used when the bandgap device has control
292 * over the thermal shutdown configuration. This means that the thermal
293 * shutdown thresholds are programmable, for instance.
294 *
295 * TI_BANDGAP_FEATURE_TALERT - used when the bandgap device instance outputs
296 * a signal representing violation of programmable alert thresholds.
297 *
298 * TI_BANDGAP_FEATURE_MODE_CONFIG - used when it is possible to choose which
299 * mode, continuous or one shot, the bandgap device instance will operate.
300 *
301 * TI_BANDGAP_FEATURE_COUNTER - used when the bandgap device instance allows
302 * programming the update interval of its internal state machine.
303 *
304 * TI_BANDGAP_FEATURE_POWER_SWITCH - used when the bandgap device allows
305 * itself to be switched on/off.
306 *
307 * TI_BANDGAP_FEATURE_CLK_CTRL - used when the clocks feeding the bandgap
308 * device are gateable or not.
309 *
310 * TI_BANDGAP_FEATURE_FREEZE_BIT - used when the bandgap device features
311 * a history buffer that its update can be freezed/unfreezed.
312 *
313 * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a
314 * specific feature (above) or not. Return non-zero, if yes.
315 */
316 #define TI_BANDGAP_FEATURE_TSHUT BIT(0)
317 #define TI_BANDGAP_FEATURE_TSHUT_CONFIG BIT(1)
318 #define TI_BANDGAP_FEATURE_TALERT BIT(2)
319 #define TI_BANDGAP_FEATURE_MODE_CONFIG BIT(3)
320 #define TI_BANDGAP_FEATURE_COUNTER BIT(4)
321 #define TI_BANDGAP_FEATURE_POWER_SWITCH BIT(5)
322 #define TI_BANDGAP_FEATURE_CLK_CTRL BIT(6)
323 #define TI_BANDGAP_FEATURE_FREEZE_BIT BIT(7)
324 #define TI_BANDGAP_HAS(b, f) \
325 ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)
326
327 /**
328 * struct ti_bandgap_data - ti bandgap data configuration structure
329 * @features: a bitwise flag set to describe the device features
330 * @conv_table: Pointer to ADC to temperature conversion table
331 * @adc_start_val: ADC conversion table starting value
332 * @adc_end_val: ADC conversion table ending value
333 * @fclock_name: clock name of the functional clock
334 * @div_ck_name: clock name of the clock divisor
335 * @sensor_count: count of temperature sensor within this bandgap device
336 * @report_temperature: callback to report thermal alert to thermal API
337 * @expose_sensor: callback to export sensor to thermal API
338 * @remove_sensor: callback to destroy sensor from thermal API
339 * @sensors: array of sensors present in this bandgap instance
340 *
341 * This is a data structure which should hold most of the static configuration
342 * of a bandgap device instance. It should describe which features this instance
343 * is capable of, the clock names to feed this device, the amount of sensors and
344 * their configuration representation, and how to export and unexport them to
345 * a thermal API.
346 */
347 struct ti_bandgap_data {
348 unsigned int features;
349 const int *conv_table;
350 u32 adc_start_val;
351 u32 adc_end_val;
352 char *fclock_name;
353 char *div_ck_name;
354 int sensor_count;
355 int (*report_temperature)(struct ti_bandgap *bgp, int id);
356 int (*expose_sensor)(struct ti_bandgap *bgp, int id, char *domain);
357 int (*remove_sensor)(struct ti_bandgap *bgp, int id);
358
359 /* this needs to be at the end */
360 struct ti_temp_sensor sensors[];
361 };
362
363 int ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot);
364 int ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val);
365 int ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold);
366 int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val);
367 int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
368 int *interval);
369 int ti_bandgap_write_update_interval(struct ti_bandgap *bgp, int id,
370 u32 interval);
371 int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
372 int *temperature);
373 int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data);
374 void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id);
375
376 #ifdef CONFIG_OMAP4_THERMAL
377 extern const struct ti_bandgap_data omap4430_data;
378 extern const struct ti_bandgap_data omap4460_data;
379 extern const struct ti_bandgap_data omap4470_data;
380 #else
381 #define omap4430_data NULL
382 #define omap4460_data NULL
383 #define omap4470_data NULL
384 #endif
385
386 #ifdef CONFIG_OMAP5_THERMAL
387 extern const struct ti_bandgap_data omap5430_data;
388 #else
389 #define omap5430_data NULL
390 #endif
391
392 #endif
This page took 0.065295 seconds and 5 git commands to generate.