![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * OMAP4 Bandgap temperature sensor driver 0004 * 0005 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 0006 * Contact: 0007 * Eduardo Valentin <eduardo.valentin@ti.com> 0008 */ 0009 #ifndef __TI_BANDGAP_H 0010 #define __TI_BANDGAP_H 0011 0012 #include <linux/spinlock.h> 0013 #include <linux/types.h> 0014 #include <linux/err.h> 0015 #include <linux/cpu_pm.h> 0016 #include <linux/device.h> 0017 #include <linux/pm_runtime.h> 0018 #include <linux/pm.h> 0019 0020 struct gpio_desc; 0021 0022 /** 0023 * DOC: bandgap driver data structure 0024 * ================================== 0025 * 0026 * +----------+----------------+ 0027 * | struct temp_sensor_regval | 0028 * +---------------------------+ 0029 * * (Array of) 0030 * | 0031 * | 0032 * +-------------------+ +-----------------+ 0033 * | struct ti_bandgap |-->| struct device * | 0034 * +----------+--------+ +-----------------+ 0035 * | 0036 * | 0037 * V 0038 * +------------------------+ 0039 * | struct ti_bandgap_data | 0040 * +------------------------+ 0041 * | 0042 * | 0043 * * (Array of) 0044 * +------------+------------------------------------------------------+ 0045 * | +----------+------------+ +-------------------------+ | 0046 * | | struct ti_temp_sensor |-->| struct temp_sensor_data | | 0047 * | +-----------------------+ +------------+------------+ | 0048 * | | | 0049 * | + | 0050 * | V | 0051 * | +----------+-------------------+ | 0052 * | | struct temp_sensor_registers | | 0053 * | +------------------------------+ | 0054 * | | 0055 * +-------------------------------------------------------------------+ 0056 * 0057 * Above is a simple diagram describing how the data structure below 0058 * are organized. For each bandgap device there should be a ti_bandgap_data 0059 * containing the device instance configuration, as well as, an array of 0060 * sensors, representing every sensor instance present in this bandgap. 0061 */ 0062 0063 /** 0064 * struct temp_sensor_registers - descriptor to access registers and bitfields 0065 * @temp_sensor_ctrl: TEMP_SENSOR_CTRL register offset 0066 * @bgap_tempsoff_mask: mask to temp_sensor_ctrl.tempsoff 0067 * @bgap_soc_mask: mask to temp_sensor_ctrl.soc 0068 * @bgap_eocz_mask: mask to temp_sensor_ctrl.eocz 0069 * @bgap_dtemp_mask: mask to temp_sensor_ctrl.dtemp 0070 * @bgap_mask_ctrl: BANDGAP_MASK_CTRL register offset 0071 * @mask_hot_mask: mask to bandgap_mask_ctrl.mask_hot 0072 * @mask_cold_mask: mask to bandgap_mask_ctrl.mask_cold 0073 * @mask_counter_delay_mask: mask to bandgap_mask_ctrl.mask_counter_delay 0074 * @mask_freeze_mask: mask to bandgap_mask_ctrl.mask_free 0075 * @bgap_mode_ctrl: BANDGAP_MODE_CTRL register offset 0076 * @mode_ctrl_mask: mask to bandgap_mode_ctrl.mode_ctrl 0077 * @bgap_counter: BANDGAP_COUNTER register offset 0078 * @counter_mask: mask to bandgap_counter.counter 0079 * @bgap_threshold: BANDGAP_THRESHOLD register offset (TALERT thresholds) 0080 * @threshold_thot_mask: mask to bandgap_threhold.thot 0081 * @threshold_tcold_mask: mask to bandgap_threhold.tcold 0082 * @tshut_threshold: TSHUT_THRESHOLD register offset (TSHUT thresholds) 0083 * @tshut_hot_mask: mask to tshut_threhold.thot 0084 * @tshut_cold_mask: mask to tshut_threhold.thot 0085 * @bgap_status: BANDGAP_STATUS register offset 0086 * @status_hot_mask: mask to bandgap_status.hot 0087 * @status_cold_mask: mask to bandgap_status.cold 0088 * @ctrl_dtemp_1: CTRL_DTEMP1 register offset 0089 * @ctrl_dtemp_2: CTRL_DTEMP2 register offset 0090 * @bgap_efuse: BANDGAP_EFUSE register offset 0091 * 0092 * The register offsets and bitfields might change across 0093 * OMAP and variants versions. Hence this struct serves as a 0094 * descriptor map on how to access the registers and the bitfields. 0095 * 0096 * This descriptor contains registers of all versions of bandgap chips. 0097 * Not all versions will use all registers, depending on the available 0098 * features. Please read TRMs for descriptive explanation on each bitfield. 0099 */ 0100 0101 struct temp_sensor_registers { 0102 u32 temp_sensor_ctrl; 0103 u32 bgap_tempsoff_mask; 0104 u32 bgap_soc_mask; 0105 u32 bgap_eocz_mask; 0106 u32 bgap_dtemp_mask; 0107 0108 u32 bgap_mask_ctrl; 0109 u32 mask_hot_mask; 0110 u32 mask_cold_mask; 0111 u32 mask_counter_delay_mask; 0112 u32 mask_freeze_mask; 0113 0114 u32 bgap_mode_ctrl; 0115 u32 mode_ctrl_mask; 0116 0117 u32 bgap_counter; 0118 u32 counter_mask; 0119 0120 u32 bgap_threshold; 0121 u32 threshold_thot_mask; 0122 u32 threshold_tcold_mask; 0123 0124 u32 tshut_threshold; 0125 u32 tshut_hot_mask; 0126 u32 tshut_cold_mask; 0127 0128 u32 bgap_status; 0129 u32 status_hot_mask; 0130 u32 status_cold_mask; 0131 0132 u32 ctrl_dtemp_1; 0133 u32 ctrl_dtemp_2; 0134 u32 bgap_efuse; 0135 }; 0136 0137 /** 0138 * struct temp_sensor_data - The thresholds and limits for temperature sensors. 0139 * @tshut_hot: temperature to trigger a thermal reset (initial value) 0140 * @tshut_cold: temp to get the plat out of reset due to thermal (init val) 0141 * @t_hot: temperature to trigger a thermal alert (high initial value) 0142 * @t_cold: temperature to trigger a thermal alert (low initial value) 0143 * @min_freq: sensor minimum clock rate 0144 * @max_freq: sensor maximum clock rate 0145 * 0146 * This data structure will hold the required thresholds and temperature limits 0147 * for a specific temperature sensor, like shutdown temperature, alert 0148 * temperature, clock / rate used, ADC conversion limits and update intervals 0149 */ 0150 struct temp_sensor_data { 0151 u32 tshut_hot; 0152 u32 tshut_cold; 0153 u32 t_hot; 0154 u32 t_cold; 0155 u32 min_freq; 0156 u32 max_freq; 0157 }; 0158 0159 struct ti_bandgap_data; 0160 0161 /** 0162 * struct temp_sensor_regval - temperature sensor register values and priv data 0163 * @bg_mode_ctrl: temp sensor control register value 0164 * @bg_ctrl: bandgap ctrl register value 0165 * @bg_counter: bandgap counter value 0166 * @bg_threshold: bandgap threshold register value 0167 * @tshut_threshold: bandgap tshut register value 0168 * @data: private data 0169 * 0170 * Data structure to save and restore bandgap register set context. Only 0171 * required registers are shadowed, when needed. 0172 */ 0173 struct temp_sensor_regval { 0174 u32 bg_mode_ctrl; 0175 u32 bg_ctrl; 0176 u32 bg_counter; 0177 u32 bg_threshold; 0178 u32 tshut_threshold; 0179 void *data; 0180 }; 0181 0182 /** 0183 * struct ti_bandgap - bandgap device structure 0184 * @dev: struct device pointer 0185 * @base: io memory base address 0186 * @conf: struct with bandgap configuration set (# sensors, conv_table, etc) 0187 * @regval: temperature sensor register values 0188 * @fclock: pointer to functional clock of temperature sensor 0189 * @div_clk: pointer to divider clock of temperature sensor fclk 0190 * @lock: spinlock for ti_bandgap structure 0191 * @irq: MPU IRQ number for thermal alert 0192 * @tshut_gpio: GPIO where Tshut signal is routed 0193 * @clk_rate: Holds current clock rate 0194 * 0195 * The bandgap device structure representing the bandgap device instance. 0196 * It holds most of the dynamic stuff. Configurations and sensor specific 0197 * entries are inside the @conf structure. 0198 */ 0199 struct ti_bandgap { 0200 struct device *dev; 0201 void __iomem *base; 0202 const struct ti_bandgap_data *conf; 0203 struct temp_sensor_regval *regval; 0204 struct clk *fclock; 0205 struct clk *div_clk; 0206 spinlock_t lock; /* shields this struct */ 0207 int irq; 0208 struct gpio_desc *tshut_gpiod; 0209 u32 clk_rate; 0210 struct notifier_block nb; 0211 unsigned int is_suspended:1; 0212 }; 0213 0214 /** 0215 * struct ti_temp_sensor - bandgap temperature sensor configuration data 0216 * @ts_data: pointer to struct with thresholds, limits of temperature sensor 0217 * @registers: pointer to the list of register offsets and bitfields 0218 * @domain: the name of the domain where the sensor is located 0219 * @slope_pcb: sensor gradient slope info for hotspot extrapolation equation 0220 * with no external influence 0221 * @constant_pcb: sensor gradient const info for hotspot extrapolation equation 0222 * with no external influence 0223 * @register_cooling: function to describe how this sensor is going to be cooled 0224 * @unregister_cooling: function to release cooling data 0225 * 0226 * Data structure to describe a temperature sensor handled by a bandgap device. 0227 * It should provide configuration details on this sensor, such as how to 0228 * access the registers affecting this sensor, shadow register buffer, how to 0229 * assess the gradient from hotspot, how to cooldown the domain when sensor 0230 * reports too hot temperature. 0231 */ 0232 struct ti_temp_sensor { 0233 struct temp_sensor_data *ts_data; 0234 struct temp_sensor_registers *registers; 0235 char *domain; 0236 /* for hotspot extrapolation */ 0237 const int slope_pcb; 0238 const int constant_pcb; 0239 int (*register_cooling)(struct ti_bandgap *bgp, int id); 0240 int (*unregister_cooling)(struct ti_bandgap *bgp, int id); 0241 }; 0242 0243 /** 0244 * DOC: ti bandgap feature types 0245 * 0246 * TI_BANDGAP_FEATURE_TSHUT - used when the thermal shutdown signal output 0247 * of a bandgap device instance is routed to the processor. This means 0248 * the system must react and perform the shutdown by itself (handle an 0249 * IRQ, for instance). 0250 * 0251 * TI_BANDGAP_FEATURE_TSHUT_CONFIG - used when the bandgap device has control 0252 * over the thermal shutdown configuration. This means that the thermal 0253 * shutdown thresholds are programmable, for instance. 0254 * 0255 * TI_BANDGAP_FEATURE_TALERT - used when the bandgap device instance outputs 0256 * a signal representing violation of programmable alert thresholds. 0257 * 0258 * TI_BANDGAP_FEATURE_MODE_CONFIG - used when it is possible to choose which 0259 * mode, continuous or one shot, the bandgap device instance will operate. 0260 * 0261 * TI_BANDGAP_FEATURE_COUNTER - used when the bandgap device instance allows 0262 * programming the update interval of its internal state machine. 0263 * 0264 * TI_BANDGAP_FEATURE_POWER_SWITCH - used when the bandgap device allows 0265 * itself to be switched on/off. 0266 * 0267 * TI_BANDGAP_FEATURE_CLK_CTRL - used when the clocks feeding the bandgap 0268 * device are gateable or not. 0269 * 0270 * TI_BANDGAP_FEATURE_FREEZE_BIT - used when the bandgap device features 0271 * a history buffer that its update can be freezed/unfreezed. 0272 * 0273 * TI_BANDGAP_FEATURE_COUNTER_DELAY - used when the bandgap device features 0274 * a delay programming based on distinct values. 0275 * 0276 * TI_BANDGAP_FEATURE_HISTORY_BUFFER - used when the bandgap device features 0277 * a history buffer of temperatures. 0278 * 0279 * TI_BANDGAP_FEATURE_ERRATA_814 - used to workaorund when the bandgap device 0280 * has Errata 814 0281 * TI_BANDGAP_FEATURE_UNRELIABLE - used when the sensor readings are too 0282 * inaccurate. 0283 * TI_BANDGAP_FEATURE_CONT_MODE_ONLY - used when single mode hangs the sensor 0284 * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a 0285 * specific feature (above) or not. Return non-zero, if yes. 0286 */ 0287 #define TI_BANDGAP_FEATURE_TSHUT BIT(0) 0288 #define TI_BANDGAP_FEATURE_TSHUT_CONFIG BIT(1) 0289 #define TI_BANDGAP_FEATURE_TALERT BIT(2) 0290 #define TI_BANDGAP_FEATURE_MODE_CONFIG BIT(3) 0291 #define TI_BANDGAP_FEATURE_COUNTER BIT(4) 0292 #define TI_BANDGAP_FEATURE_POWER_SWITCH BIT(5) 0293 #define TI_BANDGAP_FEATURE_CLK_CTRL BIT(6) 0294 #define TI_BANDGAP_FEATURE_FREEZE_BIT BIT(7) 0295 #define TI_BANDGAP_FEATURE_COUNTER_DELAY BIT(8) 0296 #define TI_BANDGAP_FEATURE_HISTORY_BUFFER BIT(9) 0297 #define TI_BANDGAP_FEATURE_ERRATA_814 BIT(10) 0298 #define TI_BANDGAP_FEATURE_UNRELIABLE BIT(11) 0299 #define TI_BANDGAP_FEATURE_CONT_MODE_ONLY BIT(12) 0300 #define TI_BANDGAP_HAS(b, f) \ 0301 ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f) 0302 0303 /** 0304 * struct ti_bandgap_data - ti bandgap data configuration structure 0305 * @features: a bitwise flag set to describe the device features 0306 * @conv_table: Pointer to ADC to temperature conversion table 0307 * @adc_start_val: ADC conversion table starting value 0308 * @adc_end_val: ADC conversion table ending value 0309 * @fclock_name: clock name of the functional clock 0310 * @div_ck_name: clock name of the clock divisor 0311 * @sensor_count: count of temperature sensor within this bandgap device 0312 * @report_temperature: callback to report thermal alert to thermal API 0313 * @expose_sensor: callback to export sensor to thermal API 0314 * @remove_sensor: callback to destroy sensor from thermal API 0315 * @sensors: array of sensors present in this bandgap instance 0316 * 0317 * This is a data structure which should hold most of the static configuration 0318 * of a bandgap device instance. It should describe which features this instance 0319 * is capable of, the clock names to feed this device, the amount of sensors and 0320 * their configuration representation, and how to export and unexport them to 0321 * a thermal API. 0322 */ 0323 struct ti_bandgap_data { 0324 unsigned int features; 0325 const int *conv_table; 0326 u32 adc_start_val; 0327 u32 adc_end_val; 0328 char *fclock_name; 0329 char *div_ck_name; 0330 int sensor_count; 0331 int (*report_temperature)(struct ti_bandgap *bgp, int id); 0332 int (*expose_sensor)(struct ti_bandgap *bgp, int id, char *domain); 0333 int (*remove_sensor)(struct ti_bandgap *bgp, int id); 0334 0335 /* this needs to be at the end */ 0336 struct ti_temp_sensor sensors[]; 0337 }; 0338 0339 int ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot); 0340 int ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val); 0341 int ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold); 0342 int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val); 0343 int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id, 0344 int *interval); 0345 int ti_bandgap_write_update_interval(struct ti_bandgap *bgp, int id, 0346 u32 interval); 0347 int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id, 0348 int *temperature); 0349 int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data); 0350 void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id); 0351 int ti_bandgap_get_trend(struct ti_bandgap *bgp, int id, int *trend); 0352 0353 #ifdef CONFIG_OMAP3_THERMAL 0354 extern const struct ti_bandgap_data omap34xx_data; 0355 extern const struct ti_bandgap_data omap36xx_data; 0356 #else 0357 #define omap34xx_data NULL 0358 #define omap36xx_data NULL 0359 #endif 0360 0361 #ifdef CONFIG_OMAP4_THERMAL 0362 extern const struct ti_bandgap_data omap4430_data; 0363 extern const struct ti_bandgap_data omap4460_data; 0364 extern const struct ti_bandgap_data omap4470_data; 0365 #else 0366 #define omap4430_data NULL 0367 #define omap4460_data NULL 0368 #define omap4470_data NULL 0369 #endif 0370 0371 #ifdef CONFIG_OMAP5_THERMAL 0372 extern const struct ti_bandgap_data omap5430_data; 0373 #else 0374 #define omap5430_data NULL 0375 #endif 0376 0377 #ifdef CONFIG_DRA752_THERMAL 0378 extern const struct ti_bandgap_data dra752_data; 0379 #else 0380 #define dra752_data NULL 0381 #endif 0382 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |