developer | 2cdaeb1 | 2022-10-04 20:25:05 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (c) 2020 MediaTek Inc. |
| 4 | */ |
| 5 | |
| 6 | #ifndef __MTK_SOC_TEMP_LVTS_H__ |
| 7 | #define __MTK_SOC_TEMP_LVTS_H__ |
| 8 | |
| 9 | /* LVTS HW filter settings |
| 10 | * 000: Get one sample |
| 11 | * 001: Get 2 samples and average them |
| 12 | * 010: Get 4 samples, drop max and min, then average the rest of 2 samples |
| 13 | * 011: Get 6 samples, drop max and min, then average the rest of 4 samples |
| 14 | * 100: Get 10 samples, drop max and min, then average the rest of 8 samples |
| 15 | * 101: Get 18 samples, drop max and min, then average the rest of 16 samples |
| 16 | */ |
| 17 | enum lvts_hw_filter { |
| 18 | LVTS_FILTER_1, |
| 19 | LVTS_FILTER_2, |
| 20 | LVTS_FILTER_2_OF_4, |
| 21 | LVTS_FILTER_4_OF_6, |
| 22 | LVTS_FILTER_8_OF_10, |
| 23 | LVTS_FILTER_16_OF_18 |
| 24 | }; |
| 25 | |
| 26 | enum lvts_sensing_point { |
| 27 | SENSING_POINT0, |
| 28 | SENSING_POINT1, |
| 29 | SENSING_POINT2, |
| 30 | SENSING_POINT3, |
| 31 | ALL_SENSING_POINTS |
| 32 | }; |
| 33 | |
| 34 | /* |
| 35 | * Data structure |
| 36 | */ |
| 37 | struct lvts_data; |
| 38 | |
| 39 | struct speed_settings { |
| 40 | unsigned int period_unit; |
| 41 | unsigned int group_interval_delay; |
| 42 | unsigned int filter_interval_delay; |
| 43 | unsigned int sensor_interval_delay; |
| 44 | }; |
| 45 | |
| 46 | struct tc_settings { |
| 47 | unsigned int domain_index; |
| 48 | unsigned int addr_offset; |
| 49 | unsigned int num_sensor; |
| 50 | unsigned int sensor_map[ALL_SENSING_POINTS]; /* In sensor ID */ |
| 51 | struct speed_settings tc_speed; |
| 52 | /* HW filter setting |
| 53 | * 000: Get one sample |
| 54 | * 001: Get 2 samples and average them |
| 55 | * 010: Get 4 samples, drop max and min, then average the rest of 2 |
| 56 | * samples |
| 57 | * 011: Get 6 samples, drop max and min, then average the rest of 4 |
| 58 | * samples |
| 59 | * 100: Get 10 samples, drop max and min, then average the rest of 8 |
| 60 | * samples |
| 61 | * 101: Get 18 samples, drop max and min, then average the rest of 16 |
| 62 | * samples |
| 63 | */ |
| 64 | unsigned int hw_filter; |
| 65 | /* Dominator_sensing point is used to select a sensing point |
| 66 | * and reference its temperature to trigger Thermal HW Reboot |
| 67 | * When it is ALL_SENSING_POINTS, it will select all sensing points |
| 68 | */ |
| 69 | int dominator_sensing_point; |
| 70 | int hw_reboot_trip_point; /* -274000: Disable HW reboot */ |
| 71 | unsigned int irq_bit; |
| 72 | }; |
| 73 | |
| 74 | struct formula_coeff { |
| 75 | int a; |
| 76 | int b; |
| 77 | unsigned int golden_temp; |
| 78 | }; |
| 79 | |
| 80 | struct sensor_cal_data { |
| 81 | int use_fake_efuse; /* 1: Use fake efuse, 0: Use real efuse */ |
| 82 | unsigned int golden_temp; |
| 83 | unsigned int *count_r; |
| 84 | unsigned int *count_rc; |
| 85 | unsigned int *count_rc_now; |
| 86 | |
| 87 | unsigned int default_golden_temp; |
| 88 | unsigned int default_count_r; |
| 89 | unsigned int default_count_rc; |
| 90 | }; |
| 91 | |
| 92 | struct platform_ops { |
| 93 | void (*efuse_to_cal_data)(struct lvts_data *lvts_data); |
| 94 | void (*device_enable_and_init)(struct lvts_data *lvts_data); |
| 95 | void (*device_enable_auto_rck)(struct lvts_data *lvts_data); |
| 96 | int (*device_read_count_rc_n)(struct lvts_data *lvts_data); |
| 97 | void (*set_cal_data)(struct lvts_data *lvts_data); |
| 98 | void (*init_controller)(struct lvts_data *lvts_data); |
| 99 | }; |
| 100 | |
| 101 | struct power_domain { |
| 102 | void __iomem *base; /* LVTS base addresses */ |
| 103 | unsigned int irq_num; /* LVTS interrupt numbers */ |
| 104 | struct reset_control *reset; |
| 105 | }; |
| 106 | |
| 107 | struct sensor_data { |
| 108 | int temp; /* Current temperature */ |
| 109 | unsigned int msr_raw; /* MSR raw data from LVTS */ |
| 110 | }; |
| 111 | |
| 112 | struct lvts_data { |
| 113 | struct device *dev; |
| 114 | struct clk *clk; |
| 115 | unsigned int num_domain; |
| 116 | struct power_domain *domain; |
| 117 | |
| 118 | int num_tc; /* Number of LVTS thermal controllers */ |
| 119 | struct tc_settings *tc; |
| 120 | int counting_window_us; /* LVTS device counting window */ |
| 121 | |
| 122 | int num_sensor; /* Number of sensors in this platform */ |
| 123 | struct sensor_data *sen_data; |
| 124 | |
| 125 | struct platform_ops ops; |
| 126 | int feature_bitmap; /* Show what features are enabled */ |
| 127 | |
| 128 | unsigned int num_efuse_addr; |
| 129 | unsigned int *efuse; |
| 130 | unsigned int num_efuse_block; /* Number of contiguous efuse indexes */ |
| 131 | struct sensor_cal_data cal_data; |
| 132 | struct formula_coeff coeff; |
| 133 | }; |
| 134 | |
| 135 | struct soc_temp_tz { |
| 136 | unsigned int id; /* if id is 0, get max temperature of all sensors */ |
| 137 | struct lvts_data *lvts_data; |
| 138 | }; |
| 139 | |
| 140 | struct match_entry { |
| 141 | char chip[32]; |
| 142 | struct lvts_data *lvts_data; |
| 143 | }; |
| 144 | |
| 145 | struct lvts_match_data { |
| 146 | unsigned int hw_version; |
| 147 | struct match_entry *table; |
| 148 | void (*set_up_common_callbacks)(struct lvts_data *lvts_data); |
| 149 | struct list_head node; |
| 150 | }; |
| 151 | |
| 152 | struct lvts_id { |
| 153 | unsigned int hw_version; |
| 154 | char chip[32]; |
| 155 | }; |
| 156 | |
| 157 | /* |
| 158 | * LVTS device register |
| 159 | */ |
| 160 | #define RG_TSFM_DATA_0 0x00 |
| 161 | #define RG_TSFM_DATA_1 0x01 |
| 162 | #define RG_TSFM_DATA_2 0x02 |
| 163 | #define RG_TSFM_CTRL_0 0x03 |
| 164 | #define RG_TSFM_CTRL_1 0x04 |
| 165 | #define RG_TSFM_CTRL_2 0x05 |
| 166 | #define RG_TSFM_CTRL_3 0x06 |
| 167 | #define RG_TSFM_CTRL_4 0x07 |
| 168 | #define RG_TSV2F_CTRL_0 0x08 |
| 169 | #define RG_TSV2F_CTRL_1 0x09 |
| 170 | #define RG_TSV2F_CTRL_2 0x0A |
| 171 | #define RG_TSV2F_CTRL_3 0x0B |
| 172 | #define RG_TSV2F_CTRL_4 0x0C |
| 173 | #define RG_TSV2F_CTRL_5 0x0D |
| 174 | #define RG_TSV2F_CTRL_6 0x0E |
| 175 | #define RG_TEMP_DATA_0 0x10 |
| 176 | #define RG_TEMP_DATA_1 0x11 |
| 177 | #define RG_TEMP_DATA_2 0x12 |
| 178 | #define RG_TEMP_DATA_3 0x13 |
| 179 | #define RG_RC_DATA_0 0x14 |
| 180 | #define RG_RC_DATA_1 0x15 |
| 181 | #define RG_RC_DATA_2 0x16 |
| 182 | #define RG_RC_DATA_3 0x17 |
| 183 | #define RG_DIV_DATA_0 0x18 |
| 184 | #define RG_DIV_DATA_1 0x19 |
| 185 | #define RG_DIV_DATA_2 0x1A |
| 186 | #define RG_DIV_DATA_3 0x1B |
| 187 | #define RG_TST_DATA_0 0x70 |
| 188 | #define RG_TST_DATA_1 0x71 |
| 189 | #define RG_TST_DATA_2 0x72 |
| 190 | #define RG_TST_CTRL 0x73 |
| 191 | #define RG_DBG_FQMTR 0xF0 |
| 192 | #define RG_DBG_LPSEQ 0xF1 |
| 193 | #define RG_DBG_STATE 0xF2 |
| 194 | #define RG_DBG_CHKSUM 0xF3 |
| 195 | #define RG_DID_LVTS 0xFC |
| 196 | #define RG_DID_REV 0xFD |
| 197 | #define RG_TSFM_RST 0xFF |
| 198 | /* |
| 199 | * LVTS controller register |
| 200 | */ |
| 201 | #define LVTSMONCTL0_0 0x000 |
| 202 | #define LVTS_SINGLE_SENSE BIT(9) |
| 203 | #define ENABLE_SENSING_POINT(num) (LVTS_SINGLE_SENSE | GENMASK(((num)-1), 0)) |
| 204 | #define DISABLE_SENSING_POINT (LVTS_SINGLE_SENSE | 0x0) |
| 205 | #define LVTSMONCTL1_0 0x004 |
| 206 | #define LVTSMONCTL2_0 0x008 |
| 207 | #define LVTSMONINT_0 0x00C |
| 208 | #define STAGE3_INT_EN BIT(31) |
| 209 | #define LVTSMONINTSTS_0 0x010 |
| 210 | #define LVTSMONIDET0_0 0x014 |
| 211 | #define LVTSMONIDET1_0 0x018 |
| 212 | #define LVTSMONIDET2_0 0x01C |
| 213 | #define LVTSMONIDET3_0 0x020 |
| 214 | #define LVTSH2NTHRE_0 0x024 |
| 215 | #define LVTSHTHRE_0 0x028 |
| 216 | #define LVTSCTHRE_0 0x02C |
| 217 | #define LVTSOFFSETH_0 0x030 |
| 218 | #define LVTSOFFSETL_0 0x034 |
| 219 | #define LVTSMSRCTL0_0 0x038 |
| 220 | #define LVTSMSRCTL1_0 0x03C |
| 221 | #define LVTSTSSEL_0 0x040 |
| 222 | #define SET_SENSOR_INDEX 0x13121110 |
| 223 | #define LVTSDEVICETO_0 0x044 |
| 224 | #define LVTSCALSCALE_0 0x048 |
| 225 | #define SET_CALC_SCALE_RULES 0x00000300 |
| 226 | #define LVTS_ID_0 0x04C |
| 227 | #define LVTS_CONFIG_0 0x050 |
| 228 | |
| 229 | #define BROADCAST_ID_UPDATE BIT(26) |
| 230 | #define DEVICE_SENSING_STATUS BIT(25) |
| 231 | #define DEVICE_ACCESS_STARTUS BIT(24) |
| 232 | #define WRITE_ACCESS BIT(16) |
| 233 | #define DEVICE_WRITE \ |
| 234 | (BIT(31) | CK26M_ACTIVE | DEVICE_ACCESS_STARTUS | BIT(17) | \ |
| 235 | WRITE_ACCESS) |
| 236 | #define DEVICE_READ \ |
| 237 | (BIT(31) | CK26M_ACTIVE | DEVICE_ACCESS_STARTUS | 1 << 17) |
| 238 | #define RESET_ALL_DEVICES \ |
| 239 | (DEVICE_WRITE | RG_TSFM_RST << 8 | 0xFF) |
| 240 | #define READ_BACK_DEVICE_ID \ |
| 241 | (BIT(31) | CK26M_ACTIVE | BROADCAST_ID_UPDATE | \ |
| 242 | DEVICE_ACCESS_STARTUS | BIT(17) | RG_DID_LVTS << 8) |
| 243 | #define READ_DEVICE_REG(reg_idx) (DEVICE_READ | (reg_idx) << 8 | 0x00) |
| 244 | #define LVTSEDATA00_0 0x054 |
| 245 | #define LVTSEDATA01_0 0x058 |
| 246 | #define LVTSEDATA02_0 0x05C |
| 247 | #define LVTSEDATA03_0 0x060 |
| 248 | #define LVTSMSR0_0 0x090 |
| 249 | #define MRS_RAW_MASK GENMASK(15, 0) |
| 250 | #define MRS_RAW_VALID_BIT BIT(16) |
| 251 | #define LVTSMSR1_0 0x094 |
| 252 | #define LVTSMSR2_0 0x098 |
| 253 | #define LVTSMSR3_0 0x09C |
| 254 | #define LVTSIMMD0_0 0x0A0 |
| 255 | #define LVTSIMMD1_0 0x0A4 |
| 256 | #define LVTSIMMD2_0 0x0A8 |
| 257 | #define LVTSIMMD3_0 0x0AC |
| 258 | #define LVTSRDATA0_0 0x0B0 |
| 259 | #define LVTSRDATA1_0 0x0B4 |
| 260 | #define LVTSRDATA2_0 0x0B8 |
| 261 | #define LVTSRDATA3_0 0x0BC |
| 262 | #define LVTSPROTCTL_0 0x0C0 |
| 263 | #define PROTOFFSET GENMASK(15, 0) |
| 264 | #define LVTSPROTTA_0 0x0C4 |
| 265 | #define LVTSPROTTB_0 0x0C8 |
| 266 | #define LVTSPROTTC_0 0x0CC |
| 267 | #define LVTSCLKEN_0 0x0E4 |
| 268 | #define ENABLE_LVTS_CTRL_CLK (1) |
| 269 | #define DISABLE_LVTS_CTRL_CLK (0) |
| 270 | #define LVTSDBGSEL_0 0x0E8 |
| 271 | #define LVTSDBGSIG_0 0x0EC |
| 272 | #define LVTSSPARE0_0 0x0F0 |
| 273 | #define LVTSSPARE1_0 0x0F4 |
| 274 | #define LVTSSPARE2_0 0x0F8 |
| 275 | #define LVTSSPARE3_0 0x0FC |
| 276 | |
| 277 | #define THERMINTST 0xF04 |
| 278 | /* |
| 279 | * LVTS register mask |
| 280 | */ |
| 281 | #define THERMAL_COLD_INTERRUPT_0 0x00000001 |
| 282 | #define THERMAL_HOT_INTERRUPT_0 0x00000002 |
| 283 | #define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 |
| 284 | #define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 |
| 285 | #define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 |
| 286 | #define THERMAL_COLD_INTERRUPT_1 0x00000020 |
| 287 | #define THERMAL_HOT_INTERRUPT_1 0x00000040 |
| 288 | #define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 |
| 289 | #define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 |
| 290 | #define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 |
| 291 | #define THERMAL_COLD_INTERRUPT_2 0x00000400 |
| 292 | #define THERMAL_HOT_INTERRUPT_2 0x00000800 |
| 293 | #define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 |
| 294 | #define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 |
| 295 | #define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 |
| 296 | #define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 |
| 297 | #define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 |
| 298 | #define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 |
| 299 | #define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 |
| 300 | #define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 |
| 301 | #define THERMAL_FILTER_INTERRUPT_0 0x00080000 |
| 302 | #define THERMAL_FILTER_INTERRUPT_1 0x00100000 |
| 303 | #define THERMAL_FILTER_INTERRUPT_2 0x00200000 |
| 304 | #define THERMAL_COLD_INTERRUPT_3 0x00400000 |
| 305 | #define THERMAL_HOT_INTERRUPT_3 0x00800000 |
| 306 | #define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 |
| 307 | #define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 |
| 308 | #define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 |
| 309 | #define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 |
| 310 | #define THERMAL_FILTER_INTERRUPT_3 0x10000000 |
| 311 | #define THERMAL_PROTECTION_STAGE_1 0x20000000 |
| 312 | #define THERMAL_PROTECTION_STAGE_2 0x40000000 |
| 313 | #define THERMAL_PROTECTION_STAGE_3 0x80000000 |
| 314 | #endif /* __MTK_SOC_TEMP_LVTS_H__ */ |