如何使用Linux内核模块获取盖子状态?

3
我可以通过读取/proc/acpi/button/lid/LID0/state文件来读取笔记本电脑盖的状态。现在我想从内核模块中读取它。
我在内核源代码中找到了源文件drivers/acpi/button.c,但我仍然不知道如何使用它。它导出了acpi_lid_notifier_register, acpi_lid_notifier_unregisteracpi_lid_open函数。
如何编写盖子状态的模块?
1个回答

2

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);

出现错误:include/acpi/acpi_drivers.h:86:32: error: unknown type name ‘acpi_handle’ - gangadhars
1
所以不要包含那个文件。包含<acpi/button.h>,这似乎是公共API。 - Dark Falcon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接