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.
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
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 | 2 +
drivers/platform/x86/Kconfig | 4 +
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
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.c
+F: drivers/platform/x86/lenovo-wmi-capdata01.h
F: drivers/platform/x86/lenovo-wmi-events.c
F: drivers/platform/x86/lenovo-wmi-events.h
F: drivers/platform/x86/lenovo-wmi-helpers.c
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..b6876611ffd9
--- /dev/null
+++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides
+ * information on tunable attributes used by the "Other Mode" WMI interface,
+ * including if it is supported by the hardware, the default_value, max_value,
+ * min_value, and step increment.
+ *
+ * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
+ */
+
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/gfp_types.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "lenovo-wmi-capdata01.h"
+
+/* Interface GUIDs */
+#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
+
+struct lwmi_cd01_priv {
+ struct wmi_device *wdev;
+};
+
+/*
+ * lenovo_cd01_component_bind() - On master bind, caches all capability data on
+ * the master device.
+ * @cd01_dev: Pointer to the capability data 01 parent device.
+ * @om_dev: Pointer to the other mode parent device.
+ * @data: capdata01_list object pointer to return the capability data with.
+ *
+ * Returns: 0, or an error.
+ */
+static int lenovo_cd01_component_bind(struct device *cd01_dev,
+ struct device *om_dev, void *data)
+{
+ struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
+ int count, idx;
+
+ if (!priv)
+ return -ENODEV;
+
+ count = wmidev_instance_count(priv->wdev);
+
+ if (count == 0)
+ return -EINVAL;
+
+ ((struct cd01_list *)data)->count = count;
+ ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
+ sizeof(struct capdata01 *),
+ GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ for (idx = 0; idx < count; idx++) {
+ union acpi_object *ret_obj __free(kfree) = NULL;
+
+ ret_obj = wmidev_block_query(priv->wdev, idx);
+ if (!ret_obj) {
+ ((struct cd01_list *)data)->data[idx] = NULL;
+ continue;
+ }
+ if (ret_obj->type != ACPI_TYPE_BUFFER) {
+ ((struct cd01_list *)data)->data[idx] = NULL;
+ continue;
+ }
+
+ if (ret_obj->buffer.length != sizeof(struct capdata01)) {
+ ((struct cd01_list *)data)->data[idx] = NULL;
+ continue;
+ }
+
+ ((struct cd01_list *)data)->data[idx] =
+ devm_kmemdup(om_dev, ret_obj->buffer.pointer,
+ ret_obj->buffer.length, GFP_KERNEL);
+ }
+ return 0;
+}
+
+static const struct component_ops lenovo_cd01_component_ops = {
+ .bind = lenovo_cd01_component_bind,
+};
+
+static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
+
+{
+ struct lwmi_cd01_priv *priv;
+ int ret;
+
+ priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->wdev = wdev;
+ dev_set_drvdata(&wdev->dev, priv);
+
+ ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
+
+ return ret;
+}
+
+static void lwmi_cd01_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &lenovo_cd01_component_ops);
+}
+
+static const struct wmi_device_id lwmi_cd01_id_table[] = {
+ { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver lwmi_cd01_driver = {
+ .driver = {
+ .name = "lenovo_wmi_cd01",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = lwmi_cd01_id_table,
+ .probe = lwmi_cd01_probe,
+ .remove = lwmi_cd01_remove,
+ .no_singleton = true,
+};
+
+int lwmi_cd01_match(struct device *dev, void *data)
+{
+ return dev->driver == &lwmi_cd01_driver.driver;
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
+
+module_wmi_driver(lwmi_cd01_driver);
+
+MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
+MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
+MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
new file mode 100644
index 000000000000..c7067a8d0398
--- /dev/null
+++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
+ *
+ */
+
+#ifndef _LENOVO_WMI_CAPDATA01_H_
+#define _LENOVO_WMI_CAPDATA01_H_
+
+#include <linux/device.h>
+#include <linux/types.h>
+
+struct capdata01 {
+ u32 id;
+ u32 supported;
+ u32 default_value;
+ u32 step;
+ u32 min_value;
+ u32 max_value;
+};
+
+struct cd01_list {
+ struct capdata01 **data;
+ int count;
+};
+
+int lwmi_cd01_match(struct device *dev, void *data);
+
+#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
--
2.49.0
On Mon, 17 Mar 2025, 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.
>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> 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 | 2 +
> drivers/platform/x86/Kconfig | 4 +
> drivers/platform/x86/Makefile | 1 +
> drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> 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.c
> +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> F: drivers/platform/x86/lenovo-wmi-events.c
> F: drivers/platform/x86/lenovo-wmi-events.h
> F: drivers/platform/x86/lenovo-wmi-helpers.c
> 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..b6876611ffd9
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> @@ -0,0 +1,136 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * LENOVO_CAPABILITY_DATA_01 WMI data block driver.
Add a empty comment line here, you might want to rephrase the opening of
the paragraph after splitting these apart.
> This interface provides
> + * information on tunable attributes used by the "Other Mode" WMI interface,
> + * including if it is supported by the hardware, the default_value, max_value,
> + * min_value, and step increment.
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + */
> +
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/container_of.h>
> +#include <linux/device.h>
> +#include <linux/gfp_types.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
Add an empty line here please.
> +#include "lenovo-wmi-capdata01.h"
> +
> +/* Interface GUIDs */
> +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> +
> +struct lwmi_cd01_priv {
> + struct wmi_device *wdev;
> +};
> +
> +/*
> + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> + * the master device.
Is this "On master bind" something that the caller should be doing? IMO,
that would belong to description paragraph instead of the function
summary.
> + * @cd01_dev: Pointer to the capability data 01 parent device.
> + * @om_dev: Pointer to the other mode parent device.
> + * @data: capdata01_list object pointer to return the capability data with.
> + *
> + * Returns: 0, or an error.
Return:
> + */
> +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> + struct device *om_dev, void *data)
> +{
> + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> + int count, idx;
> +
> + if (!priv)
> + return -ENODEV;
> +
> + count = wmidev_instance_count(priv->wdev);
> +
> + if (count == 0)
> + return -EINVAL;
> +
> + ((struct cd01_list *)data)->count = count;
Please create a local variable with the correct type and since data is
void *, you don't need to cast it while assigning to that local variable.
> + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> + sizeof(struct capdata01 *),
sizeof() should preferrably take the type directly from ->data (with the
correct amount of * chars).
> + GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + for (idx = 0; idx < count; idx++) {
> + union acpi_object *ret_obj __free(kfree) = NULL;
> +
> + ret_obj = wmidev_block_query(priv->wdev, idx);
> + if (!ret_obj) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> + if (ret_obj->type != ACPI_TYPE_BUFFER) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
You could consider joining these 3 if()s with || to avoid having to
repeat the NULL assignment and continue.
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + ((struct cd01_list *)data)->data[idx] =
> + devm_kmemdup(om_dev, ret_obj->buffer.pointer,
> + ret_obj->buffer.length, GFP_KERNEL);
> + }
> + return 0;
> +}
> +
> +static const struct component_ops lenovo_cd01_component_ops = {
> + .bind = lenovo_cd01_component_bind,
> +};
> +
> +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
> +
> +{
> + struct lwmi_cd01_priv *priv;
> + int ret;
> +
> + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->wdev = wdev;
> + dev_set_drvdata(&wdev->dev, priv);
> +
> + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
> +
> + return ret;
> +}
> +
> +static void lwmi_cd01_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &lenovo_cd01_component_ops);
> +}
> +
> +static const struct wmi_device_id lwmi_cd01_id_table[] = {
> + { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver lwmi_cd01_driver = {
> + .driver = {
> + .name = "lenovo_wmi_cd01",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = lwmi_cd01_id_table,
> + .probe = lwmi_cd01_probe,
> + .remove = lwmi_cd01_remove,
> + .no_singleton = true,
> +};
> +
> +int lwmi_cd01_match(struct device *dev, void *data)
> +{
> + return dev->driver == &lwmi_cd01_driver.driver;
> +}
> +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
> +
> +module_wmi_driver(lwmi_cd01_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
> +MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
> +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
> new file mode 100644
> index 000000000000..c7067a8d0398
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + *
Extra line
> + */
> +
> +#ifndef _LENOVO_WMI_CAPDATA01_H_
> +#define _LENOVO_WMI_CAPDATA01_H_
> +
> +#include <linux/device.h>
Please fwd declare struct device instead.
> +#include <linux/types.h>
> +
> +struct capdata01 {
> + u32 id;
> + u32 supported;
> + u32 default_value;
> + u32 step;
> + u32 min_value;
> + u32 max_value;
> +};
> +
> +struct cd01_list {
> + struct capdata01 **data;
> + int count;
> +};
> +
> +int lwmi_cd01_match(struct device *dev, void *data);
> +
> +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
>
--
i.
On Thu, Mar 27, 2025 at 5:56 AM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> On Mon, 17 Mar 2025, 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.
> >
> > Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> > ---
> > 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 | 2 +
> > drivers/platform/x86/Kconfig | 4 +
> > drivers/platform/x86/Makefile | 1 +
> > drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> > drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> > 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> > 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.c
> > +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> > F: drivers/platform/x86/lenovo-wmi-events.c
> > F: drivers/platform/x86/lenovo-wmi-events.h
> > F: drivers/platform/x86/lenovo-wmi-helpers.c
> > 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..b6876611ffd9
> > --- /dev/null
> > +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> > @@ -0,0 +1,136 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * LENOVO_CAPABILITY_DATA_01 WMI data block driver.
>
> Add a empty comment line here, you might want to rephrase the opening of
> the paragraph after splitting these apart.
>
> > This interface provides
> > + * information on tunable attributes used by the "Other Mode" WMI interface,
> > + * including if it is supported by the hardware, the default_value, max_value,
> > + * min_value, and step increment.
> > + *
> > + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> > + */
> > +
> > +#include <linux/cleanup.h>
> > +#include <linux/component.h>
> > +#include <linux/container_of.h>
> > +#include <linux/device.h>
> > +#include <linux/gfp_types.h>
> > +#include <linux/types.h>
> > +#include <linux/wmi.h>
>
> Add an empty line here please.
>
> > +#include "lenovo-wmi-capdata01.h"
> > +
> > +/* Interface GUIDs */
> > +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> > +
> > +struct lwmi_cd01_priv {
> > + struct wmi_device *wdev;
> > +};
> > +
> > +/*
> > + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> > + * the master device.
>
> Is this "On master bind" something that the caller should be doing? IMO,
> that would belong to description paragraph instead of the function
> summary.
>
Acked
> > + * @cd01_dev: Pointer to the capability data 01 parent device.
> > + * @om_dev: Pointer to the other mode parent device.
> > + * @data: capdata01_list object pointer to return the capability data with.
> > + *
> > + * Returns: 0, or an error.
>
> Return:
>
> > + */
> > +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> > + struct device *om_dev, void *data)
> > +{
> > + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> > + int count, idx;
> > +
> > + if (!priv)
> > + return -ENODEV;
> > +
> > + count = wmidev_instance_count(priv->wdev);
> > +
> > + if (count == 0)
> > + return -EINVAL;
> > +
> > + ((struct cd01_list *)data)->count = count;
>
> Please create a local variable with the correct type and since data is
> void *, you don't need to cast it while assigning to that local variable.
>
This will be reworked a bit with Armin's suggestions.
> > + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> > + sizeof(struct capdata01 *),
>
> sizeof() should preferrably take the type directly from ->data (with the
> correct amount of * chars).
>
With Armin's suggestion I'll be using struct_size, but I'll note this
for future reference, thanks.
> > + GFP_KERNEL);
> > + if (!data)
> > + return -ENOMEM;
> > +
> > + for (idx = 0; idx < count; idx++) {
> > + union acpi_object *ret_obj __free(kfree) = NULL;
> > +
> > + ret_obj = wmidev_block_query(priv->wdev, idx);
> > + if (!ret_obj) {
> > + ((struct cd01_list *)data)->data[idx] = NULL;
> > + continue;
> > + }
> > + if (ret_obj->type != ACPI_TYPE_BUFFER) {
> > + ((struct cd01_list *)data)->data[idx] = NULL;
> > + continue;
> > + }
> > +
> > + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
>
> You could consider joining these 3 if()s with || to avoid having to
> repeat the NULL assignment and continue.
>
devm_kzalloc will take care of the NULL assignment going forward. for
!ret_obj, should I return an error here instead? It seems like a
problem if that fails.
> > + ((struct cd01_list *)data)->data[idx] = NULL;
> > + continue;
> > + }
> > +
> > + ((struct cd01_list *)data)->data[idx] =
> > + devm_kmemdup(om_dev, ret_obj->buffer.pointer,
> > + ret_obj->buffer.length, GFP_KERNEL);
> > + }
> > + return 0;
> > +}
> > +
> > +static const struct component_ops lenovo_cd01_component_ops = {
> > + .bind = lenovo_cd01_component_bind,
> > +};
> > +
> > +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
> > +
> > +{
> > + struct lwmi_cd01_priv *priv;
> > + int ret;
> > +
> > + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> > + if (!priv)
> > + return -ENOMEM;
> > +
> > + priv->wdev = wdev;
> > + dev_set_drvdata(&wdev->dev, priv);
> > +
> > + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
> > +
> > + return ret;
> > +}
> > +
> > +static void lwmi_cd01_remove(struct wmi_device *wdev)
> > +{
> > + component_del(&wdev->dev, &lenovo_cd01_component_ops);
> > +}
> > +
> > +static const struct wmi_device_id lwmi_cd01_id_table[] = {
> > + { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
> > + {}
> > +};
> > +
> > +static struct wmi_driver lwmi_cd01_driver = {
> > + .driver = {
> > + .name = "lenovo_wmi_cd01",
> > + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> > + },
> > + .id_table = lwmi_cd01_id_table,
> > + .probe = lwmi_cd01_probe,
> > + .remove = lwmi_cd01_remove,
> > + .no_singleton = true,
> > +};
> > +
> > +int lwmi_cd01_match(struct device *dev, void *data)
> > +{
> > + return dev->driver == &lwmi_cd01_driver.driver;
> > +}
> > +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
> > +
> > +module_wmi_driver(lwmi_cd01_driver);
> > +
> > +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
> > +MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
> > +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
> > +MODULE_LICENSE("GPL");
> > diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
> > new file mode 100644
> > index 000000000000..c7067a8d0398
> > --- /dev/null
> > +++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
> > @@ -0,0 +1,29 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later
> > + *
> > + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> > + *
>
> Extra line
>
> > + */
> > +
> > +#ifndef _LENOVO_WMI_CAPDATA01_H_
> > +#define _LENOVO_WMI_CAPDATA01_H_
> > +
> > +#include <linux/device.h>
>
> Please fwd declare struct device instead.
>
> > +#include <linux/types.h>
> > +
> > +struct capdata01 {
> > + u32 id;
> > + u32 supported;
> > + u32 default_value;
> > + u32 step;
> > + u32 min_value;
> > + u32 max_value;
> > +};
> > +
> > +struct cd01_list {
> > + struct capdata01 **data;
> > + int count;
> > +};
> > +
> > +int lwmi_cd01_match(struct device *dev, void *data);
> > +
> > +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
> >
>
> --
> i.
>
On Wed, 2 Apr 2025, Derek John Clark wrote:
> On Thu, Mar 27, 2025 at 5:56 AM Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> >
> > On Mon, 17 Mar 2025, 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.
> > >
> > > Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> > > ---
> > > 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 | 2 +
> > > drivers/platform/x86/Kconfig | 4 +
> > > drivers/platform/x86/Makefile | 1 +
> > > drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> > > drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> > > 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> > > 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.c
> > > +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> > > F: drivers/platform/x86/lenovo-wmi-events.c
> > > F: drivers/platform/x86/lenovo-wmi-events.h
> > > F: drivers/platform/x86/lenovo-wmi-helpers.c
> > > 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..b6876611ffd9
> > > --- /dev/null
> > > +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> > > @@ -0,0 +1,136 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +/*
> > > + * LENOVO_CAPABILITY_DATA_01 WMI data block driver.
> >
> > Add a empty comment line here, you might want to rephrase the opening of
> > the paragraph after splitting these apart.
> >
> > > This interface provides
> > > + * information on tunable attributes used by the "Other Mode" WMI interface,
> > > + * including if it is supported by the hardware, the default_value, max_value,
> > > + * min_value, and step increment.
> > > + *
> > > + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> > > + */
> > > +
> > > +#include <linux/cleanup.h>
> > > +#include <linux/component.h>
> > > +#include <linux/container_of.h>
> > > +#include <linux/device.h>
> > > +#include <linux/gfp_types.h>
> > > +#include <linux/types.h>
> > > +#include <linux/wmi.h>
> >
> > Add an empty line here please.
> >
> > > +#include "lenovo-wmi-capdata01.h"
> > > +
> > > +/* Interface GUIDs */
> > > +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> > > +
> > > +struct lwmi_cd01_priv {
> > > + struct wmi_device *wdev;
> > > +};
> > > +
> > > +/*
> > > + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> > > + * the master device.
> >
> > Is this "On master bind" something that the caller should be doing? IMO,
> > that would belong to description paragraph instead of the function
> > summary.
> >
>
> Acked
>
> > > + * @cd01_dev: Pointer to the capability data 01 parent device.
> > > + * @om_dev: Pointer to the other mode parent device.
> > > + * @data: capdata01_list object pointer to return the capability data with.
> > > + *
> > > + * Returns: 0, or an error.
> >
> > Return:
> >
> > > + */
> > > +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> > > + struct device *om_dev, void *data)
> > > +{
> > > + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> > > + int count, idx;
> > > +
> > > + if (!priv)
> > > + return -ENODEV;
> > > +
> > > + count = wmidev_instance_count(priv->wdev);
> > > +
> > > + if (count == 0)
> > > + return -EINVAL;
> > > +
> > > + ((struct cd01_list *)data)->count = count;
> >
> > Please create a local variable with the correct type and since data is
> > void *, you don't need to cast it while assigning to that local variable.
> >
>
> This will be reworked a bit with Armin's suggestions.
>
> > > + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> > > + sizeof(struct capdata01 *),
> >
> > sizeof() should preferrably take the type directly from ->data (with the
> > correct amount of * chars).
> >
>
> With Armin's suggestion I'll be using struct_size, but I'll note this
> for future reference, thanks.
>
> > > + GFP_KERNEL);
> > > + if (!data)
> > > + return -ENOMEM;
> > > +
> > > + for (idx = 0; idx < count; idx++) {
> > > + union acpi_object *ret_obj __free(kfree) = NULL;
> > > +
> > > + ret_obj = wmidev_block_query(priv->wdev, idx);
> > > + if (!ret_obj) {
> > > + ((struct cd01_list *)data)->data[idx] = NULL;
> > > + continue;
> > > + }
> > > + if (ret_obj->type != ACPI_TYPE_BUFFER) {
> > > + ((struct cd01_list *)data)->data[idx] = NULL;
> > > + continue;
> > > + }
> > > +
> > > + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
> >
> > You could consider joining these 3 if()s with || to avoid having to
> > repeat the NULL assignment and continue.
> >
>
> devm_kzalloc will take care of the NULL assignment going forward. for
> !ret_obj, should I return an error here instead? It seems like a
> problem if that fails.
Sure, if you think something is an indication of a bigger problem that
requires giving up.
BTW, in general (not related to this particular comment), you don't have
reply/ack those review comments you're going to implement as I suggested.
I trust you to make the changes you don't contest :-).
That way, we can focus on the points that need further discussion.
--
i.
Am 02.04.25 um 23:22 schrieb Derek John Clark:
> On Thu, Mar 27, 2025 at 5:56 AM Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
>> On Mon, 17 Mar 2025, 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.
>>>
>>> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
>>> ---
>>> 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 | 2 +
>>> drivers/platform/x86/Kconfig | 4 +
>>> drivers/platform/x86/Makefile | 1 +
>>> drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
>>> drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
>>> 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
>>> --- a/MAINTAINERS
>>> +++ b/MAINTAINERS
>>> @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
>>> 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.c
>>> +F: drivers/platform/x86/lenovo-wmi-capdata01.h
>>> F: drivers/platform/x86/lenovo-wmi-events.c
>>> F: drivers/platform/x86/lenovo-wmi-events.h
>>> F: drivers/platform/x86/lenovo-wmi-helpers.c
>>> 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..b6876611ffd9
>>> --- /dev/null
>>> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
>>> @@ -0,0 +1,136 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/*
>>> + * LENOVO_CAPABILITY_DATA_01 WMI data block driver.
>> Add a empty comment line here, you might want to rephrase the opening of
>> the paragraph after splitting these apart.
>>
>>> This interface provides
>>> + * information on tunable attributes used by the "Other Mode" WMI interface,
>>> + * including if it is supported by the hardware, the default_value, max_value,
>>> + * min_value, and step increment.
>>> + *
>>> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
>>> + */
>>> +
>>> +#include <linux/cleanup.h>
>>> +#include <linux/component.h>
>>> +#include <linux/container_of.h>
>>> +#include <linux/device.h>
>>> +#include <linux/gfp_types.h>
>>> +#include <linux/types.h>
>>> +#include <linux/wmi.h>
>> Add an empty line here please.
>>
>>> +#include "lenovo-wmi-capdata01.h"
>>> +
>>> +/* Interface GUIDs */
>>> +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
>>> +
>>> +struct lwmi_cd01_priv {
>>> + struct wmi_device *wdev;
>>> +};
>>> +
>>> +/*
>>> + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
>>> + * the master device.
>> Is this "On master bind" something that the caller should be doing? IMO,
>> that would belong to description paragraph instead of the function
>> summary.
>>
> Acked
>
>>> + * @cd01_dev: Pointer to the capability data 01 parent device.
>>> + * @om_dev: Pointer to the other mode parent device.
>>> + * @data: capdata01_list object pointer to return the capability data with.
>>> + *
>>> + * Returns: 0, or an error.
>> Return:
>>
>>> + */
>>> +static int lenovo_cd01_component_bind(struct device *cd01_dev,
>>> + struct device *om_dev, void *data)
>>> +{
>>> + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
>>> + int count, idx;
>>> +
>>> + if (!priv)
>>> + return -ENODEV;
>>> +
>>> + count = wmidev_instance_count(priv->wdev);
>>> +
>>> + if (count == 0)
>>> + return -EINVAL;
>>> +
>>> + ((struct cd01_list *)data)->count = count;
>> Please create a local variable with the correct type and since data is
>> void *, you don't need to cast it while assigning to that local variable.
>>
> This will be reworked a bit with Armin's suggestions.
>
>>> + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
>>> + sizeof(struct capdata01 *),
>> sizeof() should preferrably take the type directly from ->data (with the
>> correct amount of * chars).
>>
> With Armin's suggestion I'll be using struct_size, but I'll note this
> for future reference, thanks.
>
>>> + GFP_KERNEL);
>>> + if (!data)
>>> + return -ENOMEM;
>>> +
>>> + for (idx = 0; idx < count; idx++) {
>>> + union acpi_object *ret_obj __free(kfree) = NULL;
>>> +
>>> + ret_obj = wmidev_block_query(priv->wdev, idx);
>>> + if (!ret_obj) {
>>> + ((struct cd01_list *)data)->data[idx] = NULL;
>>> + continue;
>>> + }
>>> + if (ret_obj->type != ACPI_TYPE_BUFFER) {
>>> + ((struct cd01_list *)data)->data[idx] = NULL;
>>> + continue;
>>> + }
>>> +
>>> + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
>> You could consider joining these 3 if()s with || to avoid having to
>> repeat the NULL assignment and continue.
>>
> devm_kzalloc will take care of the NULL assignment going forward. for
> !ret_obj, should I return an error here instead? It seems like a
> problem if that fails.
Returning an error if a ACPI object is invalid should be OK here. This way the driver
ensures that it either exports all capdata entries on a given machine or none at all.
Just a side note: the check "ret_obj->buffer.length != sizeof(struct capdata01)" should
be turned into "ret_obj->buffer.length < sizeof(struct capdata01)" to also accept oversized
buffers. This would mimic the behavior of the Windows WMI-ACPI driver.
Thanks,
Armin Wolf
>>> + ((struct cd01_list *)data)->data[idx] = NULL;
>>> + continue;
>>> + }
>>> +
>>> + ((struct cd01_list *)data)->data[idx] =
>>> + devm_kmemdup(om_dev, ret_obj->buffer.pointer,
>>> + ret_obj->buffer.length, GFP_KERNEL);
>>> + }
>>> + return 0;
>>> +}
>>> +
>>> +static const struct component_ops lenovo_cd01_component_ops = {
>>> + .bind = lenovo_cd01_component_bind,
>>> +};
>>> +
>>> +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
>>> +
>>> +{
>>> + struct lwmi_cd01_priv *priv;
>>> + int ret;
>>> +
>>> + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
>>> + if (!priv)
>>> + return -ENOMEM;
>>> +
>>> + priv->wdev = wdev;
>>> + dev_set_drvdata(&wdev->dev, priv);
>>> +
>>> + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
>>> +
>>> + return ret;
>>> +}
>>> +
>>> +static void lwmi_cd01_remove(struct wmi_device *wdev)
>>> +{
>>> + component_del(&wdev->dev, &lenovo_cd01_component_ops);
>>> +}
>>> +
>>> +static const struct wmi_device_id lwmi_cd01_id_table[] = {
>>> + { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
>>> + {}
>>> +};
>>> +
>>> +static struct wmi_driver lwmi_cd01_driver = {
>>> + .driver = {
>>> + .name = "lenovo_wmi_cd01",
>>> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
>>> + },
>>> + .id_table = lwmi_cd01_id_table,
>>> + .probe = lwmi_cd01_probe,
>>> + .remove = lwmi_cd01_remove,
>>> + .no_singleton = true,
>>> +};
>>> +
>>> +int lwmi_cd01_match(struct device *dev, void *data)
>>> +{
>>> + return dev->driver == &lwmi_cd01_driver.driver;
>>> +}
>>> +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
>>> +
>>> +module_wmi_driver(lwmi_cd01_driver);
>>> +
>>> +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
>>> +MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
>>> +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
>>> +MODULE_LICENSE("GPL");
>>> diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
>>> new file mode 100644
>>> index 000000000000..c7067a8d0398
>>> --- /dev/null
>>> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
>>> @@ -0,0 +1,29 @@
>>> +/* SPDX-License-Identifier: GPL-2.0-or-later
>>> + *
>>> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
>>> + *
>> Extra line
>>
>>> + */
>>> +
>>> +#ifndef _LENOVO_WMI_CAPDATA01_H_
>>> +#define _LENOVO_WMI_CAPDATA01_H_
>>> +
>>> +#include <linux/device.h>
>> Please fwd declare struct device instead.
>>
>>> +#include <linux/types.h>
>>> +
>>> +struct capdata01 {
>>> + u32 id;
>>> + u32 supported;
>>> + u32 default_value;
>>> + u32 step;
>>> + u32 min_value;
>>> + u32 max_value;
>>> +};
>>> +
>>> +struct cd01_list {
>>> + struct capdata01 **data;
>>> + int count;
>>> +};
>>> +
>>> +int lwmi_cd01_match(struct device *dev, void *data);
>>> +
>>> +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
>>>
>> --
>> i.
>>
Am 17.03.25 um 15:43 schrieb Derek J. Clark:
> 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.
>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> 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 | 2 +
> drivers/platform/x86/Kconfig | 4 +
> drivers/platform/x86/Makefile | 1 +
> drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> 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.c
> +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> F: drivers/platform/x86/lenovo-wmi-events.c
> F: drivers/platform/x86/lenovo-wmi-events.h
> F: drivers/platform/x86/lenovo-wmi-helpers.c
> 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..b6876611ffd9
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> @@ -0,0 +1,136 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides
> + * information on tunable attributes used by the "Other Mode" WMI interface,
> + * including if it is supported by the hardware, the default_value, max_value,
> + * min_value, and step increment.
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + */
> +
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/container_of.h>
> +#include <linux/device.h>
> +#include <linux/gfp_types.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "lenovo-wmi-capdata01.h"
Hi,
please also include linux/acpi.h, linux/export.h and linux/module.h.
> +
> +/* Interface GUIDs */
> +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> +
> +struct lwmi_cd01_priv {
> + struct wmi_device *wdev;
> +};
> +
> +/*
/* -> /**
> + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> + * the master device.
> + * @cd01_dev: Pointer to the capability data 01 parent device.
> + * @om_dev: Pointer to the other mode parent device.
> + * @data: capdata01_list object pointer to return the capability data with.
> + *
> + * Returns: 0, or an error.
> + */
> +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> + struct device *om_dev, void *data)
> +{
> + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> + int count, idx;
> +
> + if (!priv)
> + return -ENODEV;
This check is unnecessary, please drop.
> +
> + count = wmidev_instance_count(priv->wdev);
> +
> + if (count == 0)
> + return -EINVAL;
The WMI driver core already ensures that WMI devices with 0 instances are
rejected. Please drop this check.
> +
> + ((struct cd01_list *)data)->count = count;
> + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> + sizeof(struct capdata01 *),
> + GFP_KERNEL);
Two things:
- using a local variable with a type of struct cd01_list * results in cleaner source code here
- using devres is not possible inside the component callbacks, since the lifetime of the component
device is not necessarily tied to the lifetime of the underlying device.
I suggest you move the whole WMI data querying into lwmi_cd01_probe(), because then you can keep using
devres.
> + if (!data)
> + return -ENOMEM;
> +
> + for (idx = 0; idx < count; idx++) {
> + union acpi_object *ret_obj __free(kfree) = NULL;
> +
> + ret_obj = wmidev_block_query(priv->wdev, idx);
> + if (!ret_obj) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> + if (ret_obj->type != ACPI_TYPE_BUFFER) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + ((struct cd01_list *)data)->data[idx] =
> + devm_kmemdup(om_dev, ret_obj->buffer.pointer,
> + ret_obj->buffer.length, GFP_KERNEL);
> + }
> + return 0;
> +}
> +
> +static const struct component_ops lenovo_cd01_component_ops = {
> + .bind = lenovo_cd01_component_bind,
> +};
> +
> +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
> +
> +{
> + struct lwmi_cd01_priv *priv;
> + int ret;
> +
> + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->wdev = wdev;
> + dev_set_drvdata(&wdev->dev, priv);
> +
> + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
> +
> + return ret;
Please just omit the local variable here and return the result of component_add() directly here.
> +}
> +
> +static void lwmi_cd01_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &lenovo_cd01_component_ops);
> +}
> +
> +static const struct wmi_device_id lwmi_cd01_id_table[] = {
> + { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver lwmi_cd01_driver = {
> + .driver = {
> + .name = "lenovo_wmi_cd01",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = lwmi_cd01_id_table,
> + .probe = lwmi_cd01_probe,
> + .remove = lwmi_cd01_remove,
> + .no_singleton = true,
> +};
> +
> +int lwmi_cd01_match(struct device *dev, void *data)
> +{
> + return dev->driver == &lwmi_cd01_driver.driver;
> +}
> +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
> +
> +module_wmi_driver(lwmi_cd01_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
> +MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
> +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
> new file mode 100644
> index 000000000000..c7067a8d0398
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later
SPDX license identifiers need to be a separate comment.
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + *
> + */
> +
> +#ifndef _LENOVO_WMI_CAPDATA01_H_
> +#define _LENOVO_WMI_CAPDATA01_H_
> +
> +#include <linux/device.h>
> +#include <linux/types.h>
> +
> +struct capdata01 {
> + u32 id;
> + u32 supported;
> + u32 default_value;
> + u32 step;
> + u32 min_value;
> + u32 max_value;
> +};
> +
> +struct cd01_list {
> + struct capdata01 **data;
> + int count;
> +};
In order to save memory you could try something like this:
struct cd01_list {
size_t count;
struct capdata01 data[];
};
This way you
1. Avoid the memory fragmentation resulting from multiple memory allocations.
2. Omit two pointers when accessing the data.
You can use struct_size() from linux/overflow.h to calculate the size of such
an array with a trailing flexible array.
Thanks,
Armin Wolf
> +
> +int lwmi_cd01_match(struct device *dev, void *data);
> +
> +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
On Wed, Mar 26, 2025 at 6:29 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> Am 17.03.25 um 15:43 schrieb Derek J. Clark:
>
> > 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.
> >
> > Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> > ---
> > 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 | 2 +
> > drivers/platform/x86/Kconfig | 4 +
> > drivers/platform/x86/Makefile | 1 +
> > drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> > drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> > 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> > 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.c
> > +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> > F: drivers/platform/x86/lenovo-wmi-events.c
> > F: drivers/platform/x86/lenovo-wmi-events.h
> > F: drivers/platform/x86/lenovo-wmi-helpers.c
> > 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..b6876611ffd9
> > --- /dev/null
> > +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> > @@ -0,0 +1,136 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides
> > + * information on tunable attributes used by the "Other Mode" WMI interface,
> > + * including if it is supported by the hardware, the default_value, max_value,
> > + * min_value, and step increment.
> > + *
> > + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> > + */
> > +
> > +#include <linux/cleanup.h>
> > +#include <linux/component.h>
> > +#include <linux/container_of.h>
> > +#include <linux/device.h>
> > +#include <linux/gfp_types.h>
> > +#include <linux/types.h>
> > +#include <linux/wmi.h>
> > +#include "lenovo-wmi-capdata01.h"
>
> Hi,
>
> please also include linux/acpi.h, linux/export.h and linux/module.h.
>
> > +
> > +/* Interface GUIDs */
> > +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> > +
> > +struct lwmi_cd01_priv {
> > + struct wmi_device *wdev;
> > +};
> > +
> > +/*
>
> /* -> /**
>
> > + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> > + * the master device.
> > + * @cd01_dev: Pointer to the capability data 01 parent device.
> > + * @om_dev: Pointer to the other mode parent device.
> > + * @data: capdata01_list object pointer to return the capability data with.
> > + *
> > + * Returns: 0, or an error.
> > + */
> > +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> > + struct device *om_dev, void *data)
> > +{
> > + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> > + int count, idx;
> > +
> > + if (!priv)
> > + return -ENODEV;
>
> This check is unnecessary, please drop.
>
Acked
> > +
> > + count = wmidev_instance_count(priv->wdev);
> > +
> > + if (count == 0)
> > + return -EINVAL;
>
> The WMI driver core already ensures that WMI devices with 0 instances are
> rejected. Please drop this check.
>
Good to know, thanks.
> > +
> > + ((struct cd01_list *)data)->count = count;
> > + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> > + sizeof(struct capdata01 *),
> > + GFP_KERNEL);
>
> Two things:
>
> - using a local variable with a type of struct cd01_list * results in cleaner source code here
>
> - using devres is not possible inside the component callbacks, since the lifetime of the component
> device is not necessarily tied to the lifetime of the underlying device.
>
> I suggest you move the whole WMI data querying into lwmi_cd01_probe(), because then you can keep using
> devres.
>
Doing this in probe() puts the list on lwmi_cd01_priv. Should I copy
that data on bind, or pass back a pointer to the cd01 device struct
and use an exported function on cd01 and dev_get_drvdata to access
priv->list->data[idx] when needed? I prefer the latter as this avoids
needing to do devm memory allocation in component/master binds, then I
can check for NULL when accessing and clear the pointer on
master_unbind to avoid calling to a removed device driver.
(snip)
> > +struct cd01_list {
> > + struct capdata01 **data;
> > + int count;
> > +};
>
> In order to save memory you could try something like this:
>
> struct cd01_list {
> size_t count;
> struct capdata01 data[];
> };
>
> This way you
>
> 1. Avoid the memory fragmentation resulting from multiple memory allocations.
>
> 2. Omit two pointers when accessing the data.
>
> You can use struct_size() from linux/overflow.h to calculate the size of such
> an array with a trailing flexible array.
>
> Thanks,
> Armin Wolf
>
I think I have this part working in my branch. Using devm_kzalloc also
allows me to omit manually setting NULL in a few cases, which is
cleaner. Is it preferred to use struct_size() directly in the
devm_kzalloc call, or create a separate `size` variable to set the
result to and pass that into the function?
- Derek
> > +
> > +int lwmi_cd01_match(struct device *dev, void *data);
> > +
> > +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
Am 02.04.25 um 22:47 schrieb Derek John Clark:
> On Wed, Mar 26, 2025 at 6:29 PM Armin Wolf <W_Armin@gmx.de> wrote:
>> Am 17.03.25 um 15:43 schrieb Derek J. Clark:
>>
>>> 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.
>>>
>>> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
>>> ---
>>> 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 | 2 +
>>> drivers/platform/x86/Kconfig | 4 +
>>> drivers/platform/x86/Makefile | 1 +
>>> drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
>>> drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
>>> 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
>>> --- a/MAINTAINERS
>>> +++ b/MAINTAINERS
>>> @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
>>> 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.c
>>> +F: drivers/platform/x86/lenovo-wmi-capdata01.h
>>> F: drivers/platform/x86/lenovo-wmi-events.c
>>> F: drivers/platform/x86/lenovo-wmi-events.h
>>> F: drivers/platform/x86/lenovo-wmi-helpers.c
>>> 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..b6876611ffd9
>>> --- /dev/null
>>> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
>>> @@ -0,0 +1,136 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/*
>>> + * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides
>>> + * information on tunable attributes used by the "Other Mode" WMI interface,
>>> + * including if it is supported by the hardware, the default_value, max_value,
>>> + * min_value, and step increment.
>>> + *
>>> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
>>> + */
>>> +
>>> +#include <linux/cleanup.h>
>>> +#include <linux/component.h>
>>> +#include <linux/container_of.h>
>>> +#include <linux/device.h>
>>> +#include <linux/gfp_types.h>
>>> +#include <linux/types.h>
>>> +#include <linux/wmi.h>
>>> +#include "lenovo-wmi-capdata01.h"
>> Hi,
>>
>> please also include linux/acpi.h, linux/export.h and linux/module.h.
>>
>>> +
>>> +/* Interface GUIDs */
>>> +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
>>> +
>>> +struct lwmi_cd01_priv {
>>> + struct wmi_device *wdev;
>>> +};
>>> +
>>> +/*
>> /* -> /**
>>
>>> + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
>>> + * the master device.
>>> + * @cd01_dev: Pointer to the capability data 01 parent device.
>>> + * @om_dev: Pointer to the other mode parent device.
>>> + * @data: capdata01_list object pointer to return the capability data with.
>>> + *
>>> + * Returns: 0, or an error.
>>> + */
>>> +static int lenovo_cd01_component_bind(struct device *cd01_dev,
>>> + struct device *om_dev, void *data)
>>> +{
>>> + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
>>> + int count, idx;
>>> +
>>> + if (!priv)
>>> + return -ENODEV;
>> This check is unnecessary, please drop.
>>
> Acked
>
>>> +
>>> + count = wmidev_instance_count(priv->wdev);
>>> +
>>> + if (count == 0)
>>> + return -EINVAL;
>> The WMI driver core already ensures that WMI devices with 0 instances are
>> rejected. Please drop this check.
>>
> Good to know, thanks.
>
>>> +
>>> + ((struct cd01_list *)data)->count = count;
>>> + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
>>> + sizeof(struct capdata01 *),
>>> + GFP_KERNEL);
>> Two things:
>>
>> - using a local variable with a type of struct cd01_list * results in cleaner source code here
>>
>> - using devres is not possible inside the component callbacks, since the lifetime of the component
>> device is not necessarily tied to the lifetime of the underlying device.
>>
>> I suggest you move the whole WMI data querying into lwmi_cd01_probe(), because then you can keep using
>> devres.
>>
> Doing this in probe() puts the list on lwmi_cd01_priv. Should I copy
> that data on bind, or pass back a pointer to the cd01 device struct
> and use an exported function on cd01 and dev_get_drvdata to access
> priv->list->data[idx] when needed? I prefer the latter as this avoids
> needing to do devm memory allocation in component/master binds, then I
> can check for NULL when accessing and clear the pointer on
> master_unbind to avoid calling to a removed device driver.
Passing a pointer is OK, but please only pass a pointer to the struct cd01_list itself,
not the full cd01 device struct. Maybe you can also add a comment explaining that this
pointer will become invalid when unbinding from the component.
Explicitly NULL-ing this pointer upon unbinding seems unnecessary to me.
> (snip)
>
>>> +struct cd01_list {
>>> + struct capdata01 **data;
>>> + int count;
>>> +};
>> In order to save memory you could try something like this:
>>
>> struct cd01_list {
>> size_t count;
>> struct capdata01 data[];
>> };
>>
>> This way you
>>
>> 1. Avoid the memory fragmentation resulting from multiple memory allocations.
>>
>> 2. Omit two pointers when accessing the data.
>>
>> You can use struct_size() from linux/overflow.h to calculate the size of such
>> an array with a trailing flexible array.
>>
>> Thanks,
>> Armin Wolf
>>
> I think I have this part working in my branch. Using devm_kzalloc also
> allows me to omit manually setting NULL in a few cases, which is
> cleaner. Is it preferred to use struct_size() directly in the
> devm_kzalloc call, or create a separate `size` variable to set the
> result to and pass that into the function?
>
> - Derek
>
In most cases using struct_size() directly inside the devm_kzalloc() call is preferred.
Thanks,
Armin Wolf
>>> +
>>> +int lwmi_cd01_match(struct device *dev, void *data);
>>> +
>>> +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
On 3/17/25 7:43 AM, 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.
>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
All exposed attributes are passed to "Other Mode" on my Legion Go and Legion Go S.
Tested-by: Matthew Schwartz <matthew.schwartz@linux.dev>
> ---
> 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 | 2 +
> drivers/platform/x86/Kconfig | 4 +
> drivers/platform/x86/Makefile | 1 +
> drivers/platform/x86/lenovo-wmi-capdata01.c | 136 ++++++++++++++++++++
> drivers/platform/x86/lenovo-wmi-capdata01.h | 29 +++++
> 5 files changed, 172 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 6dde75922aaf..56ead241a053 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -13164,6 +13164,8 @@ L: platform-driver-x86@vger.kernel.org
> 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.c
> +F: drivers/platform/x86/lenovo-wmi-capdata01.h
> F: drivers/platform/x86/lenovo-wmi-events.c
> F: drivers/platform/x86/lenovo-wmi-events.h
> F: drivers/platform/x86/lenovo-wmi-helpers.c
> 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..b6876611ffd9
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.c
> @@ -0,0 +1,136 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * LENOVO_CAPABILITY_DATA_01 WMI data block driver. This interface provides
> + * information on tunable attributes used by the "Other Mode" WMI interface,
> + * including if it is supported by the hardware, the default_value, max_value,
> + * min_value, and step increment.
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + */
> +
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/container_of.h>
> +#include <linux/device.h>
> +#include <linux/gfp_types.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "lenovo-wmi-capdata01.h"
> +
> +/* Interface GUIDs */
> +#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> +
> +struct lwmi_cd01_priv {
> + struct wmi_device *wdev;
> +};
> +
> +/*
> + * lenovo_cd01_component_bind() - On master bind, caches all capability data on
> + * the master device.
> + * @cd01_dev: Pointer to the capability data 01 parent device.
> + * @om_dev: Pointer to the other mode parent device.
> + * @data: capdata01_list object pointer to return the capability data with.
> + *
> + * Returns: 0, or an error.
> + */
> +static int lenovo_cd01_component_bind(struct device *cd01_dev,
> + struct device *om_dev, void *data)
> +{
> + struct lwmi_cd01_priv *priv = dev_get_drvdata(cd01_dev);
> + int count, idx;
> +
> + if (!priv)
> + return -ENODEV;
> +
> + count = wmidev_instance_count(priv->wdev);
> +
> + if (count == 0)
> + return -EINVAL;
> +
> + ((struct cd01_list *)data)->count = count;
> + ((struct cd01_list *)data)->data = devm_kmalloc_array(om_dev, count,
> + sizeof(struct capdata01 *),
> + GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + for (idx = 0; idx < count; idx++) {
> + union acpi_object *ret_obj __free(kfree) = NULL;
> +
> + ret_obj = wmidev_block_query(priv->wdev, idx);
> + if (!ret_obj) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> + if (ret_obj->type != ACPI_TYPE_BUFFER) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + if (ret_obj->buffer.length != sizeof(struct capdata01)) {
> + ((struct cd01_list *)data)->data[idx] = NULL;
> + continue;
> + }
> +
> + ((struct cd01_list *)data)->data[idx] =
> + devm_kmemdup(om_dev, ret_obj->buffer.pointer,
> + ret_obj->buffer.length, GFP_KERNEL);
> + }
> + return 0;
> +}
> +
> +static const struct component_ops lenovo_cd01_component_ops = {
> + .bind = lenovo_cd01_component_bind,
> +};
> +
> +static int lwmi_cd01_probe(struct wmi_device *wdev, const void *context)
> +
> +{
> + struct lwmi_cd01_priv *priv;
> + int ret;
> +
> + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->wdev = wdev;
> + dev_set_drvdata(&wdev->dev, priv);
> +
> + ret = component_add(&wdev->dev, &lenovo_cd01_component_ops);
> +
> + return ret;
> +}
> +
> +static void lwmi_cd01_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &lenovo_cd01_component_ops);
> +}
> +
> +static const struct wmi_device_id lwmi_cd01_id_table[] = {
> + { LENOVO_CAPABILITY_DATA_01_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver lwmi_cd01_driver = {
> + .driver = {
> + .name = "lenovo_wmi_cd01",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = lwmi_cd01_id_table,
> + .probe = lwmi_cd01_probe,
> + .remove = lwmi_cd01_remove,
> + .no_singleton = true,
> +};
> +
> +int lwmi_cd01_match(struct device *dev, void *data)
> +{
> + return dev->driver == &lwmi_cd01_driver.driver;
> +}
> +EXPORT_SYMBOL_NS_GPL(lwmi_cd01_match, "LENOVO_WMI_CD01");
> +
> +module_wmi_driver(lwmi_cd01_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, lwmi_cd01_id_table);
> +MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
> +MODULE_DESCRIPTION("Lenovo Capability Data 01 WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo-wmi-capdata01.h b/drivers/platform/x86/lenovo-wmi-capdata01.h
> new file mode 100644
> index 000000000000..c7067a8d0398
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo-wmi-capdata01.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * Copyright(C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + *
> + */
> +
> +#ifndef _LENOVO_WMI_CAPDATA01_H_
> +#define _LENOVO_WMI_CAPDATA01_H_
> +
> +#include <linux/device.h>
> +#include <linux/types.h>
> +
> +struct capdata01 {
> + u32 id;
> + u32 supported;
> + u32 default_value;
> + u32 step;
> + u32 min_value;
> + u32 max_value;
> +};
> +
> +struct cd01_list {
> + struct capdata01 **data;
> + int count;
> +};
> +
> +int lwmi_cd01_match(struct device *dev, void *data);
> +
> +#endif /* !_LENOVO_WMI_CAPDATA01_H_ */
© 2016 - 2025 Red Hat, Inc.