Re: [PATCH v7 4/6] platform/x86: Add Lenovo Capability Data 01 WMI Driver

From: ALOK TIWARI
Date: Sat May 03 2025 - 04:38:47 EST




On 03-05-2025 05:31, Derek J. Clark wrote:
Adds lenovo-wmi-capdata01 driver which provides the
LENOVO_CAPABILITY_DATA_01 WMI data block that comes on "Other Mode"
enabled hardware. Provides an interface for querying if a given
attribute is supported by the hardware, as well as its default_value,
max_value, min_value, and step increment.

Reviewed-by: Armin Wolf <W_Armin@xxxxxx>
Signed-off-by: Derek J. Clark <derekjohn.clark@xxxxxxxxx>
--
v7:
- Do memcpy instead of returning pointer in lwmi_cd01_get_data.
- Put list mutex inside lwmi_cd01_priv struct.
- Unregister from acpi events on dev remove.
- Fix typos.
v6:
- Recache capabiltiy data on ACPI AC events to ensure accutare
max_value.
- Fix typos and rewordings from v5 review.
v5:
- Return to cache at device initialization. On component bind, pass a
pointer to lenovo-wmi-other.
- Fixes from v4 review.
v4:
- Make driver data a private struct, remove references from Other Mode
driver.
- Don't cache data at device initialization. Instead, on component bind,
cache the data on a member variable of the Other Mode driver data
passed as a void pointer.
- Add header file for capdata01 structs.
- Add new struct to pass capdata01 array data and array length to Other
Mode.
v3:
- Add as component to lenovo-wmi-other driver.
v2:
- Use devm_kmalloc to ensure driver can be instanced, remove global
reference.
- Ensure reverse Christmas tree for all variable declarations.
- Remove extra whitespace.
- Use guard(mutex) in all mutex instances, global mutex.
- Use pr_fmt instead of adding the driver name to each pr_err.
- Remove noisy pr_info usage.
- Rename capdata_wmi to lenovo_wmi_cd01_priv and cd01_wmi to priv.
- Use list to get the lenovo_wmi_cd01_priv instance in
lenovo_wmi_capdata01_get as none of the data provided by the macros
that will use it can pass a member of the struct for use in
container_of.
---
MAINTAINERS | 1 +
drivers/platform/x86/Kconfig | 4 +
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/lenovo-wmi-capdata01.c | 301 ++++++++++++++++++++
drivers/platform/x86/lenovo-wmi-capdata01.h | 25 ++
5 files changed, 332 insertions(+)
create mode 100644 drivers/platform/x86/lenovo-wmi-capdata01.c
create mode 100644 drivers/platform/x86/lenovo-wmi-capdata01.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 2b4b06e81192..1b22e41cc730 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13164,6 +13164,7 @@ L: platform-driver-x86@xxxxxxxxxxxxxxx
S: Maintained
F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst
F: Documentation/wmi/devices/lenovo-wmi-other.rst
+F: drivers/platform/x86/lenovo-wmi-capdata01.*
F: drivers/platform/x86/lenovo-wmi-events.*
F: drivers/platform/x86/lenovo-wmi-helpers.*
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 13b8f4ac5dc5..64663667f0cb 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -467,6 +467,10 @@ config LENOVO_WMI_HELPERS
tristate
depends on ACPI_WMI
+config LENOVO_WMI_DATA01
+ tristate
+ depends on ACPI_WMI
+
config IDEAPAD_LAPTOP
tristate "Lenovo IdeaPad Laptop Extras"
depends on ACPI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index fc039839286a..7a35c77221b7 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o
obj-$(CONFIG_YT2_1380) += lenovo-yoga-tab2-pro-1380-fastcharger.o
obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o
+obj-$(CONFIG_LENOVO_WMI_DATA01) += lenovo-wmi-capdata01.o
obj-$(CONFIG_LENOVO_WMI_EVENTS) += lenovo-wmi-events.o
obj-$(CONFIG_LENOVO_WMI_HELPERS) += lenovo-wmi-helpers.o
diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.c b/drivers/platform/x86/lenovo-wmi-capdata01.c
new file mode 100644
index 000000000000..419b51f7f7c3
--- /dev/null
+++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
@@ -0,0 +1,301 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo Capability Data 01 WMI Data Block driver.
+ *
+ * Lenovo Capability Data 01 provides information on tunable attributes used by
+ * the "Other Mode" WMI interface. The data includes if the attribute is
+ * supported by the hardware, the default_value, max_value, min_value, and step
+ * increment. Each attibute has multiple pages, one for each of the thermal

typo attibute -> attribute

+ * modes managed by the Gamezone interface.
+ *
+ * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@xxxxxxxxx>
+ */
+
[clip]
+
+/**
+ * lwmi_cd01_component_bind() - Bind component to master device.
+ * @cd01_dev: Pointer to the lenovo-wmi-capdata01 driver parent device.
+ * @om_dev: Pointer to the lenovo-wmi-other driver parent device.
+ * @data: capdata01_list object pointer used to return the capability data.
+ *
+ * On lenovo-wmi-other's master bind, provide a pointer to the local capdata01
+ * list. This is used to call lwmi_cd01_get_data to look up attribute data
+ * from the lenovo-wmi-other driver.
+ *
+:* Return: 0 on success, or an error code.

typo :* Return -> * Return:


Other than that, LGTM.

Reviewed-by: Alok Tiwari <alok.a.tiwari@xxxxxxxxxx>

Thanks,
Alok