2010年1月5日 星期二

android power management

PM_SUSPEND_MEM -> mxc_cpu_lp_set(STOP_POWER_OFF)
PM_SUSPEND_STANDBY-> mxc_cpu_lp_set(WAIT_UNLOCKED_POWER_OFF)


~/myandroid/frameworks/base/services/java/com/android/server/PowerManagerService.java]
It offers the core service and is encapsulated as the package com.android.server. It calls Power.java to do the real job.

[~/myandroid/frameworks/base/core/java/android/os/Power.java]
It will communicate with the low level through JNI.

[~/myandroid/frameworks/base/core/jni/android_os_Power.cpp]
It is the JNI implementation for Power.java. It will call lower level power.c

[~/myandroid/hardware/libhardware_legacy/power/power.c]
In this file, it offers some functions, like initialize_fds(), though writing or reading some files, to control the power divice driver.

On the kernel side,

[~/myandroid/kernel_imx/include/linux/sysfs.h]
A macro __ATTR is defined in this file.

[~/myandroid/kernel_imx/kernel/power/main.c]
state_show() and state_store() are defined in this file. In state_store(), request_suspend_state function is called.


这个东东又不是驱动——我不清楚它是如何将最简单的用户态系统调用write最终映射到这个
> state_store上来的(或者说我没有找到的某个更上层的函数)~

这个涉及到sysfs文件系统和kobject.

在state_store下面有个宏power_attr(state),它定义了一个kobj_attribute (state_attr), 在pm_init()的时候会创建一个名为power的kobject.最后通过sysfs_create_group会在/sys/下面创建一个 power的目录,这个目录下面会后所有在kernel/power/main.c里定义的attribute(在g[]中), 包括state_attr.读写这些attribute的话就会调用相应attribute的show和store函数。这些都是在sysfs里面做的,使用者只需准备好这些函数就行了。

call trace is like following:

sys_write -> sysfs_write_file -> flush_write_buffer -> sysfs_ops.store
(sysfs_ops在open一个sysfs文件的时候会设置,这里是kobj_sysfs_ops)

-> kobj_sysfs_ops.store (kobj_attr_store) -> state_store

[~/myandroid/kernel_imx/kernel/power/earlysuspend.c]
The request_suspend_state() is defined here and it will generate the debug info about suspend status changing in console.

沒有留言:

張貼留言