diff mbox series

[RFC,15/21] alienware-wmi: Refactor sysfs visibility methods

Message ID 20241205004457.2186386-2-kuurtb@gmail.com (mailing list archive)
State Changes Requested, archived
Headers show
Series alienware-wmi driver rework | expand

Commit Message

Kurt Borja Dec. 5, 2024, 12:44 a.m. UTC
All sysfs visibility methods relied on the `quirks` global variable. To
avoid this let the WMI drivers set this information as platform specific
data, and refactor visibility methods accordingly.

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
 drivers/platform/x86/dell/alienware-wmi.c | 52 ++++++++++++++++++++---
 1 file changed, 47 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
index 18a15dcf90a3..25e0139ed78c 100644
--- a/drivers/platform/x86/dell/alienware-wmi.c
+++ b/drivers/platform/x86/dell/alienware-wmi.c
@@ -427,6 +427,10 @@  struct alienfx_ops {
 struct alienfx_platdata {
 	struct wmi_device *wdev;
 	struct alienfx_ops ops;
+	u8 num_zones;
+	bool hdmi_mux;
+	bool amplifier;
+	bool deepslp;
 };
 
 static u8 interface;
@@ -597,12 +601,24 @@  static DEVICE_ATTR_RW(lighting_control_state);
 static umode_t zone_attr_visible(struct kobject *kobj,
 				 struct attribute *attr, int n)
 {
-	return n < quirks->num_zones + 1 ? 0644 : 0;
+	struct device *dev;
+	struct alienfx_platdata *pdata;
+
+	dev = container_of(kobj, struct device, kobj);
+	pdata = dev_get_platdata(dev);
+
+	return n < pdata->num_zones + 1 ? 0644 : 0;
 }
 
 static bool zone_group_visible(struct kobject *kobj)
 {
-	return quirks->num_zones > 0;
+	struct device *dev;
+	struct alienfx_platdata *pdata;
+
+	dev = container_of(kobj, struct device, kobj);
+	pdata = dev_get_platdata(dev);
+
+	return pdata->num_zones > 0;
 }
 DEFINE_SYSFS_GROUP_VISIBLE(zone);
 
@@ -737,7 +753,13 @@  static DEVICE_ATTR(source, S_IRUGO | S_IWUSR, show_hdmi_source,
 
 static bool hdmi_group_visible(struct kobject *kobj)
 {
-	return quirks->hdmi_mux;
+	struct device *dev;
+	struct alienfx_platdata *pdata;
+
+	dev = container_of(kobj, struct device, kobj);
+	pdata = dev_get_platdata(dev);
+
+	return pdata->hdmi_mux;
 }
 DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(hdmi);
 
@@ -786,7 +808,13 @@  static DEVICE_ATTR(status, S_IRUGO, show_amplifier_status, NULL);
 
 static bool amplifier_group_visible(struct kobject *kobj)
 {
-	return quirks->amplifier;
+	struct device *dev;
+	struct alienfx_platdata *pdata;
+
+	dev = container_of(kobj, struct device, kobj);
+	pdata = dev_get_platdata(dev);
+
+	return pdata->amplifier;
 }
 DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(amplifier);
 
@@ -862,7 +890,13 @@  static DEVICE_ATTR(deepsleep, S_IRUGO | S_IWUSR, show_deepsleep_status, toggle_d
 
 static bool deepsleep_group_visible(struct kobject *kobj)
 {
-	return quirks->deepslp;
+	struct device *dev;
+	struct alienfx_platdata *pdata;
+
+	dev = container_of(kobj, struct device, kobj);
+	pdata = dev_get_platdata(dev);
+
+	return pdata->deepslp;
 }
 DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(deepsleep);
 
@@ -1211,6 +1245,10 @@  static int legacy_wmi_probe(struct wmi_device *wdev, const void *context)
 			.upd_led = legacy_wmi_update_led,
 			.upd_brightness = legacy_wmi_update_brightness,
 		},
+		.num_zones = quirks->num_zones,
+		.hdmi_mux = quirks->hdmi_mux,
+		.amplifier = quirks->amplifier,
+		.deepslp = quirks->deepslp,
 	};
 
 	if (quirks->num_zones > 0)
@@ -1291,6 +1329,10 @@  static int wmax_wmi_probe(struct wmi_device *wdev, const void *context)
 			.upd_led = wmax_wmi_update_led,
 			.upd_brightness = wmax_wmi_update_brightness,
 		},
+		.num_zones = quirks->num_zones,
+		.hdmi_mux = quirks->hdmi_mux,
+		.amplifier = quirks->amplifier,
+		.deepslp = quirks->deepslp,
 	};
 
 	if (quirks->thermal)