linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: core: Avoid duplicate hwmon device from thermal framework
@ 2023-06-13  9:07 Chen-Yu Tsai
  2023-07-19 22:13 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Chen-Yu Tsai @ 2023-06-13  9:07 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Chen-Yu Tsai, linux-pm, linux-kernel

When the power supply device being registered supports a temperature
readout, the core registers a thermal zone for it. The thermal core
would register a hwmon device for that unless told otherwise.

When CONFIG_POWER_SUPPLY_HWMON is enabled, the power supply core creates
a hwmon device. This results in a second entry, one which has a better
name than the one registered through the thermal framework. It could
potentially have readouts other than temperature.

To simplify the result, tell the thermal framework to not register a
hwmon device if CONFIG_POWER_SUPPLY_HWMON is enabled. The result is
one hwmon device with all the readings the device supports.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/power/supply/power_supply_core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 3791aec69ddc..4aa466c945e2 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1305,8 +1305,12 @@ static int psy_register_thermal(struct power_supply *psy)
 
 	/* Register battery zone device psy reports temperature */
 	if (psy_has_property(psy->desc, POWER_SUPPLY_PROP_TEMP)) {
+		/* Prefer our hwmon device and avoid duplicates */
+		struct thermal_zone_params tzp = {
+			.no_hwmon = IS_ENABLED(CONFIG_POWER_SUPPLY_HWMON)
+		};
 		psy->tzd = thermal_zone_device_register(psy->desc->name,
-				0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
+				0, 0, psy, &psy_tzd_ops, &tzp, 0, 0);
 		if (IS_ERR(psy->tzd))
 			return PTR_ERR(psy->tzd);
 		ret = thermal_zone_device_enable(psy->tzd);
-- 
2.41.0.162.gfafddb0af9-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power: supply: core: Avoid duplicate hwmon device from thermal framework
  2023-06-13  9:07 [PATCH] power: supply: core: Avoid duplicate hwmon device from thermal framework Chen-Yu Tsai
@ 2023-07-19 22:13 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2023-07-19 22:13 UTC (permalink / raw)
  To: Chen-Yu Tsai; +Cc: linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]

Hi,

On Tue, Jun 13, 2023 at 05:07:23PM +0800, Chen-Yu Tsai wrote:
> When the power supply device being registered supports a temperature
> readout, the core registers a thermal zone for it. The thermal core
> would register a hwmon device for that unless told otherwise.
> 
> When CONFIG_POWER_SUPPLY_HWMON is enabled, the power supply core creates
> a hwmon device. This results in a second entry, one which has a better
> name than the one registered through the thermal framework. It could
> potentially have readouts other than temperature.
> 
> To simplify the result, tell the thermal framework to not register a
> hwmon device if CONFIG_POWER_SUPPLY_HWMON is enabled. The result is
> one hwmon device with all the readings the device supports.

Thanks, queued.

-- Sebastian

>  drivers/power/supply/power_supply_core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 3791aec69ddc..4aa466c945e2 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1305,8 +1305,12 @@ static int psy_register_thermal(struct power_supply *psy)
>  
>  	/* Register battery zone device psy reports temperature */
>  	if (psy_has_property(psy->desc, POWER_SUPPLY_PROP_TEMP)) {
> +		/* Prefer our hwmon device and avoid duplicates */
> +		struct thermal_zone_params tzp = {
> +			.no_hwmon = IS_ENABLED(CONFIG_POWER_SUPPLY_HWMON)
> +		};
>  		psy->tzd = thermal_zone_device_register(psy->desc->name,
> -				0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
> +				0, 0, psy, &psy_tzd_ops, &tzp, 0, 0);
>  		if (IS_ERR(psy->tzd))
>  			return PTR_ERR(psy->tzd);
>  		ret = thermal_zone_device_enable(psy->tzd);
> -- 
> 2.41.0.162.gfafddb0af9-goog
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-19 22:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13  9:07 [PATCH] power: supply: core: Avoid duplicate hwmon device from thermal framework Chen-Yu Tsai
2023-07-19 22:13 ` Sebastian Reichel

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).