24 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
45 #define EXYNOS_TMU_REG_TRIMINFO 0x0
46 #define EXYNOS_TMU_REG_CONTROL 0x20
47 #define EXYNOS_TMU_REG_STATUS 0x28
48 #define EXYNOS_TMU_REG_CURRENT_TEMP 0x40
49 #define EXYNOS_TMU_REG_INTEN 0x70
50 #define EXYNOS_TMU_REG_INTSTAT 0x74
51 #define EXYNOS_TMU_REG_INTCLEAR 0x78
53 #define EXYNOS_TMU_TRIM_TEMP_MASK 0xff
54 #define EXYNOS_TMU_GAIN_SHIFT 8
55 #define EXYNOS_TMU_REF_VOLTAGE_SHIFT 24
56 #define EXYNOS_TMU_CORE_ON 3
57 #define EXYNOS_TMU_CORE_OFF 2
58 #define EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET 50
61 #define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44
62 #define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50
63 #define EXYNOS4210_TMU_REG_TRIG_LEVEL1 0x54
64 #define EXYNOS4210_TMU_REG_TRIG_LEVEL2 0x58
65 #define EXYNOS4210_TMU_REG_TRIG_LEVEL3 0x5C
66 #define EXYNOS4210_TMU_REG_PAST_TEMP0 0x60
67 #define EXYNOS4210_TMU_REG_PAST_TEMP1 0x64
68 #define EXYNOS4210_TMU_REG_PAST_TEMP2 0x68
69 #define EXYNOS4210_TMU_REG_PAST_TEMP3 0x6C
71 #define EXYNOS4210_TMU_TRIG_LEVEL0_MASK 0x1
72 #define EXYNOS4210_TMU_TRIG_LEVEL1_MASK 0x10
73 #define EXYNOS4210_TMU_TRIG_LEVEL2_MASK 0x100
74 #define EXYNOS4210_TMU_TRIG_LEVEL3_MASK 0x1000
75 #define EXYNOS4210_TMU_INTCLEAR_VAL 0x1111
78 #define EXYNOS_TMU_TRIMINFO_CON 0x14
79 #define EXYNOS_THD_TEMP_RISE 0x50
80 #define EXYNOS_THD_TEMP_FALL 0x54
81 #define EXYNOS_EMUL_CON 0x80
83 #define EXYNOS_TRIMINFO_RELOAD 0x1
84 #define EXYNOS_TMU_CLEAR_RISE_INT 0x111
85 #define EXYNOS_TMU_CLEAR_FALL_INT (0x111 << 16)
86 #define EXYNOS_MUX_ADDR_VALUE 6
87 #define EXYNOS_MUX_ADDR_SHIFT 20
88 #define EXYNOS_TMU_TRIP_MODE_SHIFT 13
90 #define EFUSE_MIN_VALUE 40
91 #define EFUSE_MAX_VALUE 100
94 #define SENSOR_NAME_LEN 16
95 #define MAX_TRIP_COUNT 8
96 #define MAX_COOLING_DEVICE 4
98 #define ACTIVE_INTERVAL 500
99 #define IDLE_INTERVAL 10000
100 #define MCELSIUS 1000
105 #define MONITOR_ZONE 2
108 #define GET_ZONE(trip) (trip + 2)
109 #define GET_TRIP(zone) (zone - 2)
111 #define EXYNOS_ZONE_COUNT 3
154 static void exynos_unregister_thermal(
void);
162 *mode = th_zone->
mode;
171 pr_notice(
"thermal zone not registered\n");
186 pr_info(
"thermal polling set for duration=%d msec\n",
217 *temp = th_zone->
sensor_conf->trip_data.trip_val[trip];
234 static int exynos_get_frequency_level(
unsigned int cpu,
unsigned int freq)
238 #ifdef CONFIG_CPU_FREQ
258 int ret = 0,
i, tab_size,
level;
265 if (tab_ptr ==
NULL || tab_size == 0)
278 for (i = 0; i < tab_size; i++) {
280 level = exynos_get_frequency_level(0, clip_data->
freq_clip_max);
288 pr_err(
"error binding cdev inst %d\n", i);
291 th_zone->
bind =
true;
305 int ret = 0,
i, tab_size;
308 if (th_zone->
bind ==
false)
326 for (i = 0; i < tab_size; i++) {
332 pr_err(
"error unbinding cdev inst=%d\n", i);
335 th_zone->
bind =
false;
351 pr_info(
"Temperature sensor not initialised\n");
355 *temp = th_zone->
sensor_conf->read_temperature(data);
375 .unbind = exynos_unbind,
376 .get_temp = exynos_get_temp,
377 .get_trend = exynos_get_trend,
378 .get_mode = exynos_get_mode,
379 .set_mode = exynos_set_mode,
380 .get_trip_type = exynos_get_trip_type,
381 .get_trip_temp = exynos_get_trip_temp,
382 .get_crit_temp = exynos_get_crit_temp,
389 static void exynos_report_trigger(
void)
397 if (th_zone->
bind ==
false) {
410 for (i = 0; i < th_zone->
sensor_conf->trip_data.trip_count; i++) {
411 if (th_zone->
therm_dev->last_temperature <
423 snprintf(data,
sizeof(data),
"%u", i);
435 pr_err(
"Temperature sensor not initialised\n");
444 cpumask_set_cpu(0, &mask_val);
447 pr_err(
"Failed to register cpufreq cooling device\n");
458 pr_err(
"Failed to register thermal zone device\n");
464 pr_info(
"Exynos: Kernel Thermal management registered\n");
469 exynos_unregister_thermal();
474 static void exynos_unregister_thermal(
void)
490 pr_info(
"Exynos: Kernel Thermal management unregistered\n");
504 if (temp < 25 || temp > 125) {
511 temp_code = (temp - 25) *
537 if (temp_code < 75 || temp_code > 175) {
544 temp = (temp_code - data->
temp_error1) * (85 - 25) /
562 unsigned int status, trim_info, rising_threshold;
563 int ret = 0, threshold_code;
581 data->
temp_error2 = ((trim_info >> 8) & EXYNOS_TMU_TRIM_TEMP_MASK);
590 threshold_code = temp_to_code(data, pdata->
threshold);
591 if (threshold_code < 0) {
592 ret = threshold_code;
612 if (threshold_code < 0) {
613 ret = threshold_code;
616 rising_threshold = threshold_code;
618 if (threshold_code < 0) {
619 ret = threshold_code;
622 rising_threshold |= (threshold_code << 8);
624 if (threshold_code < 0) {
625 ret = threshold_code;
628 rising_threshold |= (threshold_code << 16);
648 unsigned int con, interrupt_en;
687 temp = code_to_temp(data, temp_code);
713 exynos_report_trigger();
727 .name =
"exynos-therm",
728 .read_temperature = (
int (*)(
void *))exynos_tmu_read,
731 #if defined(CONFIG_CPU_EXYNOS4210)
734 .trigger_levels[0] = 5,
735 .trigger_levels[1] = 20,
736 .trigger_levels[2] = 30,
737 .trigger_level0_en = 1,
738 .trigger_level1_en = 1,
739 .trigger_level2_en = 1,
740 .trigger_level3_en = 0,
742 .reference_voltage = 7,
745 .freq_clip_max = 800 * 1000,
749 .freq_clip_max = 200 * 1000,
755 #define EXYNOS4210_TMU_DRV_DATA (&exynos4210_default_tmu_data)
757 #define EXYNOS4210_TMU_DRV_DATA (NULL)
760 #if defined(CONFIG_SOC_EXYNOS5250) || defined(CONFIG_SOC_EXYNOS4412)
762 .trigger_levels[0] = 85,
763 .trigger_levels[1] = 103,
764 .trigger_levels[2] = 110,
765 .trigger_level0_en = 1,
766 .trigger_level1_en = 1,
767 .trigger_level2_en = 1,
768 .trigger_level3_en = 0,
770 .reference_voltage = 16,
771 .noise_cancel_mode = 4,
775 .freq_clip_max = 800 * 1000,
779 .freq_clip_max = 200 * 1000,
785 #define EXYNOS_TMU_DRV_DATA (&exynos_default_tmu_data)
787 #define EXYNOS_TMU_DRV_DATA (NULL)
793 .compatible =
"samsung,exynos4210-tmu",
797 .compatible =
"samsung,exynos5250-tmu",
804 #define exynos_tmu_match NULL
809 .name =
"exynos4210-tmu",
813 .name =
"exynos5250-tmu",
824 if (pdev->
dev.of_node) {
842 pdata = exynos_get_driver_data(pdev);
845 dev_err(&pdev->
dev,
"No platform init data supplied.\n");
851 dev_err(&pdev->
dev,
"Failed to allocate driver structure\n");
857 dev_err(&pdev->
dev,
"Failed to get platform irq\n");
865 dev_err(&pdev->
dev,
"Failed to get platform resource\n");
871 dev_err(&pdev->
dev,
"Failed to ioremap memory\n");
875 ret = devm_request_irq(&pdev->
dev, data->
irq, exynos_tmu_irq,
878 dev_err(&pdev->
dev,
"Failed to request irq: %d\n", data->
irq);
883 if (IS_ERR(data->
clk)) {
885 return PTR_ERR(data->
clk);
893 dev_err(&pdev->
dev,
"Platform not supported\n");
898 platform_set_drvdata(pdev, data);
901 ret = exynos_tmu_initialize(pdev);
903 dev_err(&pdev->
dev,
"Failed to initialize TMU\n");
907 exynos_tmu_control(pdev,
true);
915 for (i = 0; i < exynos_sensor_conf.
trip_data.trip_count; i++)
916 exynos_sensor_conf.
trip_data.trip_val[i] =
928 ret = exynos_register_thermal(&exynos_sensor_conf);
930 dev_err(&pdev->
dev,
"Failed to register thermal interface\n");
935 platform_set_drvdata(pdev,
NULL);
944 exynos_tmu_control(pdev,
false);
946 exynos_unregister_thermal();
950 platform_set_drvdata(pdev,
NULL);
955 #ifdef CONFIG_PM_SLEEP
956 static int exynos_tmu_suspend(
struct device *
dev)
963 static int exynos_tmu_resume(
struct device *dev)
967 exynos_tmu_initialize(pdev);
968 exynos_tmu_control(pdev,
true);
974 exynos_tmu_suspend, exynos_tmu_resume);
975 #define EXYNOS_TMU_PM (&exynos_tmu_pm)
977 #define EXYNOS_TMU_PM NULL
982 .name =
"exynos-tmu",
987 .probe = exynos_tmu_probe,
989 .id_table = exynos_tmu_driver_ids,