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