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

device注册

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

  1. #define SABRESD_POWER_OFF IMX_GPIO_NR(3, 29)
  2. static struct gpio_keys_button new_sabresd_buttons[] = {
  3. GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "volume-up", 0, 1),
  4. GPIO_BUTTON(SABRESD_VOLUME_DN, KEY_VOLUMEDOWN, 1, "volume-down", 0, 1),
  5. GPIO_BUTTON(SABRESD_POWER_OFF, KEY_POWER, 1, "power-key", 1, 1),
  6. };
  7. static struct gpio_keys_platform_data new_sabresd_button_data = {
  8. .buttons = new_sabresd_buttons,
  9. .nbuttons = ARRAY_SIZE(new_sabresd_buttons),
  10. };
  11. static struct platform_device sabresd_button_device = {
  12. .name = "gpio-keys",
  13. .id = -1,
  14. .num_resources = 0,
  15. };
  16. static void __init imx6q_add_device_buttons(void)
  17. {
  18. /* fix me */
  19. /* For new sabresd(RevB4 ane above) change the
  20. * ONOFF key(SW1) design, the SW1 now connect
  21. * to GPIO_3_29, it can be use as a general power
  22. * key that Android reuired. But those old sabresd
  23. * such as RevB or older could not support this
  24. * change, so it needs a way to distinguish different
  25. * boards. Before board id/rev are defined cleary,
  26. * there is a simple way to achive this, that is using
  27. * SOC revison to identify differnt board revison.
  28. *
  29. * With the new sabresd change and SW mapping the
  30. * SW1 as power key, below function related to power
  31. * key are OK on new sabresd board(B4 or above).
  32. * 1 Act as power button to power on the device when device is power off
  33. * 2 Act as power button to power on the device(need keep press SW1 >5s)
  34. * 3 Act as power key to let device suspend/resume
  35. * 4 Act screenshort(hold power key and volume down key for 2s)
  36. */
  37. platform_device_add_data(&sabresd_button_device,
  38. &new_sabresd_button_data,
  39. sizeof(new_sabresd_button_data));
  40. platform_device_register(&sabresd_button_device);
  41. }
  42. static void __init mx6_sabresd_board_init(void)
  43. {
  44. ......
  45. imx6q_add_device_buttons();
  46. ......
  47. }

driver

对应驱动代码

drivers/input/keyboard/gpio_keys.c

test

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

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

echo mem > /sys/power/state

echo standby > /sys/power/state

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

    据说,对于网页开发人员来说,Firebug是Firefox浏览器中最好的插件之一. 我最近就在学习怎么使用Firebug,网上找到一篇针对初学者的教程,感觉比较有用,就翻译了出来. ========= ...

  2. HDU 4681 String(DP)

    题目链接 枚举A和B中每一段含有C的段,A的前面 后面和B前面后面,求最长公共子序.观察发现,可以预处理最长公共子序. #include <iostream> #include <c ...

  3. POJ 3071 Football(概率DP)

    题目链接 不1Y都对不住看过那么多年的球.dp[i][j]表示i队进入第j轮的概率,此题用0-1<<n表示非常方便. #include <cstdio> #include &l ...

  4. 基于淘宝开源Tair分布式KV存储引擎的整合部署

    一.前言 Tair支撑了淘宝几乎所有系统的缓存信息(Tair = Taobao Pair,Pair即Key-Value键值对),内置了三个存储引擎:mdb(默认,类似于Memcache).rdb(类似 ...

  5. HttpClient_用Apache HttpClient实现URL重定向

    很多网站都使用了URL重定向技术,把一个原始请求从一个位置路由到另一个位置.原因可能是多方面的,比如域名转发.URL缩写.隐私保护.在同一网站维持相似的域名等.本文讲述怎样使用Apache HTTPC ...

  6. 内核Makefile编写

    对于大部分内核模块或设备驱动的开发者和使用者来说,最常接触到的就是各层目录下基于kbuild架构的kbuild Makefile文件.主要部分有:1.目标定义,目标定义就是用来定义哪些内容要做为模块编 ...

  7. Metasploit 笔记

    目录一.名词解释···································································· 3二.msf基础··············· ...

  8. 解决main No MyBatis mapper was found in 的警告

    在集成Spring + mybaits时出现以下警告 org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner.main No MyBatis ...

  9. [办公自动化] 再读《让EXCEL飞》(从excel导入access数据时,union联合查询,数据源中没有包含可见的表格)

    一年多以前就买了@Mrexcel的<让excel飞>这本书.整体思路是利用access结合excel,大幅度提高数据分析效率. 最近又拿出来看了看.第十五章,比高级筛选更“高级”,P241 ...

  10. 深入说明HDR

    http://wenku.baidu.com/link?url=xBdq0VRVi2t0x9uis3XfU_0mKf2eK0e6y_1hiSo7IWSWyUE8yAwaTJ60ZlxTzQf91VPf ...