Here's the tenth post in the Build-a-Driver series for MCP9808.
(If this post seems out of context, please refer to "Build-a-Driver Introduction" post.)
Adding support for the PM (power management) operations SUSPEND/RESUME.
These kernel documents explain the design and testing of PM OPs.
- move shutdown functionality out of .remove so it can be reused for the suspend operation
- create mcp9808_suspend/resume functions inside an #ifdef CONFIG_PM_SLEEP
- _suspend(): do a sensor shutdown prior to sleep (stop continuous conversion mode)
- _resume(): will set the integration time to last known time, in case we lost complete power during the suspend. It will then turn back on sensor continuous conversion mode.
- define the pm_ops routines and declare in the i2c_driver structure
I used this script to verify on a virtual machine using the Diolan adapter
echo devices > /sys/power/pm_test
echo reboot > /sys/power/disk
echo disk > /sys/power/state
Labels: Build-a-Driver, iio, IIO Driver, MCP9808, power management, resume, suspend, Temperature Sensor