最近需要使用到power button按键,linux中有gpio keys的机制,只要注册即可。

device注册

arch/arm/mach-mx6/board-mx6q_sabresd.c

#define SABRESD_POWER_OFF	IMX_GPIO_NR(3, 29)

static struct gpio_keys_button new_sabresd_buttons[] = {
GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "volume-up", 0, 1),
GPIO_BUTTON(SABRESD_VOLUME_DN, KEY_VOLUMEDOWN, 1, "volume-down", 0, 1),
GPIO_BUTTON(SABRESD_POWER_OFF, KEY_POWER, 1, "power-key", 1, 1),
}; static struct gpio_keys_platform_data new_sabresd_button_data = {
.buttons = new_sabresd_buttons,
.nbuttons = ARRAY_SIZE(new_sabresd_buttons),
}; static struct platform_device sabresd_button_device = {
.name = "gpio-keys",
.id = -1,
.num_resources = 0,
}; static void __init imx6q_add_device_buttons(void)
{
/* fix me */
/* For new sabresd(RevB4 ane above) change the
* ONOFF key(SW1) design, the SW1 now connect
* to GPIO_3_29, it can be use as a general power
* key that Android reuired. But those old sabresd
* such as RevB or older could not support this
* change, so it needs a way to distinguish different
* boards. Before board id/rev are defined cleary,
* there is a simple way to achive this, that is using
* SOC revison to identify differnt board revison.
*
* With the new sabresd change and SW mapping the
* SW1 as power key, below function related to power
* key are OK on new sabresd board(B4 or above).
* 1 Act as power button to power on the device when device is power off
* 2 Act as power button to power on the device(need keep press SW1 >5s)
* 3 Act as power key to let device suspend/resume
* 4 Act screenshort(hold power key and volume down key for 2s)
*/
platform_device_add_data(&sabresd_button_device,
&new_sabresd_button_data,
sizeof(new_sabresd_button_data)); platform_device_register(&sabresd_button_device);
} static void __init mx6_sabresd_board_init(void)
{
......
imx6q_add_device_buttons();
......
}

driver

对应驱动代码

drivers/input/keyboard/gpio_keys.c

test

加载驱动之后,按住power key,却不能熄灭屏幕。由于是linux系统,与安卓有所不同,这一块的问题还没解决。

目前只是在文件系统层,使系统进入低功耗模式,power key就能够唤醒系统。不过这样每次都得手动操作才能使屏幕熄灭。

echo mem > /sys/power/state

echo standby > /sys/power/state

root@freescale /sys/power$ ll
-rw-r--r-- 1 root root 4096 Jan 1 00:15 device_suspend_time_threshold
-rw-r--r-- 1 root root 4096 Jan 1 00:15 pm_async
-rw-r--r-- 1 root root 4096 Jan 1 00:15 pm_test
-rw-r--r-- 1 root root 4096 Jan 1 00:15 state
-rw-r--r-- 1 root root 4096 Jan 1 00:15 wakeup_count
# 查看支持的模式
root@freescale /sys/power$ cat state
standby mem
# 使cpu进入standby模式 (或者mem模式), 此时屏幕熄灭
root@freescale /sys/power$ echo standby > state
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.01 seconds) done.
Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
Suspending console(s) (use no_console_suspend to debug)
# 按住power key,屏幕又重新点亮
add wake up source irq 103
PM: suspend of devices complete after 3.163 msecs
PM: suspend devices took 0.010 seconds
PM: late suspend of devices complete after 0.701 msecs
Disabling non-boot CPUs ...
CPU1: shutdown
Suspended for 0.000 seconds
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
Calibrating delay loop (skipped) already calibrated this CPU
i.MXC CPU frequency driver
CPU1 is up
PM: early resume of devices complete after 0.497 msecs
imx-ipuv3 imx-ipuv3.0: IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)
remove wake up source irq 103
usb 2-1: reset high speed USB device number 2 using fsl-ehci
usb 2-1.1: reset low speed USB device number 3 using fsl-ehci
PM: resume of devices complete after 1357.464 msecs
PM: resume devices took 1.360 seconds
Restarting tasks ... done.

Tony Liu

2016-12-3, Shenzhen

linux power button的更多相关文章

  1. Ubuntu 拦截并监听 power button 的关机消息

    system:ubuntu 18.04 platform:rockchip 3399 board:NanoPi M4 前言 物理上的电源按键短按之后,系统直接硬关机了,导致应用程序无法保护现场,就直接 ...

  2. Linux power supply class hacking

    /*************************************************************************** * Linux power supply cl ...

  3. Linux Power Managment详解 【转】

    转自:http://blog.chinaunix.net/uid-24517893-id-254740.html Linux Power Managment 谨以此文纪念过往的岁月 一.前言 在这个对 ...

  4. Tasker to answer incoming call by pressing power button

    nowadays, the smartphone is getting bigger in size, eg. samsung galaxy note and note 2, sorta big in ...

  5. Linux Power(一): kernel/power/earlysuspend.c

    /* kernel/power/earlysuspend.c * * Copyright (C) 2005-2008 Google, Inc. * * This software is license ...

  6. Linux power supply class(1)_软件架构及API汇整【转】

    1. 前言 power supply class为编写供电设备(power supply,后面简称PSY)的驱动提供了统一的框架,功能包括: 1)抽象PSY设备的共性,向用户空间提供统一的API. 2 ...

  7. system(linux) power on note

    读詹荣开文档摘 BIOS 在完成硬件检测和资源分配后,将硬盘 MBR 中的 Boot Loader 读到系统的 RAM 中,然后将控制权交给 OS Boot Loader Boot Loader执行全 ...

  8. Linux 驱动——Button驱动7(Timer)消抖

    button_drv.c驱动文件: #include <linux/module.h>#include <linux/kernel.h>#include <linux/f ...

  9. Linux 驱动——Button驱动6(mutex、NBLOCK、O_NONBLOCK)互斥信号量、阻塞、非阻塞

    button_drv.c驱动文件: #include <linux/module.h>#include <linux/kernel.h>#include <linux/f ...

随机推荐

  1. javascript第四弹——变量、作用域、内存

    一.变量 定义 变量是松散型的 变量是保存特定值的一个名字 变量包含两种数据类型的值:基本数据类型的值和引用数据类型的值 基本数据类型值 基本数据类型值是一个简单的数据段,在内存中占用固定的空间,保存 ...

  2. java语言中一些使用的小技巧(区别于c++)

    正在自学java中...想记录下java和c++在一些小的方面的不同点.(未完待续...) java中class的对象均是引用类型的,如果想把连个同类型的对象相关联起来,只要将一个赋值给另一个就可以了 ...

  3. post可以直接把get请求代入到目标url中

    Feigong --非攻 非攻 取自<秦时明月>--非攻,针对不同情况自由变化的武器 Feigong,针对各种情况自由变化的mysql注入脚本 Feigong,In view of the ...

  4. Java8 十大新特性详解(转)

    本教程将Java8的新特新逐一列出,并将使用简单的代码示例来指导你如何使用默认接口方法,lambda表达式,方法引用以及多重Annotation,之后你将会学到最新的API上的改进,比如流,函数式接口 ...

  5. PowerShell监控Windows打印服务器

    转自:http://sodaxu.blog.51cto.com/8850288/1417385 #获取日志,事件ID 307即我们需要提取的事件. path后的路径要与operational日志属性里 ...

  6. ScrollFix.js:一个 iOS5 溢出滚动的(有限)修复方案

    Update: Unfortunately this does not 100% solve the problem, the script falls down when handling touc ...

  7. AC之路开始了~

    已经进行了半年ACM的学习啦~虽然实力很弱但是仍然快快乐乐的慢慢学习... 新建了我的博客~ 记录A题经验 感悟学习点滴~ 加油~

  8. HTTP 笔记与总结(4 )socket 编程:批量发帖

    浏览器发送 POST 请求: 表单 form.html <!doctype html> <html lang="en"> <head> < ...

  9. jedis操作

    Jedis jedis = RedisUtil.getJedis(); try { // 向key-->name中放入了value-->minxr jedis.set("name ...

  10. phantomjs 安装使用

    PhantomJS 是一个基于 WebKit 的服务器端 JavaScript API.它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, JSON, ...