f186f4ff44c4445861996fe542615e1665702ecd
[firefly-linux-kernel-4.4.55.git] / drivers / thermal / samsung / exynos_tmu.h
1 /*
2  * exynos_tmu.h - Samsung EXYNOS TMU (Thermal Management Unit)
3  *
4  *  Copyright (C) 2011 Samsung Electronics
5  *  Donggeun Kim <dg77.kim@samsung.com>
6  *  Amit Daniel Kachhap <amit.daniel@samsung.com>
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef _EXYNOS_TMU_H
24 #define _EXYNOS_TMU_H
25 #include <linux/cpu_cooling.h>
26
27 #include "exynos_thermal_common.h"
28
29 enum calibration_type {
30         TYPE_ONE_POINT_TRIMMING,
31         TYPE_ONE_POINT_TRIMMING_25,
32         TYPE_ONE_POINT_TRIMMING_85,
33         TYPE_TWO_POINT_TRIMMING,
34         TYPE_NONE,
35 };
36
37 enum soc_type {
38         SOC_ARCH_EXYNOS3250 = 1,
39         SOC_ARCH_EXYNOS4210,
40         SOC_ARCH_EXYNOS4412,
41         SOC_ARCH_EXYNOS5250,
42         SOC_ARCH_EXYNOS5260,
43         SOC_ARCH_EXYNOS5420,
44         SOC_ARCH_EXYNOS5420_TRIMINFO,
45         SOC_ARCH_EXYNOS5440,
46 };
47
48 /**
49  * EXYNOS TMU supported features.
50  * TMU_SUPPORT_EMULATION - This features is used to set user defined
51  *                      temperature to the TMU controller.
52  * TMU_SUPPORT_MULTI_INST - This features denotes that the soc
53  *                      has many instances of TMU.
54  * TMU_SUPPORT_FALLING_TRIP - This features shows that interrupt can
55  *                      be registered for falling trips also.
56  * TMU_SUPPORT_EMUL_TIME - This features allows to set next temp emulation
57  *                      sample time.
58  * TMU_SUPPORT_ADDRESS_MULTIPLE - This feature tells that the different TMU
59  *                      sensors shares some common registers.
60  * TMU_SUPPORT - macro to compare the above features with the supplied.
61  */
62 #define TMU_SUPPORT_EMULATION                   BIT(0)
63 #define TMU_SUPPORT_MULTI_INST                  BIT(1)
64 #define TMU_SUPPORT_FALLING_TRIP                BIT(2)
65 #define TMU_SUPPORT_EMUL_TIME                   BIT(3)
66 #define TMU_SUPPORT_ADDRESS_MULTIPLE            BIT(4)
67
68 #define TMU_SUPPORTS(a, b)      (a->features & TMU_SUPPORT_ ## b)
69
70 /**
71  * struct exynos_tmu_register - register descriptors to access registers and
72  * bitfields. The register validity, offsets and bitfield values may vary
73  * slightly across different exynos SOC's.
74  * @tmu_ctrl: TMU main controller register.
75  * @tmu_cur_temp: register containing the current temperature of the TMU.
76  * @tmu_inten: register containing the different threshold interrupt
77         enable bits.
78  * @inten_rise0_shift: shift bits of rising 0 interrupt bits.
79  * @inten_rise1_shift: shift bits of rising 1 interrupt bits.
80  * @inten_rise2_shift: shift bits of rising 2 interrupt bits.
81  * @inten_rise3_shift: shift bits of rising 3 interrupt bits.
82  * @inten_fall0_shift: shift bits of falling 0 interrupt bits.
83  * @tmu_intstat: Register containing the interrupt status values.
84  * @tmu_intclear: Register for clearing the raised interrupt status.
85  * @emul_con: TMU emulation controller register.
86  */
87 struct exynos_tmu_registers {
88         u32     tmu_ctrl;
89
90         u32     tmu_cur_temp;
91
92         u32     tmu_inten;
93         u32     inten_rise0_shift;
94         u32     inten_rise1_shift;
95         u32     inten_rise2_shift;
96         u32     inten_rise3_shift;
97         u32     inten_fall0_shift;
98
99         u32     tmu_intstat;
100
101         u32     tmu_intclear;
102
103         u32     emul_con;
104 };
105
106 /**
107  * struct exynos_tmu_platform_data
108  * @threshold: basic temperature for generating interrupt
109  *             25 <= threshold <= 125 [unit: degree Celsius]
110  * @threshold_falling: differntial value for setting threshold
111  *                     of temperature falling interrupt.
112  * @trigger_levels: array for each interrupt levels
113  *      [unit: degree Celsius]
114  *      0: temperature for trigger_level0 interrupt
115  *         condition for trigger_level0 interrupt:
116  *              current temperature > threshold + trigger_levels[0]
117  *      1: temperature for trigger_level1 interrupt
118  *         condition for trigger_level1 interrupt:
119  *              current temperature > threshold + trigger_levels[1]
120  *      2: temperature for trigger_level2 interrupt
121  *         condition for trigger_level2 interrupt:
122  *              current temperature > threshold + trigger_levels[2]
123  *      3: temperature for trigger_level3 interrupt
124  *         condition for trigger_level3 interrupt:
125  *              current temperature > threshold + trigger_levels[3]
126  * @trigger_type: defines the type of trigger. Possible values are,
127  *      THROTTLE_ACTIVE trigger type
128  *      THROTTLE_PASSIVE trigger type
129  *      SW_TRIP trigger type
130  *      HW_TRIP
131  * @trigger_enable[]: array to denote which trigger levels are enabled.
132  *      1 = enable trigger_level[] interrupt,
133  *      0 = disable trigger_level[] interrupt
134  * @max_trigger_level: max trigger level supported by the TMU
135  * @non_hw_trigger_levels: number of defined non-hardware trigger levels
136  * @gain: gain of amplifier in the positive-TC generator block
137  *      0 < gain <= 15
138  * @reference_voltage: reference voltage of amplifier
139  *      in the positive-TC generator block
140  *      0 < reference_voltage <= 31
141  * @noise_cancel_mode: noise cancellation mode
142  *      000, 100, 101, 110 and 111 can be different modes
143  * @type: determines the type of SOC
144  * @efuse_value: platform defined fuse value
145  * @min_efuse_value: minimum valid trimming data
146  * @max_efuse_value: maximum valid trimming data
147  * @first_point_trim: temp value of the first point trimming
148  * @second_point_trim: temp value of the second point trimming
149  * @default_temp_offset: default temperature offset in case of no trimming
150  * @test_mux; information if SoC supports test MUX
151  * @cal_type: calibration type for temperature
152  * @freq_clip_table: Table representing frequency reduction percentage.
153  * @freq_tab_count: Count of the above table as frequency reduction may
154  *      applicable to only some of the trigger levels.
155  * @registers: Pointer to structure containing all the TMU controller registers
156  *      and bitfields shifts and masks.
157  * @features: a bitfield value indicating the features supported in SOC like
158  *      emulation, multi instance etc
159  *
160  * This structure is required for configuration of exynos_tmu driver.
161  */
162 struct exynos_tmu_platform_data {
163         u8 threshold;
164         u8 threshold_falling;
165         u8 trigger_levels[MAX_TRIP_COUNT];
166         enum trigger_type trigger_type[MAX_TRIP_COUNT];
167         bool trigger_enable[MAX_TRIP_COUNT];
168         u8 max_trigger_level;
169         u8 non_hw_trigger_levels;
170         u8 gain;
171         u8 reference_voltage;
172         u8 noise_cancel_mode;
173
174         u32 efuse_value;
175         u32 min_efuse_value;
176         u32 max_efuse_value;
177         u8 first_point_trim;
178         u8 second_point_trim;
179         u8 default_temp_offset;
180         u8 test_mux;
181
182         enum calibration_type cal_type;
183         enum soc_type type;
184         struct freq_clip_table freq_tab[4];
185         unsigned int freq_tab_count;
186         const struct exynos_tmu_registers *registers;
187         unsigned int features;
188 };
189
190 /**
191  * struct exynos_tmu_init_data
192  * @tmu_count: number of TMU instances.
193  * @tmu_data: platform data of all TMU instances.
194  * This structure is required to store data for multi-instance exynos tmu
195  * driver.
196  */
197 struct exynos_tmu_init_data {
198         int tmu_count;
199         struct exynos_tmu_platform_data tmu_data[];
200 };
201
202 #endif /* _EXYNOS_TMU_H */