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