我可以通过读取/proc/acpi/button/lid/LID0/state文件来读取笔记本盖子的状态。现在我想从内核模块中读取它。
我在内核源代码中找到了源文件drivers/acpi/button.c。但我还是不知道怎么用。它导出acpi_lid_notifier_register, acpi_lid_notifier_unregiste和acpi_lid_open函数。
如何为lid状态编写模块?
发布于 2015-05-28 17:52:33
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);https://stackoverflow.com/questions/30512998
复制相似问题