hwmon: (acpi_power_meter) Replace the deprecated hwmon_device_register
authorHuisong Li <lihuisong@huawei.com>
Wed, 19 Mar 2025 02:06:38 +0000 (10:06 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 21 Mar 2025 15:01:05 +0000 (08:01 -0700)
commit16746ce8adfe04f9ff8df75c1133286ba93c0e17
tree02dd871d39e687d9cbf96c4d479f3d7fd209aa9e
parentbf1bb26f23f10f835e596337604d32d34ab798a6
hwmon: (acpi_power_meter) Replace the deprecated hwmon_device_register

When load this mode, we can see the following log:
"power_meter ACPI000D:00: hwmon_device_register() is deprecated. Please
 convert the driver to use hwmon_device_register_with_info()."

So replace hwmon_device_register with hwmon_device_register_with_info.

These attributes, 'power_accuracy', 'power_cap_hyst', 'power_average_min'
and 'power_average_max', should have been placed in hwmon_chip_info as
power data type. But these attributes are displayed as string format on
the following case:
a) power1_accuracy  --> display like '90.0%'
b) power1_cap_hyst  --> display 'unknown' when its value is 0xFFFFFFFF
c) power1_average_min/max --> display 'unknown' when its value is
      negative.
To avoid any changes in the display of these sysfs interfaces, we can't
modifiy the type of these attributes in hwmon core and have to put them
to extra_groups.

Please note that the path of these sysfs interfaces are modified
accordingly if use hwmon_device_register_with_info():
old: all sysfs interfaces are under acpi device, namely,
     /sys/class/hwmon/hwmonX/device/
now: all sysfs interfaces are under hwmon device, namely,
     /sys/class/hwmon/hwmonX/
The new ABI does not guarantee that the underlying path remains the same.
But we have to accept this change so as to replace the deprecated API.
Fortunately, some userspace application, like libsensors, would scan
the two path and handles this automatically. So we can accept this change
so as to drop the deprecated message.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://lore.kernel.org/r/20250319020638.59925-1-lihuisong@huawei.com
[groeck: Fixed some multi-line alignment issues;
 reverted to 32-bit arithmetic in power1_accuracy_show()
 fixed bad return code from power_meter_is_visible()]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/acpi_power_meter.c