diff options
-rw-r--r-- | drivers/thermal/int340x_thermal/Makefile | 1 | ||||
-rw-r--r-- | drivers/thermal/int340x_thermal/int340x_thermal_zone.c | 262 | ||||
-rw-r--r-- | drivers/thermal/int340x_thermal/int340x_thermal_zone.h | 65 |
3 files changed, 328 insertions, 0 deletions
diff --git a/drivers/thermal/int340x_thermal/Makefile b/drivers/thermal/int340x_thermal/Makefile index d4413698a85f..ba77a34f659f 100644 --- a/drivers/thermal/int340x_thermal/Makefile +++ b/drivers/thermal/int340x_thermal/Makefile | |||
@@ -1,4 +1,5 @@ | |||
1 | obj-$(CONFIG_INT340X_THERMAL) += int3400_thermal.o | 1 | obj-$(CONFIG_INT340X_THERMAL) += int3400_thermal.o |
2 | obj-$(CONFIG_INT340X_THERMAL) += int340x_thermal_zone.o | ||
2 | obj-$(CONFIG_INT340X_THERMAL) += int3402_thermal.o | 3 | obj-$(CONFIG_INT340X_THERMAL) += int3402_thermal.o |
3 | obj-$(CONFIG_INT340X_THERMAL) += int3403_thermal.o | 4 | obj-$(CONFIG_INT340X_THERMAL) += int3403_thermal.o |
4 | obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_device.o | 5 | obj-$(CONFIG_INT340X_THERMAL) += processor_thermal_device.o |
diff --git a/drivers/thermal/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/int340x_thermal/int340x_thermal_zone.c new file mode 100644 index 000000000000..162e545cc93a --- /dev/null +++ b/drivers/thermal/int340x_thermal/int340x_thermal_zone.c | |||
@@ -0,0 +1,262 @@ | |||
1 | /* | ||
2 | * int340x_thermal_zone.c | ||
3 | * Copyright (c) 2015, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/acpi.h> | ||
19 | #include <linux/thermal.h> | ||
20 | #include "int340x_thermal_zone.h" | ||
21 | |||
22 | static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone, | ||
23 | unsigned long *temp) | ||
24 | { | ||
25 | struct int34x_thermal_zone *d = zone->devdata; | ||
26 | unsigned long long tmp; | ||
27 | acpi_status status; | ||
28 | |||
29 | if (d->override_ops && d->override_ops->get_temp) | ||
30 | return d->override_ops->get_temp(zone, temp); | ||
31 | |||
32 | status = acpi_evaluate_integer(d->adev->handle, "_TMP", NULL, &tmp); | ||
33 | if (ACPI_FAILURE(status)) | ||
34 | return -EIO; | ||
35 | |||
36 | /* _TMP returns the temperature in tenths of degrees Kelvin */ | ||
37 | *temp = DECI_KELVIN_TO_MILLICELSIUS(tmp); | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone, | ||
43 | int trip, unsigned long *temp) | ||
44 | { | ||
45 | struct int34x_thermal_zone *d = zone->devdata; | ||
46 | int i; | ||
47 | |||
48 | if (d->override_ops && d->override_ops->get_trip_temp) | ||
49 | return d->override_ops->get_trip_temp(zone, trip, temp); | ||
50 | |||
51 | if (trip < d->aux_trip_nr) | ||
52 | *temp = d->aux_trips[trip]; | ||
53 | else if (trip == d->crt_trip_id) | ||
54 | *temp = d->crt_temp; | ||
55 | else if (trip == d->psv_trip_id) | ||
56 | *temp = d->psv_temp; | ||
57 | else if (trip == d->hot_trip_id) | ||
58 | *temp = d->hot_temp; | ||
59 | else { | ||
60 | for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { | ||
61 | if (d->act_trips[i].valid && | ||
62 | d->act_trips[i].id == trip) { | ||
63 | *temp = d->act_trips[i].temp; | ||
64 | break; | ||
65 | } | ||
66 | } | ||
67 | if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT) | ||
68 | return -EINVAL; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone, | ||
75 | int trip, | ||
76 | enum thermal_trip_type *type) | ||
77 | { | ||
78 | struct int34x_thermal_zone *d = zone->devdata; | ||
79 | int i; | ||
80 | |||
81 | if (d->override_ops && d->override_ops->get_trip_type) | ||
82 | return d->override_ops->get_trip_type(zone, trip, type); | ||
83 | |||
84 | if (trip < d->aux_trip_nr) | ||
85 | *type = THERMAL_TRIP_PASSIVE; | ||
86 | else if (trip == d->crt_trip_id) | ||
87 | *type = THERMAL_TRIP_CRITICAL; | ||
88 | else if (trip == d->hot_trip_id) | ||
89 | *type = THERMAL_TRIP_HOT; | ||
90 | else if (trip == d->psv_trip_id) | ||
91 | *type = THERMAL_TRIP_PASSIVE; | ||
92 | else { | ||
93 | for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { | ||
94 | if (d->act_trips[i].valid && | ||
95 | d->act_trips[i].id == trip) { | ||
96 | *type = THERMAL_TRIP_ACTIVE; | ||
97 | break; | ||
98 | } | ||
99 | } | ||
100 | if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT) | ||
101 | return -EINVAL; | ||
102 | } | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone, | ||
108 | int trip, unsigned long temp) | ||
109 | { | ||
110 | struct int34x_thermal_zone *d = zone->devdata; | ||
111 | acpi_status status; | ||
112 | char name[10]; | ||
113 | |||
114 | if (d->override_ops && d->override_ops->set_trip_temp) | ||
115 | return d->override_ops->set_trip_temp(zone, trip, temp); | ||
116 | |||
117 | snprintf(name, sizeof(name), "PAT%d", trip); | ||
118 | status = acpi_execute_simple_method(d->adev->handle, name, | ||
119 | MILLICELSIUS_TO_DECI_KELVIN(temp)); | ||
120 | if (ACPI_FAILURE(status)) | ||
121 | return -EIO; | ||
122 | |||
123 | d->aux_trips[trip] = temp; | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | |||
129 | static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone, | ||
130 | int trip, unsigned long *temp) | ||
131 | { | ||
132 | struct int34x_thermal_zone *d = zone->devdata; | ||
133 | acpi_status status; | ||
134 | unsigned long long hyst; | ||
135 | |||
136 | if (d->override_ops && d->override_ops->get_trip_hyst) | ||
137 | return d->override_ops->get_trip_hyst(zone, trip, temp); | ||
138 | |||
139 | status = acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst); | ||
140 | if (ACPI_FAILURE(status)) | ||
141 | return -EIO; | ||
142 | |||
143 | *temp = hyst * 100; | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static struct thermal_zone_device_ops int340x_thermal_zone_ops = { | ||
149 | .get_temp = int340x_thermal_get_zone_temp, | ||
150 | .get_trip_temp = int340x_thermal_get_trip_temp, | ||
151 | .get_trip_type = int340x_thermal_get_trip_type, | ||
152 | .set_trip_temp = int340x_thermal_set_trip_temp, | ||
153 | .get_trip_hyst = int340x_thermal_get_trip_hyst, | ||
154 | }; | ||
155 | |||
156 | static int int340x_thermal_get_trip_config(acpi_handle handle, char *name, | ||
157 | unsigned long *temp) | ||
158 | { | ||
159 | unsigned long long r; | ||
160 | acpi_status status; | ||
161 | |||
162 | status = acpi_evaluate_integer(handle, name, NULL, &r); | ||
163 | if (ACPI_FAILURE(status)) | ||
164 | return -EIO; | ||
165 | |||
166 | *temp = DECI_KELVIN_TO_MILLICELSIUS(r); | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static struct thermal_zone_params int340x_thermal_params = { | ||
172 | .governor_name = "user_space", | ||
173 | .no_hwmon = true, | ||
174 | }; | ||
175 | |||
176 | struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, | ||
177 | struct thermal_zone_device_ops *override_ops) | ||
178 | { | ||
179 | struct int34x_thermal_zone *int34x_thermal_zone; | ||
180 | acpi_status status; | ||
181 | unsigned long long trip_cnt; | ||
182 | int trip_mask = 0, i; | ||
183 | int ret; | ||
184 | |||
185 | int34x_thermal_zone = kzalloc(sizeof(*int34x_thermal_zone), | ||
186 | GFP_KERNEL); | ||
187 | if (!int34x_thermal_zone) | ||
188 | return ERR_PTR(-ENOMEM); | ||
189 | |||
190 | int34x_thermal_zone->adev = adev; | ||
191 | int34x_thermal_zone->override_ops = override_ops; | ||
192 | |||
193 | status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt); | ||
194 | if (ACPI_FAILURE(status)) | ||
195 | trip_cnt = 0; | ||
196 | else { | ||
197 | int34x_thermal_zone->aux_trips = kzalloc( | ||
198 | sizeof(*int34x_thermal_zone->aux_trips) * | ||
199 | trip_cnt, GFP_KERNEL); | ||
200 | if (!int34x_thermal_zone->aux_trips) { | ||
201 | ret = -ENOMEM; | ||
202 | goto free_mem; | ||
203 | } | ||
204 | trip_mask = BIT(trip_cnt) - 1; | ||
205 | int34x_thermal_zone->aux_trip_nr = trip_cnt; | ||
206 | } | ||
207 | |||
208 | int34x_thermal_zone->crt_trip_id = -1; | ||
209 | if (!int340x_thermal_get_trip_config(adev->handle, "_CRT", | ||
210 | &int34x_thermal_zone->crt_temp)) | ||
211 | int34x_thermal_zone->crt_trip_id = trip_cnt++; | ||
212 | int34x_thermal_zone->hot_trip_id = -1; | ||
213 | if (!int340x_thermal_get_trip_config(adev->handle, "_HOT", | ||
214 | &int34x_thermal_zone->hot_temp)) | ||
215 | int34x_thermal_zone->hot_trip_id = trip_cnt++; | ||
216 | int34x_thermal_zone->psv_trip_id = -1; | ||
217 | if (!int340x_thermal_get_trip_config(adev->handle, "_PSV", | ||
218 | &int34x_thermal_zone->psv_temp)) | ||
219 | int34x_thermal_zone->psv_trip_id = trip_cnt++; | ||
220 | for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { | ||
221 | char name[5] = { '_', 'A', 'C', '0' + i, '\0' }; | ||
222 | |||
223 | if (int340x_thermal_get_trip_config(adev->handle, name, | ||
224 | &int34x_thermal_zone->act_trips[i].temp)) | ||
225 | break; | ||
226 | |||
227 | int34x_thermal_zone->act_trips[i].id = trip_cnt++; | ||
228 | int34x_thermal_zone->act_trips[i].valid = true; | ||
229 | } | ||
230 | |||
231 | int34x_thermal_zone->zone = thermal_zone_device_register( | ||
232 | acpi_device_bid(adev), | ||
233 | trip_cnt, | ||
234 | trip_mask, int34x_thermal_zone, | ||
235 | &int340x_thermal_zone_ops, | ||
236 | &int340x_thermal_params, | ||
237 | 0, 0); | ||
238 | if (IS_ERR(int34x_thermal_zone->zone)) { | ||
239 | ret = PTR_ERR(int34x_thermal_zone->zone); | ||
240 | goto free_mem; | ||
241 | } | ||
242 | |||
243 | return int34x_thermal_zone; | ||
244 | |||
245 | free_mem: | ||
246 | kfree(int34x_thermal_zone); | ||
247 | return ERR_PTR(ret); | ||
248 | } | ||
249 | EXPORT_SYMBOL_GPL(int340x_thermal_zone_add); | ||
250 | |||
251 | void int340x_thermal_zone_remove(struct int34x_thermal_zone | ||
252 | *int34x_thermal_zone) | ||
253 | { | ||
254 | thermal_zone_device_unregister(int34x_thermal_zone->zone); | ||
255 | kfree(int34x_thermal_zone); | ||
256 | } | ||
257 | EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove); | ||
258 | |||
259 | MODULE_AUTHOR("Aaron Lu <aaron.lu@intel.com>"); | ||
260 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); | ||
261 | MODULE_DESCRIPTION("Intel INT340x common thermal zone handler"); | ||
262 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/thermal/int340x_thermal/int340x_thermal_zone.h b/drivers/thermal/int340x_thermal/int340x_thermal_zone.h new file mode 100644 index 000000000000..11f2f5260c3a --- /dev/null +++ b/drivers/thermal/int340x_thermal/int340x_thermal_zone.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * int340x_thermal_zone.h | ||
3 | * Copyright (c) 2015, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #ifndef __INT340X_THERMAL_ZONE_H__ | ||
17 | #define __INT340X_THERMAL_ZONE_H__ | ||
18 | |||
19 | #define INT340X_THERMAL_MAX_ACT_TRIP_COUNT 10 | ||
20 | |||
21 | struct active_trip { | ||
22 | unsigned long temp; | ||
23 | int id; | ||
24 | bool valid; | ||
25 | }; | ||
26 | |||
27 | struct int34x_thermal_zone { | ||
28 | struct acpi_device *adev; | ||
29 | struct active_trip act_trips[INT340X_THERMAL_MAX_ACT_TRIP_COUNT]; | ||
30 | unsigned long *aux_trips; | ||
31 | int aux_trip_nr; | ||
32 | unsigned long psv_temp; | ||
33 | int psv_trip_id; | ||
34 | unsigned long crt_temp; | ||
35 | int crt_trip_id; | ||
36 | unsigned long hot_temp; | ||
37 | int hot_trip_id; | ||
38 | struct thermal_zone_device *zone; | ||
39 | struct thermal_zone_device_ops *override_ops; | ||
40 | void *priv_data; | ||
41 | }; | ||
42 | |||
43 | struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *, | ||
44 | struct thermal_zone_device_ops *override_ops); | ||
45 | void int340x_thermal_zone_remove(struct int34x_thermal_zone *); | ||
46 | |||
47 | static inline void int340x_thermal_zone_set_priv_data( | ||
48 | struct int34x_thermal_zone *tzone, void *priv_data) | ||
49 | { | ||
50 | tzone->priv_data = priv_data; | ||
51 | } | ||
52 | |||
53 | static inline void *int340x_thermal_zone_get_priv_data( | ||
54 | struct int34x_thermal_zone *tzone) | ||
55 | { | ||
56 | return tzone->priv_data; | ||
57 | } | ||
58 | |||
59 | static inline void int340x_thermal_zone_device_update( | ||
60 | struct int34x_thermal_zone *tzone) | ||
61 | { | ||
62 | thermal_zone_device_update(tzone->zone); | ||
63 | } | ||
64 | |||
65 | #endif | ||