Skip to content

Commit a1ebf2c

Browse files
dlezcanoDaniel Lezcano
authored andcommitted
thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function
The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Hans de Goede <[email protected]> Acked-by: Peter Kästle <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 69cf4ea commit a1ebf2c

File tree

1 file changed

+26
-47
lines changed

1 file changed

+26
-47
lines changed

drivers/platform/x86/acerhdf.c

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
* measured by the on-die thermal monitor are within 0 <= Tj <= 90. So,
4747
* assume 89°C is critical temperature.
4848
*/
49+
#define ACERHDF_DEFAULT_TEMP_FANON 60000
50+
#define ACERHDF_DEFAULT_TEMP_FANOFF 53000
4951
#define ACERHDF_TEMP_CRIT 89000
5052
#define ACERHDF_FAN_OFF 0
5153
#define ACERHDF_FAN_AUTO 1
@@ -70,8 +72,8 @@ static int kernelmode;
7072
#endif
7173

7274
static unsigned int interval = 10;
73-
static unsigned int fanon = 60000;
74-
static unsigned int fanoff = 53000;
75+
static unsigned int fanon = ACERHDF_DEFAULT_TEMP_FANON;
76+
static unsigned int fanoff = ACERHDF_DEFAULT_TEMP_FANOFF;
7577
static unsigned int verbose;
7678
static unsigned int list_supported;
7779
static unsigned int fanstate = ACERHDF_FAN_AUTO;
@@ -137,6 +139,15 @@ struct ctrl_settings {
137139
int mcmd_enable;
138140
};
139141

142+
static struct thermal_trip trips[] = {
143+
[0] = { .temperature = ACERHDF_DEFAULT_TEMP_FANON,
144+
.hysteresis = ACERHDF_DEFAULT_TEMP_FANON - ACERHDF_DEFAULT_TEMP_FANOFF,
145+
.type = THERMAL_TRIP_ACTIVE },
146+
147+
[1] = { .temperature = ACERHDF_TEMP_CRIT,
148+
.type = THERMAL_TRIP_CRITICAL }
149+
};
150+
140151
static struct ctrl_settings ctrl_cfg __read_mostly;
141152

142153
/* Register addresses and values for different BIOS versions */
@@ -326,6 +337,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
326337
fanon = ACERHDF_MAX_FANON;
327338
}
328339

340+
if (fanon < fanoff) {
341+
pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n",
342+
fanoff, fanon, fanon);
343+
fanoff = fanon;
344+
};
345+
346+
trips[0].temperature = fanon;
347+
trips[0].hysteresis = fanon - fanoff;
348+
329349
if (kernelmode && prev_interval != interval) {
330350
if (interval > ACERHDF_MAX_INTERVAL) {
331351
pr_err("interval too high, set to %d\n",
@@ -424,43 +444,6 @@ static int acerhdf_change_mode(struct thermal_zone_device *thermal,
424444
return 0;
425445
}
426446

427-
static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip,
428-
enum thermal_trip_type *type)
429-
{
430-
if (trip == 0)
431-
*type = THERMAL_TRIP_ACTIVE;
432-
else if (trip == 1)
433-
*type = THERMAL_TRIP_CRITICAL;
434-
else
435-
return -EINVAL;
436-
437-
return 0;
438-
}
439-
440-
static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
441-
int *temp)
442-
{
443-
if (trip != 0)
444-
return -EINVAL;
445-
446-
*temp = fanon - fanoff;
447-
448-
return 0;
449-
}
450-
451-
static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
452-
int *temp)
453-
{
454-
if (trip == 0)
455-
*temp = fanon;
456-
else if (trip == 1)
457-
*temp = ACERHDF_TEMP_CRIT;
458-
else
459-
return -EINVAL;
460-
461-
return 0;
462-
}
463-
464447
static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal,
465448
int *temperature)
466449
{
@@ -474,13 +457,9 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = {
474457
.unbind = acerhdf_unbind,
475458
.get_temp = acerhdf_get_ec_temp,
476459
.change_mode = acerhdf_change_mode,
477-
.get_trip_type = acerhdf_get_trip_type,
478-
.get_trip_hyst = acerhdf_get_trip_hyst,
479-
.get_trip_temp = acerhdf_get_trip_temp,
480460
.get_crit_temp = acerhdf_get_crit_temp,
481461
};
482462

483-
484463
/*
485464
* cooling device callback functions
486465
* get maximal fan cooling state
@@ -710,10 +689,10 @@ static int __init acerhdf_register_thermal(void)
710689
if (IS_ERR(cl_dev))
711690
return -EINVAL;
712691

713-
thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL,
714-
&acerhdf_dev_ops,
715-
&acerhdf_zone_params, 0,
716-
(kernelmode) ? interval*1000 : 0);
692+
thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips),
693+
0, NULL, &acerhdf_dev_ops,
694+
&acerhdf_zone_params, 0,
695+
(kernelmode) ? interval*1000 : 0);
717696
if (IS_ERR(thz_dev))
718697
return -EINVAL;
719698

0 commit comments

Comments
 (0)