imx_thermal.c (1ee14820fd8ee79c4fc191155f48c985f28040e2) | imx_thermal.c (7f4957be0d5b83c8964491863202136c916107ae) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2// 3// Copyright 2013 Freescale Semiconductor, Inc. 4 5#include <linux/clk.h> 6#include <linux/cpufreq.h> 7#include <linux/cpu_cooling.h> 8#include <linux/delay.h> --- 241 unchanged lines hidden (view full) --- 250{ 251 struct imx_thermal_data *data = tz->devdata; 252 const struct thermal_soc_data *soc_data = data->socdata; 253 struct regmap *map = data->tempmon; 254 unsigned int n_meas; 255 bool wait; 256 u32 val; 257 | 1// SPDX-License-Identifier: GPL-2.0 2// 3// Copyright 2013 Freescale Semiconductor, Inc. 4 5#include <linux/clk.h> 6#include <linux/cpufreq.h> 7#include <linux/cpu_cooling.h> 8#include <linux/delay.h> --- 241 unchanged lines hidden (view full) --- 250{ 251 struct imx_thermal_data *data = tz->devdata; 252 const struct thermal_soc_data *soc_data = data->socdata; 253 struct regmap *map = data->tempmon; 254 unsigned int n_meas; 255 bool wait; 256 u32 val; 257 |
258 if (tz->mode == THERMAL_DEVICE_ENABLED) { | 258 if (thermal_zone_device_is_enabled(tz)) { |
259 /* Check if a measurement is currently in progress */ 260 regmap_read(map, soc_data->temp_data, &val); 261 wait = !(val & soc_data->temp_valid_mask); 262 } else { 263 /* 264 * Every time we measure the temperature, we will power on the 265 * temperature sensor, enable measurements, take a reading, 266 * disable measurements, power off the temperature sensor. --- 10 unchanged lines hidden (view full) --- 277 * According to the temp sensor designers, it may require up to ~17us 278 * to complete a measurement. 279 */ 280 if (wait) 281 usleep_range(20, 50); 282 283 regmap_read(map, soc_data->temp_data, &val); 284 | 259 /* Check if a measurement is currently in progress */ 260 regmap_read(map, soc_data->temp_data, &val); 261 wait = !(val & soc_data->temp_valid_mask); 262 } else { 263 /* 264 * Every time we measure the temperature, we will power on the 265 * temperature sensor, enable measurements, take a reading, 266 * disable measurements, power off the temperature sensor. --- 10 unchanged lines hidden (view full) --- 277 * According to the temp sensor designers, it may require up to ~17us 278 * to complete a measurement. 279 */ 280 if (wait) 281 usleep_range(20, 50); 282 283 regmap_read(map, soc_data->temp_data, &val); 284 |
285 if (tz->mode != THERMAL_DEVICE_ENABLED) { | 285 if (!thermal_zone_device_is_enabled(tz)) { |
286 regmap_write(map, soc_data->sensor_ctrl + REG_CLR, 287 soc_data->measure_temp_mask); 288 regmap_write(map, soc_data->sensor_ctrl + REG_SET, 289 soc_data->power_down_mask); 290 } 291 292 if ((val & soc_data->temp_valid_mask) == 0) { 293 dev_dbg(&tz->device, "temp measurement never finished\n"); --- 66 unchanged lines hidden (view full) --- 360 tz->passive_delay = 0; 361 362 if (data->irq_enabled) { 363 disable_irq(data->irq); 364 data->irq_enabled = false; 365 } 366 } 367 | 286 regmap_write(map, soc_data->sensor_ctrl + REG_CLR, 287 soc_data->measure_temp_mask); 288 regmap_write(map, soc_data->sensor_ctrl + REG_SET, 289 soc_data->power_down_mask); 290 } 291 292 if ((val & soc_data->temp_valid_mask) == 0) { 293 dev_dbg(&tz->device, "temp measurement never finished\n"); --- 66 unchanged lines hidden (view full) --- 360 tz->passive_delay = 0; 361 362 if (data->irq_enabled) { 363 disable_irq(data->irq); 364 data->irq_enabled = false; 365 } 366 } 367 |
368 tz->mode = mode; 369 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 370 | |
371 return 0; 372} 373 374static int imx_get_trip_type(struct thermal_zone_device *tz, int trip, 375 enum thermal_trip_type *type) 376{ 377 *type = (trip == IMX_TRIP_PASSIVE) ? THERMAL_TRIP_PASSIVE : 378 THERMAL_TRIP_CRITICAL; --- 435 unchanged lines hidden (view full) --- 814 imx_set_panic_temp(data, data->temp_critical); 815 816 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, 817 data->socdata->power_down_mask); 818 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 819 data->socdata->measure_temp_mask); 820 821 data->irq_enabled = true; | 368 return 0; 369} 370 371static int imx_get_trip_type(struct thermal_zone_device *tz, int trip, 372 enum thermal_trip_type *type) 373{ 374 *type = (trip == IMX_TRIP_PASSIVE) ? THERMAL_TRIP_PASSIVE : 375 THERMAL_TRIP_CRITICAL; --- 435 unchanged lines hidden (view full) --- 811 imx_set_panic_temp(data, data->temp_critical); 812 813 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, 814 data->socdata->power_down_mask); 815 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 816 data->socdata->measure_temp_mask); 817 818 data->irq_enabled = true; |
822 data->tz->mode = THERMAL_DEVICE_ENABLED; | 819 ret = thermal_zone_device_enable(data->tz); 820 if (ret) 821 goto thermal_zone_unregister; |
823 824 ret = devm_request_threaded_irq(&pdev->dev, data->irq, 825 imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, 826 0, "imx_thermal", data); 827 if (ret < 0) { 828 dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); 829 goto thermal_zone_unregister; 830 } --- 25 unchanged lines hidden (view full) --- 856 imx_thermal_unregister_legacy_cooling(data); 857 858 return 0; 859} 860 861static int __maybe_unused imx_thermal_suspend(struct device *dev) 862{ 863 struct imx_thermal_data *data = dev_get_drvdata(dev); | 822 823 ret = devm_request_threaded_irq(&pdev->dev, data->irq, 824 imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, 825 0, "imx_thermal", data); 826 if (ret < 0) { 827 dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); 828 goto thermal_zone_unregister; 829 } --- 25 unchanged lines hidden (view full) --- 855 imx_thermal_unregister_legacy_cooling(data); 856 857 return 0; 858} 859 860static int __maybe_unused imx_thermal_suspend(struct device *dev) 861{ 862 struct imx_thermal_data *data = dev_get_drvdata(dev); |
864 struct regmap *map = data->tempmon; | 863 int ret; |
865 866 /* 867 * Need to disable thermal sensor, otherwise, when thermal core 868 * try to get temperature before thermal sensor resume, a wrong 869 * temperature will be read as the thermal sensor is powered | 864 865 /* 866 * Need to disable thermal sensor, otherwise, when thermal core 867 * try to get temperature before thermal sensor resume, a wrong 868 * temperature will be read as the thermal sensor is powered |
870 * down. | 869 * down. This is done in set_mode() operation called from 870 * thermal_zone_device_disable() |
871 */ | 871 */ |
872 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, 873 data->socdata->measure_temp_mask); 874 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 875 data->socdata->power_down_mask); 876 data->tz->mode = THERMAL_DEVICE_DISABLED; | 872 ret = thermal_zone_device_disable(data->tz); 873 if (ret) 874 return ret; |
877 clk_disable_unprepare(data->thermal_clk); 878 879 return 0; 880} 881 882static int __maybe_unused imx_thermal_resume(struct device *dev) 883{ 884 struct imx_thermal_data *data = dev_get_drvdata(dev); | 875 clk_disable_unprepare(data->thermal_clk); 876 877 return 0; 878} 879 880static int __maybe_unused imx_thermal_resume(struct device *dev) 881{ 882 struct imx_thermal_data *data = dev_get_drvdata(dev); |
885 struct regmap *map = data->tempmon; | |
886 int ret; 887 888 ret = clk_prepare_enable(data->thermal_clk); 889 if (ret) 890 return ret; 891 /* Enabled thermal sensor after resume */ | 883 int ret; 884 885 ret = clk_prepare_enable(data->thermal_clk); 886 if (ret) 887 return ret; 888 /* Enabled thermal sensor after resume */ |
892 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, 893 data->socdata->power_down_mask); 894 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, 895 data->socdata->measure_temp_mask); 896 data->tz->mode = THERMAL_DEVICE_ENABLED; | 889 ret = thermal_zone_device_enable(data->tz); 890 if (ret) 891 return ret; |
897 898 return 0; 899} 900 901static SIMPLE_DEV_PM_OPS(imx_thermal_pm_ops, 902 imx_thermal_suspend, imx_thermal_resume); 903 904static struct platform_driver imx_thermal = { --- 14 unchanged lines hidden --- | 892 893 return 0; 894} 895 896static SIMPLE_DEV_PM_OPS(imx_thermal_pm_ops, 897 imx_thermal_suspend, imx_thermal_resume); 898 899static struct platform_driver imx_thermal = { --- 14 unchanged lines hidden --- |