一个模块之间触发中断需要调用另一个模块,可以用通知链的方式处理
//ko 模块之间通信 通知链
manager.c
//注册通知链
+#include <linux/kernel.h>
+#include <linux/notifier.h>
+BLOCKING_NOTIFIER_HEAD(test_chain_head); //加入通知链队列
+struct blocking_notifier_head test_chain_head;
+EXPORT_SYMBOL_GPL(test_chain_head);
+
+int register_test_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&test_chain_head, nb);
+}
+
+int unregister_test_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&test_chain_head, nb);
+}
+
+static int test_chain_notify(struct notifier_block *nb,unsigned long mode, void *_unused)
+{
+ printk(KERN_EMERG "notifier: test_chain_notify!\n"); //回调处理函数
+ return 0;
+}
+
+static struct notifier_block test_chain_nb = {
+ .notifier_call = test_chain_notify,
+};
+
+
static int charger_manager_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
@@ -7666,6 +7700,8 @@ static int charger_manager_probe(struct platform_device *pdev)
queue_delayed_work(system_power_efficient_wq, &cm->cap_update_work, CM_CAP_CYCLE_TRACK_TIME_15S * HZ);
INIT_DELAYED_WORK(&cm->uvlo_work, cm_uvlo_check_work);
+ register_test_notifier(&test_chain_nb);
+
return 0;
err:
@@ -7685,6 +7721,8 @@ static int charger_manager_remove(struct platform_device *pdev)
list_del(&cm->entry);
mutex_unlock(&cm_list_mtx);
+ unregister_test_notifier(&test_chain_nb);
+
xxxxx.c
@@ -28,6 +28,9 @@
+#include <linux/notifier.h>
+
+
+extern struct blocking_notifier_head test_chain_head;
+
+static int call_notifier_call_chain(unsigned long val)
+{
+ int ret = blocking_notifier_call_chain(&test_chain_head, val, NULL);
+ return notifier_to_errno(ret);
+}
+
+
+
//触发通知链
static irqreturn_t sc8885_irq_handler_thread(int irq, void *private)
{
struct sc888x_device *charger = private;
@@ -1695,6 +1707,8 @@ static irqreturn_t sc8885_irq_handler_thread(int irq, void *private)
}
irq_set_irq_type(irq, irq_flag | IRQF_ONESHOT);
+ call_notifier_call_chain(123);
+
return IRQ_HANDLED;
}