Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux

Pull thermal management fixes from Zhang Rui:
"Specifics:

- several fixes and cleanups on Rockchip thermal drivers.

- add the missing support of RK3368 SoCs in Rockchip driver.

- small fixes on of-thermal, power_allocator, rcar driver, IMX, and
QCOM drivers, and also compilation fixes, on thermal.h, when thermal
is not selected"

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux:
imx: thermal: use CPU temperature grade info for thresholds
thermal: fix thermal_zone_bind_cooling_device prototype
Revert "thermal: qcom_spmi: allow compile test"
thermal: rcar_thermal: remove redundant operation
thermal: of-thermal: Reduce log level for message when can't fine thermal zone
thermal: power_allocator: Use temperature reading from tz
thermal: rockchip: Support the RK3368 SoCs in thermal driver
thermal: rockchip: consistently use int for temperatures
thermal: rockchip: Add the sort mode for adc value increment or decrement
thermal: rockchip: improve the conversion function
thermal: rockchip: trivial: fix typo in commit
thermal: rockchip: better to compatible the driver for different SoCs
dt-bindings: rockchip-thermal: Support the RK3368 SoCs compatible

+314 -150
+3 -1
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
··· 1 1 * Temperature Sensor ADC (TSADC) on rockchip SoCs 2 2 3 3 Required properties: 4 - - compatible : "rockchip,rk3288-tsadc" 4 + - compatible : should be "rockchip,<name>-tsadc" 5 + "rockchip,rk3288-tsadc": found on RK3288 SoCs 6 + "rockchip,rk3368-tsadc": found on RK3368 SoCs 5 7 - reg : physical base address of the controller and length of memory mapped 6 8 region. 7 9 - interrupts : The interrupt number to the cpu. The interrupt specifier format
+1 -1
drivers/thermal/Kconfig
··· 382 382 383 383 config QCOM_SPMI_TEMP_ALARM 384 384 tristate "Qualcomm SPMI PMIC Temperature Alarm" 385 - depends on OF && (SPMI || COMPILE_TEST) && IIO 385 + depends on OF && SPMI && IIO 386 386 select REGMAP_SPMI 387 387 help 388 388 This enables a thermal sysfs driver for Qualcomm plug-and-play (QPNP)
+41 -15
drivers/thermal/imx_thermal.c
··· 55 55 #define TEMPSENSE2_PANIC_VALUE_SHIFT 16 56 56 #define TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000 57 57 58 + #define OCOTP_MEM0 0x0480 58 59 #define OCOTP_ANA1 0x04e0 59 60 60 61 /* The driver supports 1 passive trip point and 1 critical trip point */ ··· 64 63 IMX_TRIP_CRITICAL, 65 64 IMX_TRIP_NUM, 66 65 }; 67 - 68 - /* 69 - * It defines the temperature in millicelsius for passive trip point 70 - * that will trigger cooling action when crossed. 71 - */ 72 - #define IMX_TEMP_PASSIVE 85000 73 66 74 67 #define IMX_POLLING_DELAY 2000 /* millisecond */ 75 68 #define IMX_PASSIVE_DELAY 1000 ··· 95 100 u32 c1, c2; /* See formula in imx_get_sensor_data() */ 96 101 int temp_passive; 97 102 int temp_critical; 103 + int temp_max; 98 104 int alarm_temp; 99 105 int last_temp; 100 106 bool irq_enabled; 101 107 int irq; 102 108 struct clk *thermal_clk; 103 109 const struct thermal_soc_data *socdata; 110 + const char *temp_grade; 104 111 }; 105 112 106 113 static void imx_set_panic_temp(struct imx_thermal_data *data, ··· 282 285 { 283 286 struct imx_thermal_data *data = tz->devdata; 284 287 288 + /* do not allow changing critical threshold */ 285 289 if (trip == IMX_TRIP_CRITICAL) 286 290 return -EPERM; 287 291 288 - if (temp < 0 || temp > IMX_TEMP_PASSIVE) 292 + /* do not allow passive to be set higher than critical */ 293 + if (temp < 0 || temp > data->temp_critical) 289 294 return -EINVAL; 290 295 291 296 data->temp_passive = temp; ··· 403 404 data->c1 = temp64; 404 405 data->c2 = n1 * data->c1 + 1000 * t1; 405 406 406 - /* 407 - * Set the default passive cooling trip point, 408 - * can be changed from userspace. 409 - */ 410 - data->temp_passive = IMX_TEMP_PASSIVE; 407 + /* use OTP for thermal grade */ 408 + ret = regmap_read(map, OCOTP_MEM0, &val); 409 + if (ret) { 410 + dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret); 411 + return ret; 412 + } 413 + 414 + /* The maximum die temp is specified by the Temperature Grade */ 415 + switch ((val >> 6) & 0x3) { 416 + case 0: /* Commercial (0 to 95C) */ 417 + data->temp_grade = "Commercial"; 418 + data->temp_max = 95000; 419 + break; 420 + case 1: /* Extended Commercial (-20 to 105C) */ 421 + data->temp_grade = "Extended Commercial"; 422 + data->temp_max = 105000; 423 + break; 424 + case 2: /* Industrial (-40 to 105C) */ 425 + data->temp_grade = "Industrial"; 426 + data->temp_max = 105000; 427 + break; 428 + case 3: /* Automotive (-40 to 125C) */ 429 + data->temp_grade = "Automotive"; 430 + data->temp_max = 125000; 431 + break; 432 + } 411 433 412 434 /* 413 - * The maximum die temperature set to 20 C higher than 414 - * IMX_TEMP_PASSIVE. 435 + * Set the critical trip point at 5C under max 436 + * Set the passive trip point at 10C under max (can change via sysfs) 415 437 */ 416 - data->temp_critical = 1000 * 20 + data->temp_passive; 438 + data->temp_critical = data->temp_max - (1000 * 5); 439 + data->temp_passive = data->temp_max - (1000 * 10); 417 440 418 441 return 0; 419 442 } ··· 571 550 cpufreq_cooling_unregister(data->cdev); 572 551 return ret; 573 552 } 553 + 554 + dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC" 555 + " critical:%dC passive:%dC\n", data->temp_grade, 556 + data->temp_max / 1000, data->temp_critical / 1000, 557 + data->temp_passive / 1000); 574 558 575 559 /* Enable measurements at ~ 10 Hz */ 576 560 regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ);
+1 -1
drivers/thermal/of-thermal.c
··· 964 964 965 965 np = of_find_node_by_name(NULL, "thermal-zones"); 966 966 if (!np) { 967 - pr_err("unable to find thermal zones\n"); 967 + pr_debug("unable to find thermal zones\n"); 968 968 return; 969 969 } 970 970
+7 -17
drivers/thermal/power_allocator.c
··· 174 174 /** 175 175 * pid_controller() - PID controller 176 176 * @tz: thermal zone we are operating in 177 - * @current_temp: the current temperature in millicelsius 178 177 * @control_temp: the target temperature in millicelsius 179 178 * @max_allocatable_power: maximum allocatable power for this thermal zone 180 179 * ··· 190 191 * Return: The power budget for the next period. 191 192 */ 192 193 static u32 pid_controller(struct thermal_zone_device *tz, 193 - int current_temp, 194 194 int control_temp, 195 195 u32 max_allocatable_power) 196 196 { ··· 209 211 true); 210 212 } 211 213 212 - err = control_temp - current_temp; 214 + err = control_temp - tz->temperature; 213 215 err = int_to_frac(err); 214 216 215 217 /* Calculate the proportional term */ ··· 330 332 } 331 333 332 334 static int allocate_power(struct thermal_zone_device *tz, 333 - int current_temp, 334 335 int control_temp) 335 336 { 336 337 struct thermal_instance *instance; ··· 415 418 i++; 416 419 } 417 420 418 - power_range = pid_controller(tz, current_temp, control_temp, 419 - max_allocatable_power); 421 + power_range = pid_controller(tz, control_temp, max_allocatable_power); 420 422 421 423 divvy_up_power(weighted_req_power, max_power, num_actors, 422 424 total_weighted_req_power, power_range, granted_power, ··· 440 444 trace_thermal_power_allocator(tz, req_power, total_req_power, 441 445 granted_power, total_granted_power, 442 446 num_actors, power_range, 443 - max_allocatable_power, current_temp, 444 - control_temp - current_temp); 447 + max_allocatable_power, tz->temperature, 448 + control_temp - tz->temperature); 445 449 446 450 kfree(req_power); 447 451 unlock: ··· 608 612 static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) 609 613 { 610 614 int ret; 611 - int switch_on_temp, control_temp, current_temp; 615 + int switch_on_temp, control_temp; 612 616 struct power_allocator_params *params = tz->governor_data; 613 617 614 618 /* ··· 618 622 if (trip != params->trip_max_desired_temperature) 619 623 return 0; 620 624 621 - ret = thermal_zone_get_temp(tz, &current_temp); 622 - if (ret) { 623 - dev_warn(&tz->device, "Failed to get temperature: %d\n", ret); 624 - return ret; 625 - } 626 - 627 625 ret = tz->ops->get_trip_temp(tz, params->trip_switch_on, 628 626 &switch_on_temp); 629 - if (!ret && (current_temp < switch_on_temp)) { 627 + if (!ret && (tz->temperature < switch_on_temp)) { 630 628 tz->passive = 0; 631 629 reset_pid_controller(params); 632 630 allow_maximum_power(tz); ··· 638 648 return ret; 639 649 } 640 650 641 - return allocate_power(tz, current_temp, control_temp); 651 + return allocate_power(tz, control_temp); 642 652 } 643 653 644 654 static struct thermal_governor thermal_gov_power_allocator = {
+21 -28
drivers/thermal/rcar_thermal.c
··· 361 361 /* 362 362 * platform functions 363 363 */ 364 + static int rcar_thermal_remove(struct platform_device *pdev) 365 + { 366 + struct rcar_thermal_common *common = platform_get_drvdata(pdev); 367 + struct device *dev = &pdev->dev; 368 + struct rcar_thermal_priv *priv; 369 + 370 + rcar_thermal_for_each_priv(priv, common) { 371 + if (rcar_has_irq_support(priv)) 372 + rcar_thermal_irq_disable(priv); 373 + thermal_zone_device_unregister(priv->zone); 374 + } 375 + 376 + pm_runtime_put(dev); 377 + pm_runtime_disable(dev); 378 + 379 + return 0; 380 + } 381 + 364 382 static int rcar_thermal_probe(struct platform_device *pdev) 365 383 { 366 384 struct rcar_thermal_common *common; ··· 394 376 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); 395 377 if (!common) 396 378 return -ENOMEM; 379 + 380 + platform_set_drvdata(pdev, common); 397 381 398 382 INIT_LIST_HEAD(&common->head); 399 383 spin_lock_init(&common->lock); ··· 474 454 rcar_thermal_common_write(common, ENR, enr_bits); 475 455 } 476 456 477 - platform_set_drvdata(pdev, common); 478 - 479 457 dev_info(dev, "%d sensor probed\n", i); 480 458 481 459 return 0; 482 460 483 461 error_unregister: 484 - rcar_thermal_for_each_priv(priv, common) { 485 - if (rcar_has_irq_support(priv)) 486 - rcar_thermal_irq_disable(priv); 487 - thermal_zone_device_unregister(priv->zone); 488 - } 489 - 490 - pm_runtime_put(dev); 491 - pm_runtime_disable(dev); 462 + rcar_thermal_remove(pdev); 492 463 493 464 return ret; 494 - } 495 - 496 - static int rcar_thermal_remove(struct platform_device *pdev) 497 - { 498 - struct rcar_thermal_common *common = platform_get_drvdata(pdev); 499 - struct device *dev = &pdev->dev; 500 - struct rcar_thermal_priv *priv; 501 - 502 - rcar_thermal_for_each_priv(priv, common) { 503 - if (rcar_has_irq_support(priv)) 504 - rcar_thermal_irq_disable(priv); 505 - thermal_zone_device_unregister(priv->zone); 506 - } 507 - 508 - pm_runtime_put(dev); 509 - pm_runtime_disable(dev); 510 - 511 - return 0; 512 465 } 513 466 514 467 static const struct of_device_id rcar_thermal_dt_ids[] = {
+238 -86
drivers/thermal/rockchip_thermal.c
··· 1 1 /* 2 2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd 3 3 * 4 + * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd 5 + * Caesar Wang <wxt@rock-chips.com> 6 + * 4 7 * This program is free software; you can redistribute it and/or modify it 5 8 * under the terms and conditions of the GNU General Public License, 6 9 * version 2, as published by the Free Software Foundation. ··· 48 45 }; 49 46 50 47 /** 51 - * The system has three Temperature Sensors. channel 0 is reserved, 52 - * channel 1 is for CPU, and channel 2 is for GPU. 48 + * The system has two Temperature Sensors. 49 + * sensor0 is for CPU, and sensor1 is for GPU. 53 50 */ 54 51 enum sensor_id { 55 - SENSOR_CPU = 1, 52 + SENSOR_CPU = 0, 56 53 SENSOR_GPU, 57 54 }; 58 55 56 + /** 57 + * The conversion table has the adc value and temperature. 58 + * ADC_DECREMENT is the adc value decremnet.(e.g. v2_code_table) 59 + * ADC_INCREMNET is the adc value incremnet.(e.g. v3_code_table) 60 + */ 61 + enum adc_sort_mode { 62 + ADC_DECREMENT = 0, 63 + ADC_INCREMENT, 64 + }; 65 + 66 + /** 67 + * The max sensors is two in rockchip SoCs. 68 + * Two sensors: CPU and GPU sensor. 69 + */ 70 + #define SOC_MAX_SENSORS 2 71 + 72 + struct chip_tsadc_table { 73 + const struct tsadc_table *id; 74 + 75 + /* the array table size*/ 76 + unsigned int length; 77 + 78 + /* that analogic mask data */ 79 + u32 data_mask; 80 + 81 + /* the sort mode is adc value that increment or decrement in table */ 82 + enum adc_sort_mode mode; 83 + }; 84 + 59 85 struct rockchip_tsadc_chip { 86 + /* The sensor id of chip correspond to the ADC channel */ 87 + int chn_id[SOC_MAX_SENSORS]; 88 + int chn_num; 89 + 60 90 /* The hardware-controlled tshut property */ 61 - long tshut_temp; 91 + int tshut_temp; 62 92 enum tshut_mode tshut_mode; 63 93 enum tshut_polarity tshut_polarity; 64 94 ··· 101 65 void (*control)(void __iomem *reg, bool on); 102 66 103 67 /* Per-sensor methods */ 104 - int (*get_temp)(int chn, void __iomem *reg, int *temp); 105 - void (*set_tshut_temp)(int chn, void __iomem *reg, long temp); 68 + int (*get_temp)(struct chip_tsadc_table table, 69 + int chn, void __iomem *reg, int *temp); 70 + void (*set_tshut_temp)(struct chip_tsadc_table table, 71 + int chn, void __iomem *reg, int temp); 106 72 void (*set_tshut_mode)(int chn, void __iomem *reg, enum tshut_mode m); 73 + 74 + /* Per-table methods */ 75 + struct chip_tsadc_table table; 107 76 }; 108 77 109 78 struct rockchip_thermal_sensor { 110 79 struct rockchip_thermal_data *thermal; 111 80 struct thermal_zone_device *tzd; 112 - enum sensor_id id; 81 + int id; 113 82 }; 114 - 115 - #define NUM_SENSORS 2 /* Ignore unused sensor 0 */ 116 83 117 84 struct rockchip_thermal_data { 118 85 const struct rockchip_tsadc_chip *chip; 119 86 struct platform_device *pdev; 120 87 struct reset_control *reset; 121 88 122 - struct rockchip_thermal_sensor sensors[NUM_SENSORS]; 89 + struct rockchip_thermal_sensor sensors[SOC_MAX_SENSORS]; 123 90 124 91 struct clk *clk; 125 92 struct clk *pclk; 126 93 127 94 void __iomem *regs; 128 95 129 - long tshut_temp; 96 + int tshut_temp; 130 97 enum tshut_mode tshut_mode; 131 98 enum tshut_polarity tshut_polarity; 132 99 }; 133 100 134 - /* TSADC V2 Sensor info define: */ 101 + /* TSADC Sensor info define: */ 135 102 #define TSADCV2_AUTO_CON 0x04 136 103 #define TSADCV2_INT_EN 0x08 137 104 #define TSADCV2_INT_PD 0x0c ··· 156 117 #define TSADCV2_INT_PD_CLEAR_MASK ~BIT(8) 157 118 158 119 #define TSADCV2_DATA_MASK 0xfff 120 + #define TSADCV3_DATA_MASK 0x3ff 121 + 159 122 #define TSADCV2_HIGHT_INT_DEBOUNCE_COUNT 4 160 123 #define TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT 4 161 124 #define TSADCV2_AUTO_PERIOD_TIME 250 /* msec */ ··· 165 124 166 125 struct tsadc_table { 167 126 u32 code; 168 - long temp; 127 + int temp; 169 128 }; 170 129 171 130 static const struct tsadc_table v2_code_table[] = { ··· 206 165 {3421, 125000}, 207 166 }; 208 167 209 - static u32 rk_tsadcv2_temp_to_code(long temp) 168 + static const struct tsadc_table v3_code_table[] = { 169 + {0, -40000}, 170 + {106, -40000}, 171 + {108, -35000}, 172 + {110, -30000}, 173 + {112, -25000}, 174 + {114, -20000}, 175 + {116, -15000}, 176 + {118, -10000}, 177 + {120, -5000}, 178 + {122, 0}, 179 + {124, 5000}, 180 + {126, 10000}, 181 + {128, 15000}, 182 + {130, 20000}, 183 + {132, 25000}, 184 + {134, 30000}, 185 + {136, 35000}, 186 + {138, 40000}, 187 + {140, 45000}, 188 + {142, 50000}, 189 + {144, 55000}, 190 + {146, 60000}, 191 + {148, 65000}, 192 + {150, 70000}, 193 + {152, 75000}, 194 + {154, 80000}, 195 + {156, 85000}, 196 + {158, 90000}, 197 + {160, 95000}, 198 + {162, 100000}, 199 + {163, 105000}, 200 + {165, 110000}, 201 + {167, 115000}, 202 + {169, 120000}, 203 + {171, 125000}, 204 + {TSADCV3_DATA_MASK, 125000}, 205 + }; 206 + 207 + static u32 rk_tsadcv2_temp_to_code(struct chip_tsadc_table table, 208 + int temp) 210 209 { 211 210 int high, low, mid; 212 211 213 212 low = 0; 214 - high = ARRAY_SIZE(v2_code_table) - 1; 213 + high = table.length - 1; 215 214 mid = (high + low) / 2; 216 215 217 - if (temp < v2_code_table[low].temp || temp > v2_code_table[high].temp) 216 + if (temp < table.id[low].temp || temp > table.id[high].temp) 218 217 return 0; 219 218 220 219 while (low <= high) { 221 - if (temp == v2_code_table[mid].temp) 222 - return v2_code_table[mid].code; 223 - else if (temp < v2_code_table[mid].temp) 220 + if (temp == table.id[mid].temp) 221 + return table.id[mid].code; 222 + else if (temp < table.id[mid].temp) 224 223 high = mid - 1; 225 224 else 226 225 low = mid + 1; ··· 270 189 return 0; 271 190 } 272 191 273 - static int rk_tsadcv2_code_to_temp(u32 code, int *temp) 192 + static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code, 193 + int *temp) 274 194 { 275 195 unsigned int low = 1; 276 - unsigned int high = ARRAY_SIZE(v2_code_table) - 1; 196 + unsigned int high = table.length - 1; 277 197 unsigned int mid = (low + high) / 2; 278 198 unsigned int num; 279 199 unsigned long denom; 280 200 281 - BUILD_BUG_ON(ARRAY_SIZE(v2_code_table) < 2); 201 + WARN_ON(table.length < 2); 282 202 283 - code &= TSADCV2_DATA_MASK; 284 - if (code < v2_code_table[high].code) 285 - return -EAGAIN; /* Incorrect reading */ 203 + switch (table.mode) { 204 + case ADC_DECREMENT: 205 + code &= table.data_mask; 206 + if (code < table.id[high].code) 207 + return -EAGAIN; /* Incorrect reading */ 286 208 287 - while (low <= high) { 288 - if (code >= v2_code_table[mid].code && 289 - code < v2_code_table[mid - 1].code) 290 - break; 291 - else if (code < v2_code_table[mid].code) 292 - low = mid + 1; 293 - else 294 - high = mid - 1; 295 - mid = (low + high) / 2; 209 + while (low <= high) { 210 + if (code >= table.id[mid].code && 211 + code < table.id[mid - 1].code) 212 + break; 213 + else if (code < table.id[mid].code) 214 + low = mid + 1; 215 + else 216 + high = mid - 1; 217 + 218 + mid = (low + high) / 2; 219 + } 220 + break; 221 + case ADC_INCREMENT: 222 + code &= table.data_mask; 223 + if (code < table.id[low].code) 224 + return -EAGAIN; /* Incorrect reading */ 225 + 226 + while (low <= high) { 227 + if (code >= table.id[mid - 1].code && 228 + code < table.id[mid].code) 229 + break; 230 + else if (code > table.id[mid].code) 231 + low = mid + 1; 232 + else 233 + high = mid - 1; 234 + 235 + mid = (low + high) / 2; 236 + } 237 + break; 238 + default: 239 + pr_err("Invalid the conversion table\n"); 296 240 } 297 241 298 242 /* ··· 326 220 * temperature between 2 table entries is linear and interpolate 327 221 * to produce less granular result. 328 222 */ 329 - num = v2_code_table[mid].temp - v2_code_table[mid - 1].temp; 330 - num *= v2_code_table[mid - 1].code - code; 331 - denom = v2_code_table[mid - 1].code - v2_code_table[mid].code; 332 - *temp = v2_code_table[mid - 1].temp + (num / denom); 223 + num = table.id[mid].temp - v2_code_table[mid - 1].temp; 224 + num *= abs(table.id[mid - 1].code - code); 225 + denom = abs(table.id[mid - 1].code - table.id[mid].code); 226 + *temp = table.id[mid - 1].temp + (num / denom); 333 227 334 228 return 0; 335 229 } 336 230 337 231 /** 338 - * rk_tsadcv2_initialize - initialize TASDC Controller 339 - * (1) Set TSADCV2_AUTO_PERIOD, configure the interleave between 340 - * every two accessing of TSADC in normal operation. 341 - * (2) Set TSADCV2_AUTO_PERIOD_HT, configure the interleave between 342 - * every two accessing of TSADC after the temperature is higher 343 - * than COM_SHUT or COM_INT. 344 - * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE, 345 - * if the temperature is higher than COMP_INT or COMP_SHUT for 346 - * "debounce" times, TSADC controller will generate interrupt or TSHUT. 232 + * rk_tsadcv2_initialize - initialize TASDC Controller. 233 + * 234 + * (1) Set TSADC_V2_AUTO_PERIOD: 235 + * Configure the interleave between every two accessing of 236 + * TSADC in normal operation. 237 + * 238 + * (2) Set TSADCV2_AUTO_PERIOD_HT: 239 + * Configure the interleave between every two accessing of 240 + * TSADC after the temperature is higher than COM_SHUT or COM_INT. 241 + * 242 + * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE: 243 + * If the temperature is higher than COMP_INT or COMP_SHUT for 244 + * "debounce" times, TSADC controller will generate interrupt or TSHUT. 347 245 */ 348 246 static void rk_tsadcv2_initialize(void __iomem *regs, 349 247 enum tshut_polarity tshut_polarity) ··· 389 279 writel_relaxed(val, regs + TSADCV2_AUTO_CON); 390 280 } 391 281 392 - static int rk_tsadcv2_get_temp(int chn, void __iomem *regs, int *temp) 282 + static int rk_tsadcv2_get_temp(struct chip_tsadc_table table, 283 + int chn, void __iomem *regs, int *temp) 393 284 { 394 285 u32 val; 395 286 396 287 val = readl_relaxed(regs + TSADCV2_DATA(chn)); 397 288 398 - return rk_tsadcv2_code_to_temp(val, temp); 289 + return rk_tsadcv2_code_to_temp(table, val, temp); 399 290 } 400 291 401 - static void rk_tsadcv2_tshut_temp(int chn, void __iomem *regs, long temp) 292 + static void rk_tsadcv2_tshut_temp(struct chip_tsadc_table table, 293 + int chn, void __iomem *regs, int temp) 402 294 { 403 295 u32 tshut_value, val; 404 296 405 - tshut_value = rk_tsadcv2_temp_to_code(temp); 297 + tshut_value = rk_tsadcv2_temp_to_code(table, temp); 406 298 writel_relaxed(tshut_value, regs + TSADCV2_COMP_SHUT(chn)); 407 299 408 300 /* TSHUT will be valid */ ··· 430 318 } 431 319 432 320 static const struct rockchip_tsadc_chip rk3288_tsadc_data = { 321 + .chn_id[SENSOR_CPU] = 1, /* cpu sensor is channel 1 */ 322 + .chn_id[SENSOR_GPU] = 2, /* gpu sensor is channel 2 */ 323 + .chn_num = 2, /* two channels for tsadc */ 324 + 433 325 .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */ 434 326 .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */ 435 327 .tshut_temp = 95000, ··· 444 328 .get_temp = rk_tsadcv2_get_temp, 445 329 .set_tshut_temp = rk_tsadcv2_tshut_temp, 446 330 .set_tshut_mode = rk_tsadcv2_tshut_mode, 331 + 332 + .table = { 333 + .id = v2_code_table, 334 + .length = ARRAY_SIZE(v2_code_table), 335 + .data_mask = TSADCV2_DATA_MASK, 336 + .mode = ADC_DECREMENT, 337 + }, 338 + }; 339 + 340 + static const struct rockchip_tsadc_chip rk3368_tsadc_data = { 341 + .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */ 342 + .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */ 343 + .chn_num = 2, /* two channels for tsadc */ 344 + 345 + .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */ 346 + .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */ 347 + .tshut_temp = 95000, 348 + 349 + .initialize = rk_tsadcv2_initialize, 350 + .irq_ack = rk_tsadcv2_irq_ack, 351 + .control = rk_tsadcv2_control, 352 + .get_temp = rk_tsadcv2_get_temp, 353 + .set_tshut_temp = rk_tsadcv2_tshut_temp, 354 + .set_tshut_mode = rk_tsadcv2_tshut_mode, 355 + 356 + .table = { 357 + .id = v3_code_table, 358 + .length = ARRAY_SIZE(v3_code_table), 359 + .data_mask = TSADCV3_DATA_MASK, 360 + .mode = ADC_INCREMENT, 361 + }, 447 362 }; 448 363 449 364 static const struct of_device_id of_rockchip_thermal_match[] = { 450 365 { 451 366 .compatible = "rockchip,rk3288-tsadc", 452 367 .data = (void *)&rk3288_tsadc_data, 368 + }, 369 + { 370 + .compatible = "rockchip,rk3368-tsadc", 371 + .data = (void *)&rk3368_tsadc_data, 453 372 }, 454 373 { /* end */ }, 455 374 }; ··· 508 357 509 358 thermal->chip->irq_ack(thermal->regs); 510 359 511 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) 360 + for (i = 0; i < thermal->chip->chn_num; i++) 512 361 thermal_zone_device_update(thermal->sensors[i].tzd); 513 362 514 363 return IRQ_HANDLED; ··· 521 370 const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip; 522 371 int retval; 523 372 524 - retval = tsadc->get_temp(sensor->id, thermal->regs, out_temp); 373 + retval = tsadc->get_temp(tsadc->table, 374 + sensor->id, thermal->regs, out_temp); 525 375 dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n", 526 376 sensor->id, *out_temp, retval); 527 377 ··· 541 389 542 390 if (of_property_read_u32(np, "rockchip,hw-tshut-temp", &shut_temp)) { 543 391 dev_warn(dev, 544 - "Missing tshut temp property, using default %ld\n", 392 + "Missing tshut temp property, using default %d\n", 545 393 thermal->chip->tshut_temp); 546 394 thermal->tshut_temp = thermal->chip->tshut_temp; 547 395 } else { ··· 549 397 } 550 398 551 399 if (thermal->tshut_temp > INT_MAX) { 552 - dev_err(dev, "Invalid tshut temperature specified: %ld\n", 400 + dev_err(dev, "Invalid tshut temperature specified: %d\n", 553 401 thermal->tshut_temp); 554 402 return -ERANGE; 555 403 } ··· 594 442 rockchip_thermal_register_sensor(struct platform_device *pdev, 595 443 struct rockchip_thermal_data *thermal, 596 444 struct rockchip_thermal_sensor *sensor, 597 - enum sensor_id id) 445 + int id) 598 446 { 599 447 const struct rockchip_tsadc_chip *tsadc = thermal->chip; 600 448 int error; 601 449 602 450 tsadc->set_tshut_mode(id, thermal->regs, thermal->tshut_mode); 603 - tsadc->set_tshut_temp(id, thermal->regs, thermal->tshut_temp); 451 + tsadc->set_tshut_temp(tsadc->table, id, thermal->regs, 452 + thermal->tshut_temp); 604 453 605 454 sensor->thermal = thermal; 606 455 sensor->id = id; ··· 634 481 const struct of_device_id *match; 635 482 struct resource *res; 636 483 int irq; 637 - int i; 484 + int i, j; 638 485 int error; 639 486 640 487 match = of_match_node(of_rockchip_thermal_match, np); ··· 709 556 710 557 thermal->chip->initialize(thermal->regs, thermal->tshut_polarity); 711 558 712 - error = rockchip_thermal_register_sensor(pdev, thermal, 713 - &thermal->sensors[0], 714 - SENSOR_CPU); 715 - if (error) { 716 - dev_err(&pdev->dev, 717 - "failed to register CPU thermal sensor: %d\n", error); 718 - goto err_disable_pclk; 719 - } 720 - 721 - error = rockchip_thermal_register_sensor(pdev, thermal, 722 - &thermal->sensors[1], 723 - SENSOR_GPU); 724 - if (error) { 725 - dev_err(&pdev->dev, 726 - "failed to register GPU thermal sensor: %d\n", error); 727 - goto err_unregister_cpu_sensor; 559 + for (i = 0; i < thermal->chip->chn_num; i++) { 560 + error = rockchip_thermal_register_sensor(pdev, thermal, 561 + &thermal->sensors[i], 562 + thermal->chip->chn_id[i]); 563 + if (error) { 564 + dev_err(&pdev->dev, 565 + "failed to register sensor[%d] : error = %d\n", 566 + i, error); 567 + for (j = 0; j < i; j++) 568 + thermal_zone_of_sensor_unregister(&pdev->dev, 569 + thermal->sensors[j].tzd); 570 + goto err_disable_pclk; 571 + } 728 572 } 729 573 730 574 error = devm_request_threaded_irq(&pdev->dev, irq, NULL, ··· 731 581 if (error) { 732 582 dev_err(&pdev->dev, 733 583 "failed to request tsadc irq: %d\n", error); 734 - goto err_unregister_gpu_sensor; 584 + goto err_unregister_sensor; 735 585 } 736 586 737 587 thermal->chip->control(thermal->regs, true); 738 588 739 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) 589 + for (i = 0; i < thermal->chip->chn_num; i++) 740 590 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); 741 591 742 592 platform_set_drvdata(pdev, thermal); 743 593 744 594 return 0; 745 595 746 - err_unregister_gpu_sensor: 747 - thermal_zone_of_sensor_unregister(&pdev->dev, thermal->sensors[1].tzd); 748 - err_unregister_cpu_sensor: 749 - thermal_zone_of_sensor_unregister(&pdev->dev, thermal->sensors[0].tzd); 596 + err_unregister_sensor: 597 + while (i--) 598 + thermal_zone_of_sensor_unregister(&pdev->dev, 599 + thermal->sensors[i].tzd); 600 + 750 601 err_disable_pclk: 751 602 clk_disable_unprepare(thermal->pclk); 752 603 err_disable_clk: ··· 761 610 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev); 762 611 int i; 763 612 764 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) { 613 + for (i = 0; i < thermal->chip->chn_num; i++) { 765 614 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i]; 766 615 767 616 rockchip_thermal_toggle_sensor(sensor, false); ··· 782 631 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev); 783 632 int i; 784 633 785 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) 634 + for (i = 0; i < thermal->chip->chn_num; i++) 786 635 rockchip_thermal_toggle_sensor(&thermal->sensors[i], false); 787 636 788 637 thermal->chip->control(thermal->regs, false); ··· 814 663 815 664 thermal->chip->initialize(thermal->regs, thermal->tshut_polarity); 816 665 817 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) { 818 - enum sensor_id id = thermal->sensors[i].id; 666 + for (i = 0; i < thermal->chip->chn_num; i++) { 667 + int id = thermal->sensors[i].id; 819 668 820 669 thermal->chip->set_tshut_mode(id, thermal->regs, 821 670 thermal->tshut_mode); 822 - thermal->chip->set_tshut_temp(id, thermal->regs, 671 + thermal->chip->set_tshut_temp(thermal->chip->table, 672 + id, thermal->regs, 823 673 thermal->tshut_temp); 824 674 } 825 675 826 676 thermal->chip->control(thermal->regs, true); 827 677 828 - for (i = 0; i < ARRAY_SIZE(thermal->sensors); i++) 678 + for (i = 0; i < thermal->chip->chn_num; i++) 829 679 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); 830 680 831 681 pinctrl_pm_select_default_state(dev);
+2 -1
include/linux/thermal.h
··· 438 438 static inline int thermal_zone_bind_cooling_device( 439 439 struct thermal_zone_device *tz, int trip, 440 440 struct thermal_cooling_device *cdev, 441 - unsigned long upper, unsigned long lower) 441 + unsigned long upper, unsigned long lower, 442 + unsigned int weight) 442 443 { return -ENODEV; } 443 444 static inline int thermal_zone_unbind_cooling_device( 444 445 struct thermal_zone_device *tz, int trip,