2 * exynos_thermal.c - Samsung EXYNOS TMU (Thermal Management Unit)
4 * Copyright (C) 2011 Samsung Electronics
5 * Donggeun Kim <dg77.kim@samsung.com>
6 * Amit Daniel Kachhap <amit.kachhap@linaro.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/err.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/platform_device.h>
29 #include <linux/interrupt.h>
30 #include <linux/clk.h>
31 #include <linux/workqueue.h>
32 #include <linux/sysfs.h>
33 #include <linux/kobject.h>
35 #include <linux/mutex.h>
36 #include <linux/platform_data/exynos_thermal.h>
37 #include <linux/thermal.h>
38 #include <linux/cpufreq.h>
39 #include <linux/cpu_cooling.h>
44 /* Exynos generic registers */
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
60 /* Exynos4210 specific registers */
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
77 /* Exynos5250 and Exynos4412 specific registers */
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
93 /* In-kernel thermal framework related macros & definations */
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
102 /* CPU Zone information */
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
113 struct exynos_tmu_data
{
114 struct exynos_tmu_platform_data
*pdata
;
115 struct resource
*mem
;
119 struct work_struct irq_work
;
122 u8 temp_error1
, temp_error2
;
125 struct thermal_trip_point_conf
{
126 int trip_val
[MAX_TRIP_COUNT
];
130 struct thermal_cooling_conf
{
131 struct freq_clip_table freq_data
[MAX_TRIP_COUNT
];
135 struct thermal_sensor_conf
{
136 char name
[SENSOR_NAME_LEN
];
137 int (*read_temperature
)(void *data
);
138 struct thermal_trip_point_conf trip_data
;
139 struct thermal_cooling_conf cooling_data
;
143 struct exynos_thermal_zone
{
144 enum thermal_device_mode mode
;
145 struct thermal_zone_device
*therm_dev
;
146 struct thermal_cooling_device
*cool_dev
[MAX_COOLING_DEVICE
];
147 unsigned int cool_dev_size
;
148 struct platform_device
*exynos4_dev
;
149 struct thermal_sensor_conf
*sensor_conf
;
153 static struct exynos_thermal_zone
*th_zone
;
154 static void exynos_unregister_thermal(void);
155 static int exynos_register_thermal(struct thermal_sensor_conf
*sensor_conf
);
157 /* Get mode callback functions for thermal zone */
158 static int exynos_get_mode(struct thermal_zone_device
*thermal
,
159 enum thermal_device_mode
*mode
)
162 *mode
= th_zone
->mode
;
166 /* Set mode callback functions for thermal zone */
167 static int exynos_set_mode(struct thermal_zone_device
*thermal
,
168 enum thermal_device_mode mode
)
170 if (!th_zone
->therm_dev
) {
171 pr_notice("thermal zone not registered\n");
175 mutex_lock(&th_zone
->therm_dev
->lock
);
177 if (mode
== THERMAL_DEVICE_ENABLED
)
178 th_zone
->therm_dev
->polling_delay
= IDLE_INTERVAL
;
180 th_zone
->therm_dev
->polling_delay
= 0;
182 mutex_unlock(&th_zone
->therm_dev
->lock
);
184 th_zone
->mode
= mode
;
185 thermal_zone_device_update(th_zone
->therm_dev
);
186 pr_info("thermal polling set for duration=%d msec\n",
187 th_zone
->therm_dev
->polling_delay
);
192 /* Get trip type callback functions for thermal zone */
193 static int exynos_get_trip_type(struct thermal_zone_device
*thermal
, int trip
,
194 enum thermal_trip_type
*type
)
196 switch (GET_ZONE(trip
)) {
199 *type
= THERMAL_TRIP_ACTIVE
;
202 *type
= THERMAL_TRIP_CRITICAL
;
210 /* Get trip temperature callback functions for thermal zone */
211 static int exynos_get_trip_temp(struct thermal_zone_device
*thermal
, int trip
,
214 if (trip
< GET_TRIP(MONITOR_ZONE
) || trip
> GET_TRIP(PANIC_ZONE
))
217 *temp
= th_zone
->sensor_conf
->trip_data
.trip_val
[trip
];
218 /* convert the temperature into millicelsius */
219 *temp
= *temp
* MCELSIUS
;
224 /* Get critical temperature callback functions for thermal zone */
225 static int exynos_get_crit_temp(struct thermal_zone_device
*thermal
,
230 ret
= exynos_get_trip_temp(thermal
, GET_TRIP(PANIC_ZONE
), temp
);
234 static int exynos_get_frequency_level(unsigned int cpu
, unsigned int freq
)
236 int i
= 0, ret
= -EINVAL
;
237 struct cpufreq_frequency_table
*table
= NULL
;
238 #ifdef CONFIG_CPU_FREQ
239 table
= cpufreq_frequency_get_table(cpu
);
244 while (table
[i
].frequency
!= CPUFREQ_TABLE_END
) {
245 if (table
[i
].frequency
== CPUFREQ_ENTRY_INVALID
)
247 if (table
[i
].frequency
== freq
)
254 /* Bind callback functions for thermal zone */
255 static int exynos_bind(struct thermal_zone_device
*thermal
,
256 struct thermal_cooling_device
*cdev
)
258 int ret
= 0, i
, tab_size
, level
;
259 struct freq_clip_table
*tab_ptr
, *clip_data
;
260 struct thermal_sensor_conf
*data
= th_zone
->sensor_conf
;
262 tab_ptr
= (struct freq_clip_table
*)data
->cooling_data
.freq_data
;
263 tab_size
= data
->cooling_data
.freq_clip_count
;
265 if (tab_ptr
== NULL
|| tab_size
== 0)
268 /* find the cooling device registered*/
269 for (i
= 0; i
< th_zone
->cool_dev_size
; i
++)
270 if (cdev
== th_zone
->cool_dev
[i
])
273 /* No matching cooling device */
274 if (i
== th_zone
->cool_dev_size
)
277 /* Bind the thermal zone to the cpufreq cooling device */
278 for (i
= 0; i
< tab_size
; i
++) {
279 clip_data
= (struct freq_clip_table
*)&(tab_ptr
[i
]);
280 level
= exynos_get_frequency_level(0, clip_data
->freq_clip_max
);
283 switch (GET_ZONE(i
)) {
286 if (thermal_zone_bind_cooling_device(thermal
, i
, cdev
,
288 pr_err("error binding cdev inst %d\n", i
);
291 th_zone
->bind
= true;
301 /* Unbind callback functions for thermal zone */
302 static int exynos_unbind(struct thermal_zone_device
*thermal
,
303 struct thermal_cooling_device
*cdev
)
305 int ret
= 0, i
, tab_size
;
306 struct thermal_sensor_conf
*data
= th_zone
->sensor_conf
;
308 if (th_zone
->bind
== false)
311 tab_size
= data
->cooling_data
.freq_clip_count
;
316 /* find the cooling device registered*/
317 for (i
= 0; i
< th_zone
->cool_dev_size
; i
++)
318 if (cdev
== th_zone
->cool_dev
[i
])
321 /* No matching cooling device */
322 if (i
== th_zone
->cool_dev_size
)
325 /* Bind the thermal zone to the cpufreq cooling device */
326 for (i
= 0; i
< tab_size
; i
++) {
327 switch (GET_ZONE(i
)) {
330 if (thermal_zone_unbind_cooling_device(thermal
, i
,
332 pr_err("error unbinding cdev inst=%d\n", i
);
335 th_zone
->bind
= false;
344 /* Get temperature callback functions for thermal zone */
345 static int exynos_get_temp(struct thermal_zone_device
*thermal
,
350 if (!th_zone
->sensor_conf
) {
351 pr_info("Temperature sensor not initialised\n");
354 data
= th_zone
->sensor_conf
->private_data
;
355 *temp
= th_zone
->sensor_conf
->read_temperature(data
);
356 /* convert the temperature into millicelsius */
357 *temp
= *temp
* MCELSIUS
;
361 /* Get the temperature trend */
362 static int exynos_get_trend(struct thermal_zone_device
*thermal
,
363 int trip
, enum thermal_trend
*trend
)
365 if (thermal
->temperature
>= trip
)
366 *trend
= THERMAL_TREND_RAISING
;
368 *trend
= THERMAL_TREND_DROPPING
;
372 /* Operation callback functions for thermal zone */
373 static struct thermal_zone_device_ops
const exynos_dev_ops
= {
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
,
386 * This function may be called from interrupt based temperature sensor
387 * when threshold is changed.
389 static void exynos_report_trigger(void)
393 char *envp
[] = { data
, NULL
};
395 if (!th_zone
|| !th_zone
->therm_dev
)
397 if (th_zone
->bind
== false) {
398 for (i
= 0; i
< th_zone
->cool_dev_size
; i
++) {
399 if (!th_zone
->cool_dev
[i
])
401 exynos_bind(th_zone
->therm_dev
,
402 th_zone
->cool_dev
[i
]);
406 thermal_zone_device_update(th_zone
->therm_dev
);
408 mutex_lock(&th_zone
->therm_dev
->lock
);
409 /* Find the level for which trip happened */
410 for (i
= 0; i
< th_zone
->sensor_conf
->trip_data
.trip_count
; i
++) {
411 if (th_zone
->therm_dev
->last_temperature
<
412 th_zone
->sensor_conf
->trip_data
.trip_val
[i
] * MCELSIUS
)
416 if (th_zone
->mode
== THERMAL_DEVICE_ENABLED
) {
418 th_zone
->therm_dev
->polling_delay
= ACTIVE_INTERVAL
;
420 th_zone
->therm_dev
->polling_delay
= IDLE_INTERVAL
;
423 snprintf(data
, sizeof(data
), "%u", i
);
424 kobject_uevent_env(&th_zone
->therm_dev
->device
.kobj
, KOBJ_CHANGE
, envp
);
425 mutex_unlock(&th_zone
->therm_dev
->lock
);
428 /* Register with the in-kernel thermal management */
429 static int exynos_register_thermal(struct thermal_sensor_conf
*sensor_conf
)
432 struct cpumask mask_val
;
434 if (!sensor_conf
|| !sensor_conf
->read_temperature
) {
435 pr_err("Temperature sensor not initialised\n");
439 th_zone
= kzalloc(sizeof(struct exynos_thermal_zone
), GFP_KERNEL
);
443 th_zone
->sensor_conf
= sensor_conf
;
444 cpumask_set_cpu(0, &mask_val
);
445 th_zone
->cool_dev
[0] = cpufreq_cooling_register(&mask_val
);
446 if (IS_ERR(th_zone
->cool_dev
[0])) {
447 pr_err("Failed to register cpufreq cooling device\n");
451 th_zone
->cool_dev_size
++;
453 th_zone
->therm_dev
= thermal_zone_device_register(sensor_conf
->name
,
454 EXYNOS_ZONE_COUNT
, 0, NULL
, &exynos_dev_ops
, NULL
, 0,
457 if (IS_ERR(th_zone
->therm_dev
)) {
458 pr_err("Failed to register thermal zone device\n");
462 th_zone
->mode
= THERMAL_DEVICE_ENABLED
;
464 pr_info("Exynos: Kernel Thermal management registered\n");
469 exynos_unregister_thermal();
473 /* Un-Register with the in-kernel thermal management */
474 static void exynos_unregister_thermal(void)
481 if (th_zone
->therm_dev
)
482 thermal_zone_device_unregister(th_zone
->therm_dev
);
484 for (i
= 0; i
< th_zone
->cool_dev_size
; i
++) {
485 if (th_zone
->cool_dev
[i
])
486 cpufreq_cooling_unregister(th_zone
->cool_dev
[i
]);
490 pr_info("Exynos: Kernel Thermal management unregistered\n");
494 * TMU treats temperature as a mapped temperature code.
495 * The temperature is converted differently depending on the calibration type.
497 static int temp_to_code(struct exynos_tmu_data
*data
, u8 temp
)
499 struct exynos_tmu_platform_data
*pdata
= data
->pdata
;
502 if (data
->soc
== SOC_ARCH_EXYNOS4210
)
503 /* temp should range between 25 and 125 */
504 if (temp
< 25 || temp
> 125) {
509 switch (pdata
->cal_type
) {
510 case TYPE_TWO_POINT_TRIMMING
:
511 temp_code
= (temp
- 25) *
512 (data
->temp_error2
- data
->temp_error1
) /
513 (85 - 25) + data
->temp_error1
;
515 case TYPE_ONE_POINT_TRIMMING
:
516 temp_code
= temp
+ data
->temp_error1
- 25;
519 temp_code
= temp
+ EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET
;
527 * Calculate a temperature value from a temperature code.
528 * The unit of the temperature is degree Celsius.
530 static int code_to_temp(struct exynos_tmu_data
*data
, u8 temp_code
)
532 struct exynos_tmu_platform_data
*pdata
= data
->pdata
;
535 if (data
->soc
== SOC_ARCH_EXYNOS4210
)
536 /* temp_code should range between 75 and 175 */
537 if (temp_code
< 75 || temp_code
> 175) {
542 switch (pdata
->cal_type
) {
543 case TYPE_TWO_POINT_TRIMMING
:
544 temp
= (temp_code
- data
->temp_error1
) * (85 - 25) /
545 (data
->temp_error2
- data
->temp_error1
) + 25;
547 case TYPE_ONE_POINT_TRIMMING
:
548 temp
= temp_code
- data
->temp_error1
+ 25;
551 temp
= temp_code
- EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET
;
558 static int exynos_tmu_initialize(struct platform_device
*pdev
)
560 struct exynos_tmu_data
*data
= platform_get_drvdata(pdev
);
561 struct exynos_tmu_platform_data
*pdata
= data
->pdata
;
562 unsigned int status
, trim_info
, rising_threshold
;
563 int ret
= 0, threshold_code
;
565 mutex_lock(&data
->lock
);
566 clk_enable(data
->clk
);
568 status
= readb(data
->base
+ EXYNOS_TMU_REG_STATUS
);
574 if (data
->soc
== SOC_ARCH_EXYNOS
) {
575 __raw_writel(EXYNOS_TRIMINFO_RELOAD
,
576 data
->base
+ EXYNOS_TMU_TRIMINFO_CON
);
578 /* Save trimming info in order to perform calibration */
579 trim_info
= readl(data
->base
+ EXYNOS_TMU_REG_TRIMINFO
);
580 data
->temp_error1
= trim_info
& EXYNOS_TMU_TRIM_TEMP_MASK
;
581 data
->temp_error2
= ((trim_info
>> 8) & EXYNOS_TMU_TRIM_TEMP_MASK
);
583 if ((EFUSE_MIN_VALUE
> data
->temp_error1
) ||
584 (data
->temp_error1
> EFUSE_MAX_VALUE
) ||
585 (data
->temp_error2
!= 0))
586 data
->temp_error1
= pdata
->efuse_value
;
588 if (data
->soc
== SOC_ARCH_EXYNOS4210
) {
589 /* Write temperature code for threshold */
590 threshold_code
= temp_to_code(data
, pdata
->threshold
);
591 if (threshold_code
< 0) {
592 ret
= threshold_code
;
595 writeb(threshold_code
,
596 data
->base
+ EXYNOS4210_TMU_REG_THRESHOLD_TEMP
);
598 writeb(pdata
->trigger_levels
[0],
599 data
->base
+ EXYNOS4210_TMU_REG_TRIG_LEVEL0
);
600 writeb(pdata
->trigger_levels
[1],
601 data
->base
+ EXYNOS4210_TMU_REG_TRIG_LEVEL1
);
602 writeb(pdata
->trigger_levels
[2],
603 data
->base
+ EXYNOS4210_TMU_REG_TRIG_LEVEL2
);
604 writeb(pdata
->trigger_levels
[3],
605 data
->base
+ EXYNOS4210_TMU_REG_TRIG_LEVEL3
);
607 writel(EXYNOS4210_TMU_INTCLEAR_VAL
,
608 data
->base
+ EXYNOS_TMU_REG_INTCLEAR
);
609 } else if (data
->soc
== SOC_ARCH_EXYNOS
) {
610 /* Write temperature code for threshold */
611 threshold_code
= temp_to_code(data
, pdata
->trigger_levels
[0]);
612 if (threshold_code
< 0) {
613 ret
= threshold_code
;
616 rising_threshold
= threshold_code
;
617 threshold_code
= temp_to_code(data
, pdata
->trigger_levels
[1]);
618 if (threshold_code
< 0) {
619 ret
= threshold_code
;
622 rising_threshold
|= (threshold_code
<< 8);
623 threshold_code
= temp_to_code(data
, pdata
->trigger_levels
[2]);
624 if (threshold_code
< 0) {
625 ret
= threshold_code
;
628 rising_threshold
|= (threshold_code
<< 16);
630 writel(rising_threshold
,
631 data
->base
+ EXYNOS_THD_TEMP_RISE
);
632 writel(0, data
->base
+ EXYNOS_THD_TEMP_FALL
);
634 writel(EXYNOS_TMU_CLEAR_RISE_INT
|EXYNOS_TMU_CLEAR_FALL_INT
,
635 data
->base
+ EXYNOS_TMU_REG_INTCLEAR
);
638 clk_disable(data
->clk
);
639 mutex_unlock(&data
->lock
);
644 static void exynos_tmu_control(struct platform_device
*pdev
, bool on
)
646 struct exynos_tmu_data
*data
= platform_get_drvdata(pdev
);
647 struct exynos_tmu_platform_data
*pdata
= data
->pdata
;
648 unsigned int con
, interrupt_en
;
650 mutex_lock(&data
->lock
);
651 clk_enable(data
->clk
);
653 con
= pdata
->reference_voltage
<< EXYNOS_TMU_REF_VOLTAGE_SHIFT
|
654 pdata
->gain
<< EXYNOS_TMU_GAIN_SHIFT
;
656 if (data
->soc
== SOC_ARCH_EXYNOS
) {
657 con
|= pdata
->noise_cancel_mode
<< EXYNOS_TMU_TRIP_MODE_SHIFT
;
658 con
|= (EXYNOS_MUX_ADDR_VALUE
<< EXYNOS_MUX_ADDR_SHIFT
);
662 con
|= EXYNOS_TMU_CORE_ON
;
663 interrupt_en
= pdata
->trigger_level3_en
<< 12 |
664 pdata
->trigger_level2_en
<< 8 |
665 pdata
->trigger_level1_en
<< 4 |
666 pdata
->trigger_level0_en
;
668 con
|= EXYNOS_TMU_CORE_OFF
;
669 interrupt_en
= 0; /* Disable all interrupts */
671 writel(interrupt_en
, data
->base
+ EXYNOS_TMU_REG_INTEN
);
672 writel(con
, data
->base
+ EXYNOS_TMU_REG_CONTROL
);
674 clk_disable(data
->clk
);
675 mutex_unlock(&data
->lock
);
678 static int exynos_tmu_read(struct exynos_tmu_data
*data
)
683 mutex_lock(&data
->lock
);
684 clk_enable(data
->clk
);
686 temp_code
= readb(data
->base
+ EXYNOS_TMU_REG_CURRENT_TEMP
);
687 temp
= code_to_temp(data
, temp_code
);
689 clk_disable(data
->clk
);
690 mutex_unlock(&data
->lock
);
695 static void exynos_tmu_work(struct work_struct
*work
)
697 struct exynos_tmu_data
*data
= container_of(work
,
698 struct exynos_tmu_data
, irq_work
);
700 mutex_lock(&data
->lock
);
701 clk_enable(data
->clk
);
704 if (data
->soc
== SOC_ARCH_EXYNOS
)
705 writel(EXYNOS_TMU_CLEAR_RISE_INT
,
706 data
->base
+ EXYNOS_TMU_REG_INTCLEAR
);
708 writel(EXYNOS4210_TMU_INTCLEAR_VAL
,
709 data
->base
+ EXYNOS_TMU_REG_INTCLEAR
);
711 clk_disable(data
->clk
);
712 mutex_unlock(&data
->lock
);
713 exynos_report_trigger();
714 enable_irq(data
->irq
);
717 static irqreturn_t
exynos_tmu_irq(int irq
, void *id
)
719 struct exynos_tmu_data
*data
= id
;
721 disable_irq_nosync(irq
);
722 schedule_work(&data
->irq_work
);
726 static struct thermal_sensor_conf exynos_sensor_conf
= {
727 .name
= "exynos-therm",
728 .read_temperature
= (int (*)(void *))exynos_tmu_read
,
731 #if defined(CONFIG_CPU_EXYNOS4210)
732 static struct exynos_tmu_platform_data
const exynos4210_default_tmu_data
= {
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,
743 .cal_type
= TYPE_ONE_POINT_TRIMMING
,
745 .freq_clip_max
= 800 * 1000,
749 .freq_clip_max
= 200 * 1000,
753 .type
= SOC_ARCH_EXYNOS4210
,
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)
761 static struct exynos_tmu_platform_data
const exynos_default_tmu_data
= {
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,
772 .cal_type
= TYPE_ONE_POINT_TRIMMING
,
775 .freq_clip_max
= 800 * 1000,
779 .freq_clip_max
= 200 * 1000,
783 .type
= SOC_ARCH_EXYNOS
,
785 #define EXYNOS_TMU_DRV_DATA (&exynos_default_tmu_data)
787 #define EXYNOS_TMU_DRV_DATA (NULL)
791 static const struct of_device_id exynos_tmu_match
[] = {
793 .compatible
= "samsung,exynos4210-tmu",
794 .data
= (void *)EXYNOS4210_TMU_DRV_DATA
,
797 .compatible
= "samsung,exynos5250-tmu",
798 .data
= (void *)EXYNOS_TMU_DRV_DATA
,
802 MODULE_DEVICE_TABLE(of
, exynos_tmu_match
);
804 #define exynos_tmu_match NULL
807 static struct platform_device_id exynos_tmu_driver_ids
[] = {
809 .name
= "exynos4210-tmu",
810 .driver_data
= (kernel_ulong_t
)EXYNOS4210_TMU_DRV_DATA
,
813 .name
= "exynos5250-tmu",
814 .driver_data
= (kernel_ulong_t
)EXYNOS_TMU_DRV_DATA
,
818 MODULE_DEVICE_TABLE(platform
, exynos_tmu_driver_ids
);
820 static inline struct exynos_tmu_platform_data
*exynos_get_driver_data(
821 struct platform_device
*pdev
)
824 if (pdev
->dev
.of_node
) {
825 const struct of_device_id
*match
;
826 match
= of_match_node(exynos_tmu_match
, pdev
->dev
.of_node
);
829 return (struct exynos_tmu_platform_data
*) match
->data
;
832 return (struct exynos_tmu_platform_data
*)
833 platform_get_device_id(pdev
)->driver_data
;
835 static int exynos_tmu_probe(struct platform_device
*pdev
)
837 struct exynos_tmu_data
*data
;
838 struct exynos_tmu_platform_data
*pdata
= pdev
->dev
.platform_data
;
842 pdata
= exynos_get_driver_data(pdev
);
845 dev_err(&pdev
->dev
, "No platform init data supplied.\n");
848 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct exynos_tmu_data
),
851 dev_err(&pdev
->dev
, "Failed to allocate driver structure\n");
855 data
->irq
= platform_get_irq(pdev
, 0);
857 dev_err(&pdev
->dev
, "Failed to get platform irq\n");
861 INIT_WORK(&data
->irq_work
, exynos_tmu_work
);
863 data
->mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
865 dev_err(&pdev
->dev
, "Failed to get platform resource\n");
869 data
->base
= devm_ioremap_resource(&pdev
->dev
, data
->mem
);
870 if (IS_ERR(data
->base
))
871 return PTR_ERR(data
->base
);
873 ret
= devm_request_irq(&pdev
->dev
, data
->irq
, exynos_tmu_irq
,
874 IRQF_TRIGGER_RISING
, "exynos-tmu", data
);
876 dev_err(&pdev
->dev
, "Failed to request irq: %d\n", data
->irq
);
880 data
->clk
= clk_get(NULL
, "tmu_apbif");
881 if (IS_ERR(data
->clk
)) {
882 dev_err(&pdev
->dev
, "Failed to get clock\n");
883 return PTR_ERR(data
->clk
);
886 if (pdata
->type
== SOC_ARCH_EXYNOS
||
887 pdata
->type
== SOC_ARCH_EXYNOS4210
)
888 data
->soc
= pdata
->type
;
891 dev_err(&pdev
->dev
, "Platform not supported\n");
896 platform_set_drvdata(pdev
, data
);
897 mutex_init(&data
->lock
);
899 ret
= exynos_tmu_initialize(pdev
);
901 dev_err(&pdev
->dev
, "Failed to initialize TMU\n");
905 exynos_tmu_control(pdev
, true);
907 /* Register the sensor with thermal management interface */
908 (&exynos_sensor_conf
)->private_data
= data
;
909 exynos_sensor_conf
.trip_data
.trip_count
= pdata
->trigger_level0_en
+
910 pdata
->trigger_level1_en
+ pdata
->trigger_level2_en
+
911 pdata
->trigger_level3_en
;
913 for (i
= 0; i
< exynos_sensor_conf
.trip_data
.trip_count
; i
++)
914 exynos_sensor_conf
.trip_data
.trip_val
[i
] =
915 pdata
->threshold
+ pdata
->trigger_levels
[i
];
917 exynos_sensor_conf
.cooling_data
.freq_clip_count
=
918 pdata
->freq_tab_count
;
919 for (i
= 0; i
< pdata
->freq_tab_count
; i
++) {
920 exynos_sensor_conf
.cooling_data
.freq_data
[i
].freq_clip_max
=
921 pdata
->freq_tab
[i
].freq_clip_max
;
922 exynos_sensor_conf
.cooling_data
.freq_data
[i
].temp_level
=
923 pdata
->freq_tab
[i
].temp_level
;
926 ret
= exynos_register_thermal(&exynos_sensor_conf
);
928 dev_err(&pdev
->dev
, "Failed to register thermal interface\n");
933 platform_set_drvdata(pdev
, NULL
);
938 static int exynos_tmu_remove(struct platform_device
*pdev
)
940 struct exynos_tmu_data
*data
= platform_get_drvdata(pdev
);
942 exynos_tmu_control(pdev
, false);
944 exynos_unregister_thermal();
948 platform_set_drvdata(pdev
, NULL
);
953 #ifdef CONFIG_PM_SLEEP
954 static int exynos_tmu_suspend(struct device
*dev
)
956 exynos_tmu_control(to_platform_device(dev
), false);
961 static int exynos_tmu_resume(struct device
*dev
)
963 struct platform_device
*pdev
= to_platform_device(dev
);
965 exynos_tmu_initialize(pdev
);
966 exynos_tmu_control(pdev
, true);
971 static SIMPLE_DEV_PM_OPS(exynos_tmu_pm
,
972 exynos_tmu_suspend
, exynos_tmu_resume
);
973 #define EXYNOS_TMU_PM (&exynos_tmu_pm)
975 #define EXYNOS_TMU_PM NULL
978 static struct platform_driver exynos_tmu_driver
= {
980 .name
= "exynos-tmu",
981 .owner
= THIS_MODULE
,
983 .of_match_table
= exynos_tmu_match
,
985 .probe
= exynos_tmu_probe
,
986 .remove
= exynos_tmu_remove
,
987 .id_table
= exynos_tmu_driver_ids
,
990 module_platform_driver(exynos_tmu_driver
);
992 MODULE_DESCRIPTION("EXYNOS TMU Driver");
993 MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
994 MODULE_LICENSE("GPL");
995 MODULE_ALIAS("platform:exynos-tmu");