6666#define WPT_TEMP_OFFSET (PCH_TEMP_OFFSET * MILLIDEGREE_PER_DEGREE)
6767#define GET_PCH_TEMP (x ) (((x) / 2) + PCH_TEMP_OFFSET)
6868
69+ #define PCH_MAX_TRIPS 3 /* critical, hot, passive */
70+
6971/* Amount of time for each cooling delay, 100ms by default for now */
7072static unsigned int delay_timeout = 100 ;
7173module_param (delay_timeout , int , 0644 );
@@ -83,12 +85,7 @@ struct pch_thermal_device {
8385 const struct pch_dev_ops * ops ;
8486 struct pci_dev * pdev ;
8587 struct thermal_zone_device * tzd ;
86- int crt_trip_id ;
87- unsigned long crt_temp ;
88- int hot_trip_id ;
89- unsigned long hot_temp ;
90- int psv_trip_id ;
91- unsigned long psv_temp ;
88+ struct thermal_trip trips [PCH_MAX_TRIPS ];
9289 bool bios_enabled ;
9390};
9491
@@ -103,33 +100,22 @@ static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
103100 int * nr_trips )
104101{
105102 struct acpi_device * adev ;
106-
107- ptd -> psv_trip_id = -1 ;
103+ int ret ;
108104
109105 adev = ACPI_COMPANION (& ptd -> pdev -> dev );
110- if (adev ) {
111- unsigned long long r ;
112- acpi_status status ;
113-
114- status = acpi_evaluate_integer (adev -> handle , "_PSV" , NULL ,
115- & r );
116- if (ACPI_SUCCESS (status )) {
117- unsigned long trip_temp ;
118-
119- trip_temp = deci_kelvin_to_millicelsius (r );
120- if (trip_temp ) {
121- ptd -> psv_temp = trip_temp ;
122- ptd -> psv_trip_id = * nr_trips ;
123- ++ (* nr_trips );
124- }
125- }
126- }
106+ if (!adev )
107+ return ;
108+
109+ ret = thermal_acpi_trip_passive (adev , & ptd -> trips [* nr_trips ]);
110+ if (ret )
111+ return ;
112+
113+ ++ (* nr_trips );
127114}
128115#else
129116static void pch_wpt_add_acpi_psv_trip (struct pch_thermal_device * ptd ,
130117 int * nr_trips )
131118{
132- ptd -> psv_trip_id = -1 ;
133119
134120}
135121#endif
@@ -164,21 +150,19 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
164150 }
165151
166152read_trips :
167- ptd -> crt_trip_id = -1 ;
168153 trip_temp = readw (ptd -> hw_base + WPT_CTT );
169154 trip_temp &= 0x1FF ;
170155 if (trip_temp ) {
171- ptd -> crt_temp = GET_WPT_TEMP (trip_temp );
172- ptd -> crt_trip_id = 0 ;
156+ ptd -> trips [ * nr_trips ]. temperature = GET_WPT_TEMP (trip_temp );
157+ ptd -> trips [ * nr_trips ]. type = THERMAL_TRIP_CRITICAL ;
173158 ++ (* nr_trips );
174159 }
175160
176- ptd -> hot_trip_id = -1 ;
177161 trip_temp = readw (ptd -> hw_base + WPT_PHL );
178162 trip_temp &= 0x1FF ;
179163 if (trip_temp ) {
180- ptd -> hot_temp = GET_WPT_TEMP (trip_temp );
181- ptd -> hot_trip_id = * nr_trips ;
164+ ptd -> trips [ * nr_trips ]. temperature = GET_WPT_TEMP (trip_temp );
165+ ptd -> trips [ * nr_trips ]. type = THERMAL_TRIP_HOT ;
182166 ++ (* nr_trips );
183167 }
184168
@@ -299,48 +283,13 @@ static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
299283 return ptd -> ops -> get_temp (ptd , temp );
300284}
301285
302- static int pch_get_trip_type (struct thermal_zone_device * tzd , int trip ,
303- enum thermal_trip_type * type )
304- {
305- struct pch_thermal_device * ptd = tzd -> devdata ;
306-
307- if (ptd -> crt_trip_id == trip )
308- * type = THERMAL_TRIP_CRITICAL ;
309- else if (ptd -> hot_trip_id == trip )
310- * type = THERMAL_TRIP_HOT ;
311- else if (ptd -> psv_trip_id == trip )
312- * type = THERMAL_TRIP_PASSIVE ;
313- else
314- return - EINVAL ;
315-
316- return 0 ;
317- }
318-
319- static int pch_get_trip_temp (struct thermal_zone_device * tzd , int trip , int * temp )
320- {
321- struct pch_thermal_device * ptd = tzd -> devdata ;
322-
323- if (ptd -> crt_trip_id == trip )
324- * temp = ptd -> crt_temp ;
325- else if (ptd -> hot_trip_id == trip )
326- * temp = ptd -> hot_temp ;
327- else if (ptd -> psv_trip_id == trip )
328- * temp = ptd -> psv_temp ;
329- else
330- return - EINVAL ;
331-
332- return 0 ;
333- }
334-
335286static void pch_critical (struct thermal_zone_device * tzd )
336287{
337288 dev_dbg (& tzd -> device , "%s: critical temperature reached\n" , tzd -> type );
338289}
339290
340291static struct thermal_zone_device_ops tzd_ops = {
341292 .get_temp = pch_thermal_get_temp ,
342- .get_trip_type = pch_get_trip_type ,
343- .get_trip_temp = pch_get_trip_temp ,
344293 .critical = pch_critical ,
345294};
346295
@@ -429,8 +378,9 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
429378 if (err )
430379 goto error_cleanup ;
431380
432- ptd -> tzd = thermal_zone_device_register (bi -> name , nr_trips , 0 , ptd ,
433- & tzd_ops , NULL , 0 , 0 );
381+ ptd -> tzd = thermal_zone_device_register_with_trips (bi -> name , ptd -> trips ,
382+ nr_trips , 0 , ptd ,
383+ & tzd_ops , NULL , 0 , 0 );
434384 if (IS_ERR (ptd -> tzd )) {
435385 dev_err (& pdev -> dev , "Failed to register thermal zone %s\n" ,
436386 bi -> name );
0 commit comments