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

Gangadhars

我可以通过读取/proc/acpi/button/lid/LID0/state文件来读取笔记本电脑盖的状态现在我想从内核模块中读取它。

drivers/acpi/button.c在内核源代码中找到了源文件但是我仍然不知道如何使用它。它出口acpi_lid_notifier_register, acpi_lid_notifier_unregisteacpi_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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章