* [PATCH v4 00/11] Stop monitoring disabled devices [not found] <Message-ID: <4493c0e4-51aa-3907-810c-74949ff27ca4@samsung.com> @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz ` (17 more replies) 2020-06-01 10:02 ` [PATCH v4 00/11] Stop monitoring disabled devices Peter Kästle 1 sibling, 18 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel There is already a reviewed v3 (not to be confused with RFC v3), which can be considered for merging: https://lore.kernel.org/linux-pm/20200423165705.13585-2-andrzej.p@collabora.com/ Let me cite Bartlomiej Zolnierkiewicz: "I couldn't find the problems with the patch itself (no new issues being introduced, all changes seem to be improvements over the current situation). Also the patch is not small but it also not that big and it mostly removes the code: 17 files changed, 105 insertions(+), 244 deletions(-)" There have been raised some concerns about bisectability and about introducing "initial_mode" member in struct thermal_zone_params. This v4 series addresses those concerns: it takes a more gradual approach and uses explicit tzd state initialization, hence there are more insertions than in v3, and the net effect is -63 lines versus -139 lines in v3. Patch 2/11 converts the 3 drivers which don't store their mode in enum thermal_device_mode to do so. Once that is cleared, struct thermal_zone_device gains its "mode" member (patch 3/11) and then all interested drivers change the location where they store their state: instead of storing it in some variable in a driver, they store it in struct thermal_zone_device (patch 4/11). Patch 4/11 does not introduce other changes. Then get_mode() driver method becomes redundant, and so it is removed (patch 5/11). This is the first part of the groundwork. The second part of the groundwork is to add (patch 6/11) and use (patch 7/11) helpers for accessing tzd's state from drivers. From this moment on the drivers don't access tzd->mode directly. Please note that after patch 4/11 all thermal zone devices have their mode implicitly initialized to DISABLED, as a result of kzalloc and THERMAL_DEVICE_DISABLED == 0. This is not a problem from the point of view of polling them, because their state is not considered when deciding to poll or to cease polling. In preparation for considering tzd's state when deciding to poll or to cease polling it ensured (patch 8/11 and some in patch 7/11) that all the drivers are explicitly initialized with regard to their state. With all that groundwork in place now it makes sense to modify thermal_core so that it stops polling DISABLED devices (patch 9/11), which is the ultimate purpose of this work. While at it, some set_mode() implementations only change the polling variables to make the core stop polling their drivers, but that is now unnecessary and those set_mode() implementations are removed. In other implementations polling variables modifications are removed. Some other set_mode() implementations are simplified or removed (patch 10/11). set_mode() is now only called when tzd's mode is about to change. Actual setting is performed in thermal_core, in thermal_zone_device_set_mode(). The meaning of set_mode() callback is actually to notify the driver about the mode being changed and giving the driver a chance to oppose such a change. To better reflect the purpose of the method it is renamed to change_mode() (patch 11/11). Andrzej Pietrasiewicz (11): acpi: thermal: Fix error handling in the register function thermal: Store thermal mode in a dedicated enum thermal: Add current mode to thermal zone device thermal: Store device mode in struct thermal_zone_device thermal: remove get_mode() operation of drivers thermal: Add mode helpers thermal: Use mode helpers in drivers thermal: Explicitly enable non-changing thermal zone devices thermal: core: Stop polling DISABLED thermal devices thermal: Simplify or eliminate unnecessary set_mode() methods thermal: Rename set_mode() to change_mode() drivers/acpi/thermal.c | 75 +++++---------- .../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++ .../ethernet/mellanox/mlxsw/core_thermal.c | 91 ++++--------------- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 +- drivers/platform/x86/acerhdf.c | 33 +++---- drivers/platform/x86/intel_mid_thermal.c | 6 ++ drivers/power/supply/power_supply_core.c | 9 +- drivers/thermal/armada_thermal.c | 6 ++ drivers/thermal/da9062-thermal.c | 16 +--- drivers/thermal/dove_thermal.c | 6 ++ drivers/thermal/hisi_thermal.c | 6 +- drivers/thermal/imx_thermal.c | 57 ++++-------- .../intel/int340x_thermal/int3400_thermal.c | 43 +++------ .../int340x_thermal/int340x_thermal_zone.c | 5 + drivers/thermal/intel/intel_pch_thermal.c | 5 + .../thermal/intel/intel_quark_dts_thermal.c | 34 ++----- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 + drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++ drivers/thermal/kirkwood_thermal.c | 7 ++ drivers/thermal/rcar_thermal.c | 9 +- drivers/thermal/rockchip_thermal.c | 6 +- drivers/thermal/spear_thermal.c | 7 ++ drivers/thermal/sprd_thermal.c | 6 +- drivers/thermal/st/st_thermal.c | 5 + drivers/thermal/thermal_core.c | 76 ++++++++++++++-- drivers/thermal/thermal_of.c | 51 ++--------- drivers/thermal/thermal_sysfs.c | 37 +------- include/linux/thermal.h | 19 +++- 28 files changed, 289 insertions(+), 352 deletions(-) base-commit: 351f4911a477ae01239c42f771f621d85b06ea10 -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-05-29 14:50 ` Guenter Roeck 2020-06-24 8:16 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz ` (16 subsequent siblings) 17 siblings, 2 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel The acpi_thermal_register_thermal_zone() is missing any error handling. This needs to be fixed. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..6de8066ca1e7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) result = sysfs_create_link(&tz->device->dev.kobj, &tz->thermal_zone->device.kobj, "thermal_zone"); if (result) - return result; + goto unregister_tzd; result = sysfs_create_link(&tz->thermal_zone->device.kobj, &tz->device->dev.kobj, "device"); if (result) - return result; + goto remove_tz_link; status = acpi_bus_attach_private_data(tz->device->handle, tz->thermal_zone); - if (ACPI_FAILURE(status)) - return -ENODEV; + if (ACPI_FAILURE(status)) { + result = -ENODEV; + goto remove_dev_link; + } tz->tz_enabled = 1; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); + return 0; + +remove_dev_link: + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); +remove_tz_link: + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); +unregister_tzd: + thermal_zone_device_unregister(tz->thermal_zone); + + return result; } static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz @ 2020-05-29 14:50 ` Guenter Roeck 2020-06-24 8:16 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Guenter Roeck @ 2020-05-29 14:50 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Emmanuel Grumbach, Heiko Stuebner, Rafael J . Wysocki, Vishal Kulkarni, Luca Coelho, Miquel Raynal, kernel, Fabio Estevam, Amit Kucheria, Chunyan Zhang, Daniel Lezcano, Allison Randal, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Johannes Berg, Intel Linux Wireless, Sascha Hauer, Ido Schimmel, Baolin Wang, Jiri Pirko, Orson Zhai, Thomas Gleixner, Kalle Valo, Support Opensource, Enrico Weigelt, Peter Kaestle, Sebastian Reichel, Bartlomiej Zolnierkiewicz, Pengutronix Kernel Team, Niklas Söderlund, Shawn Guo, David S . Miller, Andy Shevchenko On Thu, May 28, 2020 at 09:20:41PM +0200, Andrzej Pietrasiewicz wrote: > The acpi_thermal_register_thermal_zone() is missing any error handling. > This needs to be fixed. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/acpi/thermal.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..6de8066ca1e7 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > result = sysfs_create_link(&tz->device->dev.kobj, > &tz->thermal_zone->device.kobj, "thermal_zone"); > if (result) > - return result; > + goto unregister_tzd; > > result = sysfs_create_link(&tz->thermal_zone->device.kobj, > &tz->device->dev.kobj, "device"); > if (result) > - return result; > + goto remove_tz_link; > > status = acpi_bus_attach_private_data(tz->device->handle, > tz->thermal_zone); > - if (ACPI_FAILURE(status)) > - return -ENODEV; > + if (ACPI_FAILURE(status)) { > + result = -ENODEV; > + goto remove_dev_link; > + } > > tz->tz_enabled = 1; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > + > return 0; > + > +remove_dev_link: > + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); > +remove_tz_link: > + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); > +unregister_tzd: > + thermal_zone_device_unregister(tz->thermal_zone); > + > + return result; > } > > static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-05-29 14:50 ` Guenter Roeck @ 2020-06-24 8:16 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 8:16 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > The acpi_thermal_register_thermal_zone() is missing any error handling. > This needs to be fixed. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..6de8066ca1e7 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > result = sysfs_create_link(&tz->device->dev.kobj, > &tz->thermal_zone->device.kobj, "thermal_zone"); > if (result) > - return result; > + goto unregister_tzd; > > result = sysfs_create_link(&tz->thermal_zone->device.kobj, > &tz->device->dev.kobj, "device"); > if (result) > - return result; > + goto remove_tz_link; > > status = acpi_bus_attach_private_data(tz->device->handle, > tz->thermal_zone); > - if (ACPI_FAILURE(status)) > - return -ENODEV; > + if (ACPI_FAILURE(status)) { > + result = -ENODEV; > + goto remove_dev_link; > + } > > tz->tz_enabled = 1; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > + > return 0; > + > +remove_dev_link: > + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); > +remove_tz_link: > + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); > +unregister_tzd: > + thermal_zone_device_unregister(tz->thermal_zone); > + > + return result; > } > > static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-05-29 14:48 ` Guenter Roeck 2020-06-24 9:38 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz ` (15 subsequent siblings) 17 siblings, 2 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for storing mode in struct thermal_zone_device. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 27 +++++++++---------- drivers/platform/x86/acerhdf.c | 8 ++++-- .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 6de8066ca1e7..fb46070c66d8 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,7 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; + enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, if (!tz) return -EINVAL; - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; + *mode = tz->mode; return 0; } @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != tz->mode) { + tz->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); + tz->mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); acpi_thermal_check(tz); } return 0; @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->tz_enabled = 1; + tz->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..830a8b060e74 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,6 +68,7 @@ static int kernelmode = 1; #else static int kernelmode; #endif +static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; + thermal_mode = THERMAL_DEVICE_DISABLED; if (thz_dev) thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; + thermal_mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; + *mode = thermal_mode; return 0; } @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + thermal_mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 0b3a62655843..e84faaadff87 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,7 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - int mode; + enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + if (mode != priv->mode) { + priv->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } evaluate_odvp(priv); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-28 19:20 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-05-29 14:48 ` Guenter Roeck 2020-05-29 15:13 ` Andrzej Pietrasiewicz 2020-06-24 9:38 ` Bartlomiej Zolnierkiewicz 1 sibling, 1 reply; 137+ messages in thread From: Guenter Roeck @ 2020-05-29 14:48 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Emmanuel Grumbach, Heiko Stuebner, Rafael J . Wysocki, Vishal Kulkarni, Luca Coelho, Miquel Raynal, kernel, Fabio Estevam, Amit Kucheria, Chunyan Zhang, Daniel Lezcano, Allison Randal, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Johannes Berg, Intel Linux Wireless, Sascha Hauer, Ido Schimmel, Baolin Wang, Jiri Pirko, Orson Zhai, Thomas Gleixner, Kalle Valo, Support Opensource, Enrico Weigelt, Peter Kaestle, Sebastian Reichel, Bartlomiej Zolnierkiewicz, Pengutronix Kernel Team, Niklas Söderlund, Shawn Guo, David S . Miller, Andy Shevchenko On Thu, May 28, 2020 at 09:20:42PM +0200, Andrzej Pietrasiewicz wrote: > Prepare for storing mode in struct thermal_zone_device. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/acpi/thermal.c | 27 +++++++++---------- > drivers/platform/x86/acerhdf.c | 8 ++++-- > .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- > 3 files changed, 25 insertions(+), 28 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 6de8066ca1e7..fb46070c66d8 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,7 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > + enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, > if (!tz) > return -EINVAL; > > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > + *mode = tz->mode; > > return 0; > } > @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; Personally I find this check unnecessary: The enum has no other values, and it is verifyable that the callers provide the enum and not some other value. > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != tz->mode) { > + tz->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > + tz->mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > acpi_thermal_check(tz); > } > return 0; > @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > goto remove_dev_link; > } > > - tz->tz_enabled = 1; > + tz->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..830a8b060e74 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -68,6 +68,7 @@ static int kernelmode = 1; > #else > static int kernelmode; > #endif > +static enum thermal_device_mode thermal_mode; > > static unsigned int interval = 10; > static unsigned int fanon = 60000; > @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > + thermal_mode = THERMAL_DEVICE_DISABLED; > if (thz_dev) > thz_dev->polling_delay = 0; > pr_notice("kernel mode fan control OFF\n"); > @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > + thermal_mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > + *mode = thermal_mode; > > return 0; > } > @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + thermal_mode = kernelmode ? > + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 0b3a62655843..e84faaadff87 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -48,7 +48,7 @@ struct int3400_thermal_priv { > struct acpi_device *adev; > struct platform_device *pdev; > struct thermal_zone_device *thermal; > - int mode; > + enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; Same as above. > > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != priv->mode) { > + priv->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > > evaluate_odvp(priv); ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-29 14:48 ` Guenter Roeck @ 2020-05-29 15:13 ` Andrzej Pietrasiewicz 2020-05-29 15:34 ` Guenter Roeck 0 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-29 15:13 UTC (permalink / raw) To: Guenter Roeck Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Emmanuel Grumbach, Heiko Stuebner, Rafael J . Wysocki, Vishal Kulkarni, Luca Coelho, Miquel Raynal, kernel, Fabio Estevam, Amit Kucheria, Chunyan Zhang, Daniel Lezcano, Allison Randal, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Johannes Berg, Intel Linux Wireless, Sascha Hauer, Ido Schimmel, Baolin Wang, Jiri Pirko, Orson Zhai, Thomas Gleixner, Kalle Valo, Support Opensource, Enrico Weigelt, Peter Kaestle, Sebastian Reichel, Bartlomiej Zolnierkiewicz, Pengutronix Kernel Team, Niklas Söderlund, Shawn Guo, David S . Miller, Andy Shevchenko Hi Guenter, W dniu 29.05.2020 o 16:48, Guenter Roeck pisze: > On Thu, May 28, 2020 at 09:20:42PM +0200, Andrzej Pietrasiewicz wrote: >> Prepare for storing mode in struct thermal_zone_device. >> >> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> >> --- >> drivers/acpi/thermal.c | 27 +++++++++---------- >> drivers/platform/x86/acerhdf.c | 8 ++++-- >> .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- >> 3 files changed, 25 insertions(+), 28 deletions(-) <snip> >> @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, >> enum thermal_device_mode mode) >> { >> struct acpi_thermal *tz = thermal->devdata; >> - int enable; >> >> if (!tz) >> return -EINVAL; >> >> + if (mode != THERMAL_DEVICE_DISABLED && >> + mode != THERMAL_DEVICE_ENABLED) >> + return -EINVAL; > > Personally I find this check unnecessary: The enum has no other values, > and it is verifyable that the callers provide the enum and not some other > value. It is getting removed in PATCH 10/11. >> + if (mode != THERMAL_DEVICE_ENABLED && >> + mode != THERMAL_DEVICE_DISABLED) >> return -EINVAL; > > Same as above. ditto. ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-29 15:13 ` Andrzej Pietrasiewicz @ 2020-05-29 15:34 ` Guenter Roeck 0 siblings, 0 replies; 137+ messages in thread From: Guenter Roeck @ 2020-05-29 15:34 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Emmanuel Grumbach, Heiko Stuebner, Rafael J . Wysocki, Vishal Kulkarni, Luca Coelho, Miquel Raynal, kernel, Fabio Estevam, Amit Kucheria, Chunyan Zhang, Daniel Lezcano, Allison Randal, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Johannes Berg, Intel Linux Wireless, Sascha Hauer, Ido Schimmel, Baolin Wang, Jiri Pirko, Orson Zhai, Thomas Gleixner, Kalle Valo, Support Opensource, Enrico Weigelt, Peter Kaestle, Sebastian Reichel, Bartlomiej Zolnierkiewicz, Pengutronix Kernel Team, Niklas Söderlund, Shawn Guo, David S . Miller, Andy Shevchenko On 5/29/20 8:13 AM, Andrzej Pietrasiewicz wrote: > Hi Guenter, > > W dniu 29.05.2020 o 16:48, Guenter Roeck pisze: >> On Thu, May 28, 2020 at 09:20:42PM +0200, Andrzej Pietrasiewicz wrote: >>> Prepare for storing mode in struct thermal_zone_device. >>> >>> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> >>> --- >>> drivers/acpi/thermal.c | 27 +++++++++---------- >>> drivers/platform/x86/acerhdf.c | 8 ++++-- >>> .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- >>> 3 files changed, 25 insertions(+), 28 deletions(-) > > <snip> > >>> @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, >>> enum thermal_device_mode mode) >>> { >>> struct acpi_thermal *tz = thermal->devdata; >>> - int enable; >>> if (!tz) >>> return -EINVAL; >>> + if (mode != THERMAL_DEVICE_DISABLED && >>> + mode != THERMAL_DEVICE_ENABLED) >>> + return -EINVAL; >> >> Personally I find this check unnecessary: The enum has no other values, >> and it is verifyable that the callers provide the enum and not some other >> value. > > It is getting removed in PATCH 10/11. > > >>> + if (mode != THERMAL_DEVICE_ENABLED && >>> + mode != THERMAL_DEVICE_DISABLED) >>> return -EINVAL; >> >> Same as above. > > ditto. Hmm, I think that would be better done with this patch. But I guess that is a bit of PoV, so Reviewed-by: Guenter Roeck <linux@roeck-us.net> since I don't have any other objections/observations. Guenter ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-28 19:20 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz 2020-05-29 14:48 ` Guenter Roeck @ 2020-06-24 9:38 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:38 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Prepare for storing mode in struct thermal_zone_device. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 27 +++++++++---------- > drivers/platform/x86/acerhdf.c | 8 ++++-- > .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- > 3 files changed, 25 insertions(+), 28 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 6de8066ca1e7..fb46070c66d8 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,7 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > + enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, > if (!tz) > return -EINVAL; > > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > + *mode = tz->mode; > > return 0; > } > @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != tz->mode) { > + tz->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > + tz->mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > acpi_thermal_check(tz); > } > return 0; > @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > goto remove_dev_link; > } > > - tz->tz_enabled = 1; > + tz->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..830a8b060e74 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -68,6 +68,7 @@ static int kernelmode = 1; > #else > static int kernelmode; > #endif > +static enum thermal_device_mode thermal_mode; > > static unsigned int interval = 10; > static unsigned int fanon = 60000; > @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > + thermal_mode = THERMAL_DEVICE_DISABLED; > if (thz_dev) > thz_dev->polling_delay = 0; > pr_notice("kernel mode fan control OFF\n"); > @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > + thermal_mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > + *mode = thermal_mode; > > return 0; > } > @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + thermal_mode = kernelmode ? > + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 0b3a62655843..e84faaadff87 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -48,7 +48,7 @@ struct int3400_thermal_priv { > struct acpi_device *adev; > struct platform_device *pdev; > struct thermal_zone_device *thermal; > - int mode; > + enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != priv->mode) { > + priv->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > > evaluate_odvp(priv); > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 03/11] thermal: Add current mode to thermal zone device 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-05-29 14:51 ` Guenter Roeck 2020-06-24 9:39 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz ` (14 subsequent siblings) 17 siblings, 2 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for changing the place where the mode is stored: now it is in drivers, which might or might not implement get_mode()/set_mode() methods. A lot of cleanup can be done thanks to storing it in struct tzd. The get_mode() methods will become redundant. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- include/linux/thermal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..5f91d7f04512 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -128,6 +128,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +171,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 03/11] thermal: Add current mode to thermal zone device 2020-05-28 19:20 ` [PATCH v4 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz @ 2020-05-29 14:51 ` Guenter Roeck 2020-06-24 9:39 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Guenter Roeck @ 2020-05-29 14:51 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Emmanuel Grumbach, Heiko Stuebner, Rafael J . Wysocki, Vishal Kulkarni, Luca Coelho, Miquel Raynal, kernel, Fabio Estevam, Amit Kucheria, Chunyan Zhang, Daniel Lezcano, Allison Randal, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Johannes Berg, Intel Linux Wireless, Sascha Hauer, Ido Schimmel, Baolin Wang, Jiri Pirko, Orson Zhai, Thomas Gleixner, Kalle Valo, Support Opensource, Enrico Weigelt, Peter Kaestle, Sebastian Reichel, Bartlomiej Zolnierkiewicz, Pengutronix Kernel Team, Niklas Söderlund, Shawn Guo, David S . Miller, Andy Shevchenko On Thu, May 28, 2020 at 09:20:43PM +0200, Andrzej Pietrasiewicz wrote: > Prepare for changing the place where the mode is stored: now it is in > drivers, which might or might not implement get_mode()/set_mode() methods. > A lot of cleanup can be done thanks to storing it in struct tzd. The > get_mode() methods will become redundant. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > include/linux/thermal.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..5f91d7f04512 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -128,6 +128,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +171,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 03/11] thermal: Add current mode to thermal zone device 2020-05-28 19:20 ` [PATCH v4 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz 2020-05-29 14:51 ` Guenter Roeck @ 2020-06-24 9:39 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:39 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Prepare for changing the place where the mode is stored: now it is in > drivers, which might or might not implement get_mode()/set_mode() methods. > A lot of cleanup can be done thanks to storing it in struct tzd. The > get_mode() methods will become redundant. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > include/linux/thermal.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..5f91d7f04512 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -128,6 +128,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +171,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 9:40 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz ` (13 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for eliminating get_mode(). Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 18 ++++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 21 +++++++------------ drivers/platform/x86/acerhdf.c | 15 ++++++------- drivers/thermal/da9062-thermal.c | 6 ++---- drivers/thermal/imx_thermal.c | 17 +++++++-------- .../intel/int340x_thermal/int3400_thermal.c | 12 +++-------- .../thermal/intel/intel_quark_dts_thermal.c | 16 +++++++------- drivers/thermal/thermal_of.c | 10 +++------ 8 files changed, 44 insertions(+), 71 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index fb46070c66d8..4ba273f49d87 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->mode != THERMAL_DEVICE_ENABLED) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) static int thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->mode; + *mode = thermal->mode; return 0; } @@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->mode) { - tz->mode = mode; + if (mode != tz->thermal_zone->mode) { + tz->thermal_zone->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->mode == THERMAL_DEVICE_ENABLED ? + tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? "Enable" : "Disable")); acpi_thermal_check(tz); } @@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->mode = THERMAL_DEVICE_ENABLED; + tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..aa082e8a0b13 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; + *mode = tzdev->mode; return 0; } @@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; mutex_unlock(&tzdev->lock); - thermal->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -469,9 +465,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; + *mode = tzdev->mode; return 0; } @@ -489,9 +483,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; + mutex_unlock(&tzdev->lock); - tz->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -765,7 +760,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; + module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -881,7 +876,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; + gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1050,7 +1045,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; + thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 830a8b060e74..97b288485837 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,7 +68,6 @@ static int kernelmode = 1; #else static int kernelmode; #endif -static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - thermal_mode = THERMAL_DEVICE_DISABLED; - if (thz_dev) + if (thz_dev) { + thz_dev->mode = THERMAL_DEVICE_DISABLED; thz_dev->polling_delay = 0; + } pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thermal_mode = THERMAL_DEVICE_ENABLED; + thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = thermal_mode; + *mode = thermal->mode; return 0; } @@ -741,8 +741,6 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thermal_mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, @@ -750,6 +748,9 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; + thz_dev->mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..a14c7981c7c7 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) static int da9062_thermal_get_mode(struct thermal_zone_device *z, enum thermal_device_mode *mode) { - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; + *mode = z->mode; return 0; } @@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); @@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } + thermal->zone->mode = THERMAL_DEVICE_ENABLED; dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..9a1114d721b6 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) static int imx_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + data->tz->mode = THERMAL_DEVICE_DISABLED; clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e84faaadff87..f65b2fc09198 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,6 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; + *mode = thermal->mode; return 0; } @@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != priv->mode) { - priv->mode = mode; + if (mode != thermal->mode) { + thermal->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..d77cb3df5ade 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, static int sys_get_mode(struct thermal_zone_device *tzd, enum thermal_device_mode *mode) { - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; + *mode = tzd->mode; return 0; } diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ddf88dbe7ba2..c495b1e48ef2 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -272,9 +270,7 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, static int of_thermal_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -296,7 +292,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, mutex_unlock(&tz->lock); - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -979,7 +975,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1134,6 +1129,7 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device 2020-05-28 19:20 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz @ 2020-06-24 9:40 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:40 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Prepare for eliminating get_mode(). > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 18 ++++++---------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 21 +++++++------------ > drivers/platform/x86/acerhdf.c | 15 ++++++------- > drivers/thermal/da9062-thermal.c | 6 ++---- > drivers/thermal/imx_thermal.c | 17 +++++++-------- > .../intel/int340x_thermal/int3400_thermal.c | 12 +++-------- > .../thermal/intel/intel_quark_dts_thermal.c | 16 +++++++------- > drivers/thermal/thermal_of.c | 10 +++------ > 8 files changed, 44 insertions(+), 71 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index fb46070c66d8..4ba273f49d87 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (tz->mode != THERMAL_DEVICE_ENABLED) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > static int thermal_get_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode *mode) > { > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->mode; > + *mode = thermal->mode; > > return 0; > } > @@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > > - if (mode != tz->mode) { > - tz->mode = mode; > + if (mode != tz->thermal_zone->mode) { > + tz->thermal_zone->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->mode == THERMAL_DEVICE_ENABLED ? > + tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? > "Enable" : "Disable")); > acpi_thermal_check(tz); > } > @@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > goto remove_dev_link; > } > > - tz->mode = THERMAL_DEVICE_ENABLED; > + tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..aa082e8a0b13 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode *mode) > { > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > + *mode = tzdev->mode; > > return 0; > } > @@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > else > tzdev->polling_delay = 0; > > + tzdev->mode = mode; > mutex_unlock(&tzdev->lock); > > - thermal->mode = mode; > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -469,9 +465,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > enum thermal_device_mode *mode) > { > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > + *mode = tzdev->mode; > > return 0; > } > @@ -489,9 +483,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > else > tzdev->polling_delay = 0; > > + tzdev->mode = mode; > + > mutex_unlock(&tzdev->lock); > > - tz->mode = mode; > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -765,7 +760,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > + module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -881,7 +876,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > + gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -1050,7 +1045,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > + thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 830a8b060e74..97b288485837 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -68,7 +68,6 @@ static int kernelmode = 1; > #else > static int kernelmode; > #endif > -static enum thermal_device_mode thermal_mode; > > static unsigned int interval = 10; > static unsigned int fanon = 60000; > @@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > - thermal_mode = THERMAL_DEVICE_DISABLED; > - if (thz_dev) > + if (thz_dev) { > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > thz_dev->polling_delay = 0; > + } > pr_notice("kernel mode fan control OFF\n"); > } > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > - thermal_mode = THERMAL_DEVICE_ENABLED; > + thz_dev->mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > @@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = thermal_mode; > + *mode = thermal->mode; > > return 0; > } > @@ -741,8 +741,6 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > - thermal_mode = kernelmode ? > - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > @@ -750,6 +748,9 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(thz_dev)) > return -EINVAL; > > + thz_dev->mode = kernelmode ? > + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > + > if (strcmp(thz_dev->governor->name, > acerhdf_zone_params.governor_name)) { > pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..a14c7981c7c7 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > static int da9062_thermal_get_mode(struct thermal_zone_device *z, > enum thermal_device_mode *mode) > { > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > + *mode = z->mode; > return 0; > } > > @@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > @@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) > ret = PTR_ERR(thermal->zone); > goto err; > } > + thermal->zone->mode = THERMAL_DEVICE_ENABLED; > > dev_dbg(&pdev->dev, > "TJUNC temperature polling period set at %d ms\n", > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..9a1114d721b6 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > static int imx_get_mode(struct thermal_zone_device *tz, > enum thermal_device_mode *mode) > { > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > + *mode = tz->mode; > > return 0; > } > @@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > + tz->mode = mode; > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + data->tz->mode = THERMAL_DEVICE_DISABLED; > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e84faaadff87..f65b2fc09198 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -48,7 +48,6 @@ struct int3400_thermal_priv { > struct acpi_device *adev; > struct platform_device *pdev; > struct thermal_zone_device *thermal; > - enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode *mode) > { > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > + *mode = thermal->mode; > > return 0; > } > @@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (mode != priv->mode) { > - priv->mode = mode; > + if (mode != thermal->mode) { > + thermal->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > priv->current_uuid_index, > mode == THERMAL_DEVICE_ENABLED); > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..d77cb3df5ade 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > static int sys_get_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode *mode) > { > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > + *mode = tzd->mode; > return 0; > } > > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index ddf88dbe7ba2..c495b1e48ef2 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -272,9 +270,7 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > static int of_thermal_get_mode(struct thermal_zone_device *tz, > enum thermal_device_mode *mode) > { > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > + *mode = tz->mode; > > return 0; > } > @@ -296,7 +292,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > > mutex_unlock(&tz->lock); > > - data->mode = mode; > + tz->mode = mode; > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -979,7 +975,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1134,6 +1129,7 @@ int __init of_parse_thermal_zones(void) > of_thermal_free_zone(tz); > /* attempting to build remaining zones still */ > } > + zone->mode = THERMAL_DEVICE_DISABLED; > } > of_node_put(np); > > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 05/11] thermal: remove get_mode() operation of drivers 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (3 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 9:47 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz ` (12 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel get_mode() is now redundant, as the state is stored in struct thermal_zone_device. Consequently the "mode" attribute in sysfs can always be visible, because it is always possible to get the mode from struct tzd. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 9 ------ .../ethernet/mellanox/mlxsw/core_thermal.c | 19 ------------ drivers/platform/x86/acerhdf.c | 12 -------- drivers/thermal/da9062-thermal.c | 8 ----- drivers/thermal/imx_thermal.c | 9 ------ .../intel/int340x_thermal/int3400_thermal.c | 9 ------ .../thermal/intel/intel_quark_dts_thermal.c | 8 ----- drivers/thermal/thermal_core.c | 7 +---- drivers/thermal/thermal_of.c | 9 ------ drivers/thermal/thermal_sysfs.c | 30 ++----------------- include/linux/thermal.h | 2 -- 11 files changed, 3 insertions(+), 119 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 4ba273f49d87..592be97c4456 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,14 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -847,7 +839,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index aa082e8a0b13..6e26678ac312 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,14 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -403,7 +395,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -462,14 +453,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -591,7 +574,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -630,7 +612,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 97b288485837..32c5fe16b7f7 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,17 +413,6 @@ static inline void acerhdf_enable_kernelmode(void) pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = thermal->mode; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -490,7 +479,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a14c7981c7c7..a7ac8afb063e 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -120,13 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - *mode = z->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -179,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 9a1114d721b6..2c7ee5da608a 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,14 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -464,7 +456,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index f65b2fc09198..9a622aaf29dd 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,14 +377,6 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -412,7 +404,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d77cb3df5ade..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -308,13 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - *mode = tzd->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -336,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b71196eaf90e..14d3b1b94c4f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1456,7 +1456,6 @@ static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { struct thermal_zone_device *tz; - enum thermal_device_mode tz_mode; switch (mode) { case PM_HIBERNATION_PREPARE: @@ -1469,11 +1468,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); - - if (tz_mode == THERMAL_DEVICE_DISABLED) + if (tz->mode == THERMAL_DEVICE_DISABLED) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index c495b1e48ef2..ba65d48a48cb 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,14 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -389,7 +381,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..096370977068 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,18 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; - - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" - : "disabled"); + return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? + "enabled" : "disabled"); } static ssize_t @@ -428,30 +419,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f91d7f04512..a808f6fa2777 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 05/11] thermal: remove get_mode() operation of drivers 2020-05-28 19:20 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz @ 2020-06-24 9:47 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:47 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > get_mode() is now redundant, as the state is stored in struct > thermal_zone_device. > > Consequently the "mode" attribute in sysfs can always be visible, because > it is always possible to get the mode from struct tzd. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> The side-effect of splitting the v3 is that some devices will be marked in sysfs as disabled (however they are in reality enabled) after applying this patch (it gets fixed by patch #08). I think that we can live with that so: Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 9 ------ > .../ethernet/mellanox/mlxsw/core_thermal.c | 19 ------------ > drivers/platform/x86/acerhdf.c | 12 -------- > drivers/thermal/da9062-thermal.c | 8 ----- > drivers/thermal/imx_thermal.c | 9 ------ > .../intel/int340x_thermal/int3400_thermal.c | 9 ------ > .../thermal/intel/intel_quark_dts_thermal.c | 8 ----- > drivers/thermal/thermal_core.c | 7 +---- > drivers/thermal/thermal_of.c | 9 ------ > drivers/thermal/thermal_sysfs.c | 30 ++----------------- > include/linux/thermal.h | 2 -- > 11 files changed, 3 insertions(+), 119 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 4ba273f49d87..592be97c4456 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -525,14 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - *mode = thermal->mode; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > @@ -847,7 +839,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index aa082e8a0b13..6e26678ac312 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -275,14 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - *mode = tzdev->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -403,7 +395,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -462,14 +453,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - *mode = tzdev->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -591,7 +574,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -630,7 +612,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 97b288485837..32c5fe16b7f7 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -413,17 +413,6 @@ static inline void acerhdf_enable_kernelmode(void) > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = thermal->mode; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -490,7 +479,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index a14c7981c7c7..a7ac8afb063e 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -120,13 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - *mode = z->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -179,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index 9a1114d721b6..2c7ee5da608a 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -330,14 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - *mode = tz->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -464,7 +456,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index f65b2fc09198..9a622aaf29dd 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -377,14 +377,6 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - *mode = thermal->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > @@ -412,7 +404,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d77cb3df5ade..c4879b4bfbf1 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -308,13 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - *mode = tzd->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -336,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index b71196eaf90e..14d3b1b94c4f 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1456,7 +1456,6 @@ static int thermal_pm_notify(struct notifier_block *nb, > unsigned long mode, void *_unused) > { > struct thermal_zone_device *tz; > - enum thermal_device_mode tz_mode; > > switch (mode) { > case PM_HIBERNATION_PREPARE: > @@ -1469,11 +1468,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > - > - if (tz_mode == THERMAL_DEVICE_DISABLED) > + if (tz->mode == THERMAL_DEVICE_DISABLED) > continue; > > thermal_zone_device_init(tz); > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index c495b1e48ef2..ba65d48a48cb 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -267,14 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - *mode = tz->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -389,7 +381,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..096370977068 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -49,18 +49,9 @@ static ssize_t > mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > - enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > - > - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > - : "disabled"); > + return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? > + "enabled" : "disabled"); > } > > static ssize_t > @@ -428,30 +419,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 5f91d7f04512..a808f6fa2777 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 06/11] thermal: Add mode helpers 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (4 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 9:49 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz ` (11 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for making the drivers not access tzd's private members. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 13 +++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14d3b1b94c4f..f2a5c5ee3455 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + /* do nothing if mode isn't changing */ + if (mode == tz->mode) { + mutex_unlock(&tz->lock); + + return ret; + } + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + if (!ret) + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + +int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} +EXPORT_SYMBOL(thermal_zone_device_enable); + +int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} +EXPORT_SYMBOL(thermal_zone_device_disable); + +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode == THERMAL_DEVICE_ENABLED; +} +EXPORT_SYMBOL(thermal_zone_device_is_enabled); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/include/linux/thermal.h b/include/linux/thermal.h index a808f6fa2777..df013c39ba9b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); void thermal_cdev_update(struct thermal_cooling_device *); void thermal_notify_framework(struct thermal_zone_device *, int); +int thermal_zone_device_enable(struct thermal_zone_device *tz); +int thermal_zone_device_disable(struct thermal_zone_device *tz); +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) static inline void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { } + +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ return -ENODEV; } #endif /* CONFIG_THERMAL */ #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 06/11] thermal: Add mode helpers 2020-05-28 19:20 ` [PATCH v4 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-06-24 9:49 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:49 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Prepare for making the drivers not access tzd's private members. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ > include/linux/thermal.h | 13 +++++++++ > 2 files changed, 66 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 14d3b1b94c4f..f2a5c5ee3455 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + int ret = 0; > + > + mutex_lock(&tz->lock); > + > + /* do nothing if mode isn't changing */ > + if (mode == tz->mode) { > + mutex_unlock(&tz->lock); > + > + return ret; > + } > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + if (!ret) > + tz->mode = mode; > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} > + > +int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > +EXPORT_SYMBOL(thermal_zone_device_enable); > + > +int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > +EXPORT_SYMBOL(thermal_zone_device_disable); > + > +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode == THERMAL_DEVICE_ENABLED; > +} > +EXPORT_SYMBOL(thermal_zone_device_is_enabled); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index a808f6fa2777..df013c39ba9b 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); > > void thermal_cdev_update(struct thermal_cooling_device *); > void thermal_notify_framework(struct thermal_zone_device *, int); > +int thermal_zone_device_enable(struct thermal_zone_device *tz); > +int thermal_zone_device_disable(struct thermal_zone_device *tz); > +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); > #else > static inline struct thermal_zone_device *thermal_zone_device_register( > const char *type, int trips, int mask, void *devdata, > @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) > static inline void thermal_notify_framework(struct thermal_zone_device *tz, > int trip) > { } > + > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ return -ENODEV; } > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ return -ENODEV; } > + > +static inline int > +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) > +{ return -ENODEV; } > #endif /* CONFIG_THERMAL */ > > #endif /* __THERMAL_H__ */ > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 07/11] thermal: Use mode helpers in drivers 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (5 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 9:51 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz ` (10 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). Consequently, all set_mode() implementations in drivers: - can stop modifying tzd's "mode" member, - shall stop taking tzd's lock, as it is taken in the helpers - shall stop calling thermal_zone_device_update() as it is called in the helpers - can assume they are called when the mode truly changes, so checks to verify that can be dropped Not providing set_mode() by a driver no longer prevents the core from being able to set tzd's mode, so the relevant check in mode_store() is removed. Other comments: - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we return from set_mode(), so use function parameter in thermal_set_mode() instead, no need to call acpi_thermal_check() in set_mode() - thermal/imx_thermal.c: regmap writes and mode assignment are done in thermal_zone_device_{en|dis}able() and set_mode() callback - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a part of set_mode() callback, so they don't need to modify tzd->mode, and don't need to fall back to the opposite mode if unsuccessful, as the return value will be propagated to thermal_zone_device_{en|dis}able() and ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). - thermal/of-thermal.c: no need to set zone->mode to DISABLED in of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 21 ++++++----- .../ethernet/mellanox/mlxsw/core_thermal.c | 37 +++++++++---------- drivers/platform/x86/acerhdf.c | 17 +++++---- drivers/thermal/da9062-thermal.c | 6 ++- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 33 +++++++---------- .../intel/int340x_thermal/int3400_thermal.c | 5 +-- .../thermal/intel/intel_quark_dts_thermal.c | 18 ++------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_of.c | 10 +---- drivers/thermal/thermal_sysfs.c | 11 ++---- 13 files changed, 80 insertions(+), 98 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 592be97c4456..52b6cda1bcc3 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) + if (!thermal_zone_device_is_enabled(tz->thermal_zone)) return; thermal_zone_device_update(tz->thermal_zone, @@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->thermal_zone->mode) { - tz->thermal_zone->mode = mode; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - acpi_thermal_check(tz); - } + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%s kernel ACPI thermal control\n", + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); + return 0; } @@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; + result = thermal_zone_device_enable(tz->thermal_zone); + if (result) + goto acpi_bus_detach; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; +acpi_bus_detach: + acpi_bus_detach_private_data(tz->device->handle); remove_dev_link: sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); remove_tz_link: diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 6e26678ac312..e1d800be8bb4 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -459,19 +452,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -741,8 +726,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + err = thermal_zone_device_enable(module_tz->tzdev); + if (err) + thermal_zone_device_unregister(module_tz->tzdev); + + return err; } static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) @@ -845,6 +833,7 @@ static int mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) { char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; + int ret; snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); @@ -857,8 +846,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + ret = thermal_zone_device_enable(gearbox_tz->tzdev); + if (ret) + thermal_zone_device_unregister(gearbox_tz->tzdev); + + return ret; } static void @@ -1026,10 +1018,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; + err = thermal_zone_device_enable(thermal->tzdev); + if (err) + goto err_unreg_gearboxes; + *p_thermal = thermal; return 0; +err_unreg_gearboxes: + mlxsw_thermal_gearboxes_fini(thermal); err_unreg_modules_tzdev: mlxsw_thermal_modules_fini(thermal); err_unreg_tzdev: diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 32c5fe16b7f7..3efe749dc5a0 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) { - thz_dev->mode = THERMAL_DEVICE_DISABLED; + if (thz_dev) thz_dev->polling_delay = 0; - } + pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } @@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) static int __init acerhdf_register_thermal(void) { + int ret; + cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, &acerhdf_cooling_ops); @@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; - thz_dev->mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (kernelmode) + ret = thermal_zone_device_enable(thz_dev); + else + ret = thermal_zone_device_disable(thz_dev); + if (ret) + return ret; if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a7ac8afb063e..4d74994f160a 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } - thermal->zone->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(thermal->zone); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone device\n"); + goto err_zone; + } dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 2c7ee5da608a..53abb1be1cba 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (tz->mode == THERMAL_DEVICE_ENABLED) { + if (thermal_zone_device_is_enabled(tz)) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (tz->mode != THERMAL_DEVICE_ENABLED) { + if (!thermal_zone_device_is_enabled(tz)) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + goto thermal_zone_unregister; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev) static int __maybe_unused imx_thermal_suspend(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; + int ret; /* * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. + * down. This is done in set_mode() operation called from + * thermal_zone_device_disable() */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->measure_temp_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->power_down_mask); - data->tz->mode = THERMAL_DEVICE_DISABLED; + ret = thermal_zone_device_disable(data->tz); + if (ret) + return ret; clk_disable_unprepare(data->thermal_clk); return 0; @@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) static int __maybe_unused imx_thermal_resume(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; int ret; ret = clk_prepare_enable(data->thermal_clk); if (ret) return ret; /* Enabled thermal sensor after resume */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->power_down_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->measure_temp_mask); - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + return ret; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 9a622aaf29dd..3c0397a29b8c 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != thermal->mode) { - thermal->mode = mode; + if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); - } + evaluate_odvp(priv); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index c4879b4bfbf1..e29c3e330b17 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - if (out & QRK_DTS_ENABLE_BIT) { - tzd->mode = THERMAL_DEVICE_ENABLED; + if (out & QRK_DTS_ENABLE_BIT) return 0; - } if (!aux_entry->locked) { out |= QRK_DTS_ENABLE_BIT; @@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) QRK_DTS_REG_OFFSET_ENABLE, out); if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_ENABLED; } else { - tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - if (!(out & QRK_DTS_ENABLE_BIT)) { - tzd->mode = THERMAL_DEVICE_DISABLED; + if (!(out & QRK_DTS_ENABLE_BIT)) return 0; - } if (!aux_entry->locked) { out &= ~QRK_DTS_ENABLE_BIT; @@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_DISABLED; } else { - tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } - mutex_lock(&dts_update_mutex); - err = soc_dts_enable(aux_entry->tzone); - mutex_unlock(&dts_update_mutex); + err = thermal_zone_device_enable(aux_entry->tzone); if (err) goto err_aux_status; diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index f2a5c5ee3455..14baf0288759 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - if (tz->mode == THERMAL_DEVICE_DISABLED) + if (!thermal_zone_device_is_enabled(tz)) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ba65d48a48cb..43a516a35d64 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -541,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } - zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 096370977068..c23d67c4dc4e 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,9 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); + int enabled = thermal_zone_device_is_enabled(tz); - return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? - "enabled" : "disabled"); + return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled"); } static ssize_t @@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr, struct thermal_zone_device *tz = to_thermal_zone(dev); int result; - if (!tz->ops->set_mode) - return -EPERM; - if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 07/11] thermal: Use mode helpers in drivers 2020-05-28 19:20 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz @ 2020-06-24 9:51 ` Bartlomiej Zolnierkiewicz 2020-06-26 16:08 ` Andrzej Pietrasiewicz 0 siblings, 1 reply; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 9:51 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). > > Consequently, all set_mode() implementations in drivers: > > - can stop modifying tzd's "mode" member, > - shall stop taking tzd's lock, as it is taken in the helpers > - shall stop calling thermal_zone_device_update() as it is called in the > helpers > - can assume they are called when the mode truly changes, so checks to > verify that can be dropped > > Not providing set_mode() by a driver no longer prevents the core from > being able to set tzd's mode, so the relevant check in mode_store() is > removed. > > Other comments: > > - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we > return from set_mode(), so use function parameter in thermal_set_mode() > instead, no need to call acpi_thermal_check() in set_mode() > - thermal/imx_thermal.c: regmap writes and mode assignment are done in > thermal_zone_device_{en|dis}able() and set_mode() callback > - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a > part of set_mode() callback, so they don't need to modify tzd->mode, and > don't need to fall back to the opposite mode if unsuccessful, as the return > value will be propagated to thermal_zone_device_{en|dis}able() and > ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). > - thermal/of-thermal.c: no need to set zone->mode to DISABLED in > of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/acpi/thermal.c | 21 ++++++----- > .../ethernet/mellanox/mlxsw/core_thermal.c | 37 +++++++++---------- > drivers/platform/x86/acerhdf.c | 17 +++++---- > drivers/thermal/da9062-thermal.c | 6 ++- > drivers/thermal/hisi_thermal.c | 6 ++- > drivers/thermal/imx_thermal.c | 33 +++++++---------- > .../intel/int340x_thermal/int3400_thermal.c | 5 +-- > .../thermal/intel/intel_quark_dts_thermal.c | 18 ++------- > drivers/thermal/rockchip_thermal.c | 6 ++- > drivers/thermal/sprd_thermal.c | 6 ++- > drivers/thermal/thermal_core.c | 2 +- > drivers/thermal/thermal_of.c | 10 +---- > drivers/thermal/thermal_sysfs.c | 11 ++---- > 13 files changed, 80 insertions(+), 98 deletions(-) [...] > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 32c5fe16b7f7..3efe749dc5a0 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > - if (thz_dev) { > - thz_dev->mode = THERMAL_DEVICE_DISABLED; > + if (thz_dev) > thz_dev->polling_delay = 0; > - } > + > pr_notice("kernel mode fan control OFF\n"); > } > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > - thz_dev->mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > pr_notice("kernel mode fan control ON\n"); > } > > @@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) > > static int __init acerhdf_register_thermal(void) > { > + int ret; > + > cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, > &acerhdf_cooling_ops); > > @@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(thz_dev)) > return -EINVAL; > > - thz_dev->mode = kernelmode ? > - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > + if (kernelmode) > + ret = thermal_zone_device_enable(thz_dev); > + else > + ret = thermal_zone_device_disable(thz_dev); > + if (ret) Cleanup on error seems to be missing here. > + return ret; > > if (strcmp(thz_dev->governor->name, > acerhdf_zone_params.governor_name)) { Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 07/11] thermal: Use mode helpers in drivers 2020-06-24 9:51 ` Bartlomiej Zolnierkiewicz @ 2020-06-26 16:08 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 16:08 UTC (permalink / raw) To: Bartlomiej Zolnierkiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel Hi Bartlomiej, W dniu 24.06.2020 o 11:51, Bartlomiej Zolnierkiewicz pisze: > > On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: >> Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). >> >> Consequently, all set_mode() implementations in drivers: >> >> - can stop modifying tzd's "mode" member, >> - shall stop taking tzd's lock, as it is taken in the helpers >> - shall stop calling thermal_zone_device_update() as it is called in the >> helpers >> - can assume they are called when the mode truly changes, so checks to >> verify that can be dropped >> >> Not providing set_mode() by a driver no longer prevents the core from >> being able to set tzd's mode, so the relevant check in mode_store() is >> removed. >> >> Other comments: >> >> - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we >> return from set_mode(), so use function parameter in thermal_set_mode() >> instead, no need to call acpi_thermal_check() in set_mode() >> - thermal/imx_thermal.c: regmap writes and mode assignment are done in >> thermal_zone_device_{en|dis}able() and set_mode() callback >> - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a >> part of set_mode() callback, so they don't need to modify tzd->mode, and >> don't need to fall back to the opposite mode if unsuccessful, as the return >> value will be propagated to thermal_zone_device_{en|dis}able() and >> ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). >> - thermal/of-thermal.c: no need to set zone->mode to DISABLED in >> of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway >> >> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> >> --- >> drivers/acpi/thermal.c | 21 ++++++----- >> .../ethernet/mellanox/mlxsw/core_thermal.c | 37 +++++++++---------- >> drivers/platform/x86/acerhdf.c | 17 +++++---- >> drivers/thermal/da9062-thermal.c | 6 ++- >> drivers/thermal/hisi_thermal.c | 6 ++- >> drivers/thermal/imx_thermal.c | 33 +++++++---------- >> .../intel/int340x_thermal/int3400_thermal.c | 5 +-- >> .../thermal/intel/intel_quark_dts_thermal.c | 18 ++------- >> drivers/thermal/rockchip_thermal.c | 6 ++- >> drivers/thermal/sprd_thermal.c | 6 ++- >> drivers/thermal/thermal_core.c | 2 +- >> drivers/thermal/thermal_of.c | 10 +---- >> drivers/thermal/thermal_sysfs.c | 11 ++---- >> 13 files changed, 80 insertions(+), 98 deletions(-) > > [...] > >> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c >> index 32c5fe16b7f7..3efe749dc5a0 100644 >> --- a/drivers/platform/x86/acerhdf.c >> +++ b/drivers/platform/x86/acerhdf.c >> @@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) >> { >> acerhdf_change_fanstate(ACERHDF_FAN_AUTO); >> kernelmode = 0; >> - if (thz_dev) { >> - thz_dev->mode = THERMAL_DEVICE_DISABLED; >> + if (thz_dev) >> thz_dev->polling_delay = 0; >> - } >> + >> pr_notice("kernel mode fan control OFF\n"); >> } >> static inline void acerhdf_enable_kernelmode(void) >> { >> kernelmode = 1; >> - thz_dev->mode = THERMAL_DEVICE_ENABLED; >> >> thz_dev->polling_delay = interval*1000; >> - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); >> pr_notice("kernel mode fan control ON\n"); >> } >> >> @@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) >> >> static int __init acerhdf_register_thermal(void) >> { >> + int ret; >> + >> cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, >> &acerhdf_cooling_ops); >> >> @@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) >> if (IS_ERR(thz_dev)) >> return -EINVAL; >> >> - thz_dev->mode = kernelmode ? >> - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; >> + if (kernelmode) >> + ret = thermal_zone_device_enable(thz_dev); >> + else >> + ret = thermal_zone_device_disable(thz_dev); >> + if (ret) > > Cleanup on error seems to be missing here. It does seem so, but it is not the case. acerhdf_register_thermal() is called from acerhdf_init(). The latter checks the return value of the former and on error jumps to the err_unreg label, where thermal zone(s) is/are unregistered. Regards, Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (6 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 10:00 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz ` (9 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Some thermal zone devices never change their state, so they should be always enabled. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++++++++ drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 ++++++++- drivers/platform/x86/intel_mid_thermal.c | 6 ++++++ drivers/power/supply/power_supply_core.c | 9 +++++++-- drivers/thermal/armada_thermal.c | 6 ++++++ drivers/thermal/dove_thermal.c | 6 ++++++ .../thermal/intel/int340x_thermal/int3400_thermal.c | 5 +++++ .../intel/int340x_thermal/int340x_thermal_zone.c | 5 +++++ drivers/thermal/intel/intel_pch_thermal.c | 5 +++++ drivers/thermal/intel/intel_soc_dts_iosf.c | 3 +++ drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++++++ drivers/thermal/kirkwood_thermal.c | 7 +++++++ drivers/thermal/rcar_thermal.c | 9 ++++++++- drivers/thermal/spear_thermal.c | 7 +++++++ drivers/thermal/st/st_thermal.c | 5 +++++ drivers/thermal/thermal_of.c | 10 +++++++++- 16 files changed, 101 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c index 3de8a5e83b6c..e3510e9b21f3 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c @@ -92,6 +92,14 @@ int cxgb4_thermal_init(struct adapter *adap) ch_thermal->tzdev = NULL; return ret; } + + ret = thermal_zone_device_enable(ch_thermal->tzdev); + if (ret) { + dev_err(adap->pdev_dev, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(adap->ch_thermal.tzdev); + return ret; + } + return 0; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 418e59b7c671..0c95663bf9ed 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -733,7 +733,7 @@ static struct thermal_zone_device_ops tzone_ops = { static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) { - int i; + int i, ret; char name[16]; static atomic_t counter = ATOMIC_INIT(0); @@ -759,6 +759,13 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) return; } + ret = thermal_zone_device_enable(mvm->tz_device.tzone); + if (ret) { + IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(mvm->tz_device.tzone); + return; + } + /* 0 is a valid temperature, * so initialize the array with S16_MIN which invalid temperature */ diff --git a/drivers/platform/x86/intel_mid_thermal.c b/drivers/platform/x86/intel_mid_thermal.c index f402e2e74a38..f12f4e7bd971 100644 --- a/drivers/platform/x86/intel_mid_thermal.c +++ b/drivers/platform/x86/intel_mid_thermal.c @@ -493,6 +493,12 @@ static int mid_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(pinfo->tzd[i]); goto err; } + ret = thermal_zone_device_enable(pinfo->tzd[i]); + if (ret) { + kfree(td_info); + thermal_zone_device_unregister(pinfo->tzd[i]); + goto err; + } } pinfo->pdev = pdev; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 1a9a9fae73d3..ca64bb9e6eed 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -931,7 +931,7 @@ static struct thermal_zone_device_ops psy_tzd_ops = { static int psy_register_thermal(struct power_supply *psy) { - int i; + int i, ret; if (psy->desc->no_thermal) return 0; @@ -941,7 +941,12 @@ static int psy_register_thermal(struct power_supply *psy) if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) { psy->tzd = thermal_zone_device_register(psy->desc->name, 0, 0, psy, &psy_tzd_ops, NULL, 0, 0); - return PTR_ERR_OR_ZERO(psy->tzd); + if (IS_ERR(psy->tzd)) + return PTR_ERR(psy->tzd); + ret = thermal_zone_device_enable(psy->tzd); + if (ret) + thermal_zone_device_unregister(psy->tzd); + return ret; } } return 0; diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index 7c447cd149e7..c2ebfb5be4b3 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -874,6 +874,12 @@ static int armada_thermal_probe(struct platform_device *pdev) return PTR_ERR(tz); } + ret = thermal_zone_device_enable(tz); + if (ret) { + thermal_zone_device_unregister(tz); + return ret; + } + drvdata->type = LEGACY; drvdata->data.tz = tz; platform_set_drvdata(pdev, drvdata); diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c index 75901ced4a62..73182eb94bc0 100644 --- a/drivers/thermal/dove_thermal.c +++ b/drivers/thermal/dove_thermal.c @@ -153,6 +153,12 @@ static int dove_thermal_probe(struct platform_device *pdev) return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + return ret; + } + platform_set_drvdata(pdev, thermal); return 0; diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 3c0397a29b8c..8e8c9af7e5f4 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -485,6 +485,10 @@ static int int3400_thermal_probe(struct platform_device *pdev) goto free_art_trt; } + result = thermal_zone_device_enable(priv->thermal); + if (result) + goto free_tzd; + priv->rel_misc_dev_res = acpi_thermal_rel_misc_device_add( priv->adev->handle); @@ -518,6 +522,7 @@ static int int3400_thermal_probe(struct platform_device *pdev) free_rel_misc: if (!priv->rel_misc_dev_res) acpi_thermal_rel_misc_device_remove(priv->adev->handle); +free_tzd: thermal_zone_device_unregister(priv->thermal); free_art_trt: kfree(priv->trts); diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..6e479deff76b 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -259,9 +259,14 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, ret = PTR_ERR(int34x_thermal_zone->zone); goto err_thermal_zone; } + ret = thermal_zone_device_enable(int34x_thermal_zone->zone); + if (ret) + goto err_enable; return int34x_thermal_zone; +err_enable: + thermal_zone_device_unregister(int34x_thermal_zone->zone); err_thermal_zone: acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table); kfree(int34x_thermal_zone->aux_trips); diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index 56401fd4708d..65702094f3d3 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -352,9 +352,14 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, err = PTR_ERR(ptd->tzd); goto error_cleanup; } + err = thermal_zone_device_enable(ptd->tzd); + if (err) + goto err_unregister; return 0; +err_unregister: + thermal_zone_device_unregister(ptd->tzd); error_cleanup: iounmap(ptd->hw_base); error_release: diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index f75271b669c6..4f1a2f7c016c 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -329,6 +329,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ret = PTR_ERR(dts->tzone); goto err_ret; } + ret = thermal_zone_device_enable(dts->tzone); + if (ret) + goto err_enable; ret = soc_dts_enable(id); if (ret) diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..b81c33202f41 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -363,6 +363,12 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) kfree(zonedev); return err; } + err = thermal_zone_device_enable(zonedev->tzone); + if (err) { + thermal_zone_device_unregister(zonedev->tzone); + kfree(zonedev); + return err; + } /* 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); diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c index 189b675cf14d..7fb6e476c82a 100644 --- a/drivers/thermal/kirkwood_thermal.c +++ b/drivers/thermal/kirkwood_thermal.c @@ -65,6 +65,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) struct thermal_zone_device *thermal = NULL; struct kirkwood_thermal_priv *priv; struct resource *res; + int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -82,6 +83,12 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) "Failed to register thermal zone device\n"); return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + dev_err(&pdev->dev, "Failed to enable thermal zone device\n"); + return ret; + } platform_set_drvdata(pdev, thermal); diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 46aeb28b4e90..787710bb88fe 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -550,12 +550,19 @@ static int rcar_thermal_probe(struct platform_device *pdev) priv->zone = devm_thermal_zone_of_sensor_register( dev, i, priv, &rcar_thermal_zone_of_ops); - else + else { priv->zone = thermal_zone_device_register( "rcar_thermal", 1, 0, priv, &rcar_thermal_zone_ops, NULL, 0, idle); + + ret = thermal_zone_device_enable(priv->zone); + if (ret) { + thermal_zone_device_unregister(priv->zone); + priv->zone = ERR_PTR(ret); + } + } if (IS_ERR(priv->zone)) { dev_err(dev, "can't register thermal zone\n"); ret = PTR_ERR(priv->zone); diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c index f68f581fd669..ee33ed692e4f 100644 --- a/drivers/thermal/spear_thermal.c +++ b/drivers/thermal/spear_thermal.c @@ -131,6 +131,11 @@ static int spear_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(spear_thermal); goto disable_clk; } + ret = thermal_zone_device_enable(spear_thermal); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone\n"); + goto unregister_tzd; + } platform_set_drvdata(pdev, spear_thermal); @@ -139,6 +144,8 @@ static int spear_thermal_probe(struct platform_device *pdev) return 0; +unregister_tzd: + thermal_zone_device_unregister(spear_thermal); disable_clk: clk_disable(stdev->clk); diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c index b928ca6a289b..1276b95604fe 100644 --- a/drivers/thermal/st/st_thermal.c +++ b/drivers/thermal/st/st_thermal.c @@ -246,11 +246,16 @@ int st_thermal_register(struct platform_device *pdev, ret = PTR_ERR(sensor->thermal_dev); goto sensor_off; } + ret = thermal_zone_device_enable(sensor->thermal_dev); + if (ret) + goto tzd_unregister; platform_set_drvdata(pdev, sensor); return 0; +tzd_unregister: + thermal_zone_device_unregister(sensor->thermal_dev); sensor_off: st_thermal_sensor_off(sensor); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 43a516a35d64..011fd7f0a01e 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -1066,7 +1066,7 @@ int __init of_parse_thermal_zones(void) for_each_available_child_of_node(np, child) { struct thermal_zone_device *zone; struct thermal_zone_params *tzp; - int i, mask = 0; + int i, ret, mask = 0; u32 prop; tz = thermal_of_build_thermal_zone(child); @@ -1113,6 +1113,14 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + ret = thermal_zone_device_enable(zone); + if (ret) { + thermal_zone_device_unregister(zone); + pr_err("Failed to enable thermal zone\n"); + kfree(tzp); + kfree(ops); + of_thermal_free_zone(tz); + } } of_node_put(np); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices 2020-05-28 19:20 ` [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz @ 2020-06-24 10:00 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 10:00 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Some thermal zone devices never change their state, so they should be > always enabled. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++++++++ > drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 ++++++++- > drivers/platform/x86/intel_mid_thermal.c | 6 ++++++ > drivers/power/supply/power_supply_core.c | 9 +++++++-- > drivers/thermal/armada_thermal.c | 6 ++++++ > drivers/thermal/dove_thermal.c | 6 ++++++ > .../thermal/intel/int340x_thermal/int3400_thermal.c | 5 +++++ > .../intel/int340x_thermal/int340x_thermal_zone.c | 5 +++++ > drivers/thermal/intel/intel_pch_thermal.c | 5 +++++ > drivers/thermal/intel/intel_soc_dts_iosf.c | 3 +++ > drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++++++ > drivers/thermal/kirkwood_thermal.c | 7 +++++++ > drivers/thermal/rcar_thermal.c | 9 ++++++++- > drivers/thermal/spear_thermal.c | 7 +++++++ > drivers/thermal/st/st_thermal.c | 5 +++++ > drivers/thermal/thermal_of.c | 10 +++++++++- > 16 files changed, 101 insertions(+), 5 deletions(-) [...] > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 3c0397a29b8c..8e8c9af7e5f4 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -485,6 +485,10 @@ static int int3400_thermal_probe(struct platform_device *pdev) > goto free_art_trt; > } > > + result = thermal_zone_device_enable(priv->thermal); I'm not sure about correctness of this addition. This driver contains ->set_mode but doesn't call it on initialization (in v3 it was using THERMAL_DEVICE_DISABLED as .initial_mode parameter). > + if (result) > + goto free_tzd; > + > priv->rel_misc_dev_res = acpi_thermal_rel_misc_device_add( > priv->adev->handle); > > @@ -518,6 +522,7 @@ static int int3400_thermal_probe(struct platform_device *pdev) > free_rel_misc: > if (!priv->rel_misc_dev_res) > acpi_thermal_rel_misc_device_remove(priv->adev->handle); > +free_tzd: > thermal_zone_device_unregister(priv->thermal); > free_art_trt: > kfree(priv->trts); [...] > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index 43a516a35d64..011fd7f0a01e 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -1066,7 +1066,7 @@ int __init of_parse_thermal_zones(void) > for_each_available_child_of_node(np, child) { > struct thermal_zone_device *zone; > struct thermal_zone_params *tzp; > - int i, mask = 0; > + int i, ret, mask = 0; > u32 prop; > > tz = thermal_of_build_thermal_zone(child); > @@ -1113,6 +1113,14 @@ int __init of_parse_thermal_zones(void) > of_thermal_free_zone(tz); > /* attempting to build remaining zones still */ > } > + ret = thermal_zone_device_enable(zone); This doesn't seem correct as it is done too early and there is already proper thermal_zone_device_enable() call in thermal_zone_of_sensor_register(). > + if (ret) { > + thermal_zone_device_unregister(zone); > + pr_err("Failed to enable thermal zone\n"); > + kfree(tzp); > + kfree(ops); > + of_thermal_free_zone(tz); > + } > } > of_node_put(np); > Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (7 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 10:02 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz ` (8 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14baf0288759..e9c0b990e4a9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -301,13 +301,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return !thermal_zone_device_is_enabled(tz); +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -517,6 +526,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices 2020-05-28 19:20 ` [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-06-24 10:02 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 10:02 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Polling DISABLED devices is not desired, as all such "disabled" devices > are meant to be handled by userspace. This patch introduces and uses > should_stop_polling() to decide whether the device should be polled or not. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/thermal/thermal_core.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 14baf0288759..e9c0b990e4a9 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -301,13 +301,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, > cancel_delayed_work(&tz->poll_queue); > } > > +static inline bool should_stop_polling(struct thermal_zone_device *tz) > +{ > + return !thermal_zone_device_is_enabled(tz); > +} > + > static void monitor_thermal_zone(struct thermal_zone_device *tz) > { > + bool stop; > + > + stop = should_stop_polling(tz); > + > mutex_lock(&tz->lock); > > - if (tz->passive) > + if (!stop && tz->passive) > thermal_zone_device_set_polling(tz, tz->passive_delay); > - else if (tz->polling_delay) > + else if (!stop && tz->polling_delay) > thermal_zone_device_set_polling(tz, tz->polling_delay); > else > thermal_zone_device_set_polling(tz, 0); > @@ -517,6 +526,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, > { > int count; > > + if (should_stop_polling(tz)) > + return; > + > if (atomic_read(&in_suspend)) > return; > > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (8 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz ` (7 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Setting polling_delay is now done at thermal_core level (by not polling DISABLED devices), so no need to repeat this code. int340x: Checking for an impossible enum value is unnecessary. acpi/thermal: It only prints debug messages. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 26 ---------------- .../ethernet/mellanox/mlxsw/core_thermal.c | 30 ------------------- drivers/platform/x86/acerhdf.c | 3 -- drivers/thermal/imx_thermal.c | 6 ---- .../intel/int340x_thermal/int3400_thermal.c | 4 --- drivers/thermal/thermal_of.c | 18 ----------- 6 files changed, 87 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 52b6cda1bcc3..29a2b73fe035 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,31 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - if (mode != THERMAL_DEVICE_DISABLED && - mode != THERMAL_DEVICE_ENABLED) - return -EINVAL; - /* - * enable/disable thermal management from ACPI thermal driver - */ - if (mode == THERMAL_DEVICE_DISABLED) - pr_warn("thermal zone will be disabled\n"); - - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - - return 0; -} - static int thermal_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { @@ -836,7 +811,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index e1d800be8bb4..c7f334383912 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,19 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, int *p_temp) { @@ -388,7 +375,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, .get_trip_temp = mlxsw_thermal_get_trip_temp, @@ -446,20 +432,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - struct mlxsw_thermal *thermal = tz->parent; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, int *p_temp) { @@ -559,7 +531,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, @@ -597,7 +568,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 3efe749dc5a0..d33a70af0869 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,8 +397,6 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) - thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); } @@ -406,7 +404,6 @@ static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->polling_delay = interval*1000; pr_notice("kernel mode fan control ON\n"); } diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 53abb1be1cba..a02398118d88 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -338,9 +338,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, const struct thermal_soc_data *soc_data = data->socdata; if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = IMX_POLLING_DELAY; - tz->passive_delay = IMX_PASSIVE_DELAY; - regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->power_down_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -356,9 +353,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, regmap_write(map, soc_data->sensor_ctrl + REG_SET, soc_data->power_down_mask); - tz->polling_delay = 0; - tz->passive_delay = 0; - if (data->irq_enabled) { disable_irq(data->irq); data->irq_enabled = false; diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 8e8c9af7e5f4..9af862ab9f65 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -386,10 +386,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, if (!priv) return -EINVAL; - if (mode != THERMAL_DEVICE_ENABLED && - mode != THERMAL_DEVICE_DISABLED) - return -EINVAL; - if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 011fd7f0a01e..8a6272570347 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,22 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) -{ - struct __thermal_zone *data = tz->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = data->polling_delay; - tz->passive_delay = data->passive_delay; - } else { - tz->polling_delay = 0; - tz->passive_delay = 0; - } - - return 0; -} - static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, enum thermal_trip_type *type) { @@ -374,8 +358,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .set_mode = of_thermal_set_mode, - .get_trip_type = of_thermal_get_trip_type, .get_trip_temp = of_thermal_get_trip_temp, .set_trip_temp = of_thermal_set_trip_temp, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods 2020-05-28 19:20 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz @ 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 10:03 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > Setting polling_delay is now done at thermal_core level (by not polling > DISABLED devices), so no need to repeat this code. > > int340x: Checking for an impossible enum value is unnecessary. > acpi/thermal: It only prints debug messages. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 26 ---------------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 30 ------------------- > drivers/platform/x86/acerhdf.c | 3 -- > drivers/thermal/imx_thermal.c | 6 ---- > .../intel/int340x_thermal/int3400_thermal.c | 4 --- > drivers/thermal/thermal_of.c | 18 ----------- > 6 files changed, 87 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 52b6cda1bcc3..29a2b73fe035 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -525,31 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_set_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - if (mode != THERMAL_DEVICE_DISABLED && > - mode != THERMAL_DEVICE_ENABLED) > - return -EINVAL; > - /* > - * enable/disable thermal management from ACPI thermal driver > - */ > - if (mode == THERMAL_DEVICE_DISABLED) > - pr_warn("thermal zone will be disabled\n"); > - > - ACPI_DEBUG_PRINT((ACPI_DB_INFO, > - "%s kernel ACPI thermal control\n", > - mode == THERMAL_DEVICE_ENABLED ? > - "Enable" : "Disable")); > - > - return 0; > -} > - > static int thermal_get_trip_type(struct thermal_zone_device *thermal, > int trip, enum thermal_trip_type *type) > { > @@ -836,7 +811,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > .get_crit_temp = thermal_get_crit_temp, > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index e1d800be8bb4..c7f334383912 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -275,19 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - if (mode == THERMAL_DEVICE_ENABLED) > - tzdev->polling_delay = thermal->polling_delay; > - else > - tzdev->polling_delay = 0; > - > - return 0; > -} > - > static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, > int *p_temp) > { > @@ -388,7 +375,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > .get_trip_temp = mlxsw_thermal_get_trip_temp, > @@ -446,20 +432,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > - enum thermal_device_mode mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - struct mlxsw_thermal *thermal = tz->parent; > - > - if (mode == THERMAL_DEVICE_ENABLED) > - tzdev->polling_delay = thermal->polling_delay; > - else > - tzdev->polling_delay = 0; > - > - return 0; > -} > - > static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, > int *p_temp) > { > @@ -559,7 +531,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > .get_trip_temp = mlxsw_thermal_module_trip_temp_get, > @@ -597,7 +568,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > .get_trip_temp = mlxsw_thermal_module_trip_temp_get, > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 3efe749dc5a0..d33a70af0869 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -397,8 +397,6 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > - if (thz_dev) > - thz_dev->polling_delay = 0; > > pr_notice("kernel mode fan control OFF\n"); > } > @@ -406,7 +404,6 @@ static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > > - thz_dev->polling_delay = interval*1000; > pr_notice("kernel mode fan control ON\n"); > } > > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index 53abb1be1cba..a02398118d88 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -338,9 +338,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > const struct thermal_soc_data *soc_data = data->socdata; > > if (mode == THERMAL_DEVICE_ENABLED) { > - tz->polling_delay = IMX_POLLING_DELAY; > - tz->passive_delay = IMX_PASSIVE_DELAY; > - > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->power_down_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -356,9 +353,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > soc_data->power_down_mask); > > - tz->polling_delay = 0; > - tz->passive_delay = 0; > - > if (data->irq_enabled) { > disable_irq(data->irq); > data->irq_enabled = false; > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 8e8c9af7e5f4..9af862ab9f65 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -386,10 +386,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > if (!priv) > return -EINVAL; > > - if (mode != THERMAL_DEVICE_ENABLED && > - mode != THERMAL_DEVICE_DISABLED) > - return -EINVAL; > - > if (mode != thermal->mode) > result = int3400_thermal_run_osc(priv->adev->handle, > priv->current_uuid_index, > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index 011fd7f0a01e..8a6272570347 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -267,22 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_set_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - if (mode == THERMAL_DEVICE_ENABLED) { > - tz->polling_delay = data->polling_delay; > - tz->passive_delay = data->passive_delay; > - } else { > - tz->polling_delay = 0; > - tz->passive_delay = 0; > - } > - > - return 0; > -} > - > static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, > enum thermal_trip_type *type) > { > @@ -374,8 +358,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .set_mode = of_thermal_set_mode, > - > .get_trip_type = of_thermal_get_trip_type, > .get_trip_temp = of_thermal_get_trip_temp, > .set_trip_temp = of_thermal_set_trip_temp, > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (9 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz @ 2020-05-28 19:20 ` Andrzej Pietrasiewicz 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 2020-06-01 11:36 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Peter Kästle ` (6 subsequent siblings) 17 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-28 19:20 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel set_mode() is only called when tzd's mode is about to change. Actual setting is performed in thermal_core, in thermal_zone_device_set_mode(). The meaning of set_mode() callback is actually to notify the driver about the mode being changed and giving the driver a chance to oppose such change. To better reflect the purpose of the method rename it to change_mode() Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/platform/x86/acerhdf.c | 6 +++--- drivers/thermal/imx_thermal.c | 8 ++++---- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 6 +++--- drivers/thermal/intel/intel_quark_dts_thermal.c | 6 +++--- drivers/thermal/thermal_core.c | 4 ++-- include/linux/thermal.h | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index d33a70af0869..63b562e06d5c 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,8 +413,8 @@ static inline void acerhdf_enable_kernelmode(void) * the temperature and the fan. * disabled: the BIOS takes control of the fan. */ -static int acerhdf_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int acerhdf_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { if (mode == THERMAL_DEVICE_DISABLED && kernelmode) acerhdf_revert_to_bios_mode(); @@ -473,7 +473,7 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .set_mode = acerhdf_set_mode, + .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, diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index a02398118d88..9700ae39feb7 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,8 +330,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) +static int imx_change_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) { struct imx_thermal_data *data = tz->devdata; struct regmap *map = data->tempmon; @@ -447,7 +447,7 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .set_mode = imx_set_mode, + .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, @@ -860,7 +860,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. This is done in set_mode() operation called from + * down. This is done in change_mode() operation called from * thermal_zone_device_disable() */ ret = thermal_zone_device_disable(data->tz); diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 9af862ab9f65..58870d215471 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,8 +377,8 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int int3400_thermal_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; int result = 0; @@ -399,7 +399,7 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .set_mode = int3400_thermal_set_mode, + .change_mode = int3400_thermal_change_mode, }; static struct thermal_zone_params int3400_thermal_params = { diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index e29c3e330b17..3eafc6b0e6c3 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -298,8 +298,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_set_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode mode) +static int sys_change_mode(struct thermal_zone_device *tzd, + enum thermal_device_mode mode) { int ret; @@ -319,7 +319,7 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .set_mode = sys_set_mode, + .change_mode = sys_change_mode, }; static void free_soc_dts(struct soc_sensor_entry *aux_entry) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e9c0b990e4a9..c00edae7839e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -482,8 +482,8 @@ int thermal_zone_device_set_mode(struct thermal_zone_device *tz, return ret; } - if (tz->ops->set_mode) - ret = tz->ops->set_mode(tz, mode); + if (tz->ops->change_mode) + ret = tz->ops->change_mode(tz, mode); if (!ret) tz->mode = mode; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index df013c39ba9b..b9efaa780d88 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,7 +76,7 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*set_mode) (struct thermal_zone_device *, + int (*change_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, enum thermal_trip_type *); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() 2020-05-28 19:20 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz @ 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-06-24 10:03 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, kernel On 5/28/20 9:20 PM, Andrzej Pietrasiewicz wrote: > set_mode() is only called when tzd's mode is about to change. Actual > setting is performed in thermal_core, in thermal_zone_device_set_mode(). > The meaning of set_mode() callback is actually to notify the driver about > the mode being changed and giving the driver a chance to oppose such > change. > > To better reflect the purpose of the method rename it to change_mode() > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/platform/x86/acerhdf.c | 6 +++--- > drivers/thermal/imx_thermal.c | 8 ++++---- > drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 6 +++--- > drivers/thermal/intel/intel_quark_dts_thermal.c | 6 +++--- > drivers/thermal/thermal_core.c | 4 ++-- > include/linux/thermal.h | 2 +- > 6 files changed, 16 insertions(+), 16 deletions(-) > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index d33a70af0869..63b562e06d5c 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -413,8 +413,8 @@ static inline void acerhdf_enable_kernelmode(void) > * the temperature and the fan. > * disabled: the BIOS takes control of the fan. > */ > -static int acerhdf_set_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode mode) > +static int acerhdf_change_mode(struct thermal_zone_device *thermal, > + enum thermal_device_mode mode) > { > if (mode == THERMAL_DEVICE_DISABLED && kernelmode) > acerhdf_revert_to_bios_mode(); > @@ -473,7 +473,7 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .set_mode = acerhdf_set_mode, > + .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, > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index a02398118d88..9700ae39feb7 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -330,8 +330,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_set_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode mode) > +static int imx_change_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > { > struct imx_thermal_data *data = tz->devdata; > struct regmap *map = data->tempmon; > @@ -447,7 +447,7 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .set_mode = imx_set_mode, > + .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, > @@ -860,7 +860,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > * Need to disable thermal sensor, otherwise, when thermal core > * try to get temperature before thermal sensor resume, a wrong > * temperature will be read as the thermal sensor is powered > - * down. This is done in set_mode() operation called from > + * down. This is done in change_mode() operation called from > * thermal_zone_device_disable() > */ > ret = thermal_zone_device_disable(data->tz); > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 9af862ab9f65..58870d215471 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -377,8 +377,8 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode mode) > +static int int3400_thermal_change_mode(struct thermal_zone_device *thermal, > + enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > int result = 0; > @@ -399,7 +399,7 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .set_mode = int3400_thermal_set_mode, > + .change_mode = int3400_thermal_change_mode, > }; > > static struct thermal_zone_params int3400_thermal_params = { > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index e29c3e330b17..3eafc6b0e6c3 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -298,8 +298,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_set_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode mode) > +static int sys_change_mode(struct thermal_zone_device *tzd, > + enum thermal_device_mode mode) > { > int ret; > > @@ -319,7 +319,7 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .set_mode = sys_set_mode, > + .change_mode = sys_change_mode, > }; > > static void free_soc_dts(struct soc_sensor_entry *aux_entry) > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index e9c0b990e4a9..c00edae7839e 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -482,8 +482,8 @@ int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > return ret; > } > > - if (tz->ops->set_mode) > - ret = tz->ops->set_mode(tz, mode); > + if (tz->ops->change_mode) > + ret = tz->ops->change_mode(tz, mode); > > if (!ret) > tz->mode = mode; > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index df013c39ba9b..b9efaa780d88 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,7 +76,7 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*set_mode) (struct thermal_zone_device *, > + int (*change_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > enum thermal_trip_type *); > ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (10 preceding siblings ...) 2020-05-28 19:20 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz @ 2020-06-01 11:36 ` Peter Kästle 2020-06-01 11:36 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Peter Kästle ` (5 subsequent siblings) 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:36 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:21, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > Prepare for storing mode in struct thermal_zone_device. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- [...] > drivers/platform/x86/acerhdf.c | 8 ++++-- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (11 preceding siblings ...) 2020-06-01 11:36 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Peter Kästle @ 2020-06-01 11:36 ` Peter Kästle 2020-06-01 11:37 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Peter Kästle ` (4 subsequent siblings) 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:36 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:21, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > Prepare for eliminating get_mode(). > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- [...] > drivers/platform/x86/acerhdf.c | 15 ++++++------- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 05/11] thermal: remove get_mode() operation of drivers 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (12 preceding siblings ...) 2020-06-01 11:36 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Peter Kästle @ 2020-06-01 11:37 ` Peter Kästle 2020-06-01 11:37 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Peter Kästle ` (3 subsequent siblings) 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:37 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:21, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > get_mode() is now redundant, as the state is stored in struct > thermal_zone_device. > > Consequently the "mode" attribute in sysfs can always be visible, because > it is always possible to get the mode from struct tzd. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- [...] > drivers/platform/x86/acerhdf.c | 12 -------- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 07/11] thermal: Use mode helpers in drivers 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (13 preceding siblings ...) 2020-06-01 11:37 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Peter Kästle @ 2020-06-01 11:37 ` Peter Kästle 2020-06-01 11:38 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Peter Kästle ` (2 subsequent siblings) 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:37 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:22, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). > > Consequently, all set_mode() implementations in drivers: > > - can stop modifying tzd's "mode" member, > - shall stop taking tzd's lock, as it is taken in the helpers > - shall stop calling thermal_zone_device_update() as it is called in the > helpers > - can assume they are called when the mode truly changes, so checks to > verify that can be dropped > > Not providing set_mode() by a driver no longer prevents the core from > being able to set tzd's mode, so the relevant check in mode_store() is > removed. > > Other comments: > > - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we > return from set_mode(), so use function parameter in thermal_set_mode() > instead, no need to call acpi_thermal_check() in set_mode() > - thermal/imx_thermal.c: regmap writes and mode assignment are done in > thermal_zone_device_{en|dis}able() and set_mode() callback > - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a > part of set_mode() callback, so they don't need to modify tzd->mode, and > don't need to fall back to the opposite mode if unsuccessful, as the return > value will be propagated to thermal_zone_device_{en|dis}able() and > ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). > - thermal/of-thermal.c: no need to set zone->mode to DISABLED in > of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- [...] > drivers/platform/x86/acerhdf.c | 17 +++++---- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (14 preceding siblings ...) 2020-06-01 11:37 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Peter Kästle @ 2020-06-01 11:38 ` Peter Kästle 2020-06-01 11:38 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Peter Kästle 2020-06-23 14:37 ` [PATCH v4 00/11] Stop monitoring disabled devices Daniel Lezcano 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:38 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:22, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > Setting polling_delay is now done at thermal_core level (by not polling > DISABLED devices), so no need to repeat this code. > > int340x: Checking for an impossible enum value is unnecessary. > acpi/thermal: It only prints debug messages. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- [...] > drivers/platform/x86/acerhdf.c | 3 -- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (15 preceding siblings ...) 2020-06-01 11:38 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Peter Kästle @ 2020-06-01 11:38 ` Peter Kästle 2020-06-23 14:37 ` [PATCH v4 00/11] Stop monitoring disabled devices Daniel Lezcano 17 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-06-01 11:38 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel 28. Mai 2020 21:22, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > set_mode() is only called when tzd's mode is about to change. Actual > setting is performed in thermal_core, in thermal_zone_device_set_mode(). > The meaning of set_mode() callback is actually to notify the driver about > the mode being changed and giving the driver a chance to oppose such > change. > > To better reflect the purpose of the method rename it to change_mode() > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/platform/x86/acerhdf.c | 6 +++--- Acked-by: Peter Kaestle <peter@piie.net> ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 00/11] Stop monitoring disabled devices 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (16 preceding siblings ...) 2020-06-01 11:38 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Peter Kästle @ 2020-06-23 14:37 ` Daniel Lezcano 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz 17 siblings, 1 reply; 137+ messages in thread From: Daniel Lezcano @ 2020-06-23 14:37 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel Hi Andrzej, On 28/05/2020 21:20, Andrzej Pietrasiewicz wrote: > There is already a reviewed v3 (not to be confused with RFC v3), which can > be considered for merging: > > https://lore.kernel.org/linux-pm/20200423165705.13585-2-andrzej.p@collabora.com/ > > Let me cite Bartlomiej Zolnierkiewicz: > > "I couldn't find the problems with the patch itself (no new issues > being introduced, all changes seem to be improvements over the current > situation). > > Also the patch is not small but it also not that big and it mostly > removes the code: > > 17 files changed, 105 insertions(+), 244 deletions(-)" Thanks for this nice cleanup. Given the series was tested, reviewed and acked, I would like to merge it as soon as possible. Can you send the V5 with the EXPORT_SYMBOL_GPL fixed ? So the series can enter the integration loop. Thanks -- Daniel -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 00/11] Stop monitoring disabled devices 2020-06-23 14:37 ` [PATCH v4 00/11] Stop monitoring disabled devices Daniel Lezcano @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz ` (10 more replies) 0 siblings, 11 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel A respin of v4 with these changes: v4..v5: - EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL (Daniel) - dropped unnecessary thermal_zone_device_enable() in int3400_thermal.c and in thermal_of.c (Bartlomiej) Andrzej Pietrasiewicz (11): acpi: thermal: Fix error handling in the register function thermal: Store thermal mode in a dedicated enum thermal: Add current mode to thermal zone device thermal: Store device mode in struct thermal_zone_device thermal: remove get_mode() operation of drivers thermal: Add mode helpers thermal: Use mode helpers in drivers thermal: Explicitly enable non-changing thermal zone devices thermal: core: Stop polling DISABLED thermal devices thermal: Simplify or eliminate unnecessary set_mode() methods thermal: Rename set_mode() to change_mode() drivers/acpi/thermal.c | 75 +++++---------- .../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++ .../ethernet/mellanox/mlxsw/core_thermal.c | 91 ++++--------------- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 +- drivers/platform/x86/acerhdf.c | 33 +++---- drivers/platform/x86/intel_mid_thermal.c | 6 ++ drivers/power/supply/power_supply_core.c | 9 +- drivers/thermal/armada_thermal.c | 6 ++ drivers/thermal/da9062-thermal.c | 16 +--- drivers/thermal/dove_thermal.c | 6 ++ drivers/thermal/hisi_thermal.c | 6 +- drivers/thermal/imx_thermal.c | 57 ++++-------- .../intel/int340x_thermal/int3400_thermal.c | 38 ++------ .../int340x_thermal/int340x_thermal_zone.c | 5 + drivers/thermal/intel/intel_pch_thermal.c | 5 + .../thermal/intel/intel_quark_dts_thermal.c | 34 ++----- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 + drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++ drivers/thermal/kirkwood_thermal.c | 7 ++ drivers/thermal/rcar_thermal.c | 9 +- drivers/thermal/rockchip_thermal.c | 6 +- drivers/thermal/spear_thermal.c | 7 ++ drivers/thermal/sprd_thermal.c | 6 +- drivers/thermal/st/st_thermal.c | 5 + drivers/thermal/thermal_core.c | 76 ++++++++++++++-- drivers/thermal/thermal_of.c | 41 +-------- drivers/thermal/thermal_sysfs.c | 37 +------- include/linux/thermal.h | 19 +++- 28 files changed, 275 insertions(+), 351 deletions(-) base-commit: 48778464bb7d346b47157d21ffde2af6b2d39110 -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz ` (9 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel The acpi_thermal_register_thermal_zone() is missing any error handling. This needs to be fixed. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..6de8066ca1e7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) result = sysfs_create_link(&tz->device->dev.kobj, &tz->thermal_zone->device.kobj, "thermal_zone"); if (result) - return result; + goto unregister_tzd; result = sysfs_create_link(&tz->thermal_zone->device.kobj, &tz->device->dev.kobj, "device"); if (result) - return result; + goto remove_tz_link; status = acpi_bus_attach_private_data(tz->device->handle, tz->thermal_zone); - if (ACPI_FAILURE(status)) - return -ENODEV; + if (ACPI_FAILURE(status)) { + result = -ENODEV; + goto remove_dev_link; + } tz->tz_enabled = 1; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); + return 0; + +remove_dev_link: + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); +remove_tz_link: + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); +unregister_tzd: + thermal_zone_device_unregister(tz->thermal_zone); + + return result; } static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function 2020-06-26 17:37 ` [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz @ 2020-06-29 7:19 ` Amit Kucheria 0 siblings, 0 replies; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:19 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > The acpi_thermal_register_thermal_zone() is missing any error handling. > This needs to be fixed. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Reviewed-by: Guenter Roeck <linux@roeck-us.net> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > drivers/acpi/thermal.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..6de8066ca1e7 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > result = sysfs_create_link(&tz->device->dev.kobj, > &tz->thermal_zone->device.kobj, "thermal_zone"); > if (result) > - return result; > + goto unregister_tzd; > > result = sysfs_create_link(&tz->thermal_zone->device.kobj, > &tz->device->dev.kobj, "device"); > if (result) > - return result; > + goto remove_tz_link; > > status = acpi_bus_attach_private_data(tz->device->handle, > tz->thermal_zone); > - if (ACPI_FAILURE(status)) > - return -ENODEV; > + if (ACPI_FAILURE(status)) { > + result = -ENODEV; > + goto remove_dev_link; > + } > > tz->tz_enabled = 1; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > + > return 0; > + > +remove_dev_link: > + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); > +remove_tz_link: > + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); > +unregister_tzd: > + thermal_zone_device_unregister(tz->thermal_zone); > + > + return result; > } > > static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz ` (8 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for storing mode in struct thermal_zone_device. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 27 +++++++++---------- drivers/platform/x86/acerhdf.c | 8 ++++-- .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 6de8066ca1e7..fb46070c66d8 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,7 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; + enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, if (!tz) return -EINVAL; - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; + *mode = tz->mode; return 0; } @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != tz->mode) { + tz->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); + tz->mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); acpi_thermal_check(tz); } return 0; @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->tz_enabled = 1; + tz->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 4df7609b4aa9..9d1030b1a4f4 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,6 +68,7 @@ static int kernelmode = 1; #else static int kernelmode; #endif +static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; + thermal_mode = THERMAL_DEVICE_DISABLED; if (thz_dev) thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; + thermal_mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; + *mode = thermal_mode; return 0; } @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + thermal_mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 0b3a62655843..e84faaadff87 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,7 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - int mode; + enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + if (mode != priv->mode) { + priv->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } evaluate_odvp(priv); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum 2020-06-26 17:37 ` [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-06-29 7:19 ` Amit Kucheria 0 siblings, 0 replies; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:19 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > Prepare for storing mode in struct thermal_zone_device. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Reviewed-by: Guenter Roeck <linux@roeck-us.net> > [for acerhdf] > Acked-by: Peter Kaestle <peter@piie.net> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > drivers/acpi/thermal.c | 27 +++++++++---------- > drivers/platform/x86/acerhdf.c | 8 ++++-- > .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- > 3 files changed, 25 insertions(+), 28 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 6de8066ca1e7..fb46070c66d8 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,7 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > + enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, > if (!tz) > return -EINVAL; > > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > + *mode = tz->mode; > > return 0; > } > @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != tz->mode) { > + tz->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > + tz->mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > acpi_thermal_check(tz); > } > return 0; > @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > goto remove_dev_link; > } > > - tz->tz_enabled = 1; > + tz->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 4df7609b4aa9..9d1030b1a4f4 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -68,6 +68,7 @@ static int kernelmode = 1; > #else > static int kernelmode; > #endif > +static enum thermal_device_mode thermal_mode; > > static unsigned int interval = 10; > static unsigned int fanon = 60000; > @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > + thermal_mode = THERMAL_DEVICE_DISABLED; > if (thz_dev) > thz_dev->polling_delay = 0; > pr_notice("kernel mode fan control OFF\n"); > @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > + thermal_mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > + *mode = thermal_mode; > > return 0; > } > @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + thermal_mode = kernelmode ? > + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 0b3a62655843..e84faaadff87 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -48,7 +48,7 @@ struct int3400_thermal_priv { > struct acpi_device *adev; > struct platform_device *pdev; > struct thermal_zone_device *thermal; > - int mode; > + enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != priv->mode) { > + priv->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > > evaluate_odvp(priv); > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 03/11] thermal: Add current mode to thermal zone device 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz ` (7 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for changing the place where the mode is stored: now it is in drivers, which might or might not implement get_mode()/set_mode() methods. A lot of cleanup can be done thanks to storing it in struct tzd. The get_mode() methods will become redundant. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- include/linux/thermal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..5f91d7f04512 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -128,6 +128,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +171,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 03/11] thermal: Add current mode to thermal zone device 2020-06-26 17:37 ` [PATCH v5 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz @ 2020-06-29 7:19 ` Amit Kucheria 0 siblings, 0 replies; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:19 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > Prepare for changing the place where the mode is stored: now it is in > drivers, which might or might not implement get_mode()/set_mode() methods. > A lot of cleanup can be done thanks to storing it in struct tzd. The > get_mode() methods will become redundant. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Reviewed-by: Guenter Roeck <linux@roeck-us.net> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > include/linux/thermal.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..5f91d7f04512 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -128,6 +128,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +171,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz ` (6 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for eliminating get_mode(). Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 18 ++++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 21 +++++++------------ drivers/platform/x86/acerhdf.c | 15 ++++++------- drivers/thermal/da9062-thermal.c | 6 ++---- drivers/thermal/imx_thermal.c | 17 +++++++-------- .../intel/int340x_thermal/int3400_thermal.c | 12 +++-------- .../thermal/intel/intel_quark_dts_thermal.c | 16 +++++++------- drivers/thermal/thermal_of.c | 10 +++------ 8 files changed, 44 insertions(+), 71 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index fb46070c66d8..4ba273f49d87 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->mode != THERMAL_DEVICE_ENABLED) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) static int thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->mode; + *mode = thermal->mode; return 0; } @@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->mode) { - tz->mode = mode; + if (mode != tz->thermal_zone->mode) { + tz->thermal_zone->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->mode == THERMAL_DEVICE_ENABLED ? + tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? "Enable" : "Disable")); acpi_thermal_check(tz); } @@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->mode = THERMAL_DEVICE_ENABLED; + tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 05f8d5a92862..51667ed99c21 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; + *mode = tzdev->mode; return 0; } @@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; mutex_unlock(&tzdev->lock); - thermal->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -468,9 +464,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; + *mode = tzdev->mode; return 0; } @@ -488,9 +482,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; + mutex_unlock(&tzdev->lock); - tz->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -780,7 +775,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; + module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -896,7 +891,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; + gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1065,7 +1060,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; + thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 9d1030b1a4f4..6f21015e5fd9 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,7 +68,6 @@ static int kernelmode = 1; #else static int kernelmode; #endif -static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - thermal_mode = THERMAL_DEVICE_DISABLED; - if (thz_dev) + if (thz_dev) { + thz_dev->mode = THERMAL_DEVICE_DISABLED; thz_dev->polling_delay = 0; + } pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thermal_mode = THERMAL_DEVICE_ENABLED; + thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = thermal_mode; + *mode = thermal->mode; return 0; } @@ -741,8 +741,6 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thermal_mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, @@ -750,6 +748,9 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; + thz_dev->mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..a14c7981c7c7 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) static int da9062_thermal_get_mode(struct thermal_zone_device *z, enum thermal_device_mode *mode) { - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; + *mode = z->mode; return 0; } @@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); @@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } + thermal->zone->mode = THERMAL_DEVICE_ENABLED; dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..9a1114d721b6 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) static int imx_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + data->tz->mode = THERMAL_DEVICE_DISABLED; clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e84faaadff87..f65b2fc09198 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,6 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; + *mode = thermal->mode; return 0; } @@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != priv->mode) { - priv->mode = mode; + if (mode != thermal->mode) { + thermal->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..d77cb3df5ade 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, static int sys_get_mode(struct thermal_zone_device *tzd, enum thermal_device_mode *mode) { - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; + *mode = tzd->mode; return 0; } diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ddf88dbe7ba2..c495b1e48ef2 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -272,9 +270,7 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, static int of_thermal_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -296,7 +292,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, mutex_unlock(&tz->lock); - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -979,7 +975,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1134,6 +1129,7 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device 2020-06-26 17:37 ` [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz @ 2020-06-29 7:19 ` Amit Kucheria 0 siblings, 0 replies; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:19 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > Prepare for eliminating get_mode(). > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > [for acerhdf] > Acked-by: Peter Kaestle <peter@piie.net> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > drivers/acpi/thermal.c | 18 ++++++---------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 21 +++++++------------ > drivers/platform/x86/acerhdf.c | 15 ++++++------- > drivers/thermal/da9062-thermal.c | 6 ++---- > drivers/thermal/imx_thermal.c | 17 +++++++-------- > .../intel/int340x_thermal/int3400_thermal.c | 12 +++-------- > .../thermal/intel/intel_quark_dts_thermal.c | 16 +++++++------- > drivers/thermal/thermal_of.c | 10 +++------ > 8 files changed, 44 insertions(+), 71 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index fb46070c66d8..4ba273f49d87 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (tz->mode != THERMAL_DEVICE_ENABLED) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > static int thermal_get_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode *mode) > { > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->mode; > + *mode = thermal->mode; > > return 0; > } > @@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > > - if (mode != tz->mode) { > - tz->mode = mode; > + if (mode != tz->thermal_zone->mode) { > + tz->thermal_zone->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->mode == THERMAL_DEVICE_ENABLED ? > + tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? > "Enable" : "Disable")); > acpi_thermal_check(tz); > } > @@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > goto remove_dev_link; > } > > - tz->mode = THERMAL_DEVICE_ENABLED; > + tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index 05f8d5a92862..51667ed99c21 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode *mode) > { > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > + *mode = tzdev->mode; > > return 0; > } > @@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > else > tzdev->polling_delay = 0; > > + tzdev->mode = mode; > mutex_unlock(&tzdev->lock); > > - thermal->mode = mode; > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -468,9 +464,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > enum thermal_device_mode *mode) > { > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > + *mode = tzdev->mode; > > return 0; > } > @@ -488,9 +482,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > else > tzdev->polling_delay = 0; > > + tzdev->mode = mode; > + > mutex_unlock(&tzdev->lock); > > - tz->mode = mode; > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -780,7 +775,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > + module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -896,7 +891,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > + gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -1065,7 +1060,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > + thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 9d1030b1a4f4..6f21015e5fd9 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -68,7 +68,6 @@ static int kernelmode = 1; > #else > static int kernelmode; > #endif > -static enum thermal_device_mode thermal_mode; > > static unsigned int interval = 10; > static unsigned int fanon = 60000; > @@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) > { > acerhdf_change_fanstate(ACERHDF_FAN_AUTO); > kernelmode = 0; > - thermal_mode = THERMAL_DEVICE_DISABLED; > - if (thz_dev) > + if (thz_dev) { > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > thz_dev->polling_delay = 0; > + } > pr_notice("kernel mode fan control OFF\n"); > } > static inline void acerhdf_enable_kernelmode(void) > { > kernelmode = 1; > - thermal_mode = THERMAL_DEVICE_ENABLED; > + thz_dev->mode = THERMAL_DEVICE_ENABLED; > > thz_dev->polling_delay = interval*1000; > thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > @@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = thermal_mode; > + *mode = thermal->mode; > > return 0; > } > @@ -741,8 +741,6 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > - thermal_mode = kernelmode ? > - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > @@ -750,6 +748,9 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(thz_dev)) > return -EINVAL; > > + thz_dev->mode = kernelmode ? > + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > + > if (strcmp(thz_dev->governor->name, > acerhdf_zone_params.governor_name)) { > pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..a14c7981c7c7 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > static int da9062_thermal_get_mode(struct thermal_zone_device *z, > enum thermal_device_mode *mode) > { > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > + *mode = z->mode; > return 0; > } > > @@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > @@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) > ret = PTR_ERR(thermal->zone); > goto err; > } > + thermal->zone->mode = THERMAL_DEVICE_ENABLED; > > dev_dbg(&pdev->dev, > "TJUNC temperature polling period set at %d ms\n", > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..9a1114d721b6 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > static int imx_get_mode(struct thermal_zone_device *tz, > enum thermal_device_mode *mode) > { > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > + *mode = tz->mode; > > return 0; > } > @@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > + tz->mode = mode; > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + data->tz->mode = THERMAL_DEVICE_DISABLED; > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e84faaadff87..f65b2fc09198 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -48,7 +48,6 @@ struct int3400_thermal_priv { > struct acpi_device *adev; > struct platform_device *pdev; > struct thermal_zone_device *thermal; > - enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode *mode) > { > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > + *mode = thermal->mode; > > return 0; > } > @@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (mode != priv->mode) { > - priv->mode = mode; > + if (mode != thermal->mode) { > + thermal->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > priv->current_uuid_index, > mode == THERMAL_DEVICE_ENABLED); > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..d77cb3df5ade 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > static int sys_get_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode *mode) > { > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > + *mode = tzd->mode; > return 0; > } > > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index ddf88dbe7ba2..c495b1e48ef2 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -272,9 +270,7 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > static int of_thermal_get_mode(struct thermal_zone_device *tz, > enum thermal_device_mode *mode) > { > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > + *mode = tz->mode; > > return 0; > } > @@ -296,7 +292,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > > mutex_unlock(&tz->lock); > > - data->mode = mode; > + tz->mode = mode; > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -979,7 +975,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1134,6 +1129,7 @@ int __init of_parse_thermal_zones(void) > of_thermal_free_zone(tz); > /* attempting to build remaining zones still */ > } > + zone->mode = THERMAL_DEVICE_DISABLED; > } > of_node_put(np); > > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 05/11] thermal: remove get_mode() operation of drivers 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (3 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-29 7:20 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz ` (5 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel get_mode() is now redundant, as the state is stored in struct thermal_zone_device. Consequently the "mode" attribute in sysfs can always be visible, because it is always possible to get the mode from struct tzd. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 9 ------ .../ethernet/mellanox/mlxsw/core_thermal.c | 19 ------------ drivers/platform/x86/acerhdf.c | 12 -------- drivers/thermal/da9062-thermal.c | 8 ----- drivers/thermal/imx_thermal.c | 9 ------ .../intel/int340x_thermal/int3400_thermal.c | 9 ------ .../thermal/intel/intel_quark_dts_thermal.c | 8 ----- drivers/thermal/thermal_core.c | 7 +---- drivers/thermal/thermal_of.c | 9 ------ drivers/thermal/thermal_sysfs.c | 30 ++----------------- include/linux/thermal.h | 2 -- 11 files changed, 3 insertions(+), 119 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 4ba273f49d87..592be97c4456 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,14 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -847,7 +839,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 51667ed99c21..ad61b2db30b8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,14 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -402,7 +394,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -461,14 +452,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -606,7 +589,6 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -645,7 +627,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 6f21015e5fd9..58c4e1caaa09 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,17 +413,6 @@ static inline void acerhdf_enable_kernelmode(void) pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = thermal->mode; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -490,7 +479,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a14c7981c7c7..a7ac8afb063e 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -120,13 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - *mode = z->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -179,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 9a1114d721b6..2c7ee5da608a 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,14 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -464,7 +456,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index f65b2fc09198..9a622aaf29dd 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,14 +377,6 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -412,7 +404,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d77cb3df5ade..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -308,13 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - *mode = tzd->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -336,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b71196eaf90e..14d3b1b94c4f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1456,7 +1456,6 @@ static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { struct thermal_zone_device *tz; - enum thermal_device_mode tz_mode; switch (mode) { case PM_HIBERNATION_PREPARE: @@ -1469,11 +1468,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); - - if (tz_mode == THERMAL_DEVICE_DISABLED) + if (tz->mode == THERMAL_DEVICE_DISABLED) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index c495b1e48ef2..ba65d48a48cb 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,14 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -389,7 +381,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..096370977068 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,18 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; - - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" - : "disabled"); + return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? + "enabled" : "disabled"); } static ssize_t @@ -428,30 +419,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f91d7f04512..a808f6fa2777 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 05/11] thermal: remove get_mode() operation of drivers 2020-06-26 17:37 ` [PATCH v5 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz @ 2020-06-29 7:20 ` Amit Kucheria 0 siblings, 0 replies; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:20 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > get_mode() is now redundant, as the state is stored in struct > thermal_zone_device. > > Consequently the "mode" attribute in sysfs can always be visible, because > it is always possible to get the mode from struct tzd. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > [for acerhdf] > Acked-by: Peter Kaestle <peter@piie.net> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> > --- > drivers/acpi/thermal.c | 9 ------ > .../ethernet/mellanox/mlxsw/core_thermal.c | 19 ------------ > drivers/platform/x86/acerhdf.c | 12 -------- > drivers/thermal/da9062-thermal.c | 8 ----- > drivers/thermal/imx_thermal.c | 9 ------ > .../intel/int340x_thermal/int3400_thermal.c | 9 ------ > .../thermal/intel/intel_quark_dts_thermal.c | 8 ----- > drivers/thermal/thermal_core.c | 7 +---- > drivers/thermal/thermal_of.c | 9 ------ > drivers/thermal/thermal_sysfs.c | 30 ++----------------- > include/linux/thermal.h | 2 -- > 11 files changed, 3 insertions(+), 119 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 4ba273f49d87..592be97c4456 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -525,14 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - *mode = thermal->mode; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > @@ -847,7 +839,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index 51667ed99c21..ad61b2db30b8 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -275,14 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - *mode = tzdev->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -402,7 +394,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -461,14 +452,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - *mode = tzdev->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -606,7 +589,6 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -645,7 +627,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 6f21015e5fd9..58c4e1caaa09 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -413,17 +413,6 @@ static inline void acerhdf_enable_kernelmode(void) > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = thermal->mode; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -490,7 +479,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index a14c7981c7c7..a7ac8afb063e 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -120,13 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - *mode = z->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -179,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index 9a1114d721b6..2c7ee5da608a 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -330,14 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - *mode = tz->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -464,7 +456,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index f65b2fc09198..9a622aaf29dd 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -377,14 +377,6 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - *mode = thermal->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > @@ -412,7 +404,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d77cb3df5ade..c4879b4bfbf1 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -308,13 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - *mode = tzd->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -336,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index b71196eaf90e..14d3b1b94c4f 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1456,7 +1456,6 @@ static int thermal_pm_notify(struct notifier_block *nb, > unsigned long mode, void *_unused) > { > struct thermal_zone_device *tz; > - enum thermal_device_mode tz_mode; > > switch (mode) { > case PM_HIBERNATION_PREPARE: > @@ -1469,11 +1468,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > - > - if (tz_mode == THERMAL_DEVICE_DISABLED) > + if (tz->mode == THERMAL_DEVICE_DISABLED) > continue; > > thermal_zone_device_init(tz); > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index c495b1e48ef2..ba65d48a48cb 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -267,14 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - *mode = tz->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -389,7 +381,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..096370977068 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -49,18 +49,9 @@ static ssize_t > mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > - enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > - > - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > - : "disabled"); > + return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? > + "enabled" : "disabled"); > } > > static ssize_t > @@ -428,30 +419,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 5f91d7f04512..a808f6fa2777 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v5 06/11] thermal: Add mode helpers 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (4 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 20:50 ` kernel test robot ` (3 more replies) 2020-06-26 17:37 ` [PATCH v5 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz ` (4 subsequent siblings) 10 siblings, 4 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for making the drivers not access tzd's private members. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> [EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL] Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 13 +++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14d3b1b94c4f..3181295075b9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + /* do nothing if mode isn't changing */ + if (mode == tz->mode) { + mutex_unlock(&tz->lock); + + return ret; + } + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + if (!ret) + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + +int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_enable); + +int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_disable); + +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode == THERMAL_DEVICE_ENABLED; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_is_enabled); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/include/linux/thermal.h b/include/linux/thermal.h index a808f6fa2777..df013c39ba9b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); void thermal_cdev_update(struct thermal_cooling_device *); void thermal_notify_framework(struct thermal_zone_device *, int); +int thermal_zone_device_enable(struct thermal_zone_device *tz); +int thermal_zone_device_disable(struct thermal_zone_device *tz); +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) static inline void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { } + +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ return -ENODEV; } #endif /* CONFIG_THERMAL */ #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 06/11] thermal: Add mode helpers 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-06-26 20:50 ` kernel test robot 2020-06-26 20:50 ` [RFC PATCH] thermal: thermal_zone_device_set_mode() can be static kernel test robot ` (2 subsequent siblings) 3 siblings, 0 replies; 137+ messages in thread From: kernel test robot @ 2020-06-26 20:50 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: kbuild-all, Rafael J . Wysocki, Len Brown [-- Attachment #1: Type: text/plain, Size: 1079 bytes --] Hi Andrzej, I love your patch! Perhaps something to improve: [auto build test WARNING on 48778464bb7d346b47157d21ffde2af6b2d39110] url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200627-013944 base: 48778464bb7d346b47157d21ffde2af6b2d39110 config: x86_64-randconfig-s022-20200624 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> drivers/thermal/thermal_core.c:462:5: sparse: sparse: symbol 'thermal_zone_device_set_mode' was not declared. Should it be static? Please review and possibly fold the followup patch. --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 30547 bytes --] ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC PATCH] thermal: thermal_zone_device_set_mode() can be static 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz 2020-06-26 20:50 ` kernel test robot @ 2020-06-26 20:50 ` kernel test robot 2020-06-26 20:55 ` [PATCH v5 06/11] thermal: Add mode helpers kernel test robot 2020-06-29 7:04 ` Amit Kucheria 3 siblings, 0 replies; 137+ messages in thread From: kernel test robot @ 2020-06-26 20:50 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: kbuild-all, Rafael J . Wysocki, Len Brown Signed-off-by: kernel test robot <lkp@intel.com> --- thermal_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 3181295075b9a..f02c57c986f0e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -459,8 +459,8 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } -int thermal_zone_device_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) +static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) { int ret = 0; ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v5 06/11] thermal: Add mode helpers 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz 2020-06-26 20:50 ` kernel test robot 2020-06-26 20:50 ` [RFC PATCH] thermal: thermal_zone_device_set_mode() can be static kernel test robot @ 2020-06-26 20:55 ` kernel test robot 2020-06-29 7:04 ` Amit Kucheria 3 siblings, 0 replies; 137+ messages in thread From: kernel test robot @ 2020-06-26 20:55 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: kbuild-all, Rafael J . Wysocki, Len Brown [-- Attachment #1: Type: text/plain, Size: 1950 bytes --] Hi Andrzej, I love your patch! Perhaps something to improve: [auto build test WARNING on 48778464bb7d346b47157d21ffde2af6b2d39110] url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200627-013944 base: 48778464bb7d346b47157d21ffde2af6b2d39110 config: arm-imx_v6_v7_defconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> drivers/thermal/thermal_core.c:462:5: warning: no previous prototype for 'thermal_zone_device_set_mode' [-Wmissing-prototypes] 462 | int thermal_zone_device_set_mode(struct thermal_zone_device *tz, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ vim +/thermal_zone_device_set_mode +462 drivers/thermal/thermal_core.c 461 > 462 int thermal_zone_device_set_mode(struct thermal_zone_device *tz, 463 enum thermal_device_mode mode) 464 { 465 int ret = 0; 466 467 mutex_lock(&tz->lock); 468 469 /* do nothing if mode isn't changing */ 470 if (mode == tz->mode) { 471 mutex_unlock(&tz->lock); 472 473 return ret; 474 } 475 476 if (tz->ops->set_mode) 477 ret = tz->ops->set_mode(tz, mode); 478 479 if (!ret) 480 tz->mode = mode; 481 482 mutex_unlock(&tz->lock); 483 484 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); 485 486 return ret; 487 } 488 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 39610 bytes --] ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v5 06/11] thermal: Add mode helpers 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-06-26 20:55 ` [PATCH v5 06/11] thermal: Add mode helpers kernel test robot @ 2020-06-29 7:04 ` Amit Kucheria 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 3 siblings, 1 reply; 137+ messages in thread From: Amit Kucheria @ 2020-06-29 7:04 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM list, linux-acpi, netdev, linux-wireless, platform-driver-x86, lakml, linux-renesas-soc, linux-rockchip, Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > Prepare for making the drivers not access tzd's private members. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> > [EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL] > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ > include/linux/thermal.h | 13 +++++++++ > 2 files changed, 66 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 14d3b1b94c4f..3181295075b9 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) Should this be static? > +{ > + int ret = 0; > + > + mutex_lock(&tz->lock); > + > + /* do nothing if mode isn't changing */ > + if (mode == tz->mode) { > + mutex_unlock(&tz->lock); > + > + return ret; > + } > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + if (!ret) > + tz->mode = mode; > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} > + > +int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_enable); > + > +int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_disable); > + > +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode == THERMAL_DEVICE_ENABLED; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_is_enabled); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index a808f6fa2777..df013c39ba9b 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); > > void thermal_cdev_update(struct thermal_cooling_device *); > void thermal_notify_framework(struct thermal_zone_device *, int); > +int thermal_zone_device_enable(struct thermal_zone_device *tz); > +int thermal_zone_device_disable(struct thermal_zone_device *tz); > +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); > #else > static inline struct thermal_zone_device *thermal_zone_device_register( > const char *type, int trips, int mask, void *devdata, > @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) > static inline void thermal_notify_framework(struct thermal_zone_device *tz, > int trip) > { } > + > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ return -ENODEV; } > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ return -ENODEV; } > + > +static inline int > +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) > +{ return -ENODEV; } > #endif /* CONFIG_THERMAL */ > > #endif /* __THERMAL_H__ */ > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v6 00/11] Stop monitoring disabled devices 2020-06-29 7:04 ` Amit Kucheria @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz ` (10 more replies) 0 siblings, 11 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel A respin of v5 with these changes: v5..v6: - staticized thermal_zone_device_set_mode() (kbuild test robot) v4..v5: - EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL (Daniel) - dropped unnecessary thermal_zone_device_enable() in int3400_thermal.c and in thermal_of.c (Bartlomiej) Andrzej Pietrasiewicz (11): acpi: thermal: Fix error handling in the register function thermal: Store thermal mode in a dedicated enum thermal: Add current mode to thermal zone device thermal: Store device mode in struct thermal_zone_device thermal: remove get_mode() operation of drivers thermal: Add mode helpers thermal: Use mode helpers in drivers thermal: Explicitly enable non-changing thermal zone devices thermal: core: Stop polling DISABLED thermal devices thermal: Simplify or eliminate unnecessary set_mode() methods thermal: Rename set_mode() to change_mode() drivers/acpi/thermal.c | 75 +++++---------- .../ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++ .../ethernet/mellanox/mlxsw/core_thermal.c | 91 ++++--------------- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 +- drivers/platform/x86/acerhdf.c | 33 +++---- drivers/platform/x86/intel_mid_thermal.c | 6 ++ drivers/power/supply/power_supply_core.c | 9 +- drivers/thermal/armada_thermal.c | 6 ++ drivers/thermal/da9062-thermal.c | 16 +--- drivers/thermal/dove_thermal.c | 6 ++ drivers/thermal/hisi_thermal.c | 6 +- drivers/thermal/imx_thermal.c | 57 ++++-------- .../intel/int340x_thermal/int3400_thermal.c | 38 ++------ .../int340x_thermal/int340x_thermal_zone.c | 5 + drivers/thermal/intel/intel_pch_thermal.c | 5 + .../thermal/intel/intel_quark_dts_thermal.c | 34 ++----- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 + drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++ drivers/thermal/kirkwood_thermal.c | 7 ++ drivers/thermal/rcar_thermal.c | 9 +- drivers/thermal/rockchip_thermal.c | 6 +- drivers/thermal/spear_thermal.c | 7 ++ drivers/thermal/sprd_thermal.c | 6 +- drivers/thermal/st/st_thermal.c | 5 + drivers/thermal/thermal_core.c | 76 ++++++++++++++-- drivers/thermal/thermal_of.c | 41 +-------- drivers/thermal/thermal_sysfs.c | 37 +------- include/linux/thermal.h | 19 +++- 28 files changed, 275 insertions(+), 351 deletions(-) base-commit: 9ebcfadb0610322ac537dd7aa5d9cbc2b2894c68 -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v6 01/11] acpi: thermal: Fix error handling in the register function 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz ` (9 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel The acpi_thermal_register_thermal_zone() is missing any error handling. This needs to be fixed. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> --- drivers/acpi/thermal.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..6de8066ca1e7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) result = sysfs_create_link(&tz->device->dev.kobj, &tz->thermal_zone->device.kobj, "thermal_zone"); if (result) - return result; + goto unregister_tzd; result = sysfs_create_link(&tz->thermal_zone->device.kobj, &tz->device->dev.kobj, "device"); if (result) - return result; + goto remove_tz_link; status = acpi_bus_attach_private_data(tz->device->handle, tz->thermal_zone); - if (ACPI_FAILURE(status)) - return -ENODEV; + if (ACPI_FAILURE(status)) { + result = -ENODEV; + goto remove_dev_link; + } tz->tz_enabled = 1; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); + return 0; + +remove_dev_link: + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); +remove_tz_link: + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); +unregister_tzd: + thermal_zone_device_unregister(tz->thermal_zone); + + return result; } static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 02/11] thermal: Store thermal mode in a dedicated enum 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz ` (8 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for storing mode in struct thermal_zone_device. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> --- drivers/acpi/thermal.c | 27 +++++++++---------- drivers/platform/x86/acerhdf.c | 8 ++++-- .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 6de8066ca1e7..fb46070c66d8 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,7 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; + enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, if (!tz) return -EINVAL; - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; + *mode = tz->mode; return 0; } @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != tz->mode) { + tz->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); + tz->mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); acpi_thermal_check(tz); } return 0; @@ -915,7 +912,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->tz_enabled = 1; + tz->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 4df7609b4aa9..9d1030b1a4f4 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,6 +68,7 @@ static int kernelmode = 1; #else static int kernelmode; #endif +static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -397,6 +398,7 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; + thermal_mode = THERMAL_DEVICE_DISABLED; if (thz_dev) thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); @@ -404,6 +406,7 @@ static inline void acerhdf_revert_to_bios_mode(void) static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; + thermal_mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -416,8 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; + *mode = thermal_mode; return 0; } @@ -739,6 +741,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + thermal_mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 0b3a62655843..e84faaadff87 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,7 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - int mode; + enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -395,24 +395,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + if (mode != priv->mode) { + priv->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } evaluate_odvp(priv); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 03/11] thermal: Add current mode to thermal zone device 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz ` (7 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for changing the place where the mode is stored: now it is in drivers, which might or might not implement get_mode()/set_mode() methods. A lot of cleanup can be done thanks to storing it in struct tzd. The get_mode() methods will become redundant. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> --- include/linux/thermal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..5f91d7f04512 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -128,6 +128,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +171,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 04/11] thermal: Store device mode in struct thermal_zone_device 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz ` (6 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Prepare for eliminating get_mode(). Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> --- drivers/acpi/thermal.c | 18 ++++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 21 +++++++------------ drivers/platform/x86/acerhdf.c | 15 ++++++------- drivers/thermal/da9062-thermal.c | 6 ++---- drivers/thermal/imx_thermal.c | 17 +++++++-------- .../intel/int340x_thermal/int3400_thermal.c | 12 +++-------- .../thermal/intel/intel_quark_dts_thermal.c | 16 +++++++------- drivers/thermal/thermal_of.c | 10 +++------ 8 files changed, 44 insertions(+), 71 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index fb46070c66d8..4ba273f49d87 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->mode != THERMAL_DEVICE_ENABLED) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -529,12 +528,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) static int thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->mode; + *mode = thermal->mode; return 0; } @@ -556,11 +550,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->mode) { - tz->mode = mode; + if (mode != tz->thermal_zone->mode) { + tz->thermal_zone->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->mode == THERMAL_DEVICE_ENABLED ? + tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? "Enable" : "Disable")); acpi_thermal_check(tz); } @@ -912,7 +906,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->mode = THERMAL_DEVICE_ENABLED; + tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 05f8d5a92862..51667ed99c21 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -280,9 +278,7 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; + *mode = tzdev->mode; return 0; } @@ -299,9 +295,9 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; mutex_unlock(&tzdev->lock); - thermal->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -468,9 +464,7 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, enum thermal_device_mode *mode) { - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; + *mode = tzdev->mode; return 0; } @@ -488,9 +482,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, else tzdev->polling_delay = 0; + tzdev->mode = mode; + mutex_unlock(&tzdev->lock); - tz->mode = mode; thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -780,7 +775,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; + module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -896,7 +891,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; + gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1065,7 +1060,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; + thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 9d1030b1a4f4..6f21015e5fd9 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -68,7 +68,6 @@ static int kernelmode = 1; #else static int kernelmode; #endif -static enum thermal_device_mode thermal_mode; static unsigned int interval = 10; static unsigned int fanon = 60000; @@ -398,15 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - thermal_mode = THERMAL_DEVICE_DISABLED; - if (thz_dev) + if (thz_dev) { + thz_dev->mode = THERMAL_DEVICE_DISABLED; thz_dev->polling_delay = 0; + } pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thermal_mode = THERMAL_DEVICE_ENABLED; + thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); @@ -419,7 +419,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = thermal_mode; + *mode = thermal->mode; return 0; } @@ -741,8 +741,6 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thermal_mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, @@ -750,6 +748,9 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; + thz_dev->mode = kernelmode ? + THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..a14c7981c7c7 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -124,8 +123,7 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) static int da9062_thermal_get_mode(struct thermal_zone_device *z, enum thermal_device_mode *mode) { - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; + *mode = z->mode; return 0; } @@ -233,7 +231,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); @@ -248,6 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } + thermal->zone->mode = THERMAL_DEVICE_ENABLED; dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..9a1114d721b6 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -334,9 +333,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) static int imx_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -376,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -831,7 +828,7 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +882,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + data->tz->mode = THERMAL_DEVICE_DISABLED; clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +902,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e84faaadff87..f65b2fc09198 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -48,7 +48,6 @@ struct int3400_thermal_priv { struct acpi_device *adev; struct platform_device *pdev; struct thermal_zone_device *thermal; - enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -381,12 +380,7 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode) { - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; + *mode = thermal->mode; return 0; } @@ -404,8 +398,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != priv->mode) { - priv->mode = mode; + if (mode != thermal->mode) { + thermal->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..d77cb3df5ade 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -312,8 +311,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, static int sys_get_mode(struct thermal_zone_device *tzd, enum thermal_device_mode *mode) { - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; + *mode = tzd->mode; return 0; } diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ddf88dbe7ba2..c495b1e48ef2 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -272,9 +270,7 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, static int of_thermal_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; + *mode = tz->mode; return 0; } @@ -296,7 +292,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, mutex_unlock(&tz->lock); - data->mode = mode; + tz->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -979,7 +975,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1134,6 +1129,7 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 05/11] thermal: remove get_mode() operation of drivers 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (3 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz ` (5 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel get_mode() is now redundant, as the state is stored in struct thermal_zone_device. Consequently the "mode" attribute in sysfs can always be visible, because it is always possible to get the mode from struct tzd. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> --- drivers/acpi/thermal.c | 9 ------ .../ethernet/mellanox/mlxsw/core_thermal.c | 19 ------------ drivers/platform/x86/acerhdf.c | 12 -------- drivers/thermal/da9062-thermal.c | 8 ----- drivers/thermal/imx_thermal.c | 9 ------ .../intel/int340x_thermal/int3400_thermal.c | 9 ------ .../thermal/intel/intel_quark_dts_thermal.c | 8 ----- drivers/thermal/thermal_core.c | 7 +---- drivers/thermal/thermal_of.c | 9 ------ drivers/thermal/thermal_sysfs.c | 30 ++----------------- include/linux/thermal.h | 2 -- 11 files changed, 3 insertions(+), 119 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 4ba273f49d87..592be97c4456 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,14 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -847,7 +839,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 51667ed99c21..ad61b2db30b8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,14 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -402,7 +394,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -461,14 +452,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - *mode = tzdev->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -606,7 +589,6 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -645,7 +627,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 6f21015e5fd9..58c4e1caaa09 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,17 +413,6 @@ static inline void acerhdf_enable_kernelmode(void) pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = thermal->mode; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -490,7 +479,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a14c7981c7c7..a7ac8afb063e 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -120,13 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - *mode = z->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -179,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 9a1114d721b6..2c7ee5da608a 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,14 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -464,7 +456,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index f65b2fc09198..9a622aaf29dd 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,14 +377,6 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - *mode = thermal->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { @@ -412,7 +404,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d77cb3df5ade..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -308,13 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - *mode = tzd->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -336,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b71196eaf90e..14d3b1b94c4f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1456,7 +1456,6 @@ static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { struct thermal_zone_device *tz; - enum thermal_device_mode tz_mode; switch (mode) { case PM_HIBERNATION_PREPARE: @@ -1469,11 +1468,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); - - if (tz_mode == THERMAL_DEVICE_DISABLED) + if (tz->mode == THERMAL_DEVICE_DISABLED) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index c495b1e48ef2..ba65d48a48cb 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,14 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - *mode = tz->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -389,7 +381,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..096370977068 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,18 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; - - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" - : "disabled"); + return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? + "enabled" : "disabled"); } static ssize_t @@ -428,30 +419,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f91d7f04512..a808f6fa2777 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 06/11] thermal: Add mode helpers 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (4 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 12:08 ` Daniel Lezcano 2020-06-29 11:16 ` [PATCH v6 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz ` (4 subsequent siblings) 10 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel, kernel test robot Prepare for making the drivers not access tzd's private members. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> [EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL] Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [staticize thermal_zone_device_set_mode()] Signed-off-by: kernel test robot <lkp@intel.com> --- drivers/thermal/thermal_core.c | 53 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 13 +++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 14d3b1b94c4f..f02c57c986f0 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + /* do nothing if mode isn't changing */ + if (mode == tz->mode) { + mutex_unlock(&tz->lock); + + return ret; + } + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + if (!ret) + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + +int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_enable); + +int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_disable); + +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode == THERMAL_DEVICE_ENABLED; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_is_enabled); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/include/linux/thermal.h b/include/linux/thermal.h index a808f6fa2777..df013c39ba9b 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz); void thermal_cdev_update(struct thermal_cooling_device *); void thermal_notify_framework(struct thermal_zone_device *, int); +int thermal_zone_device_enable(struct thermal_zone_device *tz); +int thermal_zone_device_disable(struct thermal_zone_device *tz); +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, @@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) static inline void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { } + +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ return -ENODEV; } + +static inline int +thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ return -ENODEV; } #endif /* CONFIG_THERMAL */ #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v6 06/11] thermal: Add mode helpers 2020-06-29 11:16 ` [PATCH v6 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-06-29 12:08 ` Daniel Lezcano 0 siblings, 0 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-06-29 12:08 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel, kernel test robot On 29/06/2020 13:16, Andrzej Pietrasiewicz wrote: > Prepare for making the drivers not access tzd's private members. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> > [EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL] > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > [staticize thermal_zone_device_set_mode()] > Signed-off-by: kernel test robot <lkp@intel.com> Duplicate signed-off line. Please resend a V7 without a reply-to, so the series will be correctly handled by patchwork and that will make my life easier. Thanks -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v6 07/11] thermal: Use mode helpers in drivers 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (5 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz ` (3 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). Consequently, all set_mode() implementations in drivers: - can stop modifying tzd's "mode" member, - shall stop taking tzd's lock, as it is taken in the helpers - shall stop calling thermal_zone_device_update() as it is called in the helpers - can assume they are called when the mode truly changes, so checks to verify that can be dropped Not providing set_mode() by a driver no longer prevents the core from being able to set tzd's mode, so the relevant check in mode_store() is removed. Other comments: - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we return from set_mode(), so use function parameter in thermal_set_mode() instead, no need to call acpi_thermal_check() in set_mode() - thermal/imx_thermal.c: regmap writes and mode assignment are done in thermal_zone_device_{en|dis}able() and set_mode() callback - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a part of set_mode() callback, so they don't need to modify tzd->mode, and don't need to fall back to the opposite mode if unsuccessful, as the return value will be propagated to thermal_zone_device_{en|dis}able() and ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). - thermal/of-thermal.c: no need to set zone->mode to DISABLED in of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> --- drivers/acpi/thermal.c | 21 ++++++----- .../ethernet/mellanox/mlxsw/core_thermal.c | 37 +++++++++---------- drivers/platform/x86/acerhdf.c | 17 +++++---- drivers/thermal/da9062-thermal.c | 6 ++- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 33 +++++++---------- .../intel/int340x_thermal/int3400_thermal.c | 5 +-- .../thermal/intel/intel_quark_dts_thermal.c | 18 ++------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_of.c | 10 +---- drivers/thermal/thermal_sysfs.c | 11 ++---- 13 files changed, 80 insertions(+), 98 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 592be97c4456..52b6cda1bcc3 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) + if (!thermal_zone_device_is_enabled(tz->thermal_zone)) return; thermal_zone_device_update(tz->thermal_zone, @@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->thermal_zone->mode) { - tz->thermal_zone->mode = mode; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - acpi_thermal_check(tz); - } + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%s kernel ACPI thermal control\n", + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); + return 0; } @@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; + result = thermal_zone_device_enable(tz->thermal_zone); + if (result) + goto acpi_bus_detach; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; +acpi_bus_detach: + acpi_bus_detach_private_data(tz->device->handle); remove_dev_link: sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); remove_tz_link: diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ad61b2db30b8..4fb73d0fd167 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -458,19 +451,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -756,8 +741,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + err = thermal_zone_device_enable(module_tz->tzdev); + if (err) + thermal_zone_device_unregister(module_tz->tzdev); + + return err; } static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) @@ -860,6 +848,7 @@ static int mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) { char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; + int ret; snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); @@ -872,8 +861,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + ret = thermal_zone_device_enable(gearbox_tz->tzdev); + if (ret) + thermal_zone_device_unregister(gearbox_tz->tzdev); + + return ret; } static void @@ -1041,10 +1033,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; + err = thermal_zone_device_enable(thermal->tzdev); + if (err) + goto err_unreg_gearboxes; + *p_thermal = thermal; return 0; +err_unreg_gearboxes: + mlxsw_thermal_gearboxes_fini(thermal); err_unreg_modules_tzdev: mlxsw_thermal_modules_fini(thermal); err_unreg_tzdev: diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 58c4e1caaa09..8fe0ecb6a626 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) { - thz_dev->mode = THERMAL_DEVICE_DISABLED; + if (thz_dev) thz_dev->polling_delay = 0; - } + pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } @@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) static int __init acerhdf_register_thermal(void) { + int ret; + cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, &acerhdf_cooling_ops); @@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; - thz_dev->mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (kernelmode) + ret = thermal_zone_device_enable(thz_dev); + else + ret = thermal_zone_device_disable(thz_dev); + if (ret) + return ret; if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a7ac8afb063e..4d74994f160a 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } - thermal->zone->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(thermal->zone); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone device\n"); + goto err_zone; + } dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 2c7ee5da608a..53abb1be1cba 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (tz->mode == THERMAL_DEVICE_ENABLED) { + if (thermal_zone_device_is_enabled(tz)) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (tz->mode != THERMAL_DEVICE_ENABLED) { + if (!thermal_zone_device_is_enabled(tz)) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + goto thermal_zone_unregister; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev) static int __maybe_unused imx_thermal_suspend(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; + int ret; /* * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. + * down. This is done in set_mode() operation called from + * thermal_zone_device_disable() */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->measure_temp_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->power_down_mask); - data->tz->mode = THERMAL_DEVICE_DISABLED; + ret = thermal_zone_device_disable(data->tz); + if (ret) + return ret; clk_disable_unprepare(data->thermal_clk); return 0; @@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) static int __maybe_unused imx_thermal_resume(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; int ret; ret = clk_prepare_enable(data->thermal_clk); if (ret) return ret; /* Enabled thermal sensor after resume */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->power_down_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->measure_temp_mask); - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + return ret; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 9a622aaf29dd..3c0397a29b8c 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != thermal->mode) { - thermal->mode = mode; + if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); - } + evaluate_odvp(priv); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index c4879b4bfbf1..e29c3e330b17 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - if (out & QRK_DTS_ENABLE_BIT) { - tzd->mode = THERMAL_DEVICE_ENABLED; + if (out & QRK_DTS_ENABLE_BIT) return 0; - } if (!aux_entry->locked) { out |= QRK_DTS_ENABLE_BIT; @@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) QRK_DTS_REG_OFFSET_ENABLE, out); if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_ENABLED; } else { - tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - if (!(out & QRK_DTS_ENABLE_BIT)) { - tzd->mode = THERMAL_DEVICE_DISABLED; + if (!(out & QRK_DTS_ENABLE_BIT)) return 0; - } if (!aux_entry->locked) { out &= ~QRK_DTS_ENABLE_BIT; @@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_DISABLED; } else { - tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } - mutex_lock(&dts_update_mutex); - err = soc_dts_enable(aux_entry->tzone); - mutex_unlock(&dts_update_mutex); + err = thermal_zone_device_enable(aux_entry->tzone); if (err) goto err_aux_status; diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index f02c57c986f0..52d136780577 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - if (tz->mode == THERMAL_DEVICE_DISABLED) + if (!thermal_zone_device_is_enabled(tz)) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ba65d48a48cb..43a516a35d64 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -541,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } - zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 096370977068..c23d67c4dc4e 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,9 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); + int enabled = thermal_zone_device_is_enabled(tz); - return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? - "enabled" : "disabled"); + return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled"); } static ssize_t @@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr, struct thermal_zone_device *tz = to_thermal_zone(dev); int result; - if (!tz->ops->set_mode) - return -EPERM; - if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 08/11] thermal: Explicitly enable non-changing thermal zone devices 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (6 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz ` (2 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Some thermal zone devices never change their state, so they should be always enabled. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++++++++ drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 ++++++++- drivers/platform/x86/intel_mid_thermal.c | 6 ++++++ drivers/power/supply/power_supply_core.c | 9 +++++++-- drivers/thermal/armada_thermal.c | 6 ++++++ drivers/thermal/dove_thermal.c | 6 ++++++ .../thermal/intel/int340x_thermal/int340x_thermal_zone.c | 5 +++++ drivers/thermal/intel/intel_pch_thermal.c | 5 +++++ drivers/thermal/intel/intel_soc_dts_iosf.c | 3 +++ drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++++++ drivers/thermal/kirkwood_thermal.c | 7 +++++++ drivers/thermal/rcar_thermal.c | 9 ++++++++- drivers/thermal/spear_thermal.c | 7 +++++++ drivers/thermal/st/st_thermal.c | 5 +++++ 14 files changed, 87 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c index 3de8a5e83b6c..e3510e9b21f3 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c @@ -92,6 +92,14 @@ int cxgb4_thermal_init(struct adapter *adap) ch_thermal->tzdev = NULL; return ret; } + + ret = thermal_zone_device_enable(ch_thermal->tzdev); + if (ret) { + dev_err(adap->pdev_dev, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(adap->ch_thermal.tzdev); + return ret; + } + return 0; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 418e59b7c671..0c95663bf9ed 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -733,7 +733,7 @@ static struct thermal_zone_device_ops tzone_ops = { static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) { - int i; + int i, ret; char name[16]; static atomic_t counter = ATOMIC_INIT(0); @@ -759,6 +759,13 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) return; } + ret = thermal_zone_device_enable(mvm->tz_device.tzone); + if (ret) { + IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(mvm->tz_device.tzone); + return; + } + /* 0 is a valid temperature, * so initialize the array with S16_MIN which invalid temperature */ diff --git a/drivers/platform/x86/intel_mid_thermal.c b/drivers/platform/x86/intel_mid_thermal.c index f402e2e74a38..f12f4e7bd971 100644 --- a/drivers/platform/x86/intel_mid_thermal.c +++ b/drivers/platform/x86/intel_mid_thermal.c @@ -493,6 +493,12 @@ static int mid_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(pinfo->tzd[i]); goto err; } + ret = thermal_zone_device_enable(pinfo->tzd[i]); + if (ret) { + kfree(td_info); + thermal_zone_device_unregister(pinfo->tzd[i]); + goto err; + } } pinfo->pdev = pdev; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 02b37fe6061c..90e56736d479 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -939,7 +939,7 @@ static struct thermal_zone_device_ops psy_tzd_ops = { static int psy_register_thermal(struct power_supply *psy) { - int i; + int i, ret; if (psy->desc->no_thermal) return 0; @@ -949,7 +949,12 @@ static int psy_register_thermal(struct power_supply *psy) if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) { psy->tzd = thermal_zone_device_register(psy->desc->name, 0, 0, psy, &psy_tzd_ops, NULL, 0, 0); - return PTR_ERR_OR_ZERO(psy->tzd); + if (IS_ERR(psy->tzd)) + return PTR_ERR(psy->tzd); + ret = thermal_zone_device_enable(psy->tzd); + if (ret) + thermal_zone_device_unregister(psy->tzd); + return ret; } } return 0; diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index 7c447cd149e7..c2ebfb5be4b3 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -874,6 +874,12 @@ static int armada_thermal_probe(struct platform_device *pdev) return PTR_ERR(tz); } + ret = thermal_zone_device_enable(tz); + if (ret) { + thermal_zone_device_unregister(tz); + return ret; + } + drvdata->type = LEGACY; drvdata->data.tz = tz; platform_set_drvdata(pdev, drvdata); diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c index 75901ced4a62..73182eb94bc0 100644 --- a/drivers/thermal/dove_thermal.c +++ b/drivers/thermal/dove_thermal.c @@ -153,6 +153,12 @@ static int dove_thermal_probe(struct platform_device *pdev) return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + return ret; + } + platform_set_drvdata(pdev, thermal); return 0; diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..6e479deff76b 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -259,9 +259,14 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, ret = PTR_ERR(int34x_thermal_zone->zone); goto err_thermal_zone; } + ret = thermal_zone_device_enable(int34x_thermal_zone->zone); + if (ret) + goto err_enable; return int34x_thermal_zone; +err_enable: + thermal_zone_device_unregister(int34x_thermal_zone->zone); err_thermal_zone: acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table); kfree(int34x_thermal_zone->aux_trips); diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index 56401fd4708d..65702094f3d3 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -352,9 +352,14 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, err = PTR_ERR(ptd->tzd); goto error_cleanup; } + err = thermal_zone_device_enable(ptd->tzd); + if (err) + goto err_unregister; return 0; +err_unregister: + thermal_zone_device_unregister(ptd->tzd); error_cleanup: iounmap(ptd->hw_base); error_release: diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index f75271b669c6..4f1a2f7c016c 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -329,6 +329,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ret = PTR_ERR(dts->tzone); goto err_ret; } + ret = thermal_zone_device_enable(dts->tzone); + if (ret) + goto err_enable; ret = soc_dts_enable(id); if (ret) diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..b81c33202f41 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -363,6 +363,12 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) kfree(zonedev); return err; } + err = thermal_zone_device_enable(zonedev->tzone); + if (err) { + thermal_zone_device_unregister(zonedev->tzone); + kfree(zonedev); + return err; + } /* 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); diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c index 189b675cf14d..7fb6e476c82a 100644 --- a/drivers/thermal/kirkwood_thermal.c +++ b/drivers/thermal/kirkwood_thermal.c @@ -65,6 +65,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) struct thermal_zone_device *thermal = NULL; struct kirkwood_thermal_priv *priv; struct resource *res; + int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -82,6 +83,12 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) "Failed to register thermal zone device\n"); return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + dev_err(&pdev->dev, "Failed to enable thermal zone device\n"); + return ret; + } platform_set_drvdata(pdev, thermal); diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 46aeb28b4e90..787710bb88fe 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -550,12 +550,19 @@ static int rcar_thermal_probe(struct platform_device *pdev) priv->zone = devm_thermal_zone_of_sensor_register( dev, i, priv, &rcar_thermal_zone_of_ops); - else + else { priv->zone = thermal_zone_device_register( "rcar_thermal", 1, 0, priv, &rcar_thermal_zone_ops, NULL, 0, idle); + + ret = thermal_zone_device_enable(priv->zone); + if (ret) { + thermal_zone_device_unregister(priv->zone); + priv->zone = ERR_PTR(ret); + } + } if (IS_ERR(priv->zone)) { dev_err(dev, "can't register thermal zone\n"); ret = PTR_ERR(priv->zone); diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c index f68f581fd669..ee33ed692e4f 100644 --- a/drivers/thermal/spear_thermal.c +++ b/drivers/thermal/spear_thermal.c @@ -131,6 +131,11 @@ static int spear_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(spear_thermal); goto disable_clk; } + ret = thermal_zone_device_enable(spear_thermal); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone\n"); + goto unregister_tzd; + } platform_set_drvdata(pdev, spear_thermal); @@ -139,6 +144,8 @@ static int spear_thermal_probe(struct platform_device *pdev) return 0; +unregister_tzd: + thermal_zone_device_unregister(spear_thermal); disable_clk: clk_disable(stdev->clk); diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c index b928ca6a289b..1276b95604fe 100644 --- a/drivers/thermal/st/st_thermal.c +++ b/drivers/thermal/st/st_thermal.c @@ -246,11 +246,16 @@ int st_thermal_register(struct platform_device *pdev, ret = PTR_ERR(sensor->thermal_dev); goto sensor_off; } + ret = thermal_zone_device_enable(sensor->thermal_dev); + if (ret) + goto tzd_unregister; platform_set_drvdata(pdev, sensor); return 0; +tzd_unregister: + thermal_zone_device_unregister(sensor->thermal_dev); sensor_off: st_thermal_sensor_off(sensor); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 09/11] thermal: core: Stop polling DISABLED thermal devices 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (7 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 52d136780577..e613f5c07bad 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -301,13 +301,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return !thermal_zone_device_is_enabled(tz); +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -517,6 +526,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (8 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Setting polling_delay is now done at thermal_core level (by not polling DISABLED devices), so no need to repeat this code. int340x: Checking for an impossible enum value is unnecessary. acpi/thermal: It only prints debug messages. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 26 ---------------- .../ethernet/mellanox/mlxsw/core_thermal.c | 30 ------------------- drivers/platform/x86/acerhdf.c | 3 -- drivers/thermal/imx_thermal.c | 6 ---- .../intel/int340x_thermal/int3400_thermal.c | 4 --- drivers/thermal/thermal_of.c | 18 ----------- 6 files changed, 87 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 52b6cda1bcc3..29a2b73fe035 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,31 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - if (mode != THERMAL_DEVICE_DISABLED && - mode != THERMAL_DEVICE_ENABLED) - return -EINVAL; - /* - * enable/disable thermal management from ACPI thermal driver - */ - if (mode == THERMAL_DEVICE_DISABLED) - pr_warn("thermal zone will be disabled\n"); - - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - - return 0; -} - static int thermal_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { @@ -836,7 +811,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 4fb73d0fd167..8fa286ccdd6b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,19 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, int *p_temp) { @@ -387,7 +374,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, .get_trip_temp = mlxsw_thermal_get_trip_temp, @@ -445,20 +431,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - struct mlxsw_thermal *thermal = tz->parent; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, int *p_temp) { @@ -574,7 +546,6 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, @@ -612,7 +583,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8fe0ecb6a626..76323855c80c 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,8 +397,6 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) - thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); } @@ -406,7 +404,6 @@ static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->polling_delay = interval*1000; pr_notice("kernel mode fan control ON\n"); } diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 53abb1be1cba..a02398118d88 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -338,9 +338,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, const struct thermal_soc_data *soc_data = data->socdata; if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = IMX_POLLING_DELAY; - tz->passive_delay = IMX_PASSIVE_DELAY; - regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->power_down_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -356,9 +353,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, regmap_write(map, soc_data->sensor_ctrl + REG_SET, soc_data->power_down_mask); - tz->polling_delay = 0; - tz->passive_delay = 0; - if (data->irq_enabled) { disable_irq(data->irq); data->irq_enabled = false; diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 3c0397a29b8c..ce49d3b100d5 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -386,10 +386,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, if (!priv) return -EINVAL; - if (mode != THERMAL_DEVICE_ENABLED && - mode != THERMAL_DEVICE_DISABLED) - return -EINVAL; - if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 43a516a35d64..69ef12f852b7 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,22 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) -{ - struct __thermal_zone *data = tz->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = data->polling_delay; - tz->passive_delay = data->passive_delay; - } else { - tz->polling_delay = 0; - tz->passive_delay = 0; - } - - return 0; -} - static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, enum thermal_trip_type *type) { @@ -374,8 +358,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .set_mode = of_thermal_set_mode, - .get_trip_type = of_thermal_get_trip_type, .get_trip_temp = of_thermal_get_trip_temp, .set_trip_temp = of_thermal_set_trip_temp, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v6 11/11] thermal: Rename set_mode() to change_mode() 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz ` (9 preceding siblings ...) 2020-06-29 11:16 ` [PATCH v6 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz @ 2020-06-29 11:16 ` Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-29 11:16 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel set_mode() is only called when tzd's mode is about to change. Actual setting is performed in thermal_core, in thermal_zone_device_set_mode(). The meaning of set_mode() callback is actually to notify the driver about the mode being changed and giving the driver a chance to oppose such change. To better reflect the purpose of the method rename it to change_mode() Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/platform/x86/acerhdf.c | 6 +++--- drivers/thermal/imx_thermal.c | 8 ++++---- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 6 +++--- drivers/thermal/intel/intel_quark_dts_thermal.c | 6 +++--- drivers/thermal/thermal_core.c | 4 ++-- include/linux/thermal.h | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 76323855c80c..f816a8a13039 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,8 +413,8 @@ static inline void acerhdf_enable_kernelmode(void) * the temperature and the fan. * disabled: the BIOS takes control of the fan. */ -static int acerhdf_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int acerhdf_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { if (mode == THERMAL_DEVICE_DISABLED && kernelmode) acerhdf_revert_to_bios_mode(); @@ -473,7 +473,7 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .set_mode = acerhdf_set_mode, + .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, diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index a02398118d88..9700ae39feb7 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,8 +330,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) +static int imx_change_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) { struct imx_thermal_data *data = tz->devdata; struct regmap *map = data->tempmon; @@ -447,7 +447,7 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .set_mode = imx_set_mode, + .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, @@ -860,7 +860,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. This is done in set_mode() operation called from + * down. This is done in change_mode() operation called from * thermal_zone_device_disable() */ ret = thermal_zone_device_disable(data->tz); diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index ce49d3b100d5..d3732f624913 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,8 +377,8 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int int3400_thermal_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; int result = 0; @@ -399,7 +399,7 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .set_mode = int3400_thermal_set_mode, + .change_mode = int3400_thermal_change_mode, }; static struct thermal_zone_params int3400_thermal_params = { diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index e29c3e330b17..3eafc6b0e6c3 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -298,8 +298,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_set_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode mode) +static int sys_change_mode(struct thermal_zone_device *tzd, + enum thermal_device_mode mode) { int ret; @@ -319,7 +319,7 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .set_mode = sys_set_mode, + .change_mode = sys_change_mode, }; static void free_soc_dts(struct soc_sensor_entry *aux_entry) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e613f5c07bad..a61e91513584 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -482,8 +482,8 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, return ret; } - if (tz->ops->set_mode) - ret = tz->ops->set_mode(tz, mode); + if (tz->ops->change_mode) + ret = tz->ops->change_mode(tz, mode); if (!ret) tz->mode = mode; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index df013c39ba9b..b9efaa780d88 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,7 +76,7 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*set_mode) (struct thermal_zone_device *, + int (*change_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, enum thermal_trip_type *); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v5 07/11] thermal: Use mode helpers in drivers 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (5 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz ` (3 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled(). Consequently, all set_mode() implementations in drivers: - can stop modifying tzd's "mode" member, - shall stop taking tzd's lock, as it is taken in the helpers - shall stop calling thermal_zone_device_update() as it is called in the helpers - can assume they are called when the mode truly changes, so checks to verify that can be dropped Not providing set_mode() by a driver no longer prevents the core from being able to set tzd's mode, so the relevant check in mode_store() is removed. Other comments: - acpi/thermal.c: tz->thermal_zone->mode will be updated only after we return from set_mode(), so use function parameter in thermal_set_mode() instead, no need to call acpi_thermal_check() in set_mode() - thermal/imx_thermal.c: regmap writes and mode assignment are done in thermal_zone_device_{en|dis}able() and set_mode() callback - thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a part of set_mode() callback, so they don't need to modify tzd->mode, and don't need to fall back to the opposite mode if unsuccessful, as the return value will be propagated to thermal_zone_device_{en|dis}able() and ultimately tzd's member will not be changed in thermal_zone_device_set_mode(). - thermal/of-thermal.c: no need to set zone->mode to DISABLED in of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> --- drivers/acpi/thermal.c | 21 ++++++----- .../ethernet/mellanox/mlxsw/core_thermal.c | 37 +++++++++---------- drivers/platform/x86/acerhdf.c | 17 +++++---- drivers/thermal/da9062-thermal.c | 6 ++- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 33 +++++++---------- .../intel/int340x_thermal/int3400_thermal.c | 5 +-- .../thermal/intel/intel_quark_dts_thermal.c | 18 ++------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_of.c | 10 +---- drivers/thermal/thermal_sysfs.c | 11 ++---- 13 files changed, 80 insertions(+), 98 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 592be97c4456..52b6cda1bcc3 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) + if (!thermal_zone_device_is_enabled(tz->thermal_zone)) return; thermal_zone_device_update(tz->thermal_zone, @@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - if (mode != tz->thermal_zone->mode) { - tz->thermal_zone->mode = mode; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - acpi_thermal_check(tz); - } + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%s kernel ACPI thermal control\n", + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); + return 0; } @@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) goto remove_dev_link; } - tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; + result = thermal_zone_device_enable(tz->thermal_zone); + if (result) + goto acpi_bus_detach; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; +acpi_bus_detach: + acpi_bus_detach_private_data(tz->device->handle); remove_dev_link: sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); remove_tz_link: diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ad61b2db30b8..4fb73d0fd167 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -458,19 +451,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - tzdev->mode = mode; - - mutex_unlock(&tzdev->lock); - - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -756,8 +741,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + err = thermal_zone_device_enable(module_tz->tzdev); + if (err) + thermal_zone_device_unregister(module_tz->tzdev); + + return err; } static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) @@ -860,6 +848,7 @@ static int mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) { char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; + int ret; snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); @@ -872,8 +861,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; - return 0; + ret = thermal_zone_device_enable(gearbox_tz->tzdev); + if (ret) + thermal_zone_device_unregister(gearbox_tz->tzdev); + + return ret; } static void @@ -1041,10 +1033,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; + err = thermal_zone_device_enable(thermal->tzdev); + if (err) + goto err_unreg_gearboxes; + *p_thermal = thermal; return 0; +err_unreg_gearboxes: + mlxsw_thermal_gearboxes_fini(thermal); err_unreg_modules_tzdev: mlxsw_thermal_modules_fini(thermal); err_unreg_tzdev: diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 58c4e1caaa09..8fe0ecb6a626 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) { - thz_dev->mode = THERMAL_DEVICE_DISABLED; + if (thz_dev) thz_dev->polling_delay = 0; - } + pr_notice("kernel mode fan control OFF\n"); } static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->mode = THERMAL_DEVICE_ENABLED; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } @@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) static int __init acerhdf_register_thermal(void) { + int ret; + cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, &acerhdf_cooling_ops); @@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(thz_dev)) return -EINVAL; - thz_dev->mode = kernelmode ? - THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; + if (kernelmode) + ret = thermal_zone_device_enable(thz_dev); + else + ret = thermal_zone_device_disable(thz_dev); + if (ret) + return ret; if (strcmp(thz_dev->governor->name, acerhdf_zone_params.governor_name)) { diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a7ac8afb063e..4d74994f160a 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } - thermal->zone->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(thermal->zone); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone device\n"); + goto err_zone; + } dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 2c7ee5da608a..53abb1be1cba 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (tz->mode == THERMAL_DEVICE_ENABLED) { + if (thermal_zone_device_is_enabled(tz)) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (tz->mode != THERMAL_DEVICE_ENABLED) { + if (!thermal_zone_device_is_enabled(tz)) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + goto thermal_zone_unregister; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev) static int __maybe_unused imx_thermal_suspend(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; + int ret; /* * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. + * down. This is done in set_mode() operation called from + * thermal_zone_device_disable() */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->measure_temp_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->power_down_mask); - data->tz->mode = THERMAL_DEVICE_DISABLED; + ret = thermal_zone_device_disable(data->tz); + if (ret) + return ret; clk_disable_unprepare(data->thermal_clk); return 0; @@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) static int __maybe_unused imx_thermal_resume(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; int ret; ret = clk_prepare_enable(data->thermal_clk); if (ret) return ret; /* Enabled thermal sensor after resume */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->power_down_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->measure_temp_mask); - data->tz->mode = THERMAL_DEVICE_ENABLED; + ret = thermal_zone_device_enable(data->tz); + if (ret) + return ret; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 9a622aaf29dd..3c0397a29b8c 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (mode != thermal->mode) { - thermal->mode = mode; + if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, mode == THERMAL_DEVICE_ENABLED); - } + evaluate_odvp(priv); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index c4879b4bfbf1..e29c3e330b17 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - if (out & QRK_DTS_ENABLE_BIT) { - tzd->mode = THERMAL_DEVICE_ENABLED; + if (out & QRK_DTS_ENABLE_BIT) return 0; - } if (!aux_entry->locked) { out |= QRK_DTS_ENABLE_BIT; @@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) QRK_DTS_REG_OFFSET_ENABLE, out); if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_ENABLED; } else { - tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - if (!(out & QRK_DTS_ENABLE_BIT)) { - tzd->mode = THERMAL_DEVICE_DISABLED; + if (!(out & QRK_DTS_ENABLE_BIT)) return 0; - } if (!aux_entry->locked) { out &= ~QRK_DTS_ENABLE_BIT; @@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - - tzd->mode = THERMAL_DEVICE_DISABLED; } else { - tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } - mutex_lock(&dts_update_mutex); - err = soc_dts_enable(aux_entry->tzone); - mutex_unlock(&dts_update_mutex); + err = thermal_zone_device_enable(aux_entry->tzone); if (err) goto err_aux_status; diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 3181295075b9..beb6dacb7830 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - if (tz->mode == THERMAL_DEVICE_DISABLED) + if (!thermal_zone_device_is_enabled(tz)) continue; thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ba65d48a48cb..43a516a35d64 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - tz->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -541,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } - zone->mode = THERMAL_DEVICE_DISABLED; } of_node_put(np); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 096370977068..c23d67c4dc4e 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,9 +49,9 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); + int enabled = thermal_zone_device_is_enabled(tz); - return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? - "enabled" : "disabled"); + return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled"); } static ssize_t @@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr, struct thermal_zone_device *tz = to_thermal_zone(dev); int result; - if (!tz->ops->set_mode) - return -EPERM; - if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v5 08/11] thermal: Explicitly enable non-changing thermal zone devices 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (6 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz ` (2 subsequent siblings) 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Some thermal zone devices never change their state, so they should be always enabled. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 8 ++++++++ drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 ++++++++- drivers/platform/x86/intel_mid_thermal.c | 6 ++++++ drivers/power/supply/power_supply_core.c | 9 +++++++-- drivers/thermal/armada_thermal.c | 6 ++++++ drivers/thermal/dove_thermal.c | 6 ++++++ .../thermal/intel/int340x_thermal/int340x_thermal_zone.c | 5 +++++ drivers/thermal/intel/intel_pch_thermal.c | 5 +++++ drivers/thermal/intel/intel_soc_dts_iosf.c | 3 +++ drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 ++++++ drivers/thermal/kirkwood_thermal.c | 7 +++++++ drivers/thermal/rcar_thermal.c | 9 ++++++++- drivers/thermal/spear_thermal.c | 7 +++++++ drivers/thermal/st/st_thermal.c | 5 +++++ 14 files changed, 87 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c index 3de8a5e83b6c..e3510e9b21f3 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c @@ -92,6 +92,14 @@ int cxgb4_thermal_init(struct adapter *adap) ch_thermal->tzdev = NULL; return ret; } + + ret = thermal_zone_device_enable(ch_thermal->tzdev); + if (ret) { + dev_err(adap->pdev_dev, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(adap->ch_thermal.tzdev); + return ret; + } + return 0; } diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 418e59b7c671..0c95663bf9ed 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -733,7 +733,7 @@ static struct thermal_zone_device_ops tzone_ops = { static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) { - int i; + int i, ret; char name[16]; static atomic_t counter = ATOMIC_INIT(0); @@ -759,6 +759,13 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) return; } + ret = thermal_zone_device_enable(mvm->tz_device.tzone); + if (ret) { + IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n"); + thermal_zone_device_unregister(mvm->tz_device.tzone); + return; + } + /* 0 is a valid temperature, * so initialize the array with S16_MIN which invalid temperature */ diff --git a/drivers/platform/x86/intel_mid_thermal.c b/drivers/platform/x86/intel_mid_thermal.c index f402e2e74a38..f12f4e7bd971 100644 --- a/drivers/platform/x86/intel_mid_thermal.c +++ b/drivers/platform/x86/intel_mid_thermal.c @@ -493,6 +493,12 @@ static int mid_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(pinfo->tzd[i]); goto err; } + ret = thermal_zone_device_enable(pinfo->tzd[i]); + if (ret) { + kfree(td_info); + thermal_zone_device_unregister(pinfo->tzd[i]); + goto err; + } } pinfo->pdev = pdev; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 02b37fe6061c..90e56736d479 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -939,7 +939,7 @@ static struct thermal_zone_device_ops psy_tzd_ops = { static int psy_register_thermal(struct power_supply *psy) { - int i; + int i, ret; if (psy->desc->no_thermal) return 0; @@ -949,7 +949,12 @@ static int psy_register_thermal(struct power_supply *psy) if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) { psy->tzd = thermal_zone_device_register(psy->desc->name, 0, 0, psy, &psy_tzd_ops, NULL, 0, 0); - return PTR_ERR_OR_ZERO(psy->tzd); + if (IS_ERR(psy->tzd)) + return PTR_ERR(psy->tzd); + ret = thermal_zone_device_enable(psy->tzd); + if (ret) + thermal_zone_device_unregister(psy->tzd); + return ret; } } return 0; diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index 7c447cd149e7..c2ebfb5be4b3 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -874,6 +874,12 @@ static int armada_thermal_probe(struct platform_device *pdev) return PTR_ERR(tz); } + ret = thermal_zone_device_enable(tz); + if (ret) { + thermal_zone_device_unregister(tz); + return ret; + } + drvdata->type = LEGACY; drvdata->data.tz = tz; platform_set_drvdata(pdev, drvdata); diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c index 75901ced4a62..73182eb94bc0 100644 --- a/drivers/thermal/dove_thermal.c +++ b/drivers/thermal/dove_thermal.c @@ -153,6 +153,12 @@ static int dove_thermal_probe(struct platform_device *pdev) return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + return ret; + } + platform_set_drvdata(pdev, thermal); return 0; diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..6e479deff76b 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -259,9 +259,14 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, ret = PTR_ERR(int34x_thermal_zone->zone); goto err_thermal_zone; } + ret = thermal_zone_device_enable(int34x_thermal_zone->zone); + if (ret) + goto err_enable; return int34x_thermal_zone; +err_enable: + thermal_zone_device_unregister(int34x_thermal_zone->zone); err_thermal_zone: acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table); kfree(int34x_thermal_zone->aux_trips); diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index 56401fd4708d..65702094f3d3 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -352,9 +352,14 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, err = PTR_ERR(ptd->tzd); goto error_cleanup; } + err = thermal_zone_device_enable(ptd->tzd); + if (err) + goto err_unregister; return 0; +err_unregister: + thermal_zone_device_unregister(ptd->tzd); error_cleanup: iounmap(ptd->hw_base); error_release: diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index f75271b669c6..4f1a2f7c016c 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -329,6 +329,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ret = PTR_ERR(dts->tzone); goto err_ret; } + ret = thermal_zone_device_enable(dts->tzone); + if (ret) + goto err_enable; ret = soc_dts_enable(id); if (ret) diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..b81c33202f41 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -363,6 +363,12 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) kfree(zonedev); return err; } + err = thermal_zone_device_enable(zonedev->tzone); + if (err) { + thermal_zone_device_unregister(zonedev->tzone); + kfree(zonedev); + return err; + } /* 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); diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c index 189b675cf14d..7fb6e476c82a 100644 --- a/drivers/thermal/kirkwood_thermal.c +++ b/drivers/thermal/kirkwood_thermal.c @@ -65,6 +65,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) struct thermal_zone_device *thermal = NULL; struct kirkwood_thermal_priv *priv; struct resource *res; + int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -82,6 +83,12 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) "Failed to register thermal zone device\n"); return PTR_ERR(thermal); } + ret = thermal_zone_device_enable(thermal); + if (ret) { + thermal_zone_device_unregister(thermal); + dev_err(&pdev->dev, "Failed to enable thermal zone device\n"); + return ret; + } platform_set_drvdata(pdev, thermal); diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 46aeb28b4e90..787710bb88fe 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -550,12 +550,19 @@ static int rcar_thermal_probe(struct platform_device *pdev) priv->zone = devm_thermal_zone_of_sensor_register( dev, i, priv, &rcar_thermal_zone_of_ops); - else + else { priv->zone = thermal_zone_device_register( "rcar_thermal", 1, 0, priv, &rcar_thermal_zone_ops, NULL, 0, idle); + + ret = thermal_zone_device_enable(priv->zone); + if (ret) { + thermal_zone_device_unregister(priv->zone); + priv->zone = ERR_PTR(ret); + } + } if (IS_ERR(priv->zone)) { dev_err(dev, "can't register thermal zone\n"); ret = PTR_ERR(priv->zone); diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c index f68f581fd669..ee33ed692e4f 100644 --- a/drivers/thermal/spear_thermal.c +++ b/drivers/thermal/spear_thermal.c @@ -131,6 +131,11 @@ static int spear_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(spear_thermal); goto disable_clk; } + ret = thermal_zone_device_enable(spear_thermal); + if (ret) { + dev_err(&pdev->dev, "Cannot enable thermal zone\n"); + goto unregister_tzd; + } platform_set_drvdata(pdev, spear_thermal); @@ -139,6 +144,8 @@ static int spear_thermal_probe(struct platform_device *pdev) return 0; +unregister_tzd: + thermal_zone_device_unregister(spear_thermal); disable_clk: clk_disable(stdev->clk); diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c index b928ca6a289b..1276b95604fe 100644 --- a/drivers/thermal/st/st_thermal.c +++ b/drivers/thermal/st/st_thermal.c @@ -246,11 +246,16 @@ int st_thermal_register(struct platform_device *pdev, ret = PTR_ERR(sensor->thermal_dev); goto sensor_off; } + ret = thermal_zone_device_enable(sensor->thermal_dev); + if (ret) + goto tzd_unregister; platform_set_drvdata(pdev, sensor); return 0; +tzd_unregister: + thermal_zone_device_unregister(sensor->thermal_dev); sensor_off: st_thermal_sensor_off(sensor); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v5 09/11] thermal: core: Stop polling DISABLED thermal devices 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (7 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index beb6dacb7830..3988ad088387 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -301,13 +301,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return !thermal_zone_device_is_enabled(tz); +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -517,6 +526,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v5 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (8 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel Setting polling_delay is now done at thermal_core level (by not polling DISABLED devices), so no need to repeat this code. int340x: Checking for an impossible enum value is unnecessary. acpi/thermal: It only prints debug messages. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/acpi/thermal.c | 26 ---------------- .../ethernet/mellanox/mlxsw/core_thermal.c | 30 ------------------- drivers/platform/x86/acerhdf.c | 3 -- drivers/thermal/imx_thermal.c | 6 ---- .../intel/int340x_thermal/int3400_thermal.c | 4 --- drivers/thermal/thermal_of.c | 18 ----------- 6 files changed, 87 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 52b6cda1bcc3..29a2b73fe035 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -525,31 +525,6 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - if (mode != THERMAL_DEVICE_DISABLED && - mode != THERMAL_DEVICE_ENABLED) - return -EINVAL; - /* - * enable/disable thermal management from ACPI thermal driver - */ - if (mode == THERMAL_DEVICE_DISABLED) - pr_warn("thermal zone will be disabled\n"); - - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "%s kernel ACPI thermal control\n", - mode == THERMAL_DEVICE_ENABLED ? - "Enable" : "Disable")); - - return 0; -} - static int thermal_get_trip_type(struct thermal_zone_device *thermal, int trip, enum thermal_trip_type *type) { @@ -836,7 +811,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 4fb73d0fd167..8fa286ccdd6b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -275,19 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, int *p_temp) { @@ -387,7 +374,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, .get_trip_temp = mlxsw_thermal_get_trip_temp, @@ -445,20 +431,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, - enum thermal_device_mode mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - struct mlxsw_thermal *thermal = tz->parent; - - if (mode == THERMAL_DEVICE_ENABLED) - tzdev->polling_delay = thermal->polling_delay; - else - tzdev->polling_delay = 0; - - return 0; -} - static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, int *p_temp) { @@ -574,7 +546,6 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, @@ -612,7 +583,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, .get_trip_temp = mlxsw_thermal_module_trip_temp_get, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8fe0ecb6a626..76323855c80c 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -397,8 +397,6 @@ static inline void acerhdf_revert_to_bios_mode(void) { acerhdf_change_fanstate(ACERHDF_FAN_AUTO); kernelmode = 0; - if (thz_dev) - thz_dev->polling_delay = 0; pr_notice("kernel mode fan control OFF\n"); } @@ -406,7 +404,6 @@ static inline void acerhdf_enable_kernelmode(void) { kernelmode = 1; - thz_dev->polling_delay = interval*1000; pr_notice("kernel mode fan control ON\n"); } diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 53abb1be1cba..a02398118d88 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -338,9 +338,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, const struct thermal_soc_data *soc_data = data->socdata; if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = IMX_POLLING_DELAY; - tz->passive_delay = IMX_PASSIVE_DELAY; - regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->power_down_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -356,9 +353,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, regmap_write(map, soc_data->sensor_ctrl + REG_SET, soc_data->power_down_mask); - tz->polling_delay = 0; - tz->passive_delay = 0; - if (data->irq_enabled) { disable_irq(data->irq); data->irq_enabled = false; diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 3c0397a29b8c..ce49d3b100d5 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -386,10 +386,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, if (!priv) return -EINVAL; - if (mode != THERMAL_DEVICE_ENABLED && - mode != THERMAL_DEVICE_DISABLED) - return -EINVAL; - if (mode != thermal->mode) result = int3400_thermal_run_osc(priv->adev->handle, priv->current_uuid_index, diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 43a516a35d64..69ef12f852b7 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -267,22 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) -{ - struct __thermal_zone *data = tz->devdata; - - if (mode == THERMAL_DEVICE_ENABLED) { - tz->polling_delay = data->polling_delay; - tz->passive_delay = data->passive_delay; - } else { - tz->polling_delay = 0; - tz->passive_delay = 0; - } - - return 0; -} - static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, enum thermal_trip_type *type) { @@ -374,8 +358,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .set_mode = of_thermal_set_mode, - .get_trip_type = of_thermal_get_trip_type, .get_trip_temp = of_thermal_get_trip_temp, .set_trip_temp = of_thermal_set_trip_temp, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH v5 11/11] thermal: Rename set_mode() to change_mode() 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz ` (9 preceding siblings ...) 2020-06-26 17:37 ` [PATCH v5 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz @ 2020-06-26 17:37 ` Andrzej Pietrasiewicz 10 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-26 17:37 UTC (permalink / raw) To: linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Peter Kaestle, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, Andrzej Pietrasiewicz, kernel set_mode() is only called when tzd's mode is about to change. Actual setting is performed in thermal_core, in thermal_zone_device_set_mode(). The meaning of set_mode() callback is actually to notify the driver about the mode being changed and giving the driver a chance to oppose such change. To better reflect the purpose of the method rename it to change_mode() Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> [for acerhdf] Acked-by: Peter Kaestle <peter@piie.net> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> --- drivers/platform/x86/acerhdf.c | 6 +++--- drivers/thermal/imx_thermal.c | 8 ++++---- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 6 +++--- drivers/thermal/intel/intel_quark_dts_thermal.c | 6 +++--- drivers/thermal/thermal_core.c | 4 ++-- include/linux/thermal.h | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 76323855c80c..f816a8a13039 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -413,8 +413,8 @@ static inline void acerhdf_enable_kernelmode(void) * the temperature and the fan. * disabled: the BIOS takes control of the fan. */ -static int acerhdf_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int acerhdf_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { if (mode == THERMAL_DEVICE_DISABLED && kernelmode) acerhdf_revert_to_bios_mode(); @@ -473,7 +473,7 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .set_mode = acerhdf_set_mode, + .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, diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index a02398118d88..9700ae39feb7 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,8 +330,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_set_mode(struct thermal_zone_device *tz, - enum thermal_device_mode mode) +static int imx_change_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) { struct imx_thermal_data *data = tz->devdata; struct regmap *map = data->tempmon; @@ -447,7 +447,7 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .set_mode = imx_set_mode, + .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, @@ -860,7 +860,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. This is done in set_mode() operation called from + * down. This is done in change_mode() operation called from * thermal_zone_device_disable() */ ret = thermal_zone_device_disable(data->tz); diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index ce49d3b100d5..d3732f624913 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -377,8 +377,8 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode mode) +static int int3400_thermal_change_mode(struct thermal_zone_device *thermal, + enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; int result = 0; @@ -399,7 +399,7 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .set_mode = int3400_thermal_set_mode, + .change_mode = int3400_thermal_change_mode, }; static struct thermal_zone_params int3400_thermal_params = { diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index e29c3e330b17..3eafc6b0e6c3 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -298,8 +298,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_set_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode mode) +static int sys_change_mode(struct thermal_zone_device *tzd, + enum thermal_device_mode mode) { int ret; @@ -319,7 +319,7 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .set_mode = sys_set_mode, + .change_mode = sys_change_mode, }; static void free_soc_dts(struct soc_sensor_entry *aux_entry) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 3988ad088387..35540a4c2716 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -482,8 +482,8 @@ int thermal_zone_device_set_mode(struct thermal_zone_device *tz, return ret; } - if (tz->ops->set_mode) - ret = tz->ops->set_mode(tz, mode); + if (tz->ops->change_mode) + ret = tz->ops->change_mode(tz, mode); if (!ret) tz->mode = mode; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index df013c39ba9b..b9efaa780d88 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,7 +76,7 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*set_mode) (struct thermal_zone_device *, + int (*change_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, enum thermal_trip_type *); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v4 00/11] Stop monitoring disabled devices [not found] <Message-ID: <4493c0e4-51aa-3907-810c-74949ff27ca4@samsung.com> 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-06-01 10:02 ` Peter Kästle 2020-06-01 10:20 ` Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: Peter Kästle @ 2020-06-01 10:02 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel Hi, 28. Mai 2020 21:21, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: [...] > This v4 series addresses those concerns: it takes a more gradual > approach and uses explicit tzd state initialization, hence there are more > insertions than in v3, and the net effect is -63 lines versus -139 lines > in v3. I'd like to test it. Which git repo / branch do you base this series of patches on? [...] > base-commit: 351f4911a477ae01239c42f771f621d85b06ea10 Can't find this hashref anywhere. -- thanks --peter; ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v4 00/11] Stop monitoring disabled devices 2020-06-01 10:02 ` [PATCH v4 00/11] Stop monitoring disabled devices Peter Kästle @ 2020-06-01 10:20 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-06-01 10:20 UTC (permalink / raw) To: Peter Kästle, linux-pm, linux-acpi, netdev, linux-wireless, platform-driver-x86, linux-arm-kernel, linux-renesas-soc, linux-rockchip Cc: Rafael J . Wysocki, Len Brown, Vishal Kulkarni, David S . Miller, Jiri Pirko, Ido Schimmel, Johannes Berg, Emmanuel Grumbach, Luca Coelho, Intel Linux Wireless, Kalle Valo, Darren Hart, Andy Shevchenko, Sebastian Reichel, Miquel Raynal, Daniel Lezcano, Amit Kucheria, Support Opensource, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Niklas Söderlund, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, Zhang Rui, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, Bartlomiej Zolnierkiewicz, kernel W dniu 01.06.2020 o 12:02, Peter Kästle pisze: > Hi, > > 28. Mai 2020 21:21, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > > [...] > >> This v4 series addresses those concerns: it takes a more gradual >> approach and uses explicit tzd state initialization, hence there are more >> insertions than in v3, and the net effect is -63 lines versus -139 lines >> in v3. > > I'd like to test it. Which git repo / branch do you base this series of patches on? > > [...] > >> base-commit: 351f4911a477ae01239c42f771f621d85b06ea10 > > Can't find this hashref anywhere. > git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git, branch "testing". base-commit: 351f4911a477ae01239c42f771f621d85b06ea10 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 0/8] Stop monitoring disabled devices @ 2020-04-07 17:49 Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz ` (8 more replies) 0 siblings, 9 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz The current kernel behavior is to keep polling the thermal zone devices regardless of their current mode. This is not desired, as all such "disabled" devices are meant to be handled by userspace, so polling them makes no sense. There was an attempt to solve this issue: https://lkml.org/lkml/2018/2/26/498 and it ultimately has not succeeded: https://lkml.org/lkml/2018/2/27/910 This is a new attempt addressing all the relevant drivers, and I have identified them with: $ git grep "thermal_zone_device_ops" | grep "= {" | cut -f1 -d: | sort | uniq The idea is to modify thermal_zone_device_update() and monitor_thermal_zone() in such a way that they stop polling a disabled device. To do decide what to do they should call ->get_mode() operation of the specialized thermal zone device in question (e.g. drivers/acpi/thermal.c's). But here comes problem: sometimes a thermal zone device must be initially disabled and becomes enabled only after its sensors appear on the system. If such thermal zone's ->get_mode() /* in the context of thermal_zone_device_update() or monitor_thermal_zone() */ is called _before_ the sensors are available, it will be reported as "disabled" and consequently polling it will be ceased. This is a change in behavior from userspace's perspective. To solve the above described problem I want to introduce the third mode of a thermal_zone_device: initial. The idea is that when the device is in its initial mode, then its polling will be handled as it is now. This is a good thing: should the temperature be just about hitting the critical treshnold early during the boot process, it might be too late if we wait for the userspace to run to save the system from overheating. The initial mode should be reported in sysfs as "enabled" to keep the userspace interface intact. From the initial mode there will be two possible transitions: to enabled or disabled mode, but there will be no transition back to initial. If the transition is from initial to enabled, then keep polling. If the transition is from initial to disabled, then stop polling. If the transition is from enabled to disabled, then stop polling. The transition from disabled to enabled must be handled in a special way: there must be a mandatory call to monitor_thermal_zone(), otherwise the polling will not start. If this transition is triggeted from sysfs, then it can be easily handled at the thermal framework level. However, if drivers call their own ->set_mode() operation then they must also call "monitor_thermal_zone()" afterwards. The latter being a sensible thing anyway, so perhaps all/most of the drivers in question do. The plan for implementation is this: - ensure ALL users use symbolic enum names (THERMAL_DEVICE_DISABLED, THERMAL_DEVICE_ENABLED) for thermal device mode rather than the numeric values of enum thermal_device_mode elements - add THERMAL_DEVICE_INITIAL to the said enum making its value 0 (so that kzalloc() results in the initial state) - modify thermal zone device's mode_show() (thermal framework level) so that it reports "enabled" for THERMAL_DEVICE_INITIAL - modify thermal zone device's mode_store() (thermal framework level) so that it calls monitor_thermal_zone() upon mode change - modify ALL thermal drivers so that their code is prepared to return THERMAL_DEVICE_INITIAL before they call thermal_zone_device_register(); when the invocation of the latter completes then polling is expected to be started - verify ALL drivers which call their own ->set_mode() to ensure they do call monitor_thermal_zone() afterwards - modify thermal_zone_device_update() and monitor_thermal_zone() so that they cancel polling for disabled thermal zone devices (but not for those in THERMAL_DEVICE_INITIAL mode) This RFC series does all the above steps in more or less that order. I kindly ask for comments/suggestions/improvements. Rebased onto v5.6. Andrzej Pietrasiewicz (8): thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops thermal: Properly handle mode values in .set_mode() thermal: Store thermal mode in a dedicated enum thermal: core: Introduce THERMAL_DEVICE_INITIAL thermal: core: Monitor thermal zone after mode change thermal: Set initial state to THERMAL_DEVICE_INITIAL thermal: of: Monitor thermal zone after enabling it thermal: Stop polling DISABLED thermal devices drivers/acpi/thermal.c | 28 +++++----- .../ethernet/mellanox/mlxsw/core_thermal.c | 11 +++- drivers/platform/x86/acerhdf.c | 17 ++++-- drivers/thermal/da9062-thermal.c | 2 +- drivers/thermal/imx_thermal.c | 5 +- .../intel/int340x_thermal/int3400_thermal.c | 24 ++++----- .../thermal/intel/intel_quark_dts_thermal.c | 6 ++- drivers/thermal/of-thermal.c | 9 +++- drivers/thermal/thermal_core.c | 52 ++++++++++++++++++- drivers/thermal/thermal_core.h | 2 + drivers/thermal/thermal_sysfs.c | 12 +++-- include/linux/thermal.h | 3 +- 12 files changed, 123 insertions(+), 48 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415091204eucas1p1983548c2db52d8d0c2a5367034ec80dd@eucas1p1.samsung.com> 2020-04-07 17:49 ` [RFC 2/8] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz ` (7 subsequent siblings) 8 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz int3400_thermal_ops is used inside int3400_thermal_probe() only after the assignments, which can just as well be made statically at struct's initizer. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index efae0c02d898..634b943e9e3d 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -271,6 +271,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, + .get_mode = int3400_thermal_get_mode, + .set_mode = int3400_thermal_set_mode, }; static struct thermal_zone_params int3400_thermal_params = { @@ -309,9 +311,6 @@ static int int3400_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); - int3400_thermal_ops.get_mode = int3400_thermal_get_mode; - int3400_thermal_ops.set_mode = int3400_thermal_set_mode; - priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, priv, &int3400_thermal_ops, &int3400_thermal_params, 0, 0); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
[parent not found: <CGME20200415091204eucas1p1983548c2db52d8d0c2a5367034ec80dd@eucas1p1.samsung.com>]
* Re: [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops [not found] ` <CGME20200415091204eucas1p1983548c2db52d8d0c2a5367034ec80dd@eucas1p1.samsung.com> @ 2020-04-15 9:12 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-15 9:12 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/7/20 7:49 PM, Andrzej Pietrasiewicz wrote: > int3400_thermal_ops is used inside int3400_thermal_probe() only after > the assignments, which can just as well be made statically at struct's > initizer. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index efae0c02d898..634b943e9e3d 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -271,6 +271,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > + .get_mode = int3400_thermal_get_mode, > + .set_mode = int3400_thermal_set_mode, > }; > > static struct thermal_zone_params int3400_thermal_params = { > @@ -309,9 +311,6 @@ static int int3400_thermal_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, priv); > > - int3400_thermal_ops.get_mode = int3400_thermal_get_mode; > - int3400_thermal_ops.set_mode = int3400_thermal_set_mode; > - > priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, > priv, &int3400_thermal_ops, > &int3400_thermal_params, 0, 0); > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 2/8] thermal: Properly handle mode values in .set_mode() 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415100543eucas1p24e24293da39844ca8791db86af5365a7@eucas1p2.samsung.com> 2020-04-07 17:49 ` [RFC 3/8] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz ` (6 subsequent siblings) 8 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Allow only THERMAL_DEVICE_ENABLED and THERMAL_DEVICE_DISABLED as valid states to transition to. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 8 ++++++-- drivers/platform/x86/acerhdf.c | 4 ++++ drivers/thermal/imx_thermal.c | 4 +++- drivers/thermal/intel/intel_quark_dts_thermal.c | 5 ++++- drivers/thermal/of-thermal.c | 4 +++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..cd435ca7adbe 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -296,8 +296,10 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; - else + else if (mode == THERMAL_DEVICE_DISABLED) tzdev->polling_delay = 0; + else + return -EINVAL; mutex_unlock(&tzdev->lock); @@ -486,8 +488,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; - else + else if (mode == THERMAL_DEVICE_DISABLED) tzdev->polling_delay = 0; + else + return -EINVAL; mutex_unlock(&tzdev->lock); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..d5188c1d688b 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -431,6 +431,10 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, static int acerhdf_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) acerhdf_revert_to_bios_mode(); else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index bb6754a5342c..014512581918 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -368,7 +368,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, data->irq_enabled = true; enable_irq(data->irq); } - } else { + } else if (mode == THERMAL_DEVICE_DISABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -381,6 +381,8 @@ static int imx_set_mode(struct thermal_zone_device *tz, disable_irq(data->irq); data->irq_enabled = false; } + } else { + return -EINVAL; } data->mode = mode; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index 5d33b350da1c..5f4bcc0e4fd3 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -328,8 +328,11 @@ static int sys_set_mode(struct thermal_zone_device *tzd, mutex_lock(&dts_update_mutex); if (mode == THERMAL_DEVICE_ENABLED) ret = soc_dts_enable(tzd); - else + else if (mode == THERMAL_DEVICE_DISABLED) ret = soc_dts_disable(tzd); + else + return -EINVAL; + mutex_unlock(&dts_update_mutex); return ret; diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index ef0baa954ff0..b7621dfab17c 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -289,9 +289,11 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; - } else { + } else if (mode == THERMAL_DEVICE_DISABLED) { tz->polling_delay = 0; tz->passive_delay = 0; + } else { + return -EINVAL; } mutex_unlock(&tz->lock); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
[parent not found: <CGME20200415100543eucas1p24e24293da39844ca8791db86af5365a7@eucas1p2.samsung.com>]
* Re: [RFC 2/8] thermal: Properly handle mode values in .set_mode() [not found] ` <CGME20200415100543eucas1p24e24293da39844ca8791db86af5365a7@eucas1p2.samsung.com> @ 2020-04-15 10:05 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-15 10:05 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/7/20 7:49 PM, Andrzej Pietrasiewicz wrote: > Allow only THERMAL_DEVICE_ENABLED and THERMAL_DEVICE_DISABLED as valid > states to transition to. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 8 ++++++-- > drivers/platform/x86/acerhdf.c | 4 ++++ > drivers/thermal/imx_thermal.c | 4 +++- > drivers/thermal/intel/intel_quark_dts_thermal.c | 5 ++++- > drivers/thermal/of-thermal.c | 4 +++- > 5 files changed, 20 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..cd435ca7adbe 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -296,8 +296,10 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > tzdev->polling_delay = 0; > + else > + return -EINVAL; Making sure that the valid parameters are passed to driver specific ->set_mode method should be handled in the higher layer (callers). Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > mutex_unlock(&tzdev->lock); > > @@ -486,8 +488,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > tzdev->polling_delay = 0; > + else > + return -EINVAL; > > mutex_unlock(&tzdev->lock); > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..d5188c1d688b 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -431,6 +431,10 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > static int acerhdf_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > + > if (mode == THERMAL_DEVICE_DISABLED && kernelmode) > acerhdf_revert_to_bios_mode(); > else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index bb6754a5342c..014512581918 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -368,7 +368,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, > data->irq_enabled = true; > enable_irq(data->irq); > } > - } else { > + } else if (mode == THERMAL_DEVICE_DISABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -381,6 +381,8 @@ static int imx_set_mode(struct thermal_zone_device *tz, > disable_irq(data->irq); > data->irq_enabled = false; > } > + } else { > + return -EINVAL; > } > > data->mode = mode; > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index 5d33b350da1c..5f4bcc0e4fd3 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -328,8 +328,11 @@ static int sys_set_mode(struct thermal_zone_device *tzd, > mutex_lock(&dts_update_mutex); > if (mode == THERMAL_DEVICE_ENABLED) > ret = soc_dts_enable(tzd); > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > ret = soc_dts_disable(tzd); > + else > + return -EINVAL; > + > mutex_unlock(&dts_update_mutex); > > return ret; > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index ef0baa954ff0..b7621dfab17c 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -289,9 +289,11 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > - } else { > + } else if (mode == THERMAL_DEVICE_DISABLED) { > tz->polling_delay = 0; > tz->passive_delay = 0; > + } else { > + return -EINVAL; > } > > mutex_unlock(&tz->lock); > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 3/8] thermal: Store thermal mode in a dedicated enum 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 2/8] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415100944eucas1p1dcfeb784e790ca2fc3417fd2797e3f5d@eucas1p1.samsung.com> 2020-04-07 17:49 ` [RFC 4/8] thermal: core: Introduce THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz ` (5 subsequent siblings) 8 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Prepare for adding THERMAL_DEVICE_INITIAL mode. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 27 +++++++++---------- drivers/platform/x86/acerhdf.c | 12 ++++++--- .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..a93b0412dd6b 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,7 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; + enum thermal_device_mode mode; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, if (!tz) return -EINVAL; - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; + *mode = tz->mode; return 0; } @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != tz->mode) { + tz->mode = mode; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); + tz->mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); acpi_thermal_check(tz); } return 0; @@ -913,7 +910,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; + tz->mode = THERMAL_DEVICE_ENABLED; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index d5188c1d688b..87e357017d4a 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -65,8 +65,10 @@ #ifdef START_IN_KERNEL_MODE static int kernelmode = 1; +static enum thermal_device_mode thermal_mode = THERMAL_DEVICE_ENABLED; #else static int kernelmode; +static enum thermal_device_mode thermal_mode = THERMAL_DEVICE_DISABLED; #endif static unsigned int interval = 10; @@ -416,8 +418,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, if (verbose) pr_notice("kernel mode fan control %d\n", kernelmode); - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; + *mode = thermal_mode; return 0; } @@ -435,10 +436,13 @@ static int acerhdf_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_ENABLED) return -EINVAL; - if (mode == THERMAL_DEVICE_DISABLED && kernelmode) + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) { acerhdf_revert_to_bios_mode(); - else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) + thermal_mode = THERMAL_DEVICE_DISABLED; + } else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) { acerhdf_enable_kernelmode(); + thermal_mode = THERMAL_DEVICE_ENABLED; + } return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 634b943e9e3d..fcbd1b14fa74 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,7 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; + enum thermal_device_mode mode; int art_count; struct art *arts; int trt_count; @@ -247,24 +247,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + if (mode != priv->mode) { + priv->mode = mode; result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
[parent not found: <CGME20200415100944eucas1p1dcfeb784e790ca2fc3417fd2797e3f5d@eucas1p1.samsung.com>]
* Re: [RFC 3/8] thermal: Store thermal mode in a dedicated enum [not found] ` <CGME20200415100944eucas1p1dcfeb784e790ca2fc3417fd2797e3f5d@eucas1p1.samsung.com> @ 2020-04-15 10:09 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-15 10:09 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/7/20 7:49 PM, Andrzej Pietrasiewicz wrote: > Prepare for adding THERMAL_DEVICE_INITIAL mode. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/acpi/thermal.c | 27 +++++++++---------- > drivers/platform/x86/acerhdf.c | 12 ++++++--- > .../intel/int340x_thermal/int3400_thermal.c | 18 +++++-------- > 3 files changed, 27 insertions(+), 30 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..a93b0412dd6b 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,7 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > + enum thermal_device_mode mode; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +500,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -534,8 +534,7 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, > if (!tz) > return -EINVAL; > > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > + *mode = tz->mode; > > return 0; > } > @@ -544,27 +543,25 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != tz->mode) { > + tz->mode = mode; > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > + tz->mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > acpi_thermal_check(tz); > } > return 0; > @@ -913,7 +910,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > + tz->mode = THERMAL_DEVICE_ENABLED; > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index d5188c1d688b..87e357017d4a 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -65,8 +65,10 @@ > > #ifdef START_IN_KERNEL_MODE > static int kernelmode = 1; > +static enum thermal_device_mode thermal_mode = THERMAL_DEVICE_ENABLED; > #else > static int kernelmode; > +static enum thermal_device_mode thermal_mode = THERMAL_DEVICE_DISABLED; > #endif > > static unsigned int interval = 10; > @@ -416,8 +418,7 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > if (verbose) > pr_notice("kernel mode fan control %d\n", kernelmode); > > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > + *mode = thermal_mode; > > return 0; > } > @@ -435,10 +436,13 @@ static int acerhdf_set_mode(struct thermal_zone_device *thermal, > mode != THERMAL_DEVICE_ENABLED) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_DISABLED && kernelmode) > + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) { > acerhdf_revert_to_bios_mode(); > - else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) > + thermal_mode = THERMAL_DEVICE_DISABLED; > + } else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) { > acerhdf_enable_kernelmode(); > + thermal_mode = THERMAL_DEVICE_ENABLED; > + } > > return 0; > } The conversion missed: * handling of "force_bios" and force_product" kernel parameters: if (force_bios[0]) { version = force_bios; pr_info("forcing BIOS version: %s\n", version); kernelmode = 0; } if (force_product[0]) { product = force_product; pr_info("forcing BIOS product: %s\n", product); kernelmode = 0; } * acerhdf_revert_to_bios_mode() call on error in acerhdf_set_cur_state() Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 634b943e9e3d..fcbd1b14fa74 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,7 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > + enum thermal_device_mode mode; > int art_count; > struct art *arts; > int trt_count; > @@ -247,24 +247,20 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != priv->mode) { > + priv->mode = mode; > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 4/8] thermal: core: Introduce THERMAL_DEVICE_INITIAL 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-04-07 17:49 ` [RFC 3/8] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 5/8] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz ` (4 subsequent siblings) 8 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Add a new mode: THERMAL_DEVICE_INITIAL. It is dedicated to handle devices which must be initially DISABLED, but which are polled at startup nonetheless. THERMAL_DEVICE_INITIAL shall be reported as "enabled" in sysfs to keep the userspace interface intact. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_sysfs.c | 4 ++-- include/linux/thermal.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..6bfef21abce4 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -59,8 +59,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) if (result) return result; - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" - : "disabled"); + return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_DISABLED ? "disabled" + : "enabled"); } static ssize_t diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 126913c6a53b..1bc6b7998093 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -48,8 +48,9 @@ struct thermal_cooling_device; struct thermal_instance; enum thermal_device_mode { - THERMAL_DEVICE_DISABLED = 0, + THERMAL_DEVICE_INITIAL = 0, THERMAL_DEVICE_ENABLED, + THERMAL_DEVICE_DISABLED, }; enum thermal_trip_type { -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC 5/8] thermal: core: Monitor thermal zone after mode change 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (3 preceding siblings ...) 2020-04-07 17:49 ` [RFC 4/8] thermal: core: Introduce THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 6/8] thermal: Set initial state to THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz ` (3 subsequent siblings) 8 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Mode changing might imply a need to stop/start polling the device. monitor_thermal_zone() when mode changes or if previous mode is unknown. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 26 ++++++++++++++++++++++++++ drivers/thermal/thermal_core.h | 2 ++ drivers/thermal/thermal_sysfs.c | 8 +++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9a321dc548c8..aae2b049d45c 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -469,6 +469,32 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + enum thermal_device_mode old_mode; + int result; + + if (!tz->ops->set_mode) + return -EPERM; + + if (tz->ops->get_mode) { + result = tz->ops->get_mode(tz, &old_mode); + if (result) + return result; + } + + result = tz->ops->set_mode(tz, mode); + if (result) + return result; + + /* old mode unknown or mode changed */ + if (!tz->ops->get_mode || mode != old_mode) + monitor_thermal_zone(tz); + + return 0; +} + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index a9bf00e91d64..1ed0bdb812d8 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -74,6 +74,8 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *, int); void thermal_zone_destroy_device_groups(struct thermal_zone_device *); void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *); void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev); +int thermal_zone_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); /* used only at binding time */ ssize_t trip_point_show(struct device *, struct device_attribute *, char *); ssize_t weight_show(struct device *, struct device_attribute *, char *); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 6bfef21abce4..cc1f808b48b3 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -68,18 +68,20 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); + enum thermal_device_mode mode; int result; if (!tz->ops->set_mode) return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + mode = THERMAL_DEVICE_ENABLED; else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + mode = THERMAL_DEVICE_DISABLED; else - result = -EINVAL; + return -EINVAL; + result = thermal_zone_set_mode(tz, mode); if (result) return result; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC 6/8] thermal: Set initial state to THERMAL_DEVICE_INITIAL 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (4 preceding siblings ...) 2020-04-07 17:49 ` [RFC 5/8] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 7/8] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz ` (2 subsequent siblings) 8 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Now that THERMAL_DEVICE_INITIAL is available use it. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 1 + drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 3 +++ drivers/platform/x86/acerhdf.c | 1 + drivers/thermal/da9062-thermal.c | 2 +- drivers/thermal/imx_thermal.c | 1 + drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 1 + drivers/thermal/intel/intel_quark_dts_thermal.c | 1 + 7 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index a93b0412dd6b..0f352cef4898 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -881,6 +881,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; i++, trips++); + tz->mode = THERMAL_DEVICE_INITIAL; if (tz->trips.passive.flags.valid) tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index cd435ca7adbe..a58ab4d18331 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -758,6 +758,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d", module_tz->module + 1); + module_tz->mode = THERMAL_DEVICE_INITIAL; module_tz->tzdev = thermal_zone_device_register(tz_name, MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, @@ -876,6 +877,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); + gearbox_tz->mode = THERMAL_DEVICE_INITIAL; gearbox_tz->tzdev = thermal_zone_device_register(tz_name, MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, @@ -1033,6 +1035,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, MLXSW_THERMAL_SLOW_POLL_INT : MLXSW_THERMAL_POLL_INT; + thermal->mode = THERMAL_DEVICE_INITIAL; thermal->tzdev = thermal_zone_device_register("mlxsw", MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 87e357017d4a..00751a0f5312 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -747,6 +747,7 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + thermal_mode = THERMAL_DEVICE_INITIAL; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..2f876760d667 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -233,7 +233,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; + thermal->mode = THERMAL_DEVICE_INITIAL; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 014512581918..1e8fd56c2568 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -805,6 +805,7 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } + data->mode = THERMAL_DEVICE_INITIAL; data->tz = thermal_zone_device_register("imx_thermal_zone", IMX_TRIP_NUM, BIT(IMX_TRIP_PASSIVE), data, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index fcbd1b14fa74..9c8caa37ed13 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -307,6 +307,7 @@ static int int3400_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); + priv->mode = THERMAL_DEVICE_INITIAL; priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, priv, &int3400_thermal_ops, &int3400_thermal_params, 0, 0); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index 5f4bcc0e4fd3..af588ff9aa76 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -411,6 +411,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } + aux_entry->mode = THERMAL_DEVICE_INITIAL; aux_entry->tzone = thermal_zone_device_register("quark_dts", QRK_MAX_DTS_TRIPS, wr_mask, -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC 7/8] thermal: of: Monitor thermal zone after enabling it 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (5 preceding siblings ...) 2020-04-07 17:49 ` [RFC 6/8] thermal: Set initial state to THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415101829eucas1p18e21324d3c39926fffc6c8b5dc52f206@eucas1p1.samsung.com> 2020-04-07 17:49 ` [RFC 8/8] thermal: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-09 10:29 ` [RFC 0/8] Stop monitoring disabled devices Daniel Lezcano 8 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz thermal/of calls its own ->set_mode() method, so monitor thermal zone afterwards. This is needed for the DISABLED->ENABLED transition. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/of-thermal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index b7621dfab17c..cf2c43ebcb78 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -523,8 +523,11 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, if (sensor_specs.np == sensor_np && id == sensor_id) { tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); - if (!IS_ERR(tzd)) + if (!IS_ERR(tzd)) { tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_update(tzd, + THERMAL_EVENT_UNSPECIFIED); + } of_node_put(sensor_specs.np); of_node_put(child); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
[parent not found: <CGME20200415101829eucas1p18e21324d3c39926fffc6c8b5dc52f206@eucas1p1.samsung.com>]
* Re: [RFC 7/8] thermal: of: Monitor thermal zone after enabling it [not found] ` <CGME20200415101829eucas1p18e21324d3c39926fffc6c8b5dc52f206@eucas1p1.samsung.com> @ 2020-04-15 10:18 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-15 10:18 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/7/20 7:49 PM, Andrzej Pietrasiewicz wrote: > thermal/of calls its own ->set_mode() method, so monitor thermal zone > afterwards. This is needed for the DISABLED->ENABLED transition. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/thermal/of-thermal.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index b7621dfab17c..cf2c43ebcb78 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -523,8 +523,11 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > if (sensor_specs.np == sensor_np && id == sensor_id) { > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > - if (!IS_ERR(tzd)) > + if (!IS_ERR(tzd)) { > tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + thermal_zone_device_update(tzd, > + THERMAL_EVENT_UNSPECIFIED); > + } > > of_node_put(sensor_specs.np); > of_node_put(child); > This patch is bogus/redundant, please look at ->set_mode implementation for thermal/of drivers: static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { struct __thermal_zone *data = tz->devdata; mutex_lock(&tz->lock); if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; } else { tz->polling_delay = 0; tz->passive_delay = 0; } mutex_unlock(&tz->lock); data->mode = mode; thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; } Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC 8/8] thermal: Stop polling DISABLED thermal devices 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (6 preceding siblings ...) 2020-04-07 17:49 ` [RFC 7/8] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz @ 2020-04-07 17:49 ` Andrzej Pietrasiewicz 2020-04-09 10:29 ` [RFC 0/8] Stop monitoring disabled devices Daniel Lezcano 8 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-07 17:49 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index aae2b049d45c..f74b7a792be7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,13 +305,32 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static bool should_stop_polling(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + int result; + + if (!tz->ops->get_mode) + return false; + + result = tz->ops->get_mode(tz, &mode); + if (result) + return false; + + return mode == THERMAL_DEVICE_DISABLED; +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -500,6 +519,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC 0/8] Stop monitoring disabled devices 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz ` (7 preceding siblings ...) 2020-04-07 17:49 ` [RFC 8/8] thermal: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-04-09 10:29 ` Daniel Lezcano 2020-04-09 11:10 ` Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz 8 siblings, 2 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-04-09 10:29 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 07/04/2020 19:49, Andrzej Pietrasiewicz wrote: > The current kernel behavior is to keep polling the thermal zone devices > regardless of their current mode. This is not desired, as all such "disabled" > devices are meant to be handled by userspace,> so polling them makes no sense. Thanks for proposing these changes. I've been (quickly) through the series and the description below. I have the feeling the series makes more complex while the current code which would deserve a cleanup. Why not first: - Add a 'mode' field in the thermal zone device - Kill all set/get_mode callbacks in the drivers which are duplicated code. - Add a function: enum thermal_device_mode thermal_zone_get_mode( *tz) { ... if (tz->ops->get_mode) return tz->ops->get_mode(); return tz->mode; } int thermal_zone_set_mode(..*tz, enum thermal_device_mode mode) { ... if (tz->ops->set_mode) return tz->ops->set_mode(tz, mode); tz->mode = mode; return 0; } static inline thermal_zone_enable(... *tz) { thermal_zone_set_mode(tz, THERMAL_DEVICE_ENABLED); } static inline thermal_zone_disable(... *tz) { thermal_zone_set_mode(tz, THERMAL_DEVICE_DISABLED); } And then when the code is consolidated, use the mode to enable/disable the polling and continue killing the duplicated code in of-thermal.c and anywhere else. > There was an attempt to solve this issue: > > https://lkml.org/lkml/2018/2/26/498 > > and it ultimately has not succeeded: > > https://lkml.org/lkml/2018/2/27/910 > > This is a new attempt addressing all the relevant drivers, and I have > identified them with: > > $ git grep "thermal_zone_device_ops" | grep "= {" | cut -f1 -d: | sort | uniq > > The idea is to modify thermal_zone_device_update() and monitor_thermal_zone() > in such a way that they stop polling a disabled device. To do decide what to > do they should call ->get_mode() operation of the specialized thermal zone > device in question (e.g. drivers/acpi/thermal.c's). But here comes problem: > sometimes a thermal zone device must be initially disabled and becomes enabled > only after its sensors appear on the system. If such thermal zone's > ->get_mode() /* in the context of thermal_zone_device_update() or > monitor_thermal_zone() */ is called _before_ the sensors are available, it will > be reported as "disabled" and consequently polling it will be ceased. This is > a change in behavior from userspace's perspective. > > To solve the above described problem I want to introduce the third mode of a > thermal_zone_device: initial. The idea is that when the device is in its > initial mode, then its polling will be handled as it is now. This is a good > thing: should the temperature be just about hitting the critical treshnold > early during the boot process, it might be too late if we wait for the > userspace to run to save the system from overheating. The initial mode should > be reported in sysfs as "enabled" to keep the userspace interface intact. > From the initial mode there will be two possible transitions: to enabled or > disabled mode, but there will be no transition back to initial. If the > transition is from initial to enabled, then keep polling. If the transition is > from initial to disabled, then stop polling. If the transition is from enabled > to disabled, then stop polling. The transition from disabled to enabled must > be handled in a special way: there must be a mandatory call to > monitor_thermal_zone(), otherwise the polling will not start. If this > transition is triggeted from sysfs, then it can be easily handled at the > thermal framework level. However, if drivers call their own ->set_mode() > operation then they must also call "monitor_thermal_zone()" afterwards. > The latter being a sensible thing anyway, so perhaps all/most of the drivers > in question do. The plan for implementation is this: > > - ensure ALL users use symbolic enum names (THERMAL_DEVICE_DISABLED, > THERMAL_DEVICE_ENABLED) for thermal device mode rather than the numeric > values of enum thermal_device_mode elements > - add THERMAL_DEVICE_INITIAL to the said enum making its value 0 (so that > kzalloc() results in the initial state) > - modify thermal zone device's mode_show() (thermal framework level) so that > it reports "enabled" for THERMAL_DEVICE_INITIAL > - modify thermal zone device's mode_store() (thermal framework level) so that > it calls monitor_thermal_zone() upon mode change > - modify ALL thermal drivers so that their code is prepared to return > THERMAL_DEVICE_INITIAL before they call thermal_zone_device_register(); when > the invocation of the latter completes then polling is expected to be started > - verify ALL drivers which call their own ->set_mode() to ensure they do call > monitor_thermal_zone() afterwards > - modify thermal_zone_device_update() and monitor_thermal_zone() so that they > cancel polling for disabled thermal zone devices (but not for those in > THERMAL_DEVICE_INITIAL mode) > > This RFC series does all the above steps in more or less that order. > > I kindly ask for comments/suggestions/improvements. > > Rebased onto v5.6. > > Andrzej Pietrasiewicz (8): > thermal: int3400_thermal: Statically initialize > .get_mode()/.set_mode() ops > thermal: Properly handle mode values in .set_mode() > thermal: Store thermal mode in a dedicated enum > thermal: core: Introduce THERMAL_DEVICE_INITIAL > thermal: core: Monitor thermal zone after mode change > thermal: Set initial state to THERMAL_DEVICE_INITIAL > thermal: of: Monitor thermal zone after enabling it > thermal: Stop polling DISABLED thermal devices > > drivers/acpi/thermal.c | 28 +++++----- > .../ethernet/mellanox/mlxsw/core_thermal.c | 11 +++- > drivers/platform/x86/acerhdf.c | 17 ++++-- > drivers/thermal/da9062-thermal.c | 2 +- > drivers/thermal/imx_thermal.c | 5 +- > .../intel/int340x_thermal/int3400_thermal.c | 24 ++++----- > .../thermal/intel/intel_quark_dts_thermal.c | 6 ++- > drivers/thermal/of-thermal.c | 9 +++- > drivers/thermal/thermal_core.c | 52 ++++++++++++++++++- > drivers/thermal/thermal_core.h | 2 + > drivers/thermal/thermal_sysfs.c | 12 +++-- > include/linux/thermal.h | 3 +- > 12 files changed, 123 insertions(+), 48 deletions(-) > -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC 0/8] Stop monitoring disabled devices 2020-04-09 10:29 ` [RFC 0/8] Stop monitoring disabled devices Daniel Lezcano @ 2020-04-09 11:10 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415104010eucas1p101278e53e34a2e56dfc7c82b533a9122@eucas1p1.samsung.com> 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-09 11:10 UTC (permalink / raw) To: Daniel Lezcano, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Daniel, W dniu 09.04.2020 o 12:29, Daniel Lezcano pisze: > On 07/04/2020 19:49, Andrzej Pietrasiewicz wrote: >> The current kernel behavior is to keep polling the thermal zone devices >> regardless of their current mode. This is not desired, as all such "disabled" >> devices are meant to be handled by userspace,> so polling them makes no sense. > > Thanks for proposing these changes. > > I've been (quickly) through the series and the description below. I have > the feeling the series makes more complex while the current code which > would deserve a cleanup. > > Why not first: > > - Add a 'mode' field in the thermal zone device > - Kill all set/get_mode callbacks in the drivers which are duplicated code. > - Add a function: > > enum thermal_device_mode thermal_zone_get_mode( *tz) > { > ... > if (tz->ops->get_mode) > return tz->ops->get_mode(); > > return tz->mode; > } > > > int thermal_zone_set_mode(..*tz, enum thermal_device_mode mode) > { > ... > if (tz->ops->set_mode) > return tz->ops->set_mode(tz, mode); > > tz->mode = mode; > > return 0; > } > > static inline thermal_zone_enable(... *tz) > { > thermal_zone_set_mode(tz, THERMAL_DEVICE_ENABLED); > } > > static inline thermal_zone_disable(... *tz) { > thermal_zone_set_mode(tz, THERMAL_DEVICE_DISABLED); > } > > And then when the code is consolidated, use the mode to enable/disable > the polling and continue killing the duplicated code in of-thermal.c and > anywhere else. > > Thanks for feedback. Anyone else? Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
[parent not found: <CGME20200415104010eucas1p101278e53e34a2e56dfc7c82b533a9122@eucas1p1.samsung.com>]
* Re: [RFC 0/8] Stop monitoring disabled devices [not found] ` <CGME20200415104010eucas1p101278e53e34a2e56dfc7c82b533a9122@eucas1p1.samsung.com> @ 2020-04-15 10:40 ` Bartlomiej Zolnierkiewicz 2020-04-17 16:23 ` Andrzej Pietrasiewicz 2020-04-17 21:11 ` Peter Kästle 0 siblings, 2 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-15 10:40 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Daniel Lezcano, linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/9/20 1:10 PM, Andrzej Pietrasiewicz wrote: > Hi Daniel, > > W dniu 09.04.2020 o 12:29, Daniel Lezcano pisze: >> On 07/04/2020 19:49, Andrzej Pietrasiewicz wrote: >>> The current kernel behavior is to keep polling the thermal zone devices >>> regardless of their current mode. This is not desired, as all such "disabled" >>> devices are meant to be handled by userspace,> so polling them makes no sense. >> >> Thanks for proposing these changes. >> >> I've been (quickly) through the series and the description below. I have >> the feeling the series makes more complex while the current code which >> would deserve a cleanup. >> >> Why not first: >> >> - Add a 'mode' field in the thermal zone device >> - Kill all set/get_mode callbacks in the drivers which are duplicated code. >> - Add a function: >> >> enum thermal_device_mode thermal_zone_get_mode( *tz) >> { >> ... >> if (tz->ops->get_mode) >> return tz->ops->get_mode(); >> >> return tz->mode; >> } >> >> >> int thermal_zone_set_mode(..*tz, enum thermal_device_mode mode) >> { >> ... >> if (tz->ops->set_mode) >> return tz->ops->set_mode(tz, mode); >> >> tz->mode = mode; >> >> return 0; >> } >> >> static inline thermal_zone_enable(... *tz) >> { >> thermal_zone_set_mode(tz, THERMAL_DEVICE_ENABLED); >> } >> >> static inline thermal_zone_disable(... *tz) { >> thermal_zone_set_mode(tz, THERMAL_DEVICE_DISABLED); >> } >> >> And then when the code is consolidated, use the mode to enable/disable >> the polling and continue killing the duplicated code in of-thermal.c and >> anywhere else. >> >> > > Thanks for feedback. > > Anyone else? Yes. :) Please take a look at the following patchset (which I'm reviving currently): https://lkml.org/lkml/2018/10/17/926 It overlaps partially with your work so we need to coordinate our efforts. Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC 0/8] Stop monitoring disabled devices 2020-04-15 10:40 ` Bartlomiej Zolnierkiewicz @ 2020-04-17 16:23 ` Andrzej Pietrasiewicz 2020-04-19 11:42 ` Bartlomiej Zolnierkiewicz 2020-04-17 21:11 ` Peter Kästle 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-17 16:23 UTC (permalink / raw) To: Bartlomiej Zolnierkiewicz Cc: Daniel Lezcano, linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Barlomiej, >> Thanks for feedback. >> >> Anyone else? > > Yes. :) > > Please take a look at the following patchset (which I'm reviving currently): > > https://lkml.org/lkml/2018/10/17/926 > > It overlaps partially with your work so we need to coordinate our efforts. > I've just sent a v3. After addressing your and Daniel's comments my series now looks pretty compact. Let's see if there's more feedback. Is your work on reviving the above mentioned 2018 series ready? Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC 0/8] Stop monitoring disabled devices 2020-04-17 16:23 ` Andrzej Pietrasiewicz @ 2020-04-19 11:42 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-19 11:42 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Daniel Lezcano, linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/17/20 6:23 PM, Andrzej Pietrasiewicz wrote: > Hi Barlomiej, > >>> Thanks for feedback. >>> >>> Anyone else? >> >> Yes. :) >> >> Please take a look at the following patchset (which I'm reviving currently): >> >> https://protect2.fireeye.com/url?k=5d37badf-00a92135-5d363190-0cc47a6cba04-376ae45aa028b19a&q=1&u=https%3A%2F%2Flkml.org%2Flkml%2F2018%2F10%2F17%2F926 >> >> It overlaps partially with your work so we need to coordinate our efforts. >> > > I've just sent a v3. After addressing your and Daniel's comments my series > now looks pretty compact. Let's see if there's more feedback. Is your work on > reviving the above mentioned 2018 series ready? Not yet, also I think now that it will be the best if I rebase my changes on top of your patchset (once it is ready/finished). Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC 0/8] Stop monitoring disabled devices 2020-04-15 10:40 ` Bartlomiej Zolnierkiewicz 2020-04-17 16:23 ` Andrzej Pietrasiewicz @ 2020-04-17 21:11 ` Peter Kästle 1 sibling, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-04-17 21:11 UTC (permalink / raw) To: Andrzej Pietrasiewicz, Bartlomiej Zolnierkiewicz Cc: Daniel Lezcano, linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi, 17. April 2020 18:23, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: [...] > I've just sent a v3. After addressing your and Daniel's comments my series > now looks pretty compact. Let's see if there's more feedback. Is your work on > reviving the above mentioned 2018 series ready? I agree, v3 looks pretty good, I will test it within next 2 days for acerhdf. Thanks for your work! -- --peter; ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 0/9] Stop monitoring disabled devices 2020-04-09 10:29 ` [RFC 0/8] Stop monitoring disabled devices Daniel Lezcano 2020-04-09 11:10 ` Andrzej Pietrasiewicz @ 2020-04-14 18:00 ` Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz ` (9 more replies) 1 sibling, 10 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:00 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz This is the second iteration of this RFC. The series now focuses on cleaning up the code in the first place. After the cleanups in patches 1-3 struct thermal_zone_device is extended so that it contains a "mode" member (patch 4/9). The next patch (5/9) makes all thermal zone devices use the "mode" member. This patch makes drivers' ->get_mode() methods redundant, so the next one (6/9) removes the method altogether. Patches 7-8/9 ensure that after changing thermal zone device's mode an attempt will be made to monitor the device. And finally patch 9/9 prevents DISABLED devices from being monitored. It also adds THERMAL_DEVICE_INITIAL to accommodate the devices, which should be monitored but cannot be initially ENABLED. Andrzej Pietrasiewicz (9): thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops thermal: Eliminate an always-false condition thermal: Properly handle mode values in .set_mode() thermal: core: Let thermal zone device's mode be stored in its struct thermal: Store mode in thermal_zone_device thermal: Remove get_mode() method thermal: core: Monitor thermal zone after mode change thermal: of: Monitor thermal zone after enabling it thermal: core: Stop polling DISABLED thermal devices drivers/acpi/thermal.c | 44 +++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 43 ++++----------- drivers/platform/x86/acerhdf.c | 28 +++++----- drivers/thermal/da9062-thermal.c | 12 +--- drivers/thermal/imx_thermal.c | 30 ++++------ .../intel/int340x_thermal/int3400_thermal.c | 39 +++---------- .../thermal/intel/intel_quark_dts_thermal.c | 27 ++++----- drivers/thermal/of-thermal.c | 28 ++++------ drivers/thermal/thermal_core.c | 40 ++++++++++++-- drivers/thermal/thermal_core.h | 2 + drivers/thermal/thermal_sysfs.c | 40 ++++---------- include/linux/thermal.h | 55 ++++++++++++++++++- 12 files changed, 180 insertions(+), 208 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz @ 2020-04-14 18:00 ` Andrzej Pietrasiewicz 2020-04-15 9:23 ` Daniel Lezcano 2020-04-14 18:00 ` [RFC v2 2/9] thermal: Eliminate an always-false condition Andrzej Pietrasiewicz ` (8 subsequent siblings) 9 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:00 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz int3400_thermal_ops is used inside int3400_thermal_probe() only after the assignments, which can just as well be made statically at struct's initizer. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index ceef89c956bd..e802922a13cf 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -271,6 +271,8 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, + .get_mode = int3400_thermal_get_mode, + .set_mode = int3400_thermal_set_mode, }; static struct thermal_zone_params int3400_thermal_params = { @@ -309,9 +311,6 @@ static int int3400_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); - int3400_thermal_ops.get_mode = int3400_thermal_get_mode; - int3400_thermal_ops.set_mode = int3400_thermal_set_mode; - priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0, priv, &int3400_thermal_ops, &int3400_thermal_params, 0, 0); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops 2020-04-14 18:00 ` [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz @ 2020-04-15 9:23 ` Daniel Lezcano 0 siblings, 0 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-04-15 9:23 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Bartlomiej Zolnierkiewicz On 14/04/2020 20:00, Andrzej Pietrasiewicz wrote: > int3400_thermal_ops is used inside int3400_thermal_probe() only after > the assignments, which can just as well be made statically at struct's > initizer. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- Applied this patch with Bartlomiej's tag. Thanks -- Daniel -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 2/9] thermal: Eliminate an always-false condition 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz @ 2020-04-14 18:00 ` Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz ` (7 subsequent siblings) 9 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:00 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz This driver provides a non-NULL "devdata" argument for thermal_zone_device_register(). Thermal core never sets it to NULL afterwards, so checking for its being NULL in this driver makes no sense. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 6 ------ drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 6 ------ 2 files changed, 12 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..328b479ce7f6 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -531,9 +531,6 @@ static int thermal_get_mode(struct thermal_zone_device *thermal, { struct acpi_thermal *tz = thermal->devdata; - if (!tz) - return -EINVAL; - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; @@ -546,9 +543,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, struct acpi_thermal *tz = thermal->devdata; int enable; - if (!tz) - return -EINVAL; - /* * enable/disable thermal management from ACPI thermal driver */ diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e802922a13cf..fbb59dd09481 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -235,9 +235,6 @@ static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, { struct int3400_thermal_priv *priv = thermal->devdata; - if (!priv) - return -EINVAL; - *mode = priv->mode; return 0; @@ -250,9 +247,6 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, bool enable; int result = 0; - if (!priv) - return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) enable = true; else if (mode == THERMAL_DEVICE_DISABLED) -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 2/9] thermal: Eliminate an always-false condition Andrzej Pietrasiewicz @ 2020-04-14 18:00 ` Andrzej Pietrasiewicz 2020-04-14 22:14 ` Daniel Lezcano 2020-04-14 18:01 ` [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz ` (6 subsequent siblings) 9 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:00 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Allow only THERMAL_DEVICE_ENABLED and THERMAL_DEVICE_DISABLED as valid states to transition to. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 8 ++++++-- drivers/platform/x86/acerhdf.c | 4 ++++ drivers/thermal/imx_thermal.c | 4 +++- drivers/thermal/intel/intel_quark_dts_thermal.c | 5 ++++- drivers/thermal/of-thermal.c | 4 +++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..cd435ca7adbe 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -296,8 +296,10 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; - else + else if (mode == THERMAL_DEVICE_DISABLED) tzdev->polling_delay = 0; + else + return -EINVAL; mutex_unlock(&tzdev->lock); @@ -486,8 +488,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; - else + else if (mode == THERMAL_DEVICE_DISABLED) tzdev->polling_delay = 0; + else + return -EINVAL; mutex_unlock(&tzdev->lock); diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..d5188c1d688b 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -431,6 +431,10 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, static int acerhdf_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) acerhdf_revert_to_bios_mode(); else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..36b1924f1938 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -361,7 +361,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, data->irq_enabled = true; enable_irq(data->irq); } - } else { + } else if (mode == THERMAL_DEVICE_DISABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -374,6 +374,8 @@ static int imx_set_mode(struct thermal_zone_device *tz, disable_irq(data->irq); data->irq_enabled = false; } + } else { + return -EINVAL; } data->mode = mode; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..11d7db895125 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -325,8 +325,11 @@ static int sys_set_mode(struct thermal_zone_device *tzd, mutex_lock(&dts_update_mutex); if (mode == THERMAL_DEVICE_ENABLED) ret = soc_dts_enable(tzd); - else + else if (mode == THERMAL_DEVICE_DISABLED) ret = soc_dts_disable(tzd); + else + return -EINVAL; + mutex_unlock(&dts_update_mutex); return ret; diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 874a47d6923f..36bebf623980 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -289,9 +289,11 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; - } else { + } else if (mode == THERMAL_DEVICE_DISABLED) { tz->polling_delay = 0; tz->passive_delay = 0; + } else { + return -EINVAL; } mutex_unlock(&tz->lock); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() 2020-04-14 18:00 ` [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz @ 2020-04-14 22:14 ` Daniel Lezcano 0 siblings, 0 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-04-14 22:14 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Andrzej, you can drop this patch. It is not useful as the caller checks the correctness of the values in the patch 4/9. Moreover the patch is bogus because it returns before releasing the lock. On 14/04/2020 20:00, Andrzej Pietrasiewicz wrote: > Allow only THERMAL_DEVICE_ENABLED and THERMAL_DEVICE_DISABLED as valid > states to transition to. > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 8 ++++++-- > drivers/platform/x86/acerhdf.c | 4 ++++ > drivers/thermal/imx_thermal.c | 4 +++- > drivers/thermal/intel/intel_quark_dts_thermal.c | 5 ++++- > drivers/thermal/of-thermal.c | 4 +++- > 5 files changed, 20 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..cd435ca7adbe 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -296,8 +296,10 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > tzdev->polling_delay = 0; > + else > + return -EINVAL; > > mutex_unlock(&tzdev->lock); > > @@ -486,8 +488,10 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > tzdev->polling_delay = 0; > + else > + return -EINVAL; > > mutex_unlock(&tzdev->lock); > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..d5188c1d688b 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -431,6 +431,10 @@ static int acerhdf_get_mode(struct thermal_zone_device *thermal, > static int acerhdf_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > + > if (mode == THERMAL_DEVICE_DISABLED && kernelmode) > acerhdf_revert_to_bios_mode(); > else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..36b1924f1938 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -361,7 +361,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, > data->irq_enabled = true; > enable_irq(data->irq); > } > - } else { > + } else if (mode == THERMAL_DEVICE_DISABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -374,6 +374,8 @@ static int imx_set_mode(struct thermal_zone_device *tz, > disable_irq(data->irq); > data->irq_enabled = false; > } > + } else { > + return -EINVAL; > } > > data->mode = mode; > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..11d7db895125 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -325,8 +325,11 @@ static int sys_set_mode(struct thermal_zone_device *tzd, > mutex_lock(&dts_update_mutex); > if (mode == THERMAL_DEVICE_ENABLED) > ret = soc_dts_enable(tzd); > - else > + else if (mode == THERMAL_DEVICE_DISABLED) > ret = soc_dts_disable(tzd); > + else > + return -EINVAL; > + > mutex_unlock(&dts_update_mutex); > > return ret; > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 874a47d6923f..36bebf623980 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -289,9 +289,11 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > - } else { > + } else if (mode == THERMAL_DEVICE_DISABLED) { > tz->polling_delay = 0; > tz->passive_delay = 0; > + } else { > + return -EINVAL; > } > > mutex_unlock(&tz->lock); > -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (2 preceding siblings ...) 2020-04-14 18:00 ` [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-14 22:30 ` Daniel Lezcano 2020-04-14 18:01 ` [RFC v2 5/9] thermal: Store mode in thermal_zone_device Andrzej Pietrasiewicz ` (5 subsequent siblings) 9 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz All the drivers which provide ->get_mode()/->set_mode() methods store their mode in a thermal_device_mode enum, so keep this information in struct thermal_zone_device rather than scattered all over the place. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 28 +++++++++++++++++++ drivers/thermal/thermal_sysfs.c | 9 +++---- include/linux/thermal.h | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9a321dc548c8..cb0ff47f0dbe 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -469,6 +469,34 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode) +{ + if (tz->ops->get_mode) + return tz->ops->get_mode(tz, mode); + + *mode = tz->mode; + + return 0; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_get_mode); + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + + if (tz->ops->set_mode) + return tz->ops->set_mode(tz, mode); + + tz->mode = mode; + + return 0; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..66d9691b8bd6 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -52,10 +52,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) enum thermal_device_mode mode; int result; - if (!tz->ops->get_mode) - return -EPERM; - - result = tz->ops->get_mode(tz, &mode); + result = thermal_zone_device_get_mode(tz, &mode); if (result) return result; @@ -74,9 +71,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index c91b1e344d56..9ff8542b7e7d 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -143,6 +143,7 @@ struct thermal_attr { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -185,6 +186,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -437,6 +439,19 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); + +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode); +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); + +static inline void +thermal_zone_device_store_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + tz->mode = mode; +} + void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); void thermal_zone_set_trips(struct thermal_zone_device *); @@ -494,6 +509,17 @@ static inline int thermal_zone_unbind_cooling_device( struct thermal_zone_device *tz, int trip, struct thermal_cooling_device *cdev) { return -ENODEV; } +static inline int thermal_zone_device_get_mode(struct thermal_zone_device *tz, + enum thermal_device_mode *mode) +{ return -ENODEV; } +static inline int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ return -ENODEV; } +static inline void +thermal_zone_device_store_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ } + static inline void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { } @@ -543,4 +569,26 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { } #endif /* CONFIG_THERMAL */ +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + +static inline void +thermal_zone_device_store_enabled(struct thermal_zone_device *tz) +{ + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline void +thermal_zone_device_store_disabled(struct thermal_zone_device *tz) +{ + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_DISABLED); +} + #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-14 18:01 ` [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-14 22:30 ` Daniel Lezcano 0 siblings, 0 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-04-14 22:30 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 14/04/2020 20:01, Andrzej Pietrasiewicz wrote: > All the drivers which provide ->get_mode()/->set_mode() methods store their > mode in a thermal_device_mode enum, so keep this information in struct > thermal_zone_device rather than scattered all over the place. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/thermal/thermal_core.c | 28 +++++++++++++++++++ > drivers/thermal/thermal_sysfs.c | 9 +++---- > include/linux/thermal.h | 48 +++++++++++++++++++++++++++++++++ > 3 files changed, 79 insertions(+), 6 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 9a321dc548c8..cb0ff47f0dbe 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -469,6 +469,34 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode) > +{ > + if (tz->ops->get_mode) > + return tz->ops->get_mode(tz, mode); I think we can get rid of the get_mode here. locks missing. and mode = tz->mode must be always set. > + *mode = tz->mode; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_get_mode); > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; I'm not sure this is useful as 'mode' is an enum and this condition will be always correct. locks missing. > + if (tz->ops->set_mode) > + return tz->ops->set_mode(tz, mode); > + tz->mode = mode; It should be like: int ret = 0; mutex_lock(&tz->lock); if (tz->ops->set_mode) ret = tz->ops->set_mode(tz, mode); *mode = tz->mode; mutex_unlock(&tz->lock); return ret; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..66d9691b8bd6 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -52,10 +52,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > enum thermal_device_mode mode; > int result; > > - if (!tz->ops->get_mode) > - return -EPERM; > - > - result = tz->ops->get_mode(tz, &mode); > + result = thermal_zone_device_get_mode(tz, &mode); > if (result) > return result; > > @@ -74,9 +71,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index c91b1e344d56..9ff8542b7e7d 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -143,6 +143,7 @@ struct thermal_attr { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -185,6 +186,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -437,6 +439,19 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, > unsigned int); > int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, > struct thermal_cooling_device *); > + > +int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode); > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > + > +static inline void > +thermal_zone_device_store_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + tz->mode = mode; > +} > + Please remove this store_mode function, it is not needed. Just: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_disable() thermal_zone_device_enable() And all of them in drivers/thermal/thermal_core.h > void thermal_zone_device_update(struct thermal_zone_device *, > enum thermal_notify_event); > void thermal_zone_set_trips(struct thermal_zone_device *); > @@ -494,6 +509,17 @@ static inline int thermal_zone_unbind_cooling_device( > struct thermal_zone_device *tz, int trip, > struct thermal_cooling_device *cdev) > { return -ENODEV; } > +static inline int thermal_zone_device_get_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode *mode) > +{ return -ENODEV; } > +static inline int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ return -ENODEV; } > +static inline void > +thermal_zone_device_store_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ } > + > static inline void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { } > @@ -543,4 +569,26 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, > { } > #endif /* CONFIG_THERMAL */ > > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > +static inline void > +thermal_zone_device_store_enabled(struct thermal_zone_device *tz) > +{ > + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline void > +thermal_zone_device_store_disabled(struct thermal_zone_device *tz) > +{ > + thermal_zone_device_store_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > #endif /* __THERMAL_H__ */ > -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 5/9] thermal: Store mode in thermal_zone_device 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (3 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-15 10:55 ` Daniel Lezcano 2020-04-14 18:01 ` [RFC v2 6/9] thermal: Remove get_mode() method Andrzej Pietrasiewicz ` (4 subsequent siblings) 9 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz struct thermal_zone_device has a "mode" member now, so use it. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 48 +++++++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 35 ++------------ drivers/platform/x86/acerhdf.c | 24 ++++------ drivers/thermal/da9062-thermal.c | 12 +---- drivers/thermal/imx_thermal.c | 30 +++++------- .../intel/int340x_thermal/int3400_thermal.c | 34 +++++-------- .../thermal/intel/intel_quark_dts_thermal.c | 22 +++------ drivers/thermal/of-thermal.c | 19 ++------ 8 files changed, 71 insertions(+), 153 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 328b479ce7f6..755f12b76c20 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -499,8 +498,14 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; + enum thermal_device_mode mode; - if (!tz->tz_enabled) + /* + * this driver does not provide ->get_mode(), so calling + * thermal_zone_device_get_mode() always succeeds + */ + thermal_zone_device_get_mode(tz->thermal_zone, &mode); + if (mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -526,39 +531,33 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; + enum thermal_device_mode old_mode; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + /* + * this driver does not provide ->get_mode(), so calling + * thermal_zone_device_get_mode() always succeeds + */ + thermal_zone_device_get_mode(thermal, &old_mode); + + if (mode != old_mode) { + thermal_zone_device_store_mode(thermal, mode); ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); acpi_thermal_check(tz); } return 0; @@ -850,7 +849,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, @@ -907,7 +905,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; + thermal_zone_device_store_enabled(tz->thermal_zone); dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index cd435ca7adbe..c4239b2ba16d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -277,16 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -303,7 +291,7 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, mutex_unlock(&tzdev->lock); - thermal->mode = mode; + thermal_zone_device_store_mode(tzdev, mode); thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -409,7 +397,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -468,16 +455,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { @@ -495,7 +472,7 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, mutex_unlock(&tzdev->lock); - tz->mode = mode; + thermal_zone_device_store_mode(tzdev, mode); thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -600,7 +577,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -639,7 +615,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -769,7 +744,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(module_tz->tzdev); return 0; } @@ -885,7 +860,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(gearbox_tz->tzdev); return 0; } @@ -1054,7 +1029,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(thermal->tzdev); *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index d5188c1d688b..e5a6abdf62ca 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -65,8 +65,10 @@ #ifdef START_IN_KERNEL_MODE static int kernelmode = 1; +#define ACERHDF_DEFAULT_MODE THERMAL_DEVICE_ENABLED #else static int kernelmode; +#define ACERHDF_DEFAULT_MODE THERMAL_DEVICE_DISABLED #endif static unsigned int interval = 10; @@ -410,18 +412,6 @@ static inline void acerhdf_enable_kernelmode(void) pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -435,10 +425,13 @@ static int acerhdf_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_ENABLED) return -EINVAL; - if (mode == THERMAL_DEVICE_DISABLED && kernelmode) + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) { acerhdf_revert_to_bios_mode(); - else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) + thermal_zone_device_store_enabled(thermal); + } else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) { acerhdf_enable_kernelmode(); + thermal_zone_device_store_disabled(thermal); + } return 0; } @@ -492,7 +485,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, @@ -757,6 +749,8 @@ static int __init acerhdf_register_thermal(void) return -EINVAL; } + thermal_zone_device_store_mode(thz_dev, ACERHDF_DEFAULT_MODE); + return 0; } diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..279d393bb048 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); @@ -248,6 +237,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) ret = PTR_ERR(thermal->zone); goto err; } + thermal_zone_device_store_enabled(thermal->zone); dev_dbg(&pdev->dev, "TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 36b1924f1938..f3f602b4ece5 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -252,11 +251,17 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) struct imx_thermal_data *data = tz->devdata; const struct thermal_soc_data *soc_data = data->socdata; struct regmap *map = data->tempmon; + enum thermal_device_mode mode; unsigned int n_meas; bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + /* + * this driver does not provide ->get_mode(), so calling + * thermal_zone_device_get_mode() always succeeds + */ + thermal_zone_device_get_mode(tz, &mode); + if (mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +288,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -331,16 +336,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -378,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, return -EINVAL; } - data->mode = mode; + thermal_zone_device_store_mode(tz, mode); thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -469,7 +464,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, @@ -833,7 +827,7 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(data->tz); ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -887,7 +881,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_store_disabled(data->tz); clk_disable_unprepare(data->thermal_clk); return 0; @@ -907,7 +901,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(data->tz); return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index fbb59dd09481..a7d9b42c060d 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; int art_count; struct art *arts; int trt_count; @@ -230,42 +229,33 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct int3400_thermal_priv *priv = thermal->devdata; - - *mode = priv->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; + enum thermal_device_mode old_mode; int result = 0; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + /* + * this driver does not provide ->get_mode(), so calling + * thermal_zone_device_get_mode() always succeeds + */ + thermal_zone_device_get_mode(thermal, &old_mode); + if (mode != old_mode) { + thermal_zone_device_store_mode(thermal, mode); result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index 11d7db895125..6d440ef3055f 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(tzd); return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(tzd); } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_store_disabled(tzd); pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_store_disabled(tzd); return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_store_disabled(tzd); } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_store_enabled(tzd); pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -341,7 +332,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 36bebf623980..0f1e134e90ea 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -269,16 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -298,7 +286,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, mutex_unlock(&tz->lock); - data->mode = mode; + thermal_zone_device_store_mode(tz, mode); thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); return 0; @@ -395,7 +383,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, @@ -556,7 +543,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -981,7 +968,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1136,6 +1122,7 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + thermal_zone_device_store_disabled(zone); } of_node_put(np); -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v2 5/9] thermal: Store mode in thermal_zone_device 2020-04-14 18:01 ` [RFC v2 5/9] thermal: Store mode in thermal_zone_device Andrzej Pietrasiewicz @ 2020-04-15 10:55 ` Daniel Lezcano 2020-04-17 16:20 ` [RFC v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 0 siblings, 1 reply; 137+ messages in thread From: Daniel Lezcano @ 2020-04-15 10:55 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Bartlomiej Zolnierkiewicz On 14/04/2020 20:01, Andrzej Pietrasiewicz wrote: > struct thermal_zone_device has a "mode" member now, so use it. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> At this point, I suggest to not go further with the changes from patch 5-9 but add a new 'mode' field in the struct thermal_zone_params. And then in the function thermal_zone_device_register() { ... if (tzp) thermal_zone_set_mode(tzp->mode); ... } The important thing is to prevent exporting the functions thermal_zone_device_enable / disable, so they stay in the thermal framework internals, thus forcing to centralize the control of the thermal zones from the framework and not from the device drivers. Temporarly, until the polling is disabled for disabled thermal zones, the acpi driver can stay in the state it is. It may need special attention afterwards. But I believe setting the mode from the register function will help to clean up a lot of drivers. > --- > drivers/acpi/thermal.c | 48 +++++++++---------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 35 ++------------ > drivers/platform/x86/acerhdf.c | 24 ++++------ > drivers/thermal/da9062-thermal.c | 12 +---- > drivers/thermal/imx_thermal.c | 30 +++++------- > .../intel/int340x_thermal/int3400_thermal.c | 34 +++++-------- > .../thermal/intel/intel_quark_dts_thermal.c | 22 +++------ > drivers/thermal/of-thermal.c | 19 ++------ > 8 files changed, 71 insertions(+), 153 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 328b479ce7f6..755f12b76c20 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -499,8 +498,14 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) > static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > + enum thermal_device_mode mode; > > - if (!tz->tz_enabled) > + /* > + * this driver does not provide ->get_mode(), so calling > + * thermal_zone_device_get_mode() always succeeds > + */ > + thermal_zone_device_get_mode(tz->thermal_zone, &mode); > + if (mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -526,39 +531,33 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > + enum thermal_device_mode old_mode; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + /* > + * this driver does not provide ->get_mode(), so calling > + * thermal_zone_device_get_mode() always succeeds > + */ > + thermal_zone_device_get_mode(thermal, &old_mode); > + > + if (mode != old_mode) { > + thermal_zone_device_store_mode(thermal, mode); > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > + mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > acpi_thermal_check(tz); > } > return 0; > @@ -850,7 +849,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > @@ -907,7 +905,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > + thermal_zone_device_store_enabled(tz->thermal_zone); > > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index cd435ca7adbe..c4239b2ba16d 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -277,16 +275,6 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -303,7 +291,7 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > > mutex_unlock(&tzdev->lock); > > - thermal->mode = mode; > + thermal_zone_device_store_mode(tzdev, mode); > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -409,7 +397,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -468,16 +455,6 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > @@ -495,7 +472,7 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > > mutex_unlock(&tzdev->lock); > > - tz->mode = mode; > + thermal_zone_device_store_mode(tzdev, mode); > thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -600,7 +577,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -639,7 +615,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -769,7 +744,7 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(module_tz->tzdev); > return 0; > } > > @@ -885,7 +860,7 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(gearbox_tz->tzdev); > return 0; > } > > @@ -1054,7 +1029,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(thermal->tzdev); > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index d5188c1d688b..e5a6abdf62ca 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -65,8 +65,10 @@ > > #ifdef START_IN_KERNEL_MODE > static int kernelmode = 1; > +#define ACERHDF_DEFAULT_MODE THERMAL_DEVICE_ENABLED > #else > static int kernelmode; > +#define ACERHDF_DEFAULT_MODE THERMAL_DEVICE_DISABLED > #endif > > static unsigned int interval = 10; > @@ -410,18 +412,6 @@ static inline void acerhdf_enable_kernelmode(void) > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -435,10 +425,13 @@ static int acerhdf_set_mode(struct thermal_zone_device *thermal, > mode != THERMAL_DEVICE_ENABLED) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_DISABLED && kernelmode) > + if (mode == THERMAL_DEVICE_DISABLED && kernelmode) { > acerhdf_revert_to_bios_mode(); > - else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) > + thermal_zone_device_store_enabled(thermal); > + } else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) { > acerhdf_enable_kernelmode(); > + thermal_zone_device_store_disabled(thermal); > + } > > return 0; > } > @@ -492,7 +485,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > @@ -757,6 +749,8 @@ static int __init acerhdf_register_thermal(void) > return -EINVAL; > } > > + thermal_zone_device_store_mode(thz_dev, ACERHDF_DEFAULT_MODE); > + > return 0; > } > > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..279d393bb048 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > @@ -248,6 +237,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) > ret = PTR_ERR(thermal->zone); > goto err; > } > + thermal_zone_device_store_enabled(thermal->zone); > > dev_dbg(&pdev->dev, > "TJUNC temperature polling period set at %d ms\n", > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index 36b1924f1938..f3f602b4ece5 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -252,11 +251,17 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > struct imx_thermal_data *data = tz->devdata; > const struct thermal_soc_data *soc_data = data->socdata; > struct regmap *map = data->tempmon; > + enum thermal_device_mode mode; > unsigned int n_meas; > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + /* > + * this driver does not provide ->get_mode(), so calling > + * thermal_zone_device_get_mode() always succeeds > + */ > + thermal_zone_device_get_mode(tz, &mode); > + if (mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +288,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -331,16 +336,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -378,7 +373,7 @@ static int imx_set_mode(struct thermal_zone_device *tz, > return -EINVAL; > } > > - data->mode = mode; > + thermal_zone_device_store_mode(tz, mode); > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -469,7 +464,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > @@ -833,7 +827,7 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(data->tz); > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -887,7 +881,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_store_disabled(data->tz); > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -907,7 +901,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(data->tz); > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index fbb59dd09481..a7d9b42c060d 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > int art_count; > struct art *arts; > int trt_count; > @@ -230,42 +229,33 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - *mode = priv->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > + enum thermal_device_mode old_mode; > int result = 0; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (enable != priv->mode) { > - priv->mode = enable; > + /* > + * this driver does not provide ->get_mode(), so calling > + * thermal_zone_device_get_mode() always succeeds > + */ > + thermal_zone_device_get_mode(thermal, &old_mode); > + if (mode != old_mode) { > + thermal_zone_device_store_mode(thermal, mode); > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index 11d7db895125..6d440ef3055f 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(tzd); > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(tzd); > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_store_disabled(tzd); > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_store_disabled(tzd); > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_store_disabled(tzd); > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_store_enabled(tzd); > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -341,7 +332,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 36bebf623980..0f1e134e90ea 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -269,16 +267,6 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -298,7 +286,7 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > > mutex_unlock(&tz->lock); > > - data->mode = mode; > + thermal_zone_device_store_mode(tz, mode); > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > return 0; > @@ -395,7 +383,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > @@ -556,7 +543,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > if (!IS_ERR(tzd)) > - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + thermal_zone_device_enable(tzd); > > of_node_put(child); > goto exit; > @@ -981,7 +968,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1136,6 +1122,7 @@ int __init of_parse_thermal_zones(void) > of_thermal_free_zone(tz); > /* attempting to build remaining zones still */ > } > + thermal_zone_device_store_disabled(zone); > } > of_node_put(np); > > -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v3 0/2] Stop monitoring disabled devices 2020-04-15 10:55 ` Daniel Lezcano @ 2020-04-17 16:20 ` Andrzej Pietrasiewicz 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz ` (2 more replies) 0 siblings, 3 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-17 16:20 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz This is the third iteration of this RFC. It has been substantially rewritten compared to v2. The first patch makes all the drivers store their mode in struct thermal_zone_device. Such a move has consequences: driver-specific variables for storing mode are not necessary. Consequently get_mode() methods become obsolete. Then sysfs "mode" attribute stops depending on get_mode() being provided, because it is always provided from now on. The first patch also introduces the initial mode to be optionally passed to thermal_zone_device_register(). Given all the groundwork done in patch 1/2 patch 2/2 becomes very simple. This series addresses comments from Daniel and Bartlomiej - thank you guys! Andrzej Pietrasiewicz (2): thermal: core: Let thermal zone device's mode be stored in its struct thermal: core: Stop polling DISABLED thermal devices drivers/acpi/thermal.c | 46 +++++--------- .../ethernet/mellanox/mlxsw/core_thermal.c | 57 ++++-------------- drivers/platform/x86/acerhdf.c | 17 +----- drivers/thermal/da9062-thermal.c | 16 ++--- drivers/thermal/imx_thermal.c | 29 +++------ .../intel/int340x_thermal/int3400_thermal.c | 30 ++-------- .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- drivers/thermal/of-thermal.c | 30 +++------- drivers/thermal/thermal_core.c | 60 +++++++++++++++++-- drivers/thermal/thermal_core.h | 16 +++++ drivers/thermal/thermal_sysfs.c | 29 +-------- include/linux/thermal.h | 7 ++- 12 files changed, 139 insertions(+), 220 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-17 16:20 ` [RFC v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-04-17 16:20 ` Andrzej Pietrasiewicz 2020-04-17 20:44 ` Andy Shevchenko ` (2 more replies) 2020-04-17 16:20 ` [RFC v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-19 13:50 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Peter Kästle 2 siblings, 3 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-17 16:20 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Thermal zone devices' mode is stored in individual drivers. This patch changes it so that mode is stored in struct thermal_zone_device instead. As a result all driver-specific variables storing the mode are not needed and are removed. Consequently, the get_mode() implementations have nothing to operate on and need to be removed, too. Some thermal framework specific functions are introduced: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_enable() thermal_zone_device_disable() thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock and the "set" calls driver's set_mode() if provided, so the latter must not take this lock again. At the end of the "set" thermal_zone_device_update() is called so drivers don't need to repeat this invocation in their specific set_mode() implementations. The scope of the above 4 functions is purposedly limited to the thermal framework and drivers are not supposed to call them. This encapsulation does not fully work at the moment for some drivers, though: - platform/x86/acerhdf.c - drivers/thermal/imx_thermal.c - drivers/thermal/intel/intel_quark_dts_thermal.c - drivers/thermal/of-thermal.c and they manipulate struct thermal_zone_device's members directly. struct thermal_zone_params gains a new member called initial_mode, which is used to set tzd's mode at registration time. The sysfs "mode" attribute is always exposed from now on, because all thermal zone devices now have their get_mode() implemented at the generic level and it is always available. Exposing "mode" doesn't hurt the drivers which don't provide their own set_mode(), because writing to "mode" will result in -EPERM, as expected. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 46 +++++---------- .../ethernet/mellanox/mlxsw/core_thermal.c | 57 ++++--------------- drivers/platform/x86/acerhdf.c | 17 +----- drivers/thermal/da9062-thermal.c | 16 ++---- drivers/thermal/imx_thermal.c | 29 +++------- .../intel/int340x_thermal/int3400_thermal.c | 30 ++-------- .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- drivers/thermal/of-thermal.c | 30 +++------- drivers/thermal/thermal_core.c | 44 +++++++++++++- drivers/thermal/thermal_core.h | 16 ++++++ drivers/thermal/thermal_sysfs.c | 29 +--------- include/linux/thermal.h | 7 ++- 12 files changed, 125 insertions(+), 218 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..67bc263332a5 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -526,46 +525,29 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != thermal->mode) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); - acpi_thermal_check(tz); + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); } return 0; } @@ -856,7 +838,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, @@ -870,6 +851,9 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) int trips = 0; int result; acpi_status status; + struct thermal_zone_params prms = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; int i; if (tz->trips.critical.flags.valid) @@ -887,13 +871,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (tz->trips.passive.flags.valid) tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, + &acpi_thermal_zone_ops, &prms, tz->trips.passive.tsp*100, tz->polling_frequency*100); else tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, + &acpi_thermal_zone_ops, &prms, 0, tz->polling_frequency*100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; @@ -913,8 +897,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; - dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..50518048b86d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - thermal->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - tz->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -749,6 +710,9 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { static int mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) { + struct thermal_zone_params tzp = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; int err; @@ -759,13 +723,12 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) MLXSW_THERMAL_TRIP_MASK, module_tz, &mlxsw_thermal_module_ops, - NULL, 0, 0); + &tzp, 0, 0); if (IS_ERR(module_tz->tzdev)) { err = PTR_ERR(module_tz->tzdev); return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -868,6 +831,9 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) static int mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) { + struct thermal_zone_params tzp = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", @@ -877,11 +843,10 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) MLXSW_THERMAL_TRIP_MASK, gearbox_tz, &mlxsw_thermal_gearbox_ops, - NULL, 0, 0); + &tzp, 0, 0); if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -960,6 +925,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core, const struct mlxsw_bus_info *bus_info, struct mlxsw_thermal **p_thermal) { + struct thermal_zone_params tzp = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; enum mlxsw_reg_mfcr_pwm_frequency freq; struct device *dev = bus_info->dev; @@ -1034,7 +1002,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, MLXSW_THERMAL_TRIP_MASK, thermal, &mlxsw_thermal_ops, - NULL, 0, + &tzp, 0, thermal->polling_delay); if (IS_ERR(thermal->tzdev)) { err = PTR_ERR(thermal->tzdev); @@ -1050,7 +1018,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..aaf8b845be90 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode = 1; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, err_out: acerhdf_revert_to_bios_mode(); + thz_dev->mode = THERMAL_DEVICE_DISABLED; return -EINVAL; } @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + acerhdf_zone_params.initial_mode = + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..4bdb6f9621c1 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; @@ -199,6 +189,9 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_reg_id_table); static int da9062_thermal_probe(struct platform_device *pdev) { + struct thermal_zone_params tzp = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; struct da9062 *chip = dev_get_drvdata(pdev->dev.parent); struct da9062_thermal *thermal; unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD; @@ -233,7 +226,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); @@ -241,7 +233,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->zone = thermal_zone_device_register(thermal->config->name, 1, 0, thermal, - &da9062_thermal_ops, NULL, pp_tmp, + &da9062_thermal_ops, &tzp, pp_tmp, 0); if (IS_ERR(thermal->zone)) { dev_err(&pdev->dev, "Cannot register thermal zone device\n"); diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..3e02323c938b 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, @@ -691,6 +676,9 @@ static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data static int imx_thermal_probe(struct platform_device *pdev) { + struct thermal_zone_params tzp = { + .initial_mode = THERMAL_DEVICE_ENABLED, + }; struct imx_thermal_data *data; struct regmap *map; int measure_freq; @@ -799,7 +787,7 @@ static int imx_thermal_probe(struct platform_device *pdev) data->tz = thermal_zone_device_register("imx_thermal_zone", IMX_TRIP_NUM, BIT(IMX_TRIP_PASSIVE), data, - &imx_tz_ops, NULL, + &imx_tz_ops, &tzp, IMX_PASSIVE_DELAY, IMX_POLLING_DELAY); if (IS_ERR(data->tz)) { @@ -831,7 +819,6 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +872,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + data->tz->mode = THERMAL_DEVICE_DISABLED; clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +892,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + data->tz->mode = THERMAL_DEVICE_ENABLED; return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e802922a13cf..86a00598ed09 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; int art_count; struct art *arts; int trt_count; @@ -230,48 +229,29 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else + if (mode != THERMAL_DEVICE_ENABLED && + mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - if (enable != priv->mode) { - priv->mode = enable; + if (mode != thermal->mode) { result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 874a47d6923f..863b89546f81 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, @@ -553,8 +533,14 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, if (id == sensor_id) { tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); - if (!IS_ERR(tzd)) + if (!IS_ERR(tzd)) { + mutex_lock(&tzd->lock); tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + tzd->mode = THERMAL_DEVICE_ENABLED; + mutex_unlock(&tzd->lock); + thermal_zone_device_update(tzd, + THERMAL_EVENT_UNSPECIFIED); + } of_node_put(child); goto exit; @@ -979,7 +965,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1120,6 +1105,7 @@ int __init of_parse_thermal_zones(void) /* these two are left for temperature drivers to use */ tzp->slope = tz->slope; tzp->offset = tz->offset; + tzp->initial_mode = THERMAL_DEVICE_DISABLED; zone = thermal_zone_device_register(child->name, tz->ntrips, mask, tz, diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c06550930979..5ff98fcc0f6a 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -463,6 +463,43 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode; +} + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + + mutex_lock(&tz->lock); + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { @@ -1344,6 +1381,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, if (atomic_cmpxchg(&tz->need_update, 1, 0)) thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + if (tzp) + thermal_zone_device_set_mode(tz, tzp->initial_mode); + return tz; unregister: @@ -1473,9 +1513,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); + tz_mode = thermal_zone_device_get_mode(tz); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index c95689586e19..8e561bac3133 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -141,6 +141,22 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, unsigned long new_state) {} #endif /* CONFIG_THERMAL_STATISTICS */ +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz); + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); + +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + /* device tree support */ #ifdef CONFIG_THERMAL_OF int of_parse_thermal_zones(void); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..cbb27b3c96d2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; + mode = thermal_zone_device_get_mode(tz); return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" : "disabled"); @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..da4141697e2e 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, @@ -128,6 +126,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +169,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -264,6 +264,9 @@ struct thermal_zone_params { int num_tbps; /* Number of tbp entries */ struct thermal_bind_params *tbp; + /* Initial mode of this thermal zone device */ + enum thermal_device_mode initial_mode; + /* * Sustainable power (heat) that this thermal zone can dissipate in * mW -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-17 20:44 ` Andy Shevchenko 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz 2020-05-23 21:24 ` Daniel Lezcano 2 siblings, 0 replies; 137+ messages in thread From: Andy Shevchenko @ 2020-04-17 20:44 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux PM, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, ACPI Devel Maling List, netdev, Platform Driver, linux-arm Mailing List, kernel, Barlomiej Zolnierkiewicz On Fri, Apr 17, 2020 at 7:20 PM Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework specific functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > The scope of the above 4 functions is purposedly limited to the thermal > framework and drivers are not supposed to call them. This encapsulation > does not fully work at the moment for some drivers, though: > > - platform/x86/acerhdf.c Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> for PDx86 bits. > - drivers/thermal/imx_thermal.c > - drivers/thermal/intel/intel_quark_dts_thermal.c > - drivers/thermal/of-thermal.c > > and they manipulate struct thermal_zone_device's members directly. > > struct thermal_zone_params gains a new member called initial_mode, which > is used to set tzd's mode at registration time. > > The sysfs "mode" attribute is always exposed from now on, because all > thermal zone devices now have their get_mode() implemented at the generic > level and it is always available. Exposing "mode" doesn't hurt the drivers > which don't provide their own set_mode(), because writing to "mode" will > result in -EPERM, as expected. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/acpi/thermal.c | 46 +++++---------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 57 ++++--------------- > drivers/platform/x86/acerhdf.c | 17 +----- > drivers/thermal/da9062-thermal.c | 16 ++---- > drivers/thermal/imx_thermal.c | 29 +++------- > .../intel/int340x_thermal/int3400_thermal.c | 30 ++-------- > .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- > drivers/thermal/of-thermal.c | 30 +++------- > drivers/thermal/thermal_core.c | 44 +++++++++++++- > drivers/thermal/thermal_core.h | 16 ++++++ > drivers/thermal/thermal_sysfs.c | 29 +--------- > include/linux/thermal.h | 7 ++- > 12 files changed, 125 insertions(+), 218 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..67bc263332a5 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -526,46 +525,29 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > + > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != thermal->mode) { > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > - acpi_thermal_check(tz); > + mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > } > return 0; > } > @@ -856,7 +838,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > @@ -870,6 +851,9 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > int trips = 0; > int result; > acpi_status status; > + struct thermal_zone_params prms = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > int i; > > if (tz->trips.critical.flags.valid) > @@ -887,13 +871,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (tz->trips.passive.flags.valid) > tz->thermal_zone = > thermal_zone_device_register("acpitz", trips, 0, tz, > - &acpi_thermal_zone_ops, NULL, > + &acpi_thermal_zone_ops, &prms, > tz->trips.passive.tsp*100, > tz->polling_frequency*100); > else > tz->thermal_zone = > thermal_zone_device_register("acpitz", trips, 0, tz, > - &acpi_thermal_zone_ops, NULL, > + &acpi_thermal_zone_ops, &prms, > 0, tz->polling_frequency*100); > if (IS_ERR(tz->thermal_zone)) > return -ENODEV; > @@ -913,8 +897,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > - > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > return 0; > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..50518048b86d 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal *thermal = tzdev->devdata; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - thermal->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal_module *tz = tzdev->devdata; > struct mlxsw_thermal *thermal = tz->parent; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - tz->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -749,6 +710,9 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { > static int > mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; > int err; > > @@ -759,13 +723,12 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > MLXSW_THERMAL_TRIP_MASK, > module_tz, > &mlxsw_thermal_module_ops, > - NULL, 0, 0); > + &tzp, 0, 0); > if (IS_ERR(module_tz->tzdev)) { > err = PTR_ERR(module_tz->tzdev); > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -868,6 +831,9 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) > static int > mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; > > snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", > @@ -877,11 +843,10 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > MLXSW_THERMAL_TRIP_MASK, > gearbox_tz, > &mlxsw_thermal_gearbox_ops, > - NULL, 0, 0); > + &tzp, 0, 0); > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -960,6 +925,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > const struct mlxsw_bus_info *bus_info, > struct mlxsw_thermal **p_thermal) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; > enum mlxsw_reg_mfcr_pwm_frequency freq; > struct device *dev = bus_info->dev; > @@ -1034,7 +1002,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > MLXSW_THERMAL_TRIP_MASK, > thermal, > &mlxsw_thermal_ops, > - NULL, 0, > + &tzp, 0, > thermal->polling_delay); > if (IS_ERR(thermal->tzdev)) { > err = PTR_ERR(thermal->tzdev); > @@ -1050,7 +1018,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..aaf8b845be90 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) > kernelmode = 1; > > thz_dev->polling_delay = interval*1000; > - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, > > err_out: > acerhdf_revert_to_bios_mode(); > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > return -EINVAL; > } > > @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + acerhdf_zone_params.initial_mode = > + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..4bdb6f9621c1 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > @@ -199,6 +189,9 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_reg_id_table); > > static int da9062_thermal_probe(struct platform_device *pdev) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > struct da9062 *chip = dev_get_drvdata(pdev->dev.parent); > struct da9062_thermal *thermal; > unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD; > @@ -233,7 +226,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > @@ -241,7 +233,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->zone = thermal_zone_device_register(thermal->config->name, > 1, 0, thermal, > - &da9062_thermal_ops, NULL, pp_tmp, > + &da9062_thermal_ops, &tzp, pp_tmp, > 0); > if (IS_ERR(thermal->zone)) { > dev_err(&pdev->dev, "Cannot register thermal zone device\n"); > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..3e02323c938b 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > @@ -691,6 +676,9 @@ static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data > > static int imx_thermal_probe(struct platform_device *pdev) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > struct imx_thermal_data *data; > struct regmap *map; > int measure_freq; > @@ -799,7 +787,7 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->tz = thermal_zone_device_register("imx_thermal_zone", > IMX_TRIP_NUM, > BIT(IMX_TRIP_PASSIVE), data, > - &imx_tz_ops, NULL, > + &imx_tz_ops, &tzp, > IMX_PASSIVE_DELAY, > IMX_POLLING_DELAY); > if (IS_ERR(data->tz)) { > @@ -831,7 +819,6 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -885,7 +872,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + data->tz->mode = THERMAL_DEVICE_DISABLED; > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -905,7 +892,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e802922a13cf..86a00598ed09 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > int art_count; > struct art *arts; > int trt_count; > @@ -230,48 +229,29 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; > > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != thermal->mode) { > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..c4879b4bfbf1 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 874a47d6923f..863b89546f81 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > struct __thermal_zone *data = tz->devdata; > > - mutex_lock(&tz->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > tz->passive_delay = 0; > } > > - mutex_unlock(&tz->lock); > - > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > @@ -553,8 +533,14 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > if (id == sensor_id) { > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > - if (!IS_ERR(tzd)) > + if (!IS_ERR(tzd)) { > + mutex_lock(&tzd->lock); > tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + tzd->mode = THERMAL_DEVICE_ENABLED; > + mutex_unlock(&tzd->lock); > + thermal_zone_device_update(tzd, > + THERMAL_EVENT_UNSPECIFIED); > + } > > of_node_put(child); > goto exit; > @@ -979,7 +965,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1120,6 +1105,7 @@ int __init of_parse_thermal_zones(void) > /* these two are left for temperature drivers to use */ > tzp->slope = tz->slope; > tzp->offset = tz->offset; > + tzp->initial_mode = THERMAL_DEVICE_DISABLED; > > zone = thermal_zone_device_register(child->name, tz->ntrips, > mask, tz, > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index c06550930979..5ff98fcc0f6a 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -463,6 +463,43 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode; > +} > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + int ret = 0; > + > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; > + > + mutex_lock(&tz->lock); > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + tz->mode = mode; > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > @@ -1344,6 +1381,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, > if (atomic_cmpxchg(&tz->need_update, 1, 0)) > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > + if (tzp) > + thermal_zone_device_set_mode(tz, tzp->initial_mode); > + > return tz; > > unregister: > @@ -1473,9 +1513,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > + tz_mode = thermal_zone_device_get_mode(tz); > > if (tz_mode == THERMAL_DEVICE_DISABLED) > continue; > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index c95689586e19..8e561bac3133 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -141,6 +141,22 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, > unsigned long new_state) {} > #endif /* CONFIG_THERMAL_STATISTICS */ > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz); > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > + > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > /* device tree support */ > #ifdef CONFIG_THERMAL_OF > int of_parse_thermal_zones(void); > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..cbb27b3c96d2 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > + mode = thermal_zone_device_get_mode(tz); > > return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > : "disabled"); > @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..da4141697e2e 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > @@ -128,6 +126,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +169,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -264,6 +264,9 @@ struct thermal_zone_params { > int num_tbps; /* Number of tbp entries */ > struct thermal_bind_params *tbp; > > + /* Initial mode of this thermal zone device */ > + enum thermal_device_mode initial_mode; > + > /* > * Sustainable power (heat) that this thermal zone can dissipate in > * mW > -- > 2.17.1 > -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-17 20:44 ` Andy Shevchenko @ 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz 2020-04-19 13:10 ` Bartlomiej Zolnierkiewicz 2020-04-20 11:03 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-05-23 21:24 ` Daniel Lezcano 2 siblings, 2 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-19 11:38 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Andrzej, On 4/17/20 6:20 PM, Andrzej Pietrasiewicz wrote: > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework specific functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > The scope of the above 4 functions is purposedly limited to the thermal > framework and drivers are not supposed to call them. This encapsulation This should be true only for thermal_zone_device_{get,set}_mode(). thermal_zone_device_{en,dis}able() should be available for device drivers: * of/thermal device drivers need to enable thermal device itself (please refer to my patchset for details) * device drivers need to call them on ->suspend and ->resume operations > does not fully work at the moment for some drivers, though: > > - platform/x86/acerhdf.c > - drivers/thermal/imx_thermal.c > - drivers/thermal/intel/intel_quark_dts_thermal.c > - drivers/thermal/of-thermal.c > > and they manipulate struct thermal_zone_device's members directly. > > struct thermal_zone_params gains a new member called initial_mode, which > is used to set tzd's mode at registration time. > > The sysfs "mode" attribute is always exposed from now on, because all > thermal zone devices now have their get_mode() implemented at the generic > level and it is always available. Exposing "mode" doesn't hurt the drivers > which don't provide their own set_mode(), because writing to "mode" will > result in -EPERM, as expected. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/acpi/thermal.c | 46 +++++---------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 57 ++++--------------- > drivers/platform/x86/acerhdf.c | 17 +----- > drivers/thermal/da9062-thermal.c | 16 ++---- > drivers/thermal/imx_thermal.c | 29 +++------- > .../intel/int340x_thermal/int3400_thermal.c | 30 ++-------- > .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- > drivers/thermal/of-thermal.c | 30 +++------- > drivers/thermal/thermal_core.c | 44 +++++++++++++- > drivers/thermal/thermal_core.h | 16 ++++++ > drivers/thermal/thermal_sysfs.c | 29 +--------- > include/linux/thermal.h | 7 ++- > 12 files changed, 125 insertions(+), 218 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..67bc263332a5 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -526,46 +525,29 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; These checks should be removed as they are already done in the caller of ->set_mode method (thermal_zone_device_set_mode()). > + > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != thermal->mode) { > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > - acpi_thermal_check(tz); > + mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > } > return 0; > } > @@ -856,7 +838,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > @@ -870,6 +851,9 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > int trips = 0; > int result; > acpi_status status; > + struct thermal_zone_params prms = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > int i; > > if (tz->trips.critical.flags.valid) > @@ -887,13 +871,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (tz->trips.passive.flags.valid) > tz->thermal_zone = > thermal_zone_device_register("acpitz", trips, 0, tz, > - &acpi_thermal_zone_ops, NULL, > + &acpi_thermal_zone_ops, &prms, > tz->trips.passive.tsp*100, > tz->polling_frequency*100); > else > tz->thermal_zone = > thermal_zone_device_register("acpitz", trips, 0, tz, > - &acpi_thermal_zone_ops, NULL, > + &acpi_thermal_zone_ops, &prms, > 0, tz->polling_frequency*100); > if (IS_ERR(tz->thermal_zone)) > return -ENODEV; > @@ -913,8 +897,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > - > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > return 0; > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..50518048b86d 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal *thermal = tzdev->devdata; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - thermal->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal_module *tz = tzdev->devdata; > struct mlxsw_thermal *thermal = tz->parent; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - tz->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -749,6 +710,9 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { > static int > mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; > int err; > > @@ -759,13 +723,12 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > MLXSW_THERMAL_TRIP_MASK, > module_tz, > &mlxsw_thermal_module_ops, > - NULL, 0, 0); > + &tzp, 0, 0); > if (IS_ERR(module_tz->tzdev)) { > err = PTR_ERR(module_tz->tzdev); > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -868,6 +831,9 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) > static int > mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; > > snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", > @@ -877,11 +843,10 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > MLXSW_THERMAL_TRIP_MASK, > gearbox_tz, > &mlxsw_thermal_gearbox_ops, > - NULL, 0, 0); > + &tzp, 0, 0); > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -960,6 +925,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > const struct mlxsw_bus_info *bus_info, > struct mlxsw_thermal **p_thermal) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; > enum mlxsw_reg_mfcr_pwm_frequency freq; > struct device *dev = bus_info->dev; > @@ -1034,7 +1002,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > MLXSW_THERMAL_TRIP_MASK, > thermal, > &mlxsw_thermal_ops, > - NULL, 0, > + &tzp, 0, > thermal->polling_delay); > if (IS_ERR(thermal->tzdev)) { > err = PTR_ERR(thermal->tzdev); > @@ -1050,7 +1018,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..aaf8b845be90 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) > kernelmode = 1; > > thz_dev->polling_delay = interval*1000; > - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, > > err_out: > acerhdf_revert_to_bios_mode(); > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > return -EINVAL; > } > > @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + acerhdf_zone_params.initial_mode = > + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..4bdb6f9621c1 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > @@ -199,6 +189,9 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_reg_id_table); > > static int da9062_thermal_probe(struct platform_device *pdev) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > struct da9062 *chip = dev_get_drvdata(pdev->dev.parent); > struct da9062_thermal *thermal; > unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD; > @@ -233,7 +226,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > @@ -241,7 +233,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->zone = thermal_zone_device_register(thermal->config->name, > 1, 0, thermal, > - &da9062_thermal_ops, NULL, pp_tmp, > + &da9062_thermal_ops, &tzp, pp_tmp, > 0); > if (IS_ERR(thermal->zone)) { > dev_err(&pdev->dev, "Cannot register thermal zone device\n"); > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..3e02323c938b 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > @@ -691,6 +676,9 @@ static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data > > static int imx_thermal_probe(struct platform_device *pdev) > { > + struct thermal_zone_params tzp = { > + .initial_mode = THERMAL_DEVICE_ENABLED, > + }; > struct imx_thermal_data *data; > struct regmap *map; > int measure_freq; > @@ -799,7 +787,7 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->tz = thermal_zone_device_register("imx_thermal_zone", > IMX_TRIP_NUM, > BIT(IMX_TRIP_PASSIVE), data, > - &imx_tz_ops, NULL, > + &imx_tz_ops, &tzp, > IMX_PASSIVE_DELAY, > IMX_POLLING_DELAY); > if (IS_ERR(data->tz)) { > @@ -831,7 +819,6 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -885,7 +872,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + data->tz->mode = THERMAL_DEVICE_DISABLED; > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -905,7 +892,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + data->tz->mode = THERMAL_DEVICE_ENABLED; > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e802922a13cf..86a00598ed09 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > int art_count; > struct art *arts; > int trt_count; > @@ -230,48 +229,29 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > + if (mode != THERMAL_DEVICE_ENABLED && > + mode != THERMAL_DEVICE_DISABLED) > return -EINVAL; These checks should be removed as they are already done in the caller of ->set_mode method (thermal_zone_device_set_mode()). > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != thermal->mode) { > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..c4879b4bfbf1 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 874a47d6923f..863b89546f81 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > struct __thermal_zone *data = tz->devdata; > > - mutex_lock(&tz->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > tz->passive_delay = 0; > } > > - mutex_unlock(&tz->lock); > - > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > @@ -553,8 +533,14 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > if (id == sensor_id) { > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > - if (!IS_ERR(tzd)) > + if (!IS_ERR(tzd)) { > + mutex_lock(&tzd->lock); > tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + tzd->mode = THERMAL_DEVICE_ENABLED; > + mutex_unlock(&tzd->lock); > + thermal_zone_device_update(tzd, > + THERMAL_EVENT_UNSPECIFIED); > + } This should use thermal_zone_device_enable() instead of open-coding it: if (!IS_ERR(tzd)) thermal_zone_device_enable(tzd); Also because of of_thermal_set_mode() modifications following of/thermal device drivers (which use ->set_mode directly): drivers/thermal/hisi_thermal.c: tzd->ops->set_mode(tzd, drivers/thermal/rockchip_thermal.c: tzd->ops->set_mode(tzd, drivers/thermal/sprd_thermal.c: tzd->ops->set_mode(tzd, need to be converted to use thermal_zone_device_{en,dis}able() instead. > of_node_put(child); > goto exit; > @@ -979,7 +965,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1120,6 +1105,7 @@ int __init of_parse_thermal_zones(void) > /* these two are left for temperature drivers to use */ > tzp->slope = tz->slope; > tzp->offset = tz->offset; > + tzp->initial_mode = THERMAL_DEVICE_DISABLED; > > zone = thermal_zone_device_register(child->name, tz->ntrips, > mask, tz, > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index c06550930979..5ff98fcc0f6a 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -463,6 +463,43 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode; > +} > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + int ret = 0; > + > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; No need for these checks as enum thermal_device_mode has only two possible values (we don't do "defensive coding" in the kernel). > + mutex_lock(&tz->lock); > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + tz->mode = mode; > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} Please add: EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); here so device drivers can use thermal_zone_device_{en,dis}able(). > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > @@ -1344,6 +1381,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, > if (atomic_cmpxchg(&tz->need_update, 1, 0)) > thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > > + if (tzp) > + thermal_zone_device_set_mode(tz, tzp->initial_mode); Please note that currently some device drivers don't access ->mode at all so their default ->mode value is THERMAL_DEVICE_DISABLED but in reality they are enabled (IOW after changes in this patch they should default to THERMAL_DEVICE_ENABLED to reflect real device state in "mode" sysfs attribue and not break after applying patch #2). Therefore we should always call thermal_zone_device_set_mode() and use the default value of THERMAL_DEVICE_ENABLED if tzp is NULL: mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; thermal_zone_device_set_mode(tz, mode); This would also simplify the patch further: * setting tz->need_update and calling thermal_zone_device_update() directly can be removed from thermal_zone_device_register() * tzp-s with only .initial_mode = THERMAL_DEVICE_ENABLED set can be removed from: drivers/thermal/acpi.c drivers/net/ethernet/mellanox/mlxsw/core_thermal.c drivers/thermal/da9062-thermal.c drivers/thermal/imx_thermal.c The rest of the patch looks fine, thank you for working on this! Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > + > return tz; > > unregister: > @@ -1473,9 +1513,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > + tz_mode = thermal_zone_device_get_mode(tz); > > if (tz_mode == THERMAL_DEVICE_DISABLED) > continue; > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index c95689586e19..8e561bac3133 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -141,6 +141,22 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, > unsigned long new_state) {} > #endif /* CONFIG_THERMAL_STATISTICS */ > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz); > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > + > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > /* device tree support */ > #ifdef CONFIG_THERMAL_OF > int of_parse_thermal_zones(void); > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..cbb27b3c96d2 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > + mode = thermal_zone_device_get_mode(tz); > > return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > : "disabled"); > @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..da4141697e2e 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > @@ -128,6 +126,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +169,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -264,6 +264,9 @@ struct thermal_zone_params { > int num_tbps; /* Number of tbp entries */ > struct thermal_bind_params *tbp; > > + /* Initial mode of this thermal zone device */ > + enum thermal_device_mode initial_mode; > + > /* > * Sustainable power (heat) that this thermal zone can dissipate in > * mW > ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz @ 2020-04-19 13:10 ` Bartlomiej Zolnierkiewicz 2020-04-20 18:17 ` [PATCH 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-20 11:03 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-19 13:10 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/19/20 1:38 PM, Bartlomiej Zolnierkiewicz wrote: > > Hi Andrzej, > > On 4/17/20 6:20 PM, Andrzej Pietrasiewicz wrote: >> Thermal zone devices' mode is stored in individual drivers. This patch >> changes it so that mode is stored in struct thermal_zone_device instead. >> >> As a result all driver-specific variables storing the mode are not needed >> and are removed. Consequently, the get_mode() implementations have nothing >> to operate on and need to be removed, too. >> >> Some thermal framework specific functions are introduced: >> >> thermal_zone_device_get_mode() >> thermal_zone_device_set_mode() >> thermal_zone_device_enable() >> thermal_zone_device_disable() >> >> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >> and the "set" calls driver's set_mode() if provided, so the latter must >> not take this lock again. At the end of the "set" >> thermal_zone_device_update() is called so drivers don't need to repeat this >> invocation in their specific set_mode() implementations. >> >> The scope of the above 4 functions is purposedly limited to the thermal >> framework and drivers are not supposed to call them. This encapsulation > > This should be true only for thermal_zone_device_{get,set}_mode(). > > thermal_zone_device_{en,dis}able() should be available for device drivers: > > * of/thermal device drivers need to enable thermal device itself > (please refer to my patchset for details) > > * device drivers need to call them on ->suspend and ->resume operations > >> does not fully work at the moment for some drivers, though: >> >> - platform/x86/acerhdf.c >> - drivers/thermal/imx_thermal.c >> - drivers/thermal/intel/intel_quark_dts_thermal.c >> - drivers/thermal/of-thermal.c >> >> and they manipulate struct thermal_zone_device's members directly. >> >> struct thermal_zone_params gains a new member called initial_mode, which >> is used to set tzd's mode at registration time. >> >> The sysfs "mode" attribute is always exposed from now on, because all >> thermal zone devices now have their get_mode() implemented at the generic >> level and it is always available. Exposing "mode" doesn't hurt the drivers >> which don't provide their own set_mode(), because writing to "mode" will >> result in -EPERM, as expected. >> >> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> >> --- >> drivers/acpi/thermal.c | 46 +++++---------- >> .../ethernet/mellanox/mlxsw/core_thermal.c | 57 ++++--------------- >> drivers/platform/x86/acerhdf.c | 17 +----- >> drivers/thermal/da9062-thermal.c | 16 ++---- >> drivers/thermal/imx_thermal.c | 29 +++------- >> .../intel/int340x_thermal/int3400_thermal.c | 30 ++-------- >> .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- >> drivers/thermal/of-thermal.c | 30 +++------- >> drivers/thermal/thermal_core.c | 44 +++++++++++++- >> drivers/thermal/thermal_core.h | 16 ++++++ >> drivers/thermal/thermal_sysfs.c | 29 +--------- >> include/linux/thermal.h | 7 ++- >> 12 files changed, 125 insertions(+), 218 deletions(-) >> >> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c >> index 19067a5e5293..67bc263332a5 100644 >> --- a/drivers/acpi/thermal.c >> +++ b/drivers/acpi/thermal.c >> @@ -172,7 +172,6 @@ struct acpi_thermal { >> struct acpi_thermal_trips trips; >> struct acpi_handle_list devices; >> struct thermal_zone_device *thermal_zone; >> - int tz_enabled; >> int kelvin_offset; /* in millidegrees */ >> struct work_struct thermal_check_work; >> }; >> @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) >> { >> struct acpi_thermal *tz = data; >> >> - if (!tz->tz_enabled) >> + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) >> return; >> >> thermal_zone_device_update(tz->thermal_zone, >> @@ -526,46 +525,29 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) >> return 0; >> } >> >> -static int thermal_get_mode(struct thermal_zone_device *thermal, >> - enum thermal_device_mode *mode) >> -{ >> - struct acpi_thermal *tz = thermal->devdata; >> - >> - if (!tz) >> - return -EINVAL; >> - >> - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : >> - THERMAL_DEVICE_DISABLED; >> - >> - return 0; >> -} >> - >> static int thermal_set_mode(struct thermal_zone_device *thermal, >> enum thermal_device_mode mode) >> { >> struct acpi_thermal *tz = thermal->devdata; >> - int enable; >> >> if (!tz) >> return -EINVAL; >> >> + if (mode != THERMAL_DEVICE_DISABLED && >> + mode != THERMAL_DEVICE_ENABLED) >> + return -EINVAL; > > These checks should be removed as they are already done in the caller > of ->set_mode method (thermal_zone_device_set_mode()). > >> + >> /* >> * enable/disable thermal management from ACPI thermal driver >> */ >> - if (mode == THERMAL_DEVICE_ENABLED) >> - enable = 1; >> - else if (mode == THERMAL_DEVICE_DISABLED) { >> - enable = 0; >> + if (mode == THERMAL_DEVICE_DISABLED) >> pr_warn("thermal zone will be disabled\n"); >> - } else >> - return -EINVAL; >> >> - if (enable != tz->tz_enabled) { >> - tz->tz_enabled = enable; >> + if (mode != thermal->mode) { >> ACPI_DEBUG_PRINT((ACPI_DB_INFO, >> "%s kernel ACPI thermal control\n", >> - tz->tz_enabled ? "Enable" : "Disable")); >> - acpi_thermal_check(tz); >> + mode == THERMAL_DEVICE_ENABLED ? >> + "Enable" : "Disable")); >> } >> return 0; >> } >> @@ -856,7 +838,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { >> .bind = acpi_thermal_bind_cooling_device, >> .unbind = acpi_thermal_unbind_cooling_device, >> .get_temp = thermal_get_temp, >> - .get_mode = thermal_get_mode, >> .set_mode = thermal_set_mode, >> .get_trip_type = thermal_get_trip_type, >> .get_trip_temp = thermal_get_trip_temp, >> @@ -870,6 +851,9 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) >> int trips = 0; >> int result; >> acpi_status status; >> + struct thermal_zone_params prms = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> int i; >> >> if (tz->trips.critical.flags.valid) >> @@ -887,13 +871,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) >> if (tz->trips.passive.flags.valid) >> tz->thermal_zone = >> thermal_zone_device_register("acpitz", trips, 0, tz, >> - &acpi_thermal_zone_ops, NULL, >> + &acpi_thermal_zone_ops, &prms, >> tz->trips.passive.tsp*100, >> tz->polling_frequency*100); >> else >> tz->thermal_zone = >> thermal_zone_device_register("acpitz", trips, 0, tz, >> - &acpi_thermal_zone_ops, NULL, >> + &acpi_thermal_zone_ops, &prms, >> 0, tz->polling_frequency*100); >> if (IS_ERR(tz->thermal_zone)) >> return -ENODEV; >> @@ -913,8 +897,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) >> if (ACPI_FAILURE(status)) >> return -ENODEV; >> >> - tz->tz_enabled = 1; >> - >> dev_info(&tz->device->dev, "registered as thermal_zone%d\n", >> tz->thermal_zone->id); >> return 0; >> diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c >> index ce0a6837daa3..50518048b86d 100644 >> --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c >> +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c >> @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { >> struct mlxsw_thermal *parent; >> struct thermal_zone_device *tzdev; >> struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; >> - enum thermal_device_mode mode; >> int module; /* Module or gearbox number */ >> }; >> >> @@ -110,7 +109,6 @@ struct mlxsw_thermal { >> struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; >> u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; >> struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; >> - enum thermal_device_mode mode; >> struct mlxsw_thermal_module *tz_module_arr; >> u8 tz_module_num; >> struct mlxsw_thermal_module *tz_gearbox_arr; >> @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, >> return 0; >> } >> >> -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, >> - enum thermal_device_mode *mode) >> -{ >> - struct mlxsw_thermal *thermal = tzdev->devdata; >> - >> - *mode = thermal->mode; >> - >> - return 0; >> -} >> - >> static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, >> enum thermal_device_mode mode) >> { >> struct mlxsw_thermal *thermal = tzdev->devdata; >> >> - mutex_lock(&tzdev->lock); >> - >> if (mode == THERMAL_DEVICE_ENABLED) >> tzdev->polling_delay = thermal->polling_delay; >> else >> tzdev->polling_delay = 0; >> >> - mutex_unlock(&tzdev->lock); >> - >> - thermal->mode = mode; >> - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); >> - >> return 0; >> } >> >> @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, >> static struct thermal_zone_device_ops mlxsw_thermal_ops = { >> .bind = mlxsw_thermal_bind, >> .unbind = mlxsw_thermal_unbind, >> - .get_mode = mlxsw_thermal_get_mode, >> .set_mode = mlxsw_thermal_set_mode, >> .get_temp = mlxsw_thermal_get_temp, >> .get_trip_type = mlxsw_thermal_get_trip_type, >> @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, >> return err; >> } >> >> -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, >> - enum thermal_device_mode *mode) >> -{ >> - struct mlxsw_thermal_module *tz = tzdev->devdata; >> - >> - *mode = tz->mode; >> - >> - return 0; >> -} >> - >> static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, >> enum thermal_device_mode mode) >> { >> struct mlxsw_thermal_module *tz = tzdev->devdata; >> struct mlxsw_thermal *thermal = tz->parent; >> >> - mutex_lock(&tzdev->lock); >> - >> if (mode == THERMAL_DEVICE_ENABLED) >> tzdev->polling_delay = thermal->polling_delay; >> else >> tzdev->polling_delay = 0; >> >> - mutex_unlock(&tzdev->lock); >> - >> - tz->mode = mode; >> - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); >> - >> return 0; >> } >> >> @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, >> static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { >> .bind = mlxsw_thermal_module_bind, >> .unbind = mlxsw_thermal_module_unbind, >> - .get_mode = mlxsw_thermal_module_mode_get, >> .set_mode = mlxsw_thermal_module_mode_set, >> .get_temp = mlxsw_thermal_module_temp_get, >> .get_trip_type = mlxsw_thermal_module_trip_type_get, >> @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, >> static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { >> .bind = mlxsw_thermal_module_bind, >> .unbind = mlxsw_thermal_module_unbind, >> - .get_mode = mlxsw_thermal_module_mode_get, >> .set_mode = mlxsw_thermal_module_mode_set, >> .get_temp = mlxsw_thermal_gearbox_temp_get, >> .get_trip_type = mlxsw_thermal_module_trip_type_get, >> @@ -749,6 +710,9 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { >> static int >> mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) >> { >> + struct thermal_zone_params tzp = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; >> int err; >> >> @@ -759,13 +723,12 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) >> MLXSW_THERMAL_TRIP_MASK, >> module_tz, >> &mlxsw_thermal_module_ops, >> - NULL, 0, 0); >> + &tzp, 0, 0); >> if (IS_ERR(module_tz->tzdev)) { >> err = PTR_ERR(module_tz->tzdev); >> return err; >> } >> >> - module_tz->mode = THERMAL_DEVICE_ENABLED; >> return 0; >> } >> >> @@ -868,6 +831,9 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) >> static int >> mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) >> { >> + struct thermal_zone_params tzp = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; >> >> snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", >> @@ -877,11 +843,10 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) >> MLXSW_THERMAL_TRIP_MASK, >> gearbox_tz, >> &mlxsw_thermal_gearbox_ops, >> - NULL, 0, 0); >> + &tzp, 0, 0); >> if (IS_ERR(gearbox_tz->tzdev)) >> return PTR_ERR(gearbox_tz->tzdev); >> >> - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; >> return 0; >> } >> >> @@ -960,6 +925,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core, >> const struct mlxsw_bus_info *bus_info, >> struct mlxsw_thermal **p_thermal) >> { >> + struct thermal_zone_params tzp = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; >> enum mlxsw_reg_mfcr_pwm_frequency freq; >> struct device *dev = bus_info->dev; >> @@ -1034,7 +1002,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, >> MLXSW_THERMAL_TRIP_MASK, >> thermal, >> &mlxsw_thermal_ops, >> - NULL, 0, >> + &tzp, 0, >> thermal->polling_delay); >> if (IS_ERR(thermal->tzdev)) { >> err = PTR_ERR(thermal->tzdev); >> @@ -1050,7 +1018,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, >> if (err) >> goto err_unreg_modules_tzdev; >> >> - thermal->mode = THERMAL_DEVICE_ENABLED; >> *p_thermal = thermal; >> return 0; >> >> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c >> index 8cc86f4e3ac1..aaf8b845be90 100644 >> --- a/drivers/platform/x86/acerhdf.c >> +++ b/drivers/platform/x86/acerhdf.c >> @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) >> kernelmode = 1; >> >> thz_dev->polling_delay = interval*1000; >> - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); >> pr_notice("kernel mode fan control ON\n"); >> } >> >> -static int acerhdf_get_mode(struct thermal_zone_device *thermal, >> - enum thermal_device_mode *mode) >> -{ >> - if (verbose) >> - pr_notice("kernel mode fan control %d\n", kernelmode); >> - >> - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED >> - : THERMAL_DEVICE_DISABLED; >> - >> - return 0; >> -} >> - >> /* >> * set operation mode; >> * enabled: the thermal layer of the kernel takes care about >> @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { >> .bind = acerhdf_bind, >> .unbind = acerhdf_unbind, >> .get_temp = acerhdf_get_ec_temp, >> - .get_mode = acerhdf_get_mode, >> .set_mode = acerhdf_set_mode, >> .get_trip_type = acerhdf_get_trip_type, >> .get_trip_hyst = acerhdf_get_trip_hyst, >> @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, >> >> err_out: >> acerhdf_revert_to_bios_mode(); >> + thz_dev->mode = THERMAL_DEVICE_DISABLED; >> return -EINVAL; >> } >> >> @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) >> if (IS_ERR(cl_dev)) >> return -EINVAL; >> >> + acerhdf_zone_params.initial_mode = >> + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; >> thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, >> &acerhdf_dev_ops, >> &acerhdf_zone_params, 0, >> diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c >> index c32709badeda..4bdb6f9621c1 100644 >> --- a/drivers/thermal/da9062-thermal.c >> +++ b/drivers/thermal/da9062-thermal.c >> @@ -49,7 +49,6 @@ struct da9062_thermal { >> struct da9062 *hw; >> struct delayed_work work; >> struct thermal_zone_device *zone; >> - enum thermal_device_mode mode; >> struct mutex lock; /* protection for da9062_thermal temperature */ >> int temperature; >> int irq; >> @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) >> return IRQ_HANDLED; >> } >> >> -static int da9062_thermal_get_mode(struct thermal_zone_device *z, >> - enum thermal_device_mode *mode) >> -{ >> - struct da9062_thermal *thermal = z->devdata; >> - *mode = thermal->mode; >> - return 0; >> -} >> - >> static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, >> int trip, >> enum thermal_trip_type *type) >> @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, >> .get_trip_type = da9062_thermal_get_trip_type, >> .get_trip_temp = da9062_thermal_get_trip_temp, >> }; >> @@ -199,6 +189,9 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_reg_id_table); >> >> static int da9062_thermal_probe(struct platform_device *pdev) >> { >> + struct thermal_zone_params tzp = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> struct da9062 *chip = dev_get_drvdata(pdev->dev.parent); >> struct da9062_thermal *thermal; >> unsigned int pp_tmp = DA9062_DEFAULT_POLLING_MS_PERIOD; >> @@ -233,7 +226,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) >> >> thermal->config = match->data; >> thermal->hw = chip; >> - thermal->mode = THERMAL_DEVICE_ENABLED; >> thermal->dev = &pdev->dev; >> >> INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); >> @@ -241,7 +233,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) >> >> thermal->zone = thermal_zone_device_register(thermal->config->name, >> 1, 0, thermal, >> - &da9062_thermal_ops, NULL, pp_tmp, >> + &da9062_thermal_ops, &tzp, pp_tmp, >> 0); >> if (IS_ERR(thermal->zone)) { >> dev_err(&pdev->dev, "Cannot register thermal zone device\n"); >> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c >> index e761c9b42217..3e02323c938b 100644 >> --- a/drivers/thermal/imx_thermal.c >> +++ b/drivers/thermal/imx_thermal.c >> @@ -197,7 +197,6 @@ struct imx_thermal_data { >> struct cpufreq_policy *policy; >> struct thermal_zone_device *tz; >> struct thermal_cooling_device *cdev; >> - enum thermal_device_mode mode; >> struct regmap *tempmon; >> u32 c1, c2; /* See formula in imx_init_calib() */ >> int temp_passive; >> @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) >> bool wait; >> u32 val; >> >> - if (data->mode == THERMAL_DEVICE_ENABLED) { >> + if (tz->mode == THERMAL_DEVICE_ENABLED) { >> /* Check if a measurement is currently in progress */ >> regmap_read(map, soc_data->temp_data, &val); >> wait = !(val & soc_data->temp_valid_mask); >> @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) >> >> regmap_read(map, soc_data->temp_data, &val); >> >> - if (data->mode != THERMAL_DEVICE_ENABLED) { >> + if (tz->mode != THERMAL_DEVICE_ENABLED) { >> regmap_write(map, soc_data->sensor_ctrl + REG_CLR, >> soc_data->measure_temp_mask); >> regmap_write(map, soc_data->sensor_ctrl + REG_SET, >> @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) >> return 0; >> } >> >> -static int imx_get_mode(struct thermal_zone_device *tz, >> - enum thermal_device_mode *mode) >> -{ >> - struct imx_thermal_data *data = tz->devdata; >> - >> - *mode = data->mode; >> - >> - return 0; >> -} >> - >> static int imx_set_mode(struct thermal_zone_device *tz, >> enum thermal_device_mode mode) >> { >> @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, >> } >> } >> >> - data->mode = mode; >> - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); >> - >> return 0; >> } >> >> @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { >> .bind = imx_bind, >> .unbind = imx_unbind, >> .get_temp = imx_get_temp, >> - .get_mode = imx_get_mode, >> .set_mode = imx_set_mode, >> .get_trip_type = imx_get_trip_type, >> .get_trip_temp = imx_get_trip_temp, >> @@ -691,6 +676,9 @@ static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data >> >> static int imx_thermal_probe(struct platform_device *pdev) >> { >> + struct thermal_zone_params tzp = { >> + .initial_mode = THERMAL_DEVICE_ENABLED, >> + }; >> struct imx_thermal_data *data; >> struct regmap *map; >> int measure_freq; >> @@ -799,7 +787,7 @@ static int imx_thermal_probe(struct platform_device *pdev) >> data->tz = thermal_zone_device_register("imx_thermal_zone", >> IMX_TRIP_NUM, >> BIT(IMX_TRIP_PASSIVE), data, >> - &imx_tz_ops, NULL, >> + &imx_tz_ops, &tzp, >> IMX_PASSIVE_DELAY, >> IMX_POLLING_DELAY); >> if (IS_ERR(data->tz)) { >> @@ -831,7 +819,6 @@ static int imx_thermal_probe(struct platform_device *pdev) >> data->socdata->measure_temp_mask); >> >> data->irq_enabled = true; >> - data->mode = THERMAL_DEVICE_ENABLED; >> >> ret = devm_request_threaded_irq(&pdev->dev, data->irq, >> imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, >> @@ -885,7 +872,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) >> data->socdata->measure_temp_mask); >> regmap_write(map, data->socdata->sensor_ctrl + REG_SET, >> data->socdata->power_down_mask); >> - data->mode = THERMAL_DEVICE_DISABLED; >> + data->tz->mode = THERMAL_DEVICE_DISABLED; >> clk_disable_unprepare(data->thermal_clk); >> >> return 0; >> @@ -905,7 +892,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) >> data->socdata->power_down_mask); >> regmap_write(map, data->socdata->sensor_ctrl + REG_SET, >> data->socdata->measure_temp_mask); >> - data->mode = THERMAL_DEVICE_ENABLED; >> + data->tz->mode = THERMAL_DEVICE_ENABLED; >> >> return 0; >> } >> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c >> index e802922a13cf..86a00598ed09 100644 >> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c >> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c >> @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { >> struct int3400_thermal_priv { >> struct acpi_device *adev; >> struct thermal_zone_device *thermal; >> - int mode; >> int art_count; >> struct art *arts; >> int trt_count; >> @@ -230,48 +229,29 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, >> return 0; >> } >> >> -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, >> - enum thermal_device_mode *mode) >> -{ >> - struct int3400_thermal_priv *priv = thermal->devdata; >> - >> - if (!priv) >> - return -EINVAL; >> - >> - *mode = priv->mode; >> - >> - return 0; >> -} >> - >> static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, >> enum thermal_device_mode mode) >> { >> struct int3400_thermal_priv *priv = thermal->devdata; >> - bool enable; >> int result = 0; >> >> if (!priv) >> return -EINVAL; >> >> - if (mode == THERMAL_DEVICE_ENABLED) >> - enable = true; >> - else if (mode == THERMAL_DEVICE_DISABLED) >> - enable = false; >> - else >> + if (mode != THERMAL_DEVICE_ENABLED && >> + mode != THERMAL_DEVICE_DISABLED) >> return -EINVAL; > > These checks should be removed as they are already done in the caller > of ->set_mode method (thermal_zone_device_set_mode()). > >> - if (enable != priv->mode) { >> - priv->mode = enable; >> + if (mode != thermal->mode) { >> result = int3400_thermal_run_osc(priv->adev->handle, >> - priv->current_uuid_index, >> - enable); >> + priv->current_uuid_index, >> + mode == THERMAL_DEVICE_ENABLED); >> } >> return result; >> } >> >> static struct thermal_zone_device_ops int3400_thermal_ops = { >> .get_temp = int3400_thermal_get_temp, >> - .get_mode = int3400_thermal_get_mode, >> .set_mode = int3400_thermal_set_mode, >> }; >> >> diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c >> index d704fc104cfd..c4879b4bfbf1 100644 >> --- a/drivers/thermal/intel/intel_quark_dts_thermal.c >> +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c >> @@ -103,7 +103,6 @@ struct soc_sensor_entry { >> bool locked; >> u32 store_ptps; >> u32 store_dts_enable; >> - enum thermal_device_mode mode; >> struct thermal_zone_device *tzone; >> }; >> >> @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) >> return ret; >> >> if (out & QRK_DTS_ENABLE_BIT) { >> - aux_entry->mode = THERMAL_DEVICE_ENABLED; >> + tzd->mode = THERMAL_DEVICE_ENABLED; >> return 0; >> } >> >> @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) >> if (ret) >> return ret; >> >> - aux_entry->mode = THERMAL_DEVICE_ENABLED; >> + tzd->mode = THERMAL_DEVICE_ENABLED; >> } else { >> - aux_entry->mode = THERMAL_DEVICE_DISABLED; >> + tzd->mode = THERMAL_DEVICE_DISABLED; >> pr_info("DTS is locked. Cannot enable DTS\n"); >> ret = -EPERM; >> } >> @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) >> return ret; >> >> if (!(out & QRK_DTS_ENABLE_BIT)) { >> - aux_entry->mode = THERMAL_DEVICE_DISABLED; >> + tzd->mode = THERMAL_DEVICE_DISABLED; >> return 0; >> } >> >> @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) >> if (ret) >> return ret; >> >> - aux_entry->mode = THERMAL_DEVICE_DISABLED; >> + tzd->mode = THERMAL_DEVICE_DISABLED; >> } else { >> - aux_entry->mode = THERMAL_DEVICE_ENABLED; >> + tzd->mode = THERMAL_DEVICE_ENABLED; >> pr_info("DTS is locked. Cannot disable DTS\n"); >> ret = -EPERM; >> } >> @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, >> return 0; >> } >> >> -static int sys_get_mode(struct thermal_zone_device *tzd, >> - enum thermal_device_mode *mode) >> -{ >> - struct soc_sensor_entry *aux_entry = tzd->devdata; >> - *mode = aux_entry->mode; >> - return 0; >> -} >> - >> static int sys_set_mode(struct thermal_zone_device *tzd, >> enum thermal_device_mode mode) >> { >> @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { >> .get_trip_type = sys_get_trip_type, >> .set_trip_temp = sys_set_trip_temp, >> .get_crit_temp = sys_get_crit_temp, >> - .get_mode = sys_get_mode, >> .set_mode = sys_set_mode, >> }; >> >> diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c >> index 874a47d6923f..863b89546f81 100644 >> --- a/drivers/thermal/of-thermal.c >> +++ b/drivers/thermal/of-thermal.c >> @@ -51,7 +51,6 @@ struct __thermal_bind_params { >> >> /** >> * struct __thermal_zone - internal representation of a thermal zone >> - * @mode: current thermal zone device mode (enabled/disabled) >> * @passive_delay: polling interval while passive cooling is activated >> * @polling_delay: zone polling interval >> * @slope: slope of the temperature adjustment curve >> @@ -65,7 +64,6 @@ struct __thermal_bind_params { >> */ >> >> struct __thermal_zone { >> - enum thermal_device_mode mode; >> int passive_delay; >> int polling_delay; >> int slope; >> @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, >> return 0; >> } >> >> -static int of_thermal_get_mode(struct thermal_zone_device *tz, >> - enum thermal_device_mode *mode) >> -{ >> - struct __thermal_zone *data = tz->devdata; >> - >> - *mode = data->mode; >> - >> - return 0; >> -} >> - >> static int of_thermal_set_mode(struct thermal_zone_device *tz, >> enum thermal_device_mode mode) >> { >> struct __thermal_zone *data = tz->devdata; >> >> - mutex_lock(&tz->lock); >> - >> if (mode == THERMAL_DEVICE_ENABLED) { >> tz->polling_delay = data->polling_delay; >> tz->passive_delay = data->passive_delay; >> @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, >> tz->passive_delay = 0; >> } >> >> - mutex_unlock(&tz->lock); >> - >> - data->mode = mode; >> - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); >> - >> return 0; >> } >> >> @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, >> } >> >> static struct thermal_zone_device_ops of_thermal_ops = { >> - .get_mode = of_thermal_get_mode, >> .set_mode = of_thermal_set_mode, >> >> .get_trip_type = of_thermal_get_trip_type, >> @@ -553,8 +533,14 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, >> if (id == sensor_id) { >> tzd = thermal_zone_of_add_sensor(child, sensor_np, >> data, ops); >> - if (!IS_ERR(tzd)) >> + if (!IS_ERR(tzd)) { >> + mutex_lock(&tzd->lock); >> tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); >> + tzd->mode = THERMAL_DEVICE_ENABLED; >> + mutex_unlock(&tzd->lock); >> + thermal_zone_device_update(tzd, >> + THERMAL_EVENT_UNSPECIFIED); >> + } > > This should use thermal_zone_device_enable() instead of open-coding it: > > if (!IS_ERR(tzd)) > thermal_zone_device_enable(tzd); > > Also because of of_thermal_set_mode() modifications following of/thermal > device drivers (which use ->set_mode directly): > > drivers/thermal/hisi_thermal.c: tzd->ops->set_mode(tzd, > drivers/thermal/rockchip_thermal.c: tzd->ops->set_mode(tzd, > drivers/thermal/sprd_thermal.c: tzd->ops->set_mode(tzd, > > need to be converted to use thermal_zone_device_{en,dis}able() instead. > >> of_node_put(child); >> goto exit; >> @@ -979,7 +965,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) >> >> finish: >> of_node_put(child); >> - tz->mode = THERMAL_DEVICE_DISABLED; >> >> return tz; >> >> @@ -1120,6 +1105,7 @@ int __init of_parse_thermal_zones(void) >> /* these two are left for temperature drivers to use */ >> tzp->slope = tz->slope; >> tzp->offset = tz->offset; >> + tzp->initial_mode = THERMAL_DEVICE_DISABLED; >> >> zone = thermal_zone_device_register(child->name, tz->ntrips, >> mask, tz, >> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c >> index c06550930979..5ff98fcc0f6a 100644 >> --- a/drivers/thermal/thermal_core.c >> +++ b/drivers/thermal/thermal_core.c >> @@ -463,6 +463,43 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) >> thermal_zone_device_init(tz); >> } >> >> +enum thermal_device_mode >> +thermal_zone_device_get_mode(struct thermal_zone_device *tz) >> +{ >> + enum thermal_device_mode mode; >> + >> + mutex_lock(&tz->lock); >> + >> + mode = tz->mode; >> + >> + mutex_unlock(&tz->lock); >> + >> + return mode; >> +} >> + >> +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, >> + enum thermal_device_mode mode) >> +{ >> + int ret = 0; >> + >> + if (mode != THERMAL_DEVICE_DISABLED && >> + mode != THERMAL_DEVICE_ENABLED) >> + return -EINVAL; > > No need for these checks as enum thermal_device_mode has only two > possible values (we don't do "defensive coding" in the kernel). > >> + mutex_lock(&tz->lock); >> + >> + if (tz->ops->set_mode) >> + ret = tz->ops->set_mode(tz, mode); >> + >> + tz->mode = mode; >> + >> + mutex_unlock(&tz->lock); >> + >> + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); >> + >> + return ret; >> +} > > Please add: > > EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); > > here so device drivers can use thermal_zone_device_{en,dis}able(). > >> void thermal_zone_device_update(struct thermal_zone_device *tz, >> enum thermal_notify_event event) >> { >> @@ -1344,6 +1381,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, >> if (atomic_cmpxchg(&tz->need_update, 1, 0)) >> thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); >> >> + if (tzp) >> + thermal_zone_device_set_mode(tz, tzp->initial_mode); > > Please note that currently some device drivers don't access ->mode > at all so their default ->mode value is THERMAL_DEVICE_DISABLED but > in reality they are enabled (IOW after changes in this patch they > should default to THERMAL_DEVICE_ENABLED to reflect real device state > in "mode" sysfs attribue and not break after applying patch #2). > > Therefore we should always call thermal_zone_device_set_mode() and > use the default value of THERMAL_DEVICE_ENABLED if tzp is NULL: > > mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; > thermal_zone_device_set_mode(tz, mode); > > This would also simplify the patch further: > > * setting tz->need_update and calling thermal_zone_device_update() > directly can be removed from thermal_zone_device_register() > > * tzp-s with only .initial_mode = THERMAL_DEVICE_ENABLED set can > be removed from: > > drivers/thermal/acpi.c > drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > drivers/thermal/da9062-thermal.c > drivers/thermal/imx_thermal.c > > The rest of the patch looks fine, thank you for working on this! Oops, one more thing, I've audited all existing users of thermal_zone_device_register() with non-NULL tzp argument: * following drivers should be updated to set .initial_mode to THERMAL_DEVICE_ENABLED in their tzp instance (no ->set_mode method and ->mode not set currently during initialization): drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c drivers/thermal/intel/x86_pkg_temp_thermal.c * following driver may be updated to explicitly set .initial_mode to THERMAL_DEVICE_DISABLED in its tzp instance (has ->set_mode method but ->mode not set currently during initialization): drivers/thermal/intel/int340x_thermal/int3400_thermal.c (THERMAL_DEVICE_DISABLED == 0 is the default currently but lets document the behavior and prepare driver for potentially changing the default into more sane THERMAL_DEVICE_ENABLED in the future) Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > Best regards, > -- > Bartlomiej Zolnierkiewicz > Samsung R&D Institute Poland > Samsung Electronics > >> + >> return tz; >> >> unregister: >> @@ -1473,9 +1513,7 @@ static int thermal_pm_notify(struct notifier_block *nb, >> case PM_POST_SUSPEND: >> atomic_set(&in_suspend, 0); >> list_for_each_entry(tz, &thermal_tz_list, node) { >> - tz_mode = THERMAL_DEVICE_ENABLED; >> - if (tz->ops->get_mode) >> - tz->ops->get_mode(tz, &tz_mode); >> + tz_mode = thermal_zone_device_get_mode(tz); >> >> if (tz_mode == THERMAL_DEVICE_DISABLED) >> continue; >> diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h >> index c95689586e19..8e561bac3133 100644 >> --- a/drivers/thermal/thermal_core.h >> +++ b/drivers/thermal/thermal_core.h >> @@ -141,6 +141,22 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, >> unsigned long new_state) {} >> #endif /* CONFIG_THERMAL_STATISTICS */ >> >> +enum thermal_device_mode >> +thermal_zone_device_get_mode(struct thermal_zone_device *tz); >> + >> +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, >> + enum thermal_device_mode mode); >> + >> +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) >> +{ >> + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); >> +} >> + >> +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) >> +{ >> + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); >> +} >> + >> /* device tree support */ >> #ifdef CONFIG_THERMAL_OF >> int of_parse_thermal_zones(void); >> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c >> index aa99edb4dff7..cbb27b3c96d2 100644 >> --- a/drivers/thermal/thermal_sysfs.c >> +++ b/drivers/thermal/thermal_sysfs.c >> @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) >> { >> struct thermal_zone_device *tz = to_thermal_zone(dev); >> enum thermal_device_mode mode; >> - int result; >> - >> - if (!tz->ops->get_mode) >> - return -EPERM; >> >> - result = tz->ops->get_mode(tz, &mode); >> - if (result) >> - return result; >> + mode = thermal_zone_device_get_mode(tz); >> >> return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" >> : "disabled"); >> @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, >> return -EPERM; >> >> if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) >> - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); >> + result = thermal_zone_device_enable(tz); >> else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) >> - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); >> + result = thermal_zone_device_disable(tz); >> else >> result = -EINVAL; >> >> @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { >> .attrs = thermal_zone_dev_attrs, >> }; >> >> -/* We expose mode only if .get_mode is present */ >> static struct attribute *thermal_zone_mode_attrs[] = { >> &dev_attr_mode.attr, >> NULL, >> }; >> >> -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, >> - struct attribute *attr, >> - int attrno) >> -{ >> - struct device *dev = container_of(kobj, struct device, kobj); >> - struct thermal_zone_device *tz; >> - >> - tz = container_of(dev, struct thermal_zone_device, device); >> - >> - if (tz->ops->get_mode) >> - return attr->mode; >> - >> - return 0; >> -} >> - >> static struct attribute_group thermal_zone_mode_attribute_group = { >> .attrs = thermal_zone_mode_attrs, >> - .is_visible = thermal_zone_mode_is_visible, >> }; >> >> /* We expose passive only if passive trips are present */ >> diff --git a/include/linux/thermal.h b/include/linux/thermal.h >> index 216185bb3014..da4141697e2e 100644 >> --- a/include/linux/thermal.h >> +++ b/include/linux/thermal.h >> @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { >> struct thermal_cooling_device *); >> int (*get_temp) (struct thermal_zone_device *, int *); >> int (*set_trips) (struct thermal_zone_device *, int, int); >> - int (*get_mode) (struct thermal_zone_device *, >> - enum thermal_device_mode *); >> int (*set_mode) (struct thermal_zone_device *, >> enum thermal_device_mode); >> int (*get_trip_type) (struct thermal_zone_device *, int, >> @@ -128,6 +126,7 @@ struct thermal_cooling_device { >> * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature >> * @trip_type_attrs: attributes for trip points for sysfs: trip type >> * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis >> + * @mode: current mode of this thermal zone >> * @devdata: private pointer for device private data >> * @trips: number of trip points the thermal zone supports >> * @trips_disabled; bitmap for disabled trips >> @@ -170,6 +169,7 @@ struct thermal_zone_device { >> struct thermal_attr *trip_temp_attrs; >> struct thermal_attr *trip_type_attrs; >> struct thermal_attr *trip_hyst_attrs; >> + enum thermal_device_mode mode; >> void *devdata; >> int trips; >> unsigned long trips_disabled; /* bitmap for disabled trips */ >> @@ -264,6 +264,9 @@ struct thermal_zone_params { >> int num_tbps; /* Number of tbp entries */ >> struct thermal_bind_params *tbp; >> >> + /* Initial mode of this thermal zone device */ >> + enum thermal_device_mode initial_mode; >> + >> /* >> * Sustainable power (heat) that this thermal zone can dissipate in >> * mW >> ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH 0/2] Stop monitoring disabled devices 2020-04-19 13:10 ` Bartlomiej Zolnierkiewicz @ 2020-04-20 18:17 ` Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz ` (2 more replies) 0 siblings, 3 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-20 18:17 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz After 3 revisions of an RFC I'm sending this as a PATCH series. The first patch makes all the drivers store their mode in struct thermal_zone_device. Such a move has consequences: driver-specific variables for storing mode are not necessary. Consequently get_mode() methods become obsolete. Then sysfs "mode" attribute stops depending on get_mode() being provided, because it is always provided from now on. The first patch also introduces the initial mode to be optionally passed to thermal_zone_device_register(). Given all the groundwork done in patch 1/2 patch 2/2 becomes very simple. Compared to RFC v3 this series addresses comments from Bartlomiej, thank you Bartlomiej for your review! RFCv3..this PATCH: - export thermal_zone_device_{enable|disable}() for drivers - don't check provided enum values in acpi's thermal_zet_mode() and in int3400_thermal_set_mode() - use thermal_zone_device_enable() in of_thermal instead of open coding it - use thermal_zone_device_{enable|disable}() in hisi_thermal, rockchip_thermal and sprd_thermal - assume THERMAL_DEVICE_ENABLED is thermal_zone_params not provided at tzd's register time - eliminated tzp-s which contain only .initial_mode = THERMAL_DEVICE_ENABLED, - don't set tz->need_update and don't call thermal_zone_device_update() at the end of thermal_zone_device_register() - used .initial_mode in int340x_thermal_zone, x86_pkg_temp_thermal and int3400_thermal Andrzej Pietrasiewicz (2): thermal: core: Let thermal zone device's mode be stored in its struct thermal: core: Stop polling DISABLED thermal devices drivers/acpi/thermal.c | 35 ++-------- .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ------------ drivers/platform/x86/acerhdf.c | 17 +---- drivers/thermal/da9062-thermal.c | 11 ---- drivers/thermal/hisi_thermal.c | 6 +- drivers/thermal/imx_thermal.c | 24 ++----- .../intel/int340x_thermal/int3400_thermal.c | 31 ++------- .../int340x_thermal/int340x_thermal_zone.c | 1 + .../thermal/intel/intel_quark_dts_thermal.c | 22 ++----- drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/thermal/of-thermal.c | 24 +------ drivers/thermal/rockchip_thermal.c | 6 +- drivers/thermal/sprd_thermal.c | 6 +- drivers/thermal/thermal_core.c | 65 ++++++++++++++++--- drivers/thermal/thermal_core.h | 3 + drivers/thermal/thermal_sysfs.c | 29 +-------- include/linux/thermal.h | 22 ++++++- 17 files changed, 121 insertions(+), 224 deletions(-) base-commit: 79799562bf087b30d9dd0fddf5bed2d3b038be08 -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-20 18:17 ` [PATCH 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-04-20 18:17 ` Andrzej Pietrasiewicz 2020-04-22 7:49 ` kbuild test robot 2020-04-22 17:03 ` kbuild test robot 2020-04-20 18:17 ` [PATCH 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-22 16:12 ` [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2 siblings, 2 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-20 18:17 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Thermal zone devices' mode is stored in individual drivers. This patch changes it so that mode is stored in struct thermal_zone_device instead. As a result all driver-specific variables storing the mode are not needed and are removed. Consequently, the get_mode() implementations have nothing to operate on and need to be removed, too. Some thermal framework functions are introduced: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_enable() thermal_zone_device_disable() thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock and the "set" calls driver's set_mode() if provided, so the latter must not take this lock again. At the end of the "set" thermal_zone_device_update() is called so drivers don't need to repeat this invocation in their specific set_mode() implementations. struct thermal_zone_params gains a new member called initial_mode, which is used to set tzd's mode at registration time and if tzp is not provided to thermal_zone_device_register() then it is assumed that the initial mode is THERMAL_DEVICE_ENABLED. The sysfs "mode" attribute is always exposed from now on, because all thermal zone devices now have their get_mode() implemented at the generic level and it is always available. Exposing "mode" doesn't hurt the drivers which don't provide their own set_mode(), because writing to "mode" will result in -EPERM, as expected. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 35 ++----------- .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ---------------- drivers/platform/x86/acerhdf.c | 17 ++----- drivers/thermal/da9062-thermal.c | 11 ----- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 24 ++------- .../intel/int340x_thermal/int3400_thermal.c | 31 ++---------- .../int340x_thermal/int340x_thermal_zone.c | 1 + .../thermal/intel/intel_quark_dts_thermal.c | 22 +++------ drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/thermal/of-thermal.c | 24 +-------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 49 ++++++++++++++++--- drivers/thermal/thermal_core.h | 3 ++ drivers/thermal/thermal_sysfs.c | 29 ++--------- include/linux/thermal.h | 22 ++++++++- 17 files changed, 107 insertions(+), 222 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..d1f352ed5241 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -526,25 +525,10 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; @@ -552,20 +536,14 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != thermal->mode) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); - acpi_thermal_check(tz); + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); } return 0; } @@ -856,7 +834,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, @@ -913,8 +890,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; - dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..5d28384046da 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - thermal->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - tz->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -765,7 +726,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -881,7 +841,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1050,7 +1009,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..aaf8b845be90 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode = 1; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, err_out: acerhdf_revert_to_bios_mode(); + thz_dev->mode = THERMAL_DEVICE_DISABLED; return -EINVAL; } @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + acerhdf_zone_params.initial_mode = + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..c3075d038095 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..edbcb30815dc 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, @@ -831,7 +816,6 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +869,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_disable(data->tz); clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +889,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_enable(data->tz); return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e802922a13cf..50642f01e2bf 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; int art_count; struct art *arts; int trt_count; @@ -230,54 +229,32 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else - return -EINVAL; - - if (enable != priv->mode) { - priv->mode = enable; + if (mode != thermal->mode) { result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; static struct thermal_zone_params int3400_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_ZONE_DISABLED, }; static int int3400_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..b36da9bfbf8a 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -208,6 +208,7 @@ EXPORT_SYMBOL_GPL(int340x_thermal_read_trips); static struct thermal_zone_params int340x_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..cb810a02aab0 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -56,6 +56,7 @@ struct zone_device { static struct thermal_zone_params pkg_temp_tz_params = { .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; /* Keep track of how many zone pointers we allocated in init() */ diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 874a47d6923f..48787a5576d8 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, @@ -554,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -979,7 +959,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1120,6 +1099,7 @@ int __init of_parse_thermal_zones(void) /* these two are left for temperature drivers to use */ tzp->slope = tz->slope; tzp->offset = tz->offset; + tzp->initial_mode = THERMAL_DEVICE_DISABLED; zone = thermal_zone_device_register(child->name, tz->ntrips, mask, tz, diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c06550930979..a012d77dd602 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -463,6 +463,44 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode; +} + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + + mutex_lock(&tz->lock); + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { @@ -1236,6 +1274,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, int result; int count; struct thermal_governor *governor; + enum thermal_device_mode mode; if (!type || strlen(type) == 0) { pr_err("Error: No thermal zone type defined\n"); @@ -1340,9 +1379,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); thermal_zone_device_reset(tz); - /* Update the new thermal zone and mark it as already updated. */ - if (atomic_cmpxchg(&tz->need_update, 1, 0)) - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; + thermal_zone_device_set_mode(tz, mode); return tz; @@ -1473,9 +1512,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); + tz_mode = thermal_zone_device_get_mode(tz); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index c95689586e19..ff5519adb68a 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -141,6 +141,9 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, unsigned long new_state) {} #endif /* CONFIG_THERMAL_STATISTICS */ +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz); + /* device tree support */ #ifdef CONFIG_THERMAL_OF int of_parse_thermal_zones(void); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..cbb27b3c96d2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; + mode = thermal_zone_device_get_mode(tz); return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" : "disabled"); @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..36b80ef80674 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, @@ -128,6 +126,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +169,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -264,6 +264,9 @@ struct thermal_zone_params { int num_tbps; /* Number of tbp entries */ struct thermal_bind_params *tbp; + /* Initial mode of this thermal zone device */ + enum thermal_device_mode initial_mode; + /* * Sustainable power (heat) that this thermal zone can dissipate in * mW @@ -395,6 +398,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); @@ -426,6 +431,9 @@ static inline struct thermal_zone_device *thermal_zone_device_register( static inline void thermal_zone_device_unregister( struct thermal_zone_device *tz) { } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ return -EINVAL } static inline struct thermal_cooling_device * thermal_cooling_device_register(char *type, void *devdata, const struct thermal_cooling_device_ops *ops) @@ -465,4 +473,14 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { } #endif /* CONFIG_THERMAL */ +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-22 7:49 ` kbuild test robot 2020-04-22 17:14 ` Andrzej Pietrasiewicz 2020-04-22 17:03 ` kbuild test robot 1 sibling, 1 reply; 137+ messages in thread From: kbuild test robot @ 2020-04-22 7:49 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: kbuild-all, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko [-- Attachment #1: Type: text/plain, Size: 3329 bytes --] Hi Andrzej, I love your patch! Yet something to improve: [auto build test ERROR on 79799562bf087b30d9dd0fddf5bed2d3b038be08] url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200422-133553 base: 79799562bf087b30d9dd0fddf5bed2d3b038be08 config: arm-iop32x_defconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=arm If you fix the issue, kindly add following tag as appropriate Reported-by: kbuild test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from drivers/hwmon/hwmon.c:22: include/linux/thermal.h: In function 'thermal_zone_device_set_mode': >> include/linux/thermal.h:436:18: error: expected ';' before '}' token 436 | { return -EINVAL } | ^ vim +436 include/linux/thermal.h 421 422 void thermal_cdev_update(struct thermal_cooling_device *); 423 void thermal_notify_framework(struct thermal_zone_device *, int); 424 #else 425 static inline struct thermal_zone_device *thermal_zone_device_register( 426 const char *type, int trips, int mask, void *devdata, 427 struct thermal_zone_device_ops *ops, 428 struct thermal_zone_params *tzp, 429 int passive_delay, int polling_delay) 430 { return ERR_PTR(-ENODEV); } 431 static inline void thermal_zone_device_unregister( 432 struct thermal_zone_device *tz) 433 { } 434 int thermal_zone_device_set_mode(struct thermal_zone_device *tz, 435 enum thermal_device_mode mode) > 436 { return -EINVAL } 437 static inline struct thermal_cooling_device * 438 thermal_cooling_device_register(char *type, void *devdata, 439 const struct thermal_cooling_device_ops *ops) 440 { return ERR_PTR(-ENODEV); } 441 static inline struct thermal_cooling_device * 442 thermal_of_cooling_device_register(struct device_node *np, 443 char *type, void *devdata, const struct thermal_cooling_device_ops *ops) 444 { return ERR_PTR(-ENODEV); } 445 static inline struct thermal_cooling_device * 446 devm_thermal_of_cooling_device_register(struct device *dev, 447 struct device_node *np, 448 char *type, void *devdata, 449 const struct thermal_cooling_device_ops *ops) 450 { 451 return ERR_PTR(-ENODEV); 452 } 453 static inline void thermal_cooling_device_unregister( 454 struct thermal_cooling_device *cdev) 455 { } 456 static inline struct thermal_zone_device *thermal_zone_get_zone_by_name( 457 const char *name) 458 { return ERR_PTR(-ENODEV); } 459 static inline int thermal_zone_get_temp( 460 struct thermal_zone_device *tz, int *temp) 461 { return -ENODEV; } 462 static inline int thermal_zone_get_slope( 463 struct thermal_zone_device *tz) 464 { return -ENODEV; } 465 static inline int thermal_zone_get_offset( 466 struct thermal_zone_device *tz) 467 { return -ENODEV; } 468 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 18793 bytes --] ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-22 7:49 ` kbuild test robot @ 2020-04-22 17:14 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-22 17:14 UTC (permalink / raw) To: kbuild test robot, linux-pm Cc: kbuild-all, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko W dniu 22.04.2020 o 09:49, kbuild test robot pisze: > Hi Andrzej, > > I love your patch! Yet something to improve: > > [auto build test ERROR on 79799562bf087b30d9dd0fddf5bed2d3b038be08] > > url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200422-133553 > base: 79799562bf087b30d9dd0fddf5bed2d3b038be08 > config: arm-iop32x_defconfig (attached as .config) > compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 > reproduce: > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # save the attached .config to linux build tree > COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=arm > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kbuild test robot <lkp@intel.com> > > All errors (new ones prefixed by >>): > > In file included from drivers/hwmon/hwmon.c:22: > include/linux/thermal.h: In function 'thermal_zone_device_set_mode': >>> include/linux/thermal.h:436:18: error: expected ';' before '}' token > 436 | { return -EINVAL } > | ^ > Addressed in PATCH RESEND 1/2, in reply to PATCH 1/2. Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-22 7:49 ` kbuild test robot @ 2020-04-22 17:03 ` kbuild test robot 2020-04-22 17:15 ` Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: kbuild test robot @ 2020-04-22 17:03 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: kbuild-all, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko [-- Attachment #1: Type: text/plain, Size: 1327 bytes --] Hi Andrzej, I love your patch! Yet something to improve: [auto build test ERROR on 79799562bf087b30d9dd0fddf5bed2d3b038be08] url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200422-133553 base: 79799562bf087b30d9dd0fddf5bed2d3b038be08 config: i386-allyesconfig (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=i386 If you fix the issue, kindly add following tag as appropriate Reported-by: kbuild test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> drivers/thermal/intel/int340x_thermal/int3400_thermal.c:257:18: error: 'THERMAL_ZONE_DISABLED' undeclared here (not in a function); did you mean 'THERMAL_DEVICE_DISABLED'? .initial_mode = THERMAL_ZONE_DISABLED, ^~~~~~~~~~~~~~~~~~~~~ THERMAL_DEVICE_DISABLED vim +257 drivers/thermal/intel/int340x_thermal/int3400_thermal.c 253 254 static struct thermal_zone_params int3400_thermal_params = { 255 .governor_name = "user_space", 256 .no_hwmon = true, > 257 .initial_mode = THERMAL_ZONE_DISABLED, 258 }; 259 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 72271 bytes --] ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-22 17:03 ` kbuild test robot @ 2020-04-22 17:15 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-22 17:15 UTC (permalink / raw) To: kbuild test robot, linux-pm Cc: kbuild-all, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko W dniu 22.04.2020 o 19:03, kbuild test robot pisze: > Hi Andrzej, > > I love your patch! Yet something to improve: > > [auto build test ERROR on 79799562bf087b30d9dd0fddf5bed2d3b038be08] > > url: https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/Stop-monitoring-disabled-devices/20200422-133553 > base: 79799562bf087b30d9dd0fddf5bed2d3b038be08 > config: i386-allyesconfig (attached as .config) > compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 > reproduce: > # save the attached .config to linux build tree > make ARCH=i386 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kbuild test robot <lkp@intel.com> > > All errors (new ones prefixed by >>): > >>> drivers/thermal/intel/int340x_thermal/int3400_thermal.c:257:18: error: 'THERMAL_ZONE_DISABLED' undeclared here (not in a function); did you mean 'THERMAL_DEVICE_DISABLED'? > .initial_mode = THERMAL_ZONE_DISABLED, > ^~~~~~~~~~~~~~~~~~~~~ > THERMAL_DEVICE_DISABLED Addressed in PATCH RESEND 1/2, in reply to PATCH 1/2. Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-20 18:17 ` [PATCH 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-20 18:17 ` Andrzej Pietrasiewicz 2020-04-22 16:12 ` [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-20 18:17 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a012d77dd602..c2dd9c561cf5 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,13 +305,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -506,6 +515,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-20 18:17 ` [PATCH 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-04-22 16:12 ` Andrzej Pietrasiewicz 2020-04-23 14:39 ` Bartlomiej Zolnierkiewicz 2 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-22 16:12 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Thermal zone devices' mode is stored in individual drivers. This patch changes it so that mode is stored in struct thermal_zone_device instead. As a result all driver-specific variables storing the mode are not needed and are removed. Consequently, the get_mode() implementations have nothing to operate on and need to be removed, too. Some thermal framework functions are introduced: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_enable() thermal_zone_device_disable() thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock and the "set" calls driver's set_mode() if provided, so the latter must not take this lock again. At the end of the "set" thermal_zone_device_update() is called so drivers don't need to repeat this invocation in their specific set_mode() implementations. struct thermal_zone_params gains a new member called initial_mode, which is used to set tzd's mode at registration time and if tzp is not provided to thermal_zone_device_register() then it is assumed that the initial mode is THERMAL_DEVICE_ENABLED. The sysfs "mode" attribute is always exposed from now on, because all thermal zone devices now have their get_mode() implemented at the generic level and it is always available. Exposing "mode" doesn't hurt the drivers which don't provide their own set_mode(), because writing to "mode" will result in -EPERM, as expected. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- Fixed two typos: - one found by kbuild test robot <lkp@intel.com> (missing semicolon in dummy implementation of thermal_zone_device_set_mode() - one found by myself (.initial_mode in int3400_thermal_params set to a nonexistent THERMAL_ZONE_DISABLED - should be THERMAL_DEVICE_DISABLED) drivers/acpi/thermal.c | 35 ++----------- .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ---------------- drivers/platform/x86/acerhdf.c | 17 ++----- drivers/thermal/da9062-thermal.c | 11 ----- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 24 ++------- .../intel/int340x_thermal/int3400_thermal.c | 31 ++---------- .../int340x_thermal/int340x_thermal_zone.c | 1 + .../thermal/intel/intel_quark_dts_thermal.c | 22 +++------ drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/thermal/of-thermal.c | 24 +-------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 49 ++++++++++++++++--- drivers/thermal/thermal_core.h | 3 ++ drivers/thermal/thermal_sysfs.c | 29 ++--------- include/linux/thermal.h | 22 ++++++++- 17 files changed, 107 insertions(+), 222 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..d1f352ed5241 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -526,25 +525,10 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; @@ -552,20 +536,14 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != thermal->mode) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); - acpi_thermal_check(tz); + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); } return 0; } @@ -856,7 +834,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, @@ -913,8 +890,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; - dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..5d28384046da 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - thermal->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - tz->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -765,7 +726,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -881,7 +841,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1050,7 +1009,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..aaf8b845be90 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode = 1; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, err_out: acerhdf_revert_to_bios_mode(); + thz_dev->mode = THERMAL_DEVICE_DISABLED; return -EINVAL; } @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + acerhdf_zone_params.initial_mode = + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..c3075d038095 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..edbcb30815dc 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, @@ -831,7 +816,6 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -885,7 +869,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_disable(data->tz); clk_disable_unprepare(data->thermal_clk); return 0; @@ -905,7 +889,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_enable(data->tz); return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e802922a13cf..1751d4b103b1 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; int art_count; struct art *arts; int trt_count; @@ -230,54 +229,32 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else - return -EINVAL; - - if (enable != priv->mode) { - priv->mode = enable; + if (mode != thermal->mode) { result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; static struct thermal_zone_params int3400_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_DISABLED, }; static int int3400_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..b36da9bfbf8a 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -208,6 +208,7 @@ EXPORT_SYMBOL_GPL(int340x_thermal_read_trips); static struct thermal_zone_params int340x_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..c4879b4bfbf1 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..cb810a02aab0 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -56,6 +56,7 @@ struct zone_device { static struct thermal_zone_params pkg_temp_tz_params = { .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; /* Keep track of how many zone pointers we allocated in init() */ diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 874a47d6923f..48787a5576d8 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, @@ -554,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -979,7 +959,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1120,6 +1099,7 @@ int __init of_parse_thermal_zones(void) /* these two are left for temperature drivers to use */ tzp->slope = tz->slope; tzp->offset = tz->offset; + tzp->initial_mode = THERMAL_DEVICE_DISABLED; zone = thermal_zone_device_register(child->name, tz->ntrips, mask, tz, diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c06550930979..a012d77dd602 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -463,6 +463,44 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode; +} + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + if (mode != THERMAL_DEVICE_DISABLED && + mode != THERMAL_DEVICE_ENABLED) + return -EINVAL; + + mutex_lock(&tz->lock); + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { @@ -1236,6 +1274,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, int result; int count; struct thermal_governor *governor; + enum thermal_device_mode mode; if (!type || strlen(type) == 0) { pr_err("Error: No thermal zone type defined\n"); @@ -1340,9 +1379,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); thermal_zone_device_reset(tz); - /* Update the new thermal zone and mark it as already updated. */ - if (atomic_cmpxchg(&tz->need_update, 1, 0)) - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; + thermal_zone_device_set_mode(tz, mode); return tz; @@ -1473,9 +1512,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); + tz_mode = thermal_zone_device_get_mode(tz); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index c95689586e19..ff5519adb68a 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -141,6 +141,9 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, unsigned long new_state) {} #endif /* CONFIG_THERMAL_STATISTICS */ +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz); + /* device tree support */ #ifdef CONFIG_THERMAL_OF int of_parse_thermal_zones(void); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..cbb27b3c96d2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; + mode = thermal_zone_device_get_mode(tz); return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" : "disabled"); @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..c789d4ff6e63 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, @@ -128,6 +126,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +169,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -264,6 +264,9 @@ struct thermal_zone_params { int num_tbps; /* Number of tbp entries */ struct thermal_bind_params *tbp; + /* Initial mode of this thermal zone device */ + enum thermal_device_mode initial_mode; + /* * Sustainable power (heat) that this thermal zone can dissipate in * mW @@ -395,6 +398,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); @@ -426,6 +431,9 @@ static inline struct thermal_zone_device *thermal_zone_device_register( static inline void thermal_zone_device_unregister( struct thermal_zone_device *tz) { } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ return -EINVAL; } static inline struct thermal_cooling_device * thermal_cooling_device_register(char *type, void *devdata, const struct thermal_cooling_device_ops *ops) @@ -465,4 +473,14 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { } #endif /* CONFIG_THERMAL */ +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-22 16:12 ` [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-23 14:39 ` Bartlomiej Zolnierkiewicz 2020-04-23 16:57 ` [PATCH v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 0 siblings, 1 reply; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-04-23 14:39 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Thank you for updating the patch, some more comments below. On 4/22/20 6:12 PM, Andrzej Pietrasiewicz wrote: > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > struct thermal_zone_params gains a new member called initial_mode, which > is used to set tzd's mode at registration time and if tzp is not provided > to thermal_zone_device_register() then it is assumed that the initial > mode is THERMAL_DEVICE_ENABLED. > > The sysfs "mode" attribute is always exposed from now on, because all > thermal zone devices now have their get_mode() implemented at the generic > level and it is always available. Exposing "mode" doesn't hurt the drivers > which don't provide their own set_mode(), because writing to "mode" will > result in -EPERM, as expected. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > > Fixed two typos: > > - one found by kbuild test robot <lkp@intel.com> (missing semicolon > in dummy implementation of thermal_zone_device_set_mode() > > - one found by myself (.initial_mode in int3400_thermal_params set to > a nonexistent THERMAL_ZONE_DISABLED - should be THERMAL_DEVICE_DISABLED) BTW Due to the above fixes the patch should have been be marked as v2, not RESEND (please use RESEND only when posting again unchanged patch). > drivers/acpi/thermal.c | 35 ++----------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ---------------- > drivers/platform/x86/acerhdf.c | 17 ++----- > drivers/thermal/da9062-thermal.c | 11 ----- > drivers/thermal/hisi_thermal.c | 6 ++- > drivers/thermal/imx_thermal.c | 24 ++------- > .../intel/int340x_thermal/int3400_thermal.c | 31 ++---------- > .../int340x_thermal/int340x_thermal_zone.c | 1 + > .../thermal/intel/intel_quark_dts_thermal.c | 22 +++------ > drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + > drivers/thermal/of-thermal.c | 24 +-------- > drivers/thermal/rockchip_thermal.c | 6 ++- > drivers/thermal/sprd_thermal.c | 6 ++- > drivers/thermal/thermal_core.c | 49 ++++++++++++++++--- > drivers/thermal/thermal_core.h | 3 ++ > drivers/thermal/thermal_sysfs.c | 29 ++--------- > include/linux/thermal.h | 22 ++++++++- > 17 files changed, 107 insertions(+), 222 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..d1f352ed5241 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -526,25 +525,10 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > @@ -552,20 +536,14 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != thermal->mode) { > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > - acpi_thermal_check(tz); > + mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > } > return 0; > } > @@ -856,7 +834,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > @@ -913,8 +890,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > - > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > return 0; > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..5d28384046da 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal *thermal = tzdev->devdata; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - thermal->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal_module *tz = tzdev->devdata; > struct mlxsw_thermal *thermal = tz->parent; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - tz->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -765,7 +726,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -881,7 +841,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -1050,7 +1009,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..aaf8b845be90 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) > kernelmode = 1; > > thz_dev->polling_delay = interval*1000; > - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, > > err_out: > acerhdf_revert_to_bios_mode(); > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > return -EINVAL; > } > > @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + acerhdf_zone_params.initial_mode = > + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..c3075d038095 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c > index 2d26ae80e202..ee05950afd2f 100644 > --- a/drivers/thermal/hisi_thermal.c > +++ b/drivers/thermal/hisi_thermal.c > @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, > { > struct thermal_zone_device *tzd = sensor->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static int hisi_thermal_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..edbcb30815dc 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > @@ -831,7 +816,6 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -885,7 +869,7 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > data->socdata->measure_temp_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_disable(data->tz); Since we now also (indirectly) call ->set_mode here the following code: regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, data->socdata->measure_temp_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->power_down_mask); should be removed from imx_thermal_suspend(). > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -905,7 +889,7 @@ static int __maybe_unused imx_thermal_resume(struct device *dev) > data->socdata->power_down_mask); > regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_enable(data->tz); Since we now also (indirectly) call ->set_mode here the following code: regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, data->socdata->power_down_mask); regmap_write(map, data->socdata->sensor_ctrl + REG_SET, data->socdata->measure_temp_mask); should be removed from imx_thermal_resume(). > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e802922a13cf..1751d4b103b1 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > int art_count; > struct art *arts; > int trt_count; > @@ -230,54 +229,32 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > - return -EINVAL; > - > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != thermal->mode) { > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > static struct thermal_zone_params int3400_thermal_params = { > .governor_name = "user_space", > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_DISABLED, > }; > > static int int3400_thermal_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > index 432213272f1e..b36da9bfbf8a 100644 > --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > @@ -208,6 +208,7 @@ EXPORT_SYMBOL_GPL(int340x_thermal_read_trips); > static struct thermal_zone_params int340x_thermal_params = { > .governor_name = "user_space", > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_ENABLED, > }; > > struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..c4879b4bfbf1 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; Please take a look at sys_set_mode(): static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { int ret; mutex_lock(&dts_update_mutex); if (mode == THERMAL_DEVICE_ENABLED) ret = soc_dts_enable(tzd); else ret = soc_dts_disable(tzd); mutex_unlock(&dts_update_mutex); return ret; } and alloc_soc_dts(): static struct soc_sensor_entry *alloc_soc_dts(void) { ... aux_entry->tzone = thermal_zone_device_register("quark_dts", QRK_MAX_DTS_TRIPS, wr_mask, aux_entry, &tzone_ops, NULL, 0, polling_delay); if (IS_ERR(aux_entry->tzone)) { err = PTR_ERR(aux_entry->tzone); goto err_ret; } mutex_lock(&dts_update_mutex); err = soc_dts_enable(aux_entry->tzone); mutex_unlock(&dts_update_mutex); if (err) goto err_aux_status; ... } Since ->set_mode is now called through thermal_zone_device_register() the following code should be removed: mutex_lock(&dts_update_mutex); err = soc_dts_enable(aux_entry->tzone); mutex_unlock(&dts_update_mutex); if (err) goto err_aux_status; > diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c > index a006b9fd1d72..cb810a02aab0 100644 > --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c > +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c > @@ -56,6 +56,7 @@ struct zone_device { > > static struct thermal_zone_params pkg_temp_tz_params = { > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_ENABLED, > }; > > /* Keep track of how many zone pointers we allocated in init() */ > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 874a47d6923f..48787a5576d8 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > struct __thermal_zone *data = tz->devdata; > > - mutex_lock(&tz->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > tz->passive_delay = 0; > } > > - mutex_unlock(&tz->lock); > - > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > @@ -554,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > if (!IS_ERR(tzd)) > - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + thermal_zone_device_enable(tzd); > > of_node_put(child); > goto exit; > @@ -979,7 +959,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1120,6 +1099,7 @@ int __init of_parse_thermal_zones(void) > /* these two are left for temperature drivers to use */ > tzp->slope = tz->slope; > tzp->offset = tz->offset; > + tzp->initial_mode = THERMAL_DEVICE_DISABLED; > > zone = thermal_zone_device_register(child->name, tz->ntrips, > mask, tz, > diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c > index 15a71ecc916c..aa9e0e31ef98 100644 > --- a/drivers/thermal/rockchip_thermal.c > +++ b/drivers/thermal/rockchip_thermal.c > @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) > { > struct thermal_zone_device *tzd = sensor->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) > diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c > index a340374e8c51..58f995b0f804 100644 > --- a/drivers/thermal/sprd_thermal.c > +++ b/drivers/thermal/sprd_thermal.c > @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) > { > struct thermal_zone_device *tzd = sen->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static int sprd_thm_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index c06550930979..a012d77dd602 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -463,6 +463,44 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode; > +} > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + int ret = 0; > + > + if (mode != THERMAL_DEVICE_DISABLED && > + mode != THERMAL_DEVICE_ENABLED) > + return -EINVAL; Please remove above checks, they really are redundant. > + mutex_lock(&tz->lock); > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + tz->mode = mode; This should be: if (!ret) tz->mode = mode; as we shouldn't change the mode information if ->set_mode has failed. > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > @@ -1236,6 +1274,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, > int result; > int count; > struct thermal_governor *governor; > + enum thermal_device_mode mode; > > if (!type || strlen(type) == 0) { > pr_err("Error: No thermal zone type defined\n"); > @@ -1340,9 +1379,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, > INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); > > thermal_zone_device_reset(tz); > - /* Update the new thermal zone and mark it as already updated. */ > - if (atomic_cmpxchg(&tz->need_update, 1, 0)) > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; > + thermal_zone_device_set_mode(tz, mode); The setting of tz->need_update earlier in thermal_zone_device_register(): /* A new thermal zone needs to be updated anyway. */ atomic_set(&tz->need_update, 1); should also be removed now. Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > > return tz; > > @@ -1473,9 +1512,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > + tz_mode = thermal_zone_device_get_mode(tz); > > if (tz_mode == THERMAL_DEVICE_DISABLED) > continue; > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index c95689586e19..ff5519adb68a 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -141,6 +141,9 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, > unsigned long new_state) {} > #endif /* CONFIG_THERMAL_STATISTICS */ > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz); > + > /* device tree support */ > #ifdef CONFIG_THERMAL_OF > int of_parse_thermal_zones(void); > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..cbb27b3c96d2 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > + mode = thermal_zone_device_get_mode(tz); > > return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > : "disabled"); > @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..c789d4ff6e63 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > @@ -128,6 +126,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +169,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -264,6 +264,9 @@ struct thermal_zone_params { > int num_tbps; /* Number of tbp entries */ > struct thermal_bind_params *tbp; > > + /* Initial mode of this thermal zone device */ > + enum thermal_device_mode initial_mode; > + > /* > * Sustainable power (heat) that this thermal zone can dissipate in > * mW > @@ -395,6 +398,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, > unsigned int); > int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, > struct thermal_cooling_device *); > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > void thermal_zone_device_update(struct thermal_zone_device *, > enum thermal_notify_event); > > @@ -426,6 +431,9 @@ static inline struct thermal_zone_device *thermal_zone_device_register( > static inline void thermal_zone_device_unregister( > struct thermal_zone_device *tz) > { } > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ return -EINVAL; } > static inline struct thermal_cooling_device * > thermal_cooling_device_register(char *type, void *devdata, > const struct thermal_cooling_device_ops *ops) > @@ -465,4 +473,14 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, > { } > #endif /* CONFIG_THERMAL */ > > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > #endif /* __THERMAL_H__ */ > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v3 0/2] Stop monitoring disabled devices 2020-04-23 14:39 ` Bartlomiej Zolnierkiewicz @ 2020-04-23 16:57 ` Andrzej Pietrasiewicz 2020-04-23 16:57 ` [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-23 16:57 ` [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 0 siblings, 2 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-23 16:57 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz This is the third iteration of this PATCH series (not counting RFCs). It addresses comments from Bartlomiej - thanks, Bartlomiej! The first patch makes all the drivers store their mode in struct thermal_zone_device. Such a move has consequences: driver-specific variables for storing mode are not necessary. Consequently get_mode() methods become obsolete. Then sysfs "mode" attribute stops depending on get_mode() being provided, because it is always provided from now on. The first patch also introduces the initial mode to be optionally passed to thermal_zone_device_register(). Given all the groundwork done in patch 1/2 patch 2/2 becomes very simple. I incorrectly named PATCH v2 a PATCH RESEND 1/2, so now I'm counting that as PATCH v2, hence this series is PATCH v3. PATCH v2..PATCH v3: - removed redundant regmap_write() in imx_thermal_suspend() and imx_thermal_resume() (Bartlomiej) - removed unnecessary call to soc_dts_enable() (now called indirectly from thermal_zone_device_register()->set_mode()) (Bartlomiej) - removed defensive-style checks for non-existent enum values in thermal_zone_device_set_mode() (Bartlomiej) - change mode only if driver's set_mode() succeeded in thermal_zone_device_set_mode() (Bartlomiej) - don't set tz->need_update in thermal_zone_device_register() - this was supposed to be part of PATCH v1, but was omitted (Bartlomiej) PATCH..PATCH v2: - fixed typo (missing semicolon in dummy thermal_zone_device_set_mode() implementation) (kbuild test robot) - fixed misspelled enum value in int3400_thermal_params.initial_mode RFCv3..this PATCH: - export thermal_zone_device_{enable|disable}() for drivers (Bartlomiej) - don't check provided enum values in acpi's thermal_zet_mode() and in int3400_thermal_set_mode() (Bartlomiej) - use thermal_zone_device_enable() in of_thermal instead of open coding it (Bartlomiej) - use thermal_zone_device_{enable|disable}() in hisi_thermal, rockchip_thermal and sprd_thermal (Bartlomiej) - assume THERMAL_DEVICE_ENABLED is thermal_zone_params not provided at tzd's register time (Bartlomiej) - eliminated tzp-s which contain only .initial_mode = THERMAL_DEVICE_ENABLED, (Bartlomiej) - don't set tz->need_update and don't call thermal_zone_device_update() at the end of thermal_zone_device_register() (Bartlomiej) - used .initial_mode in int340x_thermal_zone, x86_pkg_temp_thermal and int3400_thermal (Bartlomiej) Andrzej Pietrasiewicz (2): thermal: core: Let thermal zone device's mode be stored in its struct thermal: core: Stop polling DISABLED thermal devices drivers/acpi/thermal.c | 35 ++-------- .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ------------ drivers/platform/x86/acerhdf.c | 17 +---- drivers/thermal/da9062-thermal.c | 11 ---- drivers/thermal/hisi_thermal.c | 6 +- drivers/thermal/imx_thermal.c | 36 ++-------- .../intel/int340x_thermal/int3400_thermal.c | 31 ++------- .../int340x_thermal/int340x_thermal_zone.c | 1 + .../thermal/intel/intel_quark_dts_thermal.c | 30 ++------- drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/thermal/of-thermal.c | 24 +------ drivers/thermal/rockchip_thermal.c | 6 +- drivers/thermal/sprd_thermal.c | 6 +- drivers/thermal/thermal_core.c | 65 +++++++++++++++---- drivers/thermal/thermal_core.h | 3 + drivers/thermal/thermal_sysfs.c | 29 +-------- include/linux/thermal.h | 22 ++++++- 17 files changed, 119 insertions(+), 246 deletions(-) base-commit: 79799562bf087b30d9dd0fddf5bed2d3b038be08 -- 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-23 16:57 ` [PATCH v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz @ 2020-04-23 16:57 ` Andrzej Pietrasiewicz 2020-05-04 7:00 ` Bartlomiej Zolnierkiewicz 2020-04-23 16:57 ` [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-23 16:57 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Thermal zone devices' mode is stored in individual drivers. This patch changes it so that mode is stored in struct thermal_zone_device instead. As a result all driver-specific variables storing the mode are not needed and are removed. Consequently, the get_mode() implementations have nothing to operate on and need to be removed, too. Some thermal framework functions are introduced: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_enable() thermal_zone_device_disable() thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock and the "set" calls driver's set_mode() if provided, so the latter must not take this lock again. At the end of the "set" thermal_zone_device_update() is called so drivers don't need to repeat this invocation in their specific set_mode() implementations. struct thermal_zone_params gains a new member called initial_mode, which is used to set tzd's mode at registration time and if tzp is not provided to thermal_zone_device_register() then it is assumed that the initial mode is THERMAL_DEVICE_ENABLED. The sysfs "mode" attribute is always exposed from now on, because all thermal zone devices now have their get_mode() implemented at the generic level and it is always available. Exposing "mode" doesn't hurt the drivers which don't provide their own set_mode(), because writing to "mode" will result in -EPERM, as expected. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 35 ++----------- .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ---------------- drivers/platform/x86/acerhdf.c | 17 ++----- drivers/thermal/da9062-thermal.c | 11 ----- drivers/thermal/hisi_thermal.c | 6 ++- drivers/thermal/imx_thermal.c | 36 ++------------ .../intel/int340x_thermal/int3400_thermal.c | 31 ++---------- .../int340x_thermal/int340x_thermal_zone.c | 1 + .../thermal/intel/intel_quark_dts_thermal.c | 30 +++--------- drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/thermal/of-thermal.c | 24 +-------- drivers/thermal/rockchip_thermal.c | 6 ++- drivers/thermal/sprd_thermal.c | 6 ++- drivers/thermal/thermal_core.c | 49 +++++++++++++++---- drivers/thermal/thermal_core.h | 3 ++ drivers/thermal/thermal_sysfs.c | 29 ++--------- include/linux/thermal.h | 22 ++++++++- 17 files changed, 105 insertions(+), 244 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 19067a5e5293..d1f352ed5241 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -172,7 +172,6 @@ struct acpi_thermal { struct acpi_thermal_trips trips; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; - int tz_enabled; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; }; @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) { struct acpi_thermal *tz = data; - if (!tz->tz_enabled) + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) return; thermal_zone_device_update(tz->thermal_zone, @@ -526,25 +525,10 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) return 0; } -static int thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct acpi_thermal *tz = thermal->devdata; - - if (!tz) - return -EINVAL; - - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : - THERMAL_DEVICE_DISABLED; - - return 0; -} - static int thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct acpi_thermal *tz = thermal->devdata; - int enable; if (!tz) return -EINVAL; @@ -552,20 +536,14 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, /* * enable/disable thermal management from ACPI thermal driver */ - if (mode == THERMAL_DEVICE_ENABLED) - enable = 1; - else if (mode == THERMAL_DEVICE_DISABLED) { - enable = 0; + if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - } else - return -EINVAL; - if (enable != tz->tz_enabled) { - tz->tz_enabled = enable; + if (mode != thermal->mode) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", - tz->tz_enabled ? "Enable" : "Disable")); - acpi_thermal_check(tz); + mode == THERMAL_DEVICE_ENABLED ? + "Enable" : "Disable")); } return 0; } @@ -856,7 +834,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_mode = thermal_get_mode, .set_mode = thermal_set_mode, .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, @@ -913,8 +890,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->tz_enabled = 1; - dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index ce0a6837daa3..5d28384046da 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; int module; /* Module or gearbox number */ }; @@ -110,7 +109,6 @@ struct mlxsw_thermal { struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; - enum thermal_device_mode mode; struct mlxsw_thermal_module *tz_module_arr; u8 tz_module_num; struct mlxsw_thermal_module *tz_gearbox_arr; @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *mode = thermal->mode; - - return 0; -} - static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal *thermal = tzdev->devdata; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - thermal->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, - .get_mode = mlxsw_thermal_get_mode, .set_mode = mlxsw_thermal_set_mode, .get_temp = mlxsw_thermal_get_temp, .get_trip_type = mlxsw_thermal_get_trip_type, @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, return err; } -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, - enum thermal_device_mode *mode) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *mode = tz->mode; - - return 0; -} - static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, enum thermal_device_mode mode) { struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal *thermal = tz->parent; - mutex_lock(&tzdev->lock); - if (mode == THERMAL_DEVICE_ENABLED) tzdev->polling_delay = thermal->polling_delay; else tzdev->polling_delay = 0; - mutex_unlock(&tzdev->lock); - - tz->mode = mode; - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_module_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, - .get_mode = mlxsw_thermal_module_mode_get, .set_mode = mlxsw_thermal_module_mode_set, .get_temp = mlxsw_thermal_gearbox_temp_get, .get_trip_type = mlxsw_thermal_module_trip_type_get, @@ -765,7 +726,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) return err; } - module_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -881,7 +841,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -1050,7 +1009,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, if (err) goto err_unreg_modules_tzdev; - thermal->mode = THERMAL_DEVICE_ENABLED; *p_thermal = thermal; return 0; diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 8cc86f4e3ac1..aaf8b845be90 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode = 1; thz_dev->polling_delay = interval*1000; - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); pr_notice("kernel mode fan control ON\n"); } -static int acerhdf_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - if (verbose) - pr_notice("kernel mode fan control %d\n", kernelmode); - - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED - : THERMAL_DEVICE_DISABLED; - - return 0; -} - /* * set operation mode; * enabled: the thermal layer of the kernel takes care about @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, - .get_mode = acerhdf_get_mode, .set_mode = acerhdf_set_mode, .get_trip_type = acerhdf_get_trip_type, .get_trip_hyst = acerhdf_get_trip_hyst, @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, err_out: acerhdf_revert_to_bios_mode(); + thz_dev->mode = THERMAL_DEVICE_DISABLED; return -EINVAL; } @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; + acerhdf_zone_params.initial_mode = + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index c32709badeda..c3075d038095 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -49,7 +49,6 @@ struct da9062_thermal { struct da9062 *hw; struct delayed_work work; struct thermal_zone_device *zone; - enum thermal_device_mode mode; struct mutex lock; /* protection for da9062_thermal temperature */ int temperature; int irq; @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static int da9062_thermal_get_mode(struct thermal_zone_device *z, - enum thermal_device_mode *mode) -{ - struct da9062_thermal *thermal = z->devdata; - *mode = thermal->mode; - return 0; -} - static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, int trip, enum thermal_trip_type *type) @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, .get_trip_type = da9062_thermal_get_trip_type, .get_trip_temp = da9062_thermal_get_trip_temp, }; @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) thermal->config = match->data; thermal->hw = chip; - thermal->mode = THERMAL_DEVICE_ENABLED; thermal->dev = &pdev->dev; INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e761c9b42217..800d2388c440 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -197,7 +197,6 @@ struct imx_thermal_data { struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - enum thermal_device_mode mode; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_passive; @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - if (data->mode == THERMAL_DEVICE_ENABLED) { + if (tz->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); wait = !(val & soc_data->temp_valid_mask); @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) regmap_read(map, soc_data->temp_data, &val); - if (data->mode != THERMAL_DEVICE_ENABLED) { + if (tz->mode != THERMAL_DEVICE_ENABLED) { regmap_write(map, soc_data->sensor_ctrl + REG_CLR, soc_data->measure_temp_mask); regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } -static int imx_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct imx_thermal_data *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int imx_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } } - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .bind = imx_bind, .unbind = imx_unbind, .get_temp = imx_get_temp, - .get_mode = imx_get_mode, .set_mode = imx_set_mode, .get_trip_type = imx_get_trip_type, .get_trip_temp = imx_get_trip_temp, @@ -831,7 +816,6 @@ static int imx_thermal_probe(struct platform_device *pdev) data->socdata->measure_temp_mask); data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -873,19 +857,14 @@ static int imx_thermal_remove(struct platform_device *pdev) static int __maybe_unused imx_thermal_suspend(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; /* * Need to disable thermal sensor, otherwise, when thermal core * try to get temperature before thermal sensor resume, a wrong * temperature will be read as the thermal sensor is powered - * down. + * down. This is done in thermal_zone_device_disable(). */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->measure_temp_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->power_down_mask); - data->mode = THERMAL_DEVICE_DISABLED; + thermal_zone_device_disable(data->tz); clk_disable_unprepare(data->thermal_clk); return 0; @@ -894,18 +873,13 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) static int __maybe_unused imx_thermal_resume(struct device *dev) { struct imx_thermal_data *data = dev_get_drvdata(dev); - struct regmap *map = data->tempmon; int ret; ret = clk_prepare_enable(data->thermal_clk); if (ret) return ret; /* Enabled thermal sensor after resume */ - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, - data->socdata->power_down_mask); - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, - data->socdata->measure_temp_mask); - data->mode = THERMAL_DEVICE_ENABLED; + thermal_zone_device_enable(data->tz); return 0; } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index e802922a13cf..1751d4b103b1 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { struct int3400_thermal_priv { struct acpi_device *adev; struct thermal_zone_device *thermal; - int mode; int art_count; struct art *arts; int trt_count; @@ -230,54 +229,32 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, return 0; } -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, - enum thermal_device_mode *mode) -{ - struct int3400_thermal_priv *priv = thermal->devdata; - - if (!priv) - return -EINVAL; - - *mode = priv->mode; - - return 0; -} - static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode) { struct int3400_thermal_priv *priv = thermal->devdata; - bool enable; int result = 0; if (!priv) return -EINVAL; - if (mode == THERMAL_DEVICE_ENABLED) - enable = true; - else if (mode == THERMAL_DEVICE_DISABLED) - enable = false; - else - return -EINVAL; - - if (enable != priv->mode) { - priv->mode = enable; + if (mode != thermal->mode) { result = int3400_thermal_run_osc(priv->adev->handle, - priv->current_uuid_index, - enable); + priv->current_uuid_index, + mode == THERMAL_DEVICE_ENABLED); } return result; } static struct thermal_zone_device_ops int3400_thermal_ops = { .get_temp = int3400_thermal_get_temp, - .get_mode = int3400_thermal_get_mode, .set_mode = int3400_thermal_set_mode, }; static struct thermal_zone_params int3400_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_DISABLED, }; static int int3400_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 432213272f1e..b36da9bfbf8a 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -208,6 +208,7 @@ EXPORT_SYMBOL_GPL(int340x_thermal_read_trips); static struct thermal_zone_params int340x_thermal_params = { .governor_name = "user_space", .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index d704fc104cfd..02dabd93f607 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -103,7 +103,6 @@ struct soc_sensor_entry { bool locked; u32 store_ptps; u32 store_dts_enable; - enum thermal_device_mode mode; struct thermal_zone_device *tzone; }; @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) return ret; if (out & QRK_DTS_ENABLE_BIT) { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; return 0; } @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; } else { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; pr_info("DTS is locked. Cannot enable DTS\n"); ret = -EPERM; } @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; if (!(out & QRK_DTS_ENABLE_BIT)) { - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; return 0; } @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) if (ret) return ret; - aux_entry->mode = THERMAL_DEVICE_DISABLED; + tzd->mode = THERMAL_DEVICE_DISABLED; } else { - aux_entry->mode = THERMAL_DEVICE_ENABLED; + tzd->mode = THERMAL_DEVICE_ENABLED; pr_info("DTS is locked. Cannot disable DTS\n"); ret = -EPERM; } @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, return 0; } -static int sys_get_mode(struct thermal_zone_device *tzd, - enum thermal_device_mode *mode) -{ - struct soc_sensor_entry *aux_entry = tzd->devdata; - *mode = aux_entry->mode; - return 0; -} - static int sys_set_mode(struct thermal_zone_device *tzd, enum thermal_device_mode mode) { @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, .get_crit_temp = sys_get_crit_temp, - .get_mode = sys_get_mode, .set_mode = sys_set_mode, }; @@ -414,16 +404,8 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } - mutex_lock(&dts_update_mutex); - err = soc_dts_enable(aux_entry->tzone); - mutex_unlock(&dts_update_mutex); - if (err) - goto err_aux_status; - return aux_entry; -err_aux_status: - thermal_zone_device_unregister(aux_entry->tzone); err_ret: kfree(aux_entry); return ERR_PTR(err); diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index a006b9fd1d72..cb810a02aab0 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -56,6 +56,7 @@ struct zone_device { static struct thermal_zone_params pkg_temp_tz_params = { .no_hwmon = true, + .initial_mode = THERMAL_DEVICE_ENABLED, }; /* Keep track of how many zone pointers we allocated in init() */ diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 874a47d6923f..48787a5576d8 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -51,7 +51,6 @@ struct __thermal_bind_params { /** * struct __thermal_zone - internal representation of a thermal zone - * @mode: current thermal zone device mode (enabled/disabled) * @passive_delay: polling interval while passive cooling is activated * @polling_delay: zone polling interval * @slope: slope of the temperature adjustment curve @@ -65,7 +64,6 @@ struct __thermal_bind_params { */ struct __thermal_zone { - enum thermal_device_mode mode; int passive_delay; int polling_delay; int slope; @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, return 0; } -static int of_thermal_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - struct __thermal_zone *data = tz->devdata; - - *mode = data->mode; - - return 0; -} - static int of_thermal_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { struct __thermal_zone *data = tz->devdata; - mutex_lock(&tz->lock); - if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = data->polling_delay; tz->passive_delay = data->passive_delay; @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, tz->passive_delay = 0; } - mutex_unlock(&tz->lock); - - data->mode = mode; - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - return 0; } @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, } static struct thermal_zone_device_ops of_thermal_ops = { - .get_mode = of_thermal_get_mode, .set_mode = of_thermal_set_mode, .get_trip_type = of_thermal_get_trip_type, @@ -554,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); if (!IS_ERR(tzd)) - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); + thermal_zone_device_enable(tzd); of_node_put(child); goto exit; @@ -979,7 +959,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) finish: of_node_put(child); - tz->mode = THERMAL_DEVICE_DISABLED; return tz; @@ -1120,6 +1099,7 @@ int __init of_parse_thermal_zones(void) /* these two are left for temperature drivers to use */ tzp->slope = tz->slope; tzp->offset = tz->offset; + tzp->initial_mode = THERMAL_DEVICE_DISABLED; zone = thermal_zone_device_register(child->name, tz->ntrips, mask, tz, diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) { struct thermal_zone_device *tzd = sensor->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) { struct thermal_zone_device *tzd = sen->tzd; - tzd->ops->set_mode(tzd, - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); + if (on) + thermal_zone_device_enable(tzd); + else + thermal_zone_device_disable(tzd); } static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c06550930979..a2a5034f76e7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -463,6 +463,41 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode; + + mutex_lock(&tz->lock); + + mode = tz->mode; + + mutex_unlock(&tz->lock); + + return mode; +} + +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + if (!ret) + tz->mode = mode; + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { @@ -1236,6 +1271,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, int result; int count; struct thermal_governor *governor; + enum thermal_device_mode mode; if (!type || strlen(type) == 0) { pr_err("Error: No thermal zone type defined\n"); @@ -1290,9 +1326,6 @@ thermal_zone_device_register(const char *type, int trips, int mask, if (result) goto remove_id; - /* A new thermal zone needs to be updated anyway. */ - atomic_set(&tz->need_update, 1); - dev_set_name(&tz->device, "thermal_zone%d", tz->id); result = device_register(&tz->device); if (result) @@ -1340,9 +1373,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); thermal_zone_device_reset(tz); - /* Update the new thermal zone and mark it as already updated. */ - if (atomic_cmpxchg(&tz->need_update, 1, 0)) - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; + thermal_zone_device_set_mode(tz, mode); return tz; @@ -1473,9 +1506,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); + tz_mode = thermal_zone_device_get_mode(tz); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index c95689586e19..ff5519adb68a 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -141,6 +141,9 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, unsigned long new_state) {} #endif /* CONFIG_THERMAL_STATISTICS */ +enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz); + /* device tree support */ #ifdef CONFIG_THERMAL_OF int of_parse_thermal_zones(void); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..cbb27b3c96d2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); enum thermal_device_mode mode; - int result; - - if (!tz->ops->get_mode) - return -EPERM; - result = tz->ops->get_mode(tz, &mode); - if (result) - return result; + mode = thermal_zone_device_get_mode(tz); return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" : "disabled"); @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + result = thermal_zone_device_disable(tz); else result = -EINVAL; @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 216185bb3014..c789d4ff6e63 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, @@ -128,6 +126,7 @@ struct thermal_cooling_device { * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature * @trip_type_attrs: attributes for trip points for sysfs: trip type * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis + * @mode: current mode of this thermal zone * @devdata: private pointer for device private data * @trips: number of trip points the thermal zone supports * @trips_disabled; bitmap for disabled trips @@ -170,6 +169,7 @@ struct thermal_zone_device { struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; + enum thermal_device_mode mode; void *devdata; int trips; unsigned long trips_disabled; /* bitmap for disabled trips */ @@ -264,6 +264,9 @@ struct thermal_zone_params { int num_tbps; /* Number of tbp entries */ struct thermal_bind_params *tbp; + /* Initial mode of this thermal zone device */ + enum thermal_device_mode initial_mode; + /* * Sustainable power (heat) that this thermal zone can dissipate in * mW @@ -395,6 +398,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); @@ -426,6 +431,9 @@ static inline struct thermal_zone_device *thermal_zone_device_register( static inline void thermal_zone_device_unregister( struct thermal_zone_device *tz) { } +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ return -EINVAL; } static inline struct thermal_cooling_device * thermal_cooling_device_register(char *type, void *devdata, const struct thermal_cooling_device_ops *ops) @@ -465,4 +473,14 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { } #endif /* CONFIG_THERMAL */ +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} + +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} + #endif /* __THERMAL_H__ */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-23 16:57 ` [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-05-04 7:00 ` Bartlomiej Zolnierkiewicz 0 siblings, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-05-04 7:00 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel On 4/23/20 6:57 PM, Andrzej Pietrasiewicz wrote: > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > struct thermal_zone_params gains a new member called initial_mode, which > is used to set tzd's mode at registration time and if tzp is not provided > to thermal_zone_device_register() then it is assumed that the initial > mode is THERMAL_DEVICE_ENABLED. > > The sysfs "mode" attribute is always exposed from now on, because all > thermal zone devices now have their get_mode() implemented at the generic > level and it is always available. Exposing "mode" doesn't hurt the drivers > which don't provide their own set_mode(), because writing to "mode" will > result in -EPERM, as expected. > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics > --- > drivers/acpi/thermal.c | 35 ++----------- > .../ethernet/mellanox/mlxsw/core_thermal.c | 42 ---------------- > drivers/platform/x86/acerhdf.c | 17 ++----- > drivers/thermal/da9062-thermal.c | 11 ----- > drivers/thermal/hisi_thermal.c | 6 ++- > drivers/thermal/imx_thermal.c | 36 ++------------ > .../intel/int340x_thermal/int3400_thermal.c | 31 ++---------- > .../int340x_thermal/int340x_thermal_zone.c | 1 + > .../thermal/intel/intel_quark_dts_thermal.c | 30 +++--------- > drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + > drivers/thermal/of-thermal.c | 24 +-------- > drivers/thermal/rockchip_thermal.c | 6 ++- > drivers/thermal/sprd_thermal.c | 6 ++- > drivers/thermal/thermal_core.c | 49 +++++++++++++++---- > drivers/thermal/thermal_core.h | 3 ++ > drivers/thermal/thermal_sysfs.c | 29 ++--------- > include/linux/thermal.h | 22 ++++++++- > 17 files changed, 105 insertions(+), 244 deletions(-) > > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c > index 19067a5e5293..d1f352ed5241 100644 > --- a/drivers/acpi/thermal.c > +++ b/drivers/acpi/thermal.c > @@ -172,7 +172,6 @@ struct acpi_thermal { > struct acpi_thermal_trips trips; > struct acpi_handle_list devices; > struct thermal_zone_device *thermal_zone; > - int tz_enabled; > int kelvin_offset; /* in millidegrees */ > struct work_struct thermal_check_work; > }; > @@ -500,7 +499,7 @@ static void acpi_thermal_check(void *data) > { > struct acpi_thermal *tz = data; > > - if (!tz->tz_enabled) > + if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) > return; > > thermal_zone_device_update(tz->thermal_zone, > @@ -526,25 +525,10 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) > return 0; > } > > -static int thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct acpi_thermal *tz = thermal->devdata; > - > - if (!tz) > - return -EINVAL; > - > - *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : > - THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > static int thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct acpi_thermal *tz = thermal->devdata; > - int enable; > > if (!tz) > return -EINVAL; > @@ -552,20 +536,14 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, > /* > * enable/disable thermal management from ACPI thermal driver > */ > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = 1; > - else if (mode == THERMAL_DEVICE_DISABLED) { > - enable = 0; > + if (mode == THERMAL_DEVICE_DISABLED) > pr_warn("thermal zone will be disabled\n"); > - } else > - return -EINVAL; > > - if (enable != tz->tz_enabled) { > - tz->tz_enabled = enable; > + if (mode != thermal->mode) { > ACPI_DEBUG_PRINT((ACPI_DB_INFO, > "%s kernel ACPI thermal control\n", > - tz->tz_enabled ? "Enable" : "Disable")); > - acpi_thermal_check(tz); > + mode == THERMAL_DEVICE_ENABLED ? > + "Enable" : "Disable")); > } > return 0; > } > @@ -856,7 +834,6 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { > .bind = acpi_thermal_bind_cooling_device, > .unbind = acpi_thermal_unbind_cooling_device, > .get_temp = thermal_get_temp, > - .get_mode = thermal_get_mode, > .set_mode = thermal_set_mode, > .get_trip_type = thermal_get_trip_type, > .get_trip_temp = thermal_get_trip_temp, > @@ -913,8 +890,6 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) > if (ACPI_FAILURE(status)) > return -ENODEV; > > - tz->tz_enabled = 1; > - > dev_info(&tz->device->dev, "registered as thermal_zone%d\n", > tz->thermal_zone->id); > return 0; > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > index ce0a6837daa3..5d28384046da 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c > @@ -98,7 +98,6 @@ struct mlxsw_thermal_module { > struct mlxsw_thermal *parent; > struct thermal_zone_device *tzdev; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > int module; /* Module or gearbox number */ > }; > > @@ -110,7 +109,6 @@ struct mlxsw_thermal { > struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; > u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; > struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; > - enum thermal_device_mode mode; > struct mlxsw_thermal_module *tz_module_arr; > u8 tz_module_num; > struct mlxsw_thermal_module *tz_gearbox_arr; > @@ -277,33 +275,16 @@ static int mlxsw_thermal_unbind(struct thermal_zone_device *tzdev, > return 0; > } > > -static int mlxsw_thermal_get_mode(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal *thermal = tzdev->devdata; > - > - *mode = thermal->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal *thermal = tzdev->devdata; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - thermal->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -407,7 +388,6 @@ static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_ops = { > .bind = mlxsw_thermal_bind, > .unbind = mlxsw_thermal_unbind, > - .get_mode = mlxsw_thermal_get_mode, > .set_mode = mlxsw_thermal_set_mode, > .get_temp = mlxsw_thermal_get_temp, > .get_trip_type = mlxsw_thermal_get_trip_type, > @@ -466,34 +446,17 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, > return err; > } > > -static int mlxsw_thermal_module_mode_get(struct thermal_zone_device *tzdev, > - enum thermal_device_mode *mode) > -{ > - struct mlxsw_thermal_module *tz = tzdev->devdata; > - > - *mode = tz->mode; > - > - return 0; > -} > - > static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, > enum thermal_device_mode mode) > { > struct mlxsw_thermal_module *tz = tzdev->devdata; > struct mlxsw_thermal *thermal = tz->parent; > > - mutex_lock(&tzdev->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) > tzdev->polling_delay = thermal->polling_delay; > else > tzdev->polling_delay = 0; > > - mutex_unlock(&tzdev->lock); > - > - tz->mode = mode; > - thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -596,7 +559,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, > static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_module_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -635,7 +597,6 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, > static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { > .bind = mlxsw_thermal_module_bind, > .unbind = mlxsw_thermal_module_unbind, > - .get_mode = mlxsw_thermal_module_mode_get, > .set_mode = mlxsw_thermal_module_mode_set, > .get_temp = mlxsw_thermal_gearbox_temp_get, > .get_trip_type = mlxsw_thermal_module_trip_type_get, > @@ -765,7 +726,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) > return err; > } > > - module_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -881,7 +841,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) > if (IS_ERR(gearbox_tz->tzdev)) > return PTR_ERR(gearbox_tz->tzdev); > > - gearbox_tz->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -1050,7 +1009,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core, > if (err) > goto err_unreg_modules_tzdev; > > - thermal->mode = THERMAL_DEVICE_ENABLED; > *p_thermal = thermal; > return 0; > > diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c > index 8cc86f4e3ac1..aaf8b845be90 100644 > --- a/drivers/platform/x86/acerhdf.c > +++ b/drivers/platform/x86/acerhdf.c > @@ -406,22 +406,9 @@ static inline void acerhdf_enable_kernelmode(void) > kernelmode = 1; > > thz_dev->polling_delay = interval*1000; > - thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED); > pr_notice("kernel mode fan control ON\n"); > } > > -static int acerhdf_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - if (verbose) > - pr_notice("kernel mode fan control %d\n", kernelmode); > - > - *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED > - : THERMAL_DEVICE_DISABLED; > - > - return 0; > -} > - > /* > * set operation mode; > * enabled: the thermal layer of the kernel takes care about > @@ -488,7 +475,6 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { > .bind = acerhdf_bind, > .unbind = acerhdf_unbind, > .get_temp = acerhdf_get_ec_temp, > - .get_mode = acerhdf_get_mode, > .set_mode = acerhdf_set_mode, > .get_trip_type = acerhdf_get_trip_type, > .get_trip_hyst = acerhdf_get_trip_hyst, > @@ -554,6 +540,7 @@ static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, > > err_out: > acerhdf_revert_to_bios_mode(); > + thz_dev->mode = THERMAL_DEVICE_DISABLED; > return -EINVAL; > } > > @@ -739,6 +726,8 @@ static int __init acerhdf_register_thermal(void) > if (IS_ERR(cl_dev)) > return -EINVAL; > > + acerhdf_zone_params.initial_mode = > + kernelmode ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; > thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, > &acerhdf_dev_ops, > &acerhdf_zone_params, 0, > diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c > index c32709badeda..c3075d038095 100644 > --- a/drivers/thermal/da9062-thermal.c > +++ b/drivers/thermal/da9062-thermal.c > @@ -49,7 +49,6 @@ struct da9062_thermal { > struct da9062 *hw; > struct delayed_work work; > struct thermal_zone_device *zone; > - enum thermal_device_mode mode; > struct mutex lock; /* protection for da9062_thermal temperature */ > int temperature; > int irq; > @@ -121,14 +120,6 @@ static irqreturn_t da9062_thermal_irq_handler(int irq, void *data) > return IRQ_HANDLED; > } > > -static int da9062_thermal_get_mode(struct thermal_zone_device *z, > - enum thermal_device_mode *mode) > -{ > - struct da9062_thermal *thermal = z->devdata; > - *mode = thermal->mode; > - return 0; > -} > - > static int da9062_thermal_get_trip_type(struct thermal_zone_device *z, > int trip, > enum thermal_trip_type *type) > @@ -181,7 +172,6 @@ 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_mode = da9062_thermal_get_mode, > .get_trip_type = da9062_thermal_get_trip_type, > .get_trip_temp = da9062_thermal_get_trip_temp, > }; > @@ -233,7 +223,6 @@ static int da9062_thermal_probe(struct platform_device *pdev) > > thermal->config = match->data; > thermal->hw = chip; > - thermal->mode = THERMAL_DEVICE_ENABLED; > thermal->dev = &pdev->dev; > > INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); > diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c > index 2d26ae80e202..ee05950afd2f 100644 > --- a/drivers/thermal/hisi_thermal.c > +++ b/drivers/thermal/hisi_thermal.c > @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, > { > struct thermal_zone_device *tzd = sensor->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static int hisi_thermal_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index e761c9b42217..800d2388c440 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -197,7 +197,6 @@ struct imx_thermal_data { > struct cpufreq_policy *policy; > struct thermal_zone_device *tz; > struct thermal_cooling_device *cdev; > - enum thermal_device_mode mode; > struct regmap *tempmon; > u32 c1, c2; /* See formula in imx_init_calib() */ > int temp_passive; > @@ -256,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > bool wait; > u32 val; > > - if (data->mode == THERMAL_DEVICE_ENABLED) { > + if (tz->mode == THERMAL_DEVICE_ENABLED) { > /* Check if a measurement is currently in progress */ > regmap_read(map, soc_data->temp_data, &val); > wait = !(val & soc_data->temp_valid_mask); > @@ -283,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > > regmap_read(map, soc_data->temp_data, &val); > > - if (data->mode != THERMAL_DEVICE_ENABLED) { > + if (tz->mode != THERMAL_DEVICE_ENABLED) { > regmap_write(map, soc_data->sensor_ctrl + REG_CLR, > soc_data->measure_temp_mask); > regmap_write(map, soc_data->sensor_ctrl + REG_SET, > @@ -331,16 +330,6 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) > return 0; > } > > -static int imx_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct imx_thermal_data *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int imx_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > @@ -376,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, > } > } > > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -467,7 +453,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { > .bind = imx_bind, > .unbind = imx_unbind, > .get_temp = imx_get_temp, > - .get_mode = imx_get_mode, > .set_mode = imx_set_mode, > .get_trip_type = imx_get_trip_type, > .get_trip_temp = imx_get_trip_temp, > @@ -831,7 +816,6 @@ static int imx_thermal_probe(struct platform_device *pdev) > data->socdata->measure_temp_mask); > > data->irq_enabled = true; > - data->mode = THERMAL_DEVICE_ENABLED; > > ret = devm_request_threaded_irq(&pdev->dev, data->irq, > imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, > @@ -873,19 +857,14 @@ static int imx_thermal_remove(struct platform_device *pdev) > static int __maybe_unused imx_thermal_suspend(struct device *dev) > { > struct imx_thermal_data *data = dev_get_drvdata(dev); > - struct regmap *map = data->tempmon; > > /* > * Need to disable thermal sensor, otherwise, when thermal core > * try to get temperature before thermal sensor resume, a wrong > * temperature will be read as the thermal sensor is powered > - * down. > + * down. This is done in thermal_zone_device_disable(). > */ > - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, > - data->socdata->measure_temp_mask); > - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > - data->socdata->power_down_mask); > - data->mode = THERMAL_DEVICE_DISABLED; > + thermal_zone_device_disable(data->tz); > clk_disable_unprepare(data->thermal_clk); > > return 0; > @@ -894,18 +873,13 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) > static int __maybe_unused imx_thermal_resume(struct device *dev) > { > struct imx_thermal_data *data = dev_get_drvdata(dev); > - struct regmap *map = data->tempmon; > int ret; > > ret = clk_prepare_enable(data->thermal_clk); > if (ret) > return ret; > /* Enabled thermal sensor after resume */ > - regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, > - data->socdata->power_down_mask); > - regmap_write(map, data->socdata->sensor_ctrl + REG_SET, > - data->socdata->measure_temp_mask); > - data->mode = THERMAL_DEVICE_ENABLED; > + thermal_zone_device_enable(data->tz); > > return 0; > } > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index e802922a13cf..1751d4b103b1 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -44,7 +44,6 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { > struct int3400_thermal_priv { > struct acpi_device *adev; > struct thermal_zone_device *thermal; > - int mode; > int art_count; > struct art *arts; > int trt_count; > @@ -230,54 +229,32 @@ static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, > return 0; > } > > -static int int3400_thermal_get_mode(struct thermal_zone_device *thermal, > - enum thermal_device_mode *mode) > -{ > - struct int3400_thermal_priv *priv = thermal->devdata; > - > - if (!priv) > - return -EINVAL; > - > - *mode = priv->mode; > - > - return 0; > -} > - > static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, > enum thermal_device_mode mode) > { > struct int3400_thermal_priv *priv = thermal->devdata; > - bool enable; > int result = 0; > > if (!priv) > return -EINVAL; > > - if (mode == THERMAL_DEVICE_ENABLED) > - enable = true; > - else if (mode == THERMAL_DEVICE_DISABLED) > - enable = false; > - else > - return -EINVAL; > - > - if (enable != priv->mode) { > - priv->mode = enable; > + if (mode != thermal->mode) { > result = int3400_thermal_run_osc(priv->adev->handle, > - priv->current_uuid_index, > - enable); > + priv->current_uuid_index, > + mode == THERMAL_DEVICE_ENABLED); > } > return result; > } > > static struct thermal_zone_device_ops int3400_thermal_ops = { > .get_temp = int3400_thermal_get_temp, > - .get_mode = int3400_thermal_get_mode, > .set_mode = int3400_thermal_set_mode, > }; > > static struct thermal_zone_params int3400_thermal_params = { > .governor_name = "user_space", > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_DISABLED, > }; > > static int int3400_thermal_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > index 432213272f1e..b36da9bfbf8a 100644 > --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c > @@ -208,6 +208,7 @@ EXPORT_SYMBOL_GPL(int340x_thermal_read_trips); > static struct thermal_zone_params int340x_thermal_params = { > .governor_name = "user_space", > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_ENABLED, > }; > > struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, > diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c > index d704fc104cfd..02dabd93f607 100644 > --- a/drivers/thermal/intel/intel_quark_dts_thermal.c > +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c > @@ -103,7 +103,6 @@ struct soc_sensor_entry { > bool locked; > u32 store_ptps; > u32 store_dts_enable; > - enum thermal_device_mode mode; > struct thermal_zone_device *tzone; > }; > > @@ -128,7 +127,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > return ret; > > if (out & QRK_DTS_ENABLE_BIT) { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > return 0; > } > > @@ -139,9 +138,9 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > pr_info("DTS is locked. Cannot enable DTS\n"); > ret = -EPERM; > } > @@ -161,7 +160,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > return ret; > > if (!(out & QRK_DTS_ENABLE_BIT)) { > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > return 0; > } > > @@ -173,9 +172,9 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) > if (ret) > return ret; > > - aux_entry->mode = THERMAL_DEVICE_DISABLED; > + tzd->mode = THERMAL_DEVICE_DISABLED; > } else { > - aux_entry->mode = THERMAL_DEVICE_ENABLED; > + tzd->mode = THERMAL_DEVICE_ENABLED; > pr_info("DTS is locked. Cannot disable DTS\n"); > ret = -EPERM; > } > @@ -309,14 +308,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, > return 0; > } > > -static int sys_get_mode(struct thermal_zone_device *tzd, > - enum thermal_device_mode *mode) > -{ > - struct soc_sensor_entry *aux_entry = tzd->devdata; > - *mode = aux_entry->mode; > - return 0; > -} > - > static int sys_set_mode(struct thermal_zone_device *tzd, > enum thermal_device_mode mode) > { > @@ -338,7 +329,6 @@ static struct thermal_zone_device_ops tzone_ops = { > .get_trip_type = sys_get_trip_type, > .set_trip_temp = sys_set_trip_temp, > .get_crit_temp = sys_get_crit_temp, > - .get_mode = sys_get_mode, > .set_mode = sys_set_mode, > }; > > @@ -414,16 +404,8 @@ static struct soc_sensor_entry *alloc_soc_dts(void) > goto err_ret; > } > > - mutex_lock(&dts_update_mutex); > - err = soc_dts_enable(aux_entry->tzone); > - mutex_unlock(&dts_update_mutex); > - if (err) > - goto err_aux_status; > - > return aux_entry; > > -err_aux_status: > - thermal_zone_device_unregister(aux_entry->tzone); > err_ret: > kfree(aux_entry); > return ERR_PTR(err); > diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c > index a006b9fd1d72..cb810a02aab0 100644 > --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c > +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c > @@ -56,6 +56,7 @@ struct zone_device { > > static struct thermal_zone_params pkg_temp_tz_params = { > .no_hwmon = true, > + .initial_mode = THERMAL_DEVICE_ENABLED, > }; > > /* Keep track of how many zone pointers we allocated in init() */ > diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c > index 874a47d6923f..48787a5576d8 100644 > --- a/drivers/thermal/of-thermal.c > +++ b/drivers/thermal/of-thermal.c > @@ -51,7 +51,6 @@ struct __thermal_bind_params { > > /** > * struct __thermal_zone - internal representation of a thermal zone > - * @mode: current thermal zone device mode (enabled/disabled) > * @passive_delay: polling interval while passive cooling is activated > * @polling_delay: zone polling interval > * @slope: slope of the temperature adjustment curve > @@ -65,7 +64,6 @@ struct __thermal_bind_params { > */ > > struct __thermal_zone { > - enum thermal_device_mode mode; > int passive_delay; > int polling_delay; > int slope; > @@ -269,23 +267,11 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, > return 0; > } > > -static int of_thermal_get_mode(struct thermal_zone_device *tz, > - enum thermal_device_mode *mode) > -{ > - struct __thermal_zone *data = tz->devdata; > - > - *mode = data->mode; > - > - return 0; > -} > - > static int of_thermal_set_mode(struct thermal_zone_device *tz, > enum thermal_device_mode mode) > { > struct __thermal_zone *data = tz->devdata; > > - mutex_lock(&tz->lock); > - > if (mode == THERMAL_DEVICE_ENABLED) { > tz->polling_delay = data->polling_delay; > tz->passive_delay = data->passive_delay; > @@ -294,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, > tz->passive_delay = 0; > } > > - mutex_unlock(&tz->lock); > - > - data->mode = mode; > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > - > return 0; > } > > @@ -393,7 +374,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, > } > > static struct thermal_zone_device_ops of_thermal_ops = { > - .get_mode = of_thermal_get_mode, > .set_mode = of_thermal_set_mode, > > .get_trip_type = of_thermal_get_trip_type, > @@ -554,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, > tzd = thermal_zone_of_add_sensor(child, sensor_np, > data, ops); > if (!IS_ERR(tzd)) > - tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); > + thermal_zone_device_enable(tzd); > > of_node_put(child); > goto exit; > @@ -979,7 +959,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) > > finish: > of_node_put(child); > - tz->mode = THERMAL_DEVICE_DISABLED; > > return tz; > > @@ -1120,6 +1099,7 @@ int __init of_parse_thermal_zones(void) > /* these two are left for temperature drivers to use */ > tzp->slope = tz->slope; > tzp->offset = tz->offset; > + tzp->initial_mode = THERMAL_DEVICE_DISABLED; > > zone = thermal_zone_device_register(child->name, tz->ntrips, > mask, tz, > diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c > index 15a71ecc916c..aa9e0e31ef98 100644 > --- a/drivers/thermal/rockchip_thermal.c > +++ b/drivers/thermal/rockchip_thermal.c > @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) > { > struct thermal_zone_device *tzd = sensor->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) > diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c > index a340374e8c51..58f995b0f804 100644 > --- a/drivers/thermal/sprd_thermal.c > +++ b/drivers/thermal/sprd_thermal.c > @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) > { > struct thermal_zone_device *tzd = sen->tzd; > > - tzd->ops->set_mode(tzd, > - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); > + if (on) > + thermal_zone_device_enable(tzd); > + else > + thermal_zone_device_disable(tzd); > } > > static int sprd_thm_probe(struct platform_device *pdev) > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index c06550930979..a2a5034f76e7 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -463,6 +463,41 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) > thermal_zone_device_init(tz); > } > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz) > +{ > + enum thermal_device_mode mode; > + > + mutex_lock(&tz->lock); > + > + mode = tz->mode; > + > + mutex_unlock(&tz->lock); > + > + return mode; > +} > + > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ > + int ret = 0; > + > + mutex_lock(&tz->lock); > + > + if (tz->ops->set_mode) > + ret = tz->ops->set_mode(tz, mode); > + > + if (!ret) > + tz->mode = mode; > + > + mutex_unlock(&tz->lock); > + > + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); > + > void thermal_zone_device_update(struct thermal_zone_device *tz, > enum thermal_notify_event event) > { > @@ -1236,6 +1271,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, > int result; > int count; > struct thermal_governor *governor; > + enum thermal_device_mode mode; > > if (!type || strlen(type) == 0) { > pr_err("Error: No thermal zone type defined\n"); > @@ -1290,9 +1326,6 @@ thermal_zone_device_register(const char *type, int trips, int mask, > if (result) > goto remove_id; > > - /* A new thermal zone needs to be updated anyway. */ > - atomic_set(&tz->need_update, 1); > - > dev_set_name(&tz->device, "thermal_zone%d", tz->id); > result = device_register(&tz->device); > if (result) > @@ -1340,9 +1373,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, > INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); > > thermal_zone_device_reset(tz); > - /* Update the new thermal zone and mark it as already updated. */ > - if (atomic_cmpxchg(&tz->need_update, 1, 0)) > - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); > + > + mode = tzp ? tzp->initial_mode : THERMAL_DEVICE_ENABLED; > + thermal_zone_device_set_mode(tz, mode); > > return tz; > > @@ -1473,9 +1506,7 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_SUSPEND: > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > - tz_mode = THERMAL_DEVICE_ENABLED; > - if (tz->ops->get_mode) > - tz->ops->get_mode(tz, &tz_mode); > + tz_mode = thermal_zone_device_get_mode(tz); > > if (tz_mode == THERMAL_DEVICE_DISABLED) > continue; > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index c95689586e19..ff5519adb68a 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -141,6 +141,9 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, > unsigned long new_state) {} > #endif /* CONFIG_THERMAL_STATISTICS */ > > +enum thermal_device_mode > +thermal_zone_device_get_mode(struct thermal_zone_device *tz); > + > /* device tree support */ > #ifdef CONFIG_THERMAL_OF > int of_parse_thermal_zones(void); > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb4dff7..cbb27b3c96d2 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -50,14 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) > { > struct thermal_zone_device *tz = to_thermal_zone(dev); > enum thermal_device_mode mode; > - int result; > - > - if (!tz->ops->get_mode) > - return -EPERM; > > - result = tz->ops->get_mode(tz, &mode); > - if (result) > - return result; > + mode = thermal_zone_device_get_mode(tz); > > return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" > : "disabled"); > @@ -74,9 +68,9 @@ mode_store(struct device *dev, struct device_attribute *attr, > return -EPERM; > > if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); > + result = thermal_zone_device_enable(tz); > else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) > - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); > + result = thermal_zone_device_disable(tz); > else > result = -EINVAL; > > @@ -428,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { > .attrs = thermal_zone_dev_attrs, > }; > > -/* We expose mode only if .get_mode is present */ > static struct attribute *thermal_zone_mode_attrs[] = { > &dev_attr_mode.attr, > NULL, > }; > > -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, > - struct attribute *attr, > - int attrno) > -{ > - struct device *dev = container_of(kobj, struct device, kobj); > - struct thermal_zone_device *tz; > - > - tz = container_of(dev, struct thermal_zone_device, device); > - > - if (tz->ops->get_mode) > - return attr->mode; > - > - return 0; > -} > - > static struct attribute_group thermal_zone_mode_attribute_group = { > .attrs = thermal_zone_mode_attrs, > - .is_visible = thermal_zone_mode_is_visible, > }; > > /* We expose passive only if passive trips are present */ > diff --git a/include/linux/thermal.h b/include/linux/thermal.h > index 216185bb3014..c789d4ff6e63 100644 > --- a/include/linux/thermal.h > +++ b/include/linux/thermal.h > @@ -76,8 +76,6 @@ struct thermal_zone_device_ops { > struct thermal_cooling_device *); > int (*get_temp) (struct thermal_zone_device *, int *); > int (*set_trips) (struct thermal_zone_device *, int, int); > - int (*get_mode) (struct thermal_zone_device *, > - enum thermal_device_mode *); > int (*set_mode) (struct thermal_zone_device *, > enum thermal_device_mode); > int (*get_trip_type) (struct thermal_zone_device *, int, > @@ -128,6 +126,7 @@ struct thermal_cooling_device { > * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature > * @trip_type_attrs: attributes for trip points for sysfs: trip type > * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis > + * @mode: current mode of this thermal zone > * @devdata: private pointer for device private data > * @trips: number of trip points the thermal zone supports > * @trips_disabled; bitmap for disabled trips > @@ -170,6 +169,7 @@ struct thermal_zone_device { > struct thermal_attr *trip_temp_attrs; > struct thermal_attr *trip_type_attrs; > struct thermal_attr *trip_hyst_attrs; > + enum thermal_device_mode mode; > void *devdata; > int trips; > unsigned long trips_disabled; /* bitmap for disabled trips */ > @@ -264,6 +264,9 @@ struct thermal_zone_params { > int num_tbps; /* Number of tbp entries */ > struct thermal_bind_params *tbp; > > + /* Initial mode of this thermal zone device */ > + enum thermal_device_mode initial_mode; > + > /* > * Sustainable power (heat) that this thermal zone can dissipate in > * mW > @@ -395,6 +398,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, > unsigned int); > int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, > struct thermal_cooling_device *); > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode); > void thermal_zone_device_update(struct thermal_zone_device *, > enum thermal_notify_event); > > @@ -426,6 +431,9 @@ static inline struct thermal_zone_device *thermal_zone_device_register( > static inline void thermal_zone_device_unregister( > struct thermal_zone_device *tz) > { } > +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, > + enum thermal_device_mode mode) > +{ return -EINVAL; } > static inline struct thermal_cooling_device * > thermal_cooling_device_register(char *type, void *devdata, > const struct thermal_cooling_device_ops *ops) > @@ -465,4 +473,14 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, > { } > #endif /* CONFIG_THERMAL */ > > +static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); > +} > + > +static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); > +} > + > #endif /* __THERMAL_H__ */ > ^ permalink raw reply [flat|nested] 137+ messages in thread
* [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-23 16:57 ` [PATCH v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-23 16:57 ` [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-23 16:57 ` Andrzej Pietrasiewicz 2020-04-24 9:03 ` Zhang, Rui 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-23 16:57 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a2a5034f76e7..03c4d8d23284 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,13 +305,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -503,6 +512,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-23 16:57 ` [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-04-24 9:03 ` Zhang, Rui 2020-04-27 14:20 ` Zhang, Rui 0 siblings, 1 reply; 137+ messages in thread From: Zhang, Rui @ 2020-04-24 9:03 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Heiko Stuebner, Orson Zhai, Baolin Wang, Chunyan Zhang, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz Hi, Andrzej, Thanks for the patches. My Linux laptop was broken and won't get fixed till next week, so I may lost some of the discussions previously. > -----Original Message----- > From: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > Sent: Friday, April 24, 2020 12:57 AM > To: linux-pm@vger.kernel.org > Cc: Zhang, Rui <rui.zhang@intel.com>; Rafael J . Wysocki > <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; Jiri Pirko > <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David S . > Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; Darren > Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; > Support Opensource <support.opensource@diasemi.com>; Daniel Lezcano > <daniel.lezcano@linaro.org>; Amit Kucheria > <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; > Sascha Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP > Linux Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; > Orson Zhai <orsonzhai@gmail.com>; Baolin Wang > <baolin.wang7@gmail.com>; Chunyan Zhang <zhang.lyra@gmail.com>; linux- > acpi@vger.kernel.org; netdev@vger.kernel.org; platform-driver- > x86@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > kernel@collabora.com; Andrzej Pietrasiewicz <andrzej.p@collabora.com>; > Barlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> > Subject: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices > Importance: High > > Polling DISABLED devices is not desired, as all such "disabled" devices are > meant to be handled by userspace. This patch introduces and uses > should_stop_polling() to decide whether the device should be polled or not. > Thanks for the fix, and IMO, this reveal some more problems. Say, we need to define "DISABLED" thermal zone. Can we read the temperature? Can we trust the trip point value? IMO, a disabled thermal zone does not mean it is handled by userspace, because that is what the userspace governor designed for. Instead, if a thermal zone is disabled, in thermal_zone_device_update(), we should basically skip all the other operations as well. I'll try your patches and probably make an incremental patch. Thanks, rui > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/thermal/thermal_core.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c > b/drivers/thermal/thermal_core.c index a2a5034f76e7..03c4d8d23284 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -305,13 +305,22 @@ static void thermal_zone_device_set_polling(struct > thermal_zone_device *tz, > cancel_delayed_work(&tz->poll_queue); > } > > +static inline bool should_stop_polling(struct thermal_zone_device *tz) > +{ > + return thermal_zone_device_get_mode(tz) == > THERMAL_DEVICE_DISABLED; } > + > static void monitor_thermal_zone(struct thermal_zone_device *tz) { > + bool stop; > + > + stop = should_stop_polling(tz); > + > mutex_lock(&tz->lock); > > - if (tz->passive) > + if (!stop && tz->passive) > thermal_zone_device_set_polling(tz, tz->passive_delay); > - else if (tz->polling_delay) > + else if (!stop && tz->polling_delay) > thermal_zone_device_set_polling(tz, tz->polling_delay); > else > thermal_zone_device_set_polling(tz, 0); @@ -503,6 +512,9 > @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { > int count; > > + if (should_stop_polling(tz)) > + return; > + > if (atomic_read(&in_suspend)) > return; > > -- > 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-24 9:03 ` Zhang, Rui @ 2020-04-27 14:20 ` Zhang, Rui 2020-04-27 18:34 ` Andrzej Pietrasiewicz 0 siblings, 1 reply; 137+ messages in thread From: Zhang, Rui @ 2020-04-27 14:20 UTC (permalink / raw) To: 'Andrzej Pietrasiewicz', 'linux-pm@vger.kernel.org' Cc: 'Rafael J . Wysocki', 'Len Brown', 'Jiri Pirko', 'Ido Schimmel', 'David S . Miller', 'Peter Kaestle', 'Darren Hart', 'Andy Shevchenko', 'Support Opensource', 'Daniel Lezcano', 'Amit Kucheria', 'Shawn Guo', 'Sascha Hauer', 'Pengutronix Kernel Team', 'Fabio Estevam', 'NXP Linux Team', 'Heiko Stuebner', 'Orson Zhai', 'Baolin Wang', 'Chunyan Zhang', 'linux-acpi@vger.kernel.org', 'netdev@vger.kernel.org', 'platform-driver-x86@vger.kernel.org', 'linux-arm-kernel@lists.infradead.org', 'kernel@collabora.com', 'Barlomiej Zolnierkiewicz' > -----Original Message----- > From: Zhang, Rui > Sent: Friday, April 24, 2020 5:03 PM > To: Andrzej Pietrasiewicz <andrzej.p@collabora.com>; linux- > pm@vger.kernel.org > Cc: Rafael J . Wysocki <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; > Jiri Pirko <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David > S . Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; Darren > Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; > Support Opensource <support.opensource@diasemi.com>; Daniel Lezcano > <daniel.lezcano@linaro.org>; Amit Kucheria > <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; > Sascha Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP > Linux Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; > Orson Zhai <orsonzhai@gmail.com>; Baolin Wang > <baolin.wang7@gmail.com>; Chunyan Zhang <zhang.lyra@gmail.com>; linux- > acpi@vger.kernel.org; netdev@vger.kernel.org; platform-driver- > x86@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > kernel@collabora.com; Barlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> > Subject: RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal > devices > > Hi, Andrzej, > > Thanks for the patches. My Linux laptop was broken and won't get fixed till > next week, so I may lost some of the discussions previously. > > > -----Original Message----- > > From: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > > Sent: Friday, April 24, 2020 12:57 AM > > To: linux-pm@vger.kernel.org > > Cc: Zhang, Rui <rui.zhang@intel.com>; Rafael J . Wysocki > > <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; Jiri Pirko > > <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David S . > > Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; Darren > > Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; > > Support Opensource <support.opensource@diasemi.com>; Daniel Lezcano > > <daniel.lezcano@linaro.org>; Amit Kucheria > > <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; > Sascha > > Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team > > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP > Linux > > Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; Orson > Zhai > > <orsonzhai@gmail.com>; Baolin Wang <baolin.wang7@gmail.com>; > Chunyan > > Zhang <zhang.lyra@gmail.com>; linux- acpi@vger.kernel.org; > > netdev@vger.kernel.org; platform-driver- x86@vger.kernel.org; > > linux-arm-kernel@lists.infradead.org; > > kernel@collabora.com; Andrzej Pietrasiewicz <andrzej.p@collabora.com>; > > Barlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> > > Subject: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal > > devices > > Importance: High > > > > Polling DISABLED devices is not desired, as all such "disabled" > > devices are meant to be handled by userspace. This patch introduces > > and uses > > should_stop_polling() to decide whether the device should be polled or > not. > > > Thanks for the fix, and IMO, this reveal some more problems. > Say, we need to define "DISABLED" thermal zone. > Can we read the temperature? Can we trust the trip point value? > > IMO, a disabled thermal zone does not mean it is handled by userspace, > because that is what the userspace governor designed for. > Instead, if a thermal zone is disabled, in thermal_zone_device_update(), we > should basically skip all the other operations as well. > I overlooked the last line of the patch. So thermal_zone_device_update() returns immediately if the thermal zone is disabled, right? But how can we stop polling in this case? There is no chance to call into monitor_thermal_zone() in thermal_zone_device_update(), or do I miss something? > I'll try your patches and probably make an incremental patch. I have finished a small patch set to improve this based on my understanding, and will post it tomorrow after testing. Thanks, rui > > Thanks, > rui > > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > > --- > > drivers/thermal/thermal_core.c | 16 ++++++++++++++-- > > 1 file changed, 14 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/thermal/thermal_core.c > > b/drivers/thermal/thermal_core.c index a2a5034f76e7..03c4d8d23284 > > 100644 > > --- a/drivers/thermal/thermal_core.c > > +++ b/drivers/thermal/thermal_core.c > > @@ -305,13 +305,22 @@ static void > > thermal_zone_device_set_polling(struct > > thermal_zone_device *tz, > > cancel_delayed_work(&tz->poll_queue); > > } > > > > +static inline bool should_stop_polling(struct thermal_zone_device > > +*tz) { > > + return thermal_zone_device_get_mode(tz) == > > THERMAL_DEVICE_DISABLED; } > > + > > static void monitor_thermal_zone(struct thermal_zone_device *tz) { > > + bool stop; > > + > > + stop = should_stop_polling(tz); > > + > > mutex_lock(&tz->lock); > > > > - if (tz->passive) > > + if (!stop && tz->passive) > > thermal_zone_device_set_polling(tz, tz->passive_delay); > > - else if (tz->polling_delay) > > + else if (!stop && tz->polling_delay) > > thermal_zone_device_set_polling(tz, tz->polling_delay); > > else > > thermal_zone_device_set_polling(tz, 0); @@ -503,6 +512,9 > @@ void > > thermal_zone_device_update(struct thermal_zone_device *tz, { > > int count; > > > > + if (should_stop_polling(tz)) > > + return; > > + > > if (atomic_read(&in_suspend)) > > return; > > > > -- > > 2.17.1 ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-27 14:20 ` Zhang, Rui @ 2020-04-27 18:34 ` Andrzej Pietrasiewicz 2020-04-28 13:55 ` Zhang, Rui 0 siblings, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-27 18:34 UTC (permalink / raw) To: Zhang, Rui, 'linux-pm@vger.kernel.org' Cc: 'Rafael J . Wysocki', 'Len Brown', 'Jiri Pirko', 'Ido Schimmel', 'David S . Miller', 'Peter Kaestle', 'Darren Hart', 'Andy Shevchenko', 'Support Opensource', 'Daniel Lezcano', 'Amit Kucheria', 'Shawn Guo', 'Sascha Hauer', 'Pengutronix Kernel Team', 'Fabio Estevam', 'NXP Linux Team', 'Heiko Stuebner', 'Orson Zhai', 'Baolin Wang', 'Chunyan Zhang', 'linux-acpi@vger.kernel.org', 'netdev@vger.kernel.org', 'platform-driver-x86@vger.kernel.org', 'linux-arm-kernel@lists.infradead.org', 'kernel@collabora.com', 'Barlomiej Zolnierkiewicz' Hi, W dniu 27.04.2020 o 16:20, Zhang, Rui pisze: > > >> -----Original Message----- >> From: Zhang, Rui >> Sent: Friday, April 24, 2020 5:03 PM >> To: Andrzej Pietrasiewicz <andrzej.p@collabora.com>; linux- >> pm@vger.kernel.org >> Cc: Rafael J . Wysocki <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; >> Jiri Pirko <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David >> S . Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; Darren >> Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; >> Support Opensource <support.opensource@diasemi.com>; Daniel Lezcano >> <daniel.lezcano@linaro.org>; Amit Kucheria >> <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; >> Sascha Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team >> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP >> Linux Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; >> Orson Zhai <orsonzhai@gmail.com>; Baolin Wang >> <baolin.wang7@gmail.com>; Chunyan Zhang <zhang.lyra@gmail.com>; linux- >> acpi@vger.kernel.org; netdev@vger.kernel.org; platform-driver- >> x86@vger.kernel.org; linux-arm-kernel@lists.infradead.org; >> kernel@collabora.com; Barlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> >> Subject: RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal >> devices >> >> Hi, Andrzej, >> >> Thanks for the patches. My Linux laptop was broken and won't get fixed till >> next week, so I may lost some of the discussions previously. >> >>> -----Original Message----- >>> From: Andrzej Pietrasiewicz <andrzej.p@collabora.com> >>> Sent: Friday, April 24, 2020 12:57 AM >>> To: linux-pm@vger.kernel.org >>> Cc: Zhang, Rui <rui.zhang@intel.com>; Rafael J . Wysocki >>> <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; Jiri Pirko >>> <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David S . >>> Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; Darren >>> Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; >>> Support Opensource <support.opensource@diasemi.com>; Daniel Lezcano >>> <daniel.lezcano@linaro.org>; Amit Kucheria >>> <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; >> Sascha >>> Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team >>> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP >> Linux >>> Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; Orson >> Zhai >>> <orsonzhai@gmail.com>; Baolin Wang <baolin.wang7@gmail.com>; >> Chunyan >>> Zhang <zhang.lyra@gmail.com>; linux- acpi@vger.kernel.org; >>> netdev@vger.kernel.org; platform-driver- x86@vger.kernel.org; >>> linux-arm-kernel@lists.infradead.org; >>> kernel@collabora.com; Andrzej Pietrasiewicz <andrzej.p@collabora.com>; >>> Barlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> >>> Subject: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal >>> devices >>> Importance: High >>> >>> Polling DISABLED devices is not desired, as all such "disabled" >>> devices are meant to be handled by userspace. This patch introduces >>> and uses >>> should_stop_polling() to decide whether the device should be polled or >> not. >>> >> Thanks for the fix, and IMO, this reveal some more problems. >> Say, we need to define "DISABLED" thermal zone. >> Can we read the temperature? Can we trust the trip point value? >> >> IMO, a disabled thermal zone does not mean it is handled by userspace, >> because that is what the userspace governor designed for. >> Instead, if a thermal zone is disabled, in thermal_zone_device_update(), we >> should basically skip all the other operations as well. >> > I overlooked the last line of the patch. So thermal_zone_device_update() returns > immediately if the thermal zone is disabled, right? > > But how can we stop polling in this case? It does stop. However, I indeed observe an extra call to thermal_zone_device_update() before it fully stops. I think what happens is this: - storing "disabled" in mode ends up in thermal_zone_device_set_mode(), which calls driver's ->set_mode() and then calls thermal_zone_device_update(), which returns immediately and does not touch the tz->poll_queue delayed work - thermal_zone_device_update() is called from the delayed work when its time comes and this time it also returns immediately, not modifying the said delayed work, so polling effectively stops now. > There is no chance to call into monitor_thermal_zone() in thermal_zone_device_update(), > or do I miss something? Without the last "if" statement in this patch polling stops with the first call to thermal_zone_device_update() because it indeed disables the delayed work. So you are probably right - that last "if" should not be introduced. > >> I'll try your patches and probably make an incremental patch. > > I have finished a small patch set to improve this based on my understanding, and will post it > tomorrow after testing. > Is your small patchset based on top of this series or is it a completely rewritten version? Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-27 18:34 ` Andrzej Pietrasiewicz @ 2020-04-28 13:55 ` Zhang, Rui 0 siblings, 0 replies; 137+ messages in thread From: Zhang, Rui @ 2020-04-28 13:55 UTC (permalink / raw) To: Andrzej Pietrasiewicz, 'linux-pm@vger.kernel.org' Cc: 'Rafael J . Wysocki', 'Len Brown', 'Jiri Pirko', 'Ido Schimmel', 'David S . Miller', 'Peter Kaestle', 'Darren Hart', 'Andy Shevchenko', 'Support Opensource', 'Daniel Lezcano', 'Amit Kucheria', 'Shawn Guo', 'Sascha Hauer', 'Pengutronix Kernel Team', 'Fabio Estevam', 'NXP Linux Team', 'Heiko Stuebner', 'Orson Zhai', 'Baolin Wang', 'Chunyan Zhang', 'linux-acpi@vger.kernel.org', 'netdev@vger.kernel.org', 'platform-driver-x86@vger.kernel.org', 'linux-arm-kernel@lists.infradead.org', 'kernel@collabora.com', 'Barlomiej Zolnierkiewicz' The patch is on top of this patch set. Run into an issue during test today, will send out after the issue resolved. Thanks, rui > -----Original Message----- > From: linux-acpi-owner@vger.kernel.org <linux-acpi-owner@vger.kernel.org> > On Behalf Of Andrzej Pietrasiewicz > Sent: Tuesday, April 28, 2020 2:35 AM > To: Zhang, Rui <rui.zhang@intel.com>; 'linux-pm@vger.kernel.org' <linux- > pm@vger.kernel.org> > Cc: 'Rafael J . Wysocki' <rjw@rjwysocki.net>; 'Len Brown' <lenb@kernel.org>; > 'Jiri Pirko' <jiri@mellanox.com>; 'Ido Schimmel' <idosch@mellanox.com>; > 'David S . Miller' <davem@davemloft.net>; 'Peter Kaestle' <peter@piie.net>; > 'Darren Hart' <dvhart@infradead.org>; 'Andy Shevchenko' > <andy@infradead.org>; 'Support Opensource' > <support.opensource@diasemi.com>; 'Daniel Lezcano' > <daniel.lezcano@linaro.org>; 'Amit Kucheria' > <amit.kucheria@verdurent.com>; 'Shawn Guo' <shawnguo@kernel.org>; > 'Sascha Hauer' <s.hauer@pengutronix.de>; 'Pengutronix Kernel Team' > <kernel@pengutronix.de>; 'Fabio Estevam' <festevam@gmail.com>; 'NXP > Linux Team' <linux-imx@nxp.com>; 'Heiko Stuebner' <heiko@sntech.de>; > 'Orson Zhai' <orsonzhai@gmail.com>; 'Baolin Wang' > <baolin.wang7@gmail.com>; 'Chunyan Zhang' <zhang.lyra@gmail.com>; > 'linux-acpi@vger.kernel.org' <linux-acpi@vger.kernel.org>; > 'netdev@vger.kernel.org' <netdev@vger.kernel.org>; 'platform-driver- > x86@vger.kernel.org' <platform-driver-x86@vger.kernel.org>; 'linux-arm- > kernel@lists.infradead.org' <linux-arm-kernel@lists.infradead.org>; > 'kernel@collabora.com' <kernel@collabora.com>; 'Barlomiej Zolnierkiewicz' > <b.zolnierkie@samsung.com> > Subject: Re: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal > devices > Importance: High > > Hi, > > W dniu 27.04.2020 o 16:20, Zhang, Rui pisze: > > > > > >> -----Original Message----- > >> From: Zhang, Rui > >> Sent: Friday, April 24, 2020 5:03 PM > >> To: Andrzej Pietrasiewicz <andrzej.p@collabora.com>; linux- > >> pm@vger.kernel.org > >> Cc: Rafael J . Wysocki <rjw@rjwysocki.net>; Len Brown > >> <lenb@kernel.org>; Jiri Pirko <jiri@mellanox.com>; Ido Schimmel > >> <idosch@mellanox.com>; David S . Miller <davem@davemloft.net>; > Peter > >> Kaestle <peter@piie.net>; Darren Hart <dvhart@infradead.org>; Andy > >> Shevchenko <andy@infradead.org>; Support Opensource > >> <support.opensource@diasemi.com>; Daniel Lezcano > >> <daniel.lezcano@linaro.org>; Amit Kucheria > >> <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; > >> Sascha Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team > >> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP > >> Linux Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; > >> Orson Zhai <orsonzhai@gmail.com>; Baolin Wang > >> <baolin.wang7@gmail.com>; Chunyan Zhang <zhang.lyra@gmail.com>; > >> linux- acpi@vger.kernel.org; netdev@vger.kernel.org; platform-driver- > >> x86@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > >> kernel@collabora.com; Barlomiej Zolnierkiewicz > >> <b.zolnierkie@samsung.com> > >> Subject: RE: [PATCH v3 2/2] thermal: core: Stop polling DISABLED > >> thermal devices > >> > >> Hi, Andrzej, > >> > >> Thanks for the patches. My Linux laptop was broken and won't get > >> fixed till next week, so I may lost some of the discussions previously. > >> > >>> -----Original Message----- > >>> From: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > >>> Sent: Friday, April 24, 2020 12:57 AM > >>> To: linux-pm@vger.kernel.org > >>> Cc: Zhang, Rui <rui.zhang@intel.com>; Rafael J . Wysocki > >>> <rjw@rjwysocki.net>; Len Brown <lenb@kernel.org>; Jiri Pirko > >>> <jiri@mellanox.com>; Ido Schimmel <idosch@mellanox.com>; David S . > >>> Miller <davem@davemloft.net>; Peter Kaestle <peter@piie.net>; > Darren > >>> Hart <dvhart@infradead.org>; Andy Shevchenko <andy@infradead.org>; > >>> Support Opensource <support.opensource@diasemi.com>; Daniel > Lezcano > >>> <daniel.lezcano@linaro.org>; Amit Kucheria > >>> <amit.kucheria@verdurent.com>; Shawn Guo <shawnguo@kernel.org>; > >> Sascha > >>> Hauer <s.hauer@pengutronix.de>; Pengutronix Kernel Team > >>> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; NXP > >> Linux > >>> Team <linux-imx@nxp.com>; Heiko Stuebner <heiko@sntech.de>; > Orson > >> Zhai > >>> <orsonzhai@gmail.com>; Baolin Wang <baolin.wang7@gmail.com>; > >> Chunyan > >>> Zhang <zhang.lyra@gmail.com>; linux- acpi@vger.kernel.org; > >>> netdev@vger.kernel.org; platform-driver- x86@vger.kernel.org; > >>> linux-arm-kernel@lists.infradead.org; > >>> kernel@collabora.com; Andrzej Pietrasiewicz > >>> <andrzej.p@collabora.com>; Barlomiej Zolnierkiewicz > >>> <b.zolnierkie@samsung.com> > >>> Subject: [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal > >>> devices > >>> Importance: High > >>> > >>> Polling DISABLED devices is not desired, as all such "disabled" > >>> devices are meant to be handled by userspace. This patch introduces > >>> and uses > >>> should_stop_polling() to decide whether the device should be polled > >>> or > >> not. > >>> > >> Thanks for the fix, and IMO, this reveal some more problems. > >> Say, we need to define "DISABLED" thermal zone. > >> Can we read the temperature? Can we trust the trip point value? > >> > >> IMO, a disabled thermal zone does not mean it is handled by > >> userspace, because that is what the userspace governor designed for. > >> Instead, if a thermal zone is disabled, in > >> thermal_zone_device_update(), we should basically skip all the other > operations as well. > >> > > I overlooked the last line of the patch. So > > thermal_zone_device_update() returns immediately if the thermal zone is > disabled, right? > > > > But how can we stop polling in this case? > > It does stop. However, I indeed observe an extra call to > thermal_zone_device_update() before it fully stops. > I think what happens is this: > > - storing "disabled" in mode ends up in thermal_zone_device_set_mode(), > which calls driver's ->set_mode() and then calls > thermal_zone_device_update(), which returns immediately and does not > touch the tz->poll_queue delayed work > > - thermal_zone_device_update() is called from the delayed work when its > time comes and this time it also returns immediately, not modifying the said > delayed work, so polling effectively stops now. > > > There is no chance to call into monitor_thermal_zone() in > > thermal_zone_device_update(), or do I miss something? > > Without the last "if" statement in this patch polling stops with the first call to > thermal_zone_device_update() because it indeed disables the delayed work. > > So you are probably right - that last "if" should not be introduced. > > > > >> I'll try your patches and probably make an incremental patch. > > > > I have finished a small patch set to improve this based on my > > understanding, and will post it tomorrow after testing. > > > > Is your small patchset based on top of this series or is it a completely > rewritten version? > > Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz 2020-04-19 13:10 ` Bartlomiej Zolnierkiewicz @ 2020-04-20 11:03 ` Andrzej Pietrasiewicz 2020-04-20 18:19 ` Andrzej Pietrasiewicz 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-20 11:03 UTC (permalink / raw) To: Bartlomiej Zolnierkiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Barlomiej, Thanks for looking into the series. @Daniel can you see below? W dniu 19.04.2020 o 13:38, Bartlomiej Zolnierkiewicz pisze: > > Hi Andrzej, > > On 4/17/20 6:20 PM, Andrzej Pietrasiewicz wrote: >> Thermal zone devices' mode is stored in individual drivers. This patch >> changes it so that mode is stored in struct thermal_zone_device instead. >> >> As a result all driver-specific variables storing the mode are not needed >> and are removed. Consequently, the get_mode() implementations have nothing >> to operate on and need to be removed, too. >> >> Some thermal framework specific functions are introduced: >> >> thermal_zone_device_get_mode() >> thermal_zone_device_set_mode() >> thermal_zone_device_enable() >> thermal_zone_device_disable() >> >> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >> and the "set" calls driver's set_mode() if provided, so the latter must >> not take this lock again. At the end of the "set" >> thermal_zone_device_update() is called so drivers don't need to repeat this >> invocation in their specific set_mode() implementations. >> >> The scope of the above 4 functions is purposedly limited to the thermal >> framework and drivers are not supposed to call them. This encapsulation > > This should be true only for thermal_zone_device_{get,set}_mode(). > > thermal_zone_device_{en,dis}able() should be available for device drivers: > > * of/thermal device drivers need to enable thermal device itself > (please refer to my patchset for details) > > * device drivers need to call them on ->suspend and ->resume operations > @Daniel: How does this compare to "Just: thermal_zone_device_get_mode() thermal_zone_device_set_mode() thermal_zone_device_disable() thermal_zone_device_enable() And all of them in drivers/thermal/thermal_core.h". Did I understand you correctly? Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-20 11:03 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-20 18:19 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-20 18:19 UTC (permalink / raw) To: Bartlomiej Zolnierkiewicz Cc: linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel @Daniel please see below W dniu 20.04.2020 o 13:03, Andrzej Pietrasiewicz pisze: > Hi Barlomiej, > > Thanks for looking into the series. > > @Daniel can you see below? > > W dniu 19.04.2020 o 13:38, Bartlomiej Zolnierkiewicz pisze: >> >> Hi Andrzej, >> >> On 4/17/20 6:20 PM, Andrzej Pietrasiewicz wrote: >>> Thermal zone devices' mode is stored in individual drivers. This patch >>> changes it so that mode is stored in struct thermal_zone_device instead. >>> >>> As a result all driver-specific variables storing the mode are not needed >>> and are removed. Consequently, the get_mode() implementations have nothing >>> to operate on and need to be removed, too. >>> >>> Some thermal framework specific functions are introduced: >>> >>> thermal_zone_device_get_mode() >>> thermal_zone_device_set_mode() >>> thermal_zone_device_enable() >>> thermal_zone_device_disable() >>> >>> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >>> and the "set" calls driver's set_mode() if provided, so the latter must >>> not take this lock again. At the end of the "set" >>> thermal_zone_device_update() is called so drivers don't need to repeat this >>> invocation in their specific set_mode() implementations. >>> >>> The scope of the above 4 functions is purposedly limited to the thermal >>> framework and drivers are not supposed to call them. This encapsulation >> >> This should be true only for thermal_zone_device_{get,set}_mode(). >> >> thermal_zone_device_{en,dis}able() should be available for device drivers: >> >> * of/thermal device drivers need to enable thermal device itself >> (please refer to my patchset for details) >> >> * device drivers need to call them on ->suspend and ->resume operations >> > > @Daniel: > > How does this compare to > > "Just: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_disable() > thermal_zone_device_enable() > > And all of them in drivers/thermal/thermal_core.h". Did I understand > you correctly? > I sent a PATCH series (rather than next iteration of RFC) addressing Bartlomiej's comments. They make sense to me. Regards, Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-17 20:44 ` Andy Shevchenko 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz @ 2020-05-23 21:24 ` Daniel Lezcano 2020-05-25 19:35 ` Andrzej Pietrasiewicz 2020-05-27 13:30 ` Bartlomiej Zolnierkiewicz 2 siblings, 2 replies; 137+ messages in thread From: Daniel Lezcano @ 2020-05-23 21:24 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz Hi Andrzej, On 17/04/2020 18:20, Andrzej Pietrasiewicz wrote: > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework specific functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > The scope of the above 4 functions is purposedly limited to the thermal > framework and drivers are not supposed to call them. This encapsulation > does not fully work at the moment for some drivers, though: > > - platform/x86/acerhdf.c > - drivers/thermal/imx_thermal.c > - drivers/thermal/intel/intel_quark_dts_thermal.c > - drivers/thermal/of-thermal.c > > and they manipulate struct thermal_zone_device's members directly. > > struct thermal_zone_params gains a new member called initial_mode, which > is used to set tzd's mode at registration time. > > The sysfs "mode" attribute is always exposed from now on, because all > thermal zone devices now have their get_mode() implemented at the generic > level and it is always available. Exposing "mode" doesn't hurt the drivers > which don't provide their own set_mode(), because writing to "mode" will > result in -EPERM, as expected. The result is great, that is a nice cleanup of the thermal framework. After review it appears there are still problems IMO, especially with the suspend / resume path. The patch is big, it is a bit complex to comment. I suggest to re-org the changes as following: - patch 1 : Add the four functions: * thermal_zone_device_set_mode() * thermal_zone_device_enable() * thermal_zone_device_disable() * thermal_zone_device_is_enabled() *but* do not export thermal_zone_device_set_mode(), it must stay private to the thermal framework ATM. - patch 2 : Add the mode THERMAL_DEVICE_SUSPENDED In the thermal_pm_notify() in the: - PM_SUSPEND_PREPARE case, set the mode to THERMAL_DEVICE_SUSPENDED if the mode is THERMAL_DEVICE_ENABLED - PM_POST_SUSPEND case, set the mode to THERMAL_DEVICE_ENABLED, if the mode is THERMAL_DEVICE_SUSPENDED - patch 3 : Change the monitor function Change monitor_thermal_zone() function to set the polling to zero if the mode is THERMAL_DEVICE_DISABLED - patch 4 : Do the changes to remove get_mode() ops Make sure there is no access to tz->mode from the drivers anymore but use of the functions of patch 1. IMO, this is the tricky part because a part of the drivers are not calling the update after setting the mode while the function thermal_zone_device_enable()/disable() call update via the thermal_zone_device_set_mode(), so we must be sure to not break anything. - patch 5 : Do the changes to remove set_mode() ops users As the patch 3 sets the polling to zero, the routine in the driver setting the polling to zero is no longer needed (eg. in the mellanox driver). I expect int300 to be the last user of this ops, hopefully we can find a way to get rid of the specific call done inside and then remove the ops. The initial_mode approach looks hackish, I suggest to make the default the thermal zone disabled after creating and then explicitly enable it. Note that is what do a lot of drivers already. Hopefully, these changes are git-bisect safe. Does it make sense ? -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-05-23 21:24 ` Daniel Lezcano @ 2020-05-25 19:35 ` Andrzej Pietrasiewicz 2020-05-25 22:08 ` Daniel Lezcano 2020-05-27 13:30 ` Bartlomiej Zolnierkiewicz 1 sibling, 1 reply; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-25 19:35 UTC (permalink / raw) To: Daniel Lezcano, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz Hi Daniel, W dniu 23.05.2020 o 23:24, Daniel Lezcano pisze: > Hi Andrzej, > > On 17/04/2020 18:20, Andrzej Pietrasiewicz wrote: >> Thermal zone devices' mode is stored in individual drivers. This patch >> changes it so that mode is stored in struct thermal_zone_device instead. >> >> As a result all driver-specific variables storing the mode are not needed >> and are removed. Consequently, the get_mode() implementations have nothing >> to operate on and need to be removed, too. >> >> Some thermal framework specific functions are introduced: >> >> thermal_zone_device_get_mode() >> thermal_zone_device_set_mode() >> thermal_zone_device_enable() >> thermal_zone_device_disable() >> >> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >> and the "set" calls driver's set_mode() if provided, so the latter must >> not take this lock again. At the end of the "set" >> thermal_zone_device_update() is called so drivers don't need to repeat this >> invocation in their specific set_mode() implementations. >> >> The scope of the above 4 functions is purposedly limited to the thermal >> framework and drivers are not supposed to call them. This encapsulation >> does not fully work at the moment for some drivers, though: >> >> - platform/x86/acerhdf.c >> - drivers/thermal/imx_thermal.c >> - drivers/thermal/intel/intel_quark_dts_thermal.c >> - drivers/thermal/of-thermal.c >> >> and they manipulate struct thermal_zone_device's members directly. >> >> struct thermal_zone_params gains a new member called initial_mode, which >> is used to set tzd's mode at registration time. >> >> The sysfs "mode" attribute is always exposed from now on, because all >> thermal zone devices now have their get_mode() implemented at the generic >> level and it is always available. Exposing "mode" doesn't hurt the drivers >> which don't provide their own set_mode(), because writing to "mode" will >> result in -EPERM, as expected. > > The result is great, that is a nice cleanup of the thermal framework. > > After review it appears there are still problems IMO, especially with > the suspend / resume path. The patch is big, it is a bit complex to > comment. I suggest to re-org the changes as following: > > - patch 1 : Add the four functions: > > * thermal_zone_device_set_mode() > * thermal_zone_device_enable() > * thermal_zone_device_disable() > * thermal_zone_device_is_enabled() > > *but* do not export thermal_zone_device_set_mode(), it must stay private > to the thermal framework ATM. Not exporting thermal_zone_device_set_mode() implies not exporting thermal_zone_device_enable()/thermal_zone_device_disable() because they are implemented in terms of the former. Or do you have a different idea? > > - patch 2 : Add the mode THERMAL_DEVICE_SUSPENDED > > In the thermal_pm_notify() in the: > > - PM_SUSPEND_PREPARE case, set the mode to THERMAL_DEVICE_SUSPENDED if > the mode is THERMAL_DEVICE_ENABLED > > - PM_POST_SUSPEND case, set the mode to THERMAL_DEVICE_ENABLED, if the > mode is THERMAL_DEVICE_SUSPENDED > > - patch 3 : Change the monitor function > > Change monitor_thermal_zone() function to set the polling to zero if the > mode is THERMAL_DEVICE_DISABLED So we assume this: if a driver creates a tz which is initially ENABLED, it will be polled. If a driver creates a tz which is initially DISABLED (which is what you suggest the drivers should be doing, but not all of them do), it won't be polled unless the driver explicitly enables its tz. Am I concluding right that a suspended device will remain polled? Is it ok? > > - patch 4 : Do the changes to remove get_mode() ops > > Make sure there is no access to tz->mode from the drivers anymore but > use of the functions of patch 1. IMO, this is the tricky part because a > part of the drivers are not calling the update after setting the mode > while the function thermal_zone_device_enable()/disable() call update > via the thermal_zone_device_set_mode(), so we must be sure to not break > anything. Ah, I guess now is the time to make the functions from patch 1 exported? Ensuring no driver accesses tz->mode directly might be tricky, indeed. If it can be shown that calling the update doesn't hurt a particular driver, it can be converted to use the helpers instead of manipulating tz->mode directly. If, however, it does make a difference then it all depends and getting rid of accessing tz->mode directly might require help from the respective maintainers. This also calls for storing tz's mode in struct thermal_zone_device rather than in individual drivers. In fact it seems the purpose of ->get_mode() is to produce the state stored internally in drivers. Removing ->get_mode() requires changing the place where the state is stored. struct thermal_zone_device seems most appropriate. So this patch is not going to be small. Once we start storing tz's state in struct thermal_zone_device the ->set_mode() implementations need to be changed, too. To me it seems awkward to split this change in two patches: if we keep the changes split then in patch 4 we need to introduce code which implements ->set_mode() in terms of the new state location, only to remove it in the very next patch. While we are at it some drivers, namely acpi/thermal and int3400 store their mode in an int rather than enum thermal_device_mode. So maybe changing this should go even before patch 4? acerhdf does not store its mode at all and on top of it it wants to manipulate the polling delay directly and it has a module parameter which specifies it. > > - patch 5 : Do the changes to remove set_mode() ops users > > As the patch 3 sets the polling to zero, the routine in the driver > setting the polling to zero is no longer needed (eg. in the mellanox > driver). I expect int300 to be the last user of this ops, hopefully we > can find a way to get rid of the specific call done inside and then > remove the ops. acerhdf wants ->set_mode() desperately. > > The initial_mode approach looks hackish, I suggest to make the default > the thermal zone disabled after creating and then explicitly enable it. Is it needed in drivers which create their thermal zone enabled? Regards, Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-05-25 19:35 ` Andrzej Pietrasiewicz @ 2020-05-25 22:08 ` Daniel Lezcano 2020-05-26 16:56 ` Andrzej Pietrasiewicz 0 siblings, 1 reply; 137+ messages in thread From: Daniel Lezcano @ 2020-05-25 22:08 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz On 25/05/2020 21:35, Andrzej Pietrasiewicz wrote: > Hi Daniel, > > W dniu 23.05.2020 o 23:24, Daniel Lezcano pisze: >> Hi Andrzej, >> >> On 17/04/2020 18:20, Andrzej Pietrasiewicz wrote: >>> Thermal zone devices' mode is stored in individual drivers. This patch >>> changes it so that mode is stored in struct thermal_zone_device instead. >>> >>> As a result all driver-specific variables storing the mode are not >>> needed >>> and are removed. Consequently, the get_mode() implementations have >>> nothing >>> to operate on and need to be removed, too. >>> >>> Some thermal framework specific functions are introduced: >>> >>> thermal_zone_device_get_mode() >>> thermal_zone_device_set_mode() >>> thermal_zone_device_enable() >>> thermal_zone_device_disable() >>> >>> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >>> and the "set" calls driver's set_mode() if provided, so the latter must >>> not take this lock again. At the end of the "set" >>> thermal_zone_device_update() is called so drivers don't need to >>> repeat this >>> invocation in their specific set_mode() implementations. >>> >>> The scope of the above 4 functions is purposedly limited to the thermal >>> framework and drivers are not supposed to call them. This encapsulation >>> does not fully work at the moment for some drivers, though: >>> >>> - platform/x86/acerhdf.c >>> - drivers/thermal/imx_thermal.c >>> - drivers/thermal/intel/intel_quark_dts_thermal.c >>> - drivers/thermal/of-thermal.c >>> >>> and they manipulate struct thermal_zone_device's members directly. >>> >>> struct thermal_zone_params gains a new member called initial_mode, which >>> is used to set tzd's mode at registration time. >>> >>> The sysfs "mode" attribute is always exposed from now on, because all >>> thermal zone devices now have their get_mode() implemented at the >>> generic >>> level and it is always available. Exposing "mode" doesn't hurt the >>> drivers >>> which don't provide their own set_mode(), because writing to "mode" will >>> result in -EPERM, as expected. >> >> The result is great, that is a nice cleanup of the thermal framework. >> >> After review it appears there are still problems IMO, especially with >> the suspend / resume path. The patch is big, it is a bit complex to >> comment. I suggest to re-org the changes as following: >> >> - patch 1 : Add the four functions: >> >> * thermal_zone_device_set_mode() >> * thermal_zone_device_enable() >> * thermal_zone_device_disable() >> * thermal_zone_device_is_enabled() >> >> *but* do not export thermal_zone_device_set_mode(), it must stay private >> to the thermal framework ATM. > > Not exporting thermal_zone_device_set_mode() implies not exporting > thermal_zone_device_enable()/thermal_zone_device_disable() because they > are implemented in terms of the former. Or do you have a different idea? I meant no inline for them but as below: in .h extern int thermal_zone_device_enable(); extern int thermal_zone_device_disable(); extern int thermal_zone_device_is_enabled(); in .c static int thermal_zone_device_set_mode() { ... } int thermal_zone_device_enable() { thermal_zone_device_set_mode(); } EXPORT_SYMBOL_GPL(thermal_zone_device_enable); >> - patch 2 : Add the mode THERMAL_DEVICE_SUSPENDED >> >> In the thermal_pm_notify() in the: >> >> - PM_SUSPEND_PREPARE case, set the mode to THERMAL_DEVICE_SUSPENDED if >> the mode is THERMAL_DEVICE_ENABLED >> >> - PM_POST_SUSPEND case, set the mode to THERMAL_DEVICE_ENABLED, if the >> mode is THERMAL_DEVICE_SUSPENDED >> >> - patch 3 : Change the monitor function >> >> Change monitor_thermal_zone() function to set the polling to zero if the >> mode is THERMAL_DEVICE_DISABLED > > So we assume this: if a driver creates a tz which is initially ENABLED, > it will be polled. If a driver creates a tz which is initially DISABLED > (which is what you suggest the drivers should be doing, but not all of them > do), it won't be polled unless the driver explicitly enables its tz. Yes. > Am I concluding right that a suspended device will remain polled? Is it ok? Actually it is not ok but AFAICT, it is the current behavior. The polling do not stop but the 'in_suspend' prevent an update. I thought we can post-pone the suspend case later when the ENABLED/DISABLED changes are consolidated, so SUSPENDED will act as DISABLED. >> - patch 4 : Do the changes to remove get_mode() ops >> >> Make sure there is no access to tz->mode from the drivers anymore but >> use of the functions of patch 1. IMO, this is the tricky part because a >> part of the drivers are not calling the update after setting the mode >> while the function thermal_zone_device_enable()/disable() call update >> via the thermal_zone_device_set_mode(), so we must be sure to not break >> anything. > > Ah, I guess now is the time to make the functions from patch 1 exported? Yes :) > Ensuring no driver accesses tz->mode directly might be tricky, indeed. > If it can be shown that calling the update doesn't hurt a particular > driver, > it can be converted to use the helpers instead of manipulating tz->mode > directly. If, however, it does make a difference then it all depends and > getting rid of accessing tz->mode directly might require help from the > respective maintainers. Agree. > This also calls for storing tz's mode in struct thermal_zone_device > rather than in individual drivers. In fact it seems the purpose > of ->get_mode() is to produce the state stored internally in drivers. > Removing ->get_mode() requires changing the place where the state is > stored. struct thermal_zone_device seems most appropriate. So this patch > is not going to be small. Yes, the patch can be big. It is fine if the changes are only to replace tz->mode by their respective disable/enable/is_enabled functions. More complex changes can be separate. > Once we start storing tz's state in struct thermal_zone_device the > ->set_mode() implementations need to be changed, too. To me it seems > awkward to split this change in two patches: if we keep the changes > split then in patch 4 we need to introduce code which implements > ->set_mode() in terms of the new state location, only to remove it > in the very next patch. Yes, it is a valid point. May be you can do the changes in two patches to see the results in terms of complexity for the review process, then decide if it is worth to merge them before sending. > While we are at it some drivers, namely acpi/thermal and int3400 store > their mode in an int rather than enum thermal_device_mode. So maybe > changing this should go even before patch 4? I agree. > acerhdf does not store > its mode at all and on top of it it wants to manipulate the polling > delay directly and it has a module parameter which specifies it. >> - patch 5 : Do the changes to remove set_mode() ops users >> >> As the patch 3 sets the polling to zero, the routine in the driver >> setting the polling to zero is no longer needed (eg. in the mellanox >> driver). I expect int300 to be the last user of this ops, hopefully we >> can find a way to get rid of the specific call done inside and then >> remove the ops. > > acerhdf wants ->set_mode() desperately. Yes, there is a couple of drivers which requires for the moment to keep the ops->set_mode to be called: int3400 and acerhdf. Both of them will be greatly simplified with the DISABLED / ENABLED changes. >> The initial_mode approach looks hackish, I suggest to make the default >> the thermal zone disabled after creating and then explicitly enable it. > > Is it needed in drivers which create their thermal zone enabled? IMO, yes. We are doing changes with a code prone to issues, so making the steps: creation + enable will make things more clear. For instance, the clk framework do the same. -- <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 ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-05-25 22:08 ` Daniel Lezcano @ 2020-05-26 16:56 ` Andrzej Pietrasiewicz 0 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-05-26 16:56 UTC (permalink / raw) To: Daniel Lezcano, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz Hi Daniel, W dniu 26.05.2020 o 00:08, Daniel Lezcano pisze: > On 25/05/2020 21:35, Andrzej Pietrasiewicz wrote: >> Hi Daniel, >> >> W dniu 23.05.2020 o 23:24, Daniel Lezcano pisze: >>> Hi Andrzej, >>> >>> On 17/04/2020 18:20, Andrzej Pietrasiewicz wrote: >>>> Thermal zone devices' mode is stored in individual drivers. This patch >>>> changes it so that mode is stored in struct thermal_zone_device instead. >>>> >>>> As a result all driver-specific variables storing the mode are not >>>> needed >>>> and are removed. Consequently, the get_mode() implementations have >>>> nothing >>>> to operate on and need to be removed, too. >>>> >>>> Some thermal framework specific functions are introduced: >>>> >>>> thermal_zone_device_get_mode() >>>> thermal_zone_device_set_mode() >>>> thermal_zone_device_enable() >>>> thermal_zone_device_disable() >>>> >>>> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >>>> and the "set" calls driver's set_mode() if provided, so the latter must >>>> not take this lock again. At the end of the "set" >>>> thermal_zone_device_update() is called so drivers don't need to >>>> repeat this >>>> invocation in their specific set_mode() implementations. >>>> >>>> The scope of the above 4 functions is purposedly limited to the thermal >>>> framework and drivers are not supposed to call them. This encapsulation >>>> does not fully work at the moment for some drivers, though: >>>> >>>> - platform/x86/acerhdf.c >>>> - drivers/thermal/imx_thermal.c >>>> - drivers/thermal/intel/intel_quark_dts_thermal.c >>>> - drivers/thermal/of-thermal.c >>>> >>>> and they manipulate struct thermal_zone_device's members directly. >>>> >>>> struct thermal_zone_params gains a new member called initial_mode, which >>>> is used to set tzd's mode at registration time. >>>> >>>> The sysfs "mode" attribute is always exposed from now on, because all >>>> thermal zone devices now have their get_mode() implemented at the >>>> generic >>>> level and it is always available. Exposing "mode" doesn't hurt the >>>> drivers >>>> which don't provide their own set_mode(), because writing to "mode" will >>>> result in -EPERM, as expected. >>> >>> The result is great, that is a nice cleanup of the thermal framework. >>> >>> After review it appears there are still problems IMO, especially with >>> the suspend / resume path. The patch is big, it is a bit complex to >>> comment. I suggest to re-org the changes as following: >>> >>> - patch 1 : Add the four functions: >>> >>> * thermal_zone_device_set_mode() >>> * thermal_zone_device_enable() >>> * thermal_zone_device_disable() >>> * thermal_zone_device_is_enabled() >>> >>> *but* do not export thermal_zone_device_set_mode(), it must stay private >>> to the thermal framework ATM. >> >> Not exporting thermal_zone_device_set_mode() implies not exporting >> thermal_zone_device_enable()/thermal_zone_device_disable() because they >> are implemented in terms of the former. Or do you have a different idea? > > I meant no inline for them but as below: > > in .h > > extern int thermal_zone_device_enable(); > extern int thermal_zone_device_disable(); > extern int thermal_zone_device_is_enabled(); > > in .c > > static int thermal_zone_device_set_mode() > { > ... > } > > int thermal_zone_device_enable() > { > thermal_zone_device_set_mode(); > } > EXPORT_SYMBOL_GPL(thermal_zone_device_enable); > Hmm. I'm trying to proceed according to what you outline, but it doesn't feel the right approach. Let me show you patch 1: drivers/thermal/thermal_core.c: +int thermal_zone_device_set_mode(struct thermal_zone_device *tz, + enum thermal_device_mode mode) +{ + int ret = 0; + + mutex_lock(&tz->lock); + + if (tz->ops->set_mode) + ret = tz->ops->set_mode(tz, mode); + + mutex_unlock(&tz->lock); + + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); + + return ret; +} + +int thermal_zone_device_enable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); +} +EXPORT_SYMBOL(thermal_zone_device_enable); + +int thermal_zone_device_disable(struct thermal_zone_device *tz) +{ + return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); +} +EXPORT_SYMBOL(thermal_zone_device_disable); + +int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) +{ + enum thermal_device_mode mode = THERMAL_DEVICE_ENABLED; + int ret; + + mutex_lock(&tz->lock); + + if (tz->ops->get_mode) + ret = tz->ops->get_mode(tz, &mode); + + mutex_unlock(&tz->lock); + + return mode == THERMAL_DEVICE_ENABLED; +} +EXPORT_SYMBOL(thermal_zone_device_is_enabled); + plus prototypes of all except set_mode in include/linux/thermal.h I can see 2 problems: 1) we add unused code to the kernel (perhaps this is ok if patches in this series will start using it) 2) tzd *does not* store mode. These are drivers that provide mode access with get_mode()/set_mode() - if they implement them. What if they don't? If thermal_zone_device_set_mode() is introduced now its effect depends on whether a driver implements set_mode() or not. If it doesn't then despite thermal_zone_device_set_mode() being invoked the mode is not changed. Then what does thermal_zone_device_is_enabled() mean? We don't know, because we don't know what the effect of thermal_zone_device_set_mode() is in the first place. And if the driver does not provide get_mode() then thermal_zone_device_is_enabled() always returns "enabled". Adding these functions now without mode being stored in tzd seems awkward to me. Consequently, IMO the first thing to do is make tzd store device's mode and this way be independent from whether drivers implement or not implement get_mode()/set_mode(). > >>> - patch 2 : Add the mode THERMAL_DEVICE_SUSPENDED >>> >>> In the thermal_pm_notify() in the: >>> >>> - PM_SUSPEND_PREPARE case, set the mode to THERMAL_DEVICE_SUSPENDED if >>> the mode is THERMAL_DEVICE_ENABLED >>> >>> - PM_POST_SUSPEND case, set the mode to THERMAL_DEVICE_ENABLED, if the >>> mode is THERMAL_DEVICE_SUSPENDED >>> drivers/thermal/thermal_core.c: case PM_HIBERNATION_PREPARE: case PM_RESTORE_PREPARE: case PM_SUSPEND_PREPARE: + list_for_each_entry(tz, &thermal_tz_list, node) { + tz_mode = THERMAL_DEVICE_ENABLED; + if (tz->ops->get_mode) + tz->ops->get_mode(tz, &tz_mode); + if (tz_mode == THERMAL_DEVICE_ENABLED) + thermal_zone_device_set_mode(tz, + THERMAL_DEVICE_SUSPENDED); + } atomic_set(&in_suspend, 1); break; case PM_POST_HIBERNATION: @@ -1530,6 +1538,9 @@ static int thermal_pm_notify(struct notifier_block *nb, tz_mode = THERMAL_DEVICE_ENABLED; if (tz->ops->get_mode) tz->ops->get_mode(tz, &tz_mode); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; + if (tz_mode == THERMAL_DEVICE_SUSPENDED) + thermal_zone_device_set_mode(tz, + THERMAL_DEVICE_ENABLED); include/linux/thermal.h: enum thermal_device_mode { THERMAL_DEVICE_DISABLED = 0, THERMAL_DEVICE_ENABLED, + THERMAL_DEVICE_SUSPENDED, We don't know if set_mode() was effective in PM_SUSPEND_PREPARE_PATH. If it wasn't then instead of being SUSPENDED the device is still ENABLED. If still enabled it doesn't need enabling so the last "if" does the right thing, but does not feel right. >>> - patch 3 : Change the monitor function >>> >>> Change monitor_thermal_zone() function to set the polling to zero if the >>> mode is THERMAL_DEVICE_DISABLED >> >> So we assume this: if a driver creates a tz which is initially ENABLED, >> it will be polled. If a driver creates a tz which is initially DISABLED >> (which is what you suggest the drivers should be doing, but not all of them >> do), it won't be polled unless the driver explicitly enables its tz. > > Yes. > >> Am I concluding right that a suspended device will remain polled? Is it ok? > > Actually it is not ok but AFAICT, it is the current behavior. The > polling do not stop but the 'in_suspend' prevent an update. I thought we > can post-pone the suspend case later when the ENABLED/DISABLED changes > are consolidated, so SUSPENDED will act as DISABLED. > drivers/thermal/thermal_core.c: static void monitor_thermal_zone(struct thermal_zone_device *tz) { + enum thermal_device_mode tz_mode = THERMAL_DEVICE_ENABLED; + mutex_lock(&tz->lock); - if (tz->passive) + if (tz->ops->get_mode) + tz->ops->get_mode(tz, &tz_mode); + + if (tz->passive && mode != THERMAL_DEVICE_DISABLED) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (tz->polling_delay && mode != THERMAL_DEVICE_DISABLED) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); If the driver does not implement get_mode() then we assume ENABLED. What if it is actually DISABLED? How does this depend on patch 1 or patch 2? >>> - patch 4 : Do the changes to remove get_mode() ops >>> >>> Make sure there is no access to tz->mode from the drivers anymore but >>> use of the functions of patch 1. IMO, this is the tricky part because a >>> part of the drivers are not calling the update after setting the mode >>> while the function thermal_zone_device_enable()/disable() call update >>> via the thermal_zone_device_set_mode(), so we must be sure to not break >>> anything. >> I haven't started this yet, but again it seems to me that drivers need to start storing their mode in tzd->mode in the first place So what I envision is this: 1) Make all drivers store their state still locally, but using the enum (not all of them do) 2) Once all drivers store their state in the enum, store the enum in struct tzd instead of locally in drivers. This makes get_mode() driver op redundant, but if you prefer more granularity removing it might be done in a separate patch (at the expense of modifying it now to use tzd's member instead of driver-local variable). This also impacts set_mode() ops, because they need to actually change tzd's member instead of some driver-level variable. Changing set_mode() IMO needs to be done in one go. 3) Remove get_mode() driver op altogether, as the mode is stored in struct tzd. 4) patch 1 you outlined - set_mode() and is_enabled() will now operate on tzd's members, so their effect does not depend on drivers implementing or not implementing set_mode(). These effects don't depend on get_mode() any more because of 3). set_mode() would still be calling the set_mode() op in drivers before modifying tzd->mode. 5) patch 2 you outlined - but it can't use thermal_zone_device_set_mode(), because if it gets and then changes tzd's mode, it must do so under tzd->lock. This is ok as this is the very implementation of thermal_core, so accessing "private" members of tzd is a valid approach here. 6) patch 3 you outlined - now it makes much more sense to query tzd's member for mode instead of relying on drivers implementing get_mode(). 7) patch 4 you outlined but under a different name, because get_mode() is already gone. The guts of the patch should be doing what you wrote, though, which is use the helpers instead of directly modifying tzd's members in drivers. 8) patch 5 you outlined - perhaps under a different name, but still doing the same thing: removing portions of code which set polling time to zero in drivers, as that is already being done at tzd's level. This would hopefully make at least some set_mode() implementations no-ops and, consequently, redundant. I can see these drivers: mellanox, part of acerhdf (this driver wants to know when it is becoming enabled/disabled, but the part setting polling can be removed), part of imx (similar situation to that of acerhdf) and of-thermal. After 8) there would be 5 non-empty set_mode() implementations: acpi - but apparently only to print some debug, maybe can be removed acerhdf - no idea if it can live without knowing when the mode changes imx - ditto int3400 - ditto quark - ditto Perhaps after 8) instead of removing set_mode() maybe we should change its name to better reflect its purpose: mode_changing() ? Or maybe even such a change should be a part of 4)? Regards, Andrzej ^ permalink raw reply [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-05-23 21:24 ` Daniel Lezcano 2020-05-25 19:35 ` Andrzej Pietrasiewicz @ 2020-05-27 13:30 ` Bartlomiej Zolnierkiewicz 1 sibling, 0 replies; 137+ messages in thread From: Bartlomiej Zolnierkiewicz @ 2020-05-27 13:30 UTC (permalink / raw) To: Daniel Lezcano Cc: Andrzej Pietrasiewicz, linux-pm, Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel Hi Daniel, On 5/23/20 11:24 PM, Daniel Lezcano wrote: > Hi Andrzej, > > On 17/04/2020 18:20, Andrzej Pietrasiewicz wrote: >> Thermal zone devices' mode is stored in individual drivers. This patch >> changes it so that mode is stored in struct thermal_zone_device instead. >> >> As a result all driver-specific variables storing the mode are not needed >> and are removed. Consequently, the get_mode() implementations have nothing >> to operate on and need to be removed, too. >> >> Some thermal framework specific functions are introduced: >> >> thermal_zone_device_get_mode() >> thermal_zone_device_set_mode() >> thermal_zone_device_enable() >> thermal_zone_device_disable() >> >> thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock >> and the "set" calls driver's set_mode() if provided, so the latter must >> not take this lock again. At the end of the "set" >> thermal_zone_device_update() is called so drivers don't need to repeat this >> invocation in their specific set_mode() implementations. >> >> The scope of the above 4 functions is purposedly limited to the thermal >> framework and drivers are not supposed to call them. This encapsulation >> does not fully work at the moment for some drivers, though: >> >> - platform/x86/acerhdf.c >> - drivers/thermal/imx_thermal.c >> - drivers/thermal/intel/intel_quark_dts_thermal.c >> - drivers/thermal/of-thermal.c >> >> and they manipulate struct thermal_zone_device's members directly. >> >> struct thermal_zone_params gains a new member called initial_mode, which >> is used to set tzd's mode at registration time. >> >> The sysfs "mode" attribute is always exposed from now on, because all >> thermal zone devices now have their get_mode() implemented at the generic >> level and it is always available. Exposing "mode" doesn't hurt the drivers >> which don't provide their own set_mode(), because writing to "mode" will >> result in -EPERM, as expected. > > The result is great, that is a nice cleanup of the thermal framework. > > After review it appears there are still problems IMO, especially with > the suspend / resume path. The patch is big, it is a bit complex to > comment. I suggest to re-org the changes as following: There are still issues with the related existing thermal code but this patch seems to be a step in the right direction. For the latest version posted ("v3" one, your mail was replied to the older "RFC v3" one): https://lore.kernel.org/linux-pm/20200423165705.13585-2-andrzej.p@collabora.com/ I couldn't find the problems with the patch itself (no new issues being introduced, all changes seem to be improvements over the current situation). Also the patch is not small but it also not that big and it mostly removes the code: 17 files changed, 105 insertions(+), 244 deletions(-) I worry that since the original code is intertwined in the interesting ways the cost of work on splitting the patch on smaller changes may be higher than its benefits. > - patch 1 : Add the four functions: > > * thermal_zone_device_set_mode() > * thermal_zone_device_enable() > * thermal_zone_device_disable() > * thermal_zone_device_is_enabled() > > *but* do not export thermal_zone_device_set_mode(), it must stay private > to the thermal framework ATM. > > - patch 2 : Add the mode THERMAL_DEVICE_SUSPENDED > > In the thermal_pm_notify() in the: > > - PM_SUSPEND_PREPARE case, set the mode to THERMAL_DEVICE_SUSPENDED if > the mode is THERMAL_DEVICE_ENABLED > > - PM_POST_SUSPEND case, set the mode to THERMAL_DEVICE_ENABLED, if the > mode is THERMAL_DEVICE_SUSPENDED > > - patch 3 : Change the monitor function > > Change monitor_thermal_zone() function to set the polling to zero if the > mode is THERMAL_DEVICE_DISABLED > > - patch 4 : Do the changes to remove get_mode() ops > > Make sure there is no access to tz->mode from the drivers anymore but > use of the functions of patch 1. IMO, this is the tricky part because a > part of the drivers are not calling the update after setting the mode > while the function thermal_zone_device_enable()/disable() call update > via the thermal_zone_device_set_mode(), so we must be sure to not break > anything. > > - patch 5 : Do the changes to remove set_mode() ops users > > As the patch 3 sets the polling to zero, the routine in the driver > setting the polling to zero is no longer needed (eg. in the mellanox > driver). I expect int300 to be the last user of this ops, hopefully we > can find a way to get rid of the specific call done inside and then > remove the ops. > > The initial_mode approach looks hackish, I suggest to make the default > the thermal zone disabled after creating and then explicitly enable it. > Note that is what do a lot of drivers already. > > Hopefully, these changes are git-bisect safe. > > Does it make sense ? Besides the requirement to split the patch it seems that the above list contains a lot of problematic areas with the existing thermal code yet to be addressed.. Best regards, -- Bartlomiej Zolnierkiewicz Samsung R&D Institute Poland Samsung Electronics ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v3 2/2] thermal: core: Stop polling DISABLED thermal devices 2020-04-17 16:20 ` [RFC v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz @ 2020-04-17 16:20 ` Andrzej Pietrasiewicz 2020-04-19 13:50 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Peter Kästle 2 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-17 16:20 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz, Barlomiej Zolnierkiewicz Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. This patch introduces and uses should_stop_polling() to decide whether the device should be polled or not. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5ff98fcc0f6a..36abdc9ce1bb 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,13 +305,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; +} + static void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -505,6 +514,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct 2020-04-17 16:20 ` [RFC v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-17 16:20 ` [RFC v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-04-19 13:50 ` Peter Kästle 2 siblings, 0 replies; 137+ messages in thread From: Peter Kästle @ 2020-04-19 13:50 UTC (permalink / raw) To: Andrzej Pietrasiewicz, linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Barlomiej Zolnierkiewicz 17. April 2020 18:20, "Andrzej Pietrasiewicz" <andrzej.p@collabora.com> schrieb: > Thermal zone devices' mode is stored in individual drivers. This patch > changes it so that mode is stored in struct thermal_zone_device instead. > > As a result all driver-specific variables storing the mode are not needed > and are removed. Consequently, the get_mode() implementations have nothing > to operate on and need to be removed, too. > > Some thermal framework specific functions are introduced: > > thermal_zone_device_get_mode() > thermal_zone_device_set_mode() > thermal_zone_device_enable() > thermal_zone_device_disable() > > thermal_zone_device_get_mode() and its "set" counterpart take tzd's lock > and the "set" calls driver's set_mode() if provided, so the latter must > not take this lock again. At the end of the "set" > thermal_zone_device_update() is called so drivers don't need to repeat this > invocation in their specific set_mode() implementations. > > The scope of the above 4 functions is purposedly limited to the thermal > framework and drivers are not supposed to call them. This encapsulation > does not fully work at the moment for some drivers, though: > > - platform/x86/acerhdf.c Acked-by: Peter Kaestle <peter@piie.net> [...] -- --peter; ^ permalink raw reply [flat|nested] 137+ messages in thread
* [RFC v2 6/9] thermal: Remove get_mode() method 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (4 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 5/9] thermal: Store mode in thermal_zone_device Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 7/9] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz ` (3 subsequent siblings) 9 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Now that mode of all thermal zone devices is stored in struct thermal_zone_device the get_mode() method is not used nor necessary any more. All its former users used it only to report the state of their then-internal variable. The sysfs "mode" attribute is always exposed from now on. It doesn't hurt the drivers which don't provide their own set_mode(), because writing to "mode" will result in -EPERM, as expected. thermal_zone_device_get_mode() will always succeed, so let it return the actual value rather than an always-zero return code. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/acpi/thermal.c | 12 ++-------- drivers/thermal/imx_thermal.c | 6 +---- .../intel/int340x_thermal/int3400_thermal.c | 6 +---- drivers/thermal/thermal_core.c | 16 +------------- drivers/thermal/thermal_sysfs.c | 22 +------------------ include/linux/thermal.h | 16 ++++++++------ 6 files changed, 15 insertions(+), 63 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 755f12b76c20..bfe573076a3f 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -500,11 +500,7 @@ static void acpi_thermal_check(void *data) struct acpi_thermal *tz = data; enum thermal_device_mode mode; - /* - * this driver does not provide ->get_mode(), so calling - * thermal_zone_device_get_mode() always succeeds - */ - thermal_zone_device_get_mode(tz->thermal_zone, &mode); + mode = thermal_zone_device_get_mode(tz->thermal_zone); if (mode != THERMAL_DEVICE_ENABLED) return; @@ -546,11 +542,7 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, if (mode == THERMAL_DEVICE_DISABLED) pr_warn("thermal zone will be disabled\n"); - /* - * this driver does not provide ->get_mode(), so calling - * thermal_zone_device_get_mode() always succeeds - */ - thermal_zone_device_get_mode(thermal, &old_mode); + old_mode = thermal_zone_device_get_mode(thermal); if (mode != old_mode) { thermal_zone_device_store_mode(thermal, mode); diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index f3f602b4ece5..8b683c6585cf 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -256,11 +256,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) bool wait; u32 val; - /* - * this driver does not provide ->get_mode(), so calling - * thermal_zone_device_get_mode() always succeeds - */ - thermal_zone_device_get_mode(tz, &mode); + mode = thermal_zone_device_get_mode(tz); if (mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ regmap_read(map, soc_data->temp_data, &val); diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index a7d9b42c060d..20007fafc04b 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -240,11 +240,7 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, mode != THERMAL_DEVICE_DISABLED) return -EINVAL; - /* - * this driver does not provide ->get_mode(), so calling - * thermal_zone_device_get_mode() always succeeds - */ - thermal_zone_device_get_mode(thermal, &old_mode); + old_mode = thermal_zone_device_get_mode(thermal); if (mode != old_mode) { thermal_zone_device_store_mode(thermal, mode); result = int3400_thermal_run_osc(priv->adev->handle, diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index cb0ff47f0dbe..a59c3411fb9c 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -469,18 +469,6 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) thermal_zone_device_init(tz); } -int thermal_zone_device_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ - if (tz->ops->get_mode) - return tz->ops->get_mode(tz, mode); - - *mode = tz->mode; - - return 0; -} -EXPORT_SYMBOL_GPL(thermal_zone_device_get_mode); - int thermal_zone_device_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { @@ -1507,9 +1495,7 @@ static int thermal_pm_notify(struct notifier_block *nb, case PM_POST_SUSPEND: atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { - tz_mode = THERMAL_DEVICE_ENABLED; - if (tz->ops->get_mode) - tz->ops->get_mode(tz, &tz_mode); + tz_mode = thermal_zone_device_get_mode(tz); if (tz_mode == THERMAL_DEVICE_DISABLED) continue; diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 66d9691b8bd6..cbb27b3c96d2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -50,11 +50,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); enum thermal_device_mode mode; - int result; - result = thermal_zone_device_get_mode(tz, &mode); - if (result) - return result; + mode = thermal_zone_device_get_mode(tz); return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" : "disabled"); @@ -425,30 +422,13 @@ static struct attribute_group thermal_zone_attribute_group = { .attrs = thermal_zone_dev_attrs, }; -/* We expose mode only if .get_mode is present */ static struct attribute *thermal_zone_mode_attrs[] = { &dev_attr_mode.attr, NULL, }; -static umode_t thermal_zone_mode_is_visible(struct kobject *kobj, - struct attribute *attr, - int attrno) -{ - struct device *dev = container_of(kobj, struct device, kobj); - struct thermal_zone_device *tz; - - tz = container_of(dev, struct thermal_zone_device, device); - - if (tz->ops->get_mode) - return attr->mode; - - return 0; -} - static struct attribute_group thermal_zone_mode_attribute_group = { .attrs = thermal_zone_mode_attrs, - .is_visible = thermal_zone_mode_is_visible, }; /* We expose passive only if passive trips are present */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 9ff8542b7e7d..efb481088035 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -86,8 +86,6 @@ struct thermal_zone_device_ops { struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*set_trips) (struct thermal_zone_device *, int, int); - int (*get_mode) (struct thermal_zone_device *, - enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, @@ -440,8 +438,12 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); -int thermal_zone_device_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode); +static inline enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ + return tz->mode; +} + int thermal_zone_device_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode); @@ -509,9 +511,9 @@ static inline int thermal_zone_unbind_cooling_device( struct thermal_zone_device *tz, int trip, struct thermal_cooling_device *cdev) { return -ENODEV; } -static inline int thermal_zone_device_get_mode(struct thermal_zone_device *tz, - enum thermal_device_mode *mode) -{ return -ENODEV; } +static inline enum thermal_device_mode +thermal_zone_device_get_mode(struct thermal_zone_device *tz) +{ return THERMAL_DEVICE_DISABLED; } static inline int thermal_zone_device_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) { return -ENODEV; } -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC v2 7/9] thermal: core: Monitor thermal zone after mode change 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (5 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 6/9] thermal: Remove get_mode() method Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 8/9] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz ` (2 subsequent siblings) 9 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Mode changing might imply a need to stop/start polling the device. monitor_thermal_zone() when mode changes. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_core.h | 2 ++ drivers/thermal/thermal_sysfs.c | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a59c3411fb9c..7637ddb79813 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,7 +305,7 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } -static void monitor_thermal_zone(struct thermal_zone_device *tz) +void monitor_thermal_zone(struct thermal_zone_device *tz) { mutex_lock(&tz->lock); diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index a9bf00e91d64..469258778161 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -89,6 +89,8 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, unsigned long new_state) {} #endif /* CONFIG_THERMAL_STATISTICS */ +void monitor_thermal_zone(struct thermal_zone_device *tz); + /* device tree support */ #ifdef CONFIG_THERMAL_OF int of_parse_thermal_zones(void); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index cbb27b3c96d2..bc34d0f9768b 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -62,11 +62,14 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); + enum thermal_device_mode old_mode, mode; int result; if (!tz->ops->set_mode) return -EPERM; + old_mode = thermal_zone_device_get_mode(tz); + if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) result = thermal_zone_device_enable(tz); else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) @@ -77,6 +80,10 @@ mode_store(struct device *dev, struct device_attribute *attr, if (result) return result; + mode = thermal_zone_device_get_mode(tz); + if (mode != old_mode) + monitor_thermal_zone(tz); + return count; } -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC v2 8/9] thermal: of: Monitor thermal zone after enabling it 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (6 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 7/9] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 9/9] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-14 21:52 ` [RFC v2 0/9] Stop monitoring disabled devices Ezequiel Garcia 9 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz thermal/of calls its own ->set_mode() method, so monitor thermal zone afterwards. This is needed for the DISABLED->ENABLED transition. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/of-thermal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 0f1e134e90ea..aa4cbc904c5c 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -542,8 +542,11 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, if (id == sensor_id) { tzd = thermal_zone_of_add_sensor(child, sensor_np, data, ops); - if (!IS_ERR(tzd)) + if (!IS_ERR(tzd)) { thermal_zone_device_enable(tzd); + thermal_zone_device_update(tzd, + THERMAL_EVENT_UNSPECIFIED); + } of_node_put(child); goto exit; -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* [RFC v2 9/9] thermal: core: Stop polling DISABLED thermal devices 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (7 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 8/9] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz @ 2020-04-14 18:01 ` Andrzej Pietrasiewicz 2020-04-14 21:52 ` [RFC v2 0/9] Stop monitoring disabled devices Ezequiel Garcia 9 siblings, 0 replies; 137+ messages in thread From: Andrzej Pietrasiewicz @ 2020-04-14 18:01 UTC (permalink / raw) To: linux-pm Cc: Zhang Rui, Rafael J . Wysocki, Len Brown, Jiri Pirko, Ido Schimmel, David S . Miller, Peter Kaestle, Darren Hart, Andy Shevchenko, Support Opensource, Daniel Lezcano, Amit Kucheria, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team, Allison Randal, Enrico Weigelt, Gayatri Kammela, Thomas Gleixner, linux-acpi, netdev, platform-driver-x86, linux-arm-kernel, kernel, Andrzej Pietrasiewicz Polling DISABLED devices is not desired, as all such "disabled" devices are meant to be handled by userspace. Add a new mode: THERMAL_DEVICE_INITIAL. It is dedicated to handle devices which must be initially DISABLED, but which are polled at startup nonetheless. THERMAL_DEVICE_INITIAL shall be reported as "enabled" in sysfs to keep the userspace interface intact. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> --- drivers/thermal/thermal_core.c | 18 ++++++++++++++++-- drivers/thermal/thermal_sysfs.c | 4 ++-- include/linux/thermal.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 7637ddb79813..c3c966a5a50b 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,13 +305,22 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } +static inline bool should_stop_polling(struct thermal_zone_device *tz) +{ + return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; +} + void monitor_thermal_zone(struct thermal_zone_device *tz) { + bool stop; + + stop = should_stop_polling(tz); + mutex_lock(&tz->lock); - if (tz->passive) + if (!stop && tz->passive) thermal_zone_device_set_polling(tz, tz->passive_delay); - else if (tz->polling_delay) + else if (!stop && tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); else thermal_zone_device_set_polling(tz, 0); @@ -490,6 +499,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, { int count; + if (should_stop_polling(tz)) + return; + if (atomic_read(&in_suspend)) return; @@ -1356,6 +1368,8 @@ thermal_zone_device_register(const char *type, int trips, int mask, list_add_tail(&tz->node, &thermal_tz_list); mutex_unlock(&thermal_list_lock); + tz->mode = THERMAL_DEVICE_INITIAL; + /* Bind cooling devices for this zone */ bind_tz(tz); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index bc34d0f9768b..9d26196735bd 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -53,8 +53,8 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) mode = thermal_zone_device_get_mode(tz); - return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" - : "disabled"); + return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_DISABLED ? "disabled" + : "enabled"); } static ssize_t diff --git a/include/linux/thermal.h b/include/linux/thermal.h index efb481088035..2f61f461da50 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -50,6 +50,7 @@ struct thermal_instance; enum thermal_device_mode { THERMAL_DEVICE_DISABLED = 0, THERMAL_DEVICE_ENABLED, + THERMAL_DEVICE_INITIAL, }; enum thermal_trip_type { -- 2.17.1 ^ permalink raw reply related [flat|nested] 137+ messages in thread
* Re: [RFC v2 0/9] Stop monitoring disabled devices 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz ` (8 preceding siblings ...) 2020-04-14 18:01 ` [RFC v2 9/9] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz @ 2020-04-14 21:52 ` Ezequiel Garcia 9 siblings, 0 replies; 137+ messages in thread From: Ezequiel Garcia @ 2020-04-14 21:52 UTC (permalink / raw) To: Andrzej Pietrasiewicz Cc: Linux-pm mailing list, Rafael J . Wysocki, platform-driver-x86, kernel, Fabio Estevam, Amit Kucheria, Daniel Lezcano, linux-acpi, NXP Linux Team, Darren Hart, Zhang Rui, Gayatri Kammela, Len Brown, Sascha Hauer, Ido Schimmel, Jiri Pirko, Thomas Gleixner, Allison Randal, linux-arm-kernel, Support Opensource, Shawn Guo, Peter Kaestle, Pengutronix Kernel Team, Networking, Enrico Weigelt, David S . Miller, Andy Shevchenko Hi Andrzej, Thanks for your patches. On Tue, 14 Apr 2020 at 15:01, Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote: > > This is the second iteration of this RFC. > > The series now focuses on cleaning up the code in the first place. > [..] > 12 files changed, 180 insertions(+), 208 deletions(-) > Compared with the previous iteration, and just judging by this diffstat, I think it's a step in the right direction. Nice job :-) Ezequiel ^ permalink raw reply [flat|nested] 137+ messages in thread
end of thread, other threads:[~2020-06-29 21:05 UTC | newest] Thread overview: 137+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <Message-ID: <4493c0e4-51aa-3907-810c-74949ff27ca4@samsung.com> 2020-05-28 19:20 ` [PATCH v4 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-05-29 14:50 ` Guenter Roeck 2020-06-24 8:16 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz 2020-05-29 14:48 ` Guenter Roeck 2020-05-29 15:13 ` Andrzej Pietrasiewicz 2020-05-29 15:34 ` Guenter Roeck 2020-06-24 9:38 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz 2020-05-29 14:51 ` Guenter Roeck 2020-06-24 9:39 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz 2020-06-24 9:40 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz 2020-06-24 9:47 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz 2020-06-24 9:49 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz 2020-06-24 9:51 ` Bartlomiej Zolnierkiewicz 2020-06-26 16:08 ` Andrzej Pietrasiewicz 2020-05-28 19:20 ` [PATCH v4 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz 2020-06-24 10:00 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-06-24 10:02 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 2020-05-28 19:20 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 2020-06-24 10:03 ` Bartlomiej Zolnierkiewicz 2020-06-01 11:36 ` [PATCH v4 02/11] thermal: Store thermal mode in a dedicated enum Peter Kästle 2020-06-01 11:36 ` [PATCH v4 04/11] thermal: Store device mode in struct thermal_zone_device Peter Kästle 2020-06-01 11:37 ` [PATCH v4 05/11] thermal: remove get_mode() operation of drivers Peter Kästle 2020-06-01 11:37 ` [PATCH v4 07/11] thermal: Use mode helpers in drivers Peter Kästle 2020-06-01 11:38 ` [PATCH v4 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Peter Kästle 2020-06-01 11:38 ` [PATCH v4 11/11] thermal: Rename set_mode() to change_mode() Peter Kästle 2020-06-23 14:37 ` [PATCH v4 00/11] Stop monitoring disabled devices Daniel Lezcano 2020-06-26 17:37 ` [PATCH v5 " Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz 2020-06-29 7:19 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz 2020-06-29 7:20 ` Amit Kucheria 2020-06-26 17:37 ` [PATCH v5 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz 2020-06-26 20:50 ` kernel test robot 2020-06-26 20:50 ` [RFC PATCH] thermal: thermal_zone_device_set_mode() can be static kernel test robot 2020-06-26 20:55 ` [PATCH v5 06/11] thermal: Add mode helpers kernel test robot 2020-06-29 7:04 ` Amit Kucheria 2020-06-29 11:16 ` [PATCH v6 00/11] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 01/11] acpi: thermal: Fix error handling in the register function Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 02/11] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 03/11] thermal: Add current mode to thermal zone device Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 04/11] thermal: Store device mode in struct thermal_zone_device Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 05/11] thermal: remove get_mode() operation of drivers Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 06/11] thermal: Add mode helpers Andrzej Pietrasiewicz 2020-06-29 12:08 ` Daniel Lezcano 2020-06-29 11:16 ` [PATCH v6 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz 2020-06-29 11:16 ` [PATCH v6 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 07/11] thermal: Use mode helpers in drivers Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 08/11] thermal: Explicitly enable non-changing thermal zone devices Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 09/11] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 10/11] thermal: Simplify or eliminate unnecessary set_mode() methods Andrzej Pietrasiewicz 2020-06-26 17:37 ` [PATCH v5 11/11] thermal: Rename set_mode() to change_mode() Andrzej Pietrasiewicz 2020-06-01 10:02 ` [PATCH v4 00/11] Stop monitoring disabled devices Peter Kästle 2020-06-01 10:20 ` Andrzej Pietrasiewicz 2020-04-07 17:49 [RFC 0/8] " Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 1/8] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz [not found] ` <CGME20200415091204eucas1p1983548c2db52d8d0c2a5367034ec80dd@eucas1p1.samsung.com> 2020-04-15 9:12 ` Bartlomiej Zolnierkiewicz 2020-04-07 17:49 ` [RFC 2/8] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz [not found] ` <CGME20200415100543eucas1p24e24293da39844ca8791db86af5365a7@eucas1p2.samsung.com> 2020-04-15 10:05 ` Bartlomiej Zolnierkiewicz 2020-04-07 17:49 ` [RFC 3/8] thermal: Store thermal mode in a dedicated enum Andrzej Pietrasiewicz [not found] ` <CGME20200415100944eucas1p1dcfeb784e790ca2fc3417fd2797e3f5d@eucas1p1.samsung.com> 2020-04-15 10:09 ` Bartlomiej Zolnierkiewicz 2020-04-07 17:49 ` [RFC 4/8] thermal: core: Introduce THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 5/8] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 6/8] thermal: Set initial state to THERMAL_DEVICE_INITIAL Andrzej Pietrasiewicz 2020-04-07 17:49 ` [RFC 7/8] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz [not found] ` <CGME20200415101829eucas1p18e21324d3c39926fffc6c8b5dc52f206@eucas1p1.samsung.com> 2020-04-15 10:18 ` Bartlomiej Zolnierkiewicz 2020-04-07 17:49 ` [RFC 8/8] thermal: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-09 10:29 ` [RFC 0/8] Stop monitoring disabled devices Daniel Lezcano 2020-04-09 11:10 ` Andrzej Pietrasiewicz [not found] ` <CGME20200415104010eucas1p101278e53e34a2e56dfc7c82b533a9122@eucas1p1.samsung.com> 2020-04-15 10:40 ` Bartlomiej Zolnierkiewicz 2020-04-17 16:23 ` Andrzej Pietrasiewicz 2020-04-19 11:42 ` Bartlomiej Zolnierkiewicz 2020-04-17 21:11 ` Peter Kästle 2020-04-14 18:00 ` [RFC v2 0/9] " Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops Andrzej Pietrasiewicz 2020-04-15 9:23 ` Daniel Lezcano 2020-04-14 18:00 ` [RFC v2 2/9] thermal: Eliminate an always-false condition Andrzej Pietrasiewicz 2020-04-14 18:00 ` [RFC v2 3/9] thermal: Properly handle mode values in .set_mode() Andrzej Pietrasiewicz 2020-04-14 22:14 ` Daniel Lezcano 2020-04-14 18:01 ` [RFC v2 4/9] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-14 22:30 ` Daniel Lezcano 2020-04-14 18:01 ` [RFC v2 5/9] thermal: Store mode in thermal_zone_device Andrzej Pietrasiewicz 2020-04-15 10:55 ` Daniel Lezcano 2020-04-17 16:20 ` [RFC v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-17 16:20 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-17 20:44 ` Andy Shevchenko 2020-04-19 11:38 ` Bartlomiej Zolnierkiewicz 2020-04-19 13:10 ` Bartlomiej Zolnierkiewicz 2020-04-20 18:17 ` [PATCH 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-22 7:49 ` kbuild test robot 2020-04-22 17:14 ` Andrzej Pietrasiewicz 2020-04-22 17:03 ` kbuild test robot 2020-04-22 17:15 ` Andrzej Pietrasiewicz 2020-04-20 18:17 ` [PATCH 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-22 16:12 ` [PATCH RESEND 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-23 14:39 ` Bartlomiej Zolnierkiewicz 2020-04-23 16:57 ` [PATCH v3 0/2] Stop monitoring disabled devices Andrzej Pietrasiewicz 2020-04-23 16:57 ` [PATCH v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-05-04 7:00 ` Bartlomiej Zolnierkiewicz 2020-04-23 16:57 ` [PATCH v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-24 9:03 ` Zhang, Rui 2020-04-27 14:20 ` Zhang, Rui 2020-04-27 18:34 ` Andrzej Pietrasiewicz 2020-04-28 13:55 ` Zhang, Rui 2020-04-20 11:03 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Andrzej Pietrasiewicz 2020-04-20 18:19 ` Andrzej Pietrasiewicz 2020-05-23 21:24 ` Daniel Lezcano 2020-05-25 19:35 ` Andrzej Pietrasiewicz 2020-05-25 22:08 ` Daniel Lezcano 2020-05-26 16:56 ` Andrzej Pietrasiewicz 2020-05-27 13:30 ` Bartlomiej Zolnierkiewicz 2020-04-17 16:20 ` [RFC v3 2/2] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-19 13:50 ` [RFC v3 1/2] thermal: core: Let thermal zone device's mode be stored in its struct Peter Kästle 2020-04-14 18:01 ` [RFC v2 6/9] thermal: Remove get_mode() method Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 7/9] thermal: core: Monitor thermal zone after mode change Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 8/9] thermal: of: Monitor thermal zone after enabling it Andrzej Pietrasiewicz 2020-04-14 18:01 ` [RFC v2 9/9] thermal: core: Stop polling DISABLED thermal devices Andrzej Pietrasiewicz 2020-04-14 21:52 ` [RFC v2 0/9] Stop monitoring disabled devices Ezequiel Garcia
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).