diff options
-rw-r--r-- | drivers/thermal/hisi_thermal.c | 92 |
1 files changed, 70 insertions, 22 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9ec5f290b850..7747b96002e3 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "thermal_core.h" | 27 | #include "thermal_core.h" |
28 | 28 | ||
29 | #define TEMP0_LAG (0x0) | ||
29 | #define TEMP0_TH (0x4) | 30 | #define TEMP0_TH (0x4) |
30 | #define TEMP0_RST_TH (0x8) | 31 | #define TEMP0_RST_TH (0x8) |
31 | #define TEMP0_CFG (0xC) | 32 | #define TEMP0_CFG (0xC) |
@@ -96,6 +97,56 @@ static inline long hisi_thermal_round_temp(int temp) | |||
96 | hisi_thermal_temp_to_step(temp)); | 97 | hisi_thermal_temp_to_step(temp)); |
97 | } | 98 | } |
98 | 99 | ||
100 | static inline void hisi_thermal_set_lag(void __iomem *addr, int value) | ||
101 | { | ||
102 | writel(value, addr + TEMP0_LAG); | ||
103 | } | ||
104 | |||
105 | static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) | ||
106 | { | ||
107 | writel(value, addr + TEMP0_INT_CLR); | ||
108 | } | ||
109 | |||
110 | static inline void hisi_thermal_alarm_enable(void __iomem *addr, int value) | ||
111 | { | ||
112 | writel(value, addr + TEMP0_INT_EN); | ||
113 | } | ||
114 | |||
115 | static inline void hisi_thermal_alarm_set(void __iomem *addr, int temp) | ||
116 | { | ||
117 | writel(hisi_thermal_temp_to_step(temp) | 0x0FFFFFF00, addr + TEMP0_TH); | ||
118 | } | ||
119 | |||
120 | static inline void hisi_thermal_reset_set(void __iomem *addr, int temp) | ||
121 | { | ||
122 | writel(hisi_thermal_temp_to_step(temp), addr + TEMP0_RST_TH); | ||
123 | } | ||
124 | |||
125 | static inline void hisi_thermal_reset_enable(void __iomem *addr, int value) | ||
126 | { | ||
127 | writel(value, addr + TEMP0_RST_MSK); | ||
128 | } | ||
129 | |||
130 | static inline void hisi_thermal_enable(void __iomem *addr, int value) | ||
131 | { | ||
132 | writel(value, addr + TEMP0_EN); | ||
133 | } | ||
134 | |||
135 | static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) | ||
136 | { | ||
137 | writel((sensor << 12), addr + TEMP0_CFG); | ||
138 | } | ||
139 | |||
140 | static inline int hisi_thermal_get_temperature(void __iomem *addr) | ||
141 | { | ||
142 | return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); | ||
143 | } | ||
144 | |||
145 | static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) | ||
146 | { | ||
147 | writel(value, addr + TEMP0_CFG); | ||
148 | } | ||
149 | |||
99 | static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, | 150 | static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, |
100 | struct hisi_thermal_sensor *sensor) | 151 | struct hisi_thermal_sensor *sensor) |
101 | { | 152 | { |
@@ -104,22 +155,21 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, | |||
104 | mutex_lock(&data->thermal_lock); | 155 | mutex_lock(&data->thermal_lock); |
105 | 156 | ||
106 | /* disable interrupt */ | 157 | /* disable interrupt */ |
107 | writel(0x0, data->regs + TEMP0_INT_EN); | 158 | hisi_thermal_alarm_enable(data->regs, 0); |
108 | writel(0x1, data->regs + TEMP0_INT_CLR); | 159 | hisi_thermal_alarm_clear(data->regs, 1); |
109 | 160 | ||
110 | /* disable module firstly */ | 161 | /* disable module firstly */ |
111 | writel(0x0, data->regs + TEMP0_EN); | 162 | hisi_thermal_enable(data->regs, 0); |
112 | 163 | ||
113 | /* select sensor id */ | 164 | /* select sensor id */ |
114 | writel((sensor->id << 12), data->regs + TEMP0_CFG); | 165 | hisi_thermal_sensor_select(data->regs, sensor->id); |
115 | 166 | ||
116 | /* enable module */ | 167 | /* enable module */ |
117 | writel(0x1, data->regs + TEMP0_EN); | 168 | hisi_thermal_enable(data->regs, 1); |
118 | 169 | ||
119 | usleep_range(3000, 5000); | 170 | usleep_range(3000, 5000); |
120 | 171 | ||
121 | val = readl(data->regs + TEMP0_VALUE); | 172 | val = hisi_thermal_get_temperature(data->regs); |
122 | val = hisi_thermal_step_to_temp(val); | ||
123 | 173 | ||
124 | mutex_unlock(&data->thermal_lock); | 174 | mutex_unlock(&data->thermal_lock); |
125 | 175 | ||
@@ -136,28 +186,26 @@ static void hisi_thermal_enable_bind_irq_sensor | |||
136 | sensor = &data->sensors; | 186 | sensor = &data->sensors; |
137 | 187 | ||
138 | /* setting the hdak time */ | 188 | /* setting the hdak time */ |
139 | writel(0x0, data->regs + TEMP0_CFG); | 189 | hisi_thermal_hdak_set(data->regs, 0); |
140 | 190 | ||
141 | /* disable module firstly */ | 191 | /* disable module firstly */ |
142 | writel(0x0, data->regs + TEMP0_RST_MSK); | 192 | hisi_thermal_reset_enable(data->regs, 0); |
143 | writel(0x0, data->regs + TEMP0_EN); | 193 | hisi_thermal_enable(data->regs, 0); |
144 | 194 | ||
145 | /* select sensor id */ | 195 | /* select sensor id */ |
146 | writel((sensor->id << 12), data->regs + TEMP0_CFG); | 196 | hisi_thermal_sensor_select(data->regs, sensor->id); |
147 | 197 | ||
148 | /* enable for interrupt */ | 198 | /* enable for interrupt */ |
149 | writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, | 199 | hisi_thermal_alarm_set(data->regs, sensor->thres_temp); |
150 | data->regs + TEMP0_TH); | ||
151 | 200 | ||
152 | writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), | 201 | hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); |
153 | data->regs + TEMP0_RST_TH); | ||
154 | 202 | ||
155 | /* enable module */ | 203 | /* enable module */ |
156 | writel(0x1, data->regs + TEMP0_RST_MSK); | 204 | hisi_thermal_reset_enable(data->regs, 1); |
157 | writel(0x1, data->regs + TEMP0_EN); | 205 | hisi_thermal_enable(data->regs, 1); |
158 | 206 | ||
159 | writel(0x0, data->regs + TEMP0_INT_CLR); | 207 | hisi_thermal_alarm_clear(data->regs, 0); |
160 | writel(0x1, data->regs + TEMP0_INT_EN); | 208 | hisi_thermal_alarm_enable(data->regs, 1); |
161 | 209 | ||
162 | usleep_range(3000, 5000); | 210 | usleep_range(3000, 5000); |
163 | 211 | ||
@@ -169,9 +217,9 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) | |||
169 | mutex_lock(&data->thermal_lock); | 217 | mutex_lock(&data->thermal_lock); |
170 | 218 | ||
171 | /* disable sensor module */ | 219 | /* disable sensor module */ |
172 | writel(0x0, data->regs + TEMP0_INT_EN); | 220 | hisi_thermal_enable(data->regs, 0); |
173 | writel(0x0, data->regs + TEMP0_RST_MSK); | 221 | hisi_thermal_alarm_enable(data->regs, 0); |
174 | writel(0x0, data->regs + TEMP0_EN); | 222 | hisi_thermal_reset_enable(data->regs, 0); |
175 | 223 | ||
176 | mutex_unlock(&data->thermal_lock); | 224 | mutex_unlock(&data->thermal_lock); |
177 | } | 225 | } |