Message ID | 20220805145729.2491611-24-daniel.lezcano@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | Rework the trip points creation | expand |
Hi, On 8/5/22 16:57, Daniel Lezcano wrote: > 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 <daniel.lezcano@linaro.org> Thanks, patch looks good to me, feel free to merge this through the thermal tree together with the rest of the series: Acked-by: Hans de Goede <hdegoede@redhat.com> Regards, Hans > --- > drivers/platform/x86/acerhdf.c | 73 ++++++++++++---------------------- > 1 file changed, 26 insertions(+), 47 deletions(-) > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 3463629f8764..cf757f3a1e6b 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -46,6 +46,8 @@ > * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So, > * assume 89°C is critical temperature. > */ > +#define ACERHDF_DEFAULT_TEMP_FANON 60000 > +#define ACERHDF_DEFAULT_TEMP_FANOFF 53000 > #define ACERHDF_TEMP_CRIT 89000 > #define ACERHDF_FAN_OFF 0 > #define ACERHDF_FAN_AUTO 1 > @@ -70,8 +72,8 @@ static int kernelmode; > #endif > > static unsigned int interval = 10; > -static unsigned int fanon = 60000; > -static unsigned int fanoff = 53000; > +static unsigned int fanon = ACERHDF_DEFAULT_TEMP_FANON; > +static unsigned int fanoff = ACERHDF_DEFAULT_TEMP_FANOFF; > static unsigned int verbose; > static unsigned int list_supported; > static unsigned int fanstate = ACERHDF_FAN_AUTO; > @@ -137,6 +139,15 @@ struct ctrl_settings { > int mcmd_enable; > }; > > +static struct thermal_trip trips[] = { > + [0] = { .temperature = ACERHDF_DEFAULT_TEMP_FANON, > + .hysteresis = ACERHDF_DEFAULT_TEMP_FANON - ACERHDF_DEFAULT_TEMP_FANOFF, > + .type = THERMAL_TRIP_ACTIVE }, > + > + [1] = { .temperature = ACERHDF_TEMP_CRIT, > + .type = THERMAL_TRIP_CRITICAL } > +}; > + > static struct ctrl_settings ctrl_cfg __read_mostly; > > /* Register addresses and values for different BIOS versions */ > @@ -326,6 +337,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal) > fanon = ACERHDF_MAX_FANON; > } > > + if (fanon < fanoff) { > + pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n", > + fanoff, fanon, fanon); > + fanoff = fanon; > + }; > + > + trips[0].temperature = fanon; > + trips[0].hysteresis = fanon - fanoff; > + > if (kernelmode && prev_interval != interval) { > if (interval > ACERHDF_MAX_INTERVAL) { > pr_err("interval too high, set to %d\n", > @@ -424,43 +444,6 @@ static int acerhdf_change_mode(struct thermal_zone_device *thermal, > return 0; > } > > -static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip, > - enum thermal_trip_type *type) > -{ > - if (trip == 0) > - *type = THERMAL_TRIP_ACTIVE; > - else if (trip == 1) > - *type = THERMAL_TRIP_CRITICAL; > - else > - return -EINVAL; > - > - return 0; > -} > - > -static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip, > - int *temp) > -{ > - if (trip != 0) > - return -EINVAL; > - > - *temp = fanon - fanoff; > - > - return 0; > -} > - > -static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip, > - int *temp) > -{ > - if (trip == 0) > - *temp = fanon; > - else if (trip == 1) > - *temp = ACERHDF_TEMP_CRIT; > - else > - return -EINVAL; > - > - return 0; > -} > - > static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal, > int *temperature) > { > @@ -474,13 +457,9 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > .change_mode = acerhdf_change_mode, > - .get_trip_type = acerhdf_get_trip_type, > - .get_trip_hyst = acerhdf_get_trip_hyst, > - .get_trip_temp = acerhdf_get_trip_temp, > .get_crit_temp = acerhdf_get_crit_temp, > }; > > - > /* > * cooling device callback functions > * get maximal fan cooling state > @@ -710,10 +689,10 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > - thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > - &acerhdf_dev_ops, > - &acerhdf_zone_params, 0, > - (kernelmode) ? interval*1000 : 0); > + thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips), > + 0, NULL, &acerhdf_dev_ops, > + &acerhdf_zone_params, 0, > + (kernelmode) ? interval*1000 : 0); > if (IS_ERR(thz_dev)) > return -EINVAL; >
Hello, some comments. Please merge if those are considered. Thanks. On 05.08.22 16:57, Daniel Lezcano wrote: > 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 <daniel.lezcano@linaro.org> Acked-by: Peter Kästle <peter@piie.net> > --- > drivers/platform/x86/acerhdf.c | 73 ++++++++++++---------------------- > 1 file changed, 26 insertions(+), 47 deletions(-) > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 3463629f8764..cf757f3a1e6b 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c [...] > @@ -137,6 +139,15 @@ struct ctrl_settings { > int mcmd_enable; > }; > > +static struct thermal_trip trips[] = { > + [0] = { .temperature = ACERHDF_DEFAULT_TEMP_FANON, > + .hysteresis = ACERHDF_DEFAULT_TEMP_FANON - ACERHDF_DEFAULT_TEMP_FANOFF, > + .type = THERMAL_TRIP_ACTIVE }, > + > + [1] = { .temperature = ACERHDF_TEMP_CRIT, > + .type = THERMAL_TRIP_CRITICAL } > +}; > + > static struct ctrl_settings ctrl_cfg __read_mostly; > > /* Register addresses and values for different BIOS versions */ > @@ -326,6 +337,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal) > fanon = ACERHDF_MAX_FANON; > } > > + if (fanon < fanoff) { > + pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n", > + fanoff, fanon, fanon); > + fanoff = fanon; > + }; > + Tab whitespace, please remove. > + trips[0].temperature = fanon; > + trips[0].hysteresis = fanon - fanoff; > + Tab whitespace, please remove > if (kernelmode && prev_interval != interval) { > if (interval > ACERHDF_MAX_INTERVAL) { > pr_err("interval too high, set to %d\n", I don't know the current behavior of the thermal layer well enough. Is it ensured, that those new trips[0].temperature / trips[0].hysteresis values are taken into account?
On 08/08/2022 21:34, Peter Kästle wrote: > Hello, > > some comments. Please merge if those are considered. Thanks. > > > On 05.08.22 16:57, Daniel Lezcano wrote: >> 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 <daniel.lezcano@linaro.org> > > Acked-by: Peter Kästle <peter@piie.net> Thanks for reviewing the patch [ ... ] >> if (kernelmode && prev_interval != interval) { >> if (interval > ACERHDF_MAX_INTERVAL) { >> pr_err("interval too high, set to %d\n", > > I don't know the current behavior of the thermal layer well enough. > Is it ensured, that those new trips[0].temperature / trips[0].hysteresis > values are taken into account? I don't have this platform so it is hard to test. All the device tree based sensors are using now those generic trip points and that works.
diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 3463629f8764..cf757f3a1e6b 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -46,6 +46,8 @@ * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So, * assume 89°C is critical temperature. */ +#define ACERHDF_DEFAULT_TEMP_FANON 60000 +#define ACERHDF_DEFAULT_TEMP_FANOFF 53000 #define ACERHDF_TEMP_CRIT 89000 #define ACERHDF_FAN_OFF 0 #define ACERHDF_FAN_AUTO 1 @@ -70,8 +72,8 @@ static int kernelmode; #endif static unsigned int interval = 10; -static unsigned int fanon = 60000; -static unsigned int fanoff = 53000; +static unsigned int fanon = ACERHDF_DEFAULT_TEMP_FANON; +static unsigned int fanoff = ACERHDF_DEFAULT_TEMP_FANOFF; static unsigned int verbose; static unsigned int list_supported; static unsigned int fanstate = ACERHDF_FAN_AUTO; @@ -137,6 +139,15 @@ struct ctrl_settings { int mcmd_enable; }; +static struct thermal_trip trips[] = { + [0] = { .temperature = ACERHDF_DEFAULT_TEMP_FANON, + .hysteresis = ACERHDF_DEFAULT_TEMP_FANON - ACERHDF_DEFAULT_TEMP_FANOFF, + .type = THERMAL_TRIP_ACTIVE }, + + [1] = { .temperature = ACERHDF_TEMP_CRIT, + .type = THERMAL_TRIP_CRITICAL } +}; + static struct ctrl_settings ctrl_cfg __read_mostly; /* Register addresses and values for different BIOS versions */ @@ -326,6 +337,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal) fanon = ACERHDF_MAX_FANON; } + if (fanon < fanoff) { + pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n", + fanoff, fanon, fanon); + fanoff = fanon; + }; + + trips[0].temperature = fanon; + trips[0].hysteresis = fanon - fanoff; + if (kernelmode && prev_interval != interval) { if (interval > ACERHDF_MAX_INTERVAL) { pr_err("interval too high, set to %d\n", @@ -424,43 +444,6 @@ static int acerhdf_change_mode(struct thermal_zone_device *thermal, return 0; } -static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - if (trip == 0) - *type = THERMAL_TRIP_ACTIVE; - else if (trip == 1) - *type = THERMAL_TRIP_CRITICAL; - else - return -EINVAL; - - return 0; -} - -static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - if (trip != 0) - return -EINVAL; - - *temp = fanon - fanoff; - - return 0; -} - -static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - if (trip == 0) - *temp = fanon; - else if (trip == 1) - *temp = ACERHDF_TEMP_CRIT; - else - return -EINVAL; - - return 0; -} - static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal, int *temperature) { @@ -474,13 +457,9 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, .change_mode = acerhdf_change_mode, - .get_trip_type = acerhdf_get_trip_type, - .get_trip_hyst = acerhdf_get_trip_hyst, - .get_trip_temp = acerhdf_get_trip_temp, .get_crit_temp = acerhdf_get_crit_temp, }; - /* * cooling device callback functions * get maximal fan cooling state @@ -710,10 +689,10 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, - &acerhdf_dev_ops, - &acerhdf_zone_params, 0, - (kernelmode) ? interval*1000 : 0); + thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips), + 0, NULL, &acerhdf_dev_ops, + &acerhdf_zone_params, 0, + (kernelmode) ? interval*1000 : 0); if (IS_ERR(thz_dev)) return -EINVAL;
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 <daniel.lezcano@linaro.org> --- drivers/platform/x86/acerhdf.c | 73 ++++++++++++---------------------- 1 file changed, 26 insertions(+), 47 deletions(-)