Rework the trip points creation
Subsystems (20)
v8 cover Rework the trip points creation
This work is the pre-requisite of handling correctly when the trip point are crossed. For that we need to rework how the trip points are declared and assigned to a thermal zone.
Even if it appears to be a common sense to have the trip points being ordered, this no guarantee neither documentation telling that is the case.
One solution could have been to create an ordered array of trips built when registering the thermal zone by calling the different get_trip* ops. However those ops receive a thermal zone pointer which is not known as it is in the process of creating it.
This cyclic dependency shows we have to rework how we manage the trip points.
Actually, all the trip points definition can be common to the backend sensor drivers and we can factor out the thermal trip structure in all of them.
Then, as we register the thermal trips array, they will be available in the thermal zone structure and a core function can return the trip given its id.
The get_trip_* ops won't be needed anymore and could be removed. The resulting code will be another step forward to a self encapsulated generic thermal framework.
Most of the drivers can be converted more or less easily. This series does a first round with most of the drivers. Some remain and will be converted but with a smaller set of changes as the conversion is a bit more complex.
Changelog:
v8:
- Pretty oneline change and parenthesis removal (Rafael)
- Collected tags
v7:
- Added missing return 0 in the x86_pkg_temp driver
v6:
- Improved the code for the get_crit_temp() function as suggested by Rafael
- Removed inner parenthesis in the set_trip_temp() function and invert the conditions. Check the type of the trip point is unchanged
- Folded patch 4 with 1
- Add per thermal zone info message in the bang-bang governor
- Folded the fix for an uninitialized variable in int340x_thermal_zone_add()
v5:
- Fixed a deadlock when calling thermal_zone_get_trip() while handling the thermal zone lock
- Remove an extra line in the sysfs change
- Collected tags
v4:
- Remove extra lines on exynos changes as reported by Krzysztof Kozlowski
- Collected tags
v3:
- Reorg the series to be git-bisect safe
- Added the set_trip generic function
- Added the get_crit_temp generic function
- Removed more dead code in the thermal-of
- Fixed the exynos changelog
- Fixed the error check for the exynos drivers
- Collected tags
v2:
- Added missing EXPORT_SYMBOL_GPL() for thermal_zone_get_trip()
- Removed tab whitespace in the acerhdf driver
- Collected tags
Daniel Lezcano (29):
thermal/core: Add a generic thermal_zone_get_trip() function thermal/sysfs: Always expose hysteresis attributes thermal/core: Add a generic thermal_zone_set_trip() function thermal/core/governors: Use thermal_zone_get_trip() instead of ops
functions
thermal/of: Use generic thermal_zone_get_trip() function thermal/of: Remove unused functions thermal/drivers/exynos: Use generic thermal_zone_get_trip() function thermal/drivers/exynos: of_thermal_get_ntrips() thermal/drivers/exynos: Replace of_thermal_is_trip_valid() by
thermal_zone_get_trip()
thermal/drivers/tegra: Use generic thermal_zone_get_trip() function thermal/drivers/uniphier: Use generic thermal_zone_get_trip() function thermal/drivers/hisi: Use generic thermal_zone_get_trip() function thermal/drivers/qcom: Use generic thermal_zone_get_trip() function thermal/drivers/armada: Use generic thermal_zone_get_trip() function thermal/drivers/rcar_gen3: Use the generic function to get the number
of trips
thermal/of: Remove of_thermal_get_ntrips()
thermal/of: Remove of_thermal_is_trip_valid()
thermal/of: Remove of_thermal_set_trip_hyst()
thermal/of: Remove of_thermal_get_crit_temp() thermal/drivers/st: Use generic trip points thermal/drivers/imx: Use generic thermal_zone_get_trip() function thermal/drivers/rcar: Use generic thermal_zone_get_trip() function thermal/drivers/broadcom: Use generic thermal_zone_get_trip() function thermal/drivers/da9062: Use generic thermal_zone_get_trip() function thermal/drivers/ti: Remove unused macros ti_thermal_get_trip_value() /
ti_thermal_trip_is_valid()
thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function thermal/drivers/cxgb4: Use generic thermal_zone_get_trip() function thermal/intel/int340x: Replace parameter to simplify thermal/drivers/intel: Use generic thermal_zone_get_trip() function
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 2 - .../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 41 +---- drivers/platform/x86/acerhdf.c | 73 +++----- drivers/thermal/armada_thermal.c | 39 ++--- drivers/thermal/broadcom/bcm2835_thermal.c | 8 +- drivers/thermal/da9062-thermal.c | 52 +----- drivers/thermal/gov_bang_bang.c | 39 +++-- drivers/thermal/gov_fair_share.c | 18 +- drivers/thermal/gov_power_allocator.c | 51 +++--- drivers/thermal/gov_step_wise.c | 22 ++- drivers/thermal/hisi_thermal.c | 11 +- drivers/thermal/imx_thermal.c | 72 +++----- .../int340x_thermal/int340x_thermal_zone.c | 33 ++-- .../int340x_thermal/int340x_thermal_zone.h | 4 +- .../processor_thermal_device.c | 10 +- drivers/thermal/intel/x86_pkg_temp_thermal.c | 120 +++++++------ drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 39 ++--- drivers/thermal/rcar_gen3_thermal.c | 2 +- drivers/thermal/rcar_thermal.c | 53 +----- drivers/thermal/samsung/exynos_tmu.c | 57 +++---- drivers/thermal/st/st_thermal.c | 47 +---- drivers/thermal/tegra/soctherm.c | 33 ++-- drivers/thermal/tegra/tegra30-tsensor.c | 17 +- drivers/thermal/thermal_core.c | 160 +++++++++++++++--- drivers/thermal/thermal_core.h | 24 +-- drivers/thermal/thermal_helpers.c | 28 +-- drivers/thermal/thermal_netlink.c | 21 +-- drivers/thermal/thermal_of.c | 116 ------------- drivers/thermal/thermal_sysfs.c | 133 +++++---------- drivers/thermal/ti-soc-thermal/ti-thermal.h | 15 -- drivers/thermal/uniphier_thermal.c | 27 ++- include/linux/thermal.h | 10 ++ 32 files changed, 559 insertions(+), 818 deletions(-)
Signature · 1 line
2.34.1
PATCH v8 1/29 thermal/core: Add a generic thermal_zone_get_trip() function
The thermal_zone_device_ops structure defines a set of ops family, get_trip_temp(), get_trip_hyst(), get_trip_type(). Each of them is returning a property of a trip point.
The result is the code is calling the ops everywhere to get a trip point which is supposed to be defined in the backend driver. It is a non-sense as a thermal trip can be generic and used by the backend driver to declare its trip points.
Part of the thermal framework has been changed and all the OF thermal drivers are using the same definition for the trip point and use a thermal zone registration variant to pass those trip points which are part of the thermal zone device structure.
Consequently, we can use a generic function to get the trip points when they are stored in the thermal zone device structure.
This approach can be generalized to all the drivers and we can get rid of the ops->get_trip_*. That will result to a much more simpler code and make possible to rework how the thermal trip are handled in the thermal core framework as discussed previously.
This change adds a function thermal_zone_get_trip() where we get the thermal trip point structure which contains all the properties (type, temp, hyst) instead of doing multiple calls to ops->get_trip_*.
That opens the door for trip point extension with more attributes. For instance, replacing the trip points disabled bitmask with a 'disabled' field in the structure.
Here we replace all the calls to ops->get_trip_* in the thermal core code with a call to the thermal_zone_get_trip() function.
The thermal zone ops defines a callback to retrieve the critical temperature. As the trip handling is being reworked, all the trip points will be the same whatever the driver and consequently finding the critical trip temperature will be just a loop to search for a critical trip point type.
Provide such a generic function, so we encapsulate the ops get_crit_temp() which can be removed when all the backend drivers are using the generic trip points handling.
While at it, add the thermal_zone_get_num_trips() to encapsulate the code more and reduce the grip with the thermal framework internals.
--- drivers/thermal/thermal_core.c | 114 ++++++++++++++++++++++++------ drivers/thermal/thermal_core.h | 2 + drivers/thermal/thermal_helpers.c | 28 ++++---- drivers/thermal/thermal_netlink.c | 21 +++--- drivers/thermal/thermal_sysfs.c | 66 +++++++---------- include/linux/thermal.h | 7 ++ 6 files changed, 149 insertions(+), 89 deletions(-)
drivers/thermal/thermal_core.c +91 -23
@@ -341,35 +341,31 @@ static void handle_critical_trips(struct thermal_zone_device *tz, tz->ops->critical (tz); } -static void handle_thermal_trip (struct thermal_zone_device *tz,int trip) +static void handle_thermal_trip (struct thermal_zone_device *tz,int trip_id) { -enum thermal_trip_type type; -int trip_temp, hyst =0 ; +struct thermal_trip trip;/* Ignore disabled trip points */ -if (test_bit (trip, &tz->trips_disabled)) +if (test_bit (trip_id, &tz->trips_disabled))return ; - tz->ops->get_trip_temp (tz, trip, &trip_temp); - tz->ops->get_trip_type (tz, trip, &type); -if (tz->ops->get_trip_hyst) - tz->ops->get_trip_hyst (tz, trip, &hyst); +__thermal_zone_get_trip (tz, trip_id, &trip);if (tz->last_temperature !=THERMAL_TEMP_INVALID ) { -if (tz->last_temperature < trip_temp && - tz->temperature >= trip_temp) -thermal_notify_tz_trip_up (tz->id, trip, +if (tz->last_temperature < trip.temperature && + tz->temperature >= trip.temperature) +thermal_notify_tz_trip_up (tz->id, trip_id, tz->temperature); -if (tz->last_temperature >= trip_temp && - tz->temperature < (trip_temp - hyst)) -thermal_notify_tz_trip_down (tz->id, trip, +if (tz->last_temperature >= trip.temperature && + tz->temperature < (trip.temperature - trip.hysteresis)) +thermal_notify_tz_trip_down (tz->id, trip_id, tz->temperature); } -if (type ==THERMAL_TRIP_CRITICAL || type ==THERMAL_TRIP_HOT ) -handle_critical_trips (tz, trip, trip_temp, type); +if (trip.type ==THERMAL_TRIP_CRITICAL || trip.type ==THERMAL_TRIP_HOT ) +handle_critical_trips (tz, trip_id, trip.temperature, trip.type);else -handle_non_critical_trips (tz, trip); +handle_non_critical_trips (tz, trip_id); }static void update_temperature (struct thermal_zone_device *tz)
@@ -1142,6 +1138,79 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms *delay_jiffies =round_jiffies (*delay_jiffies); } +int thermal_zone_get_num_trips (struct thermal_zone_device *tz) +{ +return tz->num_trips; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_num_trips); + +int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp) +{ +int i, ret = -EINVAL ; + +if (tz->ops->get_crit_temp) +return tz->ops->get_crit_temp (tz, temp); + +if (!tz->trips) +return -EINVAL ; + +mutex_lock (&tz->lock); + +for (i =0 ; i < tz->num_trips; i++) { +if (tz->trips[i].type ==THERMAL_TRIP_CRITICAL ) { + *temp = tz->trips[i].temperature; + ret =0 ; +break ; + } + } + +mutex_unlock (&tz->lock); + +return ret; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_crit_temp); + +int __thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip) +{ +int ret; + +if (!tz || trip_id <0 || trip_id >= tz->num_trips || !trip) +return -EINVAL ; + +if (tz->trips) { + *trip = tz->trips[trip_id]; +return 0 ; + } + +if (tz->ops->get_trip_hyst) { + ret = tz->ops->get_trip_hyst (tz, trip_id, &trip->hysteresis); +if (ret) +return ret; + }else { + trip->hysteresis =0 ; + } + + ret = tz->ops->get_trip_temp (tz, trip_id, &trip->temperature); +if (ret) +return ret; + +return tz->ops->get_trip_type (tz, trip_id, &trip->type); +} + +int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip) +{ +int ret; + +mutex_lock (&tz->lock); + ret =__thermal_zone_get_trip (tz, trip_id, trip); +mutex_unlock (&tz->lock); + +return ret; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_trip); +/** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type
@@ -1174,8 +1243,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t int polling_delay) {struct thermal_zone_device *tz; -enum thermal_trip_type trip_type; -int trip_temp;int id;int result;int count;
@@ -1202,7 +1269,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *treturn ERR_PTR (-EINVAL ); } -if (num_trips >0 && (!ops->get_trip_type || !ops->get_trip_temp)) +if (num_trips >0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)return ERR_PTR (-EINVAL ); tz =kzalloc (sizeof (*tz),GFP_KERNEL );
@@ -1252,9 +1319,10 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t goto release_device;for (count =0 ; count < num_trips; count++) { -if (tz->ops->get_trip_type (tz, count, &trip_type) || - tz->ops->get_trip_temp (tz, count, &trip_temp) || - !trip_temp) +struct thermal_trip trip; + + result =thermal_zone_get_trip (tz, count, &trip); +if (result)set_bit (count, &tz->trips_disabled); }
drivers/thermal/thermal_core.h +2 -0
@@ -113,6 +113,8 @@ int thermal_build_list_of_policies(char *buf);/* Helpers */ void thermal_zone_set_trips (struct thermal_zone_device *tz);void __thermal_zone_set_trips (struct thermal_zone_device *tz); +int __thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip);int __thermal_zone_get_temp (struct thermal_zone_device *tz,int *temp);/* sysfs I/F */
drivers/thermal/thermal_helpers.c +14 -14
@@ -69,7 +69,7 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)int ret = -EINVAL ;int count;int crit_temp =INT_MAX ; -enum thermal_trip_type type; +struct thermal_trip trip;lockdep_assert_held (&tz->lock);
@@ -80,10 +80,9 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)if (IS_ENABLED (CONFIG_THERMAL_EMULATION ) && tz->emul_temperature) {for (count =0 ; count < tz->num_trips; count++) { - ret = tz->ops->get_trip_type (tz, count, &type); -if (!ret && type ==THERMAL_TRIP_CRITICAL ) { - ret = tz->ops->get_trip_temp (tz, count, - &crit_temp); + ret =__thermal_zone_get_trip (tz, count, &trip); +if (!ret && trip.type ==THERMAL_TRIP_CRITICAL ) { + crit_temp = trip.temperature;break ; } }
@@ -124,29 +123,30 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_temp);void __thermal_zone_set_trips (struct thermal_zone_device *tz) { -int low = -INT_MAX ; -int high =INT_MAX ; -int trip_temp, hysteresis; +struct thermal_trip trip; +int low = -INT_MAX , high =INT_MAX ;int i, ret;lockdep_assert_held (&tz->lock); -if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) +if (!tz->ops->set_trips)return ;for (i =0 ; i < tz->num_trips; i++) {int trip_low; - tz->ops->get_trip_temp (tz, i, &trip_temp); - tz->ops->get_trip_hyst (tz, i, &hysteresis); + ret =__thermal_zone_get_trip (tz, i , &trip); +if (ret) +return ; - trip_low = trip_temp - hysteresis; + trip_low = trip.temperature - trip.hysteresis;if (trip_low < tz->temperature && trip_low > low) low = trip_low; -if (trip_temp > tz->temperature && trip_temp < high) - high = trip_temp; +if (trip.temperature > tz->temperature && + trip.temperature < high) + high = trip.temperature; }/* No need to change trip points */
drivers/thermal/thermal_netlink.c +9 -12
@@ -452,7 +452,8 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)struct sk_buff *msg = p->msg;struct thermal_zone_device *tz;struct nlattr *start_trip; -int i, id; +struct thermal_trip trip; +int ret, i, id;if (!p->attrs[THERMAL_GENL_ATTR_TZ_ID ])return -EINVAL ;
@@ -471,18 +472,14 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)for (i =0 ; i < tz->num_trips; i++) { -enum thermal_trip_type type; -int temp, hyst =0 ; - - tz->ops->get_trip_type (tz, i, &type); - tz->ops->get_trip_temp (tz, i, &temp); -if (tz->ops->get_trip_hyst) - tz->ops->get_trip_hyst (tz, i, &hyst); - + ret =__thermal_zone_get_trip (tz, i, &trip); +if (ret) + goto out_cancel_nest; +if (nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_ID , i) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TYPE , type) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TEMP , temp) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_HYST , hyst)) +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TYPE , trip.type) || +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TEMP , trip.temperature) || +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_HYST , trip.hysteresis)) goto out_cancel_nest; }
drivers/thermal/thermal_sysfs.c +26 -40
124 lines not on this page · raw message
include/linux/thermal.h +7 -0
@@ -335,6 +335,13 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, }#endif +int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip); + +int thermal_zone_get_num_trips (struct thermal_zone_device *tz); + +int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp); +#ifdef CONFIG_THERMAL struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, void *, struct thermal_zone_device_ops *,
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/core: Add a generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 2ccd22c69a7ea95910a770fdab47c53c1d10a9bd Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//2ccd22c69a7ea95910a770fdab47c53c1d10a9bd Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:34 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 12:22:11 +01:00
thermal/core: Add a generic thermal_zone_get_trip() function
The thermal_zone_device_ops structure defines a set of ops family, get_trip_temp(), get_trip_hyst(), get_trip_type(). Each of them is returning a property of a trip point.
The result is the code is calling the ops everywhere to get a trip point which is supposed to be defined in the backend driver. It is a non-sense as a thermal trip can be generic and used by the backend driver to declare its trip points.
Part of the thermal framework has been changed and all the OF thermal drivers are using the same definition for the trip point and use a thermal zone registration variant to pass those trip points which are part of the thermal zone device structure.
Consequently, we can use a generic function to get the trip points when they are stored in the thermal zone device structure.
This approach can be generalized to all the drivers and we can get rid of the ops->get_trip_*. That will result to a much more simpler code and make possible to rework how the thermal trip are handled in the thermal core framework as discussed previously.
This change adds a function thermal_zone_get_trip() where we get the thermal trip point structure which contains all the properties (type, temp, hyst) instead of doing multiple calls to ops->get_trip_*.
That opens the door for trip point extension with more attributes. For instance, replacing the trip points disabled bitmask with a 'disabled' field in the structure.
Here we replace all the calls to ops->get_trip_* in the thermal core code with a call to the thermal_zone_get_trip() function.
The thermal zone ops defines a callback to retrieve the critical temperature. As the trip handling is being reworked, all the trip points will be the same whatever the driver and consequently finding the critical trip temperature will be just a loop to search for a critical trip point type.
Provide such a generic function, so we encapsulate the ops get_crit_temp() which can be removed when all the backend drivers are using the generic trip points handling.
While at it, add the thermal_zone_get_num_trips() to encapsulate the code more and reduce the grip with the thermal framework internals.
--- drivers/thermal/thermal_core.c | 114 +++++++++++++++++++++++------ drivers/thermal/thermal_core.h | 2 +- drivers/thermal/thermal_helpers.c | 28 +++---- drivers/thermal/thermal_netlink.c | 19 ++--- drivers/thermal/thermal_sysfs.c | 64 ++++++---------- include/linux/thermal.h | 7 ++- 6 files changed, 147 insertions(+), 87 deletions(-)
drivers/thermal/thermal_core.c +91 -23
@@ -344,35 +344,31 @@ static void handle_critical_trips(struct thermal_zone_device *tz, tz->ops->critical (tz); } -static void handle_thermal_trip (struct thermal_zone_device *tz,int trip) +static void handle_thermal_trip (struct thermal_zone_device *tz,int trip_id) { -enum thermal_trip_type type; -int trip_temp, hyst =0 ; +struct thermal_trip trip;/* Ignore disabled trip points */ -if (test_bit (trip, &tz->trips_disabled)) +if (test_bit (trip_id, &tz->trips_disabled))return ; - tz->ops->get_trip_temp (tz, trip, &trip_temp); - tz->ops->get_trip_type (tz, trip, &type); -if (tz->ops->get_trip_hyst) - tz->ops->get_trip_hyst (tz, trip, &hyst); +__thermal_zone_get_trip (tz, trip_id, &trip);if (tz->last_temperature !=THERMAL_TEMP_INVALID ) { -if (tz->last_temperature < trip_temp && - tz->temperature >= trip_temp) -thermal_notify_tz_trip_up (tz->id, trip, +if (tz->last_temperature < trip.temperature && + tz->temperature >= trip.temperature) +thermal_notify_tz_trip_up (tz->id, trip_id, tz->temperature); -if (tz->last_temperature >= trip_temp && - tz->temperature < (trip_temp - hyst)) -thermal_notify_tz_trip_down (tz->id, trip, +if (tz->last_temperature >= trip.temperature && + tz->temperature < (trip.temperature - trip.hysteresis)) +thermal_notify_tz_trip_down (tz->id, trip_id, tz->temperature); } -if (type ==THERMAL_TRIP_CRITICAL || type ==THERMAL_TRIP_HOT ) -handle_critical_trips (tz, trip, trip_temp, type); +if (trip.type ==THERMAL_TRIP_CRITICAL || trip.type ==THERMAL_TRIP_HOT ) +handle_critical_trips (tz, trip_id, trip.temperature, trip.type);else -handle_non_critical_trips (tz, trip); +handle_non_critical_trips (tz, trip_id); }static void update_temperature (struct thermal_zone_device *tz)
@@ -1159,6 +1155,79 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms *delay_jiffies =round_jiffies (*delay_jiffies); } +int thermal_zone_get_num_trips (struct thermal_zone_device *tz) +{ +return tz->num_trips; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_num_trips); + +int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp) +{ +int i, ret = -EINVAL ; + +if (tz->ops->get_crit_temp) +return tz->ops->get_crit_temp (tz, temp); + +if (!tz->trips) +return -EINVAL ; + +mutex_lock (&tz->lock); + +for (i =0 ; i < tz->num_trips; i++) { +if (tz->trips[i].type ==THERMAL_TRIP_CRITICAL ) { + *temp = tz->trips[i].temperature; + ret =0 ; +break ; + } + } + +mutex_unlock (&tz->lock); + +return ret; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_crit_temp); + +int __thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip) +{ +int ret; + +if (!tz || trip_id <0 || trip_id >= tz->num_trips || !trip) +return -EINVAL ; + +if (tz->trips) { + *trip = tz->trips[trip_id]; +return 0 ; + } + +if (tz->ops->get_trip_hyst) { + ret = tz->ops->get_trip_hyst (tz, trip_id, &trip->hysteresis); +if (ret) +return ret; + }else { + trip->hysteresis =0 ; + } + + ret = tz->ops->get_trip_temp (tz, trip_id, &trip->temperature); +if (ret) +return ret; + +return tz->ops->get_trip_type (tz, trip_id, &trip->type); +} + +int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip) +{ +int ret; + +mutex_lock (&tz->lock); + ret =__thermal_zone_get_trip (tz, trip_id, trip); +mutex_unlock (&tz->lock); + +return ret; +} +EXPORT_SYMBOL_GPL (thermal_zone_get_trip); +/** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type
@@ -1191,8 +1260,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t int polling_delay) {struct thermal_zone_device *tz; -enum thermal_trip_type trip_type; -int trip_temp;int id;int result;int count;
@@ -1232,7 +1299,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *treturn ERR_PTR (-EINVAL ); } -if (num_trips >0 && (!ops->get_trip_type || !ops->get_trip_temp)) +if (num_trips >0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)return ERR_PTR (-EINVAL ); tz =kzalloc (sizeof (*tz),GFP_KERNEL );
@@ -1283,9 +1350,10 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t goto release_device;for (count =0 ; count < num_trips; count++) { -if (tz->ops->get_trip_type (tz, count, &trip_type) || - tz->ops->get_trip_temp (tz, count, &trip_temp) || - !trip_temp) +struct thermal_trip trip; + + result =thermal_zone_get_trip (tz, count, &trip); +if (result)set_bit (count, &tz->trips_disabled); }
drivers/thermal/thermal_core.h +2 -0
@@ -114,6 +114,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,/* Helpers */ void __thermal_zone_set_trips (struct thermal_zone_device *tz); +int __thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip);int __thermal_zone_get_temp (struct thermal_zone_device *tz,int *temp);/* sysfs I/F */
drivers/thermal/thermal_helpers.c +14 -14
@@ -83,7 +83,7 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)int ret = -EINVAL ;int count;int crit_temp =INT_MAX ; -enum thermal_trip_type type; +struct thermal_trip trip;lockdep_assert_held (&tz->lock);
@@ -91,10 +91,9 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)if (IS_ENABLED (CONFIG_THERMAL_EMULATION ) && tz->emul_temperature) {for (count =0 ; count < tz->num_trips; count++) { - ret = tz->ops->get_trip_type (tz, count, &type); -if (!ret && type ==THERMAL_TRIP_CRITICAL ) { - ret = tz->ops->get_trip_temp (tz, count, - &crit_temp); + ret =__thermal_zone_get_trip (tz, count, &trip); +if (!ret && trip.type ==THERMAL_TRIP_CRITICAL ) { + crit_temp = trip.temperature;break ; } }
@@ -164,29 +163,30 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_temp);*/ void __thermal_zone_set_trips (struct thermal_zone_device *tz) { -int low = -INT_MAX ; -int high =INT_MAX ; -int trip_temp, hysteresis; +struct thermal_trip trip; +int low = -INT_MAX , high =INT_MAX ;int i, ret;lockdep_assert_held (&tz->lock); -if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) +if (!tz->ops->set_trips)return ;for (i =0 ; i < tz->num_trips; i++) {int trip_low; - tz->ops->get_trip_temp (tz, i, &trip_temp); - tz->ops->get_trip_hyst (tz, i, &hysteresis); + ret =__thermal_zone_get_trip (tz, i , &trip); +if (ret) +return ; - trip_low = trip_temp - hysteresis; + trip_low = trip.temperature - trip.hysteresis;if (trip_low < tz->temperature && trip_low > low) low = trip_low; -if (trip_temp > tz->temperature && trip_temp < high) - high = trip_temp; +if (trip.temperature > tz->temperature && + trip.temperature < high) + high = trip.temperature; }/* No need to change trip points */
drivers/thermal/thermal_netlink.c +8 -11
@@ -452,7 +452,8 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)struct sk_buff *msg = p->msg;struct thermal_zone_device *tz;struct nlattr *start_trip; -int i, id; +struct thermal_trip trip; +int ret, i, id;if (!p->attrs[THERMAL_GENL_ATTR_TZ_ID ])return -EINVAL ;
@@ -471,18 +472,14 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)for (i =0 ; i < tz->num_trips; i++) { -enum thermal_trip_type type; -int temp, hyst =0 ; - - tz->ops->get_trip_type (tz, i, &type); - tz->ops->get_trip_temp (tz, i, &temp); -if (tz->ops->get_trip_hyst) - tz->ops->get_trip_hyst (tz, i, &hyst); + ret =__thermal_zone_get_trip (tz, i, &trip); +if (ret) + goto out_cancel_nest;if (nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_ID , i) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TYPE , type) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TEMP , temp) || -nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_HYST , hyst)) +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TYPE , trip.type) || +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_TEMP , trip.temperature) || +nla_put_u32 (msg,THERMAL_GENL_ATTR_TZ_TRIP_HYST , trip.hysteresis)) goto out_cancel_nest; }
drivers/thermal/thermal_sysfs.c +25 -39
145 lines not on this page · raw message
include/linux/thermal.h +7 -0
@@ -334,6 +334,13 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, }#endif +int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id, +struct thermal_trip *trip); + +int thermal_zone_get_num_trips (struct thermal_zone_device *tz); + +int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp); +#ifdef CONFIG_THERMAL struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, void *, struct thermal_zone_device_ops *,
Re: [PATCH v8 01/29] thermal/core: Add a generic thermal_zone_get_trip() function
In reply to Daniel LezcanoReview thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t · line 1327
Quoted 13 lines · Daniel Lezcano
(quoted diff) +4
-3@@ -1252,9 +1319,10 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t goto release_device; for (count = 0; count < num_trips; count++) { - if (tz->ops->get_trip_type(tz, count, &trip_type) || - tz->ops->get_trip_temp(tz, count, &trip_temp) || - !trip_temp) + struct thermal_trip trip; + + result = thermal_zone_get_trip(tz, count, &trip); + if (result) set_bit(count, &tz->trips_disabled); }
Daniel, this change makes it so that trip points with a temperature of zero are no longer disabled. This behavior was originally added in commit 81ad4276b505 ("Thermal: Ignore invalid trip points"). The mlxsw driver relies on this behavior - see mlxsw_thermal_module_trips_reset()
- and with this change I see that the thermal subsystem tries to repeatedly set the state of the associated cooling devices to the maximum state. Other drivers might also be affected by this.
Following patch solves the problem for me:
drivers/thermal/thermal_core.c +1 -1
@@ -1309,7 +1309,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *tstruct thermal_trip trip; result =thermal_zone_get_trip (tz, count, &trip); -if (result) +if (result || !trip.temperature)set_bit (count, &tz->trips_disabled); }
Should I submit it or do you have a better idea?
Thanks
Re: [PATCH v8 01/29] thermal/core: Add a generic thermal_zone_get_trip() function
Hi Ido,
Quoted 38 lines · Ido Schimmel
Review thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t · line 1327
Quoted 13 lines · Daniel Lezcano
(quoted diff) +4
-3@@ -1252,9 +1319,10 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t goto release_device; for (count = 0; count < num_trips; count++) { - if (tz->ops->get_trip_type(tz, count, &trip_type) || - tz->ops->get_trip_temp(tz, count, &trip_temp) || - !trip_temp) + struct thermal_trip trip; + + result = thermal_zone_get_trip(tz, count, &trip); + if (result) set_bit(count, &tz->trips_disabled); }Daniel, this change makes it so that trip points with a temperature of zero are no longer disabled. This behavior was originally added in commit
81ad4276b505("Thermal: Ignore invalid trip points"). The mlxsw driver relies on this behavior - seemlxsw_thermal_module_trips_reset()
- and with this change I see that the thermal subsystem tries to repeatedly set the state of the associated cooling devices to the maximum state. Other drivers might also be affected by this.Following patch solves the problem for me:
drivers/thermal/thermal_core.c +1
-1@@ -1309,7 +1309,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *tstruct thermal_trip trip; result =thermal_zone_get_trip (tz, count, &trip); -if (result) +if (result || !trip.temperature)set_bit (count, &tz->trips_disabled); }
Quoted 1 line
Should I submit it or do you have a better idea?
Thanks for reporting this, I think the fix you are proposing is correct regarding the previous behavior.
However, I disagree with the commit 81ad4276b505, because it defines the zero as an invalid trip point. But some platforms have warming devices, when the temperature is too cold, eg 0°C, we enable the warming device in order to stay in the functioning temperature range.
Other devices can do the same with negative temperature values.
This feature is not yet upstream and the rework of the trip point should allow proper handling of cold trip points.
If you can send the change to fix the regression that would be great.
But keep in mind, the driver is assuming an internal thermal framework behavior. The trips_disabled is only to overcome a trip point description bug and you should not rely on it as well as not changing the trip points on the fly after they are registered.
Actually, the mlxsw driver should just build a valid array of trip points without 0°C trip point and pass it to thermal_zone_device_register_with_trips(). That would be a proper change without relying on a side effect of the thermal trip bug 0°C workaround.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH v8 01/29] thermal/core: Add a generic thermal_zone_get_trip() function
Quoted 8 lines · Daniel Lezcano
Thanks for reporting this, I think the fix you are proposing is correct regarding the previous behavior.
However, I disagree with the commit
81ad4276b505, because it defines the zero as an invalid trip point. But some platforms have warming devices, when the temperature is too cold, eg 0°C, we enable the warming device in order to stay in the functioning temperature range.
Quoted 6 lines
Other devices can do the same with negative temperature values.
This feature is not yet upstream and the rework of the trip point should allow proper handling of cold trip points.
If you can send the change to fix the regression that would be great.
Thanks for the reply. Will send you the fix later this week. I want to test it across all of our systems.
Quoted 10 lines
But keep in mind, the driver is assuming an internal thermal framework behavior. The
trips_disabledis only to overcome a trip point description bug and you should not rely on it as well as not changing the trip points on the fly after they are registered.Actually, the mlxsw driver should just build a valid array of trip points without 0°C trip point and pass it to
thermal_zone_device_register_with_trips(). That would be a proper change without relying on a side effect of the thermal trip bug 0°C workaround.
Understood. Will check with Vadim what we can do in order not to rely on this behavior.
PATCH v8 2/29 thermal/sysfs: Always expose hysteresis attributes
In reply to Daniel LezcanoInstead of avoiding to expose the hysteresis attributes of a thermal zone when its get_trip_hyst() operation is not defined, which is confusing, expose them always and use the default thermal_zone_get_trip() function returning 0 hysteresis when that operation is not present.
The hysteresis of 0 is perfectly valid, so this change should not introduce any backwards compatibility issues.
--- drivers/thermal/thermal_sysfs.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/thermal/thermal_sysfs.c +9 -16
@@ -426,23 +426,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)return -ENOMEM ; } -if (tz->ops->get_trip_hyst) { - tz->trip_hyst_attrs =kcalloc (tz->num_trips, -sizeof (*tz->trip_hyst_attrs), -GFP_KERNEL ); -if (!tz->trip_hyst_attrs) { -kfree (tz->trip_type_attrs); -kfree (tz->trip_temp_attrs); -return -ENOMEM ; - } + tz->trip_hyst_attrs =kcalloc (tz->num_trips, +sizeof (*tz->trip_hyst_attrs), +GFP_KERNEL ); +if (!tz->trip_hyst_attrs) { +kfree (tz->trip_type_attrs); +kfree (tz->trip_temp_attrs); +return -ENOMEM ; } attrs =kcalloc (tz->num_trips *3 +1 ,sizeof (*attrs),GFP_KERNEL );if (!attrs) {kfree (tz->trip_type_attrs);kfree (tz->trip_temp_attrs); -if (tz->ops->get_trip_hyst) -kfree (tz->trip_hyst_attrs); +kfree (tz->trip_hyst_attrs);return -ENOMEM ; }
@@ -475,9 +472,6 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) } attrs[indx + tz->num_trips] = &tz->trip_temp_attrs[indx].attr.attr; -/* create Optional trip hyst attribute */ -if (!tz->ops->get_trip_hyst) -continue ;snprintf (tz->trip_hyst_attrs[indx].name,THERMAL_NAME_LENGTH ,"trip_point_%d_hyst" , indx);
@@ -514,8 +508,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz)kfree (tz->trip_type_attrs);kfree (tz->trip_temp_attrs); -if (tz->ops->get_trip_hyst) -kfree (tz->trip_hyst_attrs); +kfree (tz->trip_hyst_attrs);kfree (tz->trips_attribute_group.attrs); }
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/sysfs: Always expose hysteresis attributes
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: d75af335875228b435b09d97d9bf49ed6ab9034b Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//d75af335875228b435b09d97d9bf49ed6ab9034b Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:35 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 12:24:16 +01:00
thermal/sysfs: Always expose hysteresis attributes
Instead of avoiding to expose the hysteresis attributes of a thermal zone when its get_trip_hyst() operation is not defined, which is confusing, expose them always and use the default thermal_zone_get_trip() function returning 0 hysteresis when that operation is not present.
The hysteresis of 0 is perfectly valid, so this change should not introduce any backwards compatibility issues.
--- drivers/thermal/thermal_sysfs.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/thermal/thermal_sysfs.c +9 -16
@@ -477,23 +477,20 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)return -ENOMEM ; } -if (tz->ops->get_trip_hyst) { - tz->trip_hyst_attrs =kcalloc (tz->num_trips, -sizeof (*tz->trip_hyst_attrs), -GFP_KERNEL ); -if (!tz->trip_hyst_attrs) { -kfree (tz->trip_type_attrs); -kfree (tz->trip_temp_attrs); -return -ENOMEM ; - } + tz->trip_hyst_attrs =kcalloc (tz->num_trips, +sizeof (*tz->trip_hyst_attrs), +GFP_KERNEL ); +if (!tz->trip_hyst_attrs) { +kfree (tz->trip_type_attrs); +kfree (tz->trip_temp_attrs); +return -ENOMEM ; } attrs =kcalloc (tz->num_trips *3 +1 ,sizeof (*attrs),GFP_KERNEL );if (!attrs) {kfree (tz->trip_type_attrs);kfree (tz->trip_temp_attrs); -if (tz->ops->get_trip_hyst) -kfree (tz->trip_hyst_attrs); +kfree (tz->trip_hyst_attrs);return -ENOMEM ; }
@@ -526,9 +523,6 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) } attrs[indx + tz->num_trips] = &tz->trip_temp_attrs[indx].attr.attr; -/* create Optional trip hyst attribute */ -if (!tz->ops->get_trip_hyst) -continue ;snprintf (tz->trip_hyst_attrs[indx].name,THERMAL_NAME_LENGTH ,"trip_point_%d_hyst" , indx);
@@ -565,8 +559,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz)kfree (tz->trip_type_attrs);kfree (tz->trip_temp_attrs); -if (tz->ops->get_trip_hyst) -kfree (tz->trip_hyst_attrs); +kfree (tz->trip_hyst_attrs);kfree (tz->trips_attribute_group.attrs); }
PATCH v8 3/29 thermal/core: Add a generic thermal_zone_set_trip() function
In reply to Daniel LezcanoThe thermal zone ops defines a set_trip callback where we can invoke the backend driver to set an interrupt for the next trip point temperature being crossed the way up or down, or setting the low level with the hysteresis.
The ops is only called from the thermal sysfs code where the userspace has the ability to modify a trip point characteristic.
With the effort of encapsulating the thermal framework core code, let's create a thermal_zone_set_trip() which is the writable side of the thermal_zone_get_trip() and put there all the ops encapsulation.
---
V8:
- pretty one line condition and parenthesis removal (Rafael J. Wysocki)
--- drivers/thermal/thermal_core.c | 46 +++++++++++++++++++++++++++++ drivers/thermal/thermal_sysfs.c | 52 +++++++++++---------------------- include/linux/thermal.h | 3 ++ 3 files changed, 66 insertions(+), 35 deletions(-)
drivers/thermal/thermal_core.c +46 -0
@@ -1211,6 +1211,52 @@ int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, }EXPORT_SYMBOL_GPL (thermal_zone_get_trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip) +{ +struct thermal_trip t; +int ret = -EINVAL ; + +mutex_lock (&tz->lock); + +if (!tz->ops->set_trip_temp && !tz->ops->set_trip_hyst && !tz->trips) + goto out; + + ret =__thermal_zone_get_trip (tz, trip_id, &t); +if (ret) + goto out; + +if (t.type != trip->type) { + ret = -EINVAL ; + goto out; + } + +if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { + ret = tz->ops->set_trip_temp (tz, trip_id, trip->temperature); +if (ret) + goto out; + } + +if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { + ret = tz->ops->set_trip_hyst (tz, trip_id, trip->hysteresis); +if (ret) + goto out; + } + +if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) + tz->trips[trip_id] = *trip; +out: +mutex_unlock (&tz->lock); + +if (!ret) { +thermal_notify_tz_trip_change (tz->id, trip_id, trip->type, + trip->temperature, trip->hysteresis); +thermal_zone_device_update (tz,THERMAL_TRIP_CHANGED ); + } + +return ret; +} +/** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type
drivers/thermal/thermal_sysfs.c +17 -35
78 lines not on this page · raw message
include/linux/thermal.h +3 -0
@@ -338,6 +338,9 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev,int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id,struct thermal_trip *trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip); +int thermal_zone_get_num_trips (struct thermal_zone_device *tz);int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp);
Signature · 1 line
2.34.1
Re: [PATCH v8 03/29] thermal/core: Add a generic thermal_zone_set_trip() function
Quoted 6 lines · Daniel Lezcano
The thermal zone ops defines a
set_tripcallback where we can invoke the backend driver to set an interrupt for the next trip point temperature being crossed the way up or down, or setting the low level with the hysteresis.
Quoted 8 lines
The ops is only called from the thermal sysfs code where the userspace has the ability to modify a trip point characteristic.
With the effort of encapsulating the thermal framework core code, let's create a
thermal_zone_set_trip()which is the writable side of thethermal_zone_get_trip()and put there all the ops encapsulation.Signed-off-by Daniel Lezcano <[email protected]>
Quoted 167 lines
---
V8:
- pretty one line condition and parenthesis removal (Rafael J. Wysocki)--- drivers/thermal/thermal_core.c | 46 +++++++++++++++++++++++++++++ drivers/thermal/thermal_sysfs.c | 52 +++++++++++---------------------- include/linux/thermal.h | 3 ++ 3 files changed, 66 insertions(+), 35 deletions(-)drivers/thermal/thermal_core.c +46
-0@@ -1211,6 +1211,52 @@ int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, }EXPORT_SYMBOL_GPL (thermal_zone_get_trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip) +{ +struct thermal_trip t; +int ret = -EINVAL ; + +mutex_lock (&tz->lock); + +if (!tz->ops->set_trip_temp && !tz->ops->set_trip_hyst && !tz->trips) + goto out; + + ret =__thermal_zone_get_trip (tz, trip_id, &t); +if (ret) + goto out; + +if (t.type != trip->type) { + ret = -EINVAL ; + goto out; + } + +if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { + ret = tz->ops->set_trip_temp (tz, trip_id, trip->temperature); +if (ret) + goto out; + } + +if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { + ret = tz->ops->set_trip_hyst (tz, trip_id, trip->hysteresis); +if (ret) + goto out; + } + +if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) + tz->trips[trip_id] = *trip; +out: +mutex_unlock (&tz->lock); + +if (!ret) { +thermal_notify_tz_trip_change (tz->id, trip_id, trip->type, + trip->temperature, trip->hysteresis); +thermal_zone_device_update (tz,THERMAL_TRIP_CHANGED ); + } + +return ret; +} +/** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type drivers/thermal/thermal_sysfs.c +17
-35@@ -115,32 +115,19 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,struct thermal_trip trip;int trip_id, ret; -if (!tz->ops->set_trip_temp && !tz->trips) -return -EPERM ; -if (sscanf (attr->attr.name,"trip_point_%d_temp" , &trip_id) !=1 )return -EINVAL ; -if (kstrtoint (buf,10 , &trip.temperature)) -return -EINVAL ; - -if (tz->ops->set_trip_temp) { - ret = tz->ops->set_trip_temp (tz, trip_id, trip.temperature); -if (ret) -return ret; - } - -if (tz->trips) - tz->trips[trip_id].temperature = trip.temperature; - ret =thermal_zone_get_trip (tz, trip_id, &trip);if (ret)return ret; -thermal_notify_tz_trip_change (tz->id, trip_id, trip.type, - trip.temperature, trip.hysteresis); +if (kstrtoint (buf,10 , &trip.temperature)) +return -EINVAL ; -thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); + ret =thermal_zone_set_trip (tz, trip_id, &trip); +if (ret) +return ret;return count; }@@ -168,29 +155,24 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {struct thermal_zone_device *tz =to_thermal_zone (dev); -int trip, ret; -int temperature; - -if (!tz->ops->set_trip_hyst) -return -EPERM ; +struct thermal_trip trip; +int trip_id, ret; -if (sscanf (attr->attr.name,"trip_point_%d_hyst" , &trip) !=1 ) +if (sscanf (attr->attr.name,"trip_point_%d_hyst" , &trip_id) !=1 )return -EINVAL ; -if (kstrtoint (buf,10 , &temperature)) -return -EINVAL ; + ret =thermal_zone_get_trip (tz, trip_id, &trip); +if (ret) +return ret; -/* -* We are not doing any check on the 'temperature' value -* here. The driver implementing 'set_trip_hyst' has to -* take care of this. -*/ - ret = tz->ops->set_trip_hyst (tz, trip, temperature); +if (kstrtoint (buf,10 , &trip.hysteresis)) +return -EINVAL ; -if (!ret) -thermal_zone_set_trips (tz); + ret =thermal_zone_set_trip (tz, trip_id, &trip); +if (ret) +return ret; -return ret ? ret : count; +return count; } static ssize_tinclude/linux/thermal.h +3
-1@@ -338,6 +338,9 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev,int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id,struct thermal_trip *trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip); +int thermal_zone_get_num_trips (struct thermal_zone_device *tz);int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp); --2.34.1
[thermal: thermal/next] thermal/core: Add a generic thermal_zone_set_trip() function
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 3ab3c603e6dd30b9ff4d73e4b48b68dff1b82163 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//3ab3c603e6dd30b9ff4d73e4b48b68dff1b82163 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:36 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/core: Add a generic thermal_zone_set_trip() function
The thermal zone ops defines a set_trip callback where we can invoke the backend driver to set an interrupt for the next trip point temperature being crossed the way up or down, or setting the low level with the hysteresis.
The ops is only called from the thermal sysfs code where the userspace has the ability to modify a trip point characteristic.
With the effort of encapsulating the thermal framework core code, let's create a thermal_zone_set_trip() which is the writable side of the thermal_zone_get_trip() and put there all the ops encapsulation.
--- drivers/thermal/thermal_core.c | 39 ++++++++++++++++++++++- drivers/thermal/thermal_sysfs.c | 56 ++++++++------------------------ include/linux/thermal.h | 3 ++- 3 files changed, 57 insertions(+), 41 deletions(-)
drivers/thermal/thermal_core.c +39 -0
@@ -1228,6 +1228,45 @@ int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, }EXPORT_SYMBOL_GPL (thermal_zone_get_trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip) +{ +struct thermal_trip t; +int ret; + +if (!tz->ops->set_trip_temp && !tz->ops->set_trip_hyst && !tz->trips) +return -EINVAL ; + + ret =__thermal_zone_get_trip (tz, trip_id, &t); +if (ret) +return ret; + +if (t.type != trip->type) +return -EINVAL ; + +if (t.temperature != trip->temperature && tz->ops->set_trip_temp) { + ret = tz->ops->set_trip_temp (tz, trip_id, trip->temperature); +if (ret) +return ret; + } + +if (t.hysteresis != trip->hysteresis && tz->ops->set_trip_hyst) { + ret = tz->ops->set_trip_hyst (tz, trip_id, trip->hysteresis); +if (ret) +return ret; + } + +if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) + tz->trips[trip_id] = *trip; + +thermal_notify_tz_trip_change (tz->id, trip_id, trip->type, + trip->temperature, trip->hysteresis); + +__thermal_zone_device_update (tz,THERMAL_TRIP_CHANGED ); + +return 0 ; +} +/** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type
drivers/thermal/thermal_sysfs.c +15 -41
93 lines not on this page · raw message
include/linux/thermal.h +3 -0
@@ -337,6 +337,9 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev,int thermal_zone_get_trip (struct thermal_zone_device *tz,int trip_id,struct thermal_trip *trip); +int thermal_zone_set_trip (struct thermal_zone_device *tz,int trip_id, +const struct thermal_trip *trip); +int thermal_zone_get_num_trips (struct thermal_zone_device *tz);int thermal_zone_get_crit_temp (struct thermal_zone_device *tz,int *temp);
PATCH v8 4/29 thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions
In reply to Daniel LezcanoThe governors are using the ops->get_trip_* functions, Replace these calls with thermal_zone_get_trip().
--- drivers/thermal/gov_bang_bang.c | 39 +++++++++++--------- drivers/thermal/gov_fair_share.c | 18 ++++------ drivers/thermal/gov_power_allocator.c | 51 ++++++++++++--------------- drivers/thermal/gov_step_wise.c | 22 ++++++------ 4 files changed, 62 insertions(+), 68 deletions(-)
drivers/thermal/gov_bang_bang.c +23 -16
@@ -13,26 +13,28 @@#include "thermal_core.h" -static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip) +static int thermal_zone_trip_update (struct thermal_zone_device *tz,int trip_id) { -int trip_temp, trip_hyst; +struct thermal_trip trip;struct thermal_instance *instance; +int ret; - tz->ops->get_trip_temp (tz, trip, &trip_temp); - -if (!tz->ops->get_trip_hyst) { -pr_warn_once ("Undefined get_trip_hyst for thermal zone %s - " -"running with default hysteresis zero\n" , tz->type); - trip_hyst =0 ; - }else - tz->ops->get_trip_hyst (tz, trip, &trip_hyst); + ret =__thermal_zone_get_trip (tz, trip_id, &trip); +if (ret) { +pr_warn_once ("Failed to retrieve trip point %d\n" , trip_id); +return ret; + } + +if (!trip.hysteresis) +dev_info_once (&tz->device, +"Zero hysteresis value for thermal zone %s\n" , tz->type);dev_dbg (&tz->device,"Trip%d[temp=%d]:temp=%d:hyst=%d\n" , - trip, trip_temp, tz->temperature, - trip_hyst); + trip_id, trip.temperature, tz->temperature, + trip.hysteresis);list_for_each_entry (instance, &tz->thermal_instances, tz_node) { -if (instance->trip != trip) +if (instance->trip != trip_id)continue ;/* in case fan is in initial state, switch the fan off */
@@ -50,10 +52,10 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)* enable fan when temperature exceeds trip_temp and disable * the fan in case it falls below trip_temp minus hysteresis */ -if (instance->target ==0 && tz->temperature >= trip_temp) +if (instance->target ==0 && tz->temperature >= trip.temperature) instance->target =1 ;else if (instance->target ==1 && - tz->temperature <= trip_temp - trip_hyst) + tz->temperature <= trip.temperature - trip.hysteresis) instance->target =0 ; dev_dbg(&instance->cdev->device, "target=%d\n",
@@ -63,6 +65,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) instance->cdev->updated = false;/* cdev needs update */ mutex_unlock (&instance->cdev->lock); } + +return 0 ; }/**
@@ -95,10 +99,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)static int bang_bang_control (struct thermal_zone_device *tz,int trip) {struct thermal_instance *instance; +int ret;lockdep_assert_held (&tz->lock); -thermal_zone_trip_update (tz, trip); + ret =thermal_zone_trip_update (tz, trip); +if (ret) +return ret;list_for_each_entry (instance, &tz->thermal_instances, tz_node)thermal_cdev_update (instance->cdev);
drivers/thermal/gov_fair_share.c +6 -12
@@ -21,16 +21,12 @@*/ static int get_trip_level (struct thermal_zone_device *tz) { -int count =0 ; -int trip_temp; -enum thermal_trip_type trip_type; - -if (tz->num_trips ==0 || !tz->ops->get_trip_temp) -return 0 ; +struct thermal_trip trip; +int count;for (count =0 ; count < tz->num_trips; count++) { - tz->ops->get_trip_temp (tz, count, &trip_temp); -if (tz->temperature < trip_temp) +__thermal_zone_get_trip (tz, count, &trip); +if (tz->temperature < trip.temperature)break ; }
@@ -38,10 +34,8 @@ static int get_trip_level(struct thermal_zone_device *tz)* count > 0 only if temperature is greater than first trip * point, in which case, trip_point = count - 1 */ -if (count >0 ) { - tz->ops->get_trip_type (tz, count -1 , &trip_type); -trace_thermal_zone_trip (tz, count -1 , trip_type); - } +if (count >0 ) +trace_thermal_zone_trip (tz, count -1 , trip.type);return count; }
drivers/thermal/gov_power_allocator.c +23 -28
123 lines not on this page · raw message
drivers/thermal/gov_step_wise.c +10 -12
@@ -95,30 +95,28 @@ static void update_passive_instance(struct thermal_zone_device *tz, tz->passive += value; } -static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip) +static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip_id) { -int trip_temp; -enum thermal_trip_type trip_type;enum thermal_trend trend;struct thermal_instance *instance; +struct thermal_trip trip;bool throttle = false;int old_target; - tz->ops->get_trip_temp (tz, trip, &trip_temp); - tz->ops->get_trip_type (tz, trip, &trip_type); +__thermal_zone_get_trip (tz, trip_id, &trip); - trend =get_tz_trend (tz, trip); + trend =get_tz_trend (tz, trip_id); -if (tz->temperature >= trip_temp) { +if (tz->temperature >= trip.temperature) { throttle = true; -trace_thermal_zone_trip (tz, trip, trip_type); +trace_thermal_zone_trip (tz, trip_id, trip.type); }dev_dbg (&tz->device,"Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n" , - trip, trip_type, trip_temp, trend, throttle); + trip_id, trip.type, trip.temperature, trend, throttle);list_for_each_entry (instance, &tz->thermal_instances, tz_node) { -if (instance->trip != trip) +if (instance->trip != trip_id)continue ; old_target = instance->target;
@@ -132,11 +130,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)/* Activate a passive thermal instance */ if (old_target ==THERMAL_NO_TARGET && instance->target !=THERMAL_NO_TARGET ) -update_passive_instance (tz, trip_type,1 ); +update_passive_instance (tz, trip.type,1 );/* Deactivate a passive thermal instance */ else if (old_target !=THERMAL_NO_TARGET && instance->target ==THERMAL_NO_TARGET ) -update_passive_instance (tz, trip_type,-1 ); +update_passive_instance (tz, trip.type,-1 ); instance->initialized = true;mutex_lock (&instance->cdev->lock);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 598b0cbd91f5b2359c3abc2ac88f7ac03b86049c Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//598b0cbd91f5b2359c3abc2ac88f7ac03b86049c Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:37 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions
The governors are using the ops->get_trip_* functions, Replace these calls with thermal_zone_get_trip().
--- drivers/thermal/gov_bang_bang.c | 37 +++++++++++-------- drivers/thermal/gov_fair_share.c | 18 +++------ drivers/thermal/gov_power_allocator.c | 51 +++++++++++--------------- drivers/thermal/gov_step_wise.c | 22 +++++------ 4 files changed, 61 insertions(+), 67 deletions(-)
drivers/thermal/gov_bang_bang.c +22 -15
@@ -13,26 +13,28 @@#include "thermal_core.h" -static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip) +static int thermal_zone_trip_update (struct thermal_zone_device *tz,int trip_id) { -int trip_temp, trip_hyst; +struct thermal_trip trip;struct thermal_instance *instance; +int ret; - tz->ops->get_trip_temp (tz, trip, &trip_temp); + ret =__thermal_zone_get_trip (tz, trip_id, &trip); +if (ret) { +pr_warn_once ("Failed to retrieve trip point %d\n" , trip_id); +return ret; + } -if (!tz->ops->get_trip_hyst) { -pr_warn_once ("Undefined get_trip_hyst for thermal zone %s - " -"running with default hysteresis zero\n" , tz->type); - trip_hyst =0 ; - }else - tz->ops->get_trip_hyst (tz, trip, &trip_hyst); +if (!trip.hysteresis) +dev_info_once (&tz->device, +"Zero hysteresis value for thermal zone %s\n" , tz->type);dev_dbg (&tz->device,"Trip%d[temp=%d]:temp=%d:hyst=%d\n" , - trip, trip_temp, tz->temperature, - trip_hyst); + trip_id, trip.temperature, tz->temperature, + trip.hysteresis);list_for_each_entry (instance, &tz->thermal_instances, tz_node) { -if (instance->trip != trip) +if (instance->trip != trip_id)continue ;/* in case fan is in initial state, switch the fan off */
@@ -50,10 +52,10 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)* enable fan when temperature exceeds trip_temp and disable * the fan in case it falls below trip_temp minus hysteresis */ -if (instance->target ==0 && tz->temperature >= trip_temp) +if (instance->target ==0 && tz->temperature >= trip.temperature) instance->target =1 ;else if (instance->target ==1 && - tz->temperature <= trip_temp - trip_hyst) + tz->temperature <= trip.temperature - trip.hysteresis) instance->target =0 ; dev_dbg(&instance->cdev->device, "target=%d\n",
@@ -63,6 +65,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) instance->cdev->updated = false;/* cdev needs update */ mutex_unlock (&instance->cdev->lock); } + +return 0 ; }/**
@@ -95,10 +99,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)static int bang_bang_control (struct thermal_zone_device *tz,int trip) {struct thermal_instance *instance; +int ret;lockdep_assert_held (&tz->lock); -thermal_zone_trip_update (tz, trip); + ret =thermal_zone_trip_update (tz, trip); +if (ret) +return ret;list_for_each_entry (instance, &tz->thermal_instances, tz_node)thermal_cdev_update (instance->cdev);
drivers/thermal/gov_fair_share.c +6 -12
@@ -21,16 +21,12 @@*/ static int get_trip_level (struct thermal_zone_device *tz) { -int count =0 ; -int trip_temp; -enum thermal_trip_type trip_type; - -if (tz->num_trips ==0 || !tz->ops->get_trip_temp) -return 0 ; +struct thermal_trip trip; +int count;for (count =0 ; count < tz->num_trips; count++) { - tz->ops->get_trip_temp (tz, count, &trip_temp); -if (tz->temperature < trip_temp) +__thermal_zone_get_trip (tz, count, &trip); +if (tz->temperature < trip.temperature)break ; }
@@ -38,10 +34,8 @@ static int get_trip_level(struct thermal_zone_device *tz)* count > 0 only if temperature is greater than first trip * point, in which case, trip_point = count - 1 */ -if (count >0 ) { - tz->ops->get_trip_type (tz, count -1 , &trip_type); -trace_thermal_zone_trip (tz, count -1 , trip_type); - } +if (count >0 ) +trace_thermal_zone_trip (tz, count -1 , trip.type);return count; }
drivers/thermal/gov_power_allocator.c +23 -28
123 lines not on this page · raw message
drivers/thermal/gov_step_wise.c +10 -12
@@ -95,30 +95,28 @@ static void update_passive_instance(struct thermal_zone_device *tz, tz->passive += value; } -static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip) +static void thermal_zone_trip_update (struct thermal_zone_device *tz,int trip_id) { -int trip_temp; -enum thermal_trip_type trip_type;enum thermal_trend trend;struct thermal_instance *instance; +struct thermal_trip trip;bool throttle = false;int old_target; - tz->ops->get_trip_temp (tz, trip, &trip_temp); - tz->ops->get_trip_type (tz, trip, &trip_type); +__thermal_zone_get_trip (tz, trip_id, &trip); - trend =get_tz_trend (tz, trip); + trend =get_tz_trend (tz, trip_id); -if (tz->temperature >= trip_temp) { +if (tz->temperature >= trip.temperature) { throttle = true; -trace_thermal_zone_trip (tz, trip, trip_type); +trace_thermal_zone_trip (tz, trip_id, trip.type); }dev_dbg (&tz->device,"Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n" , - trip, trip_type, trip_temp, trend, throttle); + trip_id, trip.type, trip.temperature, trend, throttle);list_for_each_entry (instance, &tz->thermal_instances, tz_node) { -if (instance->trip != trip) +if (instance->trip != trip_id)continue ; old_target = instance->target;
@@ -132,11 +130,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)/* Activate a passive thermal instance */ if (old_target ==THERMAL_NO_TARGET && instance->target !=THERMAL_NO_TARGET ) -update_passive_instance (tz, trip_type,1 ); +update_passive_instance (tz, trip.type,1 );/* Deactivate a passive thermal instance */ else if (old_target !=THERMAL_NO_TARGET && instance->target ==THERMAL_NO_TARGET ) -update_passive_instance (tz, trip_type,-1 ); +update_passive_instance (tz, trip.type,-1 ); instance->initialized = true;mutex_lock (&instance->cdev->lock);
PATCH v8 5/29 thermal/of: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
The thermal OF code uses the thermal_zone_device_register_with_trips() function. It builds the trips array and pass it to the register function. That means the get_trip_* ops are duplicated with what does already the core code.
Remove them.
--- drivers/thermal/thermal_of.c | 36 ------------------------------------ 1 file changed, 36 deletions(-)
drivers/thermal/thermal_of.c +0 -36
@@ -71,39 +71,6 @@ of_thermal_get_trip_points(struct thermal_zone_device *tz) }EXPORT_SYMBOL_GPL (of_thermal_get_trip_points); -static int of_thermal_get_trip_type (struct thermal_zone_device *tz,int trip, -enum thermal_trip_type *type) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *type = tz->trips[trip].type; - -return 0 ; -} - -static int of_thermal_get_trip_temp (struct thermal_zone_device *tz,int trip, -int *temp) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *temp = tz->trips[trip].temperature; - -return 0 ; -} - -static int of_thermal_get_trip_hyst (struct thermal_zone_device *tz,int trip, -int *hyst) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *hyst = tz->trips[trip].hysteresis; - -return 0 ; -} -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
@@ -626,9 +593,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->get_trip_type = of_ops->get_trip_type ? : of_thermal_get_trip_type; - of_ops->get_trip_temp = of_ops->get_trip_temp ? : of_thermal_get_trip_temp; - of_ops->get_trip_hyst = of_ops->get_trip_hyst ? : of_thermal_get_trip_hyst; of_ops->set_trip_hyst = of_ops->set_trip_hyst ? : of_thermal_set_trip_hyst; of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/of: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 2df03b0ea88d284cb43c18da26117a5866951b9f Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//2df03b0ea88d284cb43c18da26117a5866951b9f Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:38 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: 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.
The thermal OF code uses the thermal_zone_device_register_with_trips() function. It builds the trips array and pass it to the register function. That means the get_trip_* ops are duplicated with what does already the core code.
Remove them.
--- drivers/thermal/thermal_of.c | 36 +----------------------------------- 1 file changed, 36 deletions(-)
drivers/thermal/thermal_of.c +0 -36
@@ -71,39 +71,6 @@ of_thermal_get_trip_points(struct thermal_zone_device *tz) }EXPORT_SYMBOL_GPL (of_thermal_get_trip_points); -static int of_thermal_get_trip_type (struct thermal_zone_device *tz,int trip, -enum thermal_trip_type *type) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *type = tz->trips[trip].type; - -return 0 ; -} - -static int of_thermal_get_trip_temp (struct thermal_zone_device *tz,int trip, -int *temp) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *temp = tz->trips[trip].temperature; - -return 0 ; -} - -static int of_thermal_get_trip_hyst (struct thermal_zone_device *tz,int trip, -int *hyst) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - - *hyst = tz->trips[trip].hysteresis; - -return 0 ; -} -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
@@ -626,9 +593,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->get_trip_type = of_ops->get_trip_type ? : of_thermal_get_trip_type; - of_ops->get_trip_temp = of_ops->get_trip_temp ? : of_thermal_get_trip_temp; - of_ops->get_trip_hyst = of_ops->get_trip_hyst ? : of_thermal_get_trip_hyst; of_ops->set_trip_hyst = of_ops->set_trip_hyst ? : of_thermal_set_trip_hyst; of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind;
PATCH v8 6/29 thermal/of: Remove unused functions
In reply to Daniel LezcanoRemove the dead code: of_thermal_get_trip_points()
--- drivers/thermal/thermal_core.h | 7 ------- drivers/thermal/thermal_of.c | 17 ----------------- 2 files changed, 24 deletions(-)
drivers/thermal/thermal_core.h +0 -7
@@ -141,8 +141,6 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,#ifdef CONFIG_THERMAL_OF int of_thermal_get_ntrips (struct thermal_zone_device *);bool of_thermal_is_trip_valid (struct thermal_zone_device *,int ); -const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *);#else static inline int of_thermal_get_ntrips (struct thermal_zone_device *tz) {
@@ -153,11 +151,6 @@ static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, {return false; } -static inline const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *tz) -{ -return NULL ; -}#endif int thermal_zone_device_is_enabled (struct thermal_zone_device *tz);
drivers/thermal/thermal_of.c +0 -17
@@ -54,23 +54,6 @@ bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip) }EXPORT_SYMBOL_GPL (of_thermal_is_trip_valid); -/** -* of_thermal_get_trip_points - function to get access to a globally exported -* trip points -* -* @tz: pointer to a thermal zone -* -* This function provides a pointer to trip points table -* -* Return: pointer to trip points table, NULL otherwise -*/ -const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *tz) -{ -return tz->trips; -} -EXPORT_SYMBOL_GPL (of_thermal_get_trip_points); -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/of: Remove unused functions
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: a2288791cb52b34a2bd1fe9ddd6879d54a87005b Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a2288791cb52b34a2bd1fe9ddd6879d54a87005b Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:39 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: Remove unused functions
Remove the dead code: of_thermal_get_trip_points()
--- drivers/thermal/thermal_core.h | 7 ------- drivers/thermal/thermal_of.c | 17 ----------------- 2 files changed, 24 deletions(-)
drivers/thermal/thermal_core.h +0 -7
@@ -142,8 +142,6 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,#ifdef CONFIG_THERMAL_OF int of_thermal_get_ntrips (struct thermal_zone_device *);bool of_thermal_is_trip_valid (struct thermal_zone_device *,int ); -const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *);#else static inline int of_thermal_get_ntrips (struct thermal_zone_device *tz) {
@@ -154,11 +152,6 @@ static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, {return false; } -static inline const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *tz) -{ -return NULL ; -}#endif int thermal_zone_device_is_enabled (struct thermal_zone_device *tz);
drivers/thermal/thermal_of.c +0 -17
@@ -54,23 +54,6 @@ bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip) }EXPORT_SYMBOL_GPL (of_thermal_is_trip_valid); -/** -* of_thermal_get_trip_points - function to get access to a globally exported -* trip points -* -* @tz: pointer to a thermal zone -* -* This function provides a pointer to trip points table -* -* Return: pointer to trip points table, NULL otherwise -*/ -const struct thermal_trip * -of_thermal_get_trip_points (struct thermal_zone_device *tz) -{ -return tz->trips; -} -EXPORT_SYMBOL_GPL (of_thermal_get_trip_points); -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
PATCH v8 7/29 thermal/drivers/exynos: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/samsung/exynos_tmu.c | 41 +++++++++++----------------- 1 file changed, 16 insertions(+), 25 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +16 -25
@@ -260,16 +260,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tzd = data->tzd; -const struct thermal_trip *const trips = -of_thermal_get_trip_points (tzd);unsigned int status; -int ret =0 , temp, hyst; - -if (!trips) { -dev_err (&pdev->dev, -"Cannot get trip points from device tree!\n" ); -return -ENODEV ; - } +int ret =0 , temp;if (data->soc !=SOC_ARCH_EXYNOS5433 )/* FIXME */ ret = tzd->ops->get_crit_temp (tzd, &temp);
@@ -303,19 +295,16 @@ static int exynos_tmu_initialize(struct platform_device *pdev)/* Write temperature code for rising and falling threshold */ for (i =0 ; i < ntrips; i++) { -/* Write temperature code for rising threshold */ - ret = tzd->ops->get_trip_temp (tzd, i, &temp); -if (ret) - goto err; - temp /=MCELSIUS ; - data->tmu_set_trip_temp (data, i, temp); -/* Write temperature code for falling threshold */ - ret = tzd->ops->get_trip_hyst (tzd, i, &hyst); +struct thermal_trip trip; + + ret =thermal_zone_get_trip (tzd, i, &trip);if (ret) goto err; - hyst /=MCELSIUS ; - data->tmu_set_trip_hyst (data, i, temp, hyst); + + data->tmu_set_trip_temp (data, i, trip.temperature /MCELSIUS ); + data->tmu_set_trip_hyst (data, i, trip.temperature /MCELSIUS , + trip.hysteresis /MCELSIUS ); } data->tmu_clear_irqs (data);
@@ -360,21 +349,23 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on) }static void exynos4210_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip,u8 temp) +int trip_id,u8 temp) { -const struct thermal_trip *const trips = -of_thermal_get_trip_points (data->tzd); +struct thermal_trip trip;u8 ref, th_code; - ref = trips[0 ].temperature /MCELSIUS ; +if (thermal_zone_get_trip (data->tzd,0 , &trip)) +return ; -if (trip ==0 ) { + ref = trip.temperature /MCELSIUS ; + +if (trip_id ==0 ) { th_code =temp_to_code (data, ref);writeb (th_code, data->base +EXYNOS4210_TMU_REG_THRESHOLD_TEMP ); } temp -= ref; -writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip *4 ); +writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id *4 ); }/* failing thresholds are not supported on Exynos4210 */
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/exynos: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 169865e317f29456c1f7d58dddb6122e1aefbeee Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//169865e317f29456c1f7d58dddb6122e1aefbeee Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:40 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/exynos: 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.
--- drivers/thermal/samsung/exynos_tmu.c | 41 ++++++++++----------------- 1 file changed, 16 insertions(+), 25 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +16 -25
@@ -260,16 +260,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tzd = data->tzd; -const struct thermal_trip *const trips = -of_thermal_get_trip_points (tzd);unsigned int status; -int ret =0 , temp, hyst; - -if (!trips) { -dev_err (&pdev->dev, -"Cannot get trip points from device tree!\n" ); -return -ENODEV ; - } +int ret =0 , temp;if (data->soc !=SOC_ARCH_EXYNOS5433 )/* FIXME */ ret = tzd->ops->get_crit_temp (tzd, &temp);
@@ -303,19 +295,16 @@ static int exynos_tmu_initialize(struct platform_device *pdev)/* Write temperature code for rising and falling threshold */ for (i =0 ; i < ntrips; i++) { -/* Write temperature code for rising threshold */ - ret = tzd->ops->get_trip_temp (tzd, i, &temp); -if (ret) - goto err; - temp /=MCELSIUS ; - data->tmu_set_trip_temp (data, i, temp); -/* Write temperature code for falling threshold */ - ret = tzd->ops->get_trip_hyst (tzd, i, &hyst); +struct thermal_trip trip; + + ret =thermal_zone_get_trip (tzd, i, &trip);if (ret) goto err; - hyst /=MCELSIUS ; - data->tmu_set_trip_hyst (data, i, temp, hyst); + + data->tmu_set_trip_temp (data, i, trip.temperature /MCELSIUS ); + data->tmu_set_trip_hyst (data, i, trip.temperature /MCELSIUS , + trip.hysteresis /MCELSIUS ); } data->tmu_clear_irqs (data);
@@ -360,21 +349,23 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on) }static void exynos4210_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip,u8 temp) +int trip_id,u8 temp) { -const struct thermal_trip *const trips = -of_thermal_get_trip_points (data->tzd); +struct thermal_trip trip;u8 ref, th_code; - ref = trips[0 ].temperature /MCELSIUS ; +if (thermal_zone_get_trip (data->tzd,0 , &trip)) +return ; + + ref = trip.temperature /MCELSIUS ; -if (trip ==0 ) { +if (trip_id ==0 ) { th_code =temp_to_code (data, ref);writeb (th_code, data->base +EXYNOS4210_TMU_REG_THRESHOLD_TEMP ); } temp -= ref; -writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip *4 ); +writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id *4 ); }/* failing thresholds are not supported on Exynos4210 */
PATCH v8 8/29 thermal/drivers/exynos: of_thermal_get_ntrips()
In reply to Daniel LezcanoThe thermal core framework allows to get the number of thermal trips, use it instead of visiting the thermal core structure internals.
--- drivers/thermal/samsung/exynos_tmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +4 -3
@@ -260,6 +260,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tzd = data->tzd; +int num_trips =thermal_zone_get_num_trips (tzd);unsigned int status;int ret =0 , temp;
@@ -271,12 +272,12 @@ static int exynos_tmu_initialize(struct platform_device *pdev) goto out; } -if (of_thermal_get_ntrips (tzd) > data->ntrip) { +if (num_trips > data->ntrip) {dev_info (&pdev->dev,"More trip points than supported by this TMU.\n" );dev_info (&pdev->dev,"%d trip points should be configured in polling mode.\n" , - (of_thermal_get_ntrips (tzd) - data->ntrip)); + num_trips - data->ntrip); }mutex_lock (&data->lock);
@@ -289,7 +290,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev) ret = -EBUSY ; }else {int i, ntrips = -min_t (int,of_thermal_get_ntrips (tzd), data->ntrip); +min_t (int, num_trips, data->ntrip); data->tmu_initialize (pdev);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/exynos: of_thermal_get_ntrips()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 27998c5baa70da4e5a2ff85505b2e3bd0abf74d6 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//27998c5baa70da4e5a2ff85505b2e3bd0abf74d6 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:41 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/exynos: of_thermal_get_ntrips()
The thermal core framework allows to get the number of thermal trips, use it instead of visiting the thermal core structure internals.
--- drivers/thermal/samsung/exynos_tmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +4 -3
@@ -260,6 +260,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tzd = data->tzd; +int num_trips =thermal_zone_get_num_trips (tzd);unsigned int status;int ret =0 , temp;
@@ -271,12 +272,12 @@ static int exynos_tmu_initialize(struct platform_device *pdev) goto out; } -if (of_thermal_get_ntrips (tzd) > data->ntrip) { +if (num_trips > data->ntrip) {dev_info (&pdev->dev,"More trip points than supported by this TMU.\n" );dev_info (&pdev->dev,"%d trip points should be configured in polling mode.\n" , - (of_thermal_get_ntrips (tzd) - data->ntrip)); + num_trips - data->ntrip); }mutex_lock (&data->lock);
@@ -289,7 +290,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev) ret = -EBUSY ; }else {int i, ntrips = -min_t (int,of_thermal_get_ntrips (tzd), data->ntrip); +min_t (int, num_trips, data->ntrip); data->tmu_initialize (pdev);
PATCH v8 9/29 thermal/drivers/exynos: Replace of_thermal_is_trip_valid() by thermal_zone_get_trip()
In reply to Daniel LezcanoThe thermal_zone_get_trip() does the same check as of_thermal_is_trip_valid(). Replace the call to of_thermal_is_trip_valid() by thermal_zone_get_trip().
--- drivers/thermal/samsung/exynos_tmu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +6 -3
@@ -554,13 +554,14 @@ static void exynos4210_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
@@ -584,13 +585,14 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , pd_det_en, i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
@@ -615,13 +617,14 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/exynos: Replace of_thermal_is_trip_valid() by thermal_zone_get_trip()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 41bbeae4762e260b1fdfe8d761f2476b364e4013 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//41bbeae4762e260b1fdfe8d761f2476b364e4013 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:42 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/exynos: Replace of_thermal_is_trip_valid() by thermal_zone_get_trip()
The thermal_zone_get_trip() does the same check as of_thermal_is_trip_valid(). Replace the call to of_thermal_is_trip_valid() by thermal_zone_get_trip().
--- drivers/thermal/samsung/exynos_tmu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +6 -3
@@ -554,13 +554,14 @@ static void exynos4210_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
@@ -584,13 +585,14 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , pd_det_en, i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
@@ -615,13 +617,14 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tz = data->tzd; +struct thermal_trip trip;unsigned int con, interrupt_en =0 , i; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) {for (i =0 ; i < data->ntrip; i++) { -if (!of_thermal_is_trip_valid (tz, i)) +if (thermal_zone_get_trip (tz, i, &trip))continue ; interrupt_en |=
PATCH v8 10/29 thermal/drivers/tegra: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoReplace a single call to thermal_zone_get_trip() to get a trip point instead of calling the different ops->get_trip*
--- drivers/thermal/tegra/soctherm.c | 33 +++++++++++-------------- drivers/thermal/tegra/tegra30-tsensor.c | 17 ++++++------- 2 files changed, 22 insertions(+), 28 deletions(-)
drivers/thermal/tegra/soctherm.c +14 -19
@@ -582,23 +582,23 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)return temp; } -static int tegra_thermctl_set_trip_temp (struct thermal_zone_device *tz,int trip,int temp) +static int tegra_thermctl_set_trip_temp (struct thermal_zone_device *tz,int trip_id,int temp) {struct tegra_thermctl_zone *zone = tz->devdata;struct tegra_soctherm *ts = zone->ts; +struct thermal_trip trip;const struct tegra_tsensor_group *sg = zone->sg;struct device *dev = zone->dev; -enum thermal_trip_type type;int ret;if (!tz)return -EINVAL ; - ret = tz->ops->get_trip_type (tz, trip, &type); + ret =thermal_zone_get_trip (tz, trip_id, &trip);if (ret)return ret; -if (type ==THERMAL_TRIP_CRITICAL ) { +if (trip.type ==THERMAL_TRIP_CRITICAL ) {/* * If thermtrips property is set in DT, * doesn't need to program critical type trip to HW,
@@ -609,7 +609,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int tripelse return 0 ; - }else if (type ==THERMAL_TRIP_HOT ) { + }else if (trip.type ==THERMAL_TRIP_HOT ) {int i;for (i =0 ; i <THROTTLE_SIZE ; i++) {
@@ -620,7 +620,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int tripcontinue ; cdev = ts->throt_cfgs[i].cdev; -if (get_thermal_instance (tz, cdev, trip)) +if (get_thermal_instance (tz, cdev, trip_id)) stc =find_throttle_cfg_by_name (ts, cdev->type);else continue ;
@@ -687,25 +687,20 @@ static const struct thermal_zone_device_ops tegra_of_thermal_ops = { .set_trips = tegra_thermctl_set_trips, }; -static int get_hot_temp (struct thermal_zone_device *tz,int *trip,int *temp) +static int get_hot_temp (struct thermal_zone_device *tz,int *trip_id,int *temp) { -int ntrips, i, ret; -enum thermal_trip_type type; +int i, ret; +struct thermal_trip trip; - ntrips =of_thermal_get_ntrips (tz); -if (ntrips <=0 ) -return -EINVAL ; +for (i =0 ; i <thermal_zone_get_num_trips (tz); i++) { -for (i =0 ; i < ntrips; i++) { - ret = tz->ops->get_trip_type (tz, i, &type); + ret =thermal_zone_get_trip (tz, i, &trip);if (ret)return -EINVAL ; -if (type ==THERMAL_TRIP_HOT ) { - ret = tz->ops->get_trip_temp (tz, i, temp); -if (!ret) - *trip = i; -return ret; +if (trip.type ==THERMAL_TRIP_HOT ) { + *trip_id = i; +return 0 ; } }
drivers/thermal/tegra/tegra30-tsensor.c +8 -9
@@ -316,18 +316,17 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, *hot_trip =85000 ; *crit_trip =90000 ; -for (i =0 ; i < tzd->num_trips; i++) { -enum thermal_trip_type type; -int trip_temp; +for (i =0 ; i <thermal_zone_get_num_trips (tzd); i++) { - tzd->ops->get_trip_temp (tzd, i, &trip_temp); - tzd->ops->get_trip_type (tzd, i, &type); +struct thermal_trip trip; -if (type ==THERMAL_TRIP_HOT ) - *hot_trip = trip_temp; +thermal_zone_get_trip (tzd, i, &trip); + +if (trip.type ==THERMAL_TRIP_HOT ) + *hot_trip = trip.temperature; -if (type ==THERMAL_TRIP_CRITICAL ) - *crit_trip = trip_temp; +if (trip.type ==THERMAL_TRIP_CRITICAL ) + *crit_trip = trip.temperature; }/* clamp hardware trips to the calibration limits */
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/tegra: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 56d7b397cc2993d8bee6d6ea41032989e168a695 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//56d7b397cc2993d8bee6d6ea41032989e168a695 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:43 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/tegra: Use generic thermal_zone_get_trip() function
Replace a single call to thermal_zone_get_trip() to get a trip point instead of calling the different ops->get_trip*
--- drivers/thermal/tegra/soctherm.c | 33 ++++++++++-------------- drivers/thermal/tegra/tegra30-tsensor.c | 17 +++++------- 2 files changed, 22 insertions(+), 28 deletions(-)
drivers/thermal/tegra/soctherm.c +14 -19
@@ -582,23 +582,23 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)return temp; } -static int tegra_thermctl_set_trip_temp (struct thermal_zone_device *tz,int trip,int temp) +static int tegra_thermctl_set_trip_temp (struct thermal_zone_device *tz,int trip_id,int temp) {struct tegra_thermctl_zone *zone = tz->devdata;struct tegra_soctherm *ts = zone->ts; +struct thermal_trip trip;const struct tegra_tsensor_group *sg = zone->sg;struct device *dev = zone->dev; -enum thermal_trip_type type;int ret;if (!tz)return -EINVAL ; - ret = tz->ops->get_trip_type (tz, trip, &type); + ret =thermal_zone_get_trip (tz, trip_id, &trip);if (ret)return ret; -if (type ==THERMAL_TRIP_CRITICAL ) { +if (trip.type ==THERMAL_TRIP_CRITICAL ) {/* * If thermtrips property is set in DT, * doesn't need to program critical type trip to HW,
@@ -609,7 +609,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int tripelse return 0 ; - }else if (type ==THERMAL_TRIP_HOT ) { + }else if (trip.type ==THERMAL_TRIP_HOT ) {int i;for (i =0 ; i <THROTTLE_SIZE ; i++) {
@@ -620,7 +620,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int tripcontinue ; cdev = ts->throt_cfgs[i].cdev; -if (get_thermal_instance (tz, cdev, trip)) +if (get_thermal_instance (tz, cdev, trip_id)) stc =find_throttle_cfg_by_name (ts, cdev->type);else continue ;
@@ -687,25 +687,20 @@ static const struct thermal_zone_device_ops tegra_of_thermal_ops = { .set_trips = tegra_thermctl_set_trips, }; -static int get_hot_temp (struct thermal_zone_device *tz,int *trip,int *temp) +static int get_hot_temp (struct thermal_zone_device *tz,int *trip_id,int *temp) { -int ntrips, i, ret; -enum thermal_trip_type type; +int i, ret; +struct thermal_trip trip; - ntrips =of_thermal_get_ntrips (tz); -if (ntrips <=0 ) -return -EINVAL ; +for (i =0 ; i <thermal_zone_get_num_trips (tz); i++) { -for (i =0 ; i < ntrips; i++) { - ret = tz->ops->get_trip_type (tz, i, &type); + ret =thermal_zone_get_trip (tz, i, &trip);if (ret)return -EINVAL ; -if (type ==THERMAL_TRIP_HOT ) { - ret = tz->ops->get_trip_temp (tz, i, temp); -if (!ret) - *trip = i; -return ret; +if (trip.type ==THERMAL_TRIP_HOT ) { + *trip_id = i; +return 0 ; } }
drivers/thermal/tegra/tegra30-tsensor.c +8 -9
@@ -316,18 +316,17 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, *hot_trip =85000 ; *crit_trip =90000 ; -for (i =0 ; i < tzd->num_trips; i++) { -enum thermal_trip_type type; -int trip_temp; +for (i =0 ; i <thermal_zone_get_num_trips (tzd); i++) { - tzd->ops->get_trip_temp (tzd, i, &trip_temp); - tzd->ops->get_trip_type (tzd, i, &type); +struct thermal_trip trip; -if (type ==THERMAL_TRIP_HOT ) - *hot_trip = trip_temp; +thermal_zone_get_trip (tzd, i, &trip); -if (type ==THERMAL_TRIP_CRITICAL ) - *crit_trip = trip_temp; +if (trip.type ==THERMAL_TRIP_HOT ) + *hot_trip = trip.temperature; + +if (trip.type ==THERMAL_TRIP_CRITICAL ) + *crit_trip = trip.temperature; }/* clamp hardware trips to the calibration limits */
PATCH v8 11/29 thermal/drivers/uniphier: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/uniphier_thermal.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/thermal/uniphier_thermal.c +12 -15
@@ -248,8 +248,7 @@ static int uniphier_tm_probe(struct platform_device *pdev)struct regmap *regmap;struct device_node *parent;struct uniphier_tm_dev *tdev; -const struct thermal_trip *trips; -int i, ret, irq, ntrips, crit_temp =INT_MAX ; +int i, ret, irq, crit_temp =INT_MAX ; tdev =devm_kzalloc (dev,sizeof (*tdev),GFP_KERNEL );if (!tdev)
@@ -296,20 +295,18 @@ static int uniphier_tm_probe(struct platform_device *pdev)return PTR_ERR (tdev->tz_dev); } -/* get trip points */ - trips =of_thermal_get_trip_points (tdev->tz_dev); - ntrips =of_thermal_get_ntrips (tdev->tz_dev); -if (ntrips >ALERT_CH_NUM ) { -dev_err (dev,"thermal zone has too many trips\n" ); -return -E2BIG ; - } -/* set alert temperatures */ -for (i =0 ; i < ntrips; i++) { -if (trips[i].type ==THERMAL_TRIP_CRITICAL && - trips[i].temperature < crit_temp) - crit_temp = trips[i].temperature; -uniphier_tm_set_alert (tdev, i, trips[i].temperature); +for (i =0 ; i <thermal_zone_get_num_trips (tdev->tz_dev); i++) { +struct thermal_trip trip; + + ret =thermal_zone_get_trip (tdev->tz_dev, i, &trip); +if (ret) +return ret; + +if (trip.type ==THERMAL_TRIP_CRITICAL && + trip.temperature < crit_temp) + crit_temp = trip.temperature; +uniphier_tm_set_alert (tdev, i, trip.temperature); tdev->alert_en[i] = true; }if (crit_temp >CRITICAL_TEMP_LIMIT ) {
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/uniphier: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: e6f4c0a03fe1a3bdd8b3f48c91d8f8d42fd8dd6e Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//e6f4c0a03fe1a3bdd8b3f48c91d8f8d42fd8dd6e Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:44 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/uniphier: 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.
--- drivers/thermal/uniphier_thermal.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/thermal/uniphier_thermal.c +12 -15
@@ -248,8 +248,7 @@ static int uniphier_tm_probe(struct platform_device *pdev)struct regmap *regmap;struct device_node *parent;struct uniphier_tm_dev *tdev; -const struct thermal_trip *trips; -int i, ret, irq, ntrips, crit_temp =INT_MAX ; +int i, ret, irq, crit_temp =INT_MAX ; tdev =devm_kzalloc (dev,sizeof (*tdev),GFP_KERNEL );if (!tdev)
@@ -296,20 +295,18 @@ static int uniphier_tm_probe(struct platform_device *pdev)return PTR_ERR (tdev->tz_dev); } -/* get trip points */ - trips =of_thermal_get_trip_points (tdev->tz_dev); - ntrips =of_thermal_get_ntrips (tdev->tz_dev); -if (ntrips >ALERT_CH_NUM ) { -dev_err (dev,"thermal zone has too many trips\n" ); -return -E2BIG ; - } -/* set alert temperatures */ -for (i =0 ; i < ntrips; i++) { -if (trips[i].type ==THERMAL_TRIP_CRITICAL && - trips[i].temperature < crit_temp) - crit_temp = trips[i].temperature; -uniphier_tm_set_alert (tdev, i, trips[i].temperature); +for (i =0 ; i <thermal_zone_get_num_trips (tdev->tz_dev); i++) { +struct thermal_trip trip; + + ret =thermal_zone_get_trip (tdev->tz_dev, i, &trip); +if (ret) +return ret; + +if (trip.type ==THERMAL_TRIP_CRITICAL && + trip.temperature < crit_temp) + crit_temp = trip.temperature; +uniphier_tm_set_alert (tdev, i, trip.temperature); tdev->alert_en[i] = true; }if (crit_temp >CRITICAL_TEMP_LIMIT ) {
PATCH v8 12/29 thermal/drivers/hisi: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/hisi_thermal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/thermal/hisi_thermal.c +6 -5
@@ -482,7 +482,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, struct hisi_thermal_sensor *sensor) {int ret, i; -const struct thermal_trip *trip; +struct thermal_trip trip; sensor->tzd = devm_thermal_of_zone_register(&pdev->dev, sensor->id, sensor,
@@ -495,11 +495,12 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,return ret; } - trip =of_thermal_get_trip_points (sensor->tzd); +for (i =0 ; i <thermal_zone_get_num_trips (sensor->tzd); i++) { -for (i =0 ; i <of_thermal_get_ntrips (sensor->tzd); i++) { -if (trip[i].type ==THERMAL_TRIP_PASSIVE ) { - sensor->thres_temp = trip[i].temperature; +thermal_zone_get_trip (sensor->tzd, i, &trip); + +if (trip.type ==THERMAL_TRIP_PASSIVE ) { + sensor->thres_temp = trip.temperature;break ; } }
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/hisi: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 14d5b7d3d338cc90f5d40c6059cc5080f392dd51 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//14d5b7d3d338cc90f5d40c6059cc5080f392dd51 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:45 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/hisi: 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.
--- drivers/thermal/hisi_thermal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/thermal/hisi_thermal.c +6 -5
@@ -482,7 +482,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, struct hisi_thermal_sensor *sensor) {int ret, i; -const struct thermal_trip *trip; +struct thermal_trip trip; sensor->tzd = devm_thermal_of_zone_register(&pdev->dev, sensor->id, sensor,
@@ -495,11 +495,12 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,return ret; } - trip =of_thermal_get_trip_points (sensor->tzd); +for (i =0 ; i <thermal_zone_get_num_trips (sensor->tzd); i++) { -for (i =0 ; i <of_thermal_get_ntrips (sensor->tzd); i++) { -if (trip[i].type ==THERMAL_TRIP_PASSIVE ) { - sensor->thres_temp = trip[i].temperature; +thermal_zone_get_trip (sensor->tzd, i, &trip); + +if (trip.type ==THERMAL_TRIP_PASSIVE ) { + sensor->thres_temp = trip.temperature;break ; } }
PATCH v8 13/29 thermal/drivers/qcom: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 39 +++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-)
drivers/thermal/qcom/qcom-spmi-temp-alarm.c +17 -22
@@ -263,17 +263,17 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,return qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); } -static int qpnp_tm_set_trip_temp (struct thermal_zone_device *tz,int trip,int temp) +static int qpnp_tm_set_trip_temp (struct thermal_zone_device *tz,int trip_id,int temp) {struct qpnp_tm_chip *chip = tz->devdata; -const struct thermal_trip *trip_points; +struct thermal_trip trip;int ret; - trip_points =of_thermal_get_trip_points (chip->tz_dev); -if (!trip_points) -return -EINVAL ; + ret =thermal_zone_get_trip (chip->tz_dev, trip_id, &trip); +if (ret) +return ret; -if (trip_points[trip].type !=THERMAL_TRIP_CRITICAL ) +if (trip.type !=THERMAL_TRIP_CRITICAL )return 0 ;mutex_lock (&chip->lock);
@@ -299,22 +299,17 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data)static int qpnp_tm_get_critical_trip_temp (struct qpnp_tm_chip *chip) { -int ntrips; -const struct thermal_trip *trips; -int i; - - ntrips =of_thermal_get_ntrips (chip->tz_dev); -if (ntrips <=0 ) -return THERMAL_TEMP_INVALID ; - - trips =of_thermal_get_trip_points (chip->tz_dev); -if (!trips) -return THERMAL_TEMP_INVALID ; - -for (i =0 ; i < ntrips; i++) { -if (of_thermal_is_trip_valid (chip->tz_dev, i) && - trips[i].type ==THERMAL_TRIP_CRITICAL ) -return trips[i].temperature; +struct thermal_trip trip; +int i, ret; + +for (i =0 ; i <thermal_zone_get_num_trips (chip->tz_dev); i++) { + + ret =thermal_zone_get_trip (chip->tz_dev, i, &trip); +if (ret) +continue ; + +if (trip.type ==THERMAL_TRIP_CRITICAL ) +return trip.temperature; }return THERMAL_TEMP_INVALID ;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/qcom: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 78c3e2429be863d4bdbd86c76d86f64c5231d9af Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//78c3e2429be863d4bdbd86c76d86f64c5231d9af Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:46 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/qcom: 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.
--- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 39 ++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-)
drivers/thermal/qcom/qcom-spmi-temp-alarm.c +17 -22
@@ -263,17 +263,17 @@ skip:return qpnp_tm_write (chip,QPNP_TM_REG_SHUTDOWN_CTRL1 , reg); } -static int qpnp_tm_set_trip_temp (struct thermal_zone_device *tz,int trip,int temp) +static int qpnp_tm_set_trip_temp (struct thermal_zone_device *tz,int trip_id,int temp) {struct qpnp_tm_chip *chip = tz->devdata; -const struct thermal_trip *trip_points; +struct thermal_trip trip;int ret; - trip_points =of_thermal_get_trip_points (chip->tz_dev); -if (!trip_points) -return -EINVAL ; + ret =thermal_zone_get_trip (chip->tz_dev, trip_id, &trip); +if (ret) +return ret; -if (trip_points[trip].type !=THERMAL_TRIP_CRITICAL ) +if (trip.type !=THERMAL_TRIP_CRITICAL )return 0 ;mutex_lock (&chip->lock);
@@ -299,22 +299,17 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data)static int qpnp_tm_get_critical_trip_temp (struct qpnp_tm_chip *chip) { -int ntrips; -const struct thermal_trip *trips; -int i; - - ntrips =of_thermal_get_ntrips (chip->tz_dev); -if (ntrips <=0 ) -return THERMAL_TEMP_INVALID ; - - trips =of_thermal_get_trip_points (chip->tz_dev); -if (!trips) -return THERMAL_TEMP_INVALID ; - -for (i =0 ; i < ntrips; i++) { -if (of_thermal_is_trip_valid (chip->tz_dev, i) && - trips[i].type ==THERMAL_TRIP_CRITICAL ) -return trips[i].temperature; +struct thermal_trip trip; +int i, ret; + +for (i =0 ; i <thermal_zone_get_num_trips (chip->tz_dev); i++) { + + ret =thermal_zone_get_trip (chip->tz_dev, i, &trip); +if (ret) +continue ; + +if (trip.type ==THERMAL_TRIP_CRITICAL ) +return trip.temperature; }return THERMAL_TEMP_INVALID ;
PATCH v8 14/29 thermal/drivers/armada: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/armada_thermal.c | 39 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-)
drivers/thermal/armada_thermal.c +20 -19
@@ -785,33 +785,34 @@ static int armada_configure_overheat_int(struct armada_thermal_priv *priv, int sensor_id) {/* Retrieve the critical trip point to enable the overheat interrupt */ -const struct thermal_trip *trips =of_thermal_get_trip_points (tz); +struct thermal_trip trip;int ret;int i; -if (!trips) -return -EINVAL ; - -for (i =0 ; i <of_thermal_get_ntrips (tz); i++) -if (trips[i].type ==THERMAL_TRIP_CRITICAL ) -break ; +for (i =0 ; i <thermal_zone_get_num_trips (tz); i++) { -if (i ==of_thermal_get_ntrips (tz)) -return -EINVAL ; + ret =thermal_zone_get_trip (tz, i, &trip); +if (ret) +return ret; + +if (trip.type !=THERMAL_TRIP_CRITICAL ) +continue ; - ret =armada_select_channel (priv, sensor_id); -if (ret) -return ret; + ret =armada_select_channel (priv, sensor_id); +if (ret) +return ret; + +armada_set_overheat_thresholds (priv, trip.temperature, + trip.hysteresis); + priv->overheat_sensor = tz; + priv->interrupt_source = sensor_id; -armada_set_overheat_thresholds (priv, - trips[i].temperature, - trips[i].hysteresis); - priv->overheat_sensor = tz; - priv->interrupt_source = sensor_id; +armada_enable_overheat_interrupt (priv); -armada_enable_overheat_interrupt (priv); +return 0 ; + } -return 0 ; +return -EINVAL ; }static int armada_thermal_probe (struct platform_device *pdev)
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/armada: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 79162ca505adc1cf8d44474c349e27da9813908d Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//79162ca505adc1cf8d44474c349e27da9813908d Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:47 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/armada: 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.
--- drivers/thermal/armada_thermal.c | 37 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/thermal/armada_thermal.c +19 -18
@@ -785,33 +785,34 @@ static int armada_configure_overheat_int(struct armada_thermal_priv *priv, int sensor_id) {/* Retrieve the critical trip point to enable the overheat interrupt */ -const struct thermal_trip *trips =of_thermal_get_trip_points (tz); +struct thermal_trip trip;int ret;int i; -if (!trips) -return -EINVAL ; +for (i =0 ; i <thermal_zone_get_num_trips (tz); i++) { -for (i =0 ; i <of_thermal_get_ntrips (tz); i++) -if (trips[i].type ==THERMAL_TRIP_CRITICAL ) -break ; + ret =thermal_zone_get_trip (tz, i, &trip); +if (ret) +return ret; -if (i ==of_thermal_get_ntrips (tz)) -return -EINVAL ; +if (trip.type !=THERMAL_TRIP_CRITICAL ) +continue ; - ret =armada_select_channel (priv, sensor_id); -if (ret) -return ret; + ret =armada_select_channel (priv, sensor_id); +if (ret) +return ret; -armada_set_overheat_thresholds (priv, - trips[i].temperature, - trips[i].hysteresis); - priv->overheat_sensor = tz; - priv->interrupt_source = sensor_id; +armada_set_overheat_thresholds (priv, trip.temperature, + trip.hysteresis); + priv->overheat_sensor = tz; + priv->interrupt_source = sensor_id; -armada_enable_overheat_interrupt (priv); +armada_enable_overheat_interrupt (priv); -return 0 ; +return 0 ; + } + +return -EINVAL ; }static int armada_thermal_probe (struct platform_device *pdev)
PATCH v8 15/29 thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
In reply to Daniel LezcanoThe thermal core framework allows to get the number of thermal trips, use it instead of visiting the thermal core structure internals.
--- drivers/thermal/rcar_gen3_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/rcar_gen3_thermal.c +1 -1
@@ -529,7 +529,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)if (ret) goto error_unregister; - ret =of_thermal_get_ntrips (tsc->zone); + ret =thermal_zone_get_num_trips (tsc->zone);if (ret <0 ) goto error_unregister;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 237ee9f6006e793b28e841e08152abfb00ffb33f Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//237ee9f6006e793b28e841e08152abfb00ffb33f Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:48 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
The thermal core framework allows to get the number of thermal trips, use it instead of visiting the thermal core structure internals.
--- drivers/thermal/rcar_gen3_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/rcar_gen3_thermal.c +1 -1
@@ -529,7 +529,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)if (ret) goto error_unregister; - ret =of_thermal_get_ntrips (tsc->zone); + ret =thermal_zone_get_num_trips (tsc->zone);if (ret <0 ) goto error_unregister;
PATCH v8 16/29 thermal/of: Remove of_thermal_get_ntrips()
In reply to Daniel LezcanoThe thermal OF code uses the generic trip points to initialize the thermal zone. Consequently thermal_zone_get_num_trips() can be used and the of_thermal_get_ntrips() is no longer needed. Remove it.
--- drivers/thermal/thermal_core.h | 5 ----- drivers/thermal/thermal_of.c | 16 ---------------- 2 files changed, 21 deletions(-)
drivers/thermal/thermal_core.h +0 -5
@@ -139,13 +139,8 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,/* device tree support */ #ifdef CONFIG_THERMAL_OF -int of_thermal_get_ntrips (struct thermal_zone_device *);bool of_thermal_is_trip_valid (struct thermal_zone_device *,int );#else -static inline int of_thermal_get_ntrips (struct thermal_zone_device *tz) -{ -return 0 ; -}static inline bool of_thermal_is_trip_valid (struct thermal_zone_device *tz,int trip) {
drivers/thermal/thermal_of.c +0 -16
@@ -19,22 +19,6 @@#include "thermal_core.h" -/** -* of_thermal_get_ntrips - function to export number of available trip -* points. -* @tz: pointer to a thermal zone -* -* This function is a globally visible wrapper to get number of trip points -* stored in the local struct __thermal_zone -* -* Return: number of available trip points, -ENODEV when data not available -*/ -int of_thermal_get_ntrips (struct thermal_zone_device *tz) -{ -return tz->num_trips; -} -EXPORT_SYMBOL_GPL (of_thermal_get_ntrips); -/** * of_thermal_is_trip_valid - function to check if trip point is valid *
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/of: Remove of_thermal_get_ntrips()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: a16eb9df9322755d7222a51b244e93357560a66a Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a16eb9df9322755d7222a51b244e93357560a66a Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:49 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: Remove of_thermal_get_ntrips()
The thermal OF code uses the generic trip points to initialize the thermal zone. Consequently thermal_zone_get_num_trips() can be used and the of_thermal_get_ntrips() is no longer needed. Remove it.
--- drivers/thermal/thermal_core.h | 5 ----- drivers/thermal/thermal_of.c | 16 ---------------- 2 files changed, 21 deletions(-)
drivers/thermal/thermal_core.h +0 -5
@@ -140,13 +140,8 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,/* device tree support */ #ifdef CONFIG_THERMAL_OF -int of_thermal_get_ntrips (struct thermal_zone_device *);bool of_thermal_is_trip_valid (struct thermal_zone_device *,int );#else -static inline int of_thermal_get_ntrips (struct thermal_zone_device *tz) -{ -return 0 ; -}static inline bool of_thermal_is_trip_valid (struct thermal_zone_device *tz,int trip) {
drivers/thermal/thermal_of.c +0 -16
@@ -20,22 +20,6 @@#include "thermal_core.h" /** -* of_thermal_get_ntrips - function to export number of available trip -* points. -* @tz: pointer to a thermal zone -* -* This function is a globally visible wrapper to get number of trip points -* stored in the local struct __thermal_zone -* -* Return: number of available trip points, -ENODEV when data not available -*/ -int of_thermal_get_ntrips (struct thermal_zone_device *tz) -{ -return tz->num_trips; -} -EXPORT_SYMBOL_GPL (of_thermal_get_ntrips); - -/** * of_thermal_is_trip_valid - function to check if trip point is valid * * @tz: pointer to a thermal zone
PATCH v8 17/29 thermal/of: Remove of_thermal_is_trip_valid()
In reply to Daniel LezcanoThere is no benefit with the of_thermal_is_trip_valid() function as it does the check the thermal_zone_get_trip() is already doing for the sake of getting the trip point.
As all the calls have been replaced by thermal_zone_get_trip(), there is no more users of of_thermal_is_trip_valid().
Remove the function.
--- drivers/thermal/thermal_core.h | 10 ---------- drivers/thermal/thermal_of.c | 19 ------------------- 2 files changed, 29 deletions(-)
drivers/thermal/thermal_core.h +0 -10
@@ -138,16 +138,6 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,#endif /* CONFIG_THERMAL_STATISTICS */ /* device tree support */ -#ifdef CONFIG_THERMAL_OF -bool of_thermal_is_trip_valid (struct thermal_zone_device *,int ); -#else -static inline bool of_thermal_is_trip_valid (struct thermal_zone_device *tz, -int trip) -{ -return false; -} -#endif -int thermal_zone_device_is_enabled (struct thermal_zone_device *tz);#endif /* __THERMAL_CORE_H__ */
drivers/thermal/thermal_of.c +0 -19
@@ -19,25 +19,6 @@#include "thermal_core.h" -/** -* of_thermal_is_trip_valid - function to check if trip point is valid -* -* @tz: pointer to a thermal zone -* @trip: trip point to evaluate -* -* This function is responsible for checking if passed trip point is valid -* -* Return: true if trip point is valid, false otherwise -*/ -bool of_thermal_is_trip_valid (struct thermal_zone_device *tz,int trip) -{ -if (trip >= tz->num_trips || trip <0 ) -return false; - -return true; -} -EXPORT_SYMBOL_GPL (of_thermal_is_trip_valid); -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/of: Remove of_thermal_is_trip_valid()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 4432917b34e8a2a4cbea64684e9c8b175ba37290 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//4432917b34e8a2a4cbea64684e9c8b175ba37290 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:50 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: Remove of_thermal_is_trip_valid()
There is no benefit with the of_thermal_is_trip_valid() function as it does the check the thermal_zone_get_trip() is already doing for the sake of getting the trip point.
As all the calls have been replaced by thermal_zone_get_trip(), there is no more users of of_thermal_is_trip_valid().
Remove the function.
--- drivers/thermal/thermal_core.h | 10 ---------- drivers/thermal/thermal_of.c | 19 ------------------- 2 files changed, 29 deletions(-)
drivers/thermal/thermal_core.h +0 -10
@@ -139,16 +139,6 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,#endif /* CONFIG_THERMAL_STATISTICS */ /* device tree support */ -#ifdef CONFIG_THERMAL_OF -bool of_thermal_is_trip_valid (struct thermal_zone_device *,int ); -#else -static inline bool of_thermal_is_trip_valid (struct thermal_zone_device *tz, -int trip) -{ -return false; -} -#endif -int thermal_zone_device_is_enabled (struct thermal_zone_device *tz);#endif /* __THERMAL_CORE_H__ */
drivers/thermal/thermal_of.c +0 -19
@@ -19,25 +19,6 @@#include "thermal_core.h" -/** -* of_thermal_is_trip_valid - function to check if trip point is valid -* -* @tz: pointer to a thermal zone -* @trip: trip point to evaluate -* -* This function is responsible for checking if passed trip point is valid -* -* Return: true if trip point is valid, false otherwise -*/ -bool of_thermal_is_trip_valid (struct thermal_zone_device *tz,int trip) -{ -if (trip >= tz->num_trips || trip <0 ) -return false; - -return true; -} -EXPORT_SYMBOL_GPL (of_thermal_is_trip_valid); -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip,int hyst) {
PATCH v8 18/29 thermal/of: Remove of_thermal_set_trip_hyst()
In reply to Daniel LezcanoThe thermal core is providing the generic thermal_zone_set_trip() function which does exactly what the OF ops function is doing.
It is pointless to define our own version, just remove the ops and the thermal_zone_set_trip() will take care of it.
--- drivers/thermal/thermal_of.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/thermal/thermal_of.c +0 -13
@@ -19,18 +19,6 @@#include "thermal_core.h" -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip, -int hyst) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - -/* thermal framework should take care of data->mask & (1 << trip) */ - tz->trips[trip].hysteresis = hyst; - -return 0 ; -} -static int of_thermal_get_crit_temp (struct thermal_zone_device *tz,int *temp) {
@@ -541,7 +529,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->set_trip_hyst = of_ops->set_trip_hyst ? : of_thermal_set_trip_hyst; of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind; of_ops->unbind = thermal_of_unbind;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/of: Remove of_thermal_set_trip_hyst()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: f00295bf50b581ecda6fad24dd8d713c2158e5da Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//f00295bf50b581ecda6fad24dd8d713c2158e5da Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:51 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: Remove of_thermal_set_trip_hyst()
The thermal core is providing the generic thermal_zone_set_trip() function which does exactly what the OF ops function is doing.
It is pointless to define our own version, just remove the ops and the thermal_zone_set_trip() will take care of it.
--- drivers/thermal/thermal_of.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/thermal/thermal_of.c +0 -13
@@ -19,18 +19,6 @@#include "thermal_core.h" -static int of_thermal_set_trip_hyst (struct thermal_zone_device *tz,int trip, -int hyst) -{ -if (trip >= tz->num_trips || trip <0 ) -return -EDOM ; - -/* thermal framework should take care of data->mask & (1 << trip) */ - tz->trips[trip].hysteresis = hyst; - -return 0 ; -} -static int of_thermal_get_crit_temp (struct thermal_zone_device *tz,int *temp) {
@@ -541,7 +529,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->set_trip_hyst = of_ops->set_trip_hyst ? : of_thermal_set_trip_hyst; of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind; of_ops->unbind = thermal_of_unbind;
PATCH v8 19/29 thermal/of: Remove of_thermal_get_crit_temp()
In reply to Daniel LezcanoThe generic version of of_thermal_get_crit_temp() can be used. Let's remove this ops which is pointless.
--- drivers/thermal/thermal_of.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/thermal/thermal_of.c +0 -15
@@ -19,20 +19,6 @@#include "thermal_core.h" -static int of_thermal_get_crit_temp (struct thermal_zone_device *tz, -int *temp) -{ -int i; - -for (i =0 ; i < tz->num_trips; i++) -if (tz->trips[i].type ==THERMAL_TRIP_CRITICAL ) { - *temp = tz->trips[i].temperature; -return 0 ; - } - -return -EINVAL ; -} -/*** functions parsing device tree nodes ***/ static int of_find_trip_id (struct device_node *np,struct device_node *trip)
@@ -529,7 +515,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind; of_ops->unbind = thermal_of_unbind;
Signature · 1 line
2.34.1
Re: [PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()
Hi Daniel,
Quoted 4 lines · Daniel Lezcano
The generic version of
of_thermal_get_crit_temp()can be used. Let's remove this ops which is pointless.Signed-off-by Daniel Lezcano <[email protected]>
This patch breaks Exynos thermal driver as it introduces a NULL pointer dereference in exynos_tmu_initialize():
8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 00000000 [00000000] *pgd=00000000 Internal error: Oops: 80000005 [#1] PREEMPT SMP ARM Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1-00072-ge521efddb107 #12941 Hardware name: Samsung Exynos (Flattened Device Tree)
dwc2 12480000.hsotg: new address 125
PC is at 0x0
LR is at exynos_tmu_initialize+0x4c/0x1e8
...
Process swapper/0 (pid: 1, stack limit = 0x(ptrval))
Stack: (0xf082dd78 to 0xf082e000)
...
exynos_tmu_initialize from exynos_tmu_probe+0x2b0/0x728 exynos_tmu_probe from platform_probe+0x5c/0xb8 platform_probe from really_probe+0xe0/0x414 really_probe from __driver_probe_device+0xa0/0x208 __driver_probe_device from driver_probe_device+0x30/0xc0 driver_probe_device from __driver_attach+0xf0/0x1f0 __driver_attach from bus_for_each_dev+0x70/0xb0 bus_for_each_dev from bus_add_driver+0x174/0x218 bus_add_driver from driver_register+0x88/0x11c driver_register from do_one_initcall+0x64/0x380 do_one_initcall from kernel_init_freeable+0x1c0/0x224 kernel_init_freeable from kernel_init+0x18/0x12c kernel_init from ret_from_fork+0x14/0x2c
Exception stack(0xf082dfb0 to 0xf082dff8) ... Code: bad PC value ---[ end trace 0000000000000000 ]---
If there is no replacement for tzd->ops->get_crit_temp(tzd, &temp), then please simply remove that call in exynos_tmu_initialize() to avoid breaking the initialization.
Quoted 28 lines
---
drivers/thermal/thermal_of.c| 15 ---------------1 file changed, 15 deletions(-)drivers/thermal/thermal_of.c +0
-14@@ -19,20 +19,6 @@#include "thermal_core.h" -static int of_thermal_get_crit_temp (struct thermal_zone_device *tz, -int *temp) -{ -int i; - -for (i =0 ; i < tz->num_trips; i++) -if (tz->trips[i].type ==THERMAL_TRIP_CRITICAL ) { - *temp = tz->trips[i].temperature; -return 0 ; - } - -return -EINVAL ; -} -/*** functions parsing device tree nodes ***/ static int
of_find_trip_id(struct device_node *np, struct device_node *trip)
drivers/thermal/thermal_of.c struct thermal_zone_device · line 520
Quoted 7 lines
drivers/thermal/thermal_of.c +0
-1@@ -529,7 +515,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind; of_ops->unbind = thermal_of_unbind;
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH 1/1 thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
The driver is assuming the get_critical temperature exists as it is inherited by the thermal of ops. But this one has been removed in favor of the generic one.
Use the generic thermal_zone_get_crit_temp() function instead
--- drivers/thermal/samsung/exynos_tmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +2 -3
@@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)unsigned int status;int ret =0 , temp; -if (data->soc !=SOC_ARCH_EXYNOS5433 )/* FIXME */ - ret = tzd->ops->get_crit_temp (tzd, &temp); -if (ret) { + ret =thermal_zone_get_crit_temp (tzd, &temp); +if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ dev_err (&pdev->dev,"No CRITICAL trip point defined in device tree!\n" ); goto out;
Signature · 1 line
2.34.1
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Quoted 9 lines · Daniel Lezcano
The driver is assuming the
get_criticaltemperature exists as it is inherited by the thermal of ops. But this one has been removed in favor of the generic one.Use the generic
thermal_zone_get_crit_temp()function insteadFixes 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")Reported-by Marek Szyprowski <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>
Looks good.
Best regards,
Krzysztof
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
In reply to Daniel LezcanoQuoted 9 lines · Daniel Lezcano
The driver is assuming the
get_criticaltemperature exists as it is inherited by the thermal of ops. But this one has been removed in favor of the generic one.Use the generic
thermal_zone_get_crit_temp()function insteadFixes 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")Reported-by Marek Szyprowski <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>
Quoted 10 lines
--- drivers/thermal/samsung/exynos_tmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/thermal/samsung/exynos_tmu.c +0
-0@@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)unsigned int status;
drivers/thermal/samsung/exynos_tmu.c static int exynos_tmu_initialize(struct platform_device *pdev) · line 271
Quoted 10 lines
drivers/thermal/samsung/exynos_tmu.c +2
-3int ret =0 , temp; -if (data->soc !=SOC_ARCH_EXYNOS5433 )/* FIXME */ - ret = tzd->ops->get_crit_temp (tzd, &temp); -if (ret) { + ret =thermal_zone_get_crit_temp (tzd, &temp); +if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ dev_err (&pdev->dev,"No CRITICAL trip point defined in device tree!\n" ); goto out;
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
In reply to Daniel LezcanoHi Daniel,
Quoted 9 lines · Daniel Lezcano
The driver is assuming the
get_criticaltemperature exists as it is inherited by the thermal of ops. But this one has been removed in favor of the generic one.Use the generic
thermal_zone_get_crit_temp()function insteadFixes 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")Reported-by Marek Szyprowski <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>
This patch has been dropped from -next, is there are reason for that?
Quoted 10 lines
--- drivers/thermal/samsung/exynos_tmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/thermal/samsung/exynos_tmu.c +0
-0@@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)unsigned int status;
drivers/thermal/samsung/exynos_tmu.c static int exynos_tmu_initialize(struct platform_device *pdev) · line 271
Quoted 10 lines
drivers/thermal/samsung/exynos_tmu.c +2
-3int ret =0 , temp; -if (data->soc !=SOC_ARCH_EXYNOS5433 )/* FIXME */ - ret = tzd->ops->get_crit_temp (tzd, &temp); -if (ret) { + ret =thermal_zone_get_crit_temp (tzd, &temp); +if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ dev_err (&pdev->dev,"No CRITICAL trip point defined in device tree!\n" ); goto out;
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Quoted 7 lines · Marek Szyprowski
Hi Daniel,
Quoted 4 lines · Daniel Lezcano
The driver is assuming the
get_criticaltemperature exists as it is inherited by the thermal of ops. But this one has been removed in favor of the generic one.
Quoted 7 lines
Quoted 5 lines
Use the generic
thermal_zone_get_crit_temp()function insteadFixes 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")Reported-by Marek Szyprowski <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>This patch has been dropped from -next, is there are reason for that?
No, my mistake. I dropped it accidentally when I rebased the branch.
Thanks for pointing it out.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()
In reply to Marek SzyprowskiHi Marek,
Quoted 11 lines · Marek Szyprowski
Hi Daniel,
Quoted 4 lines · Daniel Lezcano
The generic version of
of_thermal_get_crit_temp()can be used. Let's remove this ops which is pointless.Signed-off-by Daniel Lezcano <[email protected]>This patch breaks Exynos thermal driver as it introduces a NULL pointer dereference in
exynos_tmu_initialize():
Thanks for testing and reporting, I've just sent a fix for that (unfortunately can not be tested from my side)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
[thermal: thermal/next] thermal/of: Remove of_thermal_get_crit_temp()
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 9b3175c5373f295685a9ed99669bc4719594bf2c Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//9b3175c5373f295685a9ed99669bc4719594bf2c Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:52 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/of: Remove of_thermal_get_crit_temp()
The generic version of of_thermal_get_crit_temp() can be used. Let's remove this ops which is pointless.
--- drivers/thermal/thermal_of.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/thermal/thermal_of.c +0 -15
@@ -19,20 +19,6 @@#include "thermal_core.h" -static int of_thermal_get_crit_temp (struct thermal_zone_device *tz, -int *temp) -{ -int i; - -for (i =0 ; i < tz->num_trips; i++) -if (tz->trips[i].type ==THERMAL_TRIP_CRITICAL ) { - *temp = tz->trips[i].temperature; -return 0 ; - } - -return -EINVAL ; -} -/*** functions parsing device tree nodes ***/ static int of_find_trip_id (struct device_node *np,struct device_node *trip)
@@ -529,7 +515,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, goto out_kfree_trips; } - of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp; of_ops->bind = thermal_of_bind; of_ops->unbind = thermal_of_unbind;
PATCH v8 20/29 thermal/drivers/st: Use generic trip points
In reply to Daniel LezcanoThe 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 to the generic trip points
--- drivers/thermal/st/st_thermal.c | 47 +++++---------------------------- 1 file changed, 7 insertions(+), 40 deletions(-)
drivers/thermal/st/st_thermal.c +7 -40
@@ -134,48 +134,12 @@ static int st_thermal_get_temp(struct thermal_zone_device *th, int *temperature)return 0 ; } -static int st_thermal_get_trip_type (struct thermal_zone_device *th, -int trip,enum thermal_trip_type *type) -{ -struct st_thermal_sensor *sensor = th->devdata; -struct device *dev = sensor->dev; - -switch (trip) { -case 0 : - *type =THERMAL_TRIP_CRITICAL ; -break ; -default : -dev_err (dev,"invalid trip point\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int st_thermal_get_trip_temp (struct thermal_zone_device *th, -int trip,int *temp) -{ -struct st_thermal_sensor *sensor = th->devdata; -struct device *dev = sensor->dev; - -switch (trip) { -case 0 : - *temp =mcelsius (sensor->cdata->crit_temp); -break ; -default : -dev_err (dev,"Invalid trip point\n" ); -return -EINVAL ; - } - -return 0 ; -} -static struct thermal_zone_device_ops st_tz_ops = { .get_temp = st_thermal_get_temp, - .get_trip_type = st_thermal_get_trip_type, - .get_trip_temp = st_thermal_get_trip_temp, }; +static struct thermal_trip trip; +int st_thermal_register (struct platform_device *pdev,const struct of_device_id *st_thermal_of_match) {
@@ -238,9 +202,12 @@ int st_thermal_register(struct platform_device *pdev, polling_delay = sensor->ops->register_enable_irq ?0 :1000 ; + trip.temperature = sensor->cdata->crit_temp; + trip.type =THERMAL_TRIP_CRITICAL ; + sensor->thermal_dev = -thermal_zone_device_register (dev_name (dev),1 ,0 , sensor, - &st_tz_ops,NULL ,0 , polling_delay); +thermal_zone_device_register_with_trips (dev_name (dev), &trip,1 ,0 , sensor, + &st_tz_ops,NULL ,0 , polling_delay);if (IS_ERR (sensor->thermal_dev)) {dev_err (dev,"failed to register thermal zone device\n" ); ret =PTR_ERR (sensor->thermal_dev);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/st: Use generic trip points
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: c838039ebdb360cda04c5f021e1047d3d694013a Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//c838039ebdb360cda04c5f021e1047d3d694013a Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:53 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/st: Use generic trip points
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 to the generic trip points
--- drivers/thermal/st/st_thermal.c | 47 ++++---------------------------- 1 file changed, 7 insertions(+), 40 deletions(-)
drivers/thermal/st/st_thermal.c +7 -40
@@ -134,48 +134,12 @@ static int st_thermal_get_temp(struct thermal_zone_device *th, int *temperature)return 0 ; } -static int st_thermal_get_trip_type (struct thermal_zone_device *th, -int trip,enum thermal_trip_type *type) -{ -struct st_thermal_sensor *sensor = th->devdata; -struct device *dev = sensor->dev; - -switch (trip) { -case 0 : - *type =THERMAL_TRIP_CRITICAL ; -break ; -default : -dev_err (dev,"invalid trip point\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int st_thermal_get_trip_temp (struct thermal_zone_device *th, -int trip,int *temp) -{ -struct st_thermal_sensor *sensor = th->devdata; -struct device *dev = sensor->dev; - -switch (trip) { -case 0 : - *temp =mcelsius (sensor->cdata->crit_temp); -break ; -default : -dev_err (dev,"Invalid trip point\n" ); -return -EINVAL ; - } - -return 0 ; -} -static struct thermal_zone_device_ops st_tz_ops = { .get_temp = st_thermal_get_temp, - .get_trip_type = st_thermal_get_trip_type, - .get_trip_temp = st_thermal_get_trip_temp, }; +static struct thermal_trip trip; +int st_thermal_register (struct platform_device *pdev,const struct of_device_id *st_thermal_of_match) {
@@ -238,9 +202,12 @@ int st_thermal_register(struct platform_device *pdev, polling_delay = sensor->ops->register_enable_irq ?0 :1000 ; + trip.temperature = sensor->cdata->crit_temp; + trip.type =THERMAL_TRIP_CRITICAL ; + sensor->thermal_dev = -thermal_zone_device_register (dev_name (dev),1 ,0 , sensor, - &st_tz_ops,NULL ,0 , polling_delay); +thermal_zone_device_register_with_trips (dev_name (dev), &trip,1 ,0 , sensor, + &st_tz_ops,NULL ,0 , polling_delay);if (IS_ERR (sensor->thermal_dev)) {dev_err (dev,"failed to register thermal zone device\n" ); ret =PTR_ERR (sensor->thermal_dev);
PATCH v8 21/29 thermal/drivers/imx: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/imx_thermal.c | 72 +++++++++++++---------------------- 1 file changed, 27 insertions(+), 45 deletions(-)
drivers/thermal/imx_thermal.c +27 -45
@@ -76,7 +76,6 @@enum imx_thermal_trip {IMX_TRIP_PASSIVE ,IMX_TRIP_CRITICAL , -IMX_TRIP_NUM , };#define IMX_POLLING_DELAY 2000/* millisecond */
@@ -115,6 +114,11 @@ struct thermal_soc_data {u32 low_alarm_shift; }; +static struct thermal_trip trips[] = { + [IMX_TRIP_PASSIVE ] = { .type =THERMAL_TRIP_PASSIVE }, + [IMX_TRIP_CRITICAL ] = { .type =THERMAL_TRIP_CRITICAL }, +}; +static struct thermal_soc_data thermal_imx6q_data = { .version =TEMPMON_IMX6Q ,
@@ -201,8 +205,6 @@ struct imx_thermal_data {struct thermal_cooling_device *cdev;struct regmap *tempmon;u32 c1, c2;/* See formula in imx_init_calib() */ -int temp_passive; -int temp_critical;int temp_max;int alarm_temp;int last_temp;
@@ -279,12 +281,12 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)/* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ if (data->socdata->version ==TEMPMON_IMX6Q ) { -if (data->alarm_temp == data->temp_passive && - *temp >= data->temp_passive) -imx_set_alarm_temp (data, data->temp_critical); -if (data->alarm_temp == data->temp_critical && - *temp < data->temp_passive) { -imx_set_alarm_temp (data, data->temp_passive); +if (data->alarm_temp == trips[IMX_TRIP_PASSIVE ].temperature && + *temp >= trips[IMX_TRIP_PASSIVE ].temperature) +imx_set_alarm_temp (data, trips[IMX_TRIP_CRITICAL ].temperature); +if (data->alarm_temp == trips[IMX_TRIP_CRITICAL ].temperature && + *temp < trips[IMX_TRIP_PASSIVE ].temperature) { +imx_set_alarm_temp (data, trips[IMX_TRIP_PASSIVE ].temperature);dev_dbg (&tz->device,"thermal alarm off: T < %d\n" , data->alarm_temp /1000 ); }
@@ -330,29 +332,10 @@ static int imx_change_mode(struct thermal_zone_device *tz,return 0 ; } -static int imx_get_trip_type (struct thermal_zone_device *tz,int trip, -enum thermal_trip_type *type) -{ - *type = (trip ==IMX_TRIP_PASSIVE ) ?THERMAL_TRIP_PASSIVE : -THERMAL_TRIP_CRITICAL ; -return 0 ; -} -static int imx_get_crit_temp (struct thermal_zone_device *tz,int *temp) { -struct imx_thermal_data *data = tz->devdata; - - *temp = data->temp_critical; -return 0 ; -} - -static int imx_get_trip_temp (struct thermal_zone_device *tz,int trip, -int *temp) -{ -struct imx_thermal_data *data = tz->devdata; + *temp = trips[IMX_TRIP_CRITICAL ].temperature; - *temp = (trip ==IMX_TRIP_PASSIVE ) ? data->temp_passive : - data->temp_critical;return 0 ; }
@@ -371,10 +354,10 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,return -EPERM ;/* do not allow passive to be set higher than critical */ -if (temp <0 || temp > data->temp_critical) +if (temp <0 || temp > trips[IMX_TRIP_CRITICAL ].temperature)return -EINVAL ; - data->temp_passive = temp; + trips[IMX_TRIP_PASSIVE ].temperature = temp;imx_set_alarm_temp (data, temp);
@@ -423,8 +406,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .unbind = imx_unbind, .get_temp = imx_get_temp, .change_mode = imx_change_mode, - .get_trip_type = imx_get_trip_type, - .get_trip_temp = imx_get_trip_temp, .get_crit_temp = imx_get_crit_temp, .set_trip_temp = imx_set_trip_temp, };
@@ -507,8 +488,8 @@ static void imx_init_temp_grade(struct platform_device *pdev, u32 ocotp_mem0)* Set the critical trip point at 5 °C under max * Set the passive trip point at 10 °C under max (changeable via sysfs) */ - data->temp_critical = data->temp_max - (1000 *5 ); - data->temp_passive = data->temp_max - (1000 *10 ); + trips[IMX_TRIP_PASSIVE ].temperature = data->temp_max - (1000 *10 ); + trips[IMX_TRIP_CRITICAL ].temperature = data->temp_max - (1000 *5 ); }static int imx_init_from_tempmon_data (struct platform_device *pdev)
@@ -743,12 +724,13 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz =thermal_zone_device_register ("imx_thermal_zone" , -IMX_TRIP_NUM , -BIT (IMX_TRIP_PASSIVE ), data, - &imx_tz_ops,NULL , -IMX_PASSIVE_DELAY , -IMX_POLLING_DELAY ); + data->tz =thermal_zone_device_register_with_trips ("imx_thermal_zone" , + trips, +ARRAY_SIZE (trips), +BIT (IMX_TRIP_PASSIVE ), data, + &imx_tz_ops,NULL , +IMX_PASSIVE_DELAY , +IMX_POLLING_DELAY );if (IS_ERR (data->tz)) { ret =PTR_ERR (data->tz); dev_err(&pdev->dev,
@@ -758,8 +740,8 @@ static int imx_thermal_probe(struct platform_device *pdev)dev_info (&pdev->dev,"%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n" , data->temp_grade, - data->temp_max /1000 , data->temp_critical /1000 , - data->temp_passive /1000 ); + data->temp_max /1000 , trips[IMX_TRIP_CRITICAL ].temperature /1000 , + trips[IMX_TRIP_PASSIVE ].temperature /1000 );/* Enable measurements at ~ 10 Hz */ regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR,
@@ -767,10 +749,10 @@ static int imx_thermal_probe(struct platform_device *pdev) measure_freq =DIV_ROUND_UP (32768 ,10 );/* 10 Hz */ regmap_write (map, data->socdata->measure_freq_ctrl +REG_SET , measure_freq << data->socdata->measure_freq_shift); -imx_set_alarm_temp (data, data->temp_passive); +imx_set_alarm_temp (data, trips[IMX_TRIP_PASSIVE ].temperature);if (data->socdata->version ==TEMPMON_IMX6SX ) -imx_set_panic_temp (data, data->temp_critical); +imx_set_panic_temp (data, trips[IMX_TRIP_CRITICAL ].temperature);regmap_write (map, data->socdata->sensor_ctrl +REG_CLR , data->socdata->power_down_mask);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/imx: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 4e87d98cd6fb918baf227a07cd02e922d6c04eb9 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//4e87d98cd6fb918baf227a07cd02e922d6c04eb9 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:54 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:42 +01:00
thermal/drivers/imx: 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.
--- drivers/thermal/imx_thermal.c | 72 ++++++++++++---------------------- 1 file changed, 27 insertions(+), 45 deletions(-)
drivers/thermal/imx_thermal.c +27 -45
@@ -76,7 +76,6 @@enum imx_thermal_trip {IMX_TRIP_PASSIVE ,IMX_TRIP_CRITICAL , -IMX_TRIP_NUM , };#define IMX_POLLING_DELAY 2000/* millisecond */
@@ -115,6 +114,11 @@ struct thermal_soc_data {u32 low_alarm_shift; }; +static struct thermal_trip trips[] = { + [IMX_TRIP_PASSIVE ] = { .type =THERMAL_TRIP_PASSIVE }, + [IMX_TRIP_CRITICAL ] = { .type =THERMAL_TRIP_CRITICAL }, +}; +static struct thermal_soc_data thermal_imx6q_data = { .version =TEMPMON_IMX6Q ,
@@ -201,8 +205,6 @@ struct imx_thermal_data {struct thermal_cooling_device *cdev;struct regmap *tempmon;u32 c1, c2;/* See formula in imx_init_calib() */ -int temp_passive; -int temp_critical;int temp_max;int alarm_temp;int last_temp;
@@ -279,12 +281,12 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)/* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ if (data->socdata->version ==TEMPMON_IMX6Q ) { -if (data->alarm_temp == data->temp_passive && - *temp >= data->temp_passive) -imx_set_alarm_temp (data, data->temp_critical); -if (data->alarm_temp == data->temp_critical && - *temp < data->temp_passive) { -imx_set_alarm_temp (data, data->temp_passive); +if (data->alarm_temp == trips[IMX_TRIP_PASSIVE ].temperature && + *temp >= trips[IMX_TRIP_PASSIVE ].temperature) +imx_set_alarm_temp (data, trips[IMX_TRIP_CRITICAL ].temperature); +if (data->alarm_temp == trips[IMX_TRIP_CRITICAL ].temperature && + *temp < trips[IMX_TRIP_PASSIVE ].temperature) { +imx_set_alarm_temp (data, trips[IMX_TRIP_PASSIVE ].temperature);dev_dbg (&tz->device,"thermal alarm off: T < %d\n" , data->alarm_temp /1000 ); }
@@ -330,29 +332,10 @@ static int imx_change_mode(struct thermal_zone_device *tz,return 0 ; } -static int imx_get_trip_type (struct thermal_zone_device *tz,int trip, -enum thermal_trip_type *type) -{ - *type = (trip ==IMX_TRIP_PASSIVE ) ?THERMAL_TRIP_PASSIVE : -THERMAL_TRIP_CRITICAL ; -return 0 ; -} -static int imx_get_crit_temp (struct thermal_zone_device *tz,int *temp) { -struct imx_thermal_data *data = tz->devdata; - - *temp = data->temp_critical; -return 0 ; -} - -static int imx_get_trip_temp (struct thermal_zone_device *tz,int trip, -int *temp) -{ -struct imx_thermal_data *data = tz->devdata; + *temp = trips[IMX_TRIP_CRITICAL ].temperature; - *temp = (trip ==IMX_TRIP_PASSIVE ) ? data->temp_passive : - data->temp_critical;return 0 ; }
@@ -371,10 +354,10 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,return -EPERM ;/* do not allow passive to be set higher than critical */ -if (temp <0 || temp > data->temp_critical) +if (temp <0 || temp > trips[IMX_TRIP_CRITICAL ].temperature)return -EINVAL ; - data->temp_passive = temp; + trips[IMX_TRIP_PASSIVE ].temperature = temp;imx_set_alarm_temp (data, temp);
@@ -423,8 +406,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .unbind = imx_unbind, .get_temp = imx_get_temp, .change_mode = imx_change_mode, - .get_trip_type = imx_get_trip_type, - .get_trip_temp = imx_get_trip_temp, .get_crit_temp = imx_get_crit_temp, .set_trip_temp = imx_set_trip_temp, };
@@ -507,8 +488,8 @@ static void imx_init_temp_grade(struct platform_device *pdev, u32 ocotp_mem0)* Set the critical trip point at 5 °C under max * Set the passive trip point at 10 °C under max (changeable via sysfs) */ - data->temp_critical = data->temp_max - (1000 *5 ); - data->temp_passive = data->temp_max - (1000 *10 ); + trips[IMX_TRIP_PASSIVE ].temperature = data->temp_max - (1000 *10 ); + trips[IMX_TRIP_CRITICAL ].temperature = data->temp_max - (1000 *5 ); }static int imx_init_from_tempmon_data (struct platform_device *pdev)
@@ -743,12 +724,13 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz =thermal_zone_device_register ("imx_thermal_zone" , -IMX_TRIP_NUM , -BIT (IMX_TRIP_PASSIVE ), data, - &imx_tz_ops,NULL , -IMX_PASSIVE_DELAY , -IMX_POLLING_DELAY ); + data->tz =thermal_zone_device_register_with_trips ("imx_thermal_zone" , + trips, +ARRAY_SIZE (trips), +BIT (IMX_TRIP_PASSIVE ), data, + &imx_tz_ops,NULL , +IMX_PASSIVE_DELAY , +IMX_POLLING_DELAY );if (IS_ERR (data->tz)) { ret =PTR_ERR (data->tz); dev_err(&pdev->dev,
@@ -758,8 +740,8 @@ static int imx_thermal_probe(struct platform_device *pdev)dev_info (&pdev->dev,"%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n" , data->temp_grade, - data->temp_max /1000 , data->temp_critical /1000 , - data->temp_passive /1000 ); + data->temp_max /1000 , trips[IMX_TRIP_CRITICAL ].temperature /1000 , + trips[IMX_TRIP_PASSIVE ].temperature /1000 );/* Enable measurements at ~ 10 Hz */ regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR,
@@ -767,10 +749,10 @@ static int imx_thermal_probe(struct platform_device *pdev) measure_freq =DIV_ROUND_UP (32768 ,10 );/* 10 Hz */ regmap_write (map, data->socdata->measure_freq_ctrl +REG_SET , measure_freq << data->socdata->measure_freq_shift); -imx_set_alarm_temp (data, data->temp_passive); +imx_set_alarm_temp (data, trips[IMX_TRIP_PASSIVE ].temperature);if (data->socdata->version ==TEMPMON_IMX6SX ) -imx_set_panic_temp (data, data->temp_critical); +imx_set_panic_temp (data, trips[IMX_TRIP_CRITICAL ].temperature);regmap_write (map, data->socdata->sensor_ctrl +REG_CLR , data->socdata->power_down_mask);
PATCH v8 22/29 thermal/drivers/rcar: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/rcar_thermal.c | 53 ++++------------------------------ 1 file changed, 6 insertions(+), 47 deletions(-)
drivers/thermal/rcar_thermal.c +6 -47
@@ -278,52 +278,12 @@ static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)return rcar_thermal_get_current_temp (priv, temp); } -static int rcar_thermal_get_trip_type (struct thermal_zone_device *zone, -int trip,enum thermal_trip_type *type) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -/* see rcar_thermal_get_temp() */ -switch (trip) { -case 0 :/* +90 <= temp */ - *type =THERMAL_TRIP_CRITICAL ; -break ; -default : -dev_err (dev,"rcar driver trip error\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int rcar_thermal_get_trip_temp (struct thermal_zone_device *zone, -int trip,int *temp) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -/* see rcar_thermal_get_temp() */ -switch (trip) { -case 0 :/* +90 <= temp */ - *temp =MCELSIUS (90 ); -break ; -default : -dev_err (dev,"rcar driver trip error\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static const struct thermal_zone_device_ops rcar_thermal_zone_of_ops = { +static struct thermal_zone_device_ops rcar_thermal_zone_ops = { .get_temp = rcar_thermal_get_temp, }; -static struct thermal_zone_device_ops rcar_thermal_zone_ops = { - .get_temp = rcar_thermal_get_temp, - .get_trip_type = rcar_thermal_get_trip_type, - .get_trip_temp = rcar_thermal_get_trip_temp, +static struct thermal_trip trips[] = { + { .type =THERMAL_TRIP_CRITICAL , .temperature =90000 } };/*
@@ -529,11 +489,10 @@ static int rcar_thermal_probe(struct platform_device *pdev)if (chip->use_of_thermal) { priv->zone =devm_thermal_of_zone_register ( dev, i, priv, - &rcar_thermal_zone_of_ops); + &rcar_thermal_zone_ops); }else { - priv->zone =thermal_zone_device_register ( -"rcar_thermal" , -1 ,0 , priv, + priv->zone =thermal_zone_device_register_with_trips ( +"rcar_thermal" , trips,ARRAY_SIZE (trips),0 , priv, &rcar_thermal_zone_ops,NULL ,0 , idle);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/rcar: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 552ad4e4c2a5a59d55e64307e7fbdbe8e5e4e1b3 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//552ad4e4c2a5a59d55e64307e7fbdbe8e5e4e1b3 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:55 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/rcar: 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.
--- drivers/thermal/rcar_thermal.c | 53 +++------------------------------ 1 file changed, 6 insertions(+), 47 deletions(-)
drivers/thermal/rcar_thermal.c +6 -47
@@ -278,52 +278,12 @@ static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)return rcar_thermal_get_current_temp (priv, temp); } -static int rcar_thermal_get_trip_type (struct thermal_zone_device *zone, -int trip,enum thermal_trip_type *type) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -/* see rcar_thermal_get_temp() */ -switch (trip) { -case 0 :/* +90 <= temp */ - *type =THERMAL_TRIP_CRITICAL ; -break ; -default : -dev_err (dev,"rcar driver trip error\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int rcar_thermal_get_trip_temp (struct thermal_zone_device *zone, -int trip,int *temp) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -/* see rcar_thermal_get_temp() */ -switch (trip) { -case 0 :/* +90 <= temp */ - *temp =MCELSIUS (90 ); -break ; -default : -dev_err (dev,"rcar driver trip error\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static const struct thermal_zone_device_ops rcar_thermal_zone_of_ops = { +static struct thermal_zone_device_ops rcar_thermal_zone_ops = { .get_temp = rcar_thermal_get_temp, }; -static struct thermal_zone_device_ops rcar_thermal_zone_ops = { - .get_temp = rcar_thermal_get_temp, - .get_trip_type = rcar_thermal_get_trip_type, - .get_trip_temp = rcar_thermal_get_trip_temp, +static struct thermal_trip trips[] = { + { .type =THERMAL_TRIP_CRITICAL , .temperature =90000 } };/*
@@ -529,11 +489,10 @@ static int rcar_thermal_probe(struct platform_device *pdev)if (chip->use_of_thermal) { priv->zone =devm_thermal_of_zone_register ( dev, i, priv, - &rcar_thermal_zone_of_ops); + &rcar_thermal_zone_ops); }else { - priv->zone =thermal_zone_device_register ( -"rcar_thermal" , -1 ,0 , priv, + priv->zone =thermal_zone_device_register_with_trips ( +"rcar_thermal" , trips,ARRAY_SIZE (trips),0 , priv, &rcar_thermal_zone_ops,NULL ,0 , idle);
PATCH v8 23/29 thermal/drivers/broadcom: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/broadcom/bcm2835_thermal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/thermal/broadcom/bcm2835_thermal.c +5 -3
@@ -18,6 +18,7 @@#include <linux/platform_device.h> #include <linux/thermal.h> +#include "../thermal_core.h" #include "../thermal_hwmon.h" #define BCM2835_TS_TSENSCTL 0x00
@@ -224,7 +225,8 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)*/ val =readl (data->regs +BCM2835_TS_TSENSCTL );if (!(val &BCM2835_TS_TSENSCTL_RSTB )) { -int trip_temp, offset, slope; +struct thermal_trip trip; +int offset, slope; slope =thermal_zone_get_slope (tz); offset =thermal_zone_get_offset (tz);
@@ -232,7 +234,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)* For now we deal only with critical, otherwise * would need to iterate */ - err = tz->ops->get_trip_temp (tz,0 , &trip_temp); + err =thermal_zone_get_trip (tz,0 , &trip);if (err <0 ) { dev_err(&pdev->dev, "Not able to read trip_temp: %d\n",
@@ -249,7 +251,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) val |= (0xFE <<BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT );/* trip_adc value from info */ - val |=bcm2835_thermal_temp2adc (trip_temp, + val |=bcm2835_thermal_temp2adc (trip.temperature, offset, slope) <<BCM2835_TS_TSENSCTL_THOLD_SHIFT ;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/broadcom: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: d5a96a90b513e0378cc504d09324bed945db8842 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//d5a96a90b513e0378cc504d09324bed945db8842 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:56 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/broadcom: 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.
--- drivers/thermal/broadcom/bcm2835_thermal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/thermal/broadcom/bcm2835_thermal.c +5 -3
@@ -18,6 +18,7 @@#include <linux/platform_device.h> #include <linux/thermal.h> +#include "../thermal_core.h" #include "../thermal_hwmon.h" #define BCM2835_TS_TSENSCTL 0x00
@@ -224,7 +225,8 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)*/ val =readl (data->regs +BCM2835_TS_TSENSCTL );if (!(val &BCM2835_TS_TSENSCTL_RSTB )) { -int trip_temp, offset, slope; +struct thermal_trip trip; +int offset, slope; slope =thermal_zone_get_slope (tz); offset =thermal_zone_get_offset (tz);
@@ -232,7 +234,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)* For now we deal only with critical, otherwise * would need to iterate */ - err = tz->ops->get_trip_temp (tz,0 , &trip_temp); + err =thermal_zone_get_trip (tz,0 , &trip);if (err <0 ) { dev_err(&pdev->dev, "Not able to read trip_temp: %d\n",
@@ -249,7 +251,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) val |= (0xFE <<BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT );/* trip_adc value from info */ - val |=bcm2835_thermal_temp2adc (trip_temp, + val |=bcm2835_thermal_temp2adc (trip.temperature, offset, slope) <<BCM2835_TS_TSENSCTL_THOLD_SHIFT ;
PATCH v8 24/29 thermal/drivers/da9062: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/da9062-thermal.c | 52 +++++--------------------------- 1 file changed, 8 insertions(+), 44 deletions(-)
drivers/thermal/da9062-thermal.c +8 -44
@@ -120,44 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)return IRQ_HANDLED ; } -static int da9062_thermal_get_trip_type (struct thermal_zone_device *z, -int trip, -enum thermal_trip_type *type) -{ -struct da9062_thermal *thermal = z->devdata; - -switch (trip) { -case 0 : - *type =THERMAL_TRIP_HOT ; -break ; -default : -dev_err (thermal->dev, -"Driver does not support more than 1 trip-wire\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int da9062_thermal_get_trip_temp (struct thermal_zone_device *z, -int trip, -int *temp) -{ -struct da9062_thermal *thermal = z->devdata; - -switch (trip) { -case 0 : - *temp =DA9062_MILLI_CELSIUS (125 ); -break ; -default : -dev_err (thermal->dev, -"Driver does not support more than 1 trip-wire\n" ); -return -EINVAL ; - } - -return 0 ; -} -static int da9062_thermal_get_temp (struct thermal_zone_device *z,int *temp) {
@@ -172,8 +134,10 @@ static int da9062_thermal_get_temp(struct thermal_zone_device *z,static struct thermal_zone_device_ops da9062_thermal_ops = { .get_temp = da9062_thermal_get_temp, - .get_trip_type = da9062_thermal_get_trip_type, - .get_trip_temp = da9062_thermal_get_trip_temp, +}; + +static struct thermal_trip trips[] = { + { .temperature =DA9062_MILLI_CELSIUS (125 ), .type =THERMAL_TRIP_HOT }, };static const struct da9062_thermal_config da9062_config = {
@@ -228,10 +192,10 @@ static int da9062_thermal_probe(struct platform_device *pdev)INIT_DELAYED_WORK (&thermal->work, da9062_thermal_poll_on);mutex_init (&thermal->lock); - thermal->zone =thermal_zone_device_register (thermal->config->name, -1 ,0 , thermal, - &da9062_thermal_ops,NULL , pp_tmp, -0 ); + thermal->zone =thermal_zone_device_register_with_trips (thermal->config->name, + trips,ARRAY_SIZE (trips),0 , thermal, + &da9062_thermal_ops,NULL , pp_tmp, +0 );if (IS_ERR (thermal->zone)) {dev_err (&pdev->dev,"Cannot register thermal zone device\n" ); ret =PTR_ERR (thermal->zone);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/da9062: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 401445435b3fc4a65834f0d69fbeef4aff104329 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//401445435b3fc4a65834f0d69fbeef4aff104329 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:57 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/da9062: 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.
--- drivers/thermal/da9062-thermal.c | 52 ++++--------------------------- 1 file changed, 8 insertions(+), 44 deletions(-)
drivers/thermal/da9062-thermal.c +8 -44
@@ -120,44 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data)return IRQ_HANDLED ; } -static int da9062_thermal_get_trip_type (struct thermal_zone_device *z, -int trip, -enum thermal_trip_type *type) -{ -struct da9062_thermal *thermal = z->devdata; - -switch (trip) { -case 0 : - *type =THERMAL_TRIP_HOT ; -break ; -default : -dev_err (thermal->dev, -"Driver does not support more than 1 trip-wire\n" ); -return -EINVAL ; - } - -return 0 ; -} - -static int da9062_thermal_get_trip_temp (struct thermal_zone_device *z, -int trip, -int *temp) -{ -struct da9062_thermal *thermal = z->devdata; - -switch (trip) { -case 0 : - *temp =DA9062_MILLI_CELSIUS (125 ); -break ; -default : -dev_err (thermal->dev, -"Driver does not support more than 1 trip-wire\n" ); -return -EINVAL ; - } - -return 0 ; -} -static int da9062_thermal_get_temp (struct thermal_zone_device *z,int *temp) {
@@ -172,8 +134,10 @@ static int da9062_thermal_get_temp(struct thermal_zone_device *z,static struct thermal_zone_device_ops da9062_thermal_ops = { .get_temp = da9062_thermal_get_temp, - .get_trip_type = da9062_thermal_get_trip_type, - .get_trip_temp = da9062_thermal_get_trip_temp, +}; + +static struct thermal_trip trips[] = { + { .temperature =DA9062_MILLI_CELSIUS (125 ), .type =THERMAL_TRIP_HOT }, };static const struct da9062_thermal_config da9062_config = {
@@ -228,10 +192,10 @@ static int da9062_thermal_probe(struct platform_device *pdev)INIT_DELAYED_WORK (&thermal->work, da9062_thermal_poll_on);mutex_init (&thermal->lock); - thermal->zone =thermal_zone_device_register (thermal->config->name, -1 ,0 , thermal, - &da9062_thermal_ops,NULL , pp_tmp, -0 ); + thermal->zone =thermal_zone_device_register_with_trips (thermal->config->name, + trips,ARRAY_SIZE (trips),0 , thermal, + &da9062_thermal_ops,NULL , pp_tmp, +0 );if (IS_ERR (thermal->zone)) {dev_err (&pdev->dev,"Cannot register thermal zone device\n" ); ret =PTR_ERR (thermal->zone);
PATCH v8 25/29 thermal/drivers/ti: Remove unused macros ti_thermal_get_trip_value() / ti_thermal_trip_is_valid()
In reply to Daniel LezcanoThe macros:
ti_thermal_get_trip_value()
ti_thermal_trip_is_valid()
are unused. Remove them.
--- drivers/thermal/ti-soc-thermal/ti-thermal.h | 15 --------------- 1 file changed, 15 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal.h +0 -15
@@ -38,21 +38,6 @@/* Update rates */ #define FAST_TEMP_MONITORING_RATE 250 -/* helper macros */ -/** -* ti_thermal_get_trip_value - returns trip temperature based on index -* @i: trip index -*/ -#define ti_thermal_get_trip_value (i) \ - (OMAP_TRIP_HOT + ((i) * OMAP_TRIP_STEP)) - -/** -* ti_thermal_is_valid_trip - check for trip index -* @i: trip index -*/ -#define ti_thermal_is_valid_trip (trip) \ - ((trip) >= 0 && (trip) < OMAP_TRIP_NUMBER) -#ifdef CONFIG_TI_THERMAL int ti_thermal_expose_sensor (struct ti_bandgap *bgp,int id,char *domain);int ti_thermal_remove_sensor (struct ti_bandgap *bgp,int id);
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/ti: Remove unused macros ti_thermal_get_trip_value() / ti_thermal_trip_is_valid()
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: a23e3ebef74e2f9c8e58a5052ea6b717cc8fa860 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a23e3ebef74e2f9c8e58a5052ea6b717cc8fa860 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:58 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/ti: Remove unused macros ti_thermal_get_trip_value() / ti_thermal_trip_is_valid()
The macros:
ti_thermal_get_trip_value()
ti_thermal_trip_is_valid()
are unused. Remove them.
--- drivers/thermal/ti-soc-thermal/ti-thermal.h | 15 --------------- 1 file changed, 15 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal.h +0 -15
@@ -38,21 +38,6 @@/* Update rates */ #define FAST_TEMP_MONITORING_RATE 250 -/* helper macros */ -/** -* ti_thermal_get_trip_value - returns trip temperature based on index -* @i: trip index -*/ -#define ti_thermal_get_trip_value (i) \ - (OMAP_TRIP_HOT + ((i) * OMAP_TRIP_STEP)) - -/** -* ti_thermal_is_valid_trip - check for trip index -* @i: trip index -*/ -#define ti_thermal_is_valid_trip (trip) \ - ((trip) >= 0 && (trip) < OMAP_TRIP_NUMBER) -#ifdef CONFIG_TI_THERMAL int ti_thermal_expose_sensor (struct ti_bandgap *bgp,int id,char *domain);int ti_thermal_remove_sensor (struct ti_bandgap *bgp,int id);
PATCH v8 26/29 thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/platform/x86/acerhdf.c | 73 ++++++++++++---------------------- 1 file changed, 26 insertions(+), 47 deletions(-)
drivers/platform/x86/acerhdf.c +26 -47
@@ -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 ;
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 38a61992756676f7789bea9b9dcb09a357191344 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//38a61992756676f7789bea9b9dcb09a357191344 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:25:59 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
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.
--- drivers/platform/x86/acerhdf.c | 73 +++++++++++---------------------- 1 file changed, 26 insertions(+), 47 deletions(-)
drivers/platform/x86/acerhdf.c +26 -47
@@ -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 ;
PATCH v8 27/29 thermal/drivers/cxgb4: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 2 - .../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 41 ++++--------------- 2 files changed, 8 insertions(+), 35 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +0 -2
@@ -1079,8 +1079,6 @@ struct mbox_list {#if IS_ENABLED (CONFIG_THERMAL )struct ch_thermal {struct thermal_zone_device *tzdev; -int trip_temp; -int trip_type; };#endif
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +8 -33
59 lines not on this page · raw message
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/cxgb4: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 0c5a6658c5482ec7fe1f5ac526bd61ce83c06fb0 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//0c5a6658c5482ec7fe1f5ac526bd61ce83c06fb0 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:26:00 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/cxgb4: 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.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 2 +- drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 39 ++----------- 2 files changed, 7 insertions(+), 34 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +0 -2
@@ -1079,8 +1079,6 @@ struct mbox_list {#if IS_ENABLED (CONFIG_THERMAL )struct ch_thermal {struct thermal_zone_device *tzdev; -int trip_temp; -int trip_type; };#endif
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +7 -32
@@ -29,36 +29,12 @@ static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,return 0 ; } -static int cxgb4_thermal_get_trip_type (struct thermal_zone_device *tzdev, -int trip,enum thermal_trip_type *type) -{ -struct adapter *adap = tzdev->devdata; - -if (!adap->ch_thermal.trip_temp) -return -EINVAL ; - - *type = adap->ch_thermal.trip_type; -return 0 ; -} - -static int cxgb4_thermal_get_trip_temp (struct thermal_zone_device *tzdev, -int trip,int *temp) -{ -struct adapter *adap = tzdev->devdata; - -if (!adap->ch_thermal.trip_temp) -return -EINVAL ; - - *temp = adap->ch_thermal.trip_temp; -return 0 ; -} -static struct thermal_zone_device_ops cxgb4_thermal_ops = { .get_temp = cxgb4_thermal_get_temp, - .get_trip_type = cxgb4_thermal_get_trip_type, - .get_trip_temp = cxgb4_thermal_get_trip_temp, }; +static struct thermal_trip trip = { .type =THERMAL_TRIP_CRITICAL } ; +int cxgb4_thermal_init (struct adapter *adap) {struct ch_thermal *ch_thermal = &adap->ch_thermal;
@@ -79,15 +55,14 @@ int cxgb4_thermal_init(struct adapter *adap)if (ret <0 ) { num_trip =0 ;/* could not get trip temperature */ }else { - ch_thermal->trip_temp = val *1000 ; - ch_thermal->trip_type =THERMAL_TRIP_CRITICAL ; + trip.temperature = val *1000 ; }snprintf (ch_tz_name,sizeof (ch_tz_name),"cxgb4_%s" , adap->name); - ch_thermal->tzdev =thermal_zone_device_register (ch_tz_name, num_trip, -0 , adap, - &cxgb4_thermal_ops, -NULL ,0 ,0 ); + ch_thermal->tzdev =thermal_zone_device_register_with_trips (ch_tz_name, &trip, num_trip, +0 , adap, + &cxgb4_thermal_ops, +NULL ,0 ,0 );if (IS_ERR (ch_thermal->tzdev)) { ret =PTR_ERR (ch_thermal->tzdev);dev_err (adap->pdev_dev,"Failed to register thermal zone\n" );
PATCH v8 28/29 thermal/intel/int340x: Replace parameter to simplify
In reply to Daniel LezcanoIn the process of replacing the get_trip_* ops by the generic trip points, the current code has an 'override' property to add another indirection to a different ops.
Rework this approach to prevent this indirection and make the code ready for the generic trip points conversion.
Actually the get_temp() is different regarding the platform, so it is pointless to add a new set of ops but just create dynamically the ops at init time.
--- .../int340x_thermal/int340x_thermal_zone.c | 33 +++++++++---------- .../int340x_thermal/int340x_thermal_zone.h | 4 +-- .../processor_thermal_device.c | 10 ++---- 3 files changed, 20 insertions(+), 27 deletions(-)
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +15 -18
@@ -18,9 +18,6 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,unsigned long long tmp;acpi_status status; -if (d->override_ops && d->override_ops->get_temp) -return d->override_ops->get_temp (zone, temp); - status =acpi_evaluate_integer (d->adev->handle,"_TMP" ,NULL , &tmp);if (ACPI_FAILURE (status))return -EIO ;
@@ -46,9 +43,6 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,struct int34x_thermal_zone *d = zone->devdata;int i; -if (d->override_ops && d->override_ops->get_trip_temp) -return d->override_ops->get_trip_temp (zone, trip, temp); -if (trip < d->aux_trip_nr) *temp = d->aux_trips[trip];else if (trip == d->crt_trip_id)
@@ -79,9 +73,6 @@ static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,struct int34x_thermal_zone *d = zone->devdata;int i; -if (d->override_ops && d->override_ops->get_trip_type) -return d->override_ops->get_trip_type (zone, trip, type); -if (trip < d->aux_trip_nr) *type =THERMAL_TRIP_PASSIVE ;else if (trip == d->crt_trip_id)
@@ -112,9 +103,6 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,acpi_status status;char name[10 ]; -if (d->override_ops && d->override_ops->set_trip_temp) -return d->override_ops->set_trip_temp (zone, trip, temp); -snprintf (name,sizeof (name),"PAT%d" , trip); status =acpi_execute_simple_method (d->adev->handle, name,millicelsius_to_deci_kelvin (temp));
@@ -134,9 +122,6 @@ static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,acpi_status status;unsigned long long hyst; -if (d->override_ops && d->override_ops->get_trip_hyst) -return d->override_ops->get_trip_hyst (zone, trip, temp); - status =acpi_evaluate_integer (d->adev->handle,"GTSH" ,NULL , &hyst);if (ACPI_FAILURE (status)) *temp =0 ;
@@ -217,7 +202,7 @@ static struct thermal_zone_params int340x_thermal_params = { };struct int34x_thermal_zone *int340x_thermal_zone_add (struct acpi_device *adev, -struct thermal_zone_device_ops *override_ops) +int (*get_temp) (struct thermal_zone_device *,int *)) {struct int34x_thermal_zone *int34x_thermal_zone;acpi_status status;
@@ -231,8 +216,17 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,return ERR_PTR (-ENOMEM ); int34x_thermal_zone->adev = adev; - int34x_thermal_zone->override_ops = override_ops; + int34x_thermal_zone->ops =kmemdup (&int340x_thermal_zone_ops, +sizeof (int340x_thermal_zone_ops),GFP_KERNEL ); +if (!int34x_thermal_zone->ops) { + ret = -ENOMEM ; + goto err_ops_alloc; + } + +if (get_temp) + int34x_thermal_zone->ops->get_temp = get_temp; + status =acpi_evaluate_integer (adev->handle,"PATC" ,NULL , &trip_cnt);if (ACPI_FAILURE (status)) trip_cnt =0 ;
@@ -262,7 +256,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,acpi_device_bid (adev), trip_cnt, trip_mask, int34x_thermal_zone, - &int340x_thermal_zone_ops, + int34x_thermal_zone->ops, &int340x_thermal_params, 0, 0);if (IS_ERR (int34x_thermal_zone->zone)) {
@@ -281,6 +275,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,acpi_lpat_free_conversion_table (int34x_thermal_zone->lpat_table);kfree (int34x_thermal_zone->aux_trips); err_trip_alloc: +kfree (int34x_thermal_zone->ops); +err_ops_alloc:kfree (int34x_thermal_zone);return ERR_PTR (ret); }
@@ -292,6 +288,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zonethermal_zone_device_unregister (int34x_thermal_zone->zone);acpi_lpat_free_conversion_table (int34x_thermal_zone->lpat_table);kfree (int34x_thermal_zone->aux_trips); +kfree (int34x_thermal_zone->ops);kfree (int34x_thermal_zone); }EXPORT_SYMBOL_GPL (int340x_thermal_zone_remove);
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +2 -2
@@ -29,13 +29,13 @@ struct int34x_thermal_zone {int hot_temp;int hot_trip_id;struct thermal_zone_device *zone; -struct thermal_zone_device_ops *override_ops; +struct thermal_zone_device_ops *ops;void *priv_data;struct acpi_lpat_conversion_table *lpat_table; };struct int34x_thermal_zone *int340x_thermal_zone_add (struct acpi_device *, -struct thermal_zone_device_ops *override_ops); +int (*get_temp) (struct thermal_zone_device *,int *));void int340x_thermal_zone_remove (struct int34x_thermal_zone *);int int340x_thermal_read_trips (struct int34x_thermal_zone *int34x_zone);
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +3 -7
@@ -207,10 +207,6 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,return ret; } -static struct thermal_zone_device_ops proc_thermal_local_ops = { - .get_temp = proc_thermal_get_zone_temp, -}; -static int proc_thermal_read_ppcc (struct proc_thermal_device *proc_priv) {int i;
@@ -285,7 +281,7 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)struct acpi_device *adev;acpi_status status;unsigned long long tmp; -struct thermal_zone_device_ops *ops =NULL ; +int (*get_temp) (struct thermal_zone_device *,int *) =NULL ;int ret; adev =ACPI_COMPANION (dev);
@@ -304,10 +300,10 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)/* there is no _TMP method, add local method */ stored_tjmax =get_tjmax ();if (stored_tjmax >0 ) - ops = &proc_thermal_local_ops; + get_temp = proc_thermal_get_zone_temp; } - proc_priv->int340x_zone =int340x_thermal_zone_add (adev, ops); + proc_priv->int340x_zone =int340x_thermal_zone_add (adev, get_temp);if (IS_ERR (proc_priv->int340x_zone)) {return PTR_ERR (proc_priv->int340x_zone); }else
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/intel/int340x: Replace parameter to simplify
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 2f31c3f7aff30aeff127050b52135ad741963588 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//2f31c3f7aff30aeff127050b52135ad741963588 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:26:01 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/intel/int340x: Replace parameter to simplify
In the process of replacing the get_trip_* ops by the generic trip points, the current code has an 'override' property to add another indirection to a different ops.
Rework this approach to prevent this indirection and make the code ready for the generic trip points conversion.
Actually the get_temp() is different regarding the platform, so it is pointless to add a new set of ops but just create dynamically the ops at init time.
--- drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 33 +++++++++++++++------------------ drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h | 4 ++-- drivers/thermal/intel/int340x_thermal/processor_thermal_device.c | 10 +++------- 3 files changed, 20 insertions(+), 27 deletions(-)
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +15 -18
@@ -18,9 +18,6 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,unsigned long long tmp;acpi_status status; -if (d->override_ops && d->override_ops->get_temp) -return d->override_ops->get_temp (zone, temp); - status =acpi_evaluate_integer (d->adev->handle,"_TMP" ,NULL , &tmp);if (ACPI_FAILURE (status))return -EIO ;
@@ -46,9 +43,6 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,struct int34x_thermal_zone *d = zone->devdata;int i; -if (d->override_ops && d->override_ops->get_trip_temp) -return d->override_ops->get_trip_temp (zone, trip, temp); -if (trip < d->aux_trip_nr) *temp = d->aux_trips[trip];else if (trip == d->crt_trip_id)
@@ -79,9 +73,6 @@ static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,struct int34x_thermal_zone *d = zone->devdata;int i; -if (d->override_ops && d->override_ops->get_trip_type) -return d->override_ops->get_trip_type (zone, trip, type); -if (trip < d->aux_trip_nr) *type =THERMAL_TRIP_PASSIVE ;else if (trip == d->crt_trip_id)
@@ -112,9 +103,6 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,acpi_status status;char name[10 ]; -if (d->override_ops && d->override_ops->set_trip_temp) -return d->override_ops->set_trip_temp (zone, trip, temp); -snprintf (name,sizeof (name),"PAT%d" , trip); status =acpi_execute_simple_method (d->adev->handle, name,millicelsius_to_deci_kelvin (temp));
@@ -134,9 +122,6 @@ static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,acpi_status status;unsigned long long hyst; -if (d->override_ops && d->override_ops->get_trip_hyst) -return d->override_ops->get_trip_hyst (zone, trip, temp); - status =acpi_evaluate_integer (d->adev->handle,"GTSH" ,NULL , &hyst);if (ACPI_FAILURE (status)) *temp =0 ;
@@ -217,7 +202,7 @@ static struct thermal_zone_params int340x_thermal_params = { };struct int34x_thermal_zone *int340x_thermal_zone_add (struct acpi_device *adev, -struct thermal_zone_device_ops *override_ops) +int (*get_temp) (struct thermal_zone_device *,int *)) {struct int34x_thermal_zone *int34x_thermal_zone;acpi_status status;
@@ -231,7 +216,16 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,return ERR_PTR (-ENOMEM ); int34x_thermal_zone->adev = adev; - int34x_thermal_zone->override_ops = override_ops; + + int34x_thermal_zone->ops =kmemdup (&int340x_thermal_zone_ops, +sizeof (int340x_thermal_zone_ops),GFP_KERNEL ); +if (!int34x_thermal_zone->ops) { + ret = -ENOMEM ; + goto err_ops_alloc; + } + +if (get_temp) + int34x_thermal_zone->ops->get_temp = get_temp; status =acpi_evaluate_integer (adev->handle,"PATC" ,NULL , &trip_cnt);if (ACPI_FAILURE (status))
@@ -262,7 +256,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,acpi_device_bid (adev), trip_cnt, trip_mask, int34x_thermal_zone, - &int340x_thermal_zone_ops, + int34x_thermal_zone->ops, &int340x_thermal_params, 0, 0);if (IS_ERR (int34x_thermal_zone->zone)) {
@@ -281,6 +275,8 @@ err_thermal_zone:acpi_lpat_free_conversion_table (int34x_thermal_zone->lpat_table);kfree (int34x_thermal_zone->aux_trips); err_trip_alloc: +kfree (int34x_thermal_zone->ops); +err_ops_alloc:kfree (int34x_thermal_zone);return ERR_PTR (ret); }
@@ -292,6 +288,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zonethermal_zone_device_unregister (int34x_thermal_zone->zone);acpi_lpat_free_conversion_table (int34x_thermal_zone->lpat_table);kfree (int34x_thermal_zone->aux_trips); +kfree (int34x_thermal_zone->ops);kfree (int34x_thermal_zone); }EXPORT_SYMBOL_GPL (int340x_thermal_zone_remove);
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +2 -2
@@ -29,13 +29,13 @@ struct int34x_thermal_zone {int hot_temp;int hot_trip_id;struct thermal_zone_device *zone; -struct thermal_zone_device_ops *override_ops; +struct thermal_zone_device_ops *ops;void *priv_data;struct acpi_lpat_conversion_table *lpat_table; };struct int34x_thermal_zone *int340x_thermal_zone_add (struct acpi_device *, -struct thermal_zone_device_ops *override_ops); +int (*get_temp) (struct thermal_zone_device *,int *));void int340x_thermal_zone_remove (struct int34x_thermal_zone *);int int340x_thermal_read_trips (struct int34x_thermal_zone *int34x_zone);
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +3 -7
@@ -207,10 +207,6 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,return ret; } -static struct thermal_zone_device_ops proc_thermal_local_ops = { - .get_temp = proc_thermal_get_zone_temp, -}; -static int proc_thermal_read_ppcc (struct proc_thermal_device *proc_priv) {int i;
@@ -285,7 +281,7 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)struct acpi_device *adev;acpi_status status;unsigned long long tmp; -struct thermal_zone_device_ops *ops =NULL ; +int (*get_temp) (struct thermal_zone_device *,int *) =NULL ;int ret; adev =ACPI_COMPANION (dev);
@@ -304,10 +300,10 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)/* there is no _TMP method, add local method */ stored_tjmax =get_tjmax ();if (stored_tjmax >0 ) - ops = &proc_thermal_local_ops; + get_temp = proc_thermal_get_zone_temp; } - proc_priv->int340x_zone =int340x_thermal_zone_add (adev, ops); + proc_priv->int340x_zone =int340x_thermal_zone_add (adev, get_temp);if (IS_ERR (proc_priv->int340x_zone)) {return PTR_ERR (proc_priv->int340x_zone); }else
PATCH v8 29/29 thermal/drivers/intel: Use generic thermal_zone_get_trip() function
In reply to Daniel LezcanoThe 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.
--- drivers/thermal/intel/x86_pkg_temp_thermal.c | 120 +++++++++++-------- 1 file changed, 67 insertions(+), 53 deletions(-)
drivers/thermal/intel/x86_pkg_temp_thermal.c +67 -53
@@ -53,6 +53,7 @@ struct zone_device {u32 msr_pkg_therm_high;struct delayed_work work;struct thermal_zone_device *tzone; +struct thermal_trip *trips;struct cpumask cpumask; };
@@ -138,40 +139,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)return -EINVAL ; } -static int sys_get_trip_temp (struct thermal_zone_device *tzd, -int trip,int *temp) -{ -struct zone_device *zonedev = tzd->devdata; -unsigned long thres_reg_value; -u32 mask, shift, eax, edx; -int ret; - -if (trip >=MAX_NUMBER_OF_TRIPS ) -return -EINVAL ; - -if (trip) { - mask =THERM_MASK_THRESHOLD1 ; - shift =THERM_SHIFT_THRESHOLD1 ; - }else { - mask =THERM_MASK_THRESHOLD0 ; - shift =THERM_SHIFT_THRESHOLD0 ; - } - - ret =rdmsr_on_cpu (zonedev->cpu,MSR_IA32_PACKAGE_THERM_INTERRUPT , - &eax, &edx); -if (ret <0 ) -return ret; - - thres_reg_value = (eax & mask) >> shift; -if (thres_reg_value) - *temp = zonedev->tj_max - thres_reg_value *1000 ; -else - *temp =THERMAL_TEMP_INVALID ; -pr_debug ("sys_get_trip_temp %d\n" , *temp); - -return 0 ; -} -static int sys_set_trip_temp (struct thermal_zone_device *tzd,int trip,int temp) {
@@ -212,18 +179,9 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) l, h); } -static int sys_get_trip_type (struct thermal_zone_device *thermal,int trip, -enum thermal_trip_type *type) -{ - *type =THERMAL_TRIP_PASSIVE ; -return 0 ; -} -/* Thermal zone callback registry */ static struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, - .get_trip_temp = sys_get_trip_temp, - .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, };
@@ -328,6 +286,48 @@ static int pkg_thermal_notify(u64 msr_val)return 0 ; } +static struct thermal_trip *pkg_temp_thermal_trips_init (int cpu,int tj_max,int num_trips) +{ +struct thermal_trip *trips; +unsigned long thres_reg_value; +u32 mask, shift, eax, edx; +int ret, i; + + trips =kzalloc (sizeof (*trips) * num_trips,GFP_KERNEL ); +if (!trips) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < num_trips; i++) { + +if (i) { + mask =THERM_MASK_THRESHOLD1 ; + shift =THERM_SHIFT_THRESHOLD1 ; + }else { + mask =THERM_MASK_THRESHOLD0 ; + shift =THERM_SHIFT_THRESHOLD0 ; + } + + ret =rdmsr_on_cpu (cpu,MSR_IA32_PACKAGE_THERM_INTERRUPT , + &eax, &edx); +if (ret <0 ) { +kfree (trips); +return ERR_PTR (ret); + } + + thres_reg_value = (eax & mask) >> shift; + + trips[i].temperature = thres_reg_value ? + tj_max - thres_reg_value *1000 :THERMAL_TEMP_INVALID ; + + trips[i].type =THERMAL_TRIP_PASSIVE ; + +pr_debug ("%s: cpu=%d, trip=%d, temp=%d\n" , + __func__, cpu, i, trips[i].temperature); + } + +return trips; +} +static int pkg_temp_thermal_device_add (unsigned int cpu) {int id =topology_logical_die_id (cpu);
@@ -353,24 +353,27 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)if (!zonedev)return -ENOMEM ; + zonedev->trips =pkg_temp_thermal_trips_init (cpu, tj_max, thres_count); +if (IS_ERR (zonedev->trips)) { + err =PTR_ERR (zonedev->trips); + goto out_kfree_zonedev; + } +INIT_DELAYED_WORK (&zonedev->work, pkg_temp_thermal_threshold_work_fn); zonedev->cpu = cpu; zonedev->tj_max = tj_max; - zonedev->tzone =thermal_zone_device_register ("x86_pkg_temp" , - thres_count, + zonedev->tzone =thermal_zone_device_register_with_trips ("x86_pkg_temp" , + zonedev->trips, thres_count, (thres_count ==MAX_NUMBER_OF_TRIPS ) ?0x03 :0x01 , zonedev, &tzone_ops, &pkg_temp_tz_params,0 ,0 );if (IS_ERR (zonedev->tzone)) { err =PTR_ERR (zonedev->tzone); -kfree (zonedev); -return err; + goto out_kfree_trips; } err =thermal_zone_device_enable (zonedev->tzone); -if (err) { -thermal_zone_device_unregister (zonedev->tzone); -kfree (zonedev); -return err; - } +if (err) + goto out_unregister_tz; +/* Store MSR value for package thermal interrupt, to restore at exit */ rdmsr (MSR_IA32_PACKAGE_THERM_INTERRUPT , zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
@@ -379,7 +382,16 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)raw_spin_lock_irq (&pkg_temp_lock); zones[id] = zonedev;raw_spin_unlock_irq (&pkg_temp_lock); +return 0 ; + +out_unregister_tz: +thermal_zone_device_unregister (zonedev->tzone); +out_kfree_trips: +kfree (zonedev->trips); +out_kfree_zonedev: +kfree (zonedev); +return err; }static int pkg_thermal_cpu_offline (unsigned int cpu)
@@ -463,8 +475,10 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)raw_spin_unlock_irq (&pkg_temp_lock);/* Final cleanup if this is the last cpu */ -if (lastcpu) +if (lastcpu) { +kfree (zonedev->trips);kfree (zonedev); + }return 0 ; }
Signature · 1 line
2.34.1
[thermal: thermal/next] thermal/drivers/intel: Use generic thermal_zone_get_trip() function
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 84eac46bddfc37461dcd13e38c52e613e47f2997 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//84eac46bddfc37461dcd13e38c52e613e47f2997 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 03 Oct 2022 11:26:02 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Dec 2022 14:30:43 +01:00
thermal/drivers/intel: 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.
--- drivers/thermal/intel/x86_pkg_temp_thermal.c | 120 ++++++++++-------- 1 file changed, 67 insertions(+), 53 deletions(-)
drivers/thermal/intel/x86_pkg_temp_thermal.c +67 -53
@@ -53,6 +53,7 @@ struct zone_device {u32 msr_pkg_therm_high;struct delayed_work work;struct thermal_zone_device *tzone; +struct thermal_trip *trips;struct cpumask cpumask; };
@@ -138,40 +139,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)return -EINVAL ; } -static int sys_get_trip_temp (struct thermal_zone_device *tzd, -int trip,int *temp) -{ -struct zone_device *zonedev = tzd->devdata; -unsigned long thres_reg_value; -u32 mask, shift, eax, edx; -int ret; - -if (trip >=MAX_NUMBER_OF_TRIPS ) -return -EINVAL ; - -if (trip) { - mask =THERM_MASK_THRESHOLD1 ; - shift =THERM_SHIFT_THRESHOLD1 ; - }else { - mask =THERM_MASK_THRESHOLD0 ; - shift =THERM_SHIFT_THRESHOLD0 ; - } - - ret =rdmsr_on_cpu (zonedev->cpu,MSR_IA32_PACKAGE_THERM_INTERRUPT , - &eax, &edx); -if (ret <0 ) -return ret; - - thres_reg_value = (eax & mask) >> shift; -if (thres_reg_value) - *temp = zonedev->tj_max - thres_reg_value *1000 ; -else - *temp =THERMAL_TEMP_INVALID ; -pr_debug ("sys_get_trip_temp %d\n" , *temp); - -return 0 ; -} -static int sys_set_trip_temp (struct thermal_zone_device *tzd,int trip,int temp) {
@@ -212,18 +179,9 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) l, h); } -static int sys_get_trip_type (struct thermal_zone_device *thermal,int trip, -enum thermal_trip_type *type) -{ - *type =THERMAL_TRIP_PASSIVE ; -return 0 ; -} -/* Thermal zone callback registry */ static struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, - .get_trip_temp = sys_get_trip_temp, - .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, };
@@ -323,6 +281,48 @@ static int pkg_thermal_notify(u64 msr_val)return 0 ; } +static struct thermal_trip *pkg_temp_thermal_trips_init (int cpu,int tj_max,int num_trips) +{ +struct thermal_trip *trips; +unsigned long thres_reg_value; +u32 mask, shift, eax, edx; +int ret, i; + + trips =kzalloc (sizeof (*trips) * num_trips,GFP_KERNEL ); +if (!trips) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < num_trips; i++) { + +if (i) { + mask =THERM_MASK_THRESHOLD1 ; + shift =THERM_SHIFT_THRESHOLD1 ; + }else { + mask =THERM_MASK_THRESHOLD0 ; + shift =THERM_SHIFT_THRESHOLD0 ; + } + + ret =rdmsr_on_cpu (cpu,MSR_IA32_PACKAGE_THERM_INTERRUPT , + &eax, &edx); +if (ret <0 ) { +kfree (trips); +return ERR_PTR (ret); + } + + thres_reg_value = (eax & mask) >> shift; + + trips[i].temperature = thres_reg_value ? + tj_max - thres_reg_value *1000 :THERMAL_TEMP_INVALID ; + + trips[i].type =THERMAL_TRIP_PASSIVE ; + +pr_debug ("%s: cpu=%d, trip=%d, temp=%d\n" , + __func__, cpu, i, trips[i].temperature); + } + +return trips; +} +static int pkg_temp_thermal_device_add (unsigned int cpu) {int id =topology_logical_die_id (cpu);
@@ -348,24 +348,27 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)if (!zonedev)return -ENOMEM ; + zonedev->trips =pkg_temp_thermal_trips_init (cpu, tj_max, thres_count); +if (IS_ERR (zonedev->trips)) { + err =PTR_ERR (zonedev->trips); + goto out_kfree_zonedev; + } +INIT_DELAYED_WORK (&zonedev->work, pkg_temp_thermal_threshold_work_fn); zonedev->cpu = cpu; zonedev->tj_max = tj_max; - zonedev->tzone =thermal_zone_device_register ("x86_pkg_temp" , - thres_count, + zonedev->tzone =thermal_zone_device_register_with_trips ("x86_pkg_temp" , + zonedev->trips, thres_count, (thres_count ==MAX_NUMBER_OF_TRIPS ) ?0x03 :0x01 , zonedev, &tzone_ops, &pkg_temp_tz_params,0 ,0 );if (IS_ERR (zonedev->tzone)) { err =PTR_ERR (zonedev->tzone); -kfree (zonedev); -return err; + goto out_kfree_trips; } err =thermal_zone_device_enable (zonedev->tzone); -if (err) { -thermal_zone_device_unregister (zonedev->tzone); -kfree (zonedev); -return err; - } +if (err) + goto out_unregister_tz; +/* Store MSR value for package thermal interrupt, to restore at exit */ rdmsr (MSR_IA32_PACKAGE_THERM_INTERRUPT , zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
@@ -374,7 +377,16 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)raw_spin_lock_irq (&pkg_temp_lock); zones[id] = zonedev;raw_spin_unlock_irq (&pkg_temp_lock); +return 0 ; + +out_unregister_tz: +thermal_zone_device_unregister (zonedev->tzone); +out_kfree_trips: +kfree (zonedev->trips); +out_kfree_zonedev: +kfree (zonedev); +return err; }static int pkg_thermal_cpu_offline (unsigned int cpu)
@@ -458,8 +470,10 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)raw_spin_unlock_irq (&pkg_temp_lock);/* Final cleanup if this is the last cpu */ -if (lastcpu) +if (lastcpu) { +kfree (zonedev->trips);kfree (zonedev); + }return 0 ; }
Hi Daniel,
Quoted 148 lines · Daniel Lezcano
This work is the pre-requisite of handling correctly when the trip point are crossed. For that we need to rework how the trip points are declared and assigned to a thermal zone.
Even if it appears to be a common sense to have the trip points being ordered, this no guarantee neither documentation telling that is the case.
One solution could have been to create an ordered array of trips built when registering the thermal zone by calling the different get_trip* ops. However those ops receive a thermal zone pointer which is not known as it is in the process of creating it.
This cyclic dependency shows we have to rework how we manage the trip points.
Actually, all the trip points definition can be common to the backend sensor drivers and we can factor out the thermal trip structure in all of them.
Then, as we register the thermal trips array, they will be available in the thermal zone structure and a core function can return the trip given its id.
The get_trip_* ops won't be needed anymore and could be removed. The resulting code will be another step forward to a self encapsulated generic thermal framework.
Most of the drivers can be converted more or less easily. This series does a first round with most of the drivers. Some remain and will be converted but with a smaller set of changes as the conversion is a bit more complex.
Changelog:
v8:
- Pretty oneline change and parenthesis removal (Rafael)
- Collected tags
v7:
- Added missing return 0 in thex86_pkg_tempdriver
v6:
- Improved the code for theget_crit_temp()function as suggested by Rafael
- Removed inner parenthesis in theset_trip_temp()function and invert the conditions. Check the type of the trip point is unchanged
- Folded patch 4 with 1
- Add per thermal zone info message in the bang-bang governor
- Folded the fix for an uninitialized variable inint340x_thermal_zone_add()
v5:
- Fixed a deadlock when callingthermal_zone_get_trip()while handling the thermal zone lock
- Remove an extra line in the sysfs change
- Collected tags
v4:
- Remove extra lines on exynos changes as reported by Krzysztof Kozlowski
- Collected tags
v3:
- Reorg the series to be git-bisect safe
- Added theset_tripgeneric function
- Added theget_crit_tempgeneric function
- Removed more dead code in the thermal-of
- Fixed the exynos changelog
- Fixed the error check for the exynos drivers
- Collected tags
v2:
- Added missingEXPORT_SYMBOL_GPL()forthermal_zone_get_trip()
- Removed tab whitespace in the acerhdf driver
- Collected tagsCc Raju Rangoju <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Cc Peter Kaestle <[email protected]>Cc Hans de Goede <[email protected]>Cc Mark Gross <[email protected]>Cc Miquel Raynal <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Daniel Lezcano <[email protected]>Cc Amit Kucheria <[email protected]>Cc Zhang Rui <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Broadcom Kernel Team <[email protected]>Cc Florian Fainelli <[email protected]>Cc Ray Jui <[email protected]>Cc Scott Branden <[email protected]>Cc Support Opensource <[email protected]>Cc Lukasz Luba <[email protected]>Cc Shawn Guo <[email protected]>Cc Sascha Hauer <[email protected]>Cc Pengutronix Kernel Team <[email protected]>Cc Fabio Estevam <[email protected]>Cc NXP Linux Team <[email protected]>Cc Thara Gopinath <[email protected]>Cc Andy Gross <[email protected]>Cc Bjorn Andersson <[email protected]>Cc "Niklas Söderlund" <[email protected]>Cc Bartlomiej Zolnierkiewicz <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Alim Akhtar <[email protected]>Cc Thierry Reding <[email protected]>Cc Jonathan Hunter <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Keerthy <[email protected]>Cc Kunihiko Hayashi <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Antoine Tenart <[email protected]>Cc Srinivas Pandruvada <[email protected]>Cc Dmitry Osipenko <[email protected]>Daniel Lezcano (29):
thermal/core: Add a genericthermal_zone_get_trip()function thermal/sysfs: Always expose hysteresis attributes thermal/core: Add a genericthermal_zone_set_trip()function thermal/core/governors: Usethermal_zone_get_trip()instead of ops functions
thermal/of: Use genericthermal_zone_get_trip()function thermal/of: Remove unused functions
thermal/drivers/exynos: Use genericthermal_zone_get_trip()function thermal/drivers/exynos:of_thermal_get_ntrips()thermal/drivers/exynos: Replaceof_thermal_is_trip_valid()bythermal_zone_get_trip()
thermal/drivers/tegra: Use genericthermal_zone_get_trip()function thermal/drivers/uniphier: Use genericthermal_zone_get_trip()function thermal/drivers/hisi: Use genericthermal_zone_get_trip()function thermal/drivers/qcom: Use genericthermal_zone_get_trip()function thermal/drivers/armada: Use genericthermal_zone_get_trip()function thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
thermal/of: Removeof_thermal_get_ntrips()
thermal/of: Removeof_thermal_is_trip_valid()
thermal/of: Removeof_thermal_set_trip_hyst()
thermal/of: Removeof_thermal_get_crit_temp()thermal/drivers/st: Use generic trip points thermal/drivers/imx: Use genericthermal_zone_get_trip()function thermal/drivers/rcar: Use genericthermal_zone_get_trip()function
Quoted 8 lines
thermal/drivers/broadcom: Use generic
thermal_zone_get_trip()function thermal/drivers/da9062: Use genericthermal_zone_get_trip()function thermal/drivers/ti: Remove unused macrosti_thermal_get_trip_value()/ti_thermal_trip_is_valid()
thermal/drivers/acerhdf: Use genericthermal_zone_get_trip()function thermal/drivers/cxgb4: Use genericthermal_zone_get_trip()function thermal/intel/int340x: Replace parameter to simplify thermal/drivers/intel: Use genericthermal_zone_get_trip()function
I've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/
patch and I got the following lockdep warning on all Exynos-based boards:
======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0 (&data->lock#2){+.+.}-{3:3}, at: exynos_get_temp+0x3c/0xc8
but task is already holding lock:c2979b94 (&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&tz->lock){+.+.}-{3:3}:
mutex_lock_nested+0x1c/0x24 thermal_zone_get_trip+0x20/0x44 exynos_tmu_initialize+0x144/0x1e0 exynos_tmu_probe+0x2b0/0x728 platform_probe+0x5c/0xb8 really_probe+0xe0/0x414 __driver_probe_device+0xa0/0x208 driver_probe_device+0x30/0xc0 __driver_attach+0xf0/0x1f0 bus_for_each_dev+0x70/0xb0 bus_add_driver+0x174/0x218 driver_register+0x88/0x11c do_one_initcall+0x64/0x380 kernel_init_freeable+0x1c0/0x224 kernel_init+0x18/0x12c ret_from_fork+0x14/0x2c 0x0
-> #0 (&data->lock#2){+.+.}-{3:3}:
lock_acquire+0x124/0x3e4 __mutex_lock+0x90/0x948 mutex_lock_nested+0x1c/0x24 exynos_get_temp+0x3c/0xc8 __thermal_zone_get_temp+0x5c/0x12c thermal_zone_device_update.part.0+0x78/0x528 __thermal_cooling_device_register.part.0+0x298/0x354 __cpufreq_cooling_register.constprop.0+0x138/0x218 of_cpufreq_cooling_register+0x48/0x8c cpufreq_online+0x8d0/0xb2c cpufreq_add_dev+0xb0/0xec subsys_interface_register+0x108/0x118 cpufreq_register_driver+0x15c/0x380 dt_cpufreq_probe+0x2e4/0x434 platform_probe+0x5c/0xb8 really_probe+0xe0/0x414 __driver_probe_device+0xa0/0x208 driver_probe_device+0x30/0xc0 __driver_attach+0xf0/0x1f0 bus_for_each_dev+0x70/0xb0 bus_add_driver+0x174/0x218 driver_register+0x88/0x11c do_one_initcall+0x64/0x380 kernel_init_freeable+0x1c0/0x224 kernel_init+0x18/0x12c ret_from_fork+0x14/0x2c 0x0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ---- lock(&tz->lock);
lock(&data->lock#2); lock(&tz->lock); lock(&data->lock#2);
*** DEADLOCK ***
5 locks held by swapper/0/1:
#0: c1c8648c (&dev->mutex){....}-{3:3}, at: __driver_attach+0xe4/0x1f0 #1: c1210434 (cpu_hotplug_lock){++++}-{0:0}, at:
cpufreq_register_driver+0xc4/0x380
#2: c1ed8298 (subsys mutex#8){+.+.}-{3:3}, at:
subsys_interface_register+0x4c/0x118
#3: c131f944 (thermal_list_lock){+.+.}-{3:3}, at:
__thermal_cooling_device_register.part.0+0x238/0x354
#4: c2979b94 (&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528
stack backtrace:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1-00083-ge5c9d117223e
#12945
Hardware name: Samsung Exynos (Flattened Device Tree)
unwind_backtrace from show_stack+0x10/0x14
show_stack from dump_stack_lvl+0x58/0x70
dump_stack_lvl from check_noncircular+0xf0/0x158
check_noncircular from __lock_acquire+0x15e8/0x2a7c
__lock_acquire from lock_acquire+0x124/0x3e4
lock_acquire from __mutex_lock+0x90/0x948
__mutex_lock from mutex_lock_nested+0x1c/0x24
mutex_lock_nested from exynos_get_temp+0x3c/0xc8
exynos_get_temp from __thermal_zone_get_temp+0x5c/0x12c
__thermal_zone_get_temp from thermal_zone_device_update.part.0+0x78/0x528
thermal_zone_device_update.part.0 from
__thermal_cooling_device_register.part.0+0x298/0x354
__thermal_cooling_device_register.part.0 from
__cpufreq_cooling_register.constprop.0+0x138/0x218
__cpufreq_cooling_register.constprop.0 from
of_cpufreq_cooling_register+0x48/0x8c
of_cpufreq_cooling_register from cpufreq_online+0x8d0/0xb2c
cpufreq_online from cpufreq_add_dev+0xb0/0xec
cpufreq_add_dev from subsys_interface_register+0x108/0x118
subsys_interface_register from cpufreq_register_driver+0x15c/0x380
cpufreq_register_driver from dt_cpufreq_probe+0x2e4/0x434
dt_cpufreq_probe from platform_probe+0x5c/0xb8
platform_probe from really_probe+0xe0/0x414
really_probe from __driver_probe_device+0xa0/0x208
__driver_probe_device from driver_probe_device+0x30/0xc0
driver_probe_device from __driver_attach+0xf0/0x1f0
__driver_attach from bus_for_each_dev+0x70/0xb0
bus_for_each_dev from bus_add_driver+0x174/0x218
bus_add_driver from driver_register+0x88/0x11c
driver_register from do_one_initcall+0x64/0x380
do_one_initcall from kernel_init_freeable+0x1c0/0x224
kernel_init_freeable from kernel_init+0x18/0x12c
kernel_init from ret_from_fork+0x14/0x2c
Exception stack(0xf082dfb0 to 0xf082dff8)...
Let me know if You need anything more to test.
Quoted 32 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h| 2 -.../ethernet/chelsio/cxgb4/cxgb4_thermal.c| 41 +----drivers/platform/x86/acerhdf.c| 73 +++-----drivers/thermal/armada_thermal.c| 39 ++---drivers/thermal/broadcom/bcm2835_thermal.c| 8 +-drivers/thermal/da9062-thermal.c| 52 +-----drivers/thermal/gov_bang_bang.c| 39 +++--drivers/thermal/gov_fair_share.c| 18 +-drivers/thermal/gov_power_allocator.c| 51 +++---drivers/thermal/gov_step_wise.c| 22 ++-drivers/thermal/hisi_thermal.c| 11 +-drivers/thermal/imx_thermal.c| 72 +++-----.../int340x_thermal/int340x_thermal_zone.c| 33 ++--.../int340x_thermal/int340x_thermal_zone.h| 4 +-.../processor_thermal_device.c| 10 +-drivers/thermal/intel/x86_pkg_temp_thermal.c| 120 +++++++------drivers/thermal/qcom/qcom-spmi-temp-alarm.c| 39 ++---drivers/thermal/rcar_gen3_thermal.c| 2 +-drivers/thermal/rcar_thermal.c| 53 +-----drivers/thermal/samsung/exynos_tmu.c| 57 +++----drivers/thermal/st/st_thermal.c| 47 +----drivers/thermal/tegra/soctherm.c| 33 ++--drivers/thermal/tegra/tegra30-tsensor.c| 17 +-drivers/thermal/thermal_core.c| 160 +++++++++++++++---drivers/thermal/thermal_core.h| 24 +--drivers/thermal/thermal_helpers.c| 28 +--drivers/thermal/thermal_netlink.c| 21 +--drivers/thermal/thermal_of.c| 116 -------------drivers/thermal/thermal_sysfs.c| 133 +++++----------drivers/thermal/ti-soc-thermal/ti-thermal.h| 15 --drivers/thermal/uniphier_thermal.c| 27 ++-include/linux/thermal.h| 10 ++
Quoted 2 lines
32 files changed, 559 insertions(+), 818 deletions(-)
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Quoted 171 lines · Marek Szyprowski
Hi Daniel,
Quoted 148 lines · Daniel Lezcano
This work is the pre-requisite of handling correctly when the trip point are crossed. For that we need to rework how the trip points are declared and assigned to a thermal zone.
Even if it appears to be a common sense to have the trip points being ordered, this no guarantee neither documentation telling that is the case.
One solution could have been to create an ordered array of trips built when registering the thermal zone by calling the different get_trip* ops. However those ops receive a thermal zone pointer which is not known as it is in the process of creating it.
This cyclic dependency shows we have to rework how we manage the trip points.
Actually, all the trip points definition can be common to the backend sensor drivers and we can factor out the thermal trip structure in all of them.
Then, as we register the thermal trips array, they will be available in the thermal zone structure and a core function can return the trip given its id.
The get_trip_* ops won't be needed anymore and could be removed. The resulting code will be another step forward to a self encapsulated generic thermal framework.
Most of the drivers can be converted more or less easily. This series does a first round with most of the drivers. Some remain and will be converted but with a smaller set of changes as the conversion is a bit more complex.
Changelog:
v8:
- Pretty oneline change and parenthesis removal (Rafael)
- Collected tags
v7:
- Added missing return 0 in thex86_pkg_tempdriver
v6:
- Improved the code for theget_crit_temp()function as suggested by Rafael
- Removed inner parenthesis in theset_trip_temp()function and invert the conditions. Check the type of the trip point is unchanged
- Folded patch 4 with 1
- Add per thermal zone info message in the bang-bang governor
- Folded the fix for an uninitialized variable inint340x_thermal_zone_add()
v5:
- Fixed a deadlock when callingthermal_zone_get_trip()while handling the thermal zone lock
- Remove an extra line in the sysfs change
- Collected tags
v4:
- Remove extra lines on exynos changes as reported by Krzysztof Kozlowski
- Collected tags
v3:
- Reorg the series to be git-bisect safe
- Added theset_tripgeneric function
- Added theget_crit_tempgeneric function
- Removed more dead code in the thermal-of
- Fixed the exynos changelog
- Fixed the error check for the exynos drivers
- Collected tags
v2:
- Added missingEXPORT_SYMBOL_GPL()forthermal_zone_get_trip()
- Removed tab whitespace in the acerhdf driver
- Collected tagsCc Raju Rangoju <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Cc Peter Kaestle <[email protected]>Cc Hans de Goede <[email protected]>Cc Mark Gross <[email protected]>Cc Miquel Raynal <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Daniel Lezcano <[email protected]>Cc Amit Kucheria <[email protected]>Cc Zhang Rui <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Broadcom Kernel Team <[email protected]>Cc Florian Fainelli <[email protected]>Cc Ray Jui <[email protected]>Cc Scott Branden <[email protected]>Cc Support Opensource <[email protected]>Cc Lukasz Luba <[email protected]>Cc Shawn Guo <[email protected]>Cc Sascha Hauer <[email protected]>Cc Pengutronix Kernel Team <[email protected]>Cc Fabio Estevam <[email protected]>Cc NXP Linux Team <[email protected]>Cc Thara Gopinath <[email protected]>Cc Andy Gross <[email protected]>Cc Bjorn Andersson <[email protected]>Cc "Niklas Söderlund" <[email protected]>Cc Bartlomiej Zolnierkiewicz <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Alim Akhtar <[email protected]>Cc Thierry Reding <[email protected]>Cc Jonathan Hunter <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Keerthy <[email protected]>Cc Kunihiko Hayashi <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Antoine Tenart <[email protected]>Cc Srinivas Pandruvada <[email protected]>Cc Dmitry Osipenko <[email protected]>Daniel Lezcano (29):
thermal/core: Add a genericthermal_zone_get_trip()function thermal/sysfs: Always expose hysteresis attributes thermal/core: Add a genericthermal_zone_set_trip()function thermal/core/governors: Usethermal_zone_get_trip()instead of ops functions
thermal/of: Use genericthermal_zone_get_trip()function thermal/of: Remove unused functions
thermal/drivers/exynos: Use genericthermal_zone_get_trip()function thermal/drivers/exynos:of_thermal_get_ntrips()thermal/drivers/exynos: Replaceof_thermal_is_trip_valid()bythermal_zone_get_trip()
thermal/drivers/tegra: Use genericthermal_zone_get_trip()function thermal/drivers/uniphier: Use genericthermal_zone_get_trip()function thermal/drivers/hisi: Use genericthermal_zone_get_trip()function thermal/drivers/qcom: Use genericthermal_zone_get_trip()function thermal/drivers/armada: Use genericthermal_zone_get_trip()function thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
thermal/of: Removeof_thermal_get_ntrips()
thermal/of: Removeof_thermal_is_trip_valid()
thermal/of: Removeof_thermal_set_trip_hyst()
thermal/of: Removeof_thermal_get_crit_temp()thermal/drivers/st: Use generic trip points thermal/drivers/imx: Use genericthermal_zone_get_trip()function thermal/drivers/rcar: Use genericthermal_zone_get_trip()functionQuoted 8 lines
thermal/drivers/broadcom: Use generic
thermal_zone_get_trip()function thermal/drivers/da9062: Use genericthermal_zone_get_trip()function thermal/drivers/ti: Remove unused macrosti_thermal_get_trip_value()/ti_thermal_trip_is_valid()
thermal/drivers/acerhdf: Use genericthermal_zone_get_trip()function thermal/drivers/cxgb4: Use genericthermal_zone_get_trip()function thermal/intel/int340x: Replace parameter to simplify thermal/drivers/intel: Use genericthermal_zone_get_trip()functionI've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/
patch and I got the following lockdep warning on all Exynos-based boards:======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8
Quoted 5 lines
but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528which lock already depends on the new lock.
Investigating ...
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 172 lines · Marek Szyprowski
Hi Daniel,
Quoted 148 lines · Daniel Lezcano
This work is the pre-requisite of handling correctly when the trip point are crossed. For that we need to rework how the trip points are declared and assigned to a thermal zone.
Even if it appears to be a common sense to have the trip points being ordered, this no guarantee neither documentation telling that is the case.
One solution could have been to create an ordered array of trips built when registering the thermal zone by calling the different get_trip* ops. However those ops receive a thermal zone pointer which is not known as it is in the process of creating it.
This cyclic dependency shows we have to rework how we manage the trip points.
Actually, all the trip points definition can be common to the backend sensor drivers and we can factor out the thermal trip structure in all of them.
Then, as we register the thermal trips array, they will be available in the thermal zone structure and a core function can return the trip given its id.
The get_trip_* ops won't be needed anymore and could be removed. The resulting code will be another step forward to a self encapsulated generic thermal framework.
Most of the drivers can be converted more or less easily. This series does a first round with most of the drivers. Some remain and will be converted but with a smaller set of changes as the conversion is a bit more complex.
Changelog:
v8:
- Pretty oneline change and parenthesis removal (Rafael)
- Collected tags
v7:
- Added missing return 0 in thex86_pkg_tempdriver
v6:
- Improved the code for theget_crit_temp()function as suggested by Rafael
- Removed inner parenthesis in theset_trip_temp()function and invert the conditions. Check the type of the trip point is unchanged
- Folded patch 4 with 1
- Add per thermal zone info message in the bang-bang governor
- Folded the fix for an uninitialized variable inint340x_thermal_zone_add()
v5:
- Fixed a deadlock when callingthermal_zone_get_trip()while handling the thermal zone lock
- Remove an extra line in the sysfs change
- Collected tags
v4:
- Remove extra lines on exynos changes as reported by Krzysztof Kozlowski
- Collected tags
v3:
- Reorg the series to be git-bisect safe
- Added theset_tripgeneric function
- Added theget_crit_tempgeneric function
- Removed more dead code in the thermal-of
- Fixed the exynos changelog
- Fixed the error check for the exynos drivers
- Collected tags
v2:
- Added missingEXPORT_SYMBOL_GPL()forthermal_zone_get_trip()
- Removed tab whitespace in the acerhdf driver
- Collected tagsCc Raju Rangoju <[email protected]>Cc "David S. Miller" <[email protected]>Cc Eric Dumazet <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Paolo Abeni <[email protected]>Cc Peter Kaestle <[email protected]>Cc Hans de Goede <[email protected]>Cc Mark Gross <[email protected]>Cc Miquel Raynal <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Daniel Lezcano <[email protected]>Cc Amit Kucheria <[email protected]>Cc Zhang Rui <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Broadcom Kernel Team <[email protected]>Cc Florian Fainelli <[email protected]>Cc Ray Jui <[email protected]>Cc Scott Branden <[email protected]>Cc Support Opensource <[email protected]>Cc Lukasz Luba <[email protected]>Cc Shawn Guo <[email protected]>Cc Sascha Hauer <[email protected]>Cc Pengutronix Kernel Team <[email protected]>Cc Fabio Estevam <[email protected]>Cc NXP Linux Team <[email protected]>Cc Thara Gopinath <[email protected]>Cc Andy Gross <[email protected]>Cc Bjorn Andersson <[email protected]>Cc "Niklas Söderlund" <[email protected]>Cc Bartlomiej Zolnierkiewicz <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Alim Akhtar <[email protected]>Cc Thierry Reding <[email protected]>Cc Jonathan Hunter <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Keerthy <[email protected]>Cc Kunihiko Hayashi <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Antoine Tenart <[email protected]>Cc Srinivas Pandruvada <[email protected]>Cc Dmitry Osipenko <[email protected]>Daniel Lezcano (29):
thermal/core: Add a genericthermal_zone_get_trip()function thermal/sysfs: Always expose hysteresis attributes thermal/core: Add a genericthermal_zone_set_trip()function thermal/core/governors: Usethermal_zone_get_trip()instead of ops functions
thermal/of: Use genericthermal_zone_get_trip()function thermal/of: Remove unused functions
thermal/drivers/exynos: Use genericthermal_zone_get_trip()function thermal/drivers/exynos:of_thermal_get_ntrips()thermal/drivers/exynos: Replaceof_thermal_is_trip_valid()bythermal_zone_get_trip()
thermal/drivers/tegra: Use genericthermal_zone_get_trip()function thermal/drivers/uniphier: Use genericthermal_zone_get_trip()function thermal/drivers/hisi: Use genericthermal_zone_get_trip()function thermal/drivers/qcom: Use genericthermal_zone_get_trip()function thermal/drivers/armada: Use genericthermal_zone_get_trip()function thermal/drivers/rcar_gen3: Use the generic function to get the number of trips
thermal/of: Removeof_thermal_get_ntrips()
thermal/of: Removeof_thermal_is_trip_valid()
thermal/of: Removeof_thermal_set_trip_hyst()
thermal/of: Removeof_thermal_get_crit_temp()thermal/drivers/st: Use generic trip points thermal/drivers/imx: Use genericthermal_zone_get_trip()function thermal/drivers/rcar: Use genericthermal_zone_get_trip()functionQuoted 8 lines
thermal/drivers/broadcom: Use generic
thermal_zone_get_trip()function thermal/drivers/da9062: Use genericthermal_zone_get_trip()function thermal/drivers/ti: Remove unused macrosti_thermal_get_trip_value()/ti_thermal_trip_is_valid()
thermal/drivers/acerhdf: Use genericthermal_zone_get_trip()function thermal/drivers/cxgb4: Use genericthermal_zone_get_trip()function thermal/intel/int340x: Replace parameter to simplify thermal/drivers/intel: Use genericthermal_zone_get_trip()functionI've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/
patch and I got the following lockdep warning on all Exynos-based boards:======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8
Quoted 5 lines
but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528which lock already depends on the new lock.
I'm wondering if the problem is not already there and related to data->lock ...
Doesn't the thermal zone lock already prevent racy access to the data structure?
Another question: if the sensor clock is disabled after reading it, how does the hardware update the temperature and detect the programed threshold is crossed?
Quoted 153 lines
the existing dependency chain (in reverse order) is:
-> #1 (&tz->lock){+.+.}-{3:3}:
mutex_lock_nested+0x1c/0x24 thermal_zone_get_trip+0x20/0x44 exynos_tmu_initialize+0x144/0x1e0 exynos_tmu_probe+0x2b0/0x728 platform_probe+0x5c/0xb8 really_probe+0xe0/0x414 __driver_probe_device+0xa0/0x208 driver_probe_device+0x30/0xc0 __driver_attach+0xf0/0x1f0 bus_for_each_dev+0x70/0xb0 bus_add_driver+0x174/0x218 driver_register+0x88/0x11c do_one_initcall+0x64/0x380 kernel_init_freeable+0x1c0/0x224 kernel_init+0x18/0x12c ret_from_fork+0x14/0x2c 0x0-> #0 (&data->lock#2){+.+.}-{3:3}:
lock_acquire+0x124/0x3e4 __mutex_lock+0x90/0x948 mutex_lock_nested+0x1c/0x24 exynos_get_temp+0x3c/0xc8 __thermal_zone_get_temp+0x5c/0x12c thermal_zone_device_update.part.0+0x78/0x528 __thermal_cooling_device_register.part.0+0x298/0x354 __cpufreq_cooling_register.constprop.0+0x138/0x218 of_cpufreq_cooling_register+0x48/0x8c cpufreq_online+0x8d0/0xb2c cpufreq_add_dev+0xb0/0xec subsys_interface_register+0x108/0x118 cpufreq_register_driver+0x15c/0x380 dt_cpufreq_probe+0x2e4/0x434 platform_probe+0x5c/0xb8 really_probe+0xe0/0x414 __driver_probe_device+0xa0/0x208 driver_probe_device+0x30/0xc0 __driver_attach+0xf0/0x1f0 bus_for_each_dev+0x70/0xb0 bus_add_driver+0x174/0x218 driver_register+0x88/0x11c do_one_initcall+0x64/0x380 kernel_init_freeable+0x1c0/0x224 kernel_init+0x18/0x12c ret_from_fork+0x14/0x2c 0x0other info that might help us debug this:
Possible unsafe locking scenario:CPU0 CPU1 ---- ---- lock(&tz->lock); lock(&data->lock#2); lock(&tz->lock); lock(&data->lock#2);*** DEADLOCK ***
5 locks held by swapper/0/1:
#0:c1c8648c(&dev->mutex){....}-{3:3}, at:__driver_attach+0xe4/0x1f0#1:c1210434(cpu_hotplug_lock){++++}-{0:0}, at:cpufreq_register_driver+0xc4/0x380 #2: c1ed8298 (subsys mutex#8){+.+.}-{3:3}, at: subsys_interface_register+0x4c/0x118 #3: c131f944 (thermal_list_lock){+.+.}-{3:3}, at: __thermal_cooling_device_register.part.0+0x238/0x354 #4: c2979b94 (&tz->lock){+.+.}-{3:3}, at: thermal_zone_device_update.part.0+0x3c/0x528 stack backtrace: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1-00083-ge5c9d117223e #12945 Hardware name: Samsung Exynos (Flattened Device Tree) unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x58/0x70 dump_stack_lvl from check_noncircular+0xf0/0x158 check_noncircular from __lock_acquire+0x15e8/0x2a7c __lock_acquire from lock_acquire+0x124/0x3e4 lock_acquire from __mutex_lock+0x90/0x948 __mutex_lock from mutex_lock_nested+0x1c/0x24 mutex_lock_nested from exynos_get_temp+0x3c/0xc8 exynos_get_temp from __thermal_zone_get_temp+0x5c/0x12c __thermal_zone_get_temp from thermal_zone_device_update.part.0+0x78/0x528 thermal_zone_device_update.part.0 from __thermal_cooling_device_register.part.0+0x298/0x354 __thermal_cooling_device_register.part.0 from __cpufreq_cooling_register.constprop.0+0x138/0x218 __cpufreq_cooling_register.constprop.0 from of_cpufreq_cooling_register+0x48/0x8c of_cpufreq_cooling_register from cpufreq_online+0x8d0/0xb2c cpufreq_online from cpufreq_add_dev+0xb0/0xec cpufreq_add_dev from subsys_interface_register+0x108/0x118 subsys_interface_register from cpufreq_register_driver+0x15c/0x380 cpufreq_register_driver from dt_cpufreq_probe+0x2e4/0x434 dt_cpufreq_probe from platform_probe+0x5c/0xb8 platform_probe from really_probe+0xe0/0x414 really_probe from __driver_probe_device+0xa0/0x208 __driver_probe_device from driver_probe_device+0x30/0xc0 driver_probe_device from __driver_attach+0xf0/0x1f0 __driver_attach from bus_for_each_dev+0x70/0xb0 bus_for_each_dev from bus_add_driver+0x174/0x218 bus_add_driver from driver_register+0x88/0x11c driver_register from do_one_initcall+0x64/0x380 do_one_initcall from kernel_init_freeable+0x1c0/0x224 kernel_init_freeable from kernel_init+0x18/0x12c kernel_init from ret_from_fork+0x14/0x2c Exception stack(0xf082dfb0 to 0xf082dff8)...
Let me know if You need anything more to test.
Quoted 32 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h| 2 -.../ethernet/chelsio/cxgb4/cxgb4_thermal.c| 41 +----drivers/platform/x86/acerhdf.c| 73 +++-----drivers/thermal/armada_thermal.c| 39 ++---drivers/thermal/broadcom/bcm2835_thermal.c| 8 +-drivers/thermal/da9062-thermal.c| 52 +-----drivers/thermal/gov_bang_bang.c| 39 +++--drivers/thermal/gov_fair_share.c| 18 +-drivers/thermal/gov_power_allocator.c| 51 +++---drivers/thermal/gov_step_wise.c| 22 ++-drivers/thermal/hisi_thermal.c| 11 +-drivers/thermal/imx_thermal.c| 72 +++-----.../int340x_thermal/int340x_thermal_zone.c| 33 ++--.../int340x_thermal/int340x_thermal_zone.h| 4 +-.../processor_thermal_device.c| 10 +-drivers/thermal/intel/x86_pkg_temp_thermal.c| 120 +++++++------drivers/thermal/qcom/qcom-spmi-temp-alarm.c| 39 ++---drivers/thermal/rcar_gen3_thermal.c| 2 +-drivers/thermal/rcar_thermal.c| 53 +-----drivers/thermal/samsung/exynos_tmu.c| 57 +++----drivers/thermal/st/st_thermal.c| 47 +----drivers/thermal/tegra/soctherm.c| 33 ++--drivers/thermal/tegra/tegra30-tsensor.c| 17 +-drivers/thermal/thermal_core.c| 160 +++++++++++++++---drivers/thermal/thermal_core.h| 24 +--drivers/thermal/thermal_helpers.c| 28 +--drivers/thermal/thermal_netlink.c| 21 +--drivers/thermal/thermal_of.c| 116 -------------drivers/thermal/thermal_sysfs.c| 133 +++++----------drivers/thermal/ti-soc-thermal/ti-thermal.h| 15 --drivers/thermal/uniphier_thermal.c| 27 ++-include/linux/thermal.h| 10 ++Quoted 2 lines
32 files changed, 559 insertions(+), 818 deletions(-)Best regards
Signature · 10 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Marek,
On 03/10/2022 23:18, Daniel Lezcano wrote:
[ ... ]
Quoted 17 lines
Quoted 17 lines
I've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/patch and I got the following lockdep warning on all Exynos-based boards:
======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528
Quoted 7 lines
Quoted 1 line
which lock already depends on the new lock.
I'm wondering if the problem is not already there and related to
data->lock...Doesn't the thermal zone lock already prevent racy access to the data structure?
Another question: if the sensor clock is disabled after reading it, how does the hardware update the temperature and detect the programed threshold is crossed?
just a gentle ping, as the fix will depend on your answer ;)
Thanks
-- D.
[ ... ]
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 31 lines · Daniel Lezcano
Hi Marek,
On 03/10/2022 23:18, Daniel Lezcano wrote:
[ ... ]
Quoted 24 lines
Quoted 15 lines
I've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/patch and I got the following lockdep warning on all Exynos-based boards:
======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8Quoted 5 lines
but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528which lock already depends on the new lock.
I'm wondering if the problem is not already there and related to
data->lock...
Quoted 9 lines
Quoted 6 lines
Doesn't the thermal zone lock already prevent racy access to the data structure?
Another question: if the sensor clock is disabled after reading it, how does the hardware update the temperature and detect the programed threshold is crossed?
just a gentle ping, as the fix will depend on your answer ;)
Sorry, I've been busy with other stuff. I thought I will fix this once I find a bit of spare time.
IMHO the clock management is a bit over-engineered, as there is little (if any) benefit from such fine grade clock management. That clock is needed only for the AHB related part of the TMU (reading/writing the registers). The IRQ generation and temperature measurement is clocked from so called 'sclk' (special clock).
I also briefly looked at the code and the internal lock doesn't look to be really necessary assuming that the thermal core already serializes all the calls.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Hi Marek,
Quoted 36 lines · Marek Szyprowski
Quoted 34 lines · Daniel Lezcano
Hi Marek,
On 03/10/2022 23:18, Daniel Lezcano wrote:
[ ... ]
Quoted 27 lines
Quoted 15 lines
I've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/patch and I got the following lockdep warning on all Exynos-based boards:
======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8Quoted 5 lines
but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528which lock already depends on the new lock.
I'm wondering if the problem is not already there and related to
data->lock...Doesn't the thermal zone lock already prevent racy access to the data structure?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Another question: if the sensor clock is disabled after reading it, how does the hardware update the temperature and detect the programed threshold is crossed?
just a gentle ping, as the fix will depend on your answer ;)
Sorry, I've been busy with other stuff. I thought I will fix this once I find a bit of spare time.
Ok, that is great if you can find time to fix it up because I've other drivers to convert to the generic thermal trips.
Quoted 9 lines
IMHO the clock management is a bit over-engineered, as there is little (if any) benefit from such fine grade clock management. That clock is needed only for the AHB related part of the TMU (reading/writing the registers). The IRQ generation and temperature measurement is clocked from so called 'sclk' (special clock).
I also briefly looked at the code and the internal lock doesn't look to be really necessary assuming that the thermal core already serializes all the calls.
I looked at the code and I think the driver can be simplified (fixed?) even more.
IIUC, the sensor has multiple trip point interrupts, so if the device tree is describing more trip points than the sensor supports, there is a warning and the number of trip point is capped.
IMO that can be simplified by using two trip point interrupt because the thermal_zone_device_update() will call the set_trips callback with the new boundaries. IOW, the thermal framework sets a new trip point interrupt when one is crossed.
That should result in the simplification of the tmu_control as well as the tmu_probe function. As well as removing the limitation of the number of trip points.
In order to have that correctly working, the 'set_trips' ops must be used to call the tmu_control callback instead of calling it in tmu_probe.
The intialization workflow should be:
probe->...
->thermal_zone_device_register()
->thermal_zone_device_update()
->update_trip_points()
->ops->set_trips()
->tmu_control()Also, replace the workqueue by a threaded interrupt.
Does it make sense?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Hi Daniel,
Quoted 88 lines · Daniel Lezcano
Quoted 35 lines · Marek Szyprowski
Quoted 33 lines · Daniel Lezcano
On 03/10/2022 23:18, Daniel Lezcano wrote:
[ ... ]
Quoted 28 lines
Quoted 16 lines
I've tested this v8 patchset after fixing the issue with Exynos TMU with
https://lore.kernel.org/all/[email protected]/patch and I got the following lockdep warning on all Exynos-based boards:
======================================================
WARNING: possible circular locking dependency detected 6.0.0-rc1-00083-ge5c9d117223e #12945 Not tainted
------------------------------------------------------
swapper/0/1 is trying to acquire lock:c1ce66b0(&data->lock#2){+.+.}-{3:3}, at:exynos_get_temp+0x3c/0xc8Quoted 5 lines
but task is already holding lock:
c2979b94(&tz->lock){+.+.}-{3:3}, at:
thermal_zone_device_update.part.0+0x3c/0x528which lock already depends on the new lock.
I'm wondering if the problem is not already there and related to
data->lock...Doesn't the thermal zone lock already prevent racy access to the data structure?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Another question: if the sensor clock is disabled after reading it, how does the hardware update the temperature and detect the programed threshold is crossed?
just a gentle ping, as the fix will depend on your answer ;)
Sorry, I've been busy with other stuff. I thought I will fix this once I find a bit of spare time.
Ok, that is great if you can find time to fix it up because I've other drivers to convert to the generic thermal trips.
Quoted 9 lines
IMHO the clock management is a bit over-engineered, as there is little (if any) benefit from such fine grade clock management. That clock is needed only for the AHB related part of the TMU (reading/writing the registers). The IRQ generation and temperature measurement is clocked from so called 'sclk' (special clock).
I also briefly looked at the code and the internal lock doesn't look to be really necessary assuming that the thermal core already serializes all the calls.
I looked at the code and I think the driver can be simplified (fixed?) even more.
IIUC, the sensor has multiple trip point interrupts, so if the device tree is describing more trip points than the sensor supports, there is a warning and the number of trip point is capped.
IMO that can be simplified by using two trip point interrupt because the
thermal_zone_device_update()will call theset_tripscallback with the new boundaries. IOW, the thermal framework sets a new trip point interrupt when one is crossed.That should result in the simplification of the
tmu_controlas well as thetmu_probefunction. As well as removing the limitation of the number of trip points.In order to have that correctly working, the '
set_trips' ops must be used to call thetmu_controlcallback instead of calling it intmu_probe.The intialization workflow should be:
probe->...
->thermal_zone_device_register()
->thermal_zone_device_update()
->update_trip_points()
->ops->set_trips()
->tmu_control()
Quoted 3 lines
Also, replace the workqueue by a threaded interrupt.
Does it make sense?
Yes, definitely. Frankly speaking I've never looked into that code, so I was not aware that it needs some cleanup.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland