Using Power Management Features

Introduction

You can put your module into two different power states: standby and power-down. In standby mode the PLLs of the AT91SAM9G20 are still running, in power-down modus the PLLs and the 18.432 MHz crystal is shut off. In practice this has some effect with which interrupts the device can wakeup. For example in standby mode you can wake up your device by typing a character on the serial console. In power-down mode this will not work, because without PLL you will not have a correct baudrate.
In this FAQ we will demonstrate how to use power saving features and wake up the device by using the wake alarm of the RTC and the sysfs interface on the console.

Power states

You can put your device in standby mode by writing /sys/power/state:

echo standby > /sys/power/state

or in power-down mode:

echo mem > /sys/power/state

As mentioned above, if you have put your device in power-down mode without setting a wake alarm in your RTC, your device will not wake up anymore.

Setting the wake alarm

The wake alarm is set by writing to /sys/class/rtc/rtc0/wakealarm. You can either write a value from seconds elapsed since epoch (1.1.1970) or a value of seconds from now.

echo "+20" > /sys/class/rtc/rtc0/wakealarm

will issue an interrupt in twenty seconds from now. Prior to setting a new alarm, you have to clear the value already written:

echo "" > /sys/class/rtc/rtc0/wakealarm

Putting it together

So using standby with wake up in twenty seconds can be done like this:

echo "" > /sys/class/rtc/rtc0/wakealarm
echo "+20" > /sys/class/rtc/rtc0/wakealarm
echo standby > /sys/power/state

and power-down:

echo "" > /sys/class/rtc/rtc0/wakealarm
echo "+20" > /sys/class/rtc/rtc0/wakealarm
echo mem > /sys/power/state

Rootfs on sd- and mmc-card

You have to add some options to your kernel. From kernel 2.6.35 on add the following argument to your bootargs, this has to be done in u-boot:

mmc_core.removable=0

For earlier kernel versions you have to enable a option in your kernel config and produce a new kernel:

Device Drivers ---> MMC/SD/SDIO card support ---> Allow unsafe resume