Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux

Pull ACPI & Thermal updates from Len Brown:
"The generic Linux thermal layer is gaining some new capabilities
(generic cooling via cpufreq) and some new customers (ARM).

Also, an ACPI EC bug fix plus a regression fix."

* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: (30 commits)
tools/power/acpi/acpidump: remove duplicated include from acpidump.c
ACPI idle, CPU hotplug: Fix NULL pointer dereference during hotplug
cpuidle / ACPI: fix potential NULL pointer dereference
ACPI: EC: Add a quirk for CLEVO M720T/M730T laptop
ACPI: EC: Make the GPE storm threshold a module parameter
thermal: Exynos: Fix NULL pointer dereference in exynos_unregister_thermal()
Thermal: Fix bug on cpu_cooling, cooling device's id conflict problem.
thermal: exynos: Use devm_* functions
ARM: exynos: add thermal sensor driver platform data support
thermal: exynos: register the tmu sensor with the kernel thermal layer
thermal: exynos5: add exynos5250 thermal sensor driver support
hwmon: exynos4: move thermal sensor driver to driver/thermal directory
thermal: add generic cpufreq cooling implementation
Fix a build error.
thermal: Fix potential NULL pointer accesses
thermal: add Renesas R-Car thermal sensor support
thermal: fix potential out-of-bounds memory access
Thermal: Introduce locking for cdev.thermal_instances list.
Thermal: Unify the code for both active and passive cooling
Thermal: Introduce simple arbitrator for setting device cooling state
...

+2204 -735
+3 -32
Documentation/hwmon/exynos4_tmu Documentation/thermal/exynos_thermal
··· 46 46 The threshold and each trigger_level are set 47 47 through the corresponding registers. 48 48 49 - When an interrupt occurs, this driver notify user space of 50 - one of four threshold levels for the interrupt 51 - through kobject_uevent_env and sysfs_notify functions. 49 + When an interrupt occurs, this driver notify kernel thermal framework 50 + with the function exynos4_report_trigger. 52 51 Although an interrupt condition for level_0 can be set, 53 - it is not notified to user space through sysfs_notify function. 54 - 55 - Sysfs Interface 56 - --------------- 57 - name name of the temperature sensor 58 - RO 59 - 60 - temp1_input temperature 61 - RO 62 - 63 - temp1_max temperature for level_1 interrupt 64 - RO 65 - 66 - temp1_crit temperature for level_2 interrupt 67 - RO 68 - 69 - temp1_emergency temperature for level_3 interrupt 70 - RO 71 - 72 - temp1_max_alarm alarm for level_1 interrupt 73 - RO 74 - 75 - temp1_crit_alarm 76 - alarm for level_2 interrupt 77 - RO 78 - 79 - temp1_emergency_alarm 80 - alarm for level_3 interrupt 81 - RO 52 + it can be used to synchronize the cooling action.
+32
Documentation/thermal/cpu-cooling-api.txt
··· 1 + CPU cooling APIs How To 2 + =================================== 3 + 4 + Written by Amit Daniel Kachhap <amit.kachhap@linaro.org> 5 + 6 + Updated: 12 May 2012 7 + 8 + Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) 9 + 10 + 0. Introduction 11 + 12 + The generic cpu cooling(freq clipping) provides registration/unregistration APIs 13 + to the caller. The binding of the cooling devices to the trip point is left for 14 + the user. The registration APIs returns the cooling device pointer. 15 + 16 + 1. cpu cooling APIs 17 + 18 + 1.1 cpufreq registration/unregistration APIs 19 + 1.1.1 struct thermal_cooling_device *cpufreq_cooling_register( 20 + struct cpumask *clip_cpus) 21 + 22 + This interface function registers the cpufreq cooling device with the name 23 + "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 24 + cooling devices. 25 + 26 + clip_cpus: cpumask of cpus where the frequency constraints will happen. 27 + 28 + 1.1.2 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) 29 + 30 + This interface function unregisters the "thermal-cpufreq-%x" cooling device. 31 + 32 + cdev: Cooling device pointer which has to be unregistered.
+8 -1
Documentation/thermal/sysfs-api.txt
··· 84 84 85 85 1.3 interface for binding a thermal zone device with a thermal cooling device 86 86 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 87 - int trip, struct thermal_cooling_device *cdev); 87 + int trip, struct thermal_cooling_device *cdev, 88 + unsigned long upper, unsigned long lower); 88 89 89 90 This interface function bind a thermal cooling device to the certain trip 90 91 point of a thermal zone device. ··· 94 93 cdev: thermal cooling device 95 94 trip: indicates which trip point the cooling devices is associated with 96 95 in this thermal zone. 96 + upper:the Maximum cooling state for this trip point. 97 + THERMAL_NO_LIMIT means no upper limit, 98 + and the cooling device can be in max_state. 99 + lower:the Minimum cooling state can be used for this trip point. 100 + THERMAL_NO_LIMIT means no lower limit, 101 + and the cooling device can be in cooling state 0. 97 102 98 103 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, 99 104 int trip, struct thermal_cooling_device *cdev);
+25 -5
drivers/acpi/ec.c
··· 71 71 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 72 72 #define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */ 73 73 74 - #define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts 75 - per one transaction */ 76 - 77 74 enum { 78 75 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 79 76 EC_FLAGS_GPE_STORM, /* GPE storm detected */ ··· 83 86 static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY; 84 87 module_param(ec_delay, uint, 0644); 85 88 MODULE_PARM_DESC(ec_delay, "Timeout(ms) waited until an EC command completes"); 89 + 90 + /* 91 + * If the number of false interrupts per one transaction exceeds 92 + * this threshold, will think there is a GPE storm happened and 93 + * will disable the GPE for normal transaction. 94 + */ 95 + static unsigned int ec_storm_threshold __read_mostly = 8; 96 + module_param(ec_storm_threshold, uint, 0644); 97 + MODULE_PARM_DESC(ec_storm_threshold, "Maxim false GPE numbers not considered as GPE storm"); 86 98 87 99 /* If we find an EC via the ECDT, we need to keep a ptr to its context */ 88 100 /* External interfaces use first EC only, so remember */ ··· 325 319 msleep(1); 326 320 /* It is safe to enable the GPE outside of the transaction. */ 327 321 acpi_enable_gpe(NULL, ec->gpe); 328 - } else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) { 322 + } else if (t->irq_count > ec_storm_threshold) { 329 323 pr_info(PREFIX "GPE storm detected, " 330 324 "transactions will use polling mode\n"); 331 325 set_bit(EC_FLAGS_GPE_STORM, &ec->flags); ··· 930 924 return 0; 931 925 } 932 926 927 + /* 928 + * Clevo M720 notebook actually works ok with IRQ mode, if we lifted 929 + * the GPE storm threshold back to 20 930 + */ 931 + static int ec_enlarge_storm_threshold(const struct dmi_system_id *id) 932 + { 933 + pr_debug("Setting the EC GPE storm threshold to 20\n"); 934 + ec_storm_threshold = 20; 935 + return 0; 936 + } 937 + 933 938 static struct dmi_system_id __initdata ec_dmi_table[] = { 934 939 { 935 940 ec_skip_dsdt_scan, "Compal JFL92", { ··· 972 955 { 973 956 ec_validate_ecdt, "ASUS hardware", { 974 957 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc.") }, NULL}, 958 + { 959 + ec_enlarge_storm_threshold, "CLEVO hardware", { 960 + DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."), 961 + DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL}, 975 962 {}, 976 963 }; 977 - 978 964 979 965 int __init acpi_ec_ecdt_probe(void) 980 966 {
+2 -1
drivers/acpi/processor_idle.c
··· 1132 1132 int acpi_processor_hotplug(struct acpi_processor *pr) 1133 1133 { 1134 1134 int ret = 0; 1135 - struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id); 1135 + struct cpuidle_device *dev; 1136 1136 1137 1137 if (disabled_by_idle_boot_param()) 1138 1138 return 0; ··· 1147 1147 if (!pr->flags.power_setup_done) 1148 1148 return -ENODEV; 1149 1149 1150 + dev = per_cpu(acpi_cpuidle_device, pr->id); 1150 1151 cpuidle_pause_and_lock(); 1151 1152 cpuidle_disable_device(dev); 1152 1153 acpi_processor_get_power_info(pr);
+71 -22
drivers/acpi/thermal.c
··· 708 708 return -EINVAL; 709 709 } 710 710 711 + static int thermal_get_trend(struct thermal_zone_device *thermal, 712 + int trip, enum thermal_trend *trend) 713 + { 714 + struct acpi_thermal *tz = thermal->devdata; 715 + enum thermal_trip_type type; 716 + int i; 717 + 718 + if (thermal_get_trip_type(thermal, trip, &type)) 719 + return -EINVAL; 720 + 721 + if (type == THERMAL_TRIP_ACTIVE) { 722 + /* aggressive active cooling */ 723 + *trend = THERMAL_TREND_RAISING; 724 + return 0; 725 + } 726 + 727 + /* 728 + * tz->temperature has already been updated by generic thermal layer, 729 + * before this callback being invoked 730 + */ 731 + i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) 732 + + (tz->trips.passive.tc2 733 + * (tz->temperature - tz->trips.passive.temperature)); 734 + 735 + if (i > 0) 736 + *trend = THERMAL_TREND_RAISING; 737 + else if (i < 0) 738 + *trend = THERMAL_TREND_DROPPING; 739 + else 740 + *trend = THERMAL_TREND_STABLE; 741 + return 0; 742 + } 743 + 744 + 711 745 static int thermal_notify(struct thermal_zone_device *thermal, int trip, 712 746 enum thermal_trip_type trip_type) 713 747 { ··· 765 731 return 0; 766 732 } 767 733 768 - typedef int (*cb)(struct thermal_zone_device *, int, 769 - struct thermal_cooling_device *); 770 734 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, 771 735 struct thermal_cooling_device *cdev, 772 - cb action) 736 + bool bind) 773 737 { 774 738 struct acpi_device *device = cdev->devdata; 775 739 struct acpi_thermal *tz = thermal->devdata; ··· 791 759 i++) { 792 760 handle = tz->trips.passive.devices.handles[i]; 793 761 status = acpi_bus_get_device(handle, &dev); 794 - if (ACPI_SUCCESS(status) && (dev == device)) { 795 - result = action(thermal, trip, cdev); 796 - if (result) 797 - goto failed; 798 - } 762 + if (ACPI_FAILURE(status) || dev != device) 763 + continue; 764 + if (bind) 765 + result = 766 + thermal_zone_bind_cooling_device 767 + (thermal, trip, cdev, 768 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 769 + else 770 + result = 771 + thermal_zone_unbind_cooling_device 772 + (thermal, trip, cdev); 773 + if (result) 774 + goto failed; 799 775 } 800 776 } 801 777 ··· 816 776 j++) { 817 777 handle = tz->trips.active[i].devices.handles[j]; 818 778 status = acpi_bus_get_device(handle, &dev); 819 - if (ACPI_SUCCESS(status) && (dev == device)) { 820 - result = action(thermal, trip, cdev); 821 - if (result) 822 - goto failed; 823 - } 779 + if (ACPI_FAILURE(status) || dev != device) 780 + continue; 781 + if (bind) 782 + result = thermal_zone_bind_cooling_device 783 + (thermal, trip, cdev, 784 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 785 + else 786 + result = thermal_zone_unbind_cooling_device 787 + (thermal, trip, cdev); 788 + if (result) 789 + goto failed; 824 790 } 825 791 } 826 792 ··· 834 788 handle = tz->devices.handles[i]; 835 789 status = acpi_bus_get_device(handle, &dev); 836 790 if (ACPI_SUCCESS(status) && (dev == device)) { 837 - result = action(thermal, -1, cdev); 791 + if (bind) 792 + result = thermal_zone_bind_cooling_device 793 + (thermal, -1, cdev, 794 + THERMAL_NO_LIMIT, 795 + THERMAL_NO_LIMIT); 796 + else 797 + result = thermal_zone_unbind_cooling_device 798 + (thermal, -1, cdev); 838 799 if (result) 839 800 goto failed; 840 801 } ··· 855 802 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, 856 803 struct thermal_cooling_device *cdev) 857 804 { 858 - return acpi_thermal_cooling_device_cb(thermal, cdev, 859 - thermal_zone_bind_cooling_device); 805 + return acpi_thermal_cooling_device_cb(thermal, cdev, true); 860 806 } 861 807 862 808 static int 863 809 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, 864 810 struct thermal_cooling_device *cdev) 865 811 { 866 - return acpi_thermal_cooling_device_cb(thermal, cdev, 867 - thermal_zone_unbind_cooling_device); 812 + return acpi_thermal_cooling_device_cb(thermal, cdev, false); 868 813 } 869 814 870 815 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { ··· 874 823 .get_trip_type = thermal_get_trip_type, 875 824 .get_trip_temp = thermal_get_trip_temp, 876 825 .get_crit_temp = thermal_get_crit_temp, 826 + .get_trend = thermal_get_trend, 877 827 .notify = thermal_notify, 878 828 }; 879 829 ··· 901 849 tz->thermal_zone = 902 850 thermal_zone_device_register("acpitz", trips, 0, tz, 903 851 &acpi_thermal_zone_ops, 904 - tz->trips.passive.tc1, 905 - tz->trips.passive.tc2, 906 852 tz->trips.passive.tsp*100, 907 853 tz->polling_frequency*100); 908 854 else 909 855 tz->thermal_zone = 910 856 thermal_zone_device_register("acpitz", trips, 0, tz, 911 - &acpi_thermal_zone_ops, 912 - 0, 0, 0, 857 + &acpi_thermal_zone_ops, 0, 913 858 tz->polling_frequency*100); 914 859 if (IS_ERR(tz->thermal_zone)) 915 860 return -ENODEV;
+1 -1
drivers/cpuidle/cpuidle.c
··· 368 368 */ 369 369 void cpuidle_disable_device(struct cpuidle_device *dev) 370 370 { 371 - if (!dev->enabled) 371 + if (!dev || !dev->enabled) 372 372 return; 373 373 if (!cpuidle_get_driver() || !cpuidle_curr_governor) 374 374 return;
-10
drivers/hwmon/Kconfig
··· 334 334 This driver can also be built as module. If so, the module 335 335 will be called da9052-hwmon. 336 336 337 - config SENSORS_EXYNOS4_TMU 338 - tristate "Temperature sensor on Samsung EXYNOS4" 339 - depends on ARCH_EXYNOS4 340 - help 341 - If you say yes here you get support for TMU (Thermal Management 342 - Unit) on SAMSUNG EXYNOS4 series of SoC. 343 - 344 - This driver can also be built as a module. If so, the module 345 - will be called exynos4-tmu. 346 - 347 337 config SENSORS_I5K_AMB 348 338 tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets" 349 339 depends on PCI
-1
drivers/hwmon/Makefile
··· 50 50 obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o 51 51 obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o 52 52 obj-$(CONFIG_SENSORS_EMC6W201) += emc6w201.o 53 - obj-$(CONFIG_SENSORS_EXYNOS4_TMU) += exynos4_tmu.o 54 53 obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 55 54 obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o 56 55 obj-$(CONFIG_SENSORS_F75375S) += f75375s.o
-518
drivers/hwmon/exynos4_tmu.c
··· 1 - /* 2 - * exynos4_tmu.c - Samsung EXYNOS4 TMU (Thermal Management Unit) 3 - * 4 - * Copyright (C) 2011 Samsung Electronics 5 - * Donggeun Kim <dg77.kim@samsung.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by 9 - * the Free Software Foundation; either version 2 of the License, or 10 - * (at your option) any later version. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License 18 - * along with this program; if not, write to the Free Software 19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 - * 21 - */ 22 - 23 - #include <linux/module.h> 24 - #include <linux/err.h> 25 - #include <linux/kernel.h> 26 - #include <linux/slab.h> 27 - #include <linux/platform_device.h> 28 - #include <linux/interrupt.h> 29 - #include <linux/clk.h> 30 - #include <linux/workqueue.h> 31 - #include <linux/sysfs.h> 32 - #include <linux/kobject.h> 33 - #include <linux/io.h> 34 - #include <linux/mutex.h> 35 - 36 - #include <linux/hwmon.h> 37 - #include <linux/hwmon-sysfs.h> 38 - 39 - #include <linux/platform_data/exynos4_tmu.h> 40 - 41 - #define EXYNOS4_TMU_REG_TRIMINFO 0x0 42 - #define EXYNOS4_TMU_REG_CONTROL 0x20 43 - #define EXYNOS4_TMU_REG_STATUS 0x28 44 - #define EXYNOS4_TMU_REG_CURRENT_TEMP 0x40 45 - #define EXYNOS4_TMU_REG_THRESHOLD_TEMP 0x44 46 - #define EXYNOS4_TMU_REG_TRIG_LEVEL0 0x50 47 - #define EXYNOS4_TMU_REG_TRIG_LEVEL1 0x54 48 - #define EXYNOS4_TMU_REG_TRIG_LEVEL2 0x58 49 - #define EXYNOS4_TMU_REG_TRIG_LEVEL3 0x5C 50 - #define EXYNOS4_TMU_REG_PAST_TEMP0 0x60 51 - #define EXYNOS4_TMU_REG_PAST_TEMP1 0x64 52 - #define EXYNOS4_TMU_REG_PAST_TEMP2 0x68 53 - #define EXYNOS4_TMU_REG_PAST_TEMP3 0x6C 54 - #define EXYNOS4_TMU_REG_INTEN 0x70 55 - #define EXYNOS4_TMU_REG_INTSTAT 0x74 56 - #define EXYNOS4_TMU_REG_INTCLEAR 0x78 57 - 58 - #define EXYNOS4_TMU_GAIN_SHIFT 8 59 - #define EXYNOS4_TMU_REF_VOLTAGE_SHIFT 24 60 - 61 - #define EXYNOS4_TMU_TRIM_TEMP_MASK 0xff 62 - #define EXYNOS4_TMU_CORE_ON 3 63 - #define EXYNOS4_TMU_CORE_OFF 2 64 - #define EXYNOS4_TMU_DEF_CODE_TO_TEMP_OFFSET 50 65 - #define EXYNOS4_TMU_TRIG_LEVEL0_MASK 0x1 66 - #define EXYNOS4_TMU_TRIG_LEVEL1_MASK 0x10 67 - #define EXYNOS4_TMU_TRIG_LEVEL2_MASK 0x100 68 - #define EXYNOS4_TMU_TRIG_LEVEL3_MASK 0x1000 69 - #define EXYNOS4_TMU_INTCLEAR_VAL 0x1111 70 - 71 - struct exynos4_tmu_data { 72 - struct exynos4_tmu_platform_data *pdata; 73 - struct device *hwmon_dev; 74 - struct resource *mem; 75 - void __iomem *base; 76 - int irq; 77 - struct work_struct irq_work; 78 - struct mutex lock; 79 - struct clk *clk; 80 - u8 temp_error1, temp_error2; 81 - }; 82 - 83 - /* 84 - * TMU treats temperature as a mapped temperature code. 85 - * The temperature is converted differently depending on the calibration type. 86 - */ 87 - static int temp_to_code(struct exynos4_tmu_data *data, u8 temp) 88 - { 89 - struct exynos4_tmu_platform_data *pdata = data->pdata; 90 - int temp_code; 91 - 92 - /* temp should range between 25 and 125 */ 93 - if (temp < 25 || temp > 125) { 94 - temp_code = -EINVAL; 95 - goto out; 96 - } 97 - 98 - switch (pdata->cal_type) { 99 - case TYPE_TWO_POINT_TRIMMING: 100 - temp_code = (temp - 25) * 101 - (data->temp_error2 - data->temp_error1) / 102 - (85 - 25) + data->temp_error1; 103 - break; 104 - case TYPE_ONE_POINT_TRIMMING: 105 - temp_code = temp + data->temp_error1 - 25; 106 - break; 107 - default: 108 - temp_code = temp + EXYNOS4_TMU_DEF_CODE_TO_TEMP_OFFSET; 109 - break; 110 - } 111 - out: 112 - return temp_code; 113 - } 114 - 115 - /* 116 - * Calculate a temperature value from a temperature code. 117 - * The unit of the temperature is degree Celsius. 118 - */ 119 - static int code_to_temp(struct exynos4_tmu_data *data, u8 temp_code) 120 - { 121 - struct exynos4_tmu_platform_data *pdata = data->pdata; 122 - int temp; 123 - 124 - /* temp_code should range between 75 and 175 */ 125 - if (temp_code < 75 || temp_code > 175) { 126 - temp = -ENODATA; 127 - goto out; 128 - } 129 - 130 - switch (pdata->cal_type) { 131 - case TYPE_TWO_POINT_TRIMMING: 132 - temp = (temp_code - data->temp_error1) * (85 - 25) / 133 - (data->temp_error2 - data->temp_error1) + 25; 134 - break; 135 - case TYPE_ONE_POINT_TRIMMING: 136 - temp = temp_code - data->temp_error1 + 25; 137 - break; 138 - default: 139 - temp = temp_code - EXYNOS4_TMU_DEF_CODE_TO_TEMP_OFFSET; 140 - break; 141 - } 142 - out: 143 - return temp; 144 - } 145 - 146 - static int exynos4_tmu_initialize(struct platform_device *pdev) 147 - { 148 - struct exynos4_tmu_data *data = platform_get_drvdata(pdev); 149 - struct exynos4_tmu_platform_data *pdata = data->pdata; 150 - unsigned int status, trim_info; 151 - int ret = 0, threshold_code; 152 - 153 - mutex_lock(&data->lock); 154 - clk_enable(data->clk); 155 - 156 - status = readb(data->base + EXYNOS4_TMU_REG_STATUS); 157 - if (!status) { 158 - ret = -EBUSY; 159 - goto out; 160 - } 161 - 162 - /* Save trimming info in order to perform calibration */ 163 - trim_info = readl(data->base + EXYNOS4_TMU_REG_TRIMINFO); 164 - data->temp_error1 = trim_info & EXYNOS4_TMU_TRIM_TEMP_MASK; 165 - data->temp_error2 = ((trim_info >> 8) & EXYNOS4_TMU_TRIM_TEMP_MASK); 166 - 167 - /* Write temperature code for threshold */ 168 - threshold_code = temp_to_code(data, pdata->threshold); 169 - if (threshold_code < 0) { 170 - ret = threshold_code; 171 - goto out; 172 - } 173 - writeb(threshold_code, 174 - data->base + EXYNOS4_TMU_REG_THRESHOLD_TEMP); 175 - 176 - writeb(pdata->trigger_levels[0], 177 - data->base + EXYNOS4_TMU_REG_TRIG_LEVEL0); 178 - writeb(pdata->trigger_levels[1], 179 - data->base + EXYNOS4_TMU_REG_TRIG_LEVEL1); 180 - writeb(pdata->trigger_levels[2], 181 - data->base + EXYNOS4_TMU_REG_TRIG_LEVEL2); 182 - writeb(pdata->trigger_levels[3], 183 - data->base + EXYNOS4_TMU_REG_TRIG_LEVEL3); 184 - 185 - writel(EXYNOS4_TMU_INTCLEAR_VAL, 186 - data->base + EXYNOS4_TMU_REG_INTCLEAR); 187 - out: 188 - clk_disable(data->clk); 189 - mutex_unlock(&data->lock); 190 - 191 - return ret; 192 - } 193 - 194 - static void exynos4_tmu_control(struct platform_device *pdev, bool on) 195 - { 196 - struct exynos4_tmu_data *data = platform_get_drvdata(pdev); 197 - struct exynos4_tmu_platform_data *pdata = data->pdata; 198 - unsigned int con, interrupt_en; 199 - 200 - mutex_lock(&data->lock); 201 - clk_enable(data->clk); 202 - 203 - con = pdata->reference_voltage << EXYNOS4_TMU_REF_VOLTAGE_SHIFT | 204 - pdata->gain << EXYNOS4_TMU_GAIN_SHIFT; 205 - if (on) { 206 - con |= EXYNOS4_TMU_CORE_ON; 207 - interrupt_en = pdata->trigger_level3_en << 12 | 208 - pdata->trigger_level2_en << 8 | 209 - pdata->trigger_level1_en << 4 | 210 - pdata->trigger_level0_en; 211 - } else { 212 - con |= EXYNOS4_TMU_CORE_OFF; 213 - interrupt_en = 0; /* Disable all interrupts */ 214 - } 215 - writel(interrupt_en, data->base + EXYNOS4_TMU_REG_INTEN); 216 - writel(con, data->base + EXYNOS4_TMU_REG_CONTROL); 217 - 218 - clk_disable(data->clk); 219 - mutex_unlock(&data->lock); 220 - } 221 - 222 - static int exynos4_tmu_read(struct exynos4_tmu_data *data) 223 - { 224 - u8 temp_code; 225 - int temp; 226 - 227 - mutex_lock(&data->lock); 228 - clk_enable(data->clk); 229 - 230 - temp_code = readb(data->base + EXYNOS4_TMU_REG_CURRENT_TEMP); 231 - temp = code_to_temp(data, temp_code); 232 - 233 - clk_disable(data->clk); 234 - mutex_unlock(&data->lock); 235 - 236 - return temp; 237 - } 238 - 239 - static void exynos4_tmu_work(struct work_struct *work) 240 - { 241 - struct exynos4_tmu_data *data = container_of(work, 242 - struct exynos4_tmu_data, irq_work); 243 - 244 - mutex_lock(&data->lock); 245 - clk_enable(data->clk); 246 - 247 - writel(EXYNOS4_TMU_INTCLEAR_VAL, data->base + EXYNOS4_TMU_REG_INTCLEAR); 248 - 249 - kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE); 250 - 251 - enable_irq(data->irq); 252 - 253 - clk_disable(data->clk); 254 - mutex_unlock(&data->lock); 255 - } 256 - 257 - static irqreturn_t exynos4_tmu_irq(int irq, void *id) 258 - { 259 - struct exynos4_tmu_data *data = id; 260 - 261 - disable_irq_nosync(irq); 262 - schedule_work(&data->irq_work); 263 - 264 - return IRQ_HANDLED; 265 - } 266 - 267 - static ssize_t exynos4_tmu_show_name(struct device *dev, 268 - struct device_attribute *attr, char *buf) 269 - { 270 - return sprintf(buf, "exynos4-tmu\n"); 271 - } 272 - 273 - static ssize_t exynos4_tmu_show_temp(struct device *dev, 274 - struct device_attribute *attr, char *buf) 275 - { 276 - struct exynos4_tmu_data *data = dev_get_drvdata(dev); 277 - int ret; 278 - 279 - ret = exynos4_tmu_read(data); 280 - if (ret < 0) 281 - return ret; 282 - 283 - /* convert from degree Celsius to millidegree Celsius */ 284 - return sprintf(buf, "%d\n", ret * 1000); 285 - } 286 - 287 - static ssize_t exynos4_tmu_show_alarm(struct device *dev, 288 - struct device_attribute *devattr, char *buf) 289 - { 290 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 291 - struct exynos4_tmu_data *data = dev_get_drvdata(dev); 292 - struct exynos4_tmu_platform_data *pdata = data->pdata; 293 - int temp; 294 - unsigned int trigger_level; 295 - 296 - temp = exynos4_tmu_read(data); 297 - if (temp < 0) 298 - return temp; 299 - 300 - trigger_level = pdata->threshold + pdata->trigger_levels[attr->index]; 301 - 302 - return sprintf(buf, "%d\n", !!(temp > trigger_level)); 303 - } 304 - 305 - static ssize_t exynos4_tmu_show_level(struct device *dev, 306 - struct device_attribute *devattr, char *buf) 307 - { 308 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 309 - struct exynos4_tmu_data *data = dev_get_drvdata(dev); 310 - struct exynos4_tmu_platform_data *pdata = data->pdata; 311 - unsigned int temp = pdata->threshold + 312 - pdata->trigger_levels[attr->index]; 313 - 314 - return sprintf(buf, "%u\n", temp * 1000); 315 - } 316 - 317 - static DEVICE_ATTR(name, S_IRUGO, exynos4_tmu_show_name, NULL); 318 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, exynos4_tmu_show_temp, NULL, 0); 319 - 320 - static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, 321 - exynos4_tmu_show_alarm, NULL, 1); 322 - static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, 323 - exynos4_tmu_show_alarm, NULL, 2); 324 - static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, 325 - exynos4_tmu_show_alarm, NULL, 3); 326 - 327 - static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, exynos4_tmu_show_level, NULL, 1); 328 - static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, exynos4_tmu_show_level, NULL, 2); 329 - static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, 330 - exynos4_tmu_show_level, NULL, 3); 331 - 332 - static struct attribute *exynos4_tmu_attributes[] = { 333 - &dev_attr_name.attr, 334 - &sensor_dev_attr_temp1_input.dev_attr.attr, 335 - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 336 - &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 337 - &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr, 338 - &sensor_dev_attr_temp1_max.dev_attr.attr, 339 - &sensor_dev_attr_temp1_crit.dev_attr.attr, 340 - &sensor_dev_attr_temp1_emergency.dev_attr.attr, 341 - NULL, 342 - }; 343 - 344 - static const struct attribute_group exynos4_tmu_attr_group = { 345 - .attrs = exynos4_tmu_attributes, 346 - }; 347 - 348 - static int __devinit exynos4_tmu_probe(struct platform_device *pdev) 349 - { 350 - struct exynos4_tmu_data *data; 351 - struct exynos4_tmu_platform_data *pdata = pdev->dev.platform_data; 352 - int ret; 353 - 354 - if (!pdata) { 355 - dev_err(&pdev->dev, "No platform init data supplied.\n"); 356 - return -ENODEV; 357 - } 358 - 359 - data = kzalloc(sizeof(struct exynos4_tmu_data), GFP_KERNEL); 360 - if (!data) { 361 - dev_err(&pdev->dev, "Failed to allocate driver structure\n"); 362 - return -ENOMEM; 363 - } 364 - 365 - data->irq = platform_get_irq(pdev, 0); 366 - if (data->irq < 0) { 367 - ret = data->irq; 368 - dev_err(&pdev->dev, "Failed to get platform irq\n"); 369 - goto err_free; 370 - } 371 - 372 - INIT_WORK(&data->irq_work, exynos4_tmu_work); 373 - 374 - data->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 375 - if (!data->mem) { 376 - ret = -ENOENT; 377 - dev_err(&pdev->dev, "Failed to get platform resource\n"); 378 - goto err_free; 379 - } 380 - 381 - data->mem = request_mem_region(data->mem->start, 382 - resource_size(data->mem), pdev->name); 383 - if (!data->mem) { 384 - ret = -ENODEV; 385 - dev_err(&pdev->dev, "Failed to request memory region\n"); 386 - goto err_free; 387 - } 388 - 389 - data->base = ioremap(data->mem->start, resource_size(data->mem)); 390 - if (!data->base) { 391 - ret = -ENODEV; 392 - dev_err(&pdev->dev, "Failed to ioremap memory\n"); 393 - goto err_mem_region; 394 - } 395 - 396 - ret = request_irq(data->irq, exynos4_tmu_irq, 397 - IRQF_TRIGGER_RISING, 398 - "exynos4-tmu", data); 399 - if (ret) { 400 - dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 401 - goto err_io_remap; 402 - } 403 - 404 - data->clk = clk_get(NULL, "tmu_apbif"); 405 - if (IS_ERR(data->clk)) { 406 - ret = PTR_ERR(data->clk); 407 - dev_err(&pdev->dev, "Failed to get clock\n"); 408 - goto err_irq; 409 - } 410 - 411 - data->pdata = pdata; 412 - platform_set_drvdata(pdev, data); 413 - mutex_init(&data->lock); 414 - 415 - ret = exynos4_tmu_initialize(pdev); 416 - if (ret) { 417 - dev_err(&pdev->dev, "Failed to initialize TMU\n"); 418 - goto err_clk; 419 - } 420 - 421 - ret = sysfs_create_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); 422 - if (ret) { 423 - dev_err(&pdev->dev, "Failed to create sysfs group\n"); 424 - goto err_clk; 425 - } 426 - 427 - data->hwmon_dev = hwmon_device_register(&pdev->dev); 428 - if (IS_ERR(data->hwmon_dev)) { 429 - ret = PTR_ERR(data->hwmon_dev); 430 - dev_err(&pdev->dev, "Failed to register hwmon device\n"); 431 - goto err_create_group; 432 - } 433 - 434 - exynos4_tmu_control(pdev, true); 435 - 436 - return 0; 437 - 438 - err_create_group: 439 - sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); 440 - err_clk: 441 - platform_set_drvdata(pdev, NULL); 442 - clk_put(data->clk); 443 - err_irq: 444 - free_irq(data->irq, data); 445 - err_io_remap: 446 - iounmap(data->base); 447 - err_mem_region: 448 - release_mem_region(data->mem->start, resource_size(data->mem)); 449 - err_free: 450 - kfree(data); 451 - 452 - return ret; 453 - } 454 - 455 - static int __devexit exynos4_tmu_remove(struct platform_device *pdev) 456 - { 457 - struct exynos4_tmu_data *data = platform_get_drvdata(pdev); 458 - 459 - exynos4_tmu_control(pdev, false); 460 - 461 - hwmon_device_unregister(data->hwmon_dev); 462 - sysfs_remove_group(&pdev->dev.kobj, &exynos4_tmu_attr_group); 463 - 464 - clk_put(data->clk); 465 - 466 - free_irq(data->irq, data); 467 - 468 - iounmap(data->base); 469 - release_mem_region(data->mem->start, resource_size(data->mem)); 470 - 471 - platform_set_drvdata(pdev, NULL); 472 - 473 - kfree(data); 474 - 475 - return 0; 476 - } 477 - 478 - #ifdef CONFIG_PM_SLEEP 479 - static int exynos4_tmu_suspend(struct device *dev) 480 - { 481 - exynos4_tmu_control(to_platform_device(dev), false); 482 - 483 - return 0; 484 - } 485 - 486 - static int exynos4_tmu_resume(struct device *dev) 487 - { 488 - struct platform_device *pdev = to_platform_device(dev); 489 - 490 - exynos4_tmu_initialize(pdev); 491 - exynos4_tmu_control(pdev, true); 492 - 493 - return 0; 494 - } 495 - 496 - static SIMPLE_DEV_PM_OPS(exynos4_tmu_pm, 497 - exynos4_tmu_suspend, exynos4_tmu_resume); 498 - #define EXYNOS4_TMU_PM &exynos4_tmu_pm 499 - #else 500 - #define EXYNOS4_TMU_PM NULL 501 - #endif 502 - 503 - static struct platform_driver exynos4_tmu_driver = { 504 - .driver = { 505 - .name = "exynos4-tmu", 506 - .owner = THIS_MODULE, 507 - .pm = EXYNOS4_TMU_PM, 508 - }, 509 - .probe = exynos4_tmu_probe, 510 - .remove = __devexit_p(exynos4_tmu_remove), 511 - }; 512 - 513 - module_platform_driver(exynos4_tmu_driver); 514 - 515 - MODULE_DESCRIPTION("EXYNOS4 TMU Driver"); 516 - MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 517 - MODULE_LICENSE("GPL"); 518 - MODULE_ALIAS("platform:exynos4-tmu");
+3 -2
drivers/platform/x86/acerhdf.c
··· 329 329 if (cdev != cl_dev) 330 330 return 0; 331 331 332 - if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) { 332 + if (thermal_zone_bind_cooling_device(thermal, 0, cdev, 333 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) { 333 334 pr_err("error binding cooling dev\n"); 334 335 return -EINVAL; 335 336 } ··· 662 661 return -EINVAL; 663 662 664 663 thz_dev = thermal_zone_device_register("acerhdf", 1, 0, NULL, 665 - &acerhdf_dev_ops, 0, 0, 0, 664 + &acerhdf_dev_ops, 0, 666 665 (kernelmode) ? interval*1000 : 0); 667 666 if (IS_ERR(thz_dev)) 668 667 return -EINVAL;
+1 -1
drivers/platform/x86/intel_mid_thermal.c
··· 502 502 goto err; 503 503 } 504 504 pinfo->tzd[i] = thermal_zone_device_register(name[i], 505 - 0, 0, td_info, &tzd_ops, 0, 0, 0, 0); 505 + 0, 0, td_info, &tzd_ops, 0, 0); 506 506 if (IS_ERR(pinfo->tzd[i])) { 507 507 kfree(td_info); 508 508 ret = PTR_ERR(pinfo->tzd[i]);
+1 -1
drivers/power/power_supply_core.c
··· 201 201 for (i = 0; i < psy->num_properties; i++) { 202 202 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { 203 203 psy->tzd = thermal_zone_device_register(psy->name, 0, 0, 204 - psy, &psy_tzd_ops, 0, 0, 0, 0); 204 + psy, &psy_tzd_ops, 0, 0); 205 205 if (IS_ERR(psy->tzd)) 206 206 return PTR_ERR(psy->tzd); 207 207 break;
+3 -2
drivers/staging/omap-thermal/omap-thermal-common.c
··· 126 126 127 127 /* TODO: bind with min and max states */ 128 128 /* Simple thing, two trips, one passive another critical */ 129 - return thermal_zone_bind_cooling_device(thermal, 0, cdev); 129 + return thermal_zone_bind_cooling_device(thermal, 0, cdev, 130 + THERMAL_NO_LIMIT, 131 + THERMAL_NO_LIMIT); 130 132 } 131 133 132 134 /* Unbind callback functions for thermal zone */ ··· 270 268 /* Create thermal zone */ 271 269 data->omap_thermal = thermal_zone_device_register(domain, 272 270 OMAP_TRIP_NUMBER, 0, data, &omap_thermal_ops, 273 - 1, 2, /*TODO: remove this when FW allows */ 274 271 FAST_TEMP_MONITORING_RATE, 275 272 FAST_TEMP_MONITORING_RATE); 276 273 if (IS_ERR_OR_NULL(data->omap_thermal)) {
+26
drivers/thermal/Kconfig
··· 19 19 depends on HWMON=y || HWMON=THERMAL 20 20 default y 21 21 22 + config CPU_THERMAL 23 + bool "generic cpu cooling support" 24 + depends on THERMAL && CPU_FREQ 25 + help 26 + This implements the generic cpu cooling mechanism through frequency 27 + reduction, cpu hotplug and any other ways of reducing temperature. An 28 + ACPI version of this already exists(drivers/acpi/processor_thermal.c). 29 + This will be useful for platforms using the generic thermal interface 30 + and not the ACPI interface. 31 + If you want this support, you should say Y here. 32 + 22 33 config SPEAR_THERMAL 23 34 bool "SPEAr thermal sensor driver" 24 35 depends on THERMAL ··· 38 27 help 39 28 Enable this to plug the SPEAr thermal sensor driver into the Linux 40 29 thermal framework 30 + 31 + config RCAR_THERMAL 32 + tristate "Renesas R-Car thermal driver" 33 + depends on THERMAL 34 + depends on ARCH_SHMOBILE 35 + help 36 + Enable this to plug the R-Car thermal sensor driver into the Linux 37 + thermal framework 38 + 39 + config EXYNOS_THERMAL 40 + tristate "Temperature sensor on Samsung EXYNOS" 41 + depends on (ARCH_EXYNOS4 || ARCH_EXYNOS5) && THERMAL 42 + help 43 + If you say yes here you get support for TMU (Thermal Managment 44 + Unit) on SAMSUNG EXYNOS series of SoC.
+3
drivers/thermal/Makefile
··· 3 3 # 4 4 5 5 obj-$(CONFIG_THERMAL) += thermal_sys.o 6 + obj-$(CONFIG_CPU_THERMAL) += cpu_cooling.o 6 7 obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o 8 + obj-$(CONFIG_RCAR_THERMAL) += rcar_thermal.o 9 + obj-$(CONFIG_EXYNOS_THERMAL) += exynos_thermal.o
+449
drivers/thermal/cpu_cooling.c
··· 1 + /* 2 + * linux/drivers/thermal/cpu_cooling.c 3 + * 4 + * Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) 5 + * Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org> 6 + * 7 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; version 2 of the License. 11 + * 12 + * This program is distributed in the hope that it will be useful, but 13 + * WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + * 17 + * You should have received a copy of the GNU General Public License along 18 + * with this program; if not, write to the Free Software Foundation, Inc., 19 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 + * 21 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 + */ 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/thermal.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/cpufreq.h> 28 + #include <linux/err.h> 29 + #include <linux/slab.h> 30 + #include <linux/cpu.h> 31 + #include <linux/cpu_cooling.h> 32 + 33 + /** 34 + * struct cpufreq_cooling_device 35 + * @id: unique integer value corresponding to each cpufreq_cooling_device 36 + * registered. 37 + * @cool_dev: thermal_cooling_device pointer to keep track of the the 38 + * egistered cooling device. 39 + * @cpufreq_state: integer value representing the current state of cpufreq 40 + * cooling devices. 41 + * @cpufreq_val: integer value representing the absolute value of the clipped 42 + * frequency. 43 + * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device. 44 + * @node: list_head to link all cpufreq_cooling_device together. 45 + * 46 + * This structure is required for keeping information of each 47 + * cpufreq_cooling_device registered as a list whose head is represented by 48 + * cooling_cpufreq_list. In order to prevent corruption of this list a 49 + * mutex lock cooling_cpufreq_lock is used. 50 + */ 51 + struct cpufreq_cooling_device { 52 + int id; 53 + struct thermal_cooling_device *cool_dev; 54 + unsigned int cpufreq_state; 55 + unsigned int cpufreq_val; 56 + struct cpumask allowed_cpus; 57 + struct list_head node; 58 + }; 59 + static LIST_HEAD(cooling_cpufreq_list); 60 + static DEFINE_IDR(cpufreq_idr); 61 + 62 + static struct mutex cooling_cpufreq_lock; 63 + 64 + /* notify_table passes value to the CPUFREQ_ADJUST callback function. */ 65 + #define NOTIFY_INVALID NULL 66 + struct cpufreq_cooling_device *notify_device; 67 + 68 + /** 69 + * get_idr - function to get a unique id. 70 + * @idr: struct idr * handle used to create a id. 71 + * @id: int * value generated by this function. 72 + */ 73 + static int get_idr(struct idr *idr, int *id) 74 + { 75 + int err; 76 + again: 77 + if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0)) 78 + return -ENOMEM; 79 + 80 + mutex_lock(&cooling_cpufreq_lock); 81 + err = idr_get_new(idr, NULL, id); 82 + mutex_unlock(&cooling_cpufreq_lock); 83 + 84 + if (unlikely(err == -EAGAIN)) 85 + goto again; 86 + else if (unlikely(err)) 87 + return err; 88 + 89 + *id = *id & MAX_IDR_MASK; 90 + return 0; 91 + } 92 + 93 + /** 94 + * release_idr - function to free the unique id. 95 + * @idr: struct idr * handle used for creating the id. 96 + * @id: int value representing the unique id. 97 + */ 98 + static void release_idr(struct idr *idr, int id) 99 + { 100 + mutex_lock(&cooling_cpufreq_lock); 101 + idr_remove(idr, id); 102 + mutex_unlock(&cooling_cpufreq_lock); 103 + } 104 + 105 + /* Below code defines functions to be used for cpufreq as cooling device */ 106 + 107 + /** 108 + * is_cpufreq_valid - function to check if a cpu has frequency transition policy. 109 + * @cpu: cpu for which check is needed. 110 + */ 111 + static int is_cpufreq_valid(int cpu) 112 + { 113 + struct cpufreq_policy policy; 114 + return !cpufreq_get_policy(&policy, cpu); 115 + } 116 + 117 + /** 118 + * get_cpu_frequency - get the absolute value of frequency from level. 119 + * @cpu: cpu for which frequency is fetched. 120 + * @level: level of frequency of the CPU 121 + * e.g level=1 --> 1st MAX FREQ, LEVEL=2 ---> 2nd MAX FREQ, .... etc 122 + */ 123 + static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) 124 + { 125 + int ret = 0, i = 0; 126 + unsigned long level_index; 127 + bool descend = false; 128 + struct cpufreq_frequency_table *table = 129 + cpufreq_frequency_get_table(cpu); 130 + if (!table) 131 + return ret; 132 + 133 + while (table[i].frequency != CPUFREQ_TABLE_END) { 134 + if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 135 + continue; 136 + 137 + /*check if table in ascending or descending order*/ 138 + if ((table[i + 1].frequency != CPUFREQ_TABLE_END) && 139 + (table[i + 1].frequency < table[i].frequency) 140 + && !descend) { 141 + descend = true; 142 + } 143 + 144 + /*return if level matched and table in descending order*/ 145 + if (descend && i == level) 146 + return table[i].frequency; 147 + i++; 148 + } 149 + i--; 150 + 151 + if (level > i || descend) 152 + return ret; 153 + level_index = i - level; 154 + 155 + /*Scan the table in reverse order and match the level*/ 156 + while (i >= 0) { 157 + if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 158 + continue; 159 + /*return if level matched*/ 160 + if (i == level_index) 161 + return table[i].frequency; 162 + i--; 163 + } 164 + return ret; 165 + } 166 + 167 + /** 168 + * cpufreq_apply_cooling - function to apply frequency clipping. 169 + * @cpufreq_device: cpufreq_cooling_device pointer containing frequency 170 + * clipping data. 171 + * @cooling_state: value of the cooling state. 172 + */ 173 + static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device, 174 + unsigned long cooling_state) 175 + { 176 + unsigned int cpuid, clip_freq; 177 + struct cpumask *maskPtr = &cpufreq_device->allowed_cpus; 178 + unsigned int cpu = cpumask_any(maskPtr); 179 + 180 + 181 + /* Check if the old cooling action is same as new cooling action */ 182 + if (cpufreq_device->cpufreq_state == cooling_state) 183 + return 0; 184 + 185 + clip_freq = get_cpu_frequency(cpu, cooling_state); 186 + if (!clip_freq) 187 + return -EINVAL; 188 + 189 + cpufreq_device->cpufreq_state = cooling_state; 190 + cpufreq_device->cpufreq_val = clip_freq; 191 + notify_device = cpufreq_device; 192 + 193 + for_each_cpu(cpuid, maskPtr) { 194 + if (is_cpufreq_valid(cpuid)) 195 + cpufreq_update_policy(cpuid); 196 + } 197 + 198 + notify_device = NOTIFY_INVALID; 199 + 200 + return 0; 201 + } 202 + 203 + /** 204 + * cpufreq_thermal_notifier - notifier callback for cpufreq policy change. 205 + * @nb: struct notifier_block * with callback info. 206 + * @event: value showing cpufreq event for which this function invoked. 207 + * @data: callback-specific data 208 + */ 209 + static int cpufreq_thermal_notifier(struct notifier_block *nb, 210 + unsigned long event, void *data) 211 + { 212 + struct cpufreq_policy *policy = data; 213 + unsigned long max_freq = 0; 214 + 215 + if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID) 216 + return 0; 217 + 218 + if (cpumask_test_cpu(policy->cpu, &notify_device->allowed_cpus)) 219 + max_freq = notify_device->cpufreq_val; 220 + 221 + /* Never exceed user_policy.max*/ 222 + if (max_freq > policy->user_policy.max) 223 + max_freq = policy->user_policy.max; 224 + 225 + if (policy->max != max_freq) 226 + cpufreq_verify_within_limits(policy, 0, max_freq); 227 + 228 + return 0; 229 + } 230 + 231 + /* 232 + * cpufreq cooling device callback functions are defined below 233 + */ 234 + 235 + /** 236 + * cpufreq_get_max_state - callback function to get the max cooling state. 237 + * @cdev: thermal cooling device pointer. 238 + * @state: fill this variable with the max cooling state. 239 + */ 240 + static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, 241 + unsigned long *state) 242 + { 243 + int ret = -EINVAL, i = 0; 244 + struct cpufreq_cooling_device *cpufreq_device; 245 + struct cpumask *maskPtr; 246 + unsigned int cpu; 247 + struct cpufreq_frequency_table *table; 248 + 249 + mutex_lock(&cooling_cpufreq_lock); 250 + list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { 251 + if (cpufreq_device && cpufreq_device->cool_dev == cdev) 252 + break; 253 + } 254 + if (cpufreq_device == NULL) 255 + goto return_get_max_state; 256 + 257 + maskPtr = &cpufreq_device->allowed_cpus; 258 + cpu = cpumask_any(maskPtr); 259 + table = cpufreq_frequency_get_table(cpu); 260 + if (!table) { 261 + *state = 0; 262 + ret = 0; 263 + goto return_get_max_state; 264 + } 265 + 266 + while (table[i].frequency != CPUFREQ_TABLE_END) { 267 + if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 268 + continue; 269 + i++; 270 + } 271 + if (i > 0) { 272 + *state = --i; 273 + ret = 0; 274 + } 275 + 276 + return_get_max_state: 277 + mutex_unlock(&cooling_cpufreq_lock); 278 + return ret; 279 + } 280 + 281 + /** 282 + * cpufreq_get_cur_state - callback function to get the current cooling state. 283 + * @cdev: thermal cooling device pointer. 284 + * @state: fill this variable with the current cooling state. 285 + */ 286 + static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, 287 + unsigned long *state) 288 + { 289 + int ret = -EINVAL; 290 + struct cpufreq_cooling_device *cpufreq_device; 291 + 292 + mutex_lock(&cooling_cpufreq_lock); 293 + list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { 294 + if (cpufreq_device && cpufreq_device->cool_dev == cdev) { 295 + *state = cpufreq_device->cpufreq_state; 296 + ret = 0; 297 + break; 298 + } 299 + } 300 + mutex_unlock(&cooling_cpufreq_lock); 301 + 302 + return ret; 303 + } 304 + 305 + /** 306 + * cpufreq_set_cur_state - callback function to set the current cooling state. 307 + * @cdev: thermal cooling device pointer. 308 + * @state: set this variable to the current cooling state. 309 + */ 310 + static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, 311 + unsigned long state) 312 + { 313 + int ret = -EINVAL; 314 + struct cpufreq_cooling_device *cpufreq_device; 315 + 316 + mutex_lock(&cooling_cpufreq_lock); 317 + list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { 318 + if (cpufreq_device && cpufreq_device->cool_dev == cdev) { 319 + ret = 0; 320 + break; 321 + } 322 + } 323 + if (!ret) 324 + ret = cpufreq_apply_cooling(cpufreq_device, state); 325 + 326 + mutex_unlock(&cooling_cpufreq_lock); 327 + 328 + return ret; 329 + } 330 + 331 + /* Bind cpufreq callbacks to thermal cooling device ops */ 332 + static struct thermal_cooling_device_ops const cpufreq_cooling_ops = { 333 + .get_max_state = cpufreq_get_max_state, 334 + .get_cur_state = cpufreq_get_cur_state, 335 + .set_cur_state = cpufreq_set_cur_state, 336 + }; 337 + 338 + /* Notifier for cpufreq policy change */ 339 + static struct notifier_block thermal_cpufreq_notifier_block = { 340 + .notifier_call = cpufreq_thermal_notifier, 341 + }; 342 + 343 + /** 344 + * cpufreq_cooling_register - function to create cpufreq cooling device. 345 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 346 + */ 347 + struct thermal_cooling_device *cpufreq_cooling_register( 348 + struct cpumask *clip_cpus) 349 + { 350 + struct thermal_cooling_device *cool_dev; 351 + struct cpufreq_cooling_device *cpufreq_dev = NULL; 352 + unsigned int cpufreq_dev_count = 0, min = 0, max = 0; 353 + char dev_name[THERMAL_NAME_LENGTH]; 354 + int ret = 0, i; 355 + struct cpufreq_policy policy; 356 + 357 + list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) 358 + cpufreq_dev_count++; 359 + 360 + /*Verify that all the clip cpus have same freq_min, freq_max limit*/ 361 + for_each_cpu(i, clip_cpus) { 362 + /*continue if cpufreq policy not found and not return error*/ 363 + if (!cpufreq_get_policy(&policy, i)) 364 + continue; 365 + if (min == 0 && max == 0) { 366 + min = policy.cpuinfo.min_freq; 367 + max = policy.cpuinfo.max_freq; 368 + } else { 369 + if (min != policy.cpuinfo.min_freq || 370 + max != policy.cpuinfo.max_freq) 371 + return ERR_PTR(-EINVAL); 372 + } 373 + } 374 + cpufreq_dev = kzalloc(sizeof(struct cpufreq_cooling_device), 375 + GFP_KERNEL); 376 + if (!cpufreq_dev) 377 + return ERR_PTR(-ENOMEM); 378 + 379 + cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); 380 + 381 + if (cpufreq_dev_count == 0) 382 + mutex_init(&cooling_cpufreq_lock); 383 + 384 + ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); 385 + if (ret) { 386 + kfree(cpufreq_dev); 387 + return ERR_PTR(-EINVAL); 388 + } 389 + 390 + sprintf(dev_name, "thermal-cpufreq-%d", cpufreq_dev->id); 391 + 392 + cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, 393 + &cpufreq_cooling_ops); 394 + if (!cool_dev) { 395 + release_idr(&cpufreq_idr, cpufreq_dev->id); 396 + kfree(cpufreq_dev); 397 + return ERR_PTR(-EINVAL); 398 + } 399 + cpufreq_dev->cool_dev = cool_dev; 400 + cpufreq_dev->cpufreq_state = 0; 401 + mutex_lock(&cooling_cpufreq_lock); 402 + list_add_tail(&cpufreq_dev->node, &cooling_cpufreq_list); 403 + 404 + /* Register the notifier for first cpufreq cooling device */ 405 + if (cpufreq_dev_count == 0) 406 + cpufreq_register_notifier(&thermal_cpufreq_notifier_block, 407 + CPUFREQ_POLICY_NOTIFIER); 408 + 409 + mutex_unlock(&cooling_cpufreq_lock); 410 + return cool_dev; 411 + } 412 + EXPORT_SYMBOL(cpufreq_cooling_register); 413 + 414 + /** 415 + * cpufreq_cooling_unregister - function to remove cpufreq cooling device. 416 + * @cdev: thermal cooling device pointer. 417 + */ 418 + void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) 419 + { 420 + struct cpufreq_cooling_device *cpufreq_dev = NULL; 421 + unsigned int cpufreq_dev_count = 0; 422 + 423 + mutex_lock(&cooling_cpufreq_lock); 424 + list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) { 425 + if (cpufreq_dev && cpufreq_dev->cool_dev == cdev) 426 + break; 427 + cpufreq_dev_count++; 428 + } 429 + 430 + if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) { 431 + mutex_unlock(&cooling_cpufreq_lock); 432 + return; 433 + } 434 + 435 + list_del(&cpufreq_dev->node); 436 + 437 + /* Unregister the notifier for the last cpufreq cooling device */ 438 + if (cpufreq_dev_count == 1) { 439 + cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, 440 + CPUFREQ_POLICY_NOTIFIER); 441 + } 442 + mutex_unlock(&cooling_cpufreq_lock); 443 + thermal_cooling_device_unregister(cpufreq_dev->cool_dev); 444 + release_idr(&cpufreq_idr, cpufreq_dev->id); 445 + if (cpufreq_dev_count == 1) 446 + mutex_destroy(&cooling_cpufreq_lock); 447 + kfree(cpufreq_dev); 448 + } 449 + EXPORT_SYMBOL(cpufreq_cooling_unregister);
+997
drivers/thermal/exynos_thermal.c
··· 1 + /* 2 + * exynos_thermal.c - Samsung EXYNOS TMU (Thermal Management Unit) 3 + * 4 + * Copyright (C) 2011 Samsung Electronics 5 + * Donggeun Kim <dg77.kim@samsung.com> 6 + * Amit Daniel Kachhap <amit.kachhap@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + * 18 + * You should have received a copy of the GNU General Public License 19 + * along with this program; if not, write to the Free Software 20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 + * 22 + */ 23 + 24 + #include <linux/module.h> 25 + #include <linux/err.h> 26 + #include <linux/kernel.h> 27 + #include <linux/slab.h> 28 + #include <linux/platform_device.h> 29 + #include <linux/interrupt.h> 30 + #include <linux/clk.h> 31 + #include <linux/workqueue.h> 32 + #include <linux/sysfs.h> 33 + #include <linux/kobject.h> 34 + #include <linux/io.h> 35 + #include <linux/mutex.h> 36 + #include <linux/platform_data/exynos_thermal.h> 37 + #include <linux/thermal.h> 38 + #include <linux/cpufreq.h> 39 + #include <linux/cpu_cooling.h> 40 + #include <linux/of.h> 41 + 42 + #include <plat/cpu.h> 43 + 44 + /* Exynos generic registers */ 45 + #define EXYNOS_TMU_REG_TRIMINFO 0x0 46 + #define EXYNOS_TMU_REG_CONTROL 0x20 47 + #define EXYNOS_TMU_REG_STATUS 0x28 48 + #define EXYNOS_TMU_REG_CURRENT_TEMP 0x40 49 + #define EXYNOS_TMU_REG_INTEN 0x70 50 + #define EXYNOS_TMU_REG_INTSTAT 0x74 51 + #define EXYNOS_TMU_REG_INTCLEAR 0x78 52 + 53 + #define EXYNOS_TMU_TRIM_TEMP_MASK 0xff 54 + #define EXYNOS_TMU_GAIN_SHIFT 8 55 + #define EXYNOS_TMU_REF_VOLTAGE_SHIFT 24 56 + #define EXYNOS_TMU_CORE_ON 3 57 + #define EXYNOS_TMU_CORE_OFF 2 58 + #define EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET 50 59 + 60 + /* Exynos4210 specific registers */ 61 + #define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44 62 + #define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50 63 + #define EXYNOS4210_TMU_REG_TRIG_LEVEL1 0x54 64 + #define EXYNOS4210_TMU_REG_TRIG_LEVEL2 0x58 65 + #define EXYNOS4210_TMU_REG_TRIG_LEVEL3 0x5C 66 + #define EXYNOS4210_TMU_REG_PAST_TEMP0 0x60 67 + #define EXYNOS4210_TMU_REG_PAST_TEMP1 0x64 68 + #define EXYNOS4210_TMU_REG_PAST_TEMP2 0x68 69 + #define EXYNOS4210_TMU_REG_PAST_TEMP3 0x6C 70 + 71 + #define EXYNOS4210_TMU_TRIG_LEVEL0_MASK 0x1 72 + #define EXYNOS4210_TMU_TRIG_LEVEL1_MASK 0x10 73 + #define EXYNOS4210_TMU_TRIG_LEVEL2_MASK 0x100 74 + #define EXYNOS4210_TMU_TRIG_LEVEL3_MASK 0x1000 75 + #define EXYNOS4210_TMU_INTCLEAR_VAL 0x1111 76 + 77 + /* Exynos5250 and Exynos4412 specific registers */ 78 + #define EXYNOS_TMU_TRIMINFO_CON 0x14 79 + #define EXYNOS_THD_TEMP_RISE 0x50 80 + #define EXYNOS_THD_TEMP_FALL 0x54 81 + #define EXYNOS_EMUL_CON 0x80 82 + 83 + #define EXYNOS_TRIMINFO_RELOAD 0x1 84 + #define EXYNOS_TMU_CLEAR_RISE_INT 0x111 85 + #define EXYNOS_TMU_CLEAR_FALL_INT (0x111 << 16) 86 + #define EXYNOS_MUX_ADDR_VALUE 6 87 + #define EXYNOS_MUX_ADDR_SHIFT 20 88 + #define EXYNOS_TMU_TRIP_MODE_SHIFT 13 89 + 90 + #define EFUSE_MIN_VALUE 40 91 + #define EFUSE_MAX_VALUE 100 92 + 93 + /* In-kernel thermal framework related macros & definations */ 94 + #define SENSOR_NAME_LEN 16 95 + #define MAX_TRIP_COUNT 8 96 + #define MAX_COOLING_DEVICE 4 97 + 98 + #define ACTIVE_INTERVAL 500 99 + #define IDLE_INTERVAL 10000 100 + #define MCELSIUS 1000 101 + 102 + /* CPU Zone information */ 103 + #define PANIC_ZONE 4 104 + #define WARN_ZONE 3 105 + #define MONITOR_ZONE 2 106 + #define SAFE_ZONE 1 107 + 108 + #define GET_ZONE(trip) (trip + 2) 109 + #define GET_TRIP(zone) (zone - 2) 110 + 111 + #define EXYNOS_ZONE_COUNT 3 112 + 113 + struct exynos_tmu_data { 114 + struct exynos_tmu_platform_data *pdata; 115 + struct resource *mem; 116 + void __iomem *base; 117 + int irq; 118 + enum soc_type soc; 119 + struct work_struct irq_work; 120 + struct mutex lock; 121 + struct clk *clk; 122 + u8 temp_error1, temp_error2; 123 + }; 124 + 125 + struct thermal_trip_point_conf { 126 + int trip_val[MAX_TRIP_COUNT]; 127 + int trip_count; 128 + }; 129 + 130 + struct thermal_cooling_conf { 131 + struct freq_clip_table freq_data[MAX_TRIP_COUNT]; 132 + int freq_clip_count; 133 + }; 134 + 135 + struct thermal_sensor_conf { 136 + char name[SENSOR_NAME_LEN]; 137 + int (*read_temperature)(void *data); 138 + struct thermal_trip_point_conf trip_data; 139 + struct thermal_cooling_conf cooling_data; 140 + void *private_data; 141 + }; 142 + 143 + struct exynos_thermal_zone { 144 + enum thermal_device_mode mode; 145 + struct thermal_zone_device *therm_dev; 146 + struct thermal_cooling_device *cool_dev[MAX_COOLING_DEVICE]; 147 + unsigned int cool_dev_size; 148 + struct platform_device *exynos4_dev; 149 + struct thermal_sensor_conf *sensor_conf; 150 + bool bind; 151 + }; 152 + 153 + static struct exynos_thermal_zone *th_zone; 154 + static void exynos_unregister_thermal(void); 155 + static int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf); 156 + 157 + /* Get mode callback functions for thermal zone */ 158 + static int exynos_get_mode(struct thermal_zone_device *thermal, 159 + enum thermal_device_mode *mode) 160 + { 161 + if (th_zone) 162 + *mode = th_zone->mode; 163 + return 0; 164 + } 165 + 166 + /* Set mode callback functions for thermal zone */ 167 + static int exynos_set_mode(struct thermal_zone_device *thermal, 168 + enum thermal_device_mode mode) 169 + { 170 + if (!th_zone->therm_dev) { 171 + pr_notice("thermal zone not registered\n"); 172 + return 0; 173 + } 174 + 175 + mutex_lock(&th_zone->therm_dev->lock); 176 + 177 + if (mode == THERMAL_DEVICE_ENABLED) 178 + th_zone->therm_dev->polling_delay = IDLE_INTERVAL; 179 + else 180 + th_zone->therm_dev->polling_delay = 0; 181 + 182 + mutex_unlock(&th_zone->therm_dev->lock); 183 + 184 + th_zone->mode = mode; 185 + thermal_zone_device_update(th_zone->therm_dev); 186 + pr_info("thermal polling set for duration=%d msec\n", 187 + th_zone->therm_dev->polling_delay); 188 + return 0; 189 + } 190 + 191 + 192 + /* Get trip type callback functions for thermal zone */ 193 + static int exynos_get_trip_type(struct thermal_zone_device *thermal, int trip, 194 + enum thermal_trip_type *type) 195 + { 196 + switch (GET_ZONE(trip)) { 197 + case MONITOR_ZONE: 198 + case WARN_ZONE: 199 + *type = THERMAL_TRIP_ACTIVE; 200 + break; 201 + case PANIC_ZONE: 202 + *type = THERMAL_TRIP_CRITICAL; 203 + break; 204 + default: 205 + return -EINVAL; 206 + } 207 + return 0; 208 + } 209 + 210 + /* Get trip temperature callback functions for thermal zone */ 211 + static int exynos_get_trip_temp(struct thermal_zone_device *thermal, int trip, 212 + unsigned long *temp) 213 + { 214 + if (trip < GET_TRIP(MONITOR_ZONE) || trip > GET_TRIP(PANIC_ZONE)) 215 + return -EINVAL; 216 + 217 + *temp = th_zone->sensor_conf->trip_data.trip_val[trip]; 218 + /* convert the temperature into millicelsius */ 219 + *temp = *temp * MCELSIUS; 220 + 221 + return 0; 222 + } 223 + 224 + /* Get critical temperature callback functions for thermal zone */ 225 + static int exynos_get_crit_temp(struct thermal_zone_device *thermal, 226 + unsigned long *temp) 227 + { 228 + int ret; 229 + /* Panic zone */ 230 + ret = exynos_get_trip_temp(thermal, GET_TRIP(PANIC_ZONE), temp); 231 + return ret; 232 + } 233 + 234 + static int exynos_get_frequency_level(unsigned int cpu, unsigned int freq) 235 + { 236 + int i = 0, ret = -EINVAL; 237 + struct cpufreq_frequency_table *table = NULL; 238 + #ifdef CONFIG_CPU_FREQ 239 + table = cpufreq_frequency_get_table(cpu); 240 + #endif 241 + if (!table) 242 + return ret; 243 + 244 + while (table[i].frequency != CPUFREQ_TABLE_END) { 245 + if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 246 + continue; 247 + if (table[i].frequency == freq) 248 + return i; 249 + i++; 250 + } 251 + return ret; 252 + } 253 + 254 + /* Bind callback functions for thermal zone */ 255 + static int exynos_bind(struct thermal_zone_device *thermal, 256 + struct thermal_cooling_device *cdev) 257 + { 258 + int ret = 0, i, tab_size, level; 259 + struct freq_clip_table *tab_ptr, *clip_data; 260 + struct thermal_sensor_conf *data = th_zone->sensor_conf; 261 + 262 + tab_ptr = (struct freq_clip_table *)data->cooling_data.freq_data; 263 + tab_size = data->cooling_data.freq_clip_count; 264 + 265 + if (tab_ptr == NULL || tab_size == 0) 266 + return -EINVAL; 267 + 268 + /* find the cooling device registered*/ 269 + for (i = 0; i < th_zone->cool_dev_size; i++) 270 + if (cdev == th_zone->cool_dev[i]) 271 + break; 272 + 273 + /* No matching cooling device */ 274 + if (i == th_zone->cool_dev_size) 275 + return 0; 276 + 277 + /* Bind the thermal zone to the cpufreq cooling device */ 278 + for (i = 0; i < tab_size; i++) { 279 + clip_data = (struct freq_clip_table *)&(tab_ptr[i]); 280 + level = exynos_get_frequency_level(0, clip_data->freq_clip_max); 281 + if (level < 0) 282 + return 0; 283 + switch (GET_ZONE(i)) { 284 + case MONITOR_ZONE: 285 + case WARN_ZONE: 286 + if (thermal_zone_bind_cooling_device(thermal, i, cdev, 287 + level, level)) { 288 + pr_err("error binding cdev inst %d\n", i); 289 + ret = -EINVAL; 290 + } 291 + th_zone->bind = true; 292 + break; 293 + default: 294 + ret = -EINVAL; 295 + } 296 + } 297 + 298 + return ret; 299 + } 300 + 301 + /* Unbind callback functions for thermal zone */ 302 + static int exynos_unbind(struct thermal_zone_device *thermal, 303 + struct thermal_cooling_device *cdev) 304 + { 305 + int ret = 0, i, tab_size; 306 + struct thermal_sensor_conf *data = th_zone->sensor_conf; 307 + 308 + if (th_zone->bind == false) 309 + return 0; 310 + 311 + tab_size = data->cooling_data.freq_clip_count; 312 + 313 + if (tab_size == 0) 314 + return -EINVAL; 315 + 316 + /* find the cooling device registered*/ 317 + for (i = 0; i < th_zone->cool_dev_size; i++) 318 + if (cdev == th_zone->cool_dev[i]) 319 + break; 320 + 321 + /* No matching cooling device */ 322 + if (i == th_zone->cool_dev_size) 323 + return 0; 324 + 325 + /* Bind the thermal zone to the cpufreq cooling device */ 326 + for (i = 0; i < tab_size; i++) { 327 + switch (GET_ZONE(i)) { 328 + case MONITOR_ZONE: 329 + case WARN_ZONE: 330 + if (thermal_zone_unbind_cooling_device(thermal, i, 331 + cdev)) { 332 + pr_err("error unbinding cdev inst=%d\n", i); 333 + ret = -EINVAL; 334 + } 335 + th_zone->bind = false; 336 + break; 337 + default: 338 + ret = -EINVAL; 339 + } 340 + } 341 + return ret; 342 + } 343 + 344 + /* Get temperature callback functions for thermal zone */ 345 + static int exynos_get_temp(struct thermal_zone_device *thermal, 346 + unsigned long *temp) 347 + { 348 + void *data; 349 + 350 + if (!th_zone->sensor_conf) { 351 + pr_info("Temperature sensor not initialised\n"); 352 + return -EINVAL; 353 + } 354 + data = th_zone->sensor_conf->private_data; 355 + *temp = th_zone->sensor_conf->read_temperature(data); 356 + /* convert the temperature into millicelsius */ 357 + *temp = *temp * MCELSIUS; 358 + return 0; 359 + } 360 + 361 + /* Get the temperature trend */ 362 + static int exynos_get_trend(struct thermal_zone_device *thermal, 363 + int trip, enum thermal_trend *trend) 364 + { 365 + if (thermal->temperature >= trip) 366 + *trend = THERMAL_TREND_RAISING; 367 + else 368 + *trend = THERMAL_TREND_DROPPING; 369 + 370 + return 0; 371 + } 372 + /* Operation callback functions for thermal zone */ 373 + static struct thermal_zone_device_ops const exynos_dev_ops = { 374 + .bind = exynos_bind, 375 + .unbind = exynos_unbind, 376 + .get_temp = exynos_get_temp, 377 + .get_trend = exynos_get_trend, 378 + .get_mode = exynos_get_mode, 379 + .set_mode = exynos_set_mode, 380 + .get_trip_type = exynos_get_trip_type, 381 + .get_trip_temp = exynos_get_trip_temp, 382 + .get_crit_temp = exynos_get_crit_temp, 383 + }; 384 + 385 + /* 386 + * This function may be called from interrupt based temperature sensor 387 + * when threshold is changed. 388 + */ 389 + static void exynos_report_trigger(void) 390 + { 391 + unsigned int i; 392 + char data[10]; 393 + char *envp[] = { data, NULL }; 394 + 395 + if (!th_zone || !th_zone->therm_dev) 396 + return; 397 + if (th_zone->bind == false) { 398 + for (i = 0; i < th_zone->cool_dev_size; i++) { 399 + if (!th_zone->cool_dev[i]) 400 + continue; 401 + exynos_bind(th_zone->therm_dev, 402 + th_zone->cool_dev[i]); 403 + } 404 + } 405 + 406 + thermal_zone_device_update(th_zone->therm_dev); 407 + 408 + mutex_lock(&th_zone->therm_dev->lock); 409 + /* Find the level for which trip happened */ 410 + for (i = 0; i < th_zone->sensor_conf->trip_data.trip_count; i++) { 411 + if (th_zone->therm_dev->last_temperature < 412 + th_zone->sensor_conf->trip_data.trip_val[i] * MCELSIUS) 413 + break; 414 + } 415 + 416 + if (th_zone->mode == THERMAL_DEVICE_ENABLED) { 417 + if (i > 0) 418 + th_zone->therm_dev->polling_delay = ACTIVE_INTERVAL; 419 + else 420 + th_zone->therm_dev->polling_delay = IDLE_INTERVAL; 421 + } 422 + 423 + snprintf(data, sizeof(data), "%u", i); 424 + kobject_uevent_env(&th_zone->therm_dev->device.kobj, KOBJ_CHANGE, envp); 425 + mutex_unlock(&th_zone->therm_dev->lock); 426 + } 427 + 428 + /* Register with the in-kernel thermal management */ 429 + static int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf) 430 + { 431 + int ret; 432 + struct cpumask mask_val; 433 + 434 + if (!sensor_conf || !sensor_conf->read_temperature) { 435 + pr_err("Temperature sensor not initialised\n"); 436 + return -EINVAL; 437 + } 438 + 439 + th_zone = kzalloc(sizeof(struct exynos_thermal_zone), GFP_KERNEL); 440 + if (!th_zone) 441 + return -ENOMEM; 442 + 443 + th_zone->sensor_conf = sensor_conf; 444 + cpumask_set_cpu(0, &mask_val); 445 + th_zone->cool_dev[0] = cpufreq_cooling_register(&mask_val); 446 + if (IS_ERR(th_zone->cool_dev[0])) { 447 + pr_err("Failed to register cpufreq cooling device\n"); 448 + ret = -EINVAL; 449 + goto err_unregister; 450 + } 451 + th_zone->cool_dev_size++; 452 + 453 + th_zone->therm_dev = thermal_zone_device_register(sensor_conf->name, 454 + EXYNOS_ZONE_COUNT, 0, NULL, &exynos_dev_ops, 0, 455 + IDLE_INTERVAL); 456 + 457 + if (IS_ERR(th_zone->therm_dev)) { 458 + pr_err("Failed to register thermal zone device\n"); 459 + ret = -EINVAL; 460 + goto err_unregister; 461 + } 462 + th_zone->mode = THERMAL_DEVICE_ENABLED; 463 + 464 + pr_info("Exynos: Kernel Thermal management registered\n"); 465 + 466 + return 0; 467 + 468 + err_unregister: 469 + exynos_unregister_thermal(); 470 + return ret; 471 + } 472 + 473 + /* Un-Register with the in-kernel thermal management */ 474 + static void exynos_unregister_thermal(void) 475 + { 476 + int i; 477 + 478 + if (!th_zone) 479 + return; 480 + 481 + if (th_zone->therm_dev) 482 + thermal_zone_device_unregister(th_zone->therm_dev); 483 + 484 + for (i = 0; i < th_zone->cool_dev_size; i++) { 485 + if (th_zone->cool_dev[i]) 486 + cpufreq_cooling_unregister(th_zone->cool_dev[i]); 487 + } 488 + 489 + kfree(th_zone); 490 + pr_info("Exynos: Kernel Thermal management unregistered\n"); 491 + } 492 + 493 + /* 494 + * TMU treats temperature as a mapped temperature code. 495 + * The temperature is converted differently depending on the calibration type. 496 + */ 497 + static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 498 + { 499 + struct exynos_tmu_platform_data *pdata = data->pdata; 500 + int temp_code; 501 + 502 + if (data->soc == SOC_ARCH_EXYNOS4210) 503 + /* temp should range between 25 and 125 */ 504 + if (temp < 25 || temp > 125) { 505 + temp_code = -EINVAL; 506 + goto out; 507 + } 508 + 509 + switch (pdata->cal_type) { 510 + case TYPE_TWO_POINT_TRIMMING: 511 + temp_code = (temp - 25) * 512 + (data->temp_error2 - data->temp_error1) / 513 + (85 - 25) + data->temp_error1; 514 + break; 515 + case TYPE_ONE_POINT_TRIMMING: 516 + temp_code = temp + data->temp_error1 - 25; 517 + break; 518 + default: 519 + temp_code = temp + EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET; 520 + break; 521 + } 522 + out: 523 + return temp_code; 524 + } 525 + 526 + /* 527 + * Calculate a temperature value from a temperature code. 528 + * The unit of the temperature is degree Celsius. 529 + */ 530 + static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) 531 + { 532 + struct exynos_tmu_platform_data *pdata = data->pdata; 533 + int temp; 534 + 535 + if (data->soc == SOC_ARCH_EXYNOS4210) 536 + /* temp_code should range between 75 and 175 */ 537 + if (temp_code < 75 || temp_code > 175) { 538 + temp = -ENODATA; 539 + goto out; 540 + } 541 + 542 + switch (pdata->cal_type) { 543 + case TYPE_TWO_POINT_TRIMMING: 544 + temp = (temp_code - data->temp_error1) * (85 - 25) / 545 + (data->temp_error2 - data->temp_error1) + 25; 546 + break; 547 + case TYPE_ONE_POINT_TRIMMING: 548 + temp = temp_code - data->temp_error1 + 25; 549 + break; 550 + default: 551 + temp = temp_code - EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET; 552 + break; 553 + } 554 + out: 555 + return temp; 556 + } 557 + 558 + static int exynos_tmu_initialize(struct platform_device *pdev) 559 + { 560 + struct exynos_tmu_data *data = platform_get_drvdata(pdev); 561 + struct exynos_tmu_platform_data *pdata = data->pdata; 562 + unsigned int status, trim_info, rising_threshold; 563 + int ret = 0, threshold_code; 564 + 565 + mutex_lock(&data->lock); 566 + clk_enable(data->clk); 567 + 568 + status = readb(data->base + EXYNOS_TMU_REG_STATUS); 569 + if (!status) { 570 + ret = -EBUSY; 571 + goto out; 572 + } 573 + 574 + if (data->soc == SOC_ARCH_EXYNOS) { 575 + __raw_writel(EXYNOS_TRIMINFO_RELOAD, 576 + data->base + EXYNOS_TMU_TRIMINFO_CON); 577 + } 578 + /* Save trimming info in order to perform calibration */ 579 + trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 580 + data->temp_error1 = trim_info & EXYNOS_TMU_TRIM_TEMP_MASK; 581 + data->temp_error2 = ((trim_info >> 8) & EXYNOS_TMU_TRIM_TEMP_MASK); 582 + 583 + if ((EFUSE_MIN_VALUE > data->temp_error1) || 584 + (data->temp_error1 > EFUSE_MAX_VALUE) || 585 + (data->temp_error2 != 0)) 586 + data->temp_error1 = pdata->efuse_value; 587 + 588 + if (data->soc == SOC_ARCH_EXYNOS4210) { 589 + /* Write temperature code for threshold */ 590 + threshold_code = temp_to_code(data, pdata->threshold); 591 + if (threshold_code < 0) { 592 + ret = threshold_code; 593 + goto out; 594 + } 595 + writeb(threshold_code, 596 + data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); 597 + 598 + writeb(pdata->trigger_levels[0], 599 + data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL0); 600 + writeb(pdata->trigger_levels[1], 601 + data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL1); 602 + writeb(pdata->trigger_levels[2], 603 + data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL2); 604 + writeb(pdata->trigger_levels[3], 605 + data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL3); 606 + 607 + writel(EXYNOS4210_TMU_INTCLEAR_VAL, 608 + data->base + EXYNOS_TMU_REG_INTCLEAR); 609 + } else if (data->soc == SOC_ARCH_EXYNOS) { 610 + /* Write temperature code for threshold */ 611 + threshold_code = temp_to_code(data, pdata->trigger_levels[0]); 612 + if (threshold_code < 0) { 613 + ret = threshold_code; 614 + goto out; 615 + } 616 + rising_threshold = threshold_code; 617 + threshold_code = temp_to_code(data, pdata->trigger_levels[1]); 618 + if (threshold_code < 0) { 619 + ret = threshold_code; 620 + goto out; 621 + } 622 + rising_threshold |= (threshold_code << 8); 623 + threshold_code = temp_to_code(data, pdata->trigger_levels[2]); 624 + if (threshold_code < 0) { 625 + ret = threshold_code; 626 + goto out; 627 + } 628 + rising_threshold |= (threshold_code << 16); 629 + 630 + writel(rising_threshold, 631 + data->base + EXYNOS_THD_TEMP_RISE); 632 + writel(0, data->base + EXYNOS_THD_TEMP_FALL); 633 + 634 + writel(EXYNOS_TMU_CLEAR_RISE_INT|EXYNOS_TMU_CLEAR_FALL_INT, 635 + data->base + EXYNOS_TMU_REG_INTCLEAR); 636 + } 637 + out: 638 + clk_disable(data->clk); 639 + mutex_unlock(&data->lock); 640 + 641 + return ret; 642 + } 643 + 644 + static void exynos_tmu_control(struct platform_device *pdev, bool on) 645 + { 646 + struct exynos_tmu_data *data = platform_get_drvdata(pdev); 647 + struct exynos_tmu_platform_data *pdata = data->pdata; 648 + unsigned int con, interrupt_en; 649 + 650 + mutex_lock(&data->lock); 651 + clk_enable(data->clk); 652 + 653 + con = pdata->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT | 654 + pdata->gain << EXYNOS_TMU_GAIN_SHIFT; 655 + 656 + if (data->soc == SOC_ARCH_EXYNOS) { 657 + con |= pdata->noise_cancel_mode << EXYNOS_TMU_TRIP_MODE_SHIFT; 658 + con |= (EXYNOS_MUX_ADDR_VALUE << EXYNOS_MUX_ADDR_SHIFT); 659 + } 660 + 661 + if (on) { 662 + con |= EXYNOS_TMU_CORE_ON; 663 + interrupt_en = pdata->trigger_level3_en << 12 | 664 + pdata->trigger_level2_en << 8 | 665 + pdata->trigger_level1_en << 4 | 666 + pdata->trigger_level0_en; 667 + } else { 668 + con |= EXYNOS_TMU_CORE_OFF; 669 + interrupt_en = 0; /* Disable all interrupts */ 670 + } 671 + writel(interrupt_en, data->base + EXYNOS_TMU_REG_INTEN); 672 + writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 673 + 674 + clk_disable(data->clk); 675 + mutex_unlock(&data->lock); 676 + } 677 + 678 + static int exynos_tmu_read(struct exynos_tmu_data *data) 679 + { 680 + u8 temp_code; 681 + int temp; 682 + 683 + mutex_lock(&data->lock); 684 + clk_enable(data->clk); 685 + 686 + temp_code = readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 687 + temp = code_to_temp(data, temp_code); 688 + 689 + clk_disable(data->clk); 690 + mutex_unlock(&data->lock); 691 + 692 + return temp; 693 + } 694 + 695 + static void exynos_tmu_work(struct work_struct *work) 696 + { 697 + struct exynos_tmu_data *data = container_of(work, 698 + struct exynos_tmu_data, irq_work); 699 + 700 + mutex_lock(&data->lock); 701 + clk_enable(data->clk); 702 + 703 + 704 + if (data->soc == SOC_ARCH_EXYNOS) 705 + writel(EXYNOS_TMU_CLEAR_RISE_INT, 706 + data->base + EXYNOS_TMU_REG_INTCLEAR); 707 + else 708 + writel(EXYNOS4210_TMU_INTCLEAR_VAL, 709 + data->base + EXYNOS_TMU_REG_INTCLEAR); 710 + 711 + clk_disable(data->clk); 712 + mutex_unlock(&data->lock); 713 + exynos_report_trigger(); 714 + enable_irq(data->irq); 715 + } 716 + 717 + static irqreturn_t exynos_tmu_irq(int irq, void *id) 718 + { 719 + struct exynos_tmu_data *data = id; 720 + 721 + disable_irq_nosync(irq); 722 + schedule_work(&data->irq_work); 723 + 724 + return IRQ_HANDLED; 725 + } 726 + static struct thermal_sensor_conf exynos_sensor_conf = { 727 + .name = "exynos-therm", 728 + .read_temperature = (int (*)(void *))exynos_tmu_read, 729 + }; 730 + 731 + #if defined(CONFIG_CPU_EXYNOS4210) 732 + static struct exynos_tmu_platform_data const exynos4210_default_tmu_data = { 733 + .threshold = 80, 734 + .trigger_levels[0] = 5, 735 + .trigger_levels[1] = 20, 736 + .trigger_levels[2] = 30, 737 + .trigger_level0_en = 1, 738 + .trigger_level1_en = 1, 739 + .trigger_level2_en = 1, 740 + .trigger_level3_en = 0, 741 + .gain = 15, 742 + .reference_voltage = 7, 743 + .cal_type = TYPE_ONE_POINT_TRIMMING, 744 + .freq_tab[0] = { 745 + .freq_clip_max = 800 * 1000, 746 + .temp_level = 85, 747 + }, 748 + .freq_tab[1] = { 749 + .freq_clip_max = 200 * 1000, 750 + .temp_level = 100, 751 + }, 752 + .freq_tab_count = 2, 753 + .type = SOC_ARCH_EXYNOS4210, 754 + }; 755 + #define EXYNOS4210_TMU_DRV_DATA (&exynos4210_default_tmu_data) 756 + #else 757 + #define EXYNOS4210_TMU_DRV_DATA (NULL) 758 + #endif 759 + 760 + #if defined(CONFIG_SOC_EXYNOS5250) || defined(CONFIG_SOC_EXYNOS4412) 761 + static struct exynos_tmu_platform_data const exynos_default_tmu_data = { 762 + .trigger_levels[0] = 85, 763 + .trigger_levels[1] = 103, 764 + .trigger_levels[2] = 110, 765 + .trigger_level0_en = 1, 766 + .trigger_level1_en = 1, 767 + .trigger_level2_en = 1, 768 + .trigger_level3_en = 0, 769 + .gain = 8, 770 + .reference_voltage = 16, 771 + .noise_cancel_mode = 4, 772 + .cal_type = TYPE_ONE_POINT_TRIMMING, 773 + .efuse_value = 55, 774 + .freq_tab[0] = { 775 + .freq_clip_max = 800 * 1000, 776 + .temp_level = 85, 777 + }, 778 + .freq_tab[1] = { 779 + .freq_clip_max = 200 * 1000, 780 + .temp_level = 103, 781 + }, 782 + .freq_tab_count = 2, 783 + .type = SOC_ARCH_EXYNOS, 784 + }; 785 + #define EXYNOS_TMU_DRV_DATA (&exynos_default_tmu_data) 786 + #else 787 + #define EXYNOS_TMU_DRV_DATA (NULL) 788 + #endif 789 + 790 + #ifdef CONFIG_OF 791 + static const struct of_device_id exynos_tmu_match[] = { 792 + { 793 + .compatible = "samsung,exynos4210-tmu", 794 + .data = (void *)EXYNOS4210_TMU_DRV_DATA, 795 + }, 796 + { 797 + .compatible = "samsung,exynos5250-tmu", 798 + .data = (void *)EXYNOS_TMU_DRV_DATA, 799 + }, 800 + {}, 801 + }; 802 + MODULE_DEVICE_TABLE(of, exynos_tmu_match); 803 + #else 804 + #define exynos_tmu_match NULL 805 + #endif 806 + 807 + static struct platform_device_id exynos_tmu_driver_ids[] = { 808 + { 809 + .name = "exynos4210-tmu", 810 + .driver_data = (kernel_ulong_t)EXYNOS4210_TMU_DRV_DATA, 811 + }, 812 + { 813 + .name = "exynos5250-tmu", 814 + .driver_data = (kernel_ulong_t)EXYNOS_TMU_DRV_DATA, 815 + }, 816 + { }, 817 + }; 818 + MODULE_DEVICE_TABLE(platform, exynos4_tmu_driver_ids); 819 + 820 + static inline struct exynos_tmu_platform_data *exynos_get_driver_data( 821 + struct platform_device *pdev) 822 + { 823 + #ifdef CONFIG_OF 824 + if (pdev->dev.of_node) { 825 + const struct of_device_id *match; 826 + match = of_match_node(exynos_tmu_match, pdev->dev.of_node); 827 + if (!match) 828 + return NULL; 829 + return (struct exynos_tmu_platform_data *) match->data; 830 + } 831 + #endif 832 + return (struct exynos_tmu_platform_data *) 833 + platform_get_device_id(pdev)->driver_data; 834 + } 835 + static int __devinit exynos_tmu_probe(struct platform_device *pdev) 836 + { 837 + struct exynos_tmu_data *data; 838 + struct exynos_tmu_platform_data *pdata = pdev->dev.platform_data; 839 + int ret, i; 840 + 841 + if (!pdata) 842 + pdata = exynos_get_driver_data(pdev); 843 + 844 + if (!pdata) { 845 + dev_err(&pdev->dev, "No platform init data supplied.\n"); 846 + return -ENODEV; 847 + } 848 + data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), 849 + GFP_KERNEL); 850 + if (!data) { 851 + dev_err(&pdev->dev, "Failed to allocate driver structure\n"); 852 + return -ENOMEM; 853 + } 854 + 855 + data->irq = platform_get_irq(pdev, 0); 856 + if (data->irq < 0) { 857 + dev_err(&pdev->dev, "Failed to get platform irq\n"); 858 + return data->irq; 859 + } 860 + 861 + INIT_WORK(&data->irq_work, exynos_tmu_work); 862 + 863 + data->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 864 + if (!data->mem) { 865 + dev_err(&pdev->dev, "Failed to get platform resource\n"); 866 + return -ENOENT; 867 + } 868 + 869 + data->base = devm_request_and_ioremap(&pdev->dev, data->mem); 870 + if (!data->base) { 871 + dev_err(&pdev->dev, "Failed to ioremap memory\n"); 872 + return -ENODEV; 873 + } 874 + 875 + ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, 876 + IRQF_TRIGGER_RISING, "exynos-tmu", data); 877 + if (ret) { 878 + dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 879 + return ret; 880 + } 881 + 882 + data->clk = clk_get(NULL, "tmu_apbif"); 883 + if (IS_ERR(data->clk)) { 884 + dev_err(&pdev->dev, "Failed to get clock\n"); 885 + return PTR_ERR(data->clk); 886 + } 887 + 888 + if (pdata->type == SOC_ARCH_EXYNOS || 889 + pdata->type == SOC_ARCH_EXYNOS4210) 890 + data->soc = pdata->type; 891 + else { 892 + ret = -EINVAL; 893 + dev_err(&pdev->dev, "Platform not supported\n"); 894 + goto err_clk; 895 + } 896 + 897 + data->pdata = pdata; 898 + platform_set_drvdata(pdev, data); 899 + mutex_init(&data->lock); 900 + 901 + ret = exynos_tmu_initialize(pdev); 902 + if (ret) { 903 + dev_err(&pdev->dev, "Failed to initialize TMU\n"); 904 + goto err_clk; 905 + } 906 + 907 + exynos_tmu_control(pdev, true); 908 + 909 + /* Register the sensor with thermal management interface */ 910 + (&exynos_sensor_conf)->private_data = data; 911 + exynos_sensor_conf.trip_data.trip_count = pdata->trigger_level0_en + 912 + pdata->trigger_level1_en + pdata->trigger_level2_en + 913 + pdata->trigger_level3_en; 914 + 915 + for (i = 0; i < exynos_sensor_conf.trip_data.trip_count; i++) 916 + exynos_sensor_conf.trip_data.trip_val[i] = 917 + pdata->threshold + pdata->trigger_levels[i]; 918 + 919 + exynos_sensor_conf.cooling_data.freq_clip_count = 920 + pdata->freq_tab_count; 921 + for (i = 0; i < pdata->freq_tab_count; i++) { 922 + exynos_sensor_conf.cooling_data.freq_data[i].freq_clip_max = 923 + pdata->freq_tab[i].freq_clip_max; 924 + exynos_sensor_conf.cooling_data.freq_data[i].temp_level = 925 + pdata->freq_tab[i].temp_level; 926 + } 927 + 928 + ret = exynos_register_thermal(&exynos_sensor_conf); 929 + if (ret) { 930 + dev_err(&pdev->dev, "Failed to register thermal interface\n"); 931 + goto err_clk; 932 + } 933 + return 0; 934 + err_clk: 935 + platform_set_drvdata(pdev, NULL); 936 + clk_put(data->clk); 937 + return ret; 938 + } 939 + 940 + static int __devexit exynos_tmu_remove(struct platform_device *pdev) 941 + { 942 + struct exynos_tmu_data *data = platform_get_drvdata(pdev); 943 + 944 + exynos_tmu_control(pdev, false); 945 + 946 + exynos_unregister_thermal(); 947 + 948 + clk_put(data->clk); 949 + 950 + platform_set_drvdata(pdev, NULL); 951 + 952 + return 0; 953 + } 954 + 955 + #ifdef CONFIG_PM_SLEEP 956 + static int exynos_tmu_suspend(struct device *dev) 957 + { 958 + exynos_tmu_control(to_platform_device(dev), false); 959 + 960 + return 0; 961 + } 962 + 963 + static int exynos_tmu_resume(struct device *dev) 964 + { 965 + struct platform_device *pdev = to_platform_device(dev); 966 + 967 + exynos_tmu_initialize(pdev); 968 + exynos_tmu_control(pdev, true); 969 + 970 + return 0; 971 + } 972 + 973 + static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, 974 + exynos_tmu_suspend, exynos_tmu_resume); 975 + #define EXYNOS_TMU_PM (&exynos_tmu_pm) 976 + #else 977 + #define EXYNOS_TMU_PM NULL 978 + #endif 979 + 980 + static struct platform_driver exynos_tmu_driver = { 981 + .driver = { 982 + .name = "exynos-tmu", 983 + .owner = THIS_MODULE, 984 + .pm = EXYNOS_TMU_PM, 985 + .of_match_table = exynos_tmu_match, 986 + }, 987 + .probe = exynos_tmu_probe, 988 + .remove = __devexit_p(exynos_tmu_remove), 989 + .id_table = exynos_tmu_driver_ids, 990 + }; 991 + 992 + module_platform_driver(exynos_tmu_driver); 993 + 994 + MODULE_DESCRIPTION("EXYNOS TMU Driver"); 995 + MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 996 + MODULE_LICENSE("GPL"); 997 + MODULE_ALIAS("platform:exynos-tmu");
+260
drivers/thermal/rcar_thermal.c
··· 1 + /* 2 + * R-Car THS/TSC thermal sensor driver 3 + * 4 + * Copyright (C) 2012 Renesas Solutions Corp. 5 + * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; version 2 of the License. 10 + * 11 + * This program is distributed in the hope that it will be useful, but 12 + * WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 + * General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License along 17 + * with this program; if not, write to the Free Software Foundation, Inc., 18 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 19 + */ 20 + #include <linux/delay.h> 21 + #include <linux/err.h> 22 + #include <linux/io.h> 23 + #include <linux/module.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/slab.h> 26 + #include <linux/spinlock.h> 27 + #include <linux/thermal.h> 28 + 29 + #define THSCR 0x2c 30 + #define THSSR 0x30 31 + 32 + /* THSCR */ 33 + #define CPTAP 0xf 34 + 35 + /* THSSR */ 36 + #define CTEMP 0x3f 37 + 38 + 39 + struct rcar_thermal_priv { 40 + void __iomem *base; 41 + struct device *dev; 42 + spinlock_t lock; 43 + u32 comp; 44 + }; 45 + 46 + /* 47 + * basic functions 48 + */ 49 + static u32 rcar_thermal_read(struct rcar_thermal_priv *priv, u32 reg) 50 + { 51 + unsigned long flags; 52 + u32 ret; 53 + 54 + spin_lock_irqsave(&priv->lock, flags); 55 + 56 + ret = ioread32(priv->base + reg); 57 + 58 + spin_unlock_irqrestore(&priv->lock, flags); 59 + 60 + return ret; 61 + } 62 + 63 + #if 0 /* no user at this point */ 64 + static void rcar_thermal_write(struct rcar_thermal_priv *priv, 65 + u32 reg, u32 data) 66 + { 67 + unsigned long flags; 68 + 69 + spin_lock_irqsave(&priv->lock, flags); 70 + 71 + iowrite32(data, priv->base + reg); 72 + 73 + spin_unlock_irqrestore(&priv->lock, flags); 74 + } 75 + #endif 76 + 77 + static void rcar_thermal_bset(struct rcar_thermal_priv *priv, u32 reg, 78 + u32 mask, u32 data) 79 + { 80 + unsigned long flags; 81 + u32 val; 82 + 83 + spin_lock_irqsave(&priv->lock, flags); 84 + 85 + val = ioread32(priv->base + reg); 86 + val &= ~mask; 87 + val |= (data & mask); 88 + iowrite32(val, priv->base + reg); 89 + 90 + spin_unlock_irqrestore(&priv->lock, flags); 91 + } 92 + 93 + /* 94 + * zone device functions 95 + */ 96 + static int rcar_thermal_get_temp(struct thermal_zone_device *zone, 97 + unsigned long *temp) 98 + { 99 + struct rcar_thermal_priv *priv = zone->devdata; 100 + int val, min, max, tmp; 101 + 102 + tmp = -200; /* default */ 103 + while (1) { 104 + if (priv->comp < 1 || priv->comp > 12) { 105 + dev_err(priv->dev, 106 + "THSSR invalid data (%d)\n", priv->comp); 107 + priv->comp = 4; /* for next thermal */ 108 + return -EINVAL; 109 + } 110 + 111 + /* 112 + * THS comparator offset and the reference temperature 113 + * 114 + * Comparator | reference | Temperature field 115 + * offset | temperature | measurement 116 + * | (degrees C) | (degrees C) 117 + * -------------+---------------+------------------- 118 + * 1 | -45 | -45 to -30 119 + * 2 | -30 | -30 to -15 120 + * 3 | -15 | -15 to 0 121 + * 4 | 0 | 0 to +15 122 + * 5 | +15 | +15 to +30 123 + * 6 | +30 | +30 to +45 124 + * 7 | +45 | +45 to +60 125 + * 8 | +60 | +60 to +75 126 + * 9 | +75 | +75 to +90 127 + * 10 | +90 | +90 to +105 128 + * 11 | +105 | +105 to +120 129 + * 12 | +120 | +120 to +135 130 + */ 131 + 132 + /* calculate thermal limitation */ 133 + min = (priv->comp * 15) - 60; 134 + max = min + 15; 135 + 136 + /* 137 + * we need to wait 300us after changing comparator offset 138 + * to get stable temperature. 139 + * see "Usage Notes" on datasheet 140 + */ 141 + rcar_thermal_bset(priv, THSCR, CPTAP, priv->comp); 142 + udelay(300); 143 + 144 + /* calculate current temperature */ 145 + val = rcar_thermal_read(priv, THSSR) & CTEMP; 146 + val = (val * 5) - 65; 147 + 148 + dev_dbg(priv->dev, "comp/min/max/val = %d/%d/%d/%d\n", 149 + priv->comp, min, max, val); 150 + 151 + /* 152 + * If val is same as min/max, then, 153 + * it should try again on next comparator. 154 + * But the val might be correct temperature. 155 + * Keep it on "tmp" and compare with next val. 156 + */ 157 + if (tmp == val) 158 + break; 159 + 160 + if (val <= min) { 161 + tmp = min; 162 + priv->comp--; /* try again */ 163 + } else if (val >= max) { 164 + tmp = max; 165 + priv->comp++; /* try again */ 166 + } else { 167 + tmp = val; 168 + break; 169 + } 170 + } 171 + 172 + *temp = tmp; 173 + return 0; 174 + } 175 + 176 + static struct thermal_zone_device_ops rcar_thermal_zone_ops = { 177 + .get_temp = rcar_thermal_get_temp, 178 + }; 179 + 180 + /* 181 + * platform functions 182 + */ 183 + static int rcar_thermal_probe(struct platform_device *pdev) 184 + { 185 + struct thermal_zone_device *zone; 186 + struct rcar_thermal_priv *priv; 187 + struct resource *res; 188 + int ret; 189 + 190 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 191 + if (!res) { 192 + dev_err(&pdev->dev, "Could not get platform resource\n"); 193 + return -ENODEV; 194 + } 195 + 196 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 197 + if (!priv) { 198 + dev_err(&pdev->dev, "Could not allocate priv\n"); 199 + return -ENOMEM; 200 + } 201 + 202 + priv->comp = 4; /* basic setup */ 203 + priv->dev = &pdev->dev; 204 + spin_lock_init(&priv->lock); 205 + priv->base = devm_ioremap_nocache(&pdev->dev, 206 + res->start, resource_size(res)); 207 + if (!priv->base) { 208 + dev_err(&pdev->dev, "Unable to ioremap thermal register\n"); 209 + ret = -ENOMEM; 210 + goto error_free_priv; 211 + } 212 + 213 + zone = thermal_zone_device_register("rcar_thermal", 0, priv, 214 + &rcar_thermal_zone_ops, 0, 0); 215 + if (IS_ERR(zone)) { 216 + dev_err(&pdev->dev, "thermal zone device is NULL\n"); 217 + ret = PTR_ERR(zone); 218 + goto error_iounmap; 219 + } 220 + 221 + platform_set_drvdata(pdev, zone); 222 + 223 + dev_info(&pdev->dev, "proved\n"); 224 + 225 + return 0; 226 + 227 + error_iounmap: 228 + devm_iounmap(&pdev->dev, priv->base); 229 + error_free_priv: 230 + devm_kfree(&pdev->dev, priv); 231 + 232 + return ret; 233 + } 234 + 235 + static int rcar_thermal_remove(struct platform_device *pdev) 236 + { 237 + struct thermal_zone_device *zone = platform_get_drvdata(pdev); 238 + struct rcar_thermal_priv *priv = zone->devdata; 239 + 240 + thermal_zone_device_unregister(zone); 241 + platform_set_drvdata(pdev, NULL); 242 + 243 + devm_iounmap(&pdev->dev, priv->base); 244 + devm_kfree(&pdev->dev, priv); 245 + 246 + return 0; 247 + } 248 + 249 + static struct platform_driver rcar_thermal_driver = { 250 + .driver = { 251 + .name = "rcar_thermal", 252 + }, 253 + .probe = rcar_thermal_probe, 254 + .remove = rcar_thermal_remove, 255 + }; 256 + module_platform_driver(rcar_thermal_driver); 257 + 258 + MODULE_LICENSE("GPL"); 259 + MODULE_DESCRIPTION("R-Car THS/TSC thermal sensor driver"); 260 + MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
+1 -1
drivers/thermal/spear_thermal.c
··· 147 147 writel_relaxed(stdev->flags, stdev->thermal_base); 148 148 149 149 spear_thermal = thermal_zone_device_register("spear_thermal", 0, 0, 150 - stdev, &ops, 0, 0, 0, 0); 150 + stdev, &ops, 0, 0); 151 151 if (IS_ERR(spear_thermal)) { 152 152 dev_err(&pdev->dev, "thermal zone device is NULL\n"); 153 153 ret = PTR_ERR(spear_thermal);
+200 -121
drivers/thermal/thermal_sys.c
··· 41 41 MODULE_DESCRIPTION("Generic thermal management sysfs support"); 42 42 MODULE_LICENSE("GPL"); 43 43 44 - struct thermal_cooling_device_instance { 44 + #define THERMAL_NO_TARGET -1UL 45 + /* 46 + * This structure is used to describe the behavior of 47 + * a certain cooling device on a certain trip point 48 + * in a certain thermal zone 49 + */ 50 + struct thermal_instance { 45 51 int id; 46 52 char name[THERMAL_NAME_LENGTH]; 47 53 struct thermal_zone_device *tz; 48 54 struct thermal_cooling_device *cdev; 49 55 int trip; 56 + unsigned long upper; /* Highest cooling state for this trip point */ 57 + unsigned long lower; /* Lowest cooling state for this trip point */ 58 + unsigned long target; /* expected cooling state */ 50 59 char attr_name[THERMAL_NAME_LENGTH]; 51 60 struct device_attribute attr; 52 - struct list_head node; 61 + struct list_head tz_node; /* node in tz->thermal_instances */ 62 + struct list_head cdev_node; /* node in cdev->thermal_instances */ 53 63 }; 54 64 55 65 static DEFINE_IDR(thermal_tz_idr); ··· 318 308 if (!strncmp("Processor", cdev->type, 319 309 sizeof("Processor"))) 320 310 thermal_zone_bind_cooling_device(tz, 321 - THERMAL_TRIPS_NONE, 322 - cdev); 311 + THERMAL_TRIPS_NONE, cdev, 312 + THERMAL_NO_LIMIT, 313 + THERMAL_NO_LIMIT); 323 314 } 324 315 mutex_unlock(&thermal_list_lock); 325 316 if (!tz->passive_delay) ··· 337 326 mutex_unlock(&thermal_list_lock); 338 327 tz->passive_delay = 0; 339 328 } 340 - 341 - tz->tc1 = 1; 342 - tz->tc2 = 1; 343 329 344 330 tz->forced_passive = state; 345 331 ··· 433 425 thermal_cooling_device_trip_point_show(struct device *dev, 434 426 struct device_attribute *attr, char *buf) 435 427 { 436 - struct thermal_cooling_device_instance *instance; 428 + struct thermal_instance *instance; 437 429 438 430 instance = 439 - container_of(attr, struct thermal_cooling_device_instance, attr); 431 + container_of(attr, struct thermal_instance, attr); 440 432 441 433 if (instance->trip == THERMAL_TRIPS_NONE) 442 434 return sprintf(buf, "-1\n"); ··· 598 590 temp->tz = tz; 599 591 hwmon->count++; 600 592 601 - snprintf(temp->temp_input.name, THERMAL_NAME_LENGTH, 593 + snprintf(temp->temp_input.name, sizeof(temp->temp_input.name), 602 594 "temp%d_input", hwmon->count); 603 595 temp->temp_input.attr.attr.name = temp->temp_input.name; 604 596 temp->temp_input.attr.attr.mode = 0444; ··· 611 603 if (tz->ops->get_crit_temp) { 612 604 unsigned long temperature; 613 605 if (!tz->ops->get_crit_temp(tz, &temperature)) { 614 - snprintf(temp->temp_crit.name, THERMAL_NAME_LENGTH, 606 + snprintf(temp->temp_crit.name, 607 + sizeof(temp->temp_crit.name), 615 608 "temp%d_crit", hwmon->count); 616 609 temp->temp_crit.attr.attr.name = temp->temp_crit.name; 617 610 temp->temp_crit.attr.attr.mode = 0444; ··· 713 704 cancel_delayed_work(&tz->poll_queue); 714 705 } 715 706 716 - static void thermal_zone_device_passive(struct thermal_zone_device *tz, 717 - int temp, int trip_temp, int trip) 718 - { 719 - int trend = 0; 720 - struct thermal_cooling_device_instance *instance; 721 - struct thermal_cooling_device *cdev; 722 - long state, max_state; 723 - 724 - /* 725 - * Above Trip? 726 - * ----------- 727 - * Calculate the thermal trend (using the passive cooling equation) 728 - * and modify the performance limit for all passive cooling devices 729 - * accordingly. Note that we assume symmetry. 730 - */ 731 - if (temp >= trip_temp) { 732 - tz->passive = true; 733 - 734 - trend = (tz->tc1 * (temp - tz->last_temperature)) + 735 - (tz->tc2 * (temp - trip_temp)); 736 - 737 - /* Heating up? */ 738 - if (trend > 0) { 739 - list_for_each_entry(instance, &tz->cooling_devices, 740 - node) { 741 - if (instance->trip != trip) 742 - continue; 743 - cdev = instance->cdev; 744 - cdev->ops->get_cur_state(cdev, &state); 745 - cdev->ops->get_max_state(cdev, &max_state); 746 - if (state++ < max_state) 747 - cdev->ops->set_cur_state(cdev, state); 748 - } 749 - } else if (trend < 0) { /* Cooling off? */ 750 - list_for_each_entry(instance, &tz->cooling_devices, 751 - node) { 752 - if (instance->trip != trip) 753 - continue; 754 - cdev = instance->cdev; 755 - cdev->ops->get_cur_state(cdev, &state); 756 - cdev->ops->get_max_state(cdev, &max_state); 757 - if (state > 0) 758 - cdev->ops->set_cur_state(cdev, --state); 759 - } 760 - } 761 - return; 762 - } 763 - 764 - /* 765 - * Below Trip? 766 - * ----------- 767 - * Implement passive cooling hysteresis to slowly increase performance 768 - * and avoid thrashing around the passive trip point. Note that we 769 - * assume symmetry. 770 - */ 771 - list_for_each_entry(instance, &tz->cooling_devices, node) { 772 - if (instance->trip != trip) 773 - continue; 774 - cdev = instance->cdev; 775 - cdev->ops->get_cur_state(cdev, &state); 776 - cdev->ops->get_max_state(cdev, &max_state); 777 - if (state > 0) 778 - cdev->ops->set_cur_state(cdev, --state); 779 - if (state == 0) 780 - tz->passive = false; 781 - } 782 - } 783 - 784 707 static void thermal_zone_device_check(struct work_struct *work) 785 708 { 786 709 struct thermal_zone_device *tz = container_of(work, struct ··· 732 791 */ 733 792 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 734 793 int trip, 735 - struct thermal_cooling_device *cdev) 794 + struct thermal_cooling_device *cdev, 795 + unsigned long upper, unsigned long lower) 736 796 { 737 - struct thermal_cooling_device_instance *dev; 738 - struct thermal_cooling_device_instance *pos; 797 + struct thermal_instance *dev; 798 + struct thermal_instance *pos; 739 799 struct thermal_zone_device *pos1; 740 800 struct thermal_cooling_device *pos2; 801 + unsigned long max_state; 741 802 int result; 742 803 743 804 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) ··· 757 814 if (tz != pos1 || cdev != pos2) 758 815 return -EINVAL; 759 816 817 + cdev->ops->get_max_state(cdev, &max_state); 818 + 819 + /* lower default 0, upper default max_state */ 820 + lower = lower == THERMAL_NO_LIMIT ? 0 : lower; 821 + upper = upper == THERMAL_NO_LIMIT ? max_state : upper; 822 + 823 + if (lower > upper || upper > max_state) 824 + return -EINVAL; 825 + 760 826 dev = 761 - kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL); 827 + kzalloc(sizeof(struct thermal_instance), GFP_KERNEL); 762 828 if (!dev) 763 829 return -ENOMEM; 764 830 dev->tz = tz; 765 831 dev->cdev = cdev; 766 832 dev->trip = trip; 833 + dev->upper = upper; 834 + dev->lower = lower; 835 + dev->target = THERMAL_NO_TARGET; 836 + 767 837 result = get_idr(&tz->idr, &tz->lock, &dev->id); 768 838 if (result) 769 839 goto free_mem; ··· 797 841 goto remove_symbol_link; 798 842 799 843 mutex_lock(&tz->lock); 800 - list_for_each_entry(pos, &tz->cooling_devices, node) 844 + mutex_lock(&cdev->lock); 845 + list_for_each_entry(pos, &tz->thermal_instances, tz_node) 801 846 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { 802 847 result = -EEXIST; 803 848 break; 804 849 } 805 - if (!result) 806 - list_add_tail(&dev->node, &tz->cooling_devices); 850 + if (!result) { 851 + list_add_tail(&dev->tz_node, &tz->thermal_instances); 852 + list_add_tail(&dev->cdev_node, &cdev->thermal_instances); 853 + } 854 + mutex_unlock(&cdev->lock); 807 855 mutex_unlock(&tz->lock); 808 856 809 857 if (!result) ··· 837 877 int trip, 838 878 struct thermal_cooling_device *cdev) 839 879 { 840 - struct thermal_cooling_device_instance *pos, *next; 880 + struct thermal_instance *pos, *next; 841 881 842 882 mutex_lock(&tz->lock); 843 - list_for_each_entry_safe(pos, next, &tz->cooling_devices, node) { 883 + mutex_lock(&cdev->lock); 884 + list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { 844 885 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { 845 - list_del(&pos->node); 886 + list_del(&pos->tz_node); 887 + list_del(&pos->cdev_node); 888 + mutex_unlock(&cdev->lock); 846 889 mutex_unlock(&tz->lock); 847 890 goto unbind; 848 891 } 849 892 } 893 + mutex_unlock(&cdev->lock); 850 894 mutex_unlock(&tz->lock); 851 895 852 896 return -ENODEV; ··· 898 934 struct thermal_zone_device *pos; 899 935 int result; 900 936 901 - if (strlen(type) >= THERMAL_NAME_LENGTH) 937 + if (type && strlen(type) >= THERMAL_NAME_LENGTH) 902 938 return ERR_PTR(-EINVAL); 903 939 904 940 if (!ops || !ops->get_max_state || !ops->get_cur_state || ··· 915 951 return ERR_PTR(result); 916 952 } 917 953 918 - strcpy(cdev->type, type); 954 + strcpy(cdev->type, type ? : ""); 955 + mutex_init(&cdev->lock); 956 + INIT_LIST_HEAD(&cdev->thermal_instances); 919 957 cdev->ops = ops; 958 + cdev->updated = true; 920 959 cdev->device.class = &thermal_class; 921 960 cdev->devdata = devdata; 922 961 dev_set_name(&cdev->device, "cooling_device%d", cdev->id); ··· 1011 1044 } 1012 1045 EXPORT_SYMBOL(thermal_cooling_device_unregister); 1013 1046 1047 + static void thermal_cdev_do_update(struct thermal_cooling_device *cdev) 1048 + { 1049 + struct thermal_instance *instance; 1050 + unsigned long target = 0; 1051 + 1052 + /* cooling device is updated*/ 1053 + if (cdev->updated) 1054 + return; 1055 + 1056 + mutex_lock(&cdev->lock); 1057 + /* Make sure cdev enters the deepest cooling state */ 1058 + list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { 1059 + if (instance->target == THERMAL_NO_TARGET) 1060 + continue; 1061 + if (instance->target > target) 1062 + target = instance->target; 1063 + } 1064 + mutex_unlock(&cdev->lock); 1065 + cdev->ops->set_cur_state(cdev, target); 1066 + cdev->updated = true; 1067 + } 1068 + 1069 + static void thermal_zone_do_update(struct thermal_zone_device *tz) 1070 + { 1071 + struct thermal_instance *instance; 1072 + 1073 + list_for_each_entry(instance, &tz->thermal_instances, tz_node) 1074 + thermal_cdev_do_update(instance->cdev); 1075 + } 1076 + 1077 + /* 1078 + * Cooling algorithm for both active and passive cooling 1079 + * 1080 + * 1. if the temperature is higher than a trip point, 1081 + * a. if the trend is THERMAL_TREND_RAISING, use higher cooling 1082 + * state for this trip point 1083 + * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling 1084 + * state for this trip point 1085 + * 1086 + * 2. if the temperature is lower than a trip point, use lower 1087 + * cooling state for this trip point 1088 + * 1089 + * Note that this behaves the same as the previous passive cooling 1090 + * algorithm. 1091 + */ 1092 + 1093 + static void thermal_zone_trip_update(struct thermal_zone_device *tz, 1094 + int trip, long temp) 1095 + { 1096 + struct thermal_instance *instance; 1097 + struct thermal_cooling_device *cdev = NULL; 1098 + unsigned long cur_state, max_state; 1099 + long trip_temp; 1100 + enum thermal_trip_type trip_type; 1101 + enum thermal_trend trend; 1102 + 1103 + if (trip == THERMAL_TRIPS_NONE) { 1104 + trip_temp = tz->forced_passive; 1105 + trip_type = THERMAL_TRIPS_NONE; 1106 + } else { 1107 + tz->ops->get_trip_temp(tz, trip, &trip_temp); 1108 + tz->ops->get_trip_type(tz, trip, &trip_type); 1109 + } 1110 + 1111 + if (!tz->ops->get_trend || tz->ops->get_trend(tz, trip, &trend)) { 1112 + /* 1113 + * compare the current temperature and previous temperature 1114 + * to get the thermal trend, if no special requirement 1115 + */ 1116 + if (tz->temperature > tz->last_temperature) 1117 + trend = THERMAL_TREND_RAISING; 1118 + else if (tz->temperature < tz->last_temperature) 1119 + trend = THERMAL_TREND_DROPPING; 1120 + else 1121 + trend = THERMAL_TREND_STABLE; 1122 + } 1123 + 1124 + if (temp >= trip_temp) { 1125 + list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 1126 + if (instance->trip != trip) 1127 + continue; 1128 + 1129 + cdev = instance->cdev; 1130 + 1131 + cdev->ops->get_cur_state(cdev, &cur_state); 1132 + cdev->ops->get_max_state(cdev, &max_state); 1133 + 1134 + if (trend == THERMAL_TREND_RAISING) { 1135 + cur_state = cur_state < instance->upper ? 1136 + (cur_state + 1) : instance->upper; 1137 + } else if (trend == THERMAL_TREND_DROPPING) { 1138 + cur_state = cur_state > instance->lower ? 1139 + (cur_state - 1) : instance->lower; 1140 + } 1141 + 1142 + /* activate a passive thermal instance */ 1143 + if ((trip_type == THERMAL_TRIP_PASSIVE || 1144 + trip_type == THERMAL_TRIPS_NONE) && 1145 + instance->target == THERMAL_NO_TARGET) 1146 + tz->passive++; 1147 + 1148 + instance->target = cur_state; 1149 + cdev->updated = false; /* cooling device needs update */ 1150 + } 1151 + } else { /* below trip */ 1152 + list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 1153 + if (instance->trip != trip) 1154 + continue; 1155 + 1156 + /* Do not use the inactive thermal instance */ 1157 + if (instance->target == THERMAL_NO_TARGET) 1158 + continue; 1159 + cdev = instance->cdev; 1160 + cdev->ops->get_cur_state(cdev, &cur_state); 1161 + 1162 + cur_state = cur_state > instance->lower ? 1163 + (cur_state - 1) : THERMAL_NO_TARGET; 1164 + 1165 + /* deactivate a passive thermal instance */ 1166 + if ((trip_type == THERMAL_TRIP_PASSIVE || 1167 + trip_type == THERMAL_TRIPS_NONE) && 1168 + cur_state == THERMAL_NO_TARGET) 1169 + tz->passive--; 1170 + instance->target = cur_state; 1171 + cdev->updated = false; /* cooling device needs update */ 1172 + } 1173 + } 1174 + 1175 + return; 1176 + } 1014 1177 /** 1015 1178 * thermal_zone_device_update - force an update of a thermal zone's state 1016 1179 * @ttz: the thermal zone to update ··· 1151 1054 int count, ret = 0; 1152 1055 long temp, trip_temp; 1153 1056 enum thermal_trip_type trip_type; 1154 - struct thermal_cooling_device_instance *instance; 1155 - struct thermal_cooling_device *cdev; 1156 1057 1157 1058 mutex_lock(&tz->lock); 1158 1059 ··· 1159 1064 pr_warn("failed to read out thermal zone %d\n", tz->id); 1160 1065 goto leave; 1161 1066 } 1067 + 1068 + tz->last_temperature = tz->temperature; 1069 + tz->temperature = temp; 1162 1070 1163 1071 for (count = 0; count < tz->trips; count++) { 1164 1072 tz->ops->get_trip_type(tz, count, &trip_type); ··· 1186 1088 tz->ops->notify(tz, count, trip_type); 1187 1089 break; 1188 1090 case THERMAL_TRIP_ACTIVE: 1189 - list_for_each_entry(instance, &tz->cooling_devices, 1190 - node) { 1191 - if (instance->trip != count) 1192 - continue; 1193 - 1194 - cdev = instance->cdev; 1195 - 1196 - if (temp >= trip_temp) 1197 - cdev->ops->set_cur_state(cdev, 1); 1198 - else 1199 - cdev->ops->set_cur_state(cdev, 0); 1200 - } 1091 + thermal_zone_trip_update(tz, count, temp); 1201 1092 break; 1202 1093 case THERMAL_TRIP_PASSIVE: 1203 1094 if (temp >= trip_temp || tz->passive) 1204 - thermal_zone_device_passive(tz, temp, 1205 - trip_temp, count); 1095 + thermal_zone_trip_update(tz, count, temp); 1206 1096 break; 1207 1097 } 1208 1098 } 1209 1099 1210 1100 if (tz->forced_passive) 1211 - thermal_zone_device_passive(tz, temp, tz->forced_passive, 1212 - THERMAL_TRIPS_NONE); 1213 - 1214 - tz->last_temperature = temp; 1101 + thermal_zone_trip_update(tz, THERMAL_TRIPS_NONE, temp); 1102 + thermal_zone_do_update(tz); 1215 1103 1216 1104 leave: 1217 1105 if (tz->passive) ··· 1320 1236 * @mask: a bit string indicating the writeablility of trip points 1321 1237 * @devdata: private device data 1322 1238 * @ops: standard thermal zone device callbacks 1323 - * @tc1: thermal coefficient 1 for passive calculations 1324 - * @tc2: thermal coefficient 2 for passive calculations 1325 1239 * @passive_delay: number of milliseconds to wait between polls when 1326 1240 * performing passive cooling 1327 1241 * @polling_delay: number of milliseconds to wait between polls when checking ··· 1327 1245 * driven systems) 1328 1246 * 1329 1247 * thermal_zone_device_unregister() must be called when the device is no 1330 - * longer needed. The passive cooling formula uses tc1 and tc2 as described in 1331 - * section 11.1.5.1 of the ACPI specification 3.0. 1248 + * longer needed. The passive cooling depends on the .get_trend() return value. 1332 1249 */ 1333 1250 struct thermal_zone_device *thermal_zone_device_register(const char *type, 1334 1251 int trips, int mask, void *devdata, 1335 1252 const struct thermal_zone_device_ops *ops, 1336 - int tc1, int tc2, int passive_delay, int polling_delay) 1253 + int passive_delay, int polling_delay) 1337 1254 { 1338 1255 struct thermal_zone_device *tz; 1339 1256 struct thermal_cooling_device *pos; ··· 1341 1260 int count; 1342 1261 int passive = 0; 1343 1262 1344 - if (strlen(type) >= THERMAL_NAME_LENGTH) 1263 + if (type && strlen(type) >= THERMAL_NAME_LENGTH) 1345 1264 return ERR_PTR(-EINVAL); 1346 1265 1347 1266 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) ··· 1354 1273 if (!tz) 1355 1274 return ERR_PTR(-ENOMEM); 1356 1275 1357 - INIT_LIST_HEAD(&tz->cooling_devices); 1276 + INIT_LIST_HEAD(&tz->thermal_instances); 1358 1277 idr_init(&tz->idr); 1359 1278 mutex_init(&tz->lock); 1360 1279 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id); ··· 1363 1282 return ERR_PTR(result); 1364 1283 } 1365 1284 1366 - strcpy(tz->type, type); 1285 + strcpy(tz->type, type ? : ""); 1367 1286 tz->ops = ops; 1368 1287 tz->device.class = &thermal_class; 1369 1288 tz->devdata = devdata; 1370 1289 tz->trips = trips; 1371 - tz->tc1 = tc1; 1372 - tz->tc2 = tc2; 1373 1290 tz->passive_delay = passive_delay; 1374 1291 tz->polling_delay = polling_delay; 1375 1292
+58
include/linux/cpu_cooling.h
··· 1 + /* 2 + * linux/include/linux/cpu_cooling.h 3 + * 4 + * Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) 5 + * Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org> 6 + * 7 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; version 2 of the License. 11 + * 12 + * This program is distributed in the hope that it will be useful, but 13 + * WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + * 17 + * You should have received a copy of the GNU General Public License along 18 + * with this program; if not, write to the Free Software Foundation, Inc., 19 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 + * 21 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 + */ 23 + 24 + #ifndef __CPU_COOLING_H__ 25 + #define __CPU_COOLING_H__ 26 + 27 + #include <linux/thermal.h> 28 + 29 + #define CPUFREQ_COOLING_START 0 30 + #define CPUFREQ_COOLING_STOP 1 31 + 32 + #ifdef CONFIG_CPU_THERMAL 33 + /** 34 + * cpufreq_cooling_register - function to create cpufreq cooling device. 35 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen 36 + */ 37 + struct thermal_cooling_device *cpufreq_cooling_register( 38 + struct cpumask *clip_cpus); 39 + 40 + /** 41 + * cpufreq_cooling_unregister - function to remove cpufreq cooling device. 42 + * @cdev: thermal cooling device pointer. 43 + */ 44 + void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); 45 + #else /* !CONFIG_CPU_THERMAL */ 46 + static inline struct thermal_cooling_device *cpufreq_cooling_register( 47 + struct cpumask *clip_cpus) 48 + { 49 + return NULL; 50 + } 51 + static inline void cpufreq_cooling_unregister( 52 + struct thermal_cooling_device *cdev) 53 + { 54 + return; 55 + } 56 + #endif /* CONFIG_CPU_THERMAL */ 57 + 58 + #endif /* __CPU_COOLING_H__ */
+40 -7
include/linux/platform_data/exynos4_tmu.h include/linux/platform_data/exynos_thermal.h
··· 1 1 /* 2 - * exynos4_tmu.h - Samsung EXYNOS4 TMU (Thermal Management Unit) 2 + * exynos_thermal.h - Samsung EXYNOS TMU (Thermal Management Unit) 3 3 * 4 4 * Copyright (C) 2011 Samsung Electronics 5 5 * Donggeun Kim <dg77.kim@samsung.com> ··· 19 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 20 */ 21 21 22 - #ifndef _LINUX_EXYNOS4_TMU_H 23 - #define _LINUX_EXYNOS4_TMU_H 22 + #ifndef _LINUX_EXYNOS_THERMAL_H 23 + #define _LINUX_EXYNOS_THERMAL_H 24 + #include <linux/cpu_cooling.h> 24 25 25 26 enum calibration_type { 26 27 TYPE_ONE_POINT_TRIMMING, ··· 29 28 TYPE_NONE, 30 29 }; 31 30 31 + enum soc_type { 32 + SOC_ARCH_EXYNOS4210 = 1, 33 + SOC_ARCH_EXYNOS, 34 + }; 32 35 /** 33 - * struct exynos4_tmu_platform_data 36 + * struct freq_clip_table 37 + * @freq_clip_max: maximum frequency allowed for this cooling state. 38 + * @temp_level: Temperature level at which the temperature clipping will 39 + * happen. 40 + * @mask_val: cpumask of the allowed cpu's where the clipping will take place. 41 + * 42 + * This structure is required to be filled and passed to the 43 + * cpufreq_cooling_unregister function. 44 + */ 45 + struct freq_clip_table { 46 + unsigned int freq_clip_max; 47 + unsigned int temp_level; 48 + const struct cpumask *mask_val; 49 + }; 50 + 51 + /** 52 + * struct exynos_tmu_platform_data 34 53 * @threshold: basic temperature for generating interrupt 35 54 * 25 <= threshold <= 125 [unit: degree Celsius] 36 55 * @trigger_levels: array for each interrupt levels ··· 84 63 * @reference_voltage: reference voltage of amplifier 85 64 * in the positive-TC generator block 86 65 * 0 <= reference_voltage <= 31 66 + * @noise_cancel_mode: noise cancellation mode 67 + * 000, 100, 101, 110 and 111 can be different modes 68 + * @type: determines the type of SOC 69 + * @efuse_value: platform defined fuse value 87 70 * @cal_type: calibration type for temperature 71 + * @freq_clip_table: Table representing frequency reduction percentage. 72 + * @freq_tab_count: Count of the above table as frequency reduction may 73 + * applicable to only some of the trigger levels. 88 74 * 89 - * This structure is required for configuration of exynos4_tmu driver. 75 + * This structure is required for configuration of exynos_tmu driver. 90 76 */ 91 - struct exynos4_tmu_platform_data { 77 + struct exynos_tmu_platform_data { 92 78 u8 threshold; 93 79 u8 trigger_levels[4]; 94 80 bool trigger_level0_en; ··· 105 77 106 78 u8 gain; 107 79 u8 reference_voltage; 80 + u8 noise_cancel_mode; 81 + u32 efuse_value; 108 82 109 83 enum calibration_type cal_type; 84 + enum soc_type type; 85 + struct freq_clip_table freq_tab[4]; 86 + unsigned int freq_tab_count; 110 87 }; 111 - #endif /* _LINUX_EXYNOS4_TMU_H */ 88 + #endif /* _LINUX_EXYNOS_THERMAL_H */
+20 -8
include/linux/thermal.h
··· 44 44 THERMAL_TRIP_CRITICAL, 45 45 }; 46 46 47 + enum thermal_trend { 48 + THERMAL_TREND_STABLE, /* temperature is stable */ 49 + THERMAL_TREND_RAISING, /* temperature is raising */ 50 + THERMAL_TREND_DROPPING, /* temperature is dropping */ 51 + }; 52 + 47 53 struct thermal_zone_device_ops { 48 54 int (*bind) (struct thermal_zone_device *, 49 55 struct thermal_cooling_device *); ··· 71 65 int (*set_trip_hyst) (struct thermal_zone_device *, int, 72 66 unsigned long); 73 67 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *); 68 + int (*get_trend) (struct thermal_zone_device *, int, 69 + enum thermal_trend *); 74 70 int (*notify) (struct thermal_zone_device *, int, 75 71 enum thermal_trip_type); 76 72 }; ··· 83 75 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long); 84 76 }; 85 77 78 + #define THERMAL_NO_LIMIT -1UL /* no upper/lower limit requirement */ 79 + 86 80 #define THERMAL_TRIPS_NONE -1 87 81 #define THERMAL_MAX_TRIPS 12 88 82 #define THERMAL_NAME_LENGTH 20 ··· 94 84 struct device device; 95 85 void *devdata; 96 86 const struct thermal_cooling_device_ops *ops; 87 + bool updated; /* true if the cooling device does not need update */ 88 + struct mutex lock; /* protect thermal_instances list */ 89 + struct list_head thermal_instances; 97 90 struct list_head node; 98 91 }; 99 92 ··· 118 105 struct thermal_attr *trip_hyst_attrs; 119 106 void *devdata; 120 107 int trips; 121 - int tc1; 122 - int tc2; 123 108 int passive_delay; 124 109 int polling_delay; 110 + int temperature; 125 111 int last_temperature; 126 - bool passive; 112 + int passive; 127 113 unsigned int forced_passive; 128 114 const struct thermal_zone_device_ops *ops; 129 - struct list_head cooling_devices; 115 + struct list_head thermal_instances; 130 116 struct idr idr; 131 - struct mutex lock; /* protect cooling devices list */ 117 + struct mutex lock; /* protect thermal_instances list */ 132 118 struct list_head node; 133 119 struct delayed_work poll_queue; 134 120 }; ··· 164 152 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1) 165 153 166 154 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, 167 - void *, const struct thermal_zone_device_ops *, int tc1, 168 - int tc2, int passive_freq, int polling_freq); 155 + void *, const struct thermal_zone_device_ops *, int, int); 169 156 void thermal_zone_device_unregister(struct thermal_zone_device *); 170 157 171 158 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, 172 - struct thermal_cooling_device *); 159 + struct thermal_cooling_device *, 160 + unsigned long, unsigned long); 173 161 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, 174 162 struct thermal_cooling_device *); 175 163 void thermal_zone_device_update(struct thermal_zone_device *);
-1
tools/power/acpi/acpidump.c
··· 62 62 #include <unistd.h> 63 63 #include <getopt.h> 64 64 65 - #include <sys/types.h> 66 65 #include <dirent.h> 67 66 68 67 #include <acpi/acconfig.h>