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