码迷,mamicode.com
首页 > 系统相关 > 详细

arm ubuntu 按键关机的实现

时间:2015-08-03 22:49:10      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:

在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"

重启apcid服务

service acpid stop
service acpid start

3、按下power键,试一下吧

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



版权声明:本文为博主原创文章,未经博主允许不得转载。

arm ubuntu 按键关机的实现

标签:

原文地址:http://blog.csdn.net/liujia2100/article/details/47262233

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!