platform/x86: dell-ddv: Implement the battery matching algorithm
authorArmin Wolf <W_Armin@gmx.de>
Tue, 29 Apr 2025 00:36:04 +0000 (02:36 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 12 May 2025 10:20:39 +0000 (13:20 +0300)
commit058de163a376b28816f91ff5e2fe6d7bc227e2ae
tree35a3622bfc941d70477df5c96cc803f24b328521
parentf4856c20c137a73d73e448caa3964098024248bf
platform/x86: dell-ddv: Implement the battery matching algorithm

Since commit db0a507cb24d ("ACPICA: Update integer-to-hex-string
conversions") the battery serial number is no longer distorted,
allowing us to finally implement the battery matching algorithm.

The battery matchign algorithm is necessary when translating between
ACPI batteries and the associated indices used by the WMI interface
based on the battery serial number. Since this serial number can only
be retrieved when the battery is present we cannot perform the initial
translation inside dell_wmi_ddv_add_battery() because the ACPI battery
might be absent at this point in time.

Introduce dell_wmi_ddv_battery_translate() which implements the
battery matching algorithm and replaces dell_wmi_ddv_battery_index().
Also implement a translation cache for caching previous translations
between ACPI batteries and indices. This is necessary because
performing a translation can be very expensive.

Tested on a Dell Inspiron 3505.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20250429003606.303870-2-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Documentation/wmi/devices/dell-wmi-ddv.rst
drivers/platform/x86/dell/dell-wmi-ddv.c