[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240620194214.3071-2-W_Armin@gmx.de>
Date: Thu, 20 Jun 2024 21:42:13 +0200
From: Armin Wolf <W_Armin@....de>
To: hdegoede@...hat.com,
ilpo.jarvinen@...ux.intel.com
Cc: corbet@....net,
platform-driver-x86@...r.kernel.org,
linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] platform/x86: wmi: Add driver_override support
Add support for forcing the WMI driver core to bind
a certain WMI driver to a WMI device. This will be
necessary to support generic WMI drivers without an
ID table
Signed-off-by: Armin Wolf <W_Armin@....de>
---
drivers/platform/x86/wmi.c | 33 +++++++++++++++++++++++++++++++++
include/linux/wmi.h | 4 ++++
2 files changed, 37 insertions(+)
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index d21f3fa25823..6bfae28b962a 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -772,11 +772,39 @@ static ssize_t expensive_show(struct device *dev,
}
static DEVICE_ATTR_RO(expensive);
+static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct wmi_device *wdev = to_wmi_device(dev);
+ ssize_t ret;
+
+ device_lock(dev);
+ ret = sysfs_emit(buf, "%s\n", wdev->driver_override);
+ device_unlock(dev);
+
+ return ret;
+}
+
+static ssize_t driver_override_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct wmi_device *wdev = to_wmi_device(dev);
+ int ret;
+
+ ret = driver_set_override(dev, &wdev->driver_override, buf, count);
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+static DEVICE_ATTR_RW(driver_override);
+
static struct attribute *wmi_attrs[] = {
&dev_attr_modalias.attr,
&dev_attr_guid.attr,
&dev_attr_instance_count.attr,
&dev_attr_expensive.attr,
+ &dev_attr_driver_override.attr,
NULL
};
ATTRIBUTE_GROUPS(wmi);
@@ -845,6 +873,7 @@ static void wmi_dev_release(struct device *dev)
{
struct wmi_block *wblock = dev_to_wblock(dev);
+ kfree(wblock->dev.driver_override);
kfree(wblock);
}
@@ -854,6 +883,10 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
struct wmi_block *wblock = dev_to_wblock(dev);
const struct wmi_device_id *id = wmi_driver->id_table;
+ /* When driver_override is set, only bind to the matching driver */
+ if (wblock->dev.driver_override)
+ return !strcmp(wblock->dev.driver_override, driver->name);
+
if (id == NULL)
return 0;
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index 63cca3b58d6d..3275470b5531 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -16,12 +16,16 @@
* struct wmi_device - WMI device structure
* @dev: Device associated with this WMI device
* @setable: True for devices implementing the Set Control Method
+ * @driver_override: Driver name to force a match; do not set directly,
+ * because core frees it; use driver_set_override() to
+ * set or clear it.
*
* This represents WMI devices discovered by the WMI driver core.
*/
struct wmi_device {
struct device dev;
bool setable;
+ const char *driver_override;
};
/**
--
2.39.2
Powered by blists - more mailing lists