aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2017-10-19 13:05:44 -0400
committerEduardo Valentin <edubezval@gmail.com>2017-10-31 22:32:14 -0400
commitff4ec2997df8fe7cc40513dbe5f86d9f88fb6be7 (patch)
treecd5f690d4295ae448a3efeb047f0a0ca7d8dbb8e
parentc176b10b025acee4dc8f2ab1cd64eb73b5ccef53 (diff)
thermal/drivers/hisi: Remove the multiple sensors support
By essence, the tsensor does not really support multiple sensor at the same time. It allows to set a sensor and use it to get the temperature, another sensor could be switched but with a delay of 3-5ms. It is difficult to read simultaneously several sensors without a big delay. Today, just one sensor is used, it is not necessary to deal with multiple sensors in the code. Remove them and if it is needed in the future add them on top of a code which will be clean up in the meantime. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Reviewed-by: Leo Yan <leo.yan@linaro.org> Acked-by: Wangtao (Kevin, Kirin) <kevin.wangtao@hisilicon.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r--drivers/thermal/hisi_thermal.c75
1 files changed, 19 insertions, 56 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 8381696241d6..725d0d434d83 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -39,6 +39,7 @@
39#define HISI_TEMP_RESET (100000) 39#define HISI_TEMP_RESET (100000)
40 40
41#define HISI_MAX_SENSORS 4 41#define HISI_MAX_SENSORS 4
42#define HISI_DEFAULT_SENSOR 2
42 43
43struct hisi_thermal_sensor { 44struct hisi_thermal_sensor {
44 struct hisi_thermal_data *thermal; 45 struct hisi_thermal_data *thermal;
@@ -53,9 +54,8 @@ struct hisi_thermal_data {
53 struct mutex thermal_lock; /* protects register data */ 54 struct mutex thermal_lock; /* protects register data */
54 struct platform_device *pdev; 55 struct platform_device *pdev;
55 struct clk *clk; 56 struct clk *clk;
56 struct hisi_thermal_sensor sensors[HISI_MAX_SENSORS]; 57 struct hisi_thermal_sensor sensors;
57 58 int irq;
58 int irq, irq_bind_sensor;
59 bool irq_enabled; 59 bool irq_enabled;
60 60
61 void __iomem *regs; 61 void __iomem *regs;
@@ -113,7 +113,7 @@ static void hisi_thermal_enable_bind_irq_sensor
113 113
114 mutex_lock(&data->thermal_lock); 114 mutex_lock(&data->thermal_lock);
115 115
116 sensor = &data->sensors[data->irq_bind_sensor]; 116 sensor = &data->sensors;
117 117
118 /* setting the hdak time */ 118 /* setting the hdak time */
119 writel(0x0, data->regs + TEMP0_CFG); 119 writel(0x0, data->regs + TEMP0_CFG);
@@ -160,31 +160,8 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp)
160 struct hisi_thermal_sensor *sensor = _sensor; 160 struct hisi_thermal_sensor *sensor = _sensor;
161 struct hisi_thermal_data *data = sensor->thermal; 161 struct hisi_thermal_data *data = sensor->thermal;
162 162
163 int sensor_id = -1, i;
164 long max_temp = 0;
165
166 *temp = hisi_thermal_get_sensor_temp(data, sensor); 163 *temp = hisi_thermal_get_sensor_temp(data, sensor);
167 164
168 sensor->sensor_temp = *temp;
169
170 for (i = 0; i < HISI_MAX_SENSORS; i++) {
171 if (!data->sensors[i].tzd)
172 continue;
173
174 if (data->sensors[i].sensor_temp >= max_temp) {
175 max_temp = data->sensors[i].sensor_temp;
176 sensor_id = i;
177 }
178 }
179
180 /* If no sensor has been enabled, then skip to enable irq */
181 if (sensor_id == -1)
182 return 0;
183
184 mutex_lock(&data->thermal_lock);
185 data->irq_bind_sensor = sensor_id;
186 mutex_unlock(&data->thermal_lock);
187
188 dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n", 165 dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n",
189 sensor->id, data->irq_enabled, *temp, sensor->thres_temp); 166 sensor->id, data->irq_enabled, *temp, sensor->thres_temp);
190 /* 167 /*
@@ -197,7 +174,7 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp)
197 return 0; 174 return 0;
198 } 175 }
199 176
200 if (max_temp < sensor->thres_temp) { 177 if (*temp < sensor->thres_temp) {
201 data->irq_enabled = true; 178 data->irq_enabled = true;
202 hisi_thermal_enable_bind_irq_sensor(data); 179 hisi_thermal_enable_bind_irq_sensor(data);
203 enable_irq(data->irq); 180 enable_irq(data->irq);
@@ -224,22 +201,16 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
224{ 201{
225 struct hisi_thermal_data *data = dev; 202 struct hisi_thermal_data *data = dev;
226 struct hisi_thermal_sensor *sensor; 203 struct hisi_thermal_sensor *sensor;
227 int i;
228 204
229 mutex_lock(&data->thermal_lock); 205 mutex_lock(&data->thermal_lock);
230 sensor = &data->sensors[data->irq_bind_sensor]; 206 sensor = &data->sensors;
231 207
232 dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", 208 dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n",
233 sensor->thres_temp / 1000); 209 sensor->thres_temp / 1000);
234 mutex_unlock(&data->thermal_lock); 210 mutex_unlock(&data->thermal_lock);
235 211
236 for (i = 0; i < HISI_MAX_SENSORS; i++) { 212 thermal_zone_device_update(data->sensors.tzd,
237 if (!data->sensors[i].tzd) 213 THERMAL_EVENT_UNSPECIFIED);
238 continue;
239
240 thermal_zone_device_update(data->sensors[i].tzd,
241 THERMAL_EVENT_UNSPECIFIED);
242 }
243 214
244 return IRQ_HANDLED; 215 return IRQ_HANDLED;
245} 216}
@@ -296,7 +267,6 @@ static int hisi_thermal_probe(struct platform_device *pdev)
296{ 267{
297 struct hisi_thermal_data *data; 268 struct hisi_thermal_data *data;
298 struct resource *res; 269 struct resource *res;
299 int i;
300 int ret; 270 int ret;
301 271
302 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 272 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
@@ -347,16 +317,17 @@ static int hisi_thermal_probe(struct platform_device *pdev)
347 hisi_thermal_enable_bind_irq_sensor(data); 317 hisi_thermal_enable_bind_irq_sensor(data);
348 data->irq_enabled = true; 318 data->irq_enabled = true;
349 319
350 for (i = 0; i < HISI_MAX_SENSORS; ++i) { 320 ret = hisi_thermal_register_sensor(pdev, data,
351 ret = hisi_thermal_register_sensor(pdev, data, 321 &data->sensors,
352 &data->sensors[i], i); 322 HISI_DEFAULT_SENSOR);
353 if (ret) 323 if (ret) {
354 dev_err(&pdev->dev, 324 dev_err(&pdev->dev, "failed to register thermal sensor: %d\n",
355 "failed to register thermal sensor: %d\n", ret); 325 ret);
356 else 326 return ret;
357 hisi_thermal_toggle_sensor(&data->sensors[i], true);
358 } 327 }
359 328
329 hisi_thermal_toggle_sensor(&data->sensors, true);
330
360 enable_irq(data->irq); 331 enable_irq(data->irq);
361 332
362 return 0; 333 return 0;
@@ -365,17 +336,9 @@ static int hisi_thermal_probe(struct platform_device *pdev)
365static int hisi_thermal_remove(struct platform_device *pdev) 336static int hisi_thermal_remove(struct platform_device *pdev)
366{ 337{
367 struct hisi_thermal_data *data = platform_get_drvdata(pdev); 338 struct hisi_thermal_data *data = platform_get_drvdata(pdev);
368 int i; 339 struct hisi_thermal_sensor *sensor = &data->sensors;
369
370 for (i = 0; i < HISI_MAX_SENSORS; i++) {
371 struct hisi_thermal_sensor *sensor = &data->sensors[i];
372
373 if (!sensor->tzd)
374 continue;
375
376 hisi_thermal_toggle_sensor(sensor, false);
377 }
378 340
341 hisi_thermal_toggle_sensor(sensor, false);
379 hisi_thermal_disable_sensor(data); 342 hisi_thermal_disable_sensor(data);
380 clk_disable_unprepare(data->clk); 343 clk_disable_unprepare(data->clk);
381 344