aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2018-09-25 05:03:04 -0400
committerEduardo Valentin <edubezval@gmail.com>2018-10-22 20:45:12 -0400
commit7edc5e406f2637ba1f9c93b1e72e0e37f446304b (patch)
tree859ec85fec748d583d026cc2e0c4cd0ad4a3fe66
parent8c0ffc8f9a76b2007258f146a4ff22ef14e68590 (diff)
thermal/drivers/hisi: Add multiple sensors support
Change the code as it is dealing with several sensors. For git-bisect compatibility (compilation and booting), assume the DT is not yet changed and we have a single interrupt. Next changes will support multiple interrupt sorted by their name. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r--drivers/thermal/hisi_thermal.c79
1 files changed, 47 insertions, 32 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 87b82fb00b08..a5756f6d13e4 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -448,8 +448,8 @@ static const struct thermal_zone_of_device_ops hisi_of_thermal_ops = {
448 448
449static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) 449static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
450{ 450{
451 struct hisi_thermal_data *data = dev; 451 struct hisi_thermal_sensor *sensor = dev;
452 struct hisi_thermal_sensor *sensor = &data->sensor[0]; 452 struct hisi_thermal_data *data = sensor->data;
453 int temp = 0; 453 int temp = 0;
454 454
455 data->ops->irq_handler(sensor); 455 data->ops->irq_handler(sensor);
@@ -457,15 +457,17 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
457 hisi_thermal_get_temp(sensor, &temp); 457 hisi_thermal_get_temp(sensor, &temp);
458 458
459 if (temp >= sensor->thres_temp) { 459 if (temp >= sensor->thres_temp) {
460 dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", 460 dev_crit(&data->pdev->dev,
461 temp, sensor->thres_temp); 461 "sensor <%d> THERMAL ALARM: %d > %d\n",
462 sensor->id, temp, sensor->thres_temp);
462 463
463 thermal_zone_device_update(data->sensor[0].tzd, 464 thermal_zone_device_update(sensor->tzd,
464 THERMAL_EVENT_UNSPECIFIED); 465 THERMAL_EVENT_UNSPECIFIED);
465 466
466 } else { 467 } else {
467 dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", 468 dev_crit(&data->pdev->dev,
468 temp, sensor->thres_temp); 469 "sensor <%d> THERMAL ALARM stopped: %d < %d\n",
470 sensor->id, temp, sensor->thres_temp);
469 } 471 }
470 472
471 return IRQ_HANDLED; 473 return IRQ_HANDLED;
@@ -543,7 +545,7 @@ static int hisi_thermal_probe(struct platform_device *pdev)
543 struct hisi_thermal_data *data; 545 struct hisi_thermal_data *data;
544 struct device *dev = &pdev->dev; 546 struct device *dev = &pdev->dev;
545 struct resource *res; 547 struct resource *res;
546 int ret; 548 int i, ret;
547 549
548 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 550 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
549 if (!data) 551 if (!data)
@@ -560,37 +562,41 @@ static int hisi_thermal_probe(struct platform_device *pdev)
560 return PTR_ERR(data->regs); 562 return PTR_ERR(data->regs);
561 } 563 }
562 564
563 data->irq = platform_get_irq(pdev, 0);
564 if (data->irq < 0)
565 return data->irq;
566
567 ret = data->ops->probe(data); 565 ret = data->ops->probe(data);
568 if (ret) 566 if (ret)
569 return ret; 567 return ret;
570 568
571 ret = hisi_thermal_register_sensor(pdev, &data->sensor[0]); 569 for (i = 0; i < data->nr_sensors; i++) {
572 if (ret) { 570 struct hisi_thermal_sensor *sensor = &data->sensor[i];
573 dev_err(dev, "failed to register thermal sensor: %d\n", ret);
574 return ret;
575 }
576 571
577 ret = data->ops->enable_sensor(&data->sensor[0]); 572 ret = hisi_thermal_register_sensor(pdev, sensor);
578 if (ret) { 573 if (ret) {
579 dev_err(dev, "Failed to setup the sensor: %d\n", ret); 574 dev_err(dev, "failed to register thermal sensor: %d\n",
580 return ret; 575 ret);
581 } 576 return ret;
577 }
578
579 data->irq = platform_get_irq(pdev, 0);
580 if (data->irq < 0)
581 return data->irq;
582 582
583 if (data->irq) {
584 ret = devm_request_threaded_irq(dev, data->irq, NULL, 583 ret = devm_request_threaded_irq(dev, data->irq, NULL,
585 hisi_thermal_alarm_irq_thread, 584 hisi_thermal_alarm_irq_thread,
586 IRQF_ONESHOT, "hisi_thermal", data); 585 IRQF_ONESHOT, "hisi_thermal",
586 sensor);
587 if (ret < 0) { 587 if (ret < 0) {
588 dev_err(dev, "failed to request alarm irq: %d\n", ret); 588 dev_err(dev, "failed to request alarm irq: %d\n", ret);
589 return ret; 589 return ret;
590 } 590 }
591 }
592 591
593 hisi_thermal_toggle_sensor(&data->sensor[0], true); 592 ret = data->ops->enable_sensor(sensor);
593 if (ret) {
594 dev_err(dev, "Failed to setup the sensor: %d\n", ret);
595 return ret;
596 }
597
598 hisi_thermal_toggle_sensor(sensor, true);
599 }
594 600
595 return 0; 601 return 0;
596} 602}
@@ -598,11 +604,14 @@ static int hisi_thermal_probe(struct platform_device *pdev)
598static int hisi_thermal_remove(struct platform_device *pdev) 604static int hisi_thermal_remove(struct platform_device *pdev)
599{ 605{
600 struct hisi_thermal_data *data = platform_get_drvdata(pdev); 606 struct hisi_thermal_data *data = platform_get_drvdata(pdev);
601 struct hisi_thermal_sensor *sensor = &data->sensor[0]; 607 int i;
602 608
603 hisi_thermal_toggle_sensor(sensor, false); 609 for (i = 0; i < data->nr_sensors; i++) {
610 struct hisi_thermal_sensor *sensor = &data->sensor[i];
604 611
605 data->ops->disable_sensor(sensor); 612 hisi_thermal_toggle_sensor(sensor, false);
613 data->ops->disable_sensor(sensor);
614 }
606 615
607 return 0; 616 return 0;
608} 617}
@@ -611,8 +620,10 @@ static int hisi_thermal_remove(struct platform_device *pdev)
611static int hisi_thermal_suspend(struct device *dev) 620static int hisi_thermal_suspend(struct device *dev)
612{ 621{
613 struct hisi_thermal_data *data = dev_get_drvdata(dev); 622 struct hisi_thermal_data *data = dev_get_drvdata(dev);
623 int i;
614 624
615 data->ops->disable_sensor(&data->sensor[0]); 625 for (i = 0; i < data->nr_sensors; i++)
626 data->ops->disable_sensor(&data->sensor[i]);
616 627
617 return 0; 628 return 0;
618} 629}
@@ -620,8 +631,12 @@ static int hisi_thermal_suspend(struct device *dev)
620static int hisi_thermal_resume(struct device *dev) 631static int hisi_thermal_resume(struct device *dev)
621{ 632{
622 struct hisi_thermal_data *data = dev_get_drvdata(dev); 633 struct hisi_thermal_data *data = dev_get_drvdata(dev);
634 int i, ret = 0;
635
636 for (i = 0; i < data->nr_sensors; i++)
637 ret |= data->ops->enable_sensor(&data->sensor[i]);
623 638
624 return data->ops->enable_sensor(&data->sensor[0]); 639 return ret;
625} 640}
626#endif 641#endif
627 642