我可以通过读取/proc/acpi/button/lid/LID0/state
文件来读取笔记本电脑盖的状态。现在我想从内核模块中读取它。
我drivers/acpi/button.c
在内核源代码中找到了源文件。但是我仍然不知道如何使用它。它出口acpi_lid_notifier_register, acpi_lid_notifier_unregiste
和acpi_lid_open
功能。
如何编写有盖状态的模块?
acpi_lid_open
返回0(关闭),1(打开)或负错误号(不受支持)。
要使用通知程序,您将在模块中定义一个回调函数和一个通知程序块:
static int yourmodule_lid_notify(struct notifier_block *nb, unsigned long val, void *unused) {
// Whatever you wanted to do here
}
static struct notifier_block lid_notifier;
// Somewhere in a function, likely your module init function:
lid_notifier.notifier_call = yourmodule_lid_notify;
if (acpi_lid_notifier_register(&lid_notifier)) {
// TODO: Handle the failure here
}
// TODO: Unregister the notifier when your module is unloaded:
acpi_lid_notifier_unregister(&lid_notifier);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句