顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2013年8月28日 星期三

[Hi3716c] Fix IR power key wake up mechanism

Some files worth noticing...
* device/hisilicon/godbox/driver/sdk/msp/ecs/drv/ir/ir_s2/ir_drv.c
IR driver. It handles IRQ.

* device/hisilicon/godbox/driver/sdk/msp_base/ecs/drv/include/ir.h
 IRQ no of IR is defined here

* kernel/arch/arm/mach-godbox/include/mach/irqs.h
Some IRQs are defined here

* device/hisilicon/godbox/driver/sdk/msp/ecs/drv/ir/ir_s2/hiir_ir2.h
Handles raw-linux_key_code mapping and works as API for the IR driver

* device/hisilicon/godbox/driver/sdk/sample/pmoc/sample_pmoc.c
A sample code to test IR and other ways to wake up the device

* device/hisilicon/godbox/driver/sdk/msp/ecs/drv/c51/drv_c51.c
MCU driver. MCU handles wake-up job after cpu power is down. The IR module decodes the infrared signals and then sends interrupts to MCU

* device/hisilicon/godbox/driver/sdk/msp/ecs/api/hi_unf_pm.c
A wrapped API to access MCU driver

* framework/base/core/jni/standby_wakeup.c
Hooked to the underlying HI_UNF_PM MCU driver wrapper APIs. It actually sets wake-up mode a particular power key code

* framework/base/service/jni/com_android_server_AlarmManagerService.cpp
android_server_AlarmManagerService_setWakeUp() body is here, which calls HI_Standby_Wakeup() in standby_wakeup.c

* framework/base/service/jni/com_android_server_PowerManagerService.cpp
android_server_PowerManagerService_nativeSetWakeup() body is here, which calls  android_server_AlarmManagerService_setWakeUp() in com_android_server_AlarmManagerService.cpp

* framework/base/services/java/com/android/server/PowerManagerService.java
goToSleep() body is here, which calls nativeSetWakeup() defined in com_android_server_PowerManagerService.cpp, which points to  android_server_PowerManagerService_nativeSetWakeup()

What happens when a power key is detected for standby mode to proceed to set the wake-up key attribute from the point of view of Android:

interceptKeyBeforeQueueing(), frameworks/base/services/jni/com_android_server_InputManager.cpp
 |
V
interceptKeyBeforeQueueing(), frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
 |
V
handleInterceptActions(), frameworks/base/services/jni/com_android_server_InputManager.cpp
 |
V
goToSleep(), framework/base/services/java/com/android/server/PowerManagerService.java
 |
V
nativeSetWakeup(),  framework/base/service/jni/com_android_server_PowerManagerService.cpp
 |
V
android_server_AlarmManagerService_setWakeUp(),  framework/base/service/jni/com_android_server_AlarmManagerService.cpp
 |
V
HI_Standby_Wakeup(),  framework/base/core/jni/standby_wakeup.c

Related shell commands...
* Trigger standby mode
echo MODE > /sys/power/state
MODE: on, standby, mem

* Test standby/wakeup functions
sample_pmoc

The fix:
Modify the wake-up value from 0x639cff00 to 0xfd024db2 in  HI_Standby_Wakeup().


2013年8月19日 星期一

[Code trace] power management (standby/suspend/resume) mechanism in Android & Linux

[INPUT MNGR]
frameworks/base/services/jni/com_android_server_InputManager.cpp
NativeInputManager::handleInterceptActions() :
dispatch keys to users or filter them as special event key like power control...

handleInterceptActions() callbacks to PowerManagerService goToSleep() for putting to sleep, to another function to wake it up, or passing keys to users

Code flow:
interceptKeyBeforeQueueing(), frameworks/base/services/jni/com_android_server_InputManager.cpp
 |
V
interceptKeyBeforeQueueing(), frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
 |
V
handleInterceptActions(), frameworks/base/services/jni/com_android_server_InputManager.cpp

[PWR MNGR CODE FLOW]
frameworks/base/core/java/android/os/PowerManager.java - API for APPS
 |
V
frameworks/base/services/java/com/android/server/PowerManagerService.java - core
 |
V
frameworks/base/core/java/android/os/Power.java - JNI


Reference links
http://blog.csdn.net/tommy_wxie/article/details/7208633
http://3y.uu456.com/bp-f823387031b76sce0s081439-1.html 

Very good illustration for the architecture of PM in Android
http://www.kandroid.org/online-pdk/guide/power_management.html

This is a very handy illustration on standby/wake framework from top to bottom
http://blog.csdn.net/lizhiguo0532/article/details/6453595

Tells different configuring opions for /sys/power/state
http://www.mjmwired.net/kernel/Documentation/power/states.txt