]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
power: supply: core: Avoid duplicate hwmon device from thermal framework
authorChen-Yu Tsai <wenst@chromium.org>
Tue, 13 Jun 2023 09:07:23 +0000 (17:07 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 19 Jul 2023 21:58:52 +0000 (23:58 +0200)
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>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_core.c

index 3791aec69ddc675404ccc5974710a01ca49be9ad..4aa466c945e2574d16811216fdd17aecfd14511e 100644 (file)
@@ -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);