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