platform/x86: ideapad-laptop: introduce a generic notification chain
authorGergo Koteles <soyer@irl.hu>
Thu, 25 Jul 2024 09:21:07 +0000 (11:21 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 8 Aug 2024 11:56:42 +0000 (14:56 +0300)
There are several cases where a notification chain can simplify Lenovo
WMI drivers.

Add a generic notification chain into ideapad-laptop.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/c5a43efae8a32bd034c3d19c0a686941347575a7.1721898747.git.soyer@irl.hu
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/ideapad-laptop.c
drivers/platform/x86/ideapad-laptop.h

index 1ace711..866b32b 100644 (file)
@@ -1592,6 +1592,39 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
        priv->r_touchpad_val = value;
 }
 
+static int ideapad_laptop_nb_notify(struct notifier_block *nb,
+                                   unsigned long action, void *data)
+{
+       switch (action) {
+       }
+
+       return 0;
+}
+
+static struct notifier_block ideapad_laptop_notifier = {
+       .notifier_call = ideapad_laptop_nb_notify,
+};
+
+static BLOCKING_NOTIFIER_HEAD(ideapad_laptop_chain_head);
+
+int ideapad_laptop_register_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_register(&ideapad_laptop_chain_head, nb);
+}
+EXPORT_SYMBOL_NS_GPL(ideapad_laptop_register_notifier, IDEAPAD_LAPTOP);
+
+int ideapad_laptop_unregister_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_unregister(&ideapad_laptop_chain_head, nb);
+}
+EXPORT_SYMBOL_NS_GPL(ideapad_laptop_unregister_notifier, IDEAPAD_LAPTOP);
+
+void ideapad_laptop_call_notifier(unsigned long action, void *data)
+{
+       blocking_notifier_call_chain(&ideapad_laptop_chain_head, action, data);
+}
+EXPORT_SYMBOL_NS_GPL(ideapad_laptop_call_notifier, IDEAPAD_LAPTOP);
+
 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
 {
        struct ideapad_private *priv = data;
@@ -1974,6 +2007,8 @@ static int ideapad_acpi_add(struct platform_device *pdev)
        if (err)
                goto shared_init_failed;
 
+       ideapad_laptop_register_notifier(&ideapad_laptop_notifier);
+
        return 0;
 
 shared_init_failed:
@@ -2006,6 +2041,8 @@ static void ideapad_acpi_remove(struct platform_device *pdev)
        struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
        int i;
 
+       ideapad_laptop_unregister_notifier(&ideapad_laptop_notifier);
+
        ideapad_shared_exit(priv);
 
        acpi_remove_notify_handler(priv->adev->handle,
index 4498a96..3eb0dcd 100644 (file)
 #include <linux/acpi.h>
 #include <linux/jiffies.h>
 #include <linux/errno.h>
+#include <linux/notifier.h>
+
+int ideapad_laptop_register_notifier(struct notifier_block *nb);
+int ideapad_laptop_unregister_notifier(struct notifier_block *nb);
+void ideapad_laptop_call_notifier(unsigned long action, void *data);
 
 enum {
        VPCCMD_R_VPC1 = 0x10,