How to use Microchip AT91 power management modes

Introduction

This page describes the way Microchip AT91 power management modes could be used in Linux.

Available modes

The Microchip AT91 power management modes are

Standby - CPU switch to WFI
ULP0 - clocks are switch to low frequencies and CPU wakes on any interrupt
ULP1 - clocks are off and the number of CPU wake up sources is limited
Backup and Self-refresh (BSR) - CPU is shutdown and DDR memory is switch to self-refresh mode 

The following table describes Linux Microchip AT91 power management modes supported by each individual Microchip AT91 SoC

SoC Support modes
SAM9X60 standby
ULP0
ULP1
SAM9X7 standby
ULP0
ULP1
SAMA5D4 standby
ULP0
SAMA5D3 standby
ULP0
SAMA5D2 standby
ULP0
ULP1
BSR
SAMA7G5 standby
ULP0
ULP1
BSR

The following table describes Linux Microchip AT91 power management modes supported by individual boards:

Board Support modes
SAM9X60 Curiosity standby
ULP0
ULP1
SAM9X60-EK standby
ULP0
ULP1
SAMA5D4 Xplained standby
ULP0
SAMA5D3 Xplained standby
ULP0
SAMA5D2-ICP standby
ULP0
ULP1
BSR
SAMA5D27 WLSOM1 EK standby
ULP0
ULP1
BSR
SAMA5D27 SOM1 EK standby
ULP0
ULP1
SAMA5D2 PTC EK standby
ULP0
ULP1
SAMA5D2 Xplained standby
ULP0
ULP1
BSR
SAMA7G5-EK standby
ULP0
ULP1
BSR

AT91Bootstrap support

To be able to use backup and self-refresh mode the AT91Bootstrap has to be compiled with the following compilation flag:

CONFIG_BACKUP_MODE

The other power management modes could be used without special support in AT91Bootstrap.

Linux kernel paramenters

When switching to a low power mode Linux will use a Microchip AT91 power management modes if these modes were previously specified as kernel parameter from bootloader.

In Linux4sam reference distributions U-Boot is used as kernel bootloader. The Microchip AT91 power management modes are passed to kernel via bootargs U-Boot variable in the format:

atmel.pm_modes=<standby-mode>,<suspend-mode>

The following table describes the value that could be provided in atmel.pm_modes variable and it's effect when executing Linux specific power management commands.

Mode Value Selected by Linux command Action while executing Linux power saving commands
standby-mode standby echo standby > /sys/power/state Switching to normal Linux standby mode
ulp0 Switching to Microchip AT91 ULP0 mode
ulp1 Switching to Microchip AT91 ULP1 mode
backup Switching to Microchip AT91 backup and self-refresh mode
suspend-mode standby echo mem > /sys/power/state Switching to normal Linux standby mode
ulp0 Switching to Microchip AT91 ULP0 mode
ulp1 Switching to Microchip AT91 ULP1 mode
backup Switching to Microchip AT91 backup and self-refresh mode

In the booting process Microchip AT91 power management modes are mapped to standard Linux power management modes. Linux power management modes are called standby and suspend. To see how Microchip AT91 power management modes are mapped to Linux power management mode the following command could be executed after boot:

root@sama7g5ek-sd:~# dmesg | grep -i pm:
[    0.050991] AT91: PM: standby: standby, suspend: ulp0

This means that Microchip AT91 standby mode is mapped to Linux standby mode and Microchip AT91 ULP0 mode is mapped to Linux suspend mode.

Examples of configurations

The following examples assume that user used AT91Bootstrap and U-Boot bootloaders.

How to use ULP0 and BSR Microchip AT91 power management modes

To be able to use ULP0 and BSR Microchip AT91 power management modes the following settings has to be done:

1. Compile AT91Bootstrap with CONFIG_BACKUP_MODE flag
2. U-Boot bootargs variable has to contain: atmel.pm_modes=ulp0,backup

For instance, on SAMA5D2 Xplained board which boots form SD card, U-Boot bootargs should look similar to this:

bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait atmel.pm_modes=ulp0,backup

To switch to ULP0 mode from Linux execute the following command:

echo standby > /sys/power/state

To switch to backup and self-refresh mode from Linux execute the following command:

echo mem > /sys/power/state

How to use ULP0 and ULP1 Microchip AT91 power management modes

To be able to use ULP0 and ULP1 Microchip AT91 power management modes the following settings has to be done:

1. U-Boot bootargs variable has to contain: atmel.pm_modes=ulp0,ulp1

For instance, on SAMA5D2 Xplained board which boots form SD card, U-Boot bootargs should look similar to this:

bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait atmel.pm_modes=ulp0,ulp1

To switch to ULP0 mode from Linux execute the following command:

echo standby > /sys/power/state

To switch to ULP1 mode from Linux execute the following command:

echo mem > /sys/power/state

If, instead of using echo standby > /sys/power/state to switch to ULP0 you want to use echo mem > /sys/power/state and vice versa, the atmel.pm_modes variable has to be in the format:

atmel.pm_modes=ulp1,ulp0

For instance, on SAMA5D2 Xplained board which boots form SD card, U-Boot bootargs should look similar to this:

bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait atmel.pm_modes=ulp1,ulp0

How to use standard Linux power management modes

To be able to use standard Linux power management modes just don't place atmel.pm_modes as part of U-Boot bootargs variable or specify standby in atme.pm_modes (something like atmel.pm_modes=standby,ulp0)

For instance, on SAMA5D2 Xplained board which boots form SD card, U-Boot bootargs should look similar to this:

bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait

Wake up sources for SAMA5D2 Xplained board

This section will explain the wake up sources for SAMA5D2 Xplained board.

Wake up sources for ULP0 and standard Linux standby mode

ULP0 and normal Linux standby mode could use any interrupt to wake up from a power management mode. There are 2 ways of configuring wake up sources:
1. via /sys/devices/.../power/wakeup
2. via device tree

/sys/devices/.../power/wakeup

To configure a device to act as a wake up source for ULP0 and standard Linux standby mode just type enabled or disabled in power/wakup file specific to the device.

For instance, to configure PB1 button on SAMA5D2 Xplained board, to act as wake up source for ULP0 enter the following command on Linux:

echo enabled > /sys/devices/platform/gpio_keys/power/wakeup

Or, to disable it:

echo disabled > /sys/devices/platform/gpio_keys/power/wakeup

Device tree wake up

To configure a device to act as a wake up source for ULP0 and standard Linux standby mode just use "wakup-source" device tree propriety on the device itself in device tree.

For instance, to configure PB1 button on SAMA5D2 Xplained board, to act as wake up source for ULP0 the device tree bindings for PB2 button should look similar to this:

gpio_keys {                                                             
   compatible = "gpio-keys";

   pinctrl-names = "default";
   pinctrl-0 = <&pinctrl_key_gpio_default>;

   bp1 {
      label = "PB_USER";
      gpios = <&pioA PIN_PB9 GPIO_ACTIVE_LOW>;
      linux,code = <0x104>;
      wakeup-source;
   };
};

Wake up sources for ULP1 mode

In ULP1 wake up source are limited.

Linux4sam 6.0 kernel

In Linux4sam 6.0 wake up source for ULP1 could be configured via device tree.

For instance, to configure PB2 button and Ethernet to act as a wake up sources the device tree bindings for PMC should look similar to this:

pmc: pmc@f0014000 {
   pmc_fast_restart {
      compatible = "atmel,sama5d2-pmc-fast-startup";
      #address-cells = <1>;
      #size-cells = <0>;

      wkpin: input@0 {
         reg = <0>;
      };

      gmac_wol: input@10 {
         reg = <10>;
         atmel,wakeup-active-high;
      };
   };
};

For more information check Fast startup for Ultra Low-Power (ULP) Mode 1 in SAMA5D2 datasheet

Vanilla kernel

In vanilla kernel ULP1 wake up sources could be configured via /sys/devices/.../power/wakeup files as explained above.

Wake up sources for backup and self-refresh mode

In backup and self refresh-mode wake up sources for SAMA5D2 Xplained boards are limited to PB2 button.

Board BSR wakeup sources
SAMA5D2-ICP RTC
START button
SAMA5D27 WLSOM1 EK RTC
START SOM button
SAMA5D2 Xplained RTC
PB2 button
SAMA7G5-EK RTC
nSTART button

For instance, to configure PB2 button on SAMA5D2 Xplained board to act as wake up source the device tree bindings for shutdown controller should look similar to this:

shdwc@f8048010 {
   atmel,shdwc-debouncer = <976>;
   
   input@0 {
      reg = <0>;
      atmel,wakeup-type = "low";
   };
};

Limitations

For ULP1 implementation in vanilla kernel, currently, there is no way to resume from ACC or RXLP events. For this reason the in Linux4sam 6.0 implementation is still based on device tree bindings.

-- Claudiu Beznea - 2018-10-17