imx_thermal.c (31d1b7710262fba12282b24083f20dc76e0efc93) | imx_thermal.c (c589c56671c914fbd6b56a6f92dce80edbbfdada) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2// 3// Copyright 2013 Freescale Semiconductor, Inc. 4 5#include <linux/clk.h> 6#include <linux/cpu.h> 7#include <linux/cpufreq.h> 8#include <linux/cpu_cooling.h> --- 634 unchanged lines hidden (view full) --- 643static const struct of_device_id of_imx_thermal_match[] = { 644 { .compatible = "fsl,imx6q-tempmon", .data = &thermal_imx6q_data, }, 645 { .compatible = "fsl,imx6sx-tempmon", .data = &thermal_imx6sx_data, }, 646 { .compatible = "fsl,imx7d-tempmon", .data = &thermal_imx7d_data, }, 647 { /* end */ } 648}; 649MODULE_DEVICE_TABLE(of, of_imx_thermal_match); 650 | 1// SPDX-License-Identifier: GPL-2.0 2// 3// Copyright 2013 Freescale Semiconductor, Inc. 4 5#include <linux/clk.h> 6#include <linux/cpu.h> 7#include <linux/cpufreq.h> 8#include <linux/cpu_cooling.h> --- 634 unchanged lines hidden (view full) --- 643static const struct of_device_id of_imx_thermal_match[] = { 644 { .compatible = "fsl,imx6q-tempmon", .data = &thermal_imx6q_data, }, 645 { .compatible = "fsl,imx6sx-tempmon", .data = &thermal_imx6sx_data, }, 646 { .compatible = "fsl,imx7d-tempmon", .data = &thermal_imx7d_data, }, 647 { /* end */ } 648}; 649MODULE_DEVICE_TABLE(of, of_imx_thermal_match); 650 |
651#ifdef CONFIG_CPU_FREQ |
|
651/* 652 * Create cooling device in case no #cooling-cells property is available in 653 * CPU node 654 */ 655static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) 656{ | 652/* 653 * Create cooling device in case no #cooling-cells property is available in 654 * CPU node 655 */ 656static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) 657{ |
657 struct device_node *np = of_get_cpu_node(data->policy->cpu, NULL); | 658 struct device_node *np; |
658 int ret; 659 | 659 int ret; 660 |
661 data->policy = cpufreq_cpu_get(0); 662 if (!data->policy) { 663 pr_debug("%s: CPUFreq policy not found\n", __func__); 664 return -EPROBE_DEFER; 665 } 666 667 np = of_get_cpu_node(data->policy->cpu, NULL); 668 |
|
660 if (!np || !of_find_property(np, "#cooling-cells", NULL)) { 661 data->cdev = cpufreq_cooling_register(data->policy); 662 if (IS_ERR(data->cdev)) { 663 ret = PTR_ERR(data->cdev); 664 cpufreq_cpu_put(data->policy); 665 return ret; 666 } 667 } 668 669 return 0; 670} 671 | 669 if (!np || !of_find_property(np, "#cooling-cells", NULL)) { 670 data->cdev = cpufreq_cooling_register(data->policy); 671 if (IS_ERR(data->cdev)) { 672 ret = PTR_ERR(data->cdev); 673 cpufreq_cpu_put(data->policy); 674 return ret; 675 } 676 } 677 678 return 0; 679} 680 |
681static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data) 682{ 683 cpufreq_cooling_unregister(data->cdev); 684 cpufreq_cpu_put(data->policy); 685} 686 687#else 688 689static inline int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) 690{ 691 return 0; 692} 693 694static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data) 695{ 696} 697#endif 698 |
|
672static int imx_thermal_probe(struct platform_device *pdev) 673{ 674 struct imx_thermal_data *data; 675 struct regmap *map; 676 int measure_freq; 677 int ret; 678 679 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); --- 58 unchanged lines hidden (view full) --- 738 regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, 739 data->socdata->measure_freq_mask); 740 if (data->socdata->version != TEMPMON_IMX7D) 741 regmap_write(map, IMX6_MISC0 + REG_SET, 742 IMX6_MISC0_REFTOP_SELBIASOFF); 743 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 744 data->socdata->power_down_mask); 745 | 699static int imx_thermal_probe(struct platform_device *pdev) 700{ 701 struct imx_thermal_data *data; 702 struct regmap *map; 703 int measure_freq; 704 int ret; 705 706 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); --- 58 unchanged lines hidden (view full) --- 765 regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, 766 data->socdata->measure_freq_mask); 767 if (data->socdata->version != TEMPMON_IMX7D) 768 regmap_write(map, IMX6_MISC0 + REG_SET, 769 IMX6_MISC0_REFTOP_SELBIASOFF); 770 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 771 data->socdata->power_down_mask); 772 |
746 data->policy = cpufreq_cpu_get(0); 747 if (!data->policy) { 748 pr_debug("%s: CPUFreq policy not found\n", __func__); 749 return -EPROBE_DEFER; 750 } 751 | |
752 ret = imx_thermal_register_legacy_cooling(data); 753 if (ret) { | 773 ret = imx_thermal_register_legacy_cooling(data); 774 if (ret) { |
775 if (ret == -EPROBE_DEFER) 776 return ret; 777 |
|
754 dev_err(&pdev->dev, 755 "failed to register cpufreq cooling device: %d\n", ret); 756 return ret; 757 } 758 759 data->thermal_clk = devm_clk_get(&pdev->dev, NULL); 760 if (IS_ERR(data->thermal_clk)) { 761 ret = PTR_ERR(data->thermal_clk); 762 if (ret != -EPROBE_DEFER) 763 dev_err(&pdev->dev, 764 "failed to get thermal clk: %d\n", ret); | 778 dev_err(&pdev->dev, 779 "failed to register cpufreq cooling device: %d\n", ret); 780 return ret; 781 } 782 783 data->thermal_clk = devm_clk_get(&pdev->dev, NULL); 784 if (IS_ERR(data->thermal_clk)) { 785 ret = PTR_ERR(data->thermal_clk); 786 if (ret != -EPROBE_DEFER) 787 dev_err(&pdev->dev, 788 "failed to get thermal clk: %d\n", ret); |
765 goto cpufreq_put; | 789 goto legacy_cleanup; |
766 } 767 768 /* 769 * Thermal sensor needs clk on to get correct value, normally 770 * we should enable its clk before taking measurement and disable 771 * clk after measurement is done, but if alarm function is enabled, 772 * hardware will auto measure the temperature periodically, so we 773 * need to keep the clk always on for alarm function. 774 */ 775 ret = clk_prepare_enable(data->thermal_clk); 776 if (ret) { 777 dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret); | 790 } 791 792 /* 793 * Thermal sensor needs clk on to get correct value, normally 794 * we should enable its clk before taking measurement and disable 795 * clk after measurement is done, but if alarm function is enabled, 796 * hardware will auto measure the temperature periodically, so we 797 * need to keep the clk always on for alarm function. 798 */ 799 ret = clk_prepare_enable(data->thermal_clk); 800 if (ret) { 801 dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret); |
778 goto cpufreq_put; | 802 goto legacy_cleanup; |
779 } 780 781 data->tz = thermal_zone_device_register("imx_thermal_zone", 782 IMX_TRIP_NUM, 783 BIT(IMX_TRIP_PASSIVE), data, 784 &imx_tz_ops, NULL, 785 IMX_PASSIVE_DELAY, 786 IMX_POLLING_DELAY); --- 37 unchanged lines hidden (view full) --- 824 } 825 826 return 0; 827 828thermal_zone_unregister: 829 thermal_zone_device_unregister(data->tz); 830clk_disable: 831 clk_disable_unprepare(data->thermal_clk); | 803 } 804 805 data->tz = thermal_zone_device_register("imx_thermal_zone", 806 IMX_TRIP_NUM, 807 BIT(IMX_TRIP_PASSIVE), data, 808 &imx_tz_ops, NULL, 809 IMX_PASSIVE_DELAY, 810 IMX_POLLING_DELAY); --- 37 unchanged lines hidden (view full) --- 848 } 849 850 return 0; 851 852thermal_zone_unregister: 853 thermal_zone_device_unregister(data->tz); 854clk_disable: 855 clk_disable_unprepare(data->thermal_clk); |
832cpufreq_put: 833 cpufreq_cooling_unregister(data->cdev); 834 cpufreq_cpu_put(data->policy); | 856legacy_cleanup: 857 imx_thermal_unregister_legacy_cooling(data); |
835 836 return ret; 837} 838 839static int imx_thermal_remove(struct platform_device *pdev) 840{ 841 struct imx_thermal_data *data = platform_get_drvdata(pdev); 842 struct regmap *map = data->tempmon; --- 74 unchanged lines hidden --- | 858 859 return ret; 860} 861 862static int imx_thermal_remove(struct platform_device *pdev) 863{ 864 struct imx_thermal_data *data = platform_get_drvdata(pdev); 865 struct regmap *map = data->tempmon; --- 74 unchanged lines hidden --- |