diff options
-rw-r--r-- | drivers/thermal/hisi_thermal.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 761d0559c268..9794cfe56a12 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c | |||
@@ -64,11 +64,18 @@ struct hisi_thermal_sensor { | |||
64 | uint32_t thres_temp; | 64 | uint32_t thres_temp; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct hisi_thermal_data { | 67 | struct hisi_thermal_data; |
68 | |||
69 | struct hisi_thermal_ops { | ||
68 | int (*get_temp)(struct hisi_thermal_data *data); | 70 | int (*get_temp)(struct hisi_thermal_data *data); |
69 | int (*enable_sensor)(struct hisi_thermal_data *data); | 71 | int (*enable_sensor)(struct hisi_thermal_data *data); |
70 | int (*disable_sensor)(struct hisi_thermal_data *data); | 72 | int (*disable_sensor)(struct hisi_thermal_data *data); |
71 | int (*irq_handler)(struct hisi_thermal_data *data); | 73 | int (*irq_handler)(struct hisi_thermal_data *data); |
74 | int (*probe)(struct hisi_thermal_data *data); | ||
75 | }; | ||
76 | |||
77 | struct hisi_thermal_data { | ||
78 | const struct hisi_thermal_ops *ops; | ||
72 | struct platform_device *pdev; | 79 | struct platform_device *pdev; |
73 | struct clk *clk; | 80 | struct clk *clk; |
74 | struct hisi_thermal_sensor sensor; | 81 | struct hisi_thermal_sensor sensor; |
@@ -374,11 +381,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) | |||
374 | struct resource *res; | 381 | struct resource *res; |
375 | int ret; | 382 | int ret; |
376 | 383 | ||
377 | data->get_temp = hi6220_thermal_get_temp; | ||
378 | data->enable_sensor = hi6220_thermal_enable_sensor; | ||
379 | data->disable_sensor = hi6220_thermal_disable_sensor; | ||
380 | data->irq_handler = hi6220_thermal_irq_handler; | ||
381 | |||
382 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 384 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
383 | data->regs = devm_ioremap_resource(dev, res); | 385 | data->regs = devm_ioremap_resource(dev, res); |
384 | if (IS_ERR(data->regs)) { | 386 | if (IS_ERR(data->regs)) { |
@@ -409,11 +411,6 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data) | |||
409 | struct device *dev = &pdev->dev; | 411 | struct device *dev = &pdev->dev; |
410 | struct resource *res; | 412 | struct resource *res; |
411 | 413 | ||
412 | data->get_temp = hi3660_thermal_get_temp; | ||
413 | data->enable_sensor = hi3660_thermal_enable_sensor; | ||
414 | data->disable_sensor = hi3660_thermal_disable_sensor; | ||
415 | data->irq_handler = hi3660_thermal_irq_handler; | ||
416 | |||
417 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 414 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
418 | data->regs = devm_ioremap_resource(dev, res); | 415 | data->regs = devm_ioremap_resource(dev, res); |
419 | if (IS_ERR(data->regs)) { | 416 | if (IS_ERR(data->regs)) { |
@@ -435,7 +432,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) | |||
435 | struct hisi_thermal_data *data = __data; | 432 | struct hisi_thermal_data *data = __data; |
436 | struct hisi_thermal_sensor *sensor = &data->sensor; | 433 | struct hisi_thermal_sensor *sensor = &data->sensor; |
437 | 434 | ||
438 | *temp = data->get_temp(data); | 435 | *temp = data->ops->get_temp(data); |
439 | 436 | ||
440 | dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", | 437 | dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", |
441 | sensor->id, *temp, sensor->thres_temp); | 438 | sensor->id, *temp, sensor->thres_temp); |
@@ -453,7 +450,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) | |||
453 | struct hisi_thermal_sensor *sensor = &data->sensor; | 450 | struct hisi_thermal_sensor *sensor = &data->sensor; |
454 | int temp = 0; | 451 | int temp = 0; |
455 | 452 | ||
456 | data->irq_handler(data); | 453 | data->ops->irq_handler(data); |
457 | 454 | ||
458 | hisi_thermal_get_temp(data, &temp); | 455 | hisi_thermal_get_temp(data, &temp); |
459 | 456 | ||
@@ -502,14 +499,30 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, | |||
502 | return 0; | 499 | return 0; |
503 | } | 500 | } |
504 | 501 | ||
502 | static const struct hisi_thermal_ops hi6220_ops = { | ||
503 | .get_temp = hi6220_thermal_get_temp, | ||
504 | .enable_sensor = hi6220_thermal_enable_sensor, | ||
505 | .disable_sensor = hi6220_thermal_disable_sensor, | ||
506 | .irq_handler = hi6220_thermal_irq_handler, | ||
507 | .probe = hi6220_thermal_probe, | ||
508 | }; | ||
509 | |||
510 | static const struct hisi_thermal_ops hi3660_ops = { | ||
511 | .get_temp = hi3660_thermal_get_temp, | ||
512 | .enable_sensor = hi3660_thermal_enable_sensor, | ||
513 | .disable_sensor = hi3660_thermal_disable_sensor, | ||
514 | .irq_handler = hi3660_thermal_irq_handler, | ||
515 | .probe = hi3660_thermal_probe, | ||
516 | }; | ||
517 | |||
505 | static const struct of_device_id of_hisi_thermal_match[] = { | 518 | static const struct of_device_id of_hisi_thermal_match[] = { |
506 | { | 519 | { |
507 | .compatible = "hisilicon,tsensor", | 520 | .compatible = "hisilicon,tsensor", |
508 | .data = hi6220_thermal_probe | 521 | .data = &hi6220_ops, |
509 | }, | 522 | }, |
510 | { | 523 | { |
511 | .compatible = "hisilicon,hi3660-tsensor", | 524 | .compatible = "hisilicon,hi3660-tsensor", |
512 | .data = hi3660_thermal_probe | 525 | .data = &hi3660_ops, |
513 | }, | 526 | }, |
514 | { /* end */ } | 527 | { /* end */ } |
515 | }; | 528 | }; |
@@ -527,7 +540,6 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, | |||
527 | static int hisi_thermal_probe(struct platform_device *pdev) | 540 | static int hisi_thermal_probe(struct platform_device *pdev) |
528 | { | 541 | { |
529 | struct hisi_thermal_data *data; | 542 | struct hisi_thermal_data *data; |
530 | int (*platform_probe)(struct hisi_thermal_data *); | ||
531 | struct device *dev = &pdev->dev; | 543 | struct device *dev = &pdev->dev; |
532 | int ret; | 544 | int ret; |
533 | 545 | ||
@@ -538,13 +550,9 @@ static int hisi_thermal_probe(struct platform_device *pdev) | |||
538 | data->pdev = pdev; | 550 | data->pdev = pdev; |
539 | platform_set_drvdata(pdev, data); | 551 | platform_set_drvdata(pdev, data); |
540 | 552 | ||
541 | platform_probe = of_device_get_match_data(dev); | 553 | data->ops = of_device_get_match_data(dev); |
542 | if (!platform_probe) { | ||
543 | dev_err(dev, "failed to get probe func\n"); | ||
544 | return -EINVAL; | ||
545 | } | ||
546 | 554 | ||
547 | ret = platform_probe(data); | 555 | ret = data->ops->probe(data); |
548 | if (ret) | 556 | if (ret) |
549 | return ret; | 557 | return ret; |
550 | 558 | ||
@@ -555,7 +563,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) | |||
555 | return ret; | 563 | return ret; |
556 | } | 564 | } |
557 | 565 | ||
558 | ret = data->enable_sensor(data); | 566 | ret = data->ops->enable_sensor(data); |
559 | if (ret) { | 567 | if (ret) { |
560 | dev_err(dev, "Failed to setup the sensor: %d\n", ret); | 568 | dev_err(dev, "Failed to setup the sensor: %d\n", ret); |
561 | return ret; | 569 | return ret; |
@@ -583,7 +591,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) | |||
583 | 591 | ||
584 | hisi_thermal_toggle_sensor(sensor, false); | 592 | hisi_thermal_toggle_sensor(sensor, false); |
585 | 593 | ||
586 | data->disable_sensor(data); | 594 | data->ops->disable_sensor(data); |
587 | 595 | ||
588 | return 0; | 596 | return 0; |
589 | } | 597 | } |
@@ -593,7 +601,7 @@ static int hisi_thermal_suspend(struct device *dev) | |||
593 | { | 601 | { |
594 | struct hisi_thermal_data *data = dev_get_drvdata(dev); | 602 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
595 | 603 | ||
596 | data->disable_sensor(data); | 604 | data->ops->disable_sensor(data); |
597 | 605 | ||
598 | return 0; | 606 | return 0; |
599 | } | 607 | } |
@@ -602,7 +610,7 @@ static int hisi_thermal_resume(struct device *dev) | |||
602 | { | 610 | { |
603 | struct hisi_thermal_data *data = dev_get_drvdata(dev); | 611 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
604 | 612 | ||
605 | return data->enable_sensor(data); | 613 | return data->ops->enable_sensor(data); |
606 | } | 614 | } |
607 | #endif | 615 | #endif |
608 | 616 | ||