标签:
在arm ubuntu系统上,关机操作 可以用命令实现: poweroff 或者 shutdown,但是如果没有终端设备或者键盘,就无法使用命令行了,这里使用acpi机制,acpi监听power事件,来操作系统。
实现步骤:
1、驱动部分,首先要实现gpio-keys设备中,power键指定,就是用一个中断引脚,code类型定义为”KEY_POWER“
比如:
/* GPIO KEYS */ static struct gpio_keys_button smdk4412_button[] = { { <span style="color:#ff0000;">.code = KEY_POWER,</span> .gpio = EXYNOS4_GPX0(1), .desc = "gpio-keys: KEY_POWER", .type = EV_KEY, .active_low = 1, .debounce_interval = 1, .wakeup = 1, }, { .code = KEY_VOLUMEUP,//.code = KEY_LEFT, .gpio = EXYNOS4_GPX1(0), .desc = "gpio-keys: KEY_VOLUMEUP", .type = EV_KEY, .active_low = 1, .debounce_interval = 10, }, { .code = KEY_VOLUMEDOWN,//.code = KEY_DOWN, .gpio = EXYNOS4_GPX1(1), .desc = "gpio-keys: KEY_VOLUMEDOWN", .type = EV_KEY, .active_low = 1, .debounce_interval = 10, }, }; static struct gpio_keys_platform_data smdk4x12_gpio_keys_data = { .buttons = smdk4412_button, .nbuttons = ARRAY_SIZE(smdk4412_button), .rep = 1, .poll_interval = 100, }; static struct platform_device smdk4x12_gpio_keys = { .name = "gpio-keys", .dev = { .platform_data = &smdk4x12_gpio_keys_data, }, };红色标记 .code=KEY_POWER, 就是电源键的事件类型,使用GPX0_1作为中断源来触发;下面两个是音量键的事件类型,可以实现音量的大小调节,
驱动配置好以后,可以在系统中使用 cat /proc/interrupts 来检查按键触发是否正常
417: 50 0 0 0 exynos-eint gpio-keys: KEY_POWER经过检测,我的板子,中断没有问题^^.
2、驱动做好后,就可以安装acpi了,
运行命令:
sudo apt-get update
sudo apt-get install apcid
备份/etc/acpi/powerbtn.sh
cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh_bk
修改/etc/acpi/powerbtn.sh
只保留下面的部分
#!/bin/sh # /etc/acpi/powerbtn.sh # Initiates a shutdown when the power button has been # pressed. /sbin/shutdown -h now "Power button pressed"
service acpid stop service acpid start
Broadcast message from root@yunz (unknown) at 20:20 ... The system is going down for halt NOW! Power button pressed wait-for-state stop/waiting * Stopping rsync daemon rsync [ OK ] * Stopping NTP server ntpd [ OK ] * Asking all remaining processes to terminate... [ OK ] * All processes ended within 1 seconds... [ OK ] ModemManager[667]: <warn> Could not acquire the 'org.freedesktop.ModemManager1' service name ModemManager[667]: <info> ModemManager is shut down * Unmounting temporary filesystems... [ OK ] * Deactivating swap... [ OK ] * Unmounting local filesystems... [ OK ] * Will now halt [ 37.468376] exynos4-reboot: Notifier called [ 38.132085] Power down. [ 38.1330?OK
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/liujia2100/article/details/47262233