>From 5afc6af28cf63c252238aea99b400497b5462012 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 18 May 2021 12:35:50 +0200
Subject: [PATCH 3/4] FIXUP platform/x86: dell-privacy: Add support for Dell
 hardware privacy

Fix the builtin vs module symbol issue with the dependencies between
dell-laptop, dell-wmi and dell-privacy:

1. Remove "depends on DELL_LAPTOP" from the dell-privacy Kconfig
2. Add "depends on DELL_WMI || DELL_WMI = n" to the dell-laptop Kconfig
3. Rename DELL_PRIVACY to DELL_WMI_PRIVACY and make it a boolean option
   which controls if privacy support gets added to the dell-wmi.ko module;
   and adjust the makefile accordingly, so there no longer is a separate
   dell-privacy.ko module

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/dell/Kconfig             | 23 ++++++++-----------
 drivers/platform/x86/dell/Makefile            |  2 +-
 drivers/platform/x86/dell/dell-laptop.c       |  2 +-
 drivers/platform/x86/dell/dell-wmi-base.c     |  7 +++++-
 ...{dell-privacy-wmi.c => dell-wmi-privacy.c} | 16 +++++++------
 ...{dell-privacy-wmi.h => dell-wmi-privacy.h} | 13 ++++++++++-
 6 files changed, 38 insertions(+), 25 deletions(-)
 rename drivers/platform/x86/dell/{dell-privacy-wmi.c => dell-wmi-privacy.c} (97%)
 rename drivers/platform/x86/dell/{dell-privacy-wmi.h => dell-wmi-privacy.h} (68%)

diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig
index be570ccbbce0..b5c6a6a32bf9 100644
--- a/drivers/platform/x86/dell/Kconfig
+++ b/drivers/platform/x86/dell/Kconfig
@@ -53,6 +53,7 @@ config DELL_LAPTOP
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
 	depends on RFKILL || RFKILL = n
+	depends on DELL_WMI || DELL_WMI = n
 	depends on SERIO_I8042
 	depends on DELL_SMBIOS
 	select POWER_SUPPLY
@@ -164,6 +165,14 @@ config DELL_WMI
 	  To compile this driver as a module, choose M here: the module will
 	  be called dell-wmi.
 
+config DELL_WMI_PRIVACY
+	bool "Dell WMI Hardware Privacy Support"
+	depends on DELL_WMI
+	depends on LEDS_TRIGGER_AUDIO
+	help
+	  This option adds integration with the "Dell Hardware Privacy"
+	  feature of Dell laptops to the dell-wmi driver.
+
 config DELL_WMI_AIO
 	tristate "WMI Hotkeys for Dell All-In-One series"
 	default m
@@ -204,18 +213,4 @@ config DELL_WMI_SYSMAN
 	  To compile this driver as a module, choose M here: the module will
 	  be called dell-wmi-sysman.
 
-config DELL_PRIVACY
-	tristate "Dell Hardware Privacy Support"
-	depends on ACPI
-	depends on ACPI_WMI
-	depends on INPUT
-	depends on DELL_LAPTOP
-	depends on LEDS_TRIGGER_AUDIO
-	depends on DELL_WMI
-	help
-	  This driver provides integration with the "Dell Hardware Privacy" feature
-	  of Dell laptops.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called dell_privacy.
 endif # X86_PLATFORM_DRIVERS_DELL
diff --git a/drivers/platform/x86/dell/Makefile b/drivers/platform/x86/dell/Makefile
index 22ff1d0af821..ddba1df71e80 100644
--- a/drivers/platform/x86/dell/Makefile
+++ b/drivers/platform/x86/dell/Makefile
@@ -16,8 +16,8 @@ dell-smbios-$(CONFIG_DELL_SMBIOS_SMM)	+= dell-smbios-smm.o
 obj-$(CONFIG_DELL_SMO8800)		+= dell-smo8800.o
 obj-$(CONFIG_DELL_WMI)			+= dell-wmi.o
 dell-wmi-objs				:= dell-wmi-base.o
+dell-wmi-$(CONFIG_DELL_WMI_PRIVACY)	+= dell-wmi-privacy.o
 obj-$(CONFIG_DELL_WMI_AIO)		+= dell-wmi-aio.o
 obj-$(CONFIG_DELL_WMI_DESCRIPTOR)	+= dell-wmi-descriptor.o
 obj-$(CONFIG_DELL_WMI_LED)		+= dell-wmi-led.o
 obj-$(CONFIG_DELL_WMI_SYSMAN)		+= dell-wmi-sysman/
-obj-$(CONFIG_DELL_PRIVACY)              += dell-privacy-wmi.o
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index 529547fb0cb1..63874982cadb 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -31,7 +31,7 @@
 #include "dell-rbtn.h"
 #include "dell-smbios.h"
 
-#include "dell-privacy-wmi.h"
+#include "dell-wmi-privacy.h"
 
 struct quirk_entry {
 	bool touchpad_led;
diff --git a/drivers/platform/x86/dell/dell-wmi-base.c b/drivers/platform/x86/dell/dell-wmi-base.c
index 1988ddc33b32..089c125e18f7 100644
--- a/drivers/platform/x86/dell/dell-wmi-base.c
+++ b/drivers/platform/x86/dell/dell-wmi-base.c
@@ -27,7 +27,7 @@
 #include <acpi/video.h>
 #include "dell-smbios.h"
 #include "dell-wmi-descriptor.h"
-#include "dell-privacy-wmi.h"
+#include "dell-wmi-privacy.h"
 
 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
@@ -754,6 +754,10 @@ static int __init dell_wmi_init(void)
 		}
 	}
 
+	err = dell_privacy_register_driver();
+	if (err)
+		return err;
+
 	return wmi_driver_register(&dell_wmi_driver);
 }
 late_initcall(dell_wmi_init);
@@ -764,6 +768,7 @@ static void __exit dell_wmi_exit(void)
 		dell_wmi_events_set_enabled(false);
 
 	wmi_driver_unregister(&dell_wmi_driver);
+	dell_privacy_unregister_driver();
 }
 module_exit(dell_wmi_exit);
 
diff --git a/drivers/platform/x86/dell/dell-privacy-wmi.c b/drivers/platform/x86/dell/dell-wmi-privacy.c
similarity index 97%
rename from drivers/platform/x86/dell/dell-privacy-wmi.c
rename to drivers/platform/x86/dell/dell-wmi-privacy.c
index a32d0fbd99da..9a36b110a314 100644
--- a/drivers/platform/x86/dell/dell-privacy-wmi.c
+++ b/drivers/platform/x86/dell/dell-wmi-privacy.c
@@ -16,7 +16,7 @@
 #include <linux/module.h>
 #include <linux/wmi.h>
 
-#include "dell-privacy-wmi.h"
+#include "dell-wmi-privacy.h"
 
 #define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919"
 #define MICROPHONE_STATUS		BIT(0)
@@ -132,7 +132,6 @@ bool dell_privacy_process_event(int type, int code, int status)
 	mutex_unlock(&list_mutex);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(dell_privacy_process_event);
 
 static ssize_t dell_privacy_supported_type_show(struct device *dev,
 					struct device_attribute *attr,
@@ -386,9 +385,12 @@ static struct wmi_driver dell_privacy_wmi_driver = {
 	.id_table = dell_wmi_privacy_wmi_id_table,
 };
 
-module_wmi_driver(dell_privacy_wmi_driver);
+int dell_privacy_register_driver(void)
+{
+	return wmi_driver_register(&dell_privacy_wmi_driver);
+}
 
-MODULE_DEVICE_TABLE(wmi, dell_wmi_privacy_wmi_id_table);
-MODULE_AUTHOR("Perry Yuan <perry_yuan@dell.com>");
-MODULE_DESCRIPTION("Dell Privacy WMI Driver");
-MODULE_LICENSE("GPL");
+void dell_privacy_unregister_driver(void)
+{
+	wmi_driver_unregister(&dell_privacy_wmi_driver);
+}
diff --git a/drivers/platform/x86/dell/dell-privacy-wmi.h b/drivers/platform/x86/dell/dell-wmi-privacy.h
similarity index 68%
rename from drivers/platform/x86/dell/dell-privacy-wmi.h
rename to drivers/platform/x86/dell/dell-wmi-privacy.h
index 54004eed7213..b139b644f004 100644
--- a/drivers/platform/x86/dell/dell-privacy-wmi.h
+++ b/drivers/platform/x86/dell/dell-wmi-privacy.h
@@ -8,9 +8,11 @@
 #ifndef _DELL_PRIVACY_WMI_H_
 #define _DELL_PRIVACY_WMI_H_
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+#if IS_ENABLED(CONFIG_DELL_WMI_PRIVACY)
 bool dell_privacy_present(void);
 bool dell_privacy_process_event(int type, int code, int status);
+int dell_privacy_register_driver(void);
+void dell_privacy_unregister_driver(void);
 #else /* CONFIG_DELL_PRIVACY */
 static inline bool dell_privacy_present(void)
 {
@@ -21,5 +23,14 @@ static inline bool dell_privacy_process_event(int type, int code, int status)
 {
 	return false;
 }
+
+static inline int dell_privacy_register_driver(void)
+{
+	return 0;
+}
+
+static inline void dell_privacy_unregister_driver(void)
+{
+}
 #endif /* CONFIG_DELL_PRIVACY */
 #endif
-- 
2.31.1

