mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 05:31:37 -04:00
platform/x86: Add lenovo-wmi-helpers
Adds lenovo-wmi-helpers, which provides a common wrapper function for wmidev_evaluate_method that does data validation and error handling. Reviewed-by: Alok Tiwari <alok.a.tiwari@oracle.com> Reviewed-by: Armin Wolf <W_Armin@gmx.de> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com> Link: https://lore.kernel.org/r/20250702033826.1057762-3-derekjohn.clark@gmail.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
committed by
Ilpo Järvinen
parent
57139e126a
commit
e521d16e76
@@ -232,3 +232,7 @@ config YT2_1380
|
|||||||
|
|
||||||
To compile this driver as a module, choose M here: the module will
|
To compile this driver as a module, choose M here: the module will
|
||||||
be called lenovo-yogabook.
|
be called lenovo-yogabook.
|
||||||
|
|
||||||
|
config LENOVO_WMI_HELPERS
|
||||||
|
tristate
|
||||||
|
depends on ACPI_WMI
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ lenovo-target-$(CONFIG_LENOVO_YMC) += ymc.o
|
|||||||
lenovo-target-$(CONFIG_YOGABOOK) += yogabook.o
|
lenovo-target-$(CONFIG_YOGABOOK) += yogabook.o
|
||||||
lenovo-target-$(CONFIG_YT2_1380) += yoga-tab2-pro-1380-fastcharger.o
|
lenovo-target-$(CONFIG_YT2_1380) += yoga-tab2-pro-1380-fastcharger.o
|
||||||
lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) += wmi-camera.o
|
lenovo-target-$(CONFIG_LENOVO_WMI_CAMERA) += wmi-camera.o
|
||||||
|
lenovo-target-$(CONFIG_LENOVO_WMI_HELPERS) += wmi-helpers.o
|
||||||
|
|
||||||
# Add 'lenovo' prefix to each module listed in lenovo-target-*
|
# Add 'lenovo' prefix to each module listed in lenovo-target-*
|
||||||
define LENOVO_OBJ_TARGET
|
define LENOVO_OBJ_TARGET
|
||||||
|
|||||||
74
drivers/platform/x86/lenovo/wmi-helpers.c
Normal file
74
drivers/platform/x86/lenovo/wmi-helpers.c
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
/*
|
||||||
|
* Lenovo Legion WMI helpers driver.
|
||||||
|
*
|
||||||
|
* The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
|
||||||
|
* that require cross-references between GUID's for some functionality. The
|
||||||
|
* "Custom Mode" interface is a legacy interface for managing and displaying
|
||||||
|
* CPU & GPU power and hwmon settings and readings. The "Other Mode" interface
|
||||||
|
* is a modern interface that replaces or extends the "Custom Mode" interface
|
||||||
|
* methods. The "Gamezone" interface adds advanced features such as fan
|
||||||
|
* profiles and overclocking. The "Lighting" interface adds control of various
|
||||||
|
* status lights related to different hardware components. Each of these
|
||||||
|
* drivers uses a common procedure to get data from the WMI interface,
|
||||||
|
* enumerated here.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/acpi.h>
|
||||||
|
#include <linux/cleanup.h>
|
||||||
|
#include <linux/errno.h>
|
||||||
|
#include <linux/export.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/wmi.h>
|
||||||
|
|
||||||
|
#include "wmi-helpers.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
|
||||||
|
* return an integer.
|
||||||
|
* @wdev: Pointer to the WMI device to be called.
|
||||||
|
* @instance: Instance of the called method.
|
||||||
|
* @method_id: WMI Method ID for the method to be called.
|
||||||
|
* @buf: Buffer of all arguments for the given method_id.
|
||||||
|
* @size: Length of the buffer.
|
||||||
|
* @retval: Pointer for the return value to be assigned.
|
||||||
|
*
|
||||||
|
* Calls wmidev_evaluate_method for Lenovo WMI devices that return an ACPI
|
||||||
|
* integer. Validates the return value type and assigns the value to the
|
||||||
|
* retval pointer.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, or an error code.
|
||||||
|
*/
|
||||||
|
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
|
||||||
|
unsigned char *buf, size_t size, u32 *retval)
|
||||||
|
{
|
||||||
|
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
|
||||||
|
union acpi_object *ret_obj __free(kfree) = NULL;
|
||||||
|
struct acpi_buffer input = { size, buf };
|
||||||
|
acpi_status status;
|
||||||
|
|
||||||
|
status = wmidev_evaluate_method(wdev, instance, method_id, &input,
|
||||||
|
&output);
|
||||||
|
if (ACPI_FAILURE(status))
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
if (retval) {
|
||||||
|
ret_obj = output.pointer;
|
||||||
|
if (!ret_obj)
|
||||||
|
return -ENODATA;
|
||||||
|
|
||||||
|
if (ret_obj->type != ACPI_TYPE_INTEGER)
|
||||||
|
return -ENXIO;
|
||||||
|
|
||||||
|
*retval = (u32)ret_obj->integer.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
EXPORT_SYMBOL_NS_GPL(lwmi_dev_evaluate_int, "LENOVO_WMI_HELPERS");
|
||||||
|
|
||||||
|
MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
|
||||||
|
MODULE_DESCRIPTION("Lenovo WMI Helpers Driver");
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
20
drivers/platform/x86/lenovo/wmi-helpers.h
Normal file
20
drivers/platform/x86/lenovo/wmi-helpers.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
|
/* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> */
|
||||||
|
|
||||||
|
#ifndef _LENOVO_WMI_HELPERS_H_
|
||||||
|
#define _LENOVO_WMI_HELPERS_H_
|
||||||
|
|
||||||
|
#include <linux/types.h>
|
||||||
|
|
||||||
|
struct wmi_device;
|
||||||
|
|
||||||
|
struct wmi_method_args_32 {
|
||||||
|
u32 arg0;
|
||||||
|
u32 arg1;
|
||||||
|
};
|
||||||
|
|
||||||
|
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
|
||||||
|
unsigned char *buf, size_t size, u32 *retval);
|
||||||
|
|
||||||
|
#endif /* !_LENOVO_WMI_HELPERS_H_ */
|
||||||
Reference in New Issue
Block a user