I have question regarding power management in kernel. What APIs are
available in linux kernel
for power management are available for device drivers? e.g. Driver is
interested in knowing the system
power startes. Which APIs the driver should register for which it will
get notifications of power states
in system?
Previously in linux kernel pm_register was used which is obselete now.
There are other things as well
like APM and ACPI. But for embedded devices, if the driver is
interested in getting the system power
states from kernel, which APIs are used?
/r
Applications:
Once all apps have released their wakelocks
App Framework:
Power manager service decides to suspend the device (if the user turns
off the screen)
by writing "mem" to /sys/power/state
Kernel:
early suspend hooks get called, entry point is:
kerne/power/main.c: state_store()....
196 #ifdef CONFIG_SUSPEND
197 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
198 if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
199 break;
200 }
201 if (state < PM_SUSPEND_MAX && *s)
202 #ifdef CONFIG_EARLYSUSPEND
203 if (state == PM_SUSPEND_ON || valid_state(state)) {
204 error = 0;
205 request_suspend_state(state);
// Early suspend here (screen off is triggered here)
206 }
207 #else
208 error = enter_state(state);
// Regular linux suspend occurs here
209 #endif
210 #endif
The order which events occurs is the following:
early suspend (triggered by pressing power button to turn screen off)
normal supsend hooks (triggered by last wakelock released from the kernel)
cpu sleep
normal resume
late resume (triggers by pressing power button to turn screen on)
If you want to debug suspend, theres a few things you can do.
enable CONFIG_PM_DEBUG and PM_VERBOSE, which combined will print out
to the dmesg when each driver suspends and resumes
There is also:
/sys/module/wakelock/parameters/debug_mask
/sys/module/earlysuspend/parameters/debug_mask
you can see the debug mask flags here:
http://android.git.kernel.org/?p=kernel/common.git;a=blob;f=kernel/power/earlysuspend.c;h=84bed51dcdce79503d718186775e690560d4637b;hb=android-2.6.32
and
-- Mike
This is more linux PM specific not so much Android, but I don't mind
answering here, just for future reference in case you want a wider
audience.
You can the register_pm_notifier() call which will register a
notifier_block and you will receive events PM_SUSPEND_PREPARE,
PM_POST_SUSPEND etc.. Only a few drivers use this, I suggest you only
use this if you have a particular spot in suspend/resume that you need
to be called. Or your driver doesn't fit well in the device tree
More commonly is to use the struct dev_pm_ops and fill in your
.suspend_noirq .resume_noirq etc...
pm_ops seems to be the new way to suspend instead of just using the
suspend/resume calls in say struct platform_driver. Chances are your
driver's struct will have a struct pm_dev_ops in there somewhere that
you can fill out when you register.
Android has an extra early_suspend hook that gets called before all
linux-pm suspend hooks, which I explain above.
-- Mike
>> /r
>
> --
> unsubscribe: android-kerne...@googlegroups.com
> website: http://groups.google.com/group/android-kernel
>
I want to add one more thing here. Also architecture specific power
management will be hooked up with the linux power management framework
like using suspend_set_ops. Which will validate which power management
modes will be supported by the hardware.
i.e when you do cat /sys/power/state
you will see which modes are supported e.g. standby, mem
cheers
raj