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