diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2018-09-25 05:03:00 -0400 |
---|---|---|
committer | Eduardo Valentin <edubezval@gmail.com> | 2018-10-22 20:42:19 -0400 |
commit | 9c9ae8da710639790f1d45b1a55d28ee70734c11 (patch) | |
tree | 5c303bf5e8d3783c49f14c46d7b96398e6272bda | |
parent | c90aaeccc7c6a8967f3efd43048eeae51072251c (diff) |
thermal/drivers/hisi: Change the driver to be sensor oriented
In order to support multiple sensors, we have to change the code to
deal with sensors and not the hisi thermal structure.
Add a back pointer to the hisi thermal structure (containerof is not a
good option because later we convert the sensor field to a pointer).
Change the functions parameters to take a sensor instead of this hisi
thermal 'data' structure.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r-- | drivers/thermal/hisi_thermal.c | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9794cfe56a12..1fdda55bd93b 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c | |||
@@ -58,27 +58,28 @@ | |||
58 | #define HI6220_DEFAULT_SENSOR 2 | 58 | #define HI6220_DEFAULT_SENSOR 2 |
59 | #define HI3660_DEFAULT_SENSOR 1 | 59 | #define HI3660_DEFAULT_SENSOR 1 |
60 | 60 | ||
61 | struct hisi_thermal_data; | ||
62 | |||
61 | struct hisi_thermal_sensor { | 63 | struct hisi_thermal_sensor { |
64 | struct hisi_thermal_data *data; | ||
62 | struct thermal_zone_device *tzd; | 65 | struct thermal_zone_device *tzd; |
63 | uint32_t id; | 66 | uint32_t id; |
64 | uint32_t thres_temp; | 67 | uint32_t thres_temp; |
65 | }; | 68 | }; |
66 | 69 | ||
67 | struct hisi_thermal_data; | ||
68 | |||
69 | struct hisi_thermal_ops { | 70 | struct hisi_thermal_ops { |
70 | int (*get_temp)(struct hisi_thermal_data *data); | 71 | int (*get_temp)(struct hisi_thermal_sensor *sensor); |
71 | int (*enable_sensor)(struct hisi_thermal_data *data); | 72 | int (*enable_sensor)(struct hisi_thermal_sensor *sensor); |
72 | int (*disable_sensor)(struct hisi_thermal_data *data); | 73 | int (*disable_sensor)(struct hisi_thermal_sensor *sensor); |
73 | int (*irq_handler)(struct hisi_thermal_data *data); | 74 | int (*irq_handler)(struct hisi_thermal_sensor *sensor); |
74 | int (*probe)(struct hisi_thermal_data *data); | 75 | int (*probe)(struct hisi_thermal_data *data); |
75 | }; | 76 | }; |
76 | 77 | ||
77 | struct hisi_thermal_data { | 78 | struct hisi_thermal_data { |
78 | const struct hisi_thermal_ops *ops; | 79 | const struct hisi_thermal_ops *ops; |
80 | struct hisi_thermal_sensor sensor; | ||
79 | struct platform_device *pdev; | 81 | struct platform_device *pdev; |
80 | struct clk *clk; | 82 | struct clk *clk; |
81 | struct hisi_thermal_sensor sensor; | ||
82 | void __iomem *regs; | 83 | void __iomem *regs; |
83 | int irq; | 84 | int irq; |
84 | }; | 85 | }; |
@@ -273,30 +274,40 @@ static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) | |||
273 | (value << 4), addr + HI6220_TEMP0_CFG); | 274 | (value << 4), addr + HI6220_TEMP0_CFG); |
274 | } | 275 | } |
275 | 276 | ||
276 | static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data) | 277 | static int hi6220_thermal_irq_handler(struct hisi_thermal_sensor *sensor) |
277 | { | 278 | { |
279 | struct hisi_thermal_data *data = sensor->data; | ||
280 | |||
278 | hi6220_thermal_alarm_clear(data->regs, 1); | 281 | hi6220_thermal_alarm_clear(data->regs, 1); |
279 | return 0; | 282 | return 0; |
280 | } | 283 | } |
281 | 284 | ||
282 | static int hi3660_thermal_irq_handler(struct hisi_thermal_data *data) | 285 | static int hi3660_thermal_irq_handler(struct hisi_thermal_sensor *sensor) |
283 | { | 286 | { |
284 | hi3660_thermal_alarm_clear(data->regs, data->sensor.id, 1); | 287 | struct hisi_thermal_data *data = sensor->data; |
288 | |||
289 | hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); | ||
285 | return 0; | 290 | return 0; |
286 | } | 291 | } |
287 | 292 | ||
288 | static int hi6220_thermal_get_temp(struct hisi_thermal_data *data) | 293 | static int hi6220_thermal_get_temp(struct hisi_thermal_sensor *sensor) |
289 | { | 294 | { |
295 | struct hisi_thermal_data *data = sensor->data; | ||
296 | |||
290 | return hi6220_thermal_get_temperature(data->regs); | 297 | return hi6220_thermal_get_temperature(data->regs); |
291 | } | 298 | } |
292 | 299 | ||
293 | static int hi3660_thermal_get_temp(struct hisi_thermal_data *data) | 300 | static int hi3660_thermal_get_temp(struct hisi_thermal_sensor *sensor) |
294 | { | 301 | { |
295 | return hi3660_thermal_get_temperature(data->regs, data->sensor.id); | 302 | struct hisi_thermal_data *data = sensor->data; |
303 | |||
304 | return hi3660_thermal_get_temperature(data->regs, sensor->id); | ||
296 | } | 305 | } |
297 | 306 | ||
298 | static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) | 307 | static int hi6220_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) |
299 | { | 308 | { |
309 | struct hisi_thermal_data *data = sensor->data; | ||
310 | |||
300 | /* disable sensor module */ | 311 | /* disable sensor module */ |
301 | hi6220_thermal_enable(data->regs, 0); | 312 | hi6220_thermal_enable(data->regs, 0); |
302 | hi6220_thermal_alarm_enable(data->regs, 0); | 313 | hi6220_thermal_alarm_enable(data->regs, 0); |
@@ -307,16 +318,18 @@ static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) | |||
307 | return 0; | 318 | return 0; |
308 | } | 319 | } |
309 | 320 | ||
310 | static int hi3660_thermal_disable_sensor(struct hisi_thermal_data *data) | 321 | static int hi3660_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) |
311 | { | 322 | { |
323 | struct hisi_thermal_data *data = sensor->data; | ||
324 | |||
312 | /* disable sensor module */ | 325 | /* disable sensor module */ |
313 | hi3660_thermal_alarm_enable(data->regs, data->sensor.id, 0); | 326 | hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); |
314 | return 0; | 327 | return 0; |
315 | } | 328 | } |
316 | 329 | ||
317 | static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) | 330 | static int hi6220_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) |
318 | { | 331 | { |
319 | struct hisi_thermal_sensor *sensor = &data->sensor; | 332 | struct hisi_thermal_data *data = sensor->data; |
320 | int ret; | 333 | int ret; |
321 | 334 | ||
322 | /* enable clock for tsensor */ | 335 | /* enable clock for tsensor */ |
@@ -352,10 +365,10 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) | |||
352 | return 0; | 365 | return 0; |
353 | } | 366 | } |
354 | 367 | ||
355 | static int hi3660_thermal_enable_sensor(struct hisi_thermal_data *data) | 368 | static int hi3660_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) |
356 | { | 369 | { |
357 | unsigned int value; | 370 | unsigned int value; |
358 | struct hisi_thermal_sensor *sensor = &data->sensor; | 371 | struct hisi_thermal_data *data = sensor->data; |
359 | 372 | ||
360 | /* disable interrupt */ | 373 | /* disable interrupt */ |
361 | hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); | 374 | hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); |
@@ -432,7 +445,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) | |||
432 | struct hisi_thermal_data *data = __data; | 445 | struct hisi_thermal_data *data = __data; |
433 | struct hisi_thermal_sensor *sensor = &data->sensor; | 446 | struct hisi_thermal_sensor *sensor = &data->sensor; |
434 | 447 | ||
435 | *temp = data->ops->get_temp(data); | 448 | *temp = data->ops->get_temp(sensor); |
436 | 449 | ||
437 | dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", | 450 | dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", |
438 | sensor->id, *temp, sensor->thres_temp); | 451 | sensor->id, *temp, sensor->thres_temp); |
@@ -450,7 +463,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) | |||
450 | struct hisi_thermal_sensor *sensor = &data->sensor; | 463 | struct hisi_thermal_sensor *sensor = &data->sensor; |
451 | int temp = 0; | 464 | int temp = 0; |
452 | 465 | ||
453 | data->ops->irq_handler(data); | 466 | data->ops->irq_handler(sensor); |
454 | 467 | ||
455 | hisi_thermal_get_temp(data, &temp); | 468 | hisi_thermal_get_temp(data, &temp); |
456 | 469 | ||
@@ -470,10 +483,10 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) | |||
470 | } | 483 | } |
471 | 484 | ||
472 | static int hisi_thermal_register_sensor(struct platform_device *pdev, | 485 | static int hisi_thermal_register_sensor(struct platform_device *pdev, |
473 | struct hisi_thermal_data *data, | ||
474 | struct hisi_thermal_sensor *sensor) | 486 | struct hisi_thermal_sensor *sensor) |
475 | { | 487 | { |
476 | int ret, i; | 488 | int ret, i; |
489 | struct hisi_thermal_data *data = sensor->data; | ||
477 | const struct thermal_trip *trip; | 490 | const struct thermal_trip *trip; |
478 | 491 | ||
479 | sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, | 492 | sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, |
@@ -549,21 +562,20 @@ static int hisi_thermal_probe(struct platform_device *pdev) | |||
549 | 562 | ||
550 | data->pdev = pdev; | 563 | data->pdev = pdev; |
551 | platform_set_drvdata(pdev, data); | 564 | platform_set_drvdata(pdev, data); |
552 | 565 | data->sensor.data = data; | |
553 | data->ops = of_device_get_match_data(dev); | 566 | data->ops = of_device_get_match_data(dev); |
554 | 567 | ||
555 | ret = data->ops->probe(data); | 568 | ret = data->ops->probe(data); |
556 | if (ret) | 569 | if (ret) |
557 | return ret; | 570 | return ret; |
558 | 571 | ||
559 | ret = hisi_thermal_register_sensor(pdev, data, | 572 | ret = hisi_thermal_register_sensor(pdev, &data->sensor); |
560 | &data->sensor); | ||
561 | if (ret) { | 573 | if (ret) { |
562 | dev_err(dev, "failed to register thermal sensor: %d\n", ret); | 574 | dev_err(dev, "failed to register thermal sensor: %d\n", ret); |
563 | return ret; | 575 | return ret; |
564 | } | 576 | } |
565 | 577 | ||
566 | ret = data->ops->enable_sensor(data); | 578 | ret = data->ops->enable_sensor(&data->sensor); |
567 | if (ret) { | 579 | if (ret) { |
568 | dev_err(dev, "Failed to setup the sensor: %d\n", ret); | 580 | dev_err(dev, "Failed to setup the sensor: %d\n", ret); |
569 | return ret; | 581 | return ret; |
@@ -591,7 +603,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) | |||
591 | 603 | ||
592 | hisi_thermal_toggle_sensor(sensor, false); | 604 | hisi_thermal_toggle_sensor(sensor, false); |
593 | 605 | ||
594 | data->ops->disable_sensor(data); | 606 | data->ops->disable_sensor(&data->sensor); |
595 | 607 | ||
596 | return 0; | 608 | return 0; |
597 | } | 609 | } |
@@ -601,7 +613,7 @@ static int hisi_thermal_suspend(struct device *dev) | |||
601 | { | 613 | { |
602 | struct hisi_thermal_data *data = dev_get_drvdata(dev); | 614 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
603 | 615 | ||
604 | data->ops->disable_sensor(data); | 616 | data->ops->disable_sensor(&data->sensor); |
605 | 617 | ||
606 | return 0; | 618 | return 0; |
607 | } | 619 | } |
@@ -610,7 +622,7 @@ static int hisi_thermal_resume(struct device *dev) | |||
610 | { | 622 | { |
611 | struct hisi_thermal_data *data = dev_get_drvdata(dev); | 623 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
612 | 624 | ||
613 | return data->ops->enable_sensor(data); | 625 | return data->ops->enable_sensor(&data->sensor); |
614 | } | 626 | } |
615 | #endif | 627 | #endif |
616 | 628 | ||