2
votes

I am working on a lcd related kernel level device driver for a android device. Can someone please help me with power management related APIs in Android through which I can register my driver to recieve any changes in device state.

To be more precise I want my driver to recieve any events from power driver(or is there something else) in case when the system state changes, for example from running state to sleep state or suspend state. I would want my driver also to sleep which in current scenario is eating up all the battery..

I have got few links http://www.kandroid.org/online-pdk/guide/power_management.html and http://developer.android.com/reference/android/os/PowerManager.html

which talks about functions like android_register_early_suspend and android_register_early_resume but I could not find any call to these functions in my entire kernel source code (based on linux 3.0)

I have heard of "Linux Power Management" and can find folders like drivers/base/power and drivers/power in my current baseline code. How can I use this driver in my code.

Please let me know if I am missing with any details. Any help would be highly appreciated.

1

1 Answers

2
votes

Your Driver should implement Runtime suspend/resume callbacks. Check this doc.

sample code to implement Device PM callbacks in 'struct dev_pm_ops' (as defined in linux/pm.h)

static int lcdxxx_suspend(struct device *dev)
{
    //Your Code to suspend your device
}

static int lcdxxx_resume(struct device *dev)
{
    //Your code to resume your device
}

static const struct dev_pm_ops lcd_pm_ops = {
    .suspend    = lcdxxx_suspend,
    .resume     = lcdxxx_resume,
};

struct device_driver lcd_driver = {
    ....
    .pm = &lcd_pm_ops,
    ....
}

This is just sample impl. Real Implementation depends on your requirements.