struct notifier_block { int (*notifier_call)(struct notifier_block *, unsigned long, void *); struct notifier_block __rcu *next; int priority; };
static int xxxx_notify(struct notifier_block *nb, unsigned long status, void *unused) { int rc; if (!the_chip) { pr_err("not initialized\n"); return -EINVAL; } switch (status) { case 0: pr_debug("0 received\n"); break; case 1: pr_debug("1 received\n"); break; case 2: break; default: pr_err("error received\n"); break; } return 0; };
2:定义alarm_notifier通知链,将上面定义的函数入口赋值给函数指针
notifier_call;
static struct notifier_block xxxx_notifier = { .notifier_call = xxxx_notify, };
{ ----- rc = xxxx_register_notifier(&alarm_notifier); if (rc) { pr_err("unable to register alarm notifier rc=%d\n", rc); return rc; ------ }
int xxxx_register_notifier(struct notifier_block *nb) { ------- rc = srcu_notifier_chain_register(&chip->irq_notifier_list, nb); ------- return rc; } EXPORT_SYMBOL(xxxx_register_notifier);
static void xxxx_isr_work(struct work_struct *work) { struct xxxx_chip *chip = container_of(work, struct xxxx_chip, irq_work); int status; if (!chip) return; status = xxxx_status_read(); srcu_notifier_call_chain(&chip->irq_notifier_list, status, NULL); }
原文地址:http://blog.csdn.net/linux_devices_driver/article/details/39504063