How to use SAMA5D2 power management modes

Introduction

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

Available modes

The SAMA5D2 power management modes are

Idle - 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 - CPU is shutdown and DDR memory is switch to self-refresh mode 

Supported boards

The ULP0, ULP1 and backup and self-refresh SAMA5D2 power management modes are currently supported only by SAMA5D2 Xplained board.

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 SAMA5D2 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 SAMA5D2 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 SAMA5D2 ULP0 mode
ulp1 Switching to SAMA5D2 ULP1 mode
backup Switching to SAMA5D2 backup and self-refresh mode
suspend-mode standby echo mem > /sys/power/state Switching to normal Linux standby mode
ulp0 Switching to SAMA5D2 ULP0 mode
ulp1 Switching to SAMA5D2 ULP1 mode
backup Switching to SAMA5D2 backup and self-refresh mode

Examples of configurations

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

How to use ULP0 and Backup and self-refresh SAMA5D2 power management modes

To be able to use ULP0 and backup and self-refresh SAMA5D2 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 SAMA5D2 power management modes

To be able to use ULP0 and ULP1 SAMA5D2 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.

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 wakep

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.

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

Linux4sam reference distributions supports all the SAMA5D2 power management modes described above. However to be able to use backup and self-refresh mode on vanilla kernel the following patches has to be applied on top of vanilla kernel for PMIC to correctly suspend and resume:

regulator: Extend the power-management APIs
regulator: Document the regulator-allow-changes-at-runtime DT property
ARM: at91: Call regulator_suspend_{begin, end}() in the platform pm ops
regulator: act8945: Implement PM functionalities
ARM: at91/dt: sama5d2_xplained: Add proper regulator states for suspend-to-mem

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 the current implementation is still based on device tree bindings.

-- Claudiu Beznea - 2018-10-17

r3 - 18 Oct 2018 - 12:43:34 - ClaudiuBeznea
 
Linux & Open Source related information for AT91 Smart ARM Microcontrollers

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.

Atmel® and others, are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. This site is powered by the TWiki collaboration platform

ARM® and others are registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others.

Ideas, requests, contributions ? Connect to LinksToCommunities page.

Syndicate this siteRSS ATOM