1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2014 - 2018, NVIDIA CORPORATION. All rights reserved. 4 * 5 * Author: 6 * Mikko Perttunen <mperttunen@nvidia.com> 7 * 8 * This software is licensed under the terms of the GNU General Public 9 * License version 2, as published by the Free Software Foundation, and 10 * may be copied, distributed, and modified under those terms. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 */ 18 19 #include <linux/debugfs.h> 20 #include <linux/bitops.h> 21 #include <linux/clk.h> 22 #include <linux/delay.h> 23 #include <linux/err.h> 24 #include <linux/interrupt.h> 25 #include <linux/io.h> 26 #include <linux/irq.h> 27 #include <linux/irqdomain.h> 28 #include <linux/module.h> 29 #include <linux/of.h> 30 #include <linux/platform_device.h> 31 #include <linux/reset.h> 32 #include <linux/thermal.h> 33 34 #include <dt-bindings/thermal/tegra114-soctherm.h> 35 #include <dt-bindings/thermal/tegra124-soctherm.h> 36 37 #include "../thermal_core.h" 38 #include "soctherm.h" 39 40 #define SENSOR_CONFIG0 0 41 #define SENSOR_CONFIG0_STOP BIT(0) 42 #define SENSOR_CONFIG0_CPTR_OVER BIT(2) 43 #define SENSOR_CONFIG0_OVER BIT(3) 44 #define SENSOR_CONFIG0_TCALC_OVER BIT(4) 45 #define SENSOR_CONFIG0_TALL_MASK (0xfffff << 8) 46 #define SENSOR_CONFIG0_TALL_SHIFT 8 47 48 #define SENSOR_CONFIG1 4 49 #define SENSOR_CONFIG1_TSAMPLE_MASK 0x3ff 50 #define SENSOR_CONFIG1_TSAMPLE_SHIFT 0 51 #define SENSOR_CONFIG1_TIDDQ_EN_MASK (0x3f << 15) 52 #define SENSOR_CONFIG1_TIDDQ_EN_SHIFT 15 53 #define SENSOR_CONFIG1_TEN_COUNT_MASK (0x3f << 24) 54 #define SENSOR_CONFIG1_TEN_COUNT_SHIFT 24 55 #define SENSOR_CONFIG1_TEMP_ENABLE BIT(31) 56 57 /* 58 * SENSOR_CONFIG2 is defined in soctherm.h 59 * because, it will be used by tegra_soctherm_fuse.c 60 */ 61 62 #define SENSOR_STATUS0 0xc 63 #define SENSOR_STATUS0_VALID_MASK BIT(31) 64 #define SENSOR_STATUS0_CAPTURE_MASK 0xffff 65 66 #define SENSOR_STATUS1 0x10 67 #define SENSOR_STATUS1_TEMP_VALID_MASK BIT(31) 68 #define SENSOR_STATUS1_TEMP_MASK 0xffff 69 70 #define READBACK_VALUE_MASK 0xff00 71 #define READBACK_VALUE_SHIFT 8 72 #define READBACK_ADD_HALF BIT(7) 73 #define READBACK_NEGATE BIT(0) 74 75 /* 76 * THERMCTL_LEVEL0_GROUP_CPU is defined in soctherm.h 77 * because it will be used by tegraxxx_soctherm.c 78 */ 79 #define THERMCTL_LVL0_CPU0_EN_MASK BIT(8) 80 #define THERMCTL_LVL0_CPU0_CPU_THROT_MASK (0x3 << 5) 81 #define THERMCTL_LVL0_CPU0_CPU_THROT_LIGHT 0x1 82 #define THERMCTL_LVL0_CPU0_CPU_THROT_HEAVY 0x2 83 #define THERMCTL_LVL0_CPU0_GPU_THROT_MASK (0x3 << 3) 84 #define THERMCTL_LVL0_CPU0_GPU_THROT_LIGHT 0x1 85 #define THERMCTL_LVL0_CPU0_GPU_THROT_HEAVY 0x2 86 #define THERMCTL_LVL0_CPU0_MEM_THROT_MASK BIT(2) 87 #define THERMCTL_LVL0_CPU0_STATUS_MASK 0x3 88 89 #define THERMCTL_LVL0_UP_STATS 0x10 90 #define THERMCTL_LVL0_DN_STATS 0x14 91 92 #define THERMCTL_INTR_STATUS 0x84 93 94 #define TH_INTR_MD0_MASK BIT(25) 95 #define TH_INTR_MU0_MASK BIT(24) 96 #define TH_INTR_GD0_MASK BIT(17) 97 #define TH_INTR_GU0_MASK BIT(16) 98 #define TH_INTR_CD0_MASK BIT(9) 99 #define TH_INTR_CU0_MASK BIT(8) 100 #define TH_INTR_PD0_MASK BIT(1) 101 #define TH_INTR_PU0_MASK BIT(0) 102 #define TH_INTR_IGNORE_MASK 0xFCFCFCFC 103 104 #define THERMCTL_STATS_CTL 0x94 105 #define STATS_CTL_CLR_DN 0x8 106 #define STATS_CTL_EN_DN 0x4 107 #define STATS_CTL_CLR_UP 0x2 108 #define STATS_CTL_EN_UP 0x1 109 110 #define OC1_CFG 0x310 111 #define OC1_CFG_LONG_LATENCY_MASK BIT(6) 112 #define OC1_CFG_HW_RESTORE_MASK BIT(5) 113 #define OC1_CFG_PWR_GOOD_MASK_MASK BIT(4) 114 #define OC1_CFG_THROTTLE_MODE_MASK (0x3 << 2) 115 #define OC1_CFG_ALARM_POLARITY_MASK BIT(1) 116 #define OC1_CFG_EN_THROTTLE_MASK BIT(0) 117 118 #define OC1_CNT_THRESHOLD 0x314 119 #define OC1_THROTTLE_PERIOD 0x318 120 #define OC1_ALARM_COUNT 0x31c 121 #define OC1_FILTER 0x320 122 #define OC1_STATS 0x3a8 123 124 #define OC_INTR_STATUS 0x39c 125 #define OC_INTR_ENABLE 0x3a0 126 #define OC_INTR_DISABLE 0x3a4 127 #define OC_STATS_CTL 0x3c4 128 #define OC_STATS_CTL_CLR_ALL 0x2 129 #define OC_STATS_CTL_EN_ALL 0x1 130 131 #define OC_INTR_OC1_MASK BIT(0) 132 #define OC_INTR_OC2_MASK BIT(1) 133 #define OC_INTR_OC3_MASK BIT(2) 134 #define OC_INTR_OC4_MASK BIT(3) 135 #define OC_INTR_OC5_MASK BIT(4) 136 137 #define THROT_GLOBAL_CFG 0x400 138 #define THROT_GLOBAL_ENB_MASK BIT(0) 139 140 #define CPU_PSKIP_STATUS 0x418 141 #define XPU_PSKIP_STATUS_M_MASK (0xff << 12) 142 #define XPU_PSKIP_STATUS_N_MASK (0xff << 4) 143 #define XPU_PSKIP_STATUS_SW_OVERRIDE_MASK BIT(1) 144 #define XPU_PSKIP_STATUS_ENABLED_MASK BIT(0) 145 146 #define THROT_PRIORITY_LOCK 0x424 147 #define THROT_PRIORITY_LOCK_PRIORITY_MASK 0xff 148 149 #define THROT_STATUS 0x428 150 #define THROT_STATUS_BREACH_MASK BIT(12) 151 #define THROT_STATUS_STATE_MASK (0xff << 4) 152 #define THROT_STATUS_ENABLED_MASK BIT(0) 153 154 #define THROT_PSKIP_CTRL_LITE_CPU 0x430 155 #define THROT_PSKIP_CTRL_ENABLE_MASK BIT(31) 156 #define THROT_PSKIP_CTRL_DIVIDEND_MASK (0xff << 8) 157 #define THROT_PSKIP_CTRL_DIVISOR_MASK 0xff 158 #define THROT_PSKIP_CTRL_VECT_GPU_MASK (0x7 << 16) 159 #define THROT_PSKIP_CTRL_VECT_CPU_MASK (0x7 << 8) 160 #define THROT_PSKIP_CTRL_VECT2_CPU_MASK 0x7 161 162 #define THROT_VECT_NONE 0x0 /* 3'b000 */ 163 #define THROT_VECT_LOW 0x1 /* 3'b001 */ 164 #define THROT_VECT_MED 0x3 /* 3'b011 */ 165 #define THROT_VECT_HIGH 0x7 /* 3'b111 */ 166 167 #define THROT_PSKIP_RAMP_LITE_CPU 0x434 168 #define THROT_PSKIP_RAMP_SEQ_BYPASS_MODE_MASK BIT(31) 169 #define THROT_PSKIP_RAMP_DURATION_MASK (0xffff << 8) 170 #define THROT_PSKIP_RAMP_STEP_MASK 0xff 171 172 #define THROT_PRIORITY_LITE 0x444 173 #define THROT_PRIORITY_LITE_PRIO_MASK 0xff 174 175 #define THROT_DELAY_LITE 0x448 176 #define THROT_DELAY_LITE_DELAY_MASK 0xff 177 178 /* car register offsets needed for enabling HW throttling */ 179 #define CAR_SUPER_CCLKG_DIVIDER 0x36c 180 #define CDIVG_USE_THERM_CONTROLS_MASK BIT(30) 181 182 /* ccroc register offsets needed for enabling HW throttling for Tegra132 */ 183 #define CCROC_SUPER_CCLKG_DIVIDER 0x024 184 185 #define CCROC_GLOBAL_CFG 0x148 186 187 #define CCROC_THROT_PSKIP_RAMP_CPU 0x150 188 #define CCROC_THROT_PSKIP_RAMP_SEQ_BYPASS_MODE_MASK BIT(31) 189 #define CCROC_THROT_PSKIP_RAMP_DURATION_MASK (0xffff << 8) 190 #define CCROC_THROT_PSKIP_RAMP_STEP_MASK 0xff 191 192 #define CCROC_THROT_PSKIP_CTRL_CPU 0x154 193 #define CCROC_THROT_PSKIP_CTRL_ENB_MASK BIT(31) 194 #define CCROC_THROT_PSKIP_CTRL_DIVIDEND_MASK (0xff << 8) 195 #define CCROC_THROT_PSKIP_CTRL_DIVISOR_MASK 0xff 196 197 /* get val from register(r) mask bits(m) */ 198 #define REG_GET_MASK(r, m) (((r) & (m)) >> (ffs(m) - 1)) 199 /* set val(v) to mask bits(m) of register(r) */ 200 #define REG_SET_MASK(r, m, v) (((r) & ~(m)) | \ 201 (((v) & (m >> (ffs(m) - 1))) << (ffs(m) - 1))) 202 203 /* get dividend from the depth */ 204 #define THROT_DEPTH_DIVIDEND(depth) ((256 * (100 - (depth)) / 100) - 1) 205 206 /* gk20a nv_therm interface N:3 Mapping. Levels defined in tegra124-soctherm.h 207 * level vector 208 * NONE 3'b000 209 * LOW 3'b001 210 * MED 3'b011 211 * HIGH 3'b111 212 */ 213 #define THROT_LEVEL_TO_DEPTH(level) ((0x1 << (level)) - 1) 214 215 /* get THROT_PSKIP_xxx offset per LIGHT/HEAVY throt and CPU/GPU dev */ 216 #define THROT_OFFSET 0x30 217 #define THROT_PSKIP_CTRL(throt, dev) (THROT_PSKIP_CTRL_LITE_CPU + \ 218 (THROT_OFFSET * throt) + (8 * dev)) 219 #define THROT_PSKIP_RAMP(throt, dev) (THROT_PSKIP_RAMP_LITE_CPU + \ 220 (THROT_OFFSET * throt) + (8 * dev)) 221 222 /* get THROT_xxx_CTRL offset per LIGHT/HEAVY throt */ 223 #define THROT_PRIORITY_CTRL(throt) (THROT_PRIORITY_LITE + \ 224 (THROT_OFFSET * throt)) 225 #define THROT_DELAY_CTRL(throt) (THROT_DELAY_LITE + \ 226 (THROT_OFFSET * throt)) 227 228 #define ALARM_OFFSET 0x14 229 #define ALARM_CFG(throt) (OC1_CFG + \ 230 (ALARM_OFFSET * (throt - THROTTLE_OC1))) 231 232 #define ALARM_CNT_THRESHOLD(throt) (OC1_CNT_THRESHOLD + \ 233 (ALARM_OFFSET * (throt - THROTTLE_OC1))) 234 235 #define ALARM_THROTTLE_PERIOD(throt) (OC1_THROTTLE_PERIOD + \ 236 (ALARM_OFFSET * (throt - THROTTLE_OC1))) 237 238 #define ALARM_ALARM_COUNT(throt) (OC1_ALARM_COUNT + \ 239 (ALARM_OFFSET * (throt - THROTTLE_OC1))) 240 241 #define ALARM_FILTER(throt) (OC1_FILTER + \ 242 (ALARM_OFFSET * (throt - THROTTLE_OC1))) 243 244 #define ALARM_STATS(throt) (OC1_STATS + \ 245 (4 * (throt - THROTTLE_OC1))) 246 247 /* get CCROC_THROT_PSKIP_xxx offset per HIGH/MED/LOW vect*/ 248 #define CCROC_THROT_OFFSET 0x0c 249 #define CCROC_THROT_PSKIP_CTRL_CPU_REG(vect) (CCROC_THROT_PSKIP_CTRL_CPU + \ 250 (CCROC_THROT_OFFSET * vect)) 251 #define CCROC_THROT_PSKIP_RAMP_CPU_REG(vect) (CCROC_THROT_PSKIP_RAMP_CPU + \ 252 (CCROC_THROT_OFFSET * vect)) 253 254 /* get THERMCTL_LEVELx offset per CPU/GPU/MEM/TSENSE rg and LEVEL0~3 lv */ 255 #define THERMCTL_LVL_REGS_SIZE 0x20 256 #define THERMCTL_LVL_REG(rg, lv) ((rg) + ((lv) * THERMCTL_LVL_REGS_SIZE)) 257 258 #define OC_THROTTLE_MODE_DISABLED 0 259 #define OC_THROTTLE_MODE_BRIEF 2 260 261 static const int min_low_temp = -127000; 262 static const int max_high_temp = 127000; 263 264 enum soctherm_throttle_id { 265 THROTTLE_LIGHT = 0, 266 THROTTLE_HEAVY, 267 THROTTLE_OC1, 268 THROTTLE_OC2, 269 THROTTLE_OC3, 270 THROTTLE_OC4, 271 THROTTLE_OC5, /* OC5 is reserved */ 272 THROTTLE_SIZE, 273 }; 274 275 enum soctherm_oc_irq_id { 276 TEGRA_SOC_OC_IRQ_1, 277 TEGRA_SOC_OC_IRQ_2, 278 TEGRA_SOC_OC_IRQ_3, 279 TEGRA_SOC_OC_IRQ_4, 280 TEGRA_SOC_OC_IRQ_5, 281 TEGRA_SOC_OC_IRQ_MAX, 282 }; 283 284 enum soctherm_throttle_dev_id { 285 THROTTLE_DEV_CPU = 0, 286 THROTTLE_DEV_GPU, 287 THROTTLE_DEV_SIZE, 288 }; 289 290 static const char *const throt_names[] = { 291 [THROTTLE_LIGHT] = "light", 292 [THROTTLE_HEAVY] = "heavy", 293 [THROTTLE_OC1] = "oc1", 294 [THROTTLE_OC2] = "oc2", 295 [THROTTLE_OC3] = "oc3", 296 [THROTTLE_OC4] = "oc4", 297 [THROTTLE_OC5] = "oc5", 298 }; 299 300 struct tegra_soctherm; 301 struct tegra_thermctl_zone { 302 void __iomem *reg; 303 struct device *dev; 304 struct tegra_soctherm *ts; 305 struct thermal_zone_device *tz; 306 const struct tegra_tsensor_group *sg; 307 }; 308 309 struct soctherm_oc_cfg { 310 u32 active_low; 311 u32 throt_period; 312 u32 alarm_cnt_thresh; 313 u32 alarm_filter; 314 u32 mode; 315 bool intr_en; 316 }; 317 318 struct soctherm_throt_cfg { 319 const char *name; 320 unsigned int id; 321 u8 priority; 322 u8 cpu_throt_level; 323 u32 cpu_throt_depth; 324 u32 gpu_throt_level; 325 struct soctherm_oc_cfg oc_cfg; 326 struct thermal_cooling_device *cdev; 327 bool init; 328 }; 329 330 struct tegra_soctherm { 331 struct reset_control *reset; 332 struct clk *clock_tsensor; 333 struct clk *clock_soctherm; 334 void __iomem *regs; 335 void __iomem *clk_regs; 336 void __iomem *ccroc_regs; 337 338 int thermal_irq; 339 int edp_irq; 340 341 u32 *calib; 342 struct thermal_zone_device **thermctl_tzs; 343 struct tegra_soctherm_soc *soc; 344 345 struct soctherm_throt_cfg throt_cfgs[THROTTLE_SIZE]; 346 347 struct dentry *debugfs_dir; 348 349 struct mutex thermctl_lock; 350 }; 351 352 struct soctherm_oc_irq_chip_data { 353 struct mutex irq_lock; /* serialize OC IRQs */ 354 struct irq_chip irq_chip; 355 struct irq_domain *domain; 356 int irq_enable; 357 }; 358 359 static struct soctherm_oc_irq_chip_data soc_irq_cdata; 360 361 /* Ensure that TEGRA114_* and TEGRA124_* counterparts are equal */ 362 static_assert(TEGRA114_SOCTHERM_SENSOR_CPU == TEGRA124_SOCTHERM_SENSOR_CPU); 363 static_assert(TEGRA114_SOCTHERM_SENSOR_MEM == TEGRA124_SOCTHERM_SENSOR_MEM); 364 static_assert(TEGRA114_SOCTHERM_SENSOR_GPU == TEGRA124_SOCTHERM_SENSOR_GPU); 365 static_assert(TEGRA114_SOCTHERM_SENSOR_PLLX == TEGRA124_SOCTHERM_SENSOR_PLLX); 366 367 /** 368 * ccroc_writel() - writes a value to a CCROC register 369 * @ts: pointer to a struct tegra_soctherm 370 * @value: the value to write 371 * @reg: the register offset 372 * 373 * Writes @v to @reg. No return value. 374 */ 375 static inline void ccroc_writel(struct tegra_soctherm *ts, u32 value, u32 reg) 376 { 377 writel(value, (ts->ccroc_regs + reg)); 378 } 379 380 /** 381 * ccroc_readl() - reads specified register from CCROC IP block 382 * @ts: pointer to a struct tegra_soctherm 383 * @reg: register address to be read 384 * 385 * Return: the value of the register 386 */ 387 static inline u32 ccroc_readl(struct tegra_soctherm *ts, u32 reg) 388 { 389 return readl(ts->ccroc_regs + reg); 390 } 391 392 static void enable_tsensor(struct tegra_soctherm *tegra, unsigned int i) 393 { 394 const struct tegra_tsensor *sensor = &tegra->soc->tsensors[i]; 395 void __iomem *base = tegra->regs + sensor->base; 396 unsigned int val; 397 398 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT; 399 writel(val, base + SENSOR_CONFIG0); 400 401 val = (sensor->config->tsample - 1) << SENSOR_CONFIG1_TSAMPLE_SHIFT; 402 val |= sensor->config->tiddq_en << SENSOR_CONFIG1_TIDDQ_EN_SHIFT; 403 val |= sensor->config->ten_count << SENSOR_CONFIG1_TEN_COUNT_SHIFT; 404 val |= SENSOR_CONFIG1_TEMP_ENABLE; 405 writel(val, base + SENSOR_CONFIG1); 406 407 writel(tegra->calib[i], base + SENSOR_CONFIG2); 408 } 409 410 /* 411 * Translate from soctherm readback format to millicelsius. 412 * The soctherm readback format in bits is as follows: 413 * TTTTTTTT H______N 414 * where T's contain the temperature in Celsius, 415 * H denotes an addition of 0.5 Celsius and N denotes negation 416 * of the final value. 417 */ 418 static int translate_temp(u16 val) 419 { 420 int t; 421 422 t = ((val & READBACK_VALUE_MASK) >> READBACK_VALUE_SHIFT) * 1000; 423 if (val & READBACK_ADD_HALF) 424 t += 500; 425 if (val & READBACK_NEGATE) 426 t *= -1; 427 428 return t; 429 } 430 431 static int tegra_thermctl_get_temp(struct thermal_zone_device *tz, int *out_temp) 432 { 433 struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz); 434 u32 val; 435 436 val = readl(zone->reg); 437 val = REG_GET_MASK(val, zone->sg->sensor_temp_mask); 438 *out_temp = translate_temp(val); 439 440 return 0; 441 } 442 443 /** 444 * enforce_temp_range() - check and enforce temperature range [min, max] 445 * @dev: struct device * of the SOC_THERM instance 446 * @trip_temp: the trip temperature to check 447 * 448 * Checks and enforces the permitted temperature range that SOC_THERM 449 * HW can support This is 450 * done while taking care of precision. 451 * 452 * Return: The precision adjusted capped temperature in millicelsius. 453 */ 454 static int enforce_temp_range(struct device *dev, int trip_temp) 455 { 456 int temp; 457 458 temp = clamp_val(trip_temp, min_low_temp, max_high_temp); 459 if (temp != trip_temp) 460 dev_dbg(dev, "soctherm: trip temperature %d forced to %d\n", 461 trip_temp, temp); 462 return temp; 463 } 464 465 /** 466 * thermtrip_program() - Configures the hardware to shut down the 467 * system if a given sensor group reaches a given temperature 468 * @dev: ptr to the struct device for the SOC_THERM IP block 469 * @sg: pointer to the sensor group to set the thermtrip temperature for 470 * @trip_temp: the temperature in millicelsius to trigger the thermal trip at 471 * 472 * Sets the thermal trip threshold of the given sensor group to be the 473 * @trip_temp. If this threshold is crossed, the hardware will shut 474 * down. 475 * 476 * Note that, although @trip_temp is specified in millicelsius, the 477 * hardware is programmed in degrees Celsius. 478 * 479 * Return: 0 upon success, or %-EINVAL upon failure. 480 */ 481 static int thermtrip_program(struct device *dev, 482 const struct tegra_tsensor_group *sg, 483 int trip_temp) 484 { 485 struct tegra_soctherm *ts = dev_get_drvdata(dev); 486 int temp; 487 u32 r; 488 489 if (!sg || !sg->thermtrip_threshold_mask) 490 return -EINVAL; 491 492 temp = enforce_temp_range(dev, trip_temp) / ts->soc->thresh_grain; 493 494 r = readl(ts->regs + THERMCTL_THERMTRIP_CTL); 495 r = REG_SET_MASK(r, sg->thermtrip_threshold_mask, temp); 496 r = REG_SET_MASK(r, sg->thermtrip_enable_mask, 1); 497 r = REG_SET_MASK(r, sg->thermtrip_any_en_mask, 0); 498 writel(r, ts->regs + THERMCTL_THERMTRIP_CTL); 499 500 return 0; 501 } 502 503 /** 504 * throttrip_program() - Configures the hardware to throttle the 505 * pulse if a given sensor group reaches a given temperature 506 * @dev: ptr to the struct device for the SOC_THERM IP block 507 * @sg: pointer to the sensor group to set the thermtrip temperature for 508 * @stc: pointer to the throttle need to be triggered 509 * @trip_temp: the temperature in millicelsius to trigger the thermal trip at 510 * 511 * Sets the thermal trip threshold and throttle event of the given sensor 512 * group. If this threshold is crossed, the hardware will trigger the 513 * throttle. 514 * 515 * Note that, although @trip_temp is specified in millicelsius, the 516 * hardware is programmed in degrees Celsius. 517 * 518 * Return: 0 upon success, or %-EINVAL upon failure. 519 */ 520 static int throttrip_program(struct device *dev, 521 const struct tegra_tsensor_group *sg, 522 struct soctherm_throt_cfg *stc, 523 int trip_temp) 524 { 525 struct tegra_soctherm *ts = dev_get_drvdata(dev); 526 int temp, cpu_throt, gpu_throt; 527 unsigned int throt; 528 u32 r, reg_off; 529 530 if (!sg || !stc || !stc->init) 531 return -EINVAL; 532 533 temp = enforce_temp_range(dev, trip_temp) / ts->soc->thresh_grain; 534 535 /* Hardcode LIGHT on LEVEL1 and HEAVY on LEVEL2 */ 536 throt = stc->id; 537 reg_off = THERMCTL_LVL_REG(sg->thermctl_lvl0_offset, throt + 1); 538 539 if (throt == THROTTLE_LIGHT) { 540 cpu_throt = THERMCTL_LVL0_CPU0_CPU_THROT_LIGHT; 541 gpu_throt = THERMCTL_LVL0_CPU0_GPU_THROT_LIGHT; 542 } else { 543 cpu_throt = THERMCTL_LVL0_CPU0_CPU_THROT_HEAVY; 544 gpu_throt = THERMCTL_LVL0_CPU0_GPU_THROT_HEAVY; 545 if (throt != THROTTLE_HEAVY) 546 dev_warn(dev, 547 "invalid throt id %d - assuming HEAVY", 548 throt); 549 } 550 551 r = readl(ts->regs + reg_off); 552 r = REG_SET_MASK(r, sg->thermctl_lvl0_up_thresh_mask, temp); 553 r = REG_SET_MASK(r, sg->thermctl_lvl0_dn_thresh_mask, temp); 554 r = REG_SET_MASK(r, THERMCTL_LVL0_CPU0_CPU_THROT_MASK, cpu_throt); 555 r = REG_SET_MASK(r, THERMCTL_LVL0_CPU0_GPU_THROT_MASK, gpu_throt); 556 r = REG_SET_MASK(r, THERMCTL_LVL0_CPU0_EN_MASK, 1); 557 writel(r, ts->regs + reg_off); 558 559 return 0; 560 } 561 562 static struct soctherm_throt_cfg * 563 find_throttle_cfg_by_name(struct tegra_soctherm *ts, const char *name) 564 { 565 unsigned int i; 566 567 for (i = 0; ts->throt_cfgs[i].name; i++) 568 if (!strcmp(ts->throt_cfgs[i].name, name)) 569 return &ts->throt_cfgs[i]; 570 571 return NULL; 572 } 573 574 static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id) 575 { 576 int i, temp = min_low_temp; 577 struct tsensor_group_thermtrips *tt = ts->soc->thermtrips; 578 579 if (id >= TEGRA124_SOCTHERM_SENSOR_NUM) 580 return temp; 581 582 if (tt) { 583 for (i = 0; i < ts->soc->num_ttgs; i++) { 584 if (tt[i].id == id) 585 return tt[i].temp; 586 } 587 } 588 589 return temp; 590 } 591 592 static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, 593 const struct thermal_trip *trip, int temp) 594 { 595 struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz); 596 struct tegra_soctherm *ts = zone->ts; 597 const struct tegra_tsensor_group *sg = zone->sg; 598 struct device *dev = zone->dev; 599 600 if (!tz) 601 return -EINVAL; 602 603 if (trip->type == THERMAL_TRIP_CRITICAL) { 604 /* 605 * If thermtrips property is set in DT, 606 * doesn't need to program critical type trip to HW, 607 * if not, program critical trip to HW. 608 */ 609 if (min_low_temp == tsensor_group_thermtrip_get(ts, sg->id)) 610 return thermtrip_program(dev, sg, temp); 611 else 612 return 0; 613 614 } else if (trip->type == THERMAL_TRIP_HOT) { 615 int i; 616 617 for (i = 0; i < THROTTLE_SIZE; i++) { 618 struct thermal_cooling_device *cdev; 619 struct soctherm_throt_cfg *stc; 620 621 if (!ts->throt_cfgs[i].init) 622 continue; 623 624 cdev = ts->throt_cfgs[i].cdev; 625 if (thermal_trip_is_bound_to_cdev(tz, trip, cdev)) 626 stc = find_throttle_cfg_by_name(ts, cdev->type); 627 else 628 continue; 629 630 return throttrip_program(dev, sg, stc, temp); 631 } 632 } 633 634 return 0; 635 } 636 637 static void thermal_irq_enable(struct tegra_thermctl_zone *zn) 638 { 639 u32 r; 640 641 /* multiple zones could be handling and setting trips at once */ 642 mutex_lock(&zn->ts->thermctl_lock); 643 r = readl(zn->ts->regs + THERMCTL_INTR_ENABLE); 644 r = REG_SET_MASK(r, zn->sg->thermctl_isr_mask, TH_INTR_UP_DN_EN); 645 writel(r, zn->ts->regs + THERMCTL_INTR_ENABLE); 646 mutex_unlock(&zn->ts->thermctl_lock); 647 } 648 649 static void thermal_irq_disable(struct tegra_thermctl_zone *zn) 650 { 651 u32 r; 652 653 /* multiple zones could be handling and setting trips at once */ 654 mutex_lock(&zn->ts->thermctl_lock); 655 r = readl(zn->ts->regs + THERMCTL_INTR_DISABLE); 656 r = REG_SET_MASK(r, zn->sg->thermctl_isr_mask, 0); 657 writel(r, zn->ts->regs + THERMCTL_INTR_DISABLE); 658 mutex_unlock(&zn->ts->thermctl_lock); 659 } 660 661 static int tegra_thermctl_set_trips(struct thermal_zone_device *tz, int lo, int hi) 662 { 663 struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz); 664 u32 r; 665 666 thermal_irq_disable(zone); 667 668 r = readl(zone->ts->regs + zone->sg->thermctl_lvl0_offset); 669 r = REG_SET_MASK(r, THERMCTL_LVL0_CPU0_EN_MASK, 0); 670 writel(r, zone->ts->regs + zone->sg->thermctl_lvl0_offset); 671 672 lo = enforce_temp_range(zone->dev, lo) / zone->ts->soc->thresh_grain; 673 hi = enforce_temp_range(zone->dev, hi) / zone->ts->soc->thresh_grain; 674 dev_dbg(zone->dev, "%s hi:%d, lo:%d\n", __func__, hi, lo); 675 676 r = REG_SET_MASK(r, zone->sg->thermctl_lvl0_up_thresh_mask, hi); 677 r = REG_SET_MASK(r, zone->sg->thermctl_lvl0_dn_thresh_mask, lo); 678 r = REG_SET_MASK(r, THERMCTL_LVL0_CPU0_EN_MASK, 1); 679 writel(r, zone->ts->regs + zone->sg->thermctl_lvl0_offset); 680 681 thermal_irq_enable(zone); 682 683 return 0; 684 } 685 686 static const struct thermal_zone_device_ops tegra_of_thermal_ops = { 687 .get_temp = tegra_thermctl_get_temp, 688 .set_trip_temp = tegra_thermctl_set_trip_temp, 689 .set_trips = tegra_thermctl_set_trips, 690 }; 691 692 static int get_hot_trip_cb(struct thermal_trip *trip, void *arg) 693 { 694 const struct thermal_trip **trip_ret = arg; 695 696 if (trip->type != THERMAL_TRIP_HOT) 697 return 0; 698 699 *trip_ret = trip; 700 /* Return nonzero to terminate the search. */ 701 return 1; 702 } 703 704 static const struct thermal_trip *get_hot_trip(struct thermal_zone_device *tz) 705 { 706 const struct thermal_trip *trip = NULL; 707 708 thermal_zone_for_each_trip(tz, get_hot_trip_cb, &trip); 709 710 return trip; 711 } 712 713 /** 714 * tegra_soctherm_set_hwtrips() - set HW trip point from DT data 715 * @dev: struct device * of the SOC_THERM instance 716 * @sg: pointer to the sensor group to set the thermtrip temperature for 717 * @tz: struct thermal_zone_device * 718 * 719 * Configure the SOC_THERM HW trip points, setting "THERMTRIP" 720 * "THROTTLE" trip points , using "thermtrips", "critical" or "hot" 721 * type trip_temp 722 * from thermal zone. 723 * After they have been configured, THERMTRIP or THROTTLE will take 724 * action when the configured SoC thermal sensor group reaches a 725 * certain temperature. 726 * 727 * Return: 0 upon success, or a negative error code on failure. 728 * "Success" does not mean that trips was enabled; it could also 729 * mean that no node was found in DT. 730 * THERMTRIP has been enabled successfully when a message similar to 731 * this one appears on the serial console: 732 * "thermtrip: will shut down when sensor group XXX reaches YYYYYY mC" 733 * THROTTLE has been enabled successfully when a message similar to 734 * this one appears on the serial console: 735 * ""throttrip: will throttle when sensor group XXX reaches YYYYYY mC" 736 */ 737 static int tegra_soctherm_set_hwtrips(struct device *dev, 738 const struct tegra_tsensor_group *sg, 739 struct thermal_zone_device *tz) 740 { 741 struct tegra_soctherm *ts = dev_get_drvdata(dev); 742 const struct thermal_trip *hot_trip; 743 struct soctherm_throt_cfg *stc; 744 int i, temperature, ret; 745 746 /* Get thermtrips. If missing, try to get critical trips. */ 747 temperature = tsensor_group_thermtrip_get(ts, sg->id); 748 if (min_low_temp == temperature) 749 if (thermal_zone_get_crit_temp(tz, &temperature)) 750 temperature = max_high_temp; 751 752 ret = thermtrip_program(dev, sg, temperature); 753 if (ret) { 754 dev_err(dev, "thermtrip: %s: error during enable\n", sg->name); 755 return ret; 756 } 757 758 dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n", 759 sg->name, temperature); 760 761 hot_trip = get_hot_trip(tz); 762 if (!hot_trip) { 763 dev_info(dev, "throttrip: %s: missing hot temperature\n", 764 sg->name); 765 return 0; 766 } 767 768 for (i = 0; i < THROTTLE_OC1; i++) { 769 struct thermal_cooling_device *cdev; 770 771 if (!ts->throt_cfgs[i].init) 772 continue; 773 774 cdev = ts->throt_cfgs[i].cdev; 775 if (thermal_trip_is_bound_to_cdev(tz, hot_trip, cdev)) 776 stc = find_throttle_cfg_by_name(ts, cdev->type); 777 else 778 continue; 779 780 ret = throttrip_program(dev, sg, stc, temperature); 781 if (ret) { 782 dev_err(dev, "throttrip: %s: error during enable\n", 783 sg->name); 784 return ret; 785 } 786 787 dev_info(dev, 788 "throttrip: will throttle when %s reaches %d mC\n", 789 sg->name, temperature); 790 break; 791 } 792 793 if (i == THROTTLE_SIZE) 794 dev_info(dev, "throttrip: %s: missing throttle cdev\n", 795 sg->name); 796 797 return 0; 798 } 799 800 static irqreturn_t soctherm_thermal_isr(int irq, void *dev_id) 801 { 802 struct tegra_soctherm *ts = dev_id; 803 u32 r; 804 805 /* Case for no lock: 806 * Although interrupts are enabled in set_trips, there is still no need 807 * to lock here because the interrupts are disabled before programming 808 * new trip points. Hence there cant be a interrupt on the same sensor. 809 * An interrupt can however occur on a sensor while trips are being 810 * programmed on a different one. This beign a LEVEL interrupt won't 811 * cause a new interrupt but this is taken care of by the re-reading of 812 * the STATUS register in the thread function. 813 */ 814 r = readl(ts->regs + THERMCTL_INTR_STATUS); 815 writel(r, ts->regs + THERMCTL_INTR_DISABLE); 816 817 return IRQ_WAKE_THREAD; 818 } 819 820 /** 821 * soctherm_thermal_isr_thread() - Handles a thermal interrupt request 822 * @irq: The interrupt number being requested; not used 823 * @dev_id: Opaque pointer to tegra_soctherm; 824 * 825 * Clears the interrupt status register if there are expected 826 * interrupt bits set. 827 * The interrupt(s) are then handled by updating the corresponding 828 * thermal zones. 829 * 830 * An error is logged if any unexpected interrupt bits are set. 831 * 832 * Disabled interrupts are re-enabled. 833 * 834 * Return: %IRQ_HANDLED. Interrupt was handled and no further processing 835 * is needed. 836 */ 837 static irqreturn_t soctherm_thermal_isr_thread(int irq, void *dev_id) 838 { 839 struct tegra_soctherm *ts = dev_id; 840 struct thermal_zone_device *tz; 841 u32 st, ex = 0, cp = 0, gp = 0, pl = 0, me = 0; 842 843 st = readl(ts->regs + THERMCTL_INTR_STATUS); 844 845 /* deliberately clear expected interrupts handled in SW */ 846 cp |= st & TH_INTR_CD0_MASK; 847 cp |= st & TH_INTR_CU0_MASK; 848 849 gp |= st & TH_INTR_GD0_MASK; 850 gp |= st & TH_INTR_GU0_MASK; 851 852 pl |= st & TH_INTR_PD0_MASK; 853 pl |= st & TH_INTR_PU0_MASK; 854 855 me |= st & TH_INTR_MD0_MASK; 856 me |= st & TH_INTR_MU0_MASK; 857 858 ex |= cp | gp | pl | me; 859 if (ex) { 860 writel(ex, ts->regs + THERMCTL_INTR_STATUS); 861 st &= ~ex; 862 863 if (cp) { 864 tz = ts->thermctl_tzs[TEGRA124_SOCTHERM_SENSOR_CPU]; 865 thermal_zone_device_update(tz, 866 THERMAL_EVENT_UNSPECIFIED); 867 } 868 869 if (gp) { 870 tz = ts->thermctl_tzs[TEGRA124_SOCTHERM_SENSOR_GPU]; 871 thermal_zone_device_update(tz, 872 THERMAL_EVENT_UNSPECIFIED); 873 } 874 875 if (pl) { 876 tz = ts->thermctl_tzs[TEGRA124_SOCTHERM_SENSOR_PLLX]; 877 thermal_zone_device_update(tz, 878 THERMAL_EVENT_UNSPECIFIED); 879 } 880 881 if (me) { 882 tz = ts->thermctl_tzs[TEGRA124_SOCTHERM_SENSOR_MEM]; 883 thermal_zone_device_update(tz, 884 THERMAL_EVENT_UNSPECIFIED); 885 } 886 } 887 888 /* deliberately ignore expected interrupts NOT handled in SW */ 889 ex |= TH_INTR_IGNORE_MASK; 890 st &= ~ex; 891 892 if (st) { 893 /* Whine about any other unexpected INTR bits still set */ 894 pr_err("soctherm: Ignored unexpected INTRs 0x%08x\n", st); 895 writel(st, ts->regs + THERMCTL_INTR_STATUS); 896 } 897 898 return IRQ_HANDLED; 899 } 900 901 /** 902 * soctherm_oc_intr_enable() - Enables the soctherm over-current interrupt 903 * @ts: pointer to a struct tegra_soctherm 904 * @alarm: The soctherm throttle id 905 * @enable: Flag indicating enable the soctherm over-current 906 * interrupt or disable it 907 * 908 * Enables a specific over-current pins @alarm to raise an interrupt if the flag 909 * is set and the alarm corresponds to OC1, OC2, OC3, or OC4. 910 */ 911 static void soctherm_oc_intr_enable(struct tegra_soctherm *ts, 912 enum soctherm_throttle_id alarm, 913 bool enable) 914 { 915 u32 r; 916 917 if (!enable) 918 return; 919 920 r = readl(ts->regs + OC_INTR_ENABLE); 921 switch (alarm) { 922 case THROTTLE_OC1: 923 r = REG_SET_MASK(r, OC_INTR_OC1_MASK, 1); 924 break; 925 case THROTTLE_OC2: 926 r = REG_SET_MASK(r, OC_INTR_OC2_MASK, 1); 927 break; 928 case THROTTLE_OC3: 929 r = REG_SET_MASK(r, OC_INTR_OC3_MASK, 1); 930 break; 931 case THROTTLE_OC4: 932 r = REG_SET_MASK(r, OC_INTR_OC4_MASK, 1); 933 break; 934 default: 935 r = 0; 936 break; 937 } 938 writel(r, ts->regs + OC_INTR_ENABLE); 939 } 940 941 /** 942 * soctherm_handle_alarm() - Handles soctherm alarms 943 * @alarm: The soctherm throttle id 944 * 945 * "Handles" over-current alarms (OC1, OC2, OC3, and OC4) by printing 946 * a warning or informative message. 947 * 948 * Return: -EINVAL for @alarm = THROTTLE_OC3, otherwise 0 (success). 949 */ 950 static int soctherm_handle_alarm(enum soctherm_throttle_id alarm) 951 { 952 int rv = -EINVAL; 953 954 switch (alarm) { 955 case THROTTLE_OC1: 956 pr_debug("soctherm: Successfully handled OC1 alarm\n"); 957 rv = 0; 958 break; 959 960 case THROTTLE_OC2: 961 pr_debug("soctherm: Successfully handled OC2 alarm\n"); 962 rv = 0; 963 break; 964 965 case THROTTLE_OC3: 966 pr_debug("soctherm: Successfully handled OC3 alarm\n"); 967 rv = 0; 968 break; 969 970 case THROTTLE_OC4: 971 pr_debug("soctherm: Successfully handled OC4 alarm\n"); 972 rv = 0; 973 break; 974 975 default: 976 break; 977 } 978 979 if (rv) 980 pr_err("soctherm: ERROR in handling %s alarm\n", 981 throt_names[alarm]); 982 983 return rv; 984 } 985 986 /** 987 * soctherm_edp_isr_thread() - log an over-current interrupt request 988 * @irq: OC irq number. Currently not being used. See description 989 * @arg: a void pointer for callback, currently not being used 990 * 991 * Over-current events are handled in hardware. This function is called to log 992 * and handle any OC events that happened. Additionally, it checks every 993 * over-current interrupt registers for registers are set but 994 * was not expected (i.e. any discrepancy in interrupt status) by the function, 995 * the discrepancy will logged. 996 * 997 * Return: %IRQ_HANDLED 998 */ 999 static irqreturn_t soctherm_edp_isr_thread(int irq, void *arg) 1000 { 1001 struct tegra_soctherm *ts = arg; 1002 u32 st, ex, oc1, oc2, oc3, oc4; 1003 1004 st = readl(ts->regs + OC_INTR_STATUS); 1005 1006 /* deliberately clear expected interrupts handled in SW */ 1007 oc1 = st & OC_INTR_OC1_MASK; 1008 oc2 = st & OC_INTR_OC2_MASK; 1009 oc3 = st & OC_INTR_OC3_MASK; 1010 oc4 = st & OC_INTR_OC4_MASK; 1011 ex = oc1 | oc2 | oc3 | oc4; 1012 1013 pr_err("soctherm: OC ALARM 0x%08x\n", ex); 1014 if (ex) { 1015 writel(st, ts->regs + OC_INTR_STATUS); 1016 st &= ~ex; 1017 1018 if (oc1 && !soctherm_handle_alarm(THROTTLE_OC1)) 1019 soctherm_oc_intr_enable(ts, THROTTLE_OC1, true); 1020 1021 if (oc2 && !soctherm_handle_alarm(THROTTLE_OC2)) 1022 soctherm_oc_intr_enable(ts, THROTTLE_OC2, true); 1023 1024 if (oc3 && !soctherm_handle_alarm(THROTTLE_OC3)) 1025 soctherm_oc_intr_enable(ts, THROTTLE_OC3, true); 1026 1027 if (oc4 && !soctherm_handle_alarm(THROTTLE_OC4)) 1028 soctherm_oc_intr_enable(ts, THROTTLE_OC4, true); 1029 1030 if (oc1 && soc_irq_cdata.irq_enable & BIT(0)) 1031 handle_nested_irq( 1032 irq_find_mapping(soc_irq_cdata.domain, 0)); 1033 1034 if (oc2 && soc_irq_cdata.irq_enable & BIT(1)) 1035 handle_nested_irq( 1036 irq_find_mapping(soc_irq_cdata.domain, 1)); 1037 1038 if (oc3 && soc_irq_cdata.irq_enable & BIT(2)) 1039 handle_nested_irq( 1040 irq_find_mapping(soc_irq_cdata.domain, 2)); 1041 1042 if (oc4 && soc_irq_cdata.irq_enable & BIT(3)) 1043 handle_nested_irq( 1044 irq_find_mapping(soc_irq_cdata.domain, 3)); 1045 } 1046 1047 if (st) { 1048 pr_err("soctherm: Ignored unexpected OC ALARM 0x%08x\n", st); 1049 writel(st, ts->regs + OC_INTR_STATUS); 1050 } 1051 1052 return IRQ_HANDLED; 1053 } 1054 1055 /** 1056 * soctherm_edp_isr() - Disables any active interrupts 1057 * @irq: The interrupt request number 1058 * @arg: Opaque pointer to an argument 1059 * 1060 * Writes to the OC_INTR_DISABLE register the over current interrupt status, 1061 * masking any asserted interrupts. Doing this prevents the same interrupts 1062 * from triggering this isr repeatedly. The thread woken by this isr will 1063 * handle asserted interrupts and subsequently unmask/re-enable them. 1064 * 1065 * The OC_INTR_DISABLE register indicates which OC interrupts 1066 * have been disabled. 1067 * 1068 * Return: %IRQ_WAKE_THREAD, handler requests to wake the handler thread 1069 */ 1070 static irqreturn_t soctherm_edp_isr(int irq, void *arg) 1071 { 1072 struct tegra_soctherm *ts = arg; 1073 u32 r; 1074 1075 if (!ts) 1076 return IRQ_NONE; 1077 1078 r = readl(ts->regs + OC_INTR_STATUS); 1079 writel(r, ts->regs + OC_INTR_DISABLE); 1080 1081 return IRQ_WAKE_THREAD; 1082 } 1083 1084 /** 1085 * soctherm_oc_irq_lock() - locks the over-current interrupt request 1086 * @data: Interrupt request data 1087 * 1088 * Looks up the chip data from @data and locks the mutex associated with 1089 * a particular over-current interrupt request. 1090 */ 1091 static void soctherm_oc_irq_lock(struct irq_data *data) 1092 { 1093 struct soctherm_oc_irq_chip_data *d = irq_data_get_irq_chip_data(data); 1094 1095 mutex_lock(&d->irq_lock); 1096 } 1097 1098 /** 1099 * soctherm_oc_irq_sync_unlock() - Unlocks the OC interrupt request 1100 * @data: Interrupt request data 1101 * 1102 * Looks up the interrupt request data @data and unlocks the mutex associated 1103 * with a particular over-current interrupt request. 1104 */ 1105 static void soctherm_oc_irq_sync_unlock(struct irq_data *data) 1106 { 1107 struct soctherm_oc_irq_chip_data *d = irq_data_get_irq_chip_data(data); 1108 1109 mutex_unlock(&d->irq_lock); 1110 } 1111 1112 /** 1113 * soctherm_oc_irq_enable() - Enables the SOC_THERM over-current interrupt queue 1114 * @data: irq_data structure of the chip 1115 * 1116 * Sets the irq_enable bit of SOC_THERM allowing SOC_THERM 1117 * to respond to over-current interrupts. 1118 * 1119 */ 1120 static void soctherm_oc_irq_enable(struct irq_data *data) 1121 { 1122 struct soctherm_oc_irq_chip_data *d = irq_data_get_irq_chip_data(data); 1123 1124 d->irq_enable |= BIT(data->hwirq); 1125 } 1126 1127 /** 1128 * soctherm_oc_irq_disable() - Disables overcurrent interrupt requests 1129 * @data: The interrupt request information 1130 * 1131 * Clears the interrupt request enable bit of the overcurrent 1132 * interrupt request chip data. 1133 * 1134 * Return: Nothing is returned (void) 1135 */ 1136 static void soctherm_oc_irq_disable(struct irq_data *data) 1137 { 1138 struct soctherm_oc_irq_chip_data *d = irq_data_get_irq_chip_data(data); 1139 1140 d->irq_enable &= ~BIT(data->hwirq); 1141 } 1142 1143 static int soctherm_oc_irq_set_type(struct irq_data *data, unsigned int type) 1144 { 1145 return 0; 1146 } 1147 1148 /** 1149 * soctherm_oc_irq_map() - SOC_THERM interrupt request domain mapper 1150 * @h: Interrupt request domain 1151 * @virq: Virtual interrupt request number 1152 * @hw: Hardware interrupt request number 1153 * 1154 * Mapping callback function for SOC_THERM's irq_domain. When a SOC_THERM 1155 * interrupt request is called, the irq_domain takes the request's virtual 1156 * request number (much like a virtual memory address) and maps it to a 1157 * physical hardware request number. 1158 * 1159 * When a mapping doesn't already exist for a virtual request number, the 1160 * irq_domain calls this function to associate the virtual request number with 1161 * a hardware request number. 1162 * 1163 * Return: 0 1164 */ 1165 static int soctherm_oc_irq_map(struct irq_domain *h, unsigned int virq, 1166 irq_hw_number_t hw) 1167 { 1168 struct soctherm_oc_irq_chip_data *data = h->host_data; 1169 1170 irq_set_chip_data(virq, data); 1171 irq_set_chip(virq, &data->irq_chip); 1172 irq_set_nested_thread(virq, 1); 1173 return 0; 1174 } 1175 1176 /** 1177 * soctherm_irq_domain_xlate_twocell() - xlate for soctherm interrupts 1178 * @d: Interrupt request domain 1179 * @ctrlr: Controller device tree node 1180 * @intspec: Array of u32s from DTs "interrupt" property 1181 * @intsize: Number of values inside the intspec array 1182 * @out_hwirq: HW IRQ value associated with this interrupt 1183 * @out_type: The IRQ SENSE type for this interrupt. 1184 * 1185 * This Device Tree IRQ specifier translation function will translate a 1186 * specific "interrupt" as defined by 2 DT values where the cell values map 1187 * the hwirq number + 1 and linux irq flags. Since the output is the hwirq 1188 * number, this function will subtract 1 from the value listed in DT. 1189 * 1190 * Return: 0 1191 */ 1192 static int soctherm_irq_domain_xlate_twocell(struct irq_domain *d, 1193 struct device_node *ctrlr, const u32 *intspec, unsigned int intsize, 1194 irq_hw_number_t *out_hwirq, unsigned int *out_type) 1195 { 1196 if (WARN_ON(intsize < 2)) 1197 return -EINVAL; 1198 1199 /* 1200 * The HW value is 1 index less than the DT IRQ values. 1201 * i.e. OC4 goes to HW index 3. 1202 */ 1203 *out_hwirq = intspec[0] - 1; 1204 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; 1205 return 0; 1206 } 1207 1208 static const struct irq_domain_ops soctherm_oc_domain_ops = { 1209 .map = soctherm_oc_irq_map, 1210 .xlate = soctherm_irq_domain_xlate_twocell, 1211 }; 1212 1213 /** 1214 * soctherm_oc_int_init() - Initial enabling of the over 1215 * current interrupts 1216 * @fwnode: The devicetree node for soctherm 1217 * @num_irqs: The number of new interrupt requests 1218 * 1219 * Sets the over current interrupt request chip data 1220 * 1221 * Return: 0 on success or if overcurrent interrupts are not enabled, 1222 * -ENOMEM (out of memory), or irq_base if the function failed to 1223 * allocate the irqs 1224 */ 1225 static int soctherm_oc_int_init(struct fwnode_handle *fwnode, int num_irqs) 1226 { 1227 if (!num_irqs) { 1228 pr_info("%s(): OC interrupts are not enabled\n", __func__); 1229 return 0; 1230 } 1231 1232 mutex_init(&soc_irq_cdata.irq_lock); 1233 soc_irq_cdata.irq_enable = 0; 1234 1235 soc_irq_cdata.irq_chip.name = "soc_therm_oc"; 1236 soc_irq_cdata.irq_chip.irq_bus_lock = soctherm_oc_irq_lock; 1237 soc_irq_cdata.irq_chip.irq_bus_sync_unlock = 1238 soctherm_oc_irq_sync_unlock; 1239 soc_irq_cdata.irq_chip.irq_disable = soctherm_oc_irq_disable; 1240 soc_irq_cdata.irq_chip.irq_enable = soctherm_oc_irq_enable; 1241 soc_irq_cdata.irq_chip.irq_set_type = soctherm_oc_irq_set_type; 1242 soc_irq_cdata.irq_chip.irq_set_wake = NULL; 1243 1244 soc_irq_cdata.domain = irq_domain_create_linear(fwnode, num_irqs, &soctherm_oc_domain_ops, 1245 &soc_irq_cdata); 1246 if (!soc_irq_cdata.domain) { 1247 pr_err("%s: Failed to create IRQ domain\n", __func__); 1248 return -ENOMEM; 1249 } 1250 1251 pr_debug("%s(): OC interrupts enabled successful\n", __func__); 1252 return 0; 1253 } 1254 1255 #ifdef CONFIG_DEBUG_FS 1256 static int regs_show(struct seq_file *s, void *data) 1257 { 1258 struct platform_device *pdev = s->private; 1259 struct tegra_soctherm *ts = platform_get_drvdata(pdev); 1260 const struct tegra_tsensor *tsensors = ts->soc->tsensors; 1261 const struct tegra_tsensor_group **ttgs = ts->soc->ttgs; 1262 u32 r, state; 1263 int i, level; 1264 1265 seq_puts(s, "-----TSENSE (convert HW)-----\n"); 1266 1267 for (i = 0; i < ts->soc->num_tsensors; i++) { 1268 r = readl(ts->regs + tsensors[i].base + SENSOR_CONFIG1); 1269 state = REG_GET_MASK(r, SENSOR_CONFIG1_TEMP_ENABLE); 1270 1271 seq_printf(s, "%s: ", tsensors[i].name); 1272 seq_printf(s, "En(%d) ", state); 1273 1274 if (!state) { 1275 seq_puts(s, "\n"); 1276 continue; 1277 } 1278 1279 state = REG_GET_MASK(r, SENSOR_CONFIG1_TIDDQ_EN_MASK); 1280 seq_printf(s, "tiddq(%d) ", state); 1281 state = REG_GET_MASK(r, SENSOR_CONFIG1_TEN_COUNT_MASK); 1282 seq_printf(s, "ten_count(%d) ", state); 1283 state = REG_GET_MASK(r, SENSOR_CONFIG1_TSAMPLE_MASK); 1284 seq_printf(s, "tsample(%d) ", state + 1); 1285 1286 r = readl(ts->regs + tsensors[i].base + SENSOR_STATUS1); 1287 state = REG_GET_MASK(r, SENSOR_STATUS1_TEMP_VALID_MASK); 1288 seq_printf(s, "Temp(%d/", state); 1289 state = REG_GET_MASK(r, SENSOR_STATUS1_TEMP_MASK); 1290 seq_printf(s, "%d) ", translate_temp(state)); 1291 1292 r = readl(ts->regs + tsensors[i].base + SENSOR_STATUS0); 1293 state = REG_GET_MASK(r, SENSOR_STATUS0_VALID_MASK); 1294 seq_printf(s, "Capture(%d/", state); 1295 state = REG_GET_MASK(r, SENSOR_STATUS0_CAPTURE_MASK); 1296 seq_printf(s, "%d) ", state); 1297 1298 r = readl(ts->regs + tsensors[i].base + SENSOR_CONFIG0); 1299 state = REG_GET_MASK(r, SENSOR_CONFIG0_STOP); 1300 seq_printf(s, "Stop(%d) ", state); 1301 state = REG_GET_MASK(r, SENSOR_CONFIG0_TALL_MASK); 1302 seq_printf(s, "Tall(%d) ", state); 1303 state = REG_GET_MASK(r, SENSOR_CONFIG0_TCALC_OVER); 1304 seq_printf(s, "Over(%d/", state); 1305 state = REG_GET_MASK(r, SENSOR_CONFIG0_OVER); 1306 seq_printf(s, "%d/", state); 1307 state = REG_GET_MASK(r, SENSOR_CONFIG0_CPTR_OVER); 1308 seq_printf(s, "%d) ", state); 1309 1310 r = readl(ts->regs + tsensors[i].base + SENSOR_CONFIG2); 1311 state = REG_GET_MASK(r, SENSOR_CONFIG2_THERMA_MASK); 1312 seq_printf(s, "Therm_A/B(%d/", state); 1313 state = REG_GET_MASK(r, SENSOR_CONFIG2_THERMB_MASK); 1314 seq_printf(s, "%d)\n", (s16)state); 1315 } 1316 1317 r = readl(ts->regs + SENSOR_PDIV); 1318 seq_printf(s, "PDIV: 0x%x\n", r); 1319 1320 r = readl(ts->regs + SENSOR_HOTSPOT_OFF); 1321 seq_printf(s, "HOTSPOT: 0x%x\n", r); 1322 1323 seq_puts(s, "\n"); 1324 seq_puts(s, "-----SOC_THERM-----\n"); 1325 1326 r = readl(ts->regs + SENSOR_TEMP1); 1327 state = REG_GET_MASK(r, SENSOR_TEMP1_CPU_TEMP_MASK); 1328 seq_printf(s, "Temperatures: CPU(%d) ", translate_temp(state)); 1329 state = REG_GET_MASK(r, SENSOR_TEMP1_GPU_TEMP_MASK); 1330 seq_printf(s, " GPU(%d) ", translate_temp(state)); 1331 r = readl(ts->regs + SENSOR_TEMP2); 1332 state = REG_GET_MASK(r, SENSOR_TEMP2_PLLX_TEMP_MASK); 1333 seq_printf(s, " PLLX(%d) ", translate_temp(state)); 1334 state = REG_GET_MASK(r, SENSOR_TEMP2_MEM_TEMP_MASK); 1335 seq_printf(s, " MEM(%d)\n", translate_temp(state)); 1336 1337 for (i = 0; i < ts->soc->num_ttgs; i++) { 1338 seq_printf(s, "%s:\n", ttgs[i]->name); 1339 for (level = 0; level < 4; level++) { 1340 s32 v; 1341 u32 mask; 1342 u16 off = ttgs[i]->thermctl_lvl0_offset; 1343 1344 r = readl(ts->regs + THERMCTL_LVL_REG(off, level)); 1345 1346 mask = ttgs[i]->thermctl_lvl0_up_thresh_mask; 1347 state = REG_GET_MASK(r, mask); 1348 v = sign_extend32(state, ts->soc->bptt - 1); 1349 v *= ts->soc->thresh_grain; 1350 seq_printf(s, " %d: Up/Dn(%d /", level, v); 1351 1352 mask = ttgs[i]->thermctl_lvl0_dn_thresh_mask; 1353 state = REG_GET_MASK(r, mask); 1354 v = sign_extend32(state, ts->soc->bptt - 1); 1355 v *= ts->soc->thresh_grain; 1356 seq_printf(s, "%d ) ", v); 1357 1358 mask = THERMCTL_LVL0_CPU0_EN_MASK; 1359 state = REG_GET_MASK(r, mask); 1360 seq_printf(s, "En(%d) ", state); 1361 1362 mask = THERMCTL_LVL0_CPU0_CPU_THROT_MASK; 1363 state = REG_GET_MASK(r, mask); 1364 seq_puts(s, "CPU Throt"); 1365 if (!state) 1366 seq_printf(s, "(%s) ", "none"); 1367 else if (state == THERMCTL_LVL0_CPU0_CPU_THROT_LIGHT) 1368 seq_printf(s, "(%s) ", "L"); 1369 else if (state == THERMCTL_LVL0_CPU0_CPU_THROT_HEAVY) 1370 seq_printf(s, "(%s) ", "H"); 1371 else 1372 seq_printf(s, "(%s) ", "H+L"); 1373 1374 mask = THERMCTL_LVL0_CPU0_GPU_THROT_MASK; 1375 state = REG_GET_MASK(r, mask); 1376 seq_puts(s, "GPU Throt"); 1377 if (!state) 1378 seq_printf(s, "(%s) ", "none"); 1379 else if (state == THERMCTL_LVL0_CPU0_GPU_THROT_LIGHT) 1380 seq_printf(s, "(%s) ", "L"); 1381 else if (state == THERMCTL_LVL0_CPU0_GPU_THROT_HEAVY) 1382 seq_printf(s, "(%s) ", "H"); 1383 else 1384 seq_printf(s, "(%s) ", "H+L"); 1385 1386 mask = THERMCTL_LVL0_CPU0_STATUS_MASK; 1387 state = REG_GET_MASK(r, mask); 1388 seq_printf(s, "Status(%s)\n", 1389 state == 0 ? "LO" : 1390 state == 1 ? "In" : 1391 state == 2 ? "Res" : "HI"); 1392 } 1393 } 1394 1395 r = readl(ts->regs + THERMCTL_STATS_CTL); 1396 seq_printf(s, "STATS: Up(%s) Dn(%s)\n", 1397 r & STATS_CTL_EN_UP ? "En" : "--", 1398 r & STATS_CTL_EN_DN ? "En" : "--"); 1399 1400 for (level = 0; level < 4; level++) { 1401 u16 off; 1402 1403 off = THERMCTL_LVL0_UP_STATS; 1404 r = readl(ts->regs + THERMCTL_LVL_REG(off, level)); 1405 seq_printf(s, " Level_%d Up(%d) ", level, r); 1406 1407 off = THERMCTL_LVL0_DN_STATS; 1408 r = readl(ts->regs + THERMCTL_LVL_REG(off, level)); 1409 seq_printf(s, "Dn(%d)\n", r); 1410 } 1411 1412 r = readl(ts->regs + THERMCTL_THERMTRIP_CTL); 1413 state = REG_GET_MASK(r, ttgs[0]->thermtrip_any_en_mask); 1414 seq_printf(s, "Thermtrip Any En(%d)\n", state); 1415 for (i = 0; i < ts->soc->num_ttgs; i++) { 1416 state = REG_GET_MASK(r, ttgs[i]->thermtrip_enable_mask); 1417 seq_printf(s, " %s En(%d) ", ttgs[i]->name, state); 1418 state = REG_GET_MASK(r, ttgs[i]->thermtrip_threshold_mask); 1419 state *= ts->soc->thresh_grain; 1420 seq_printf(s, "Thresh(%d)\n", state); 1421 } 1422 1423 r = readl(ts->regs + THROT_GLOBAL_CFG); 1424 seq_puts(s, "\n"); 1425 seq_printf(s, "GLOBAL THROTTLE CONFIG: 0x%08x\n", r); 1426 1427 seq_puts(s, "---------------------------------------------------\n"); 1428 r = readl(ts->regs + THROT_STATUS); 1429 state = REG_GET_MASK(r, THROT_STATUS_BREACH_MASK); 1430 seq_printf(s, "THROT STATUS: breach(%d) ", state); 1431 state = REG_GET_MASK(r, THROT_STATUS_STATE_MASK); 1432 seq_printf(s, "state(%d) ", state); 1433 state = REG_GET_MASK(r, THROT_STATUS_ENABLED_MASK); 1434 seq_printf(s, "enabled(%d)\n", state); 1435 1436 r = readl(ts->regs + CPU_PSKIP_STATUS); 1437 if (ts->soc->use_ccroc) { 1438 state = REG_GET_MASK(r, XPU_PSKIP_STATUS_ENABLED_MASK); 1439 seq_printf(s, "CPU PSKIP STATUS: enabled(%d)\n", state); 1440 } else { 1441 state = REG_GET_MASK(r, XPU_PSKIP_STATUS_M_MASK); 1442 seq_printf(s, "CPU PSKIP STATUS: M(%d) ", state); 1443 state = REG_GET_MASK(r, XPU_PSKIP_STATUS_N_MASK); 1444 seq_printf(s, "N(%d) ", state); 1445 state = REG_GET_MASK(r, XPU_PSKIP_STATUS_ENABLED_MASK); 1446 seq_printf(s, "enabled(%d)\n", state); 1447 } 1448 1449 return 0; 1450 } 1451 1452 DEFINE_SHOW_ATTRIBUTE(regs); 1453 1454 static void soctherm_debug_init(struct platform_device *pdev) 1455 { 1456 struct tegra_soctherm *tegra = platform_get_drvdata(pdev); 1457 struct dentry *root; 1458 1459 root = debugfs_create_dir("soctherm", NULL); 1460 1461 tegra->debugfs_dir = root; 1462 1463 debugfs_create_file("reg_contents", 0644, root, pdev, ®s_fops); 1464 } 1465 #else 1466 static inline void soctherm_debug_init(struct platform_device *pdev) {} 1467 #endif 1468 1469 static int soctherm_clk_enable(struct platform_device *pdev, bool enable) 1470 { 1471 struct tegra_soctherm *tegra = platform_get_drvdata(pdev); 1472 int err; 1473 1474 if (!tegra->clock_soctherm || !tegra->clock_tsensor) 1475 return -EINVAL; 1476 1477 reset_control_assert(tegra->reset); 1478 1479 if (enable) { 1480 err = clk_prepare_enable(tegra->clock_soctherm); 1481 if (err) { 1482 reset_control_deassert(tegra->reset); 1483 return err; 1484 } 1485 1486 err = clk_prepare_enable(tegra->clock_tsensor); 1487 if (err) { 1488 clk_disable_unprepare(tegra->clock_soctherm); 1489 reset_control_deassert(tegra->reset); 1490 return err; 1491 } 1492 } else { 1493 clk_disable_unprepare(tegra->clock_tsensor); 1494 clk_disable_unprepare(tegra->clock_soctherm); 1495 } 1496 1497 reset_control_deassert(tegra->reset); 1498 1499 return 0; 1500 } 1501 1502 static void soctherm_clk_disable(void *data) 1503 { 1504 struct platform_device *pdev = data; 1505 1506 soctherm_clk_enable(pdev, false); 1507 } 1508 1509 static int throt_get_cdev_max_state(struct thermal_cooling_device *cdev, 1510 unsigned long *max_state) 1511 { 1512 *max_state = 1; 1513 return 0; 1514 } 1515 1516 static int throt_get_cdev_cur_state(struct thermal_cooling_device *cdev, 1517 unsigned long *cur_state) 1518 { 1519 struct tegra_soctherm *ts = cdev->devdata; 1520 u32 r; 1521 1522 r = readl(ts->regs + THROT_STATUS); 1523 if (REG_GET_MASK(r, THROT_STATUS_STATE_MASK)) 1524 *cur_state = 1; 1525 else 1526 *cur_state = 0; 1527 1528 return 0; 1529 } 1530 1531 static int throt_set_cdev_state(struct thermal_cooling_device *cdev, 1532 unsigned long cur_state) 1533 { 1534 return 0; 1535 } 1536 1537 static const struct thermal_cooling_device_ops throt_cooling_ops = { 1538 .get_max_state = throt_get_cdev_max_state, 1539 .get_cur_state = throt_get_cdev_cur_state, 1540 .set_cur_state = throt_set_cdev_state, 1541 }; 1542 1543 static int soctherm_thermtrips_parse(struct platform_device *pdev) 1544 { 1545 struct device *dev = &pdev->dev; 1546 struct tegra_soctherm *ts = dev_get_drvdata(dev); 1547 struct tsensor_group_thermtrips *tt = ts->soc->thermtrips; 1548 const int max_num_prop = ts->soc->num_ttgs * 2; 1549 u32 *tlb; 1550 int i, j, n, ret; 1551 1552 if (!tt) 1553 return -ENOMEM; 1554 1555 n = of_property_count_u32_elems(dev->of_node, "nvidia,thermtrips"); 1556 if (n <= 0) { 1557 dev_info(dev, 1558 "missing thermtrips, will use critical trips as shut down temp\n"); 1559 return n; 1560 } 1561 1562 n = min(max_num_prop, n); 1563 1564 tlb = devm_kcalloc(&pdev->dev, max_num_prop, sizeof(u32), GFP_KERNEL); 1565 if (!tlb) 1566 return -ENOMEM; 1567 ret = of_property_read_u32_array(dev->of_node, "nvidia,thermtrips", 1568 tlb, n); 1569 if (ret) { 1570 dev_err(dev, "invalid num ele: thermtrips:%d\n", ret); 1571 return ret; 1572 } 1573 1574 i = 0; 1575 for (j = 0; j < n; j = j + 2) { 1576 if (tlb[j] >= TEGRA124_SOCTHERM_SENSOR_NUM) 1577 continue; 1578 1579 tt[i].id = tlb[j]; 1580 tt[i].temp = tlb[j + 1]; 1581 i++; 1582 } 1583 1584 return 0; 1585 } 1586 1587 static void soctherm_oc_cfg_parse(struct device *dev, 1588 struct device_node *np_oc, 1589 struct soctherm_throt_cfg *stc) 1590 { 1591 u32 val; 1592 1593 if (of_property_read_bool(np_oc, "nvidia,polarity-active-low")) 1594 stc->oc_cfg.active_low = 1; 1595 else 1596 stc->oc_cfg.active_low = 0; 1597 1598 if (!of_property_read_u32(np_oc, "nvidia,count-threshold", &val)) { 1599 stc->oc_cfg.intr_en = 1; 1600 stc->oc_cfg.alarm_cnt_thresh = val; 1601 } 1602 1603 if (!of_property_read_u32(np_oc, "nvidia,throttle-period-us", &val)) 1604 stc->oc_cfg.throt_period = val; 1605 1606 if (!of_property_read_u32(np_oc, "nvidia,alarm-filter", &val)) 1607 stc->oc_cfg.alarm_filter = val; 1608 1609 /* BRIEF throttling by default, do not support STICKY */ 1610 stc->oc_cfg.mode = OC_THROTTLE_MODE_BRIEF; 1611 } 1612 1613 static int soctherm_throt_cfg_parse(struct device *dev, 1614 struct device_node *np, 1615 struct soctherm_throt_cfg *stc) 1616 { 1617 struct tegra_soctherm *ts = dev_get_drvdata(dev); 1618 int ret; 1619 u32 val; 1620 1621 ret = of_property_read_u32(np, "nvidia,priority", &val); 1622 if (ret) { 1623 dev_err(dev, "throttle-cfg: %s: invalid priority\n", stc->name); 1624 return -EINVAL; 1625 } 1626 stc->priority = val; 1627 1628 ret = of_property_read_u32(np, ts->soc->use_ccroc ? 1629 "nvidia,cpu-throt-level" : 1630 "nvidia,cpu-throt-percent", &val); 1631 if (!ret) { 1632 if (ts->soc->use_ccroc && 1633 val <= TEGRA_SOCTHERM_THROT_LEVEL_HIGH) 1634 stc->cpu_throt_level = val; 1635 else if (!ts->soc->use_ccroc && val <= 100) 1636 stc->cpu_throt_depth = val; 1637 else 1638 goto err; 1639 } else { 1640 goto err; 1641 } 1642 1643 ret = of_property_read_u32(np, "nvidia,gpu-throt-level", &val); 1644 if (!ret && val <= TEGRA_SOCTHERM_THROT_LEVEL_HIGH) 1645 stc->gpu_throt_level = val; 1646 else 1647 goto err; 1648 1649 return 0; 1650 1651 err: 1652 dev_err(dev, "throttle-cfg: %s: no throt prop or invalid prop\n", 1653 stc->name); 1654 return -EINVAL; 1655 } 1656 1657 /** 1658 * soctherm_init_hw_throt_cdev() - Parse the HW throttle configurations 1659 * and register them as cooling devices. 1660 * @pdev: Pointer to platform_device struct 1661 */ 1662 static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) 1663 { 1664 struct device *dev = &pdev->dev; 1665 struct tegra_soctherm *ts = dev_get_drvdata(dev); 1666 struct device_node *np_stc; 1667 const char *name; 1668 int i; 1669 1670 for (i = 0; i < THROTTLE_SIZE; i++) { 1671 ts->throt_cfgs[i].name = throt_names[i]; 1672 ts->throt_cfgs[i].id = i; 1673 ts->throt_cfgs[i].init = false; 1674 } 1675 1676 np_stc = of_get_child_by_name(dev->of_node, "throttle-cfgs"); 1677 if (!np_stc) { 1678 dev_info(dev, 1679 "throttle-cfg: no throttle-cfgs - not enabling\n"); 1680 return; 1681 } 1682 1683 for_each_child_of_node_scoped(np_stc, np_stcc) { 1684 struct soctherm_throt_cfg *stc; 1685 struct thermal_cooling_device *tcd; 1686 int err; 1687 1688 name = np_stcc->name; 1689 stc = find_throttle_cfg_by_name(ts, name); 1690 if (!stc) { 1691 dev_err(dev, 1692 "throttle-cfg: could not find %s\n", name); 1693 continue; 1694 } 1695 1696 if (stc->init) { 1697 dev_err(dev, "throttle-cfg: %s: redefined!\n", name); 1698 break; 1699 } 1700 1701 err = soctherm_throt_cfg_parse(dev, np_stcc, stc); 1702 if (err) 1703 continue; 1704 1705 if (stc->id >= THROTTLE_OC1) { 1706 soctherm_oc_cfg_parse(dev, np_stcc, stc); 1707 stc->init = true; 1708 } else { 1709 1710 tcd = devm_thermal_of_child_cooling_device_register(dev, np_stcc, 1711 (char *)name, ts, 1712 &throt_cooling_ops); 1713 if (IS_ERR_OR_NULL(tcd)) { 1714 dev_err(dev, 1715 "throttle-cfg: %s: failed to register cooling device\n", 1716 name); 1717 continue; 1718 } 1719 stc->cdev = tcd; 1720 stc->init = true; 1721 } 1722 1723 } 1724 1725 of_node_put(np_stc); 1726 } 1727 1728 /** 1729 * throttlectl_cpu_level_cfg() - programs CCROC NV_THERM level config 1730 * @ts: pointer to a struct tegra_soctherm 1731 * @level: describing the level LOW/MED/HIGH of throttling 1732 * 1733 * It's necessary to set up the CPU-local CCROC NV_THERM instance with 1734 * the M/N values desired for each level. This function does this. 1735 * 1736 * This function pre-programs the CCROC NV_THERM levels in terms of 1737 * pre-configured "Low", "Medium" or "Heavy" throttle levels which are 1738 * mapped to THROT_LEVEL_LOW, THROT_LEVEL_MED and THROT_LEVEL_HVY. 1739 */ 1740 static void throttlectl_cpu_level_cfg(struct tegra_soctherm *ts, int level) 1741 { 1742 u8 depth, dividend; 1743 u32 r; 1744 1745 switch (level) { 1746 case TEGRA_SOCTHERM_THROT_LEVEL_LOW: 1747 depth = 50; 1748 break; 1749 case TEGRA_SOCTHERM_THROT_LEVEL_MED: 1750 depth = 75; 1751 break; 1752 case TEGRA_SOCTHERM_THROT_LEVEL_HIGH: 1753 depth = 80; 1754 break; 1755 case TEGRA_SOCTHERM_THROT_LEVEL_NONE: 1756 return; 1757 default: 1758 return; 1759 } 1760 1761 dividend = THROT_DEPTH_DIVIDEND(depth); 1762 1763 /* setup PSKIP in ccroc nv_therm registers */ 1764 r = ccroc_readl(ts, CCROC_THROT_PSKIP_RAMP_CPU_REG(level)); 1765 r = REG_SET_MASK(r, CCROC_THROT_PSKIP_RAMP_DURATION_MASK, 0xff); 1766 r = REG_SET_MASK(r, CCROC_THROT_PSKIP_RAMP_STEP_MASK, 0xf); 1767 ccroc_writel(ts, r, CCROC_THROT_PSKIP_RAMP_CPU_REG(level)); 1768 1769 r = ccroc_readl(ts, CCROC_THROT_PSKIP_CTRL_CPU_REG(level)); 1770 r = REG_SET_MASK(r, CCROC_THROT_PSKIP_CTRL_ENB_MASK, 1); 1771 r = REG_SET_MASK(r, CCROC_THROT_PSKIP_CTRL_DIVIDEND_MASK, dividend); 1772 r = REG_SET_MASK(r, CCROC_THROT_PSKIP_CTRL_DIVISOR_MASK, 0xff); 1773 ccroc_writel(ts, r, CCROC_THROT_PSKIP_CTRL_CPU_REG(level)); 1774 } 1775 1776 /** 1777 * throttlectl_cpu_level_select() - program CPU pulse skipper config 1778 * @ts: pointer to a struct tegra_soctherm 1779 * @throt: the LIGHT/HEAVY of throttle event id 1780 * 1781 * Pulse skippers are used to throttle clock frequencies. This 1782 * function programs the pulse skippers based on @throt and platform 1783 * data. This function is used on SoCs which have CPU-local pulse 1784 * skipper control, such as T13x. It programs soctherm's interface to 1785 * Denver:CCROC NV_THERM in terms of Low, Medium and HIGH throttling 1786 * vectors. PSKIP_BYPASS mode is set as required per HW spec. 1787 */ 1788 static void throttlectl_cpu_level_select(struct tegra_soctherm *ts, 1789 enum soctherm_throttle_id throt) 1790 { 1791 u32 r, throt_vect; 1792 1793 /* Denver:CCROC NV_THERM interface N:3 Mapping */ 1794 switch (ts->throt_cfgs[throt].cpu_throt_level) { 1795 case TEGRA_SOCTHERM_THROT_LEVEL_LOW: 1796 throt_vect = THROT_VECT_LOW; 1797 break; 1798 case TEGRA_SOCTHERM_THROT_LEVEL_MED: 1799 throt_vect = THROT_VECT_MED; 1800 break; 1801 case TEGRA_SOCTHERM_THROT_LEVEL_HIGH: 1802 throt_vect = THROT_VECT_HIGH; 1803 break; 1804 default: 1805 throt_vect = THROT_VECT_NONE; 1806 break; 1807 } 1808 1809 r = readl(ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_CPU)); 1810 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_ENABLE_MASK, 1); 1811 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_VECT_CPU_MASK, throt_vect); 1812 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_VECT2_CPU_MASK, throt_vect); 1813 writel(r, ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_CPU)); 1814 1815 /* bypass sequencer in soc_therm as it is programmed in ccroc */ 1816 r = REG_SET_MASK(0, THROT_PSKIP_RAMP_SEQ_BYPASS_MODE_MASK, 1); 1817 writel(r, ts->regs + THROT_PSKIP_RAMP(throt, THROTTLE_DEV_CPU)); 1818 } 1819 1820 /** 1821 * throttlectl_cpu_mn() - program CPU pulse skipper configuration 1822 * @ts: pointer to a struct tegra_soctherm 1823 * @throt: the LIGHT/HEAVY of throttle event id 1824 * 1825 * Pulse skippers are used to throttle clock frequencies. This 1826 * function programs the pulse skippers based on @throt and platform 1827 * data. This function is used for CPUs that have "remote" pulse 1828 * skipper control, e.g., the CPU pulse skipper is controlled by the 1829 * SOC_THERM IP block. (SOC_THERM is located outside the CPU 1830 * complex.) 1831 */ 1832 static void throttlectl_cpu_mn(struct tegra_soctherm *ts, 1833 enum soctherm_throttle_id throt) 1834 { 1835 u32 r; 1836 int depth; 1837 u8 dividend; 1838 1839 depth = ts->throt_cfgs[throt].cpu_throt_depth; 1840 dividend = THROT_DEPTH_DIVIDEND(depth); 1841 1842 r = readl(ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_CPU)); 1843 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_ENABLE_MASK, 1); 1844 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_DIVIDEND_MASK, dividend); 1845 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_DIVISOR_MASK, 0xff); 1846 writel(r, ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_CPU)); 1847 1848 r = readl(ts->regs + THROT_PSKIP_RAMP(throt, THROTTLE_DEV_CPU)); 1849 r = REG_SET_MASK(r, THROT_PSKIP_RAMP_DURATION_MASK, 0xff); 1850 r = REG_SET_MASK(r, THROT_PSKIP_RAMP_STEP_MASK, 0xf); 1851 writel(r, ts->regs + THROT_PSKIP_RAMP(throt, THROTTLE_DEV_CPU)); 1852 } 1853 1854 /** 1855 * throttlectl_gpu_level_select() - selects throttling level for GPU 1856 * @ts: pointer to a struct tegra_soctherm 1857 * @throt: the LIGHT/HEAVY of throttle event id 1858 * 1859 * This function programs soctherm's interface to GK20a NV_THERM to select 1860 * pre-configured "Low", "Medium" or "Heavy" throttle levels. 1861 * 1862 * Return: boolean true if HW was programmed 1863 */ 1864 static void throttlectl_gpu_level_select(struct tegra_soctherm *ts, 1865 enum soctherm_throttle_id throt) 1866 { 1867 u32 r, level, throt_vect; 1868 1869 level = ts->throt_cfgs[throt].gpu_throt_level; 1870 throt_vect = THROT_LEVEL_TO_DEPTH(level); 1871 r = readl(ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_GPU)); 1872 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_ENABLE_MASK, 1); 1873 r = REG_SET_MASK(r, THROT_PSKIP_CTRL_VECT_GPU_MASK, throt_vect); 1874 writel(r, ts->regs + THROT_PSKIP_CTRL(throt, THROTTLE_DEV_GPU)); 1875 } 1876 1877 static int soctherm_oc_cfg_program(struct tegra_soctherm *ts, 1878 enum soctherm_throttle_id throt) 1879 { 1880 u32 r; 1881 struct soctherm_oc_cfg *oc = &ts->throt_cfgs[throt].oc_cfg; 1882 1883 if (oc->mode == OC_THROTTLE_MODE_DISABLED) 1884 return -EINVAL; 1885 1886 r = REG_SET_MASK(0, OC1_CFG_HW_RESTORE_MASK, 1); 1887 r = REG_SET_MASK(r, OC1_CFG_THROTTLE_MODE_MASK, oc->mode); 1888 r = REG_SET_MASK(r, OC1_CFG_ALARM_POLARITY_MASK, oc->active_low); 1889 r = REG_SET_MASK(r, OC1_CFG_EN_THROTTLE_MASK, 1); 1890 writel(r, ts->regs + ALARM_CFG(throt)); 1891 writel(oc->throt_period, ts->regs + ALARM_THROTTLE_PERIOD(throt)); 1892 writel(oc->alarm_cnt_thresh, ts->regs + ALARM_CNT_THRESHOLD(throt)); 1893 writel(oc->alarm_filter, ts->regs + ALARM_FILTER(throt)); 1894 soctherm_oc_intr_enable(ts, throt, oc->intr_en); 1895 1896 return 0; 1897 } 1898 1899 /** 1900 * soctherm_throttle_program() - programs pulse skippers' configuration 1901 * @ts: pointer to a struct tegra_soctherm 1902 * @throt: the LIGHT/HEAVY of the throttle event id. 1903 * 1904 * Pulse skippers are used to throttle clock frequencies. 1905 * This function programs the pulse skippers. 1906 */ 1907 static void soctherm_throttle_program(struct tegra_soctherm *ts, 1908 enum soctherm_throttle_id throt) 1909 { 1910 u32 r; 1911 struct soctherm_throt_cfg stc = ts->throt_cfgs[throt]; 1912 1913 if (!stc.init) 1914 return; 1915 1916 if ((throt >= THROTTLE_OC1) && (soctherm_oc_cfg_program(ts, throt))) 1917 return; 1918 1919 /* Setup PSKIP parameters */ 1920 if (ts->soc->use_ccroc) 1921 throttlectl_cpu_level_select(ts, throt); 1922 else 1923 throttlectl_cpu_mn(ts, throt); 1924 1925 throttlectl_gpu_level_select(ts, throt); 1926 1927 r = REG_SET_MASK(0, THROT_PRIORITY_LITE_PRIO_MASK, stc.priority); 1928 writel(r, ts->regs + THROT_PRIORITY_CTRL(throt)); 1929 1930 r = REG_SET_MASK(0, THROT_DELAY_LITE_DELAY_MASK, 0); 1931 writel(r, ts->regs + THROT_DELAY_CTRL(throt)); 1932 1933 r = readl(ts->regs + THROT_PRIORITY_LOCK); 1934 r = REG_GET_MASK(r, THROT_PRIORITY_LOCK_PRIORITY_MASK); 1935 if (r >= stc.priority) 1936 return; 1937 r = REG_SET_MASK(0, THROT_PRIORITY_LOCK_PRIORITY_MASK, 1938 stc.priority); 1939 writel(r, ts->regs + THROT_PRIORITY_LOCK); 1940 } 1941 1942 static void tegra_soctherm_throttle(struct device *dev) 1943 { 1944 struct tegra_soctherm *ts = dev_get_drvdata(dev); 1945 u32 v; 1946 int i; 1947 1948 /* configure LOW, MED and HIGH levels for CCROC NV_THERM */ 1949 if (ts->soc->use_ccroc) { 1950 throttlectl_cpu_level_cfg(ts, TEGRA_SOCTHERM_THROT_LEVEL_LOW); 1951 throttlectl_cpu_level_cfg(ts, TEGRA_SOCTHERM_THROT_LEVEL_MED); 1952 throttlectl_cpu_level_cfg(ts, TEGRA_SOCTHERM_THROT_LEVEL_HIGH); 1953 } 1954 1955 /* Thermal HW throttle programming */ 1956 for (i = 0; i < THROTTLE_SIZE; i++) 1957 soctherm_throttle_program(ts, i); 1958 1959 v = REG_SET_MASK(0, THROT_GLOBAL_ENB_MASK, 1); 1960 if (ts->soc->use_ccroc) { 1961 ccroc_writel(ts, v, CCROC_GLOBAL_CFG); 1962 1963 v = ccroc_readl(ts, CCROC_SUPER_CCLKG_DIVIDER); 1964 v = REG_SET_MASK(v, CDIVG_USE_THERM_CONTROLS_MASK, 1); 1965 ccroc_writel(ts, v, CCROC_SUPER_CCLKG_DIVIDER); 1966 } else { 1967 writel(v, ts->regs + THROT_GLOBAL_CFG); 1968 1969 v = readl(ts->clk_regs + CAR_SUPER_CCLKG_DIVIDER); 1970 v = REG_SET_MASK(v, CDIVG_USE_THERM_CONTROLS_MASK, 1); 1971 writel(v, ts->clk_regs + CAR_SUPER_CCLKG_DIVIDER); 1972 } 1973 1974 /* initialize stats collection */ 1975 v = STATS_CTL_CLR_DN | STATS_CTL_EN_DN | 1976 STATS_CTL_CLR_UP | STATS_CTL_EN_UP; 1977 writel(v, ts->regs + THERMCTL_STATS_CTL); 1978 } 1979 1980 static int soctherm_interrupts_init(struct platform_device *pdev, 1981 struct tegra_soctherm *tegra) 1982 { 1983 int ret; 1984 1985 ret = soctherm_oc_int_init(dev_fwnode(&pdev->dev), TEGRA_SOC_OC_IRQ_MAX); 1986 if (ret < 0) { 1987 dev_err(&pdev->dev, "soctherm_oc_int_init failed\n"); 1988 return ret; 1989 } 1990 1991 tegra->thermal_irq = platform_get_irq(pdev, 0); 1992 if (tegra->thermal_irq < 0) { 1993 dev_dbg(&pdev->dev, "get 'thermal_irq' failed.\n"); 1994 return 0; 1995 } 1996 1997 tegra->edp_irq = platform_get_irq(pdev, 1); 1998 if (tegra->edp_irq < 0) { 1999 dev_dbg(&pdev->dev, "get 'edp_irq' failed.\n"); 2000 return 0; 2001 } 2002 2003 ret = devm_request_threaded_irq(&pdev->dev, 2004 tegra->thermal_irq, 2005 soctherm_thermal_isr, 2006 soctherm_thermal_isr_thread, 2007 IRQF_ONESHOT, 2008 dev_name(&pdev->dev), 2009 tegra); 2010 if (ret < 0) 2011 return ret; 2012 2013 ret = devm_request_threaded_irq(&pdev->dev, 2014 tegra->edp_irq, 2015 soctherm_edp_isr, 2016 soctherm_edp_isr_thread, 2017 IRQF_ONESHOT, 2018 "soctherm_edp", 2019 tegra); 2020 if (ret < 0) 2021 return ret; 2022 2023 return 0; 2024 } 2025 2026 static void soctherm_init(struct platform_device *pdev) 2027 { 2028 struct tegra_soctherm *tegra = platform_get_drvdata(pdev); 2029 const struct tegra_tsensor_group **ttgs = tegra->soc->ttgs; 2030 int i; 2031 u32 pdiv, hotspot; 2032 2033 /* Initialize raw sensors */ 2034 for (i = 0; i < tegra->soc->num_tsensors; ++i) 2035 enable_tsensor(tegra, i); 2036 2037 /* program pdiv and hotspot offsets per THERM */ 2038 pdiv = readl(tegra->regs + SENSOR_PDIV); 2039 hotspot = readl(tegra->regs + SENSOR_HOTSPOT_OFF); 2040 for (i = 0; i < tegra->soc->num_ttgs; ++i) { 2041 pdiv = REG_SET_MASK(pdiv, ttgs[i]->pdiv_mask, 2042 ttgs[i]->pdiv); 2043 /* hotspot offset from PLLX, doesn't need to configure PLLX */ 2044 if (ttgs[i]->id == TEGRA124_SOCTHERM_SENSOR_PLLX) 2045 continue; 2046 hotspot = REG_SET_MASK(hotspot, 2047 ttgs[i]->pllx_hotspot_mask, 2048 ttgs[i]->pllx_hotspot_diff); 2049 } 2050 writel(pdiv, tegra->regs + SENSOR_PDIV); 2051 writel(hotspot, tegra->regs + SENSOR_HOTSPOT_OFF); 2052 2053 /* Configure hw throttle */ 2054 tegra_soctherm_throttle(&pdev->dev); 2055 } 2056 2057 static const struct of_device_id tegra_soctherm_of_match[] = { 2058 #ifdef CONFIG_ARCH_TEGRA_114_SOC 2059 { 2060 .compatible = "nvidia,tegra114-soctherm", 2061 .data = &tegra114_soctherm, 2062 }, 2063 #endif 2064 #ifdef CONFIG_ARCH_TEGRA_124_SOC 2065 { 2066 .compatible = "nvidia,tegra124-soctherm", 2067 .data = &tegra124_soctherm, 2068 }, 2069 #endif 2070 #ifdef CONFIG_ARCH_TEGRA_132_SOC 2071 { 2072 .compatible = "nvidia,tegra132-soctherm", 2073 .data = &tegra132_soctherm, 2074 }, 2075 #endif 2076 #ifdef CONFIG_ARCH_TEGRA_210_SOC 2077 { 2078 .compatible = "nvidia,tegra210-soctherm", 2079 .data = &tegra210_soctherm, 2080 }, 2081 #endif 2082 { }, 2083 }; 2084 MODULE_DEVICE_TABLE(of, tegra_soctherm_of_match); 2085 2086 static int tegra_soctherm_probe(struct platform_device *pdev) 2087 { 2088 const struct of_device_id *match; 2089 struct tegra_soctherm *tegra; 2090 struct thermal_zone_device *z; 2091 struct tsensor_shared_calib shared_calib; 2092 struct tegra_soctherm_soc *soc; 2093 unsigned int i; 2094 int err; 2095 2096 match = of_match_node(tegra_soctherm_of_match, pdev->dev.of_node); 2097 if (!match) 2098 return -ENODEV; 2099 2100 soc = (struct tegra_soctherm_soc *)match->data; 2101 if (soc->num_ttgs > TEGRA124_SOCTHERM_SENSOR_NUM) 2102 return -EINVAL; 2103 2104 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); 2105 if (!tegra) 2106 return -ENOMEM; 2107 2108 mutex_init(&tegra->thermctl_lock); 2109 dev_set_drvdata(&pdev->dev, tegra); 2110 2111 tegra->soc = soc; 2112 2113 tegra->regs = devm_platform_ioremap_resource_byname(pdev, "soctherm-reg"); 2114 if (IS_ERR(tegra->regs)) { 2115 dev_err(&pdev->dev, "can't get soctherm registers"); 2116 return PTR_ERR(tegra->regs); 2117 } 2118 2119 if (!tegra->soc->use_ccroc) { 2120 tegra->clk_regs = devm_platform_ioremap_resource_byname(pdev, "car-reg"); 2121 if (IS_ERR(tegra->clk_regs)) { 2122 dev_err(&pdev->dev, "can't get car clk registers"); 2123 return PTR_ERR(tegra->clk_regs); 2124 } 2125 } else { 2126 tegra->ccroc_regs = devm_platform_ioremap_resource_byname(pdev, "ccroc-reg"); 2127 if (IS_ERR(tegra->ccroc_regs)) { 2128 dev_err(&pdev->dev, "can't get ccroc registers"); 2129 return PTR_ERR(tegra->ccroc_regs); 2130 } 2131 } 2132 2133 tegra->reset = devm_reset_control_get(&pdev->dev, "soctherm"); 2134 if (IS_ERR(tegra->reset)) { 2135 dev_err(&pdev->dev, "can't get soctherm reset\n"); 2136 return PTR_ERR(tegra->reset); 2137 } 2138 2139 tegra->clock_tsensor = devm_clk_get(&pdev->dev, "tsensor"); 2140 if (IS_ERR(tegra->clock_tsensor)) { 2141 dev_err(&pdev->dev, "can't get tsensor clock\n"); 2142 return PTR_ERR(tegra->clock_tsensor); 2143 } 2144 2145 tegra->clock_soctherm = devm_clk_get(&pdev->dev, "soctherm"); 2146 if (IS_ERR(tegra->clock_soctherm)) { 2147 dev_err(&pdev->dev, "can't get soctherm clock\n"); 2148 return PTR_ERR(tegra->clock_soctherm); 2149 } 2150 2151 tegra->calib = devm_kcalloc(&pdev->dev, 2152 soc->num_tsensors, sizeof(u32), 2153 GFP_KERNEL); 2154 if (!tegra->calib) 2155 return -ENOMEM; 2156 2157 /* calculate shared calibration data */ 2158 err = tegra_calc_shared_calib(soc->tfuse, &shared_calib); 2159 if (err) 2160 return err; 2161 2162 /* calculate tsensor calibration data */ 2163 for (i = 0; i < soc->num_tsensors; ++i) { 2164 err = tegra_calc_tsensor_calib(&soc->tsensors[i], 2165 &shared_calib, 2166 &tegra->calib[i]); 2167 if (err) 2168 return err; 2169 } 2170 2171 tegra->thermctl_tzs = devm_kcalloc(&pdev->dev, 2172 soc->num_ttgs, sizeof(z), 2173 GFP_KERNEL); 2174 if (!tegra->thermctl_tzs) 2175 return -ENOMEM; 2176 2177 err = soctherm_clk_enable(pdev, true); 2178 if (err) 2179 return err; 2180 2181 err = devm_add_action_or_reset(&pdev->dev, soctherm_clk_disable, pdev); 2182 if (err) 2183 return err; 2184 2185 soctherm_thermtrips_parse(pdev); 2186 2187 soctherm_init_hw_throt_cdev(pdev); 2188 2189 soctherm_init(pdev); 2190 2191 for (i = 0; i < soc->num_ttgs; ++i) { 2192 struct tegra_thermctl_zone *zone = 2193 devm_kzalloc(&pdev->dev, sizeof(*zone), GFP_KERNEL); 2194 if (!zone) 2195 return -ENOMEM; 2196 2197 zone->reg = tegra->regs + soc->ttgs[i]->sensor_temp_offset; 2198 zone->dev = &pdev->dev; 2199 zone->sg = soc->ttgs[i]; 2200 zone->ts = tegra; 2201 2202 z = devm_thermal_of_zone_register(&pdev->dev, 2203 soc->ttgs[i]->id, zone, 2204 &tegra_of_thermal_ops); 2205 if (IS_ERR(z)) { 2206 err = PTR_ERR(z); 2207 dev_err(&pdev->dev, "failed to register sensor: %d\n", 2208 err); 2209 return err; 2210 } 2211 2212 zone->tz = z; 2213 tegra->thermctl_tzs[soc->ttgs[i]->id] = z; 2214 2215 /* Configure hw trip points */ 2216 err = tegra_soctherm_set_hwtrips(&pdev->dev, soc->ttgs[i], z); 2217 if (err) 2218 return err; 2219 } 2220 2221 err = soctherm_interrupts_init(pdev, tegra); 2222 2223 soctherm_debug_init(pdev); 2224 2225 return 0; 2226 } 2227 2228 static void tegra_soctherm_remove(struct platform_device *pdev) 2229 { 2230 struct tegra_soctherm *tegra = platform_get_drvdata(pdev); 2231 2232 debugfs_remove_recursive(tegra->debugfs_dir); 2233 } 2234 2235 static int __maybe_unused soctherm_suspend(struct device *dev) 2236 { 2237 struct platform_device *pdev = to_platform_device(dev); 2238 2239 soctherm_clk_enable(pdev, false); 2240 2241 return 0; 2242 } 2243 2244 static int __maybe_unused soctherm_resume(struct device *dev) 2245 { 2246 struct platform_device *pdev = to_platform_device(dev); 2247 struct tegra_soctherm *tegra = platform_get_drvdata(pdev); 2248 struct tegra_soctherm_soc *soc = tegra->soc; 2249 int err, i; 2250 2251 err = soctherm_clk_enable(pdev, true); 2252 if (err) { 2253 dev_err(&pdev->dev, 2254 "Resume failed: enable clocks failed\n"); 2255 return err; 2256 } 2257 2258 soctherm_init(pdev); 2259 2260 for (i = 0; i < soc->num_ttgs; ++i) { 2261 struct thermal_zone_device *tz; 2262 2263 tz = tegra->thermctl_tzs[soc->ttgs[i]->id]; 2264 err = tegra_soctherm_set_hwtrips(dev, soc->ttgs[i], tz); 2265 if (err) { 2266 dev_err(&pdev->dev, 2267 "Resume failed: set hwtrips failed\n"); 2268 return err; 2269 } 2270 } 2271 2272 return 0; 2273 } 2274 2275 static SIMPLE_DEV_PM_OPS(tegra_soctherm_pm, soctherm_suspend, soctherm_resume); 2276 2277 static struct platform_driver tegra_soctherm_driver = { 2278 .probe = tegra_soctherm_probe, 2279 .remove = tegra_soctherm_remove, 2280 .driver = { 2281 .name = "tegra_soctherm", 2282 .pm = &tegra_soctherm_pm, 2283 .of_match_table = tegra_soctherm_of_match, 2284 }, 2285 }; 2286 module_platform_driver(tegra_soctherm_driver); 2287 2288 MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>"); 2289 MODULE_DESCRIPTION("NVIDIA Tegra SOCTHERM thermal management driver"); 2290 MODULE_LICENSE("GPL v2"); 2291