How to get lid state using linux kernel module?

微笑、不失礼 提交于 2020-01-04 02:21:24

问题


I can read the status of my laptop lid by reading /proc/acpi/button/lid/LID0/state file. Now I want to read it from kernel module.

I found the source file drivers/acpi/button.c in kernel source. But still I didn't understand how to use it. It exporting acpi_lid_notifier_register, acpi_lid_notifier_unregiste and acpi_lid_open functions.

How to write a module for lid state?


回答1:


acpi_lid_open returns 0 (closed), 1 (open), or a negative error number (unsupported).

To use the notifier, you would define a callback function and a notifier block in your module:

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/how-to-get-lid-state-using-linux-kernel-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!