驱动模块之间通知链

一个模块之间触发中断需要调用另一个模块,可以用通知链的方式处理

 //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;
 }

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值