1. Purpose[edit | edit source]
This article describes how to configure the PWR wake-up pins for use in Linux, using the OP-TEE driver.
The PWR wake-up pins are used to wake the system from Standby using an external device.
This article applies to all STM32 Arm® Cortex® MPUs
in OpenSTLinux when the PWR peripheral is assigned exclusively to OP-TEE.
This was not the case for STM32MP15x lines
before ecosystem release v7.0.0
, when PWR wake-up interrupts were handled by the Linux pwr_irq irqchip driver.
2. Overview[edit | edit source]
- Hardware:
- Button: one external device connected to a wake-up pin. This could also be a PMIC.
- PWR: PWR internal peripheral
- OP-TEE in Secure world:
- PWR IRQ driver: the driver responsible for managing the PWR peripheral and providing access to the wake-up pin through an interrupt interface.
- EXTI driver: manages wake-up IRQs, including PWR interrupts
- STM32 IRQ notifier: driver used to manage interrupts and forward events as notifications to the non-secure world.
- OP-TEE notification: stack responsible for communication with the non-secure world.
- Linux kernel space:
- Linaro OP-TEE driver: stack responsible for communication with the secure world. Transforms OP-TEE notifications to interrupts.
- GPIO keys driver: a Linux driver that uses a wake-up pin handled by OP-TEE. Other Linux drivers that can handle interrupts could also be used.
3. Wake-up pin configuration[edit | edit source]
3.1. OP-TEE configuration[edit | edit source]
PWR in OP-TEE is an interrupt provider and each WKUP pin is associated with an interrupt line. In the SoC device tree, each PWR interrupt (index 0 for WKUP1 through index 5 for WKUP6) is associated with the corresponding EXTI (see the reference manual for details):
For STM32MP1 series, EXTI 55 to EXTI 60 (see examples in core/arch/arm/dts/stm32mp131.dtsi and core/arch/arm/dts/stm32mp151.dtsi )
exti: interrupt-controller@5000d000 {
compatible = "st,stm32mp1-exti";
...
<&pwr_irq 0 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP1
<&pwr_irq 1 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP2
<&pwr_irq 2 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP3
<&pwr_irq 3 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP4
<&pwr_irq 4 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP5
<&pwr_irq 5 IRQ_TYPE_EDGE_FALLING>, /* EXTI_60 */ interrupt for WKUP6
...
For STM32MP2 series, EXTI1 52 to EXTI1 57 (see the example in core/arch/arm/dts/stm32mp211.dtsi , core/arch/arm/dts/stm32mp231.dtsi or core/arch/arm/dts/stm32mp251.dtsi )
exti1: interrupt-controller@44220000 {
compatible = "st,stm32mp1-exti", "syscon";
interrupts-extended =
...
<&intc GIC_SPI 210 IRQ_TYPE_LEVEL_HIGH>, /* EXTI_50 */
<0>,
<&pwr 0 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP1
<&pwr 1 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP2
<&pwr 2 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP3
<&pwr 3 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP4
<&pwr 4 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP5
<&pwr 5 IRQ_TYPE_EDGE_FALLING>, interrupt for WKUP6
<0>,
...
In the OP-TEE device tree, the WKUP user is associated with this EXTI interrupt and the corresponding WKUP pin is configured in the PWR node.
The generic interrupts-extended device tree property identifies this EXTI interrupt (see the Interrupt overview page for details) and specifies its polarity as IRQ_TYPE_EDGE_RISING or IRQ_TYPE_EDGE_FALLING.
Each PWR WKUP pin is configured in the OP-TEE device tree through the wakeup-gpios property in the pwr node, following the generic GPIO device tree configuration.
In the SoC device tree, all WKUP pins are unassigned by default:
wakeup-gpios = <0>, <0>, <0>, <0>, <0>, <0>;
In the board device tree, configure the six WKUP GPIOs using the wakeup-gpios property. Unassigned WKUP pins are indicated by <0>. Configure the wake-up pull for each pin (maintained in Standby mode) using GPIO_PULL_UP, GPIO_PULL_DOWN or GPIO_ACTIVE_HIGH (no pull).
Note: The WKUP pins for each STM32 MPU are listed in its datasheet and validated by the OP-TEE PWR IRQ driver.
- For STM32MP1 series in core/arch/arm/plat-stm32mp1/drivers/stm32mp1_pwr_irq.c :
#ifdef CFG_STM32MP13
static const struct stm32_pwr_pin_map pin_map[PWR_NB_WAKEUPPINS] = {
{ .bank = GPIO_BANK('F'), .pin = 8, },
{ .bank = GPIO_BANK('I'), .pin = 3, },
{ .bank = GPIO_BANK('C'), .pin = 13, },
{ .bank = GPIO_BANK('I'), .pin = 1, },
{ .bank = GPIO_BANK('I'), .pin = 2, },
{ .bank = GPIO_BANK('A'), .pin = 3, },
};
#endif
#ifdef CFG_STM32MP15
static const struct stm32_pwr_pin_map pin_map[PWR_NB_WAKEUPPINS] = {
{ .bank = GPIO_BANK('A'), .pin = 0, },
{ .bank = GPIO_BANK('A'), .pin = 2, },
{ .bank = GPIO_BANK('C'), .pin = 13, },
{ .bank = GPIO_BANK('I'), .pin = 8, },
{ .bank = GPIO_BANK('I'), .pin = 11, },
{ .bank = GPIO_BANK('C'), .pin = 1, },
};
#
- For STM32MP2 series in core/arch/arm/plat-stm32mp2/drivers/stm32mp25_pwr_irq.c :
WKUP pins are PA0 PH5 PG1 PI6 PG2 PG3
static const struct stm32_pwr_pin_map pin_map[PWR_NB_WAKEUPPINS] = {
{ .bank = GPIO_BANK('A'), .pin = 0, },
{ .bank = GPIO_BANK('H'), .pin = 5, },
{ .bank = GPIO_BANK('G'), .pin = 1, },
{ .bank = GPIO_BANK('I'), .pin = 6, },
{ .bank = GPIO_BANK('G'), .pin = 2, },
{ .bank = GPIO_BANK('G'), .pin = 3, },
};
See the binding for details: documentation/devicetree/bindings/mfd/st,stm32mp25-pwr.yaml
A stm32-irq-notifier node can be instantiated on the EXTI line associated with the selected PWR WKUP pin to handle that wake-up pin; when the associated interrupt occurs, the driver sends an OP-TEE notification with identifier st,notif-it-id to Linux in the non-secure world:
- binding documentation: documentation/devicetree/bindings/soc/stm32/st,stm32-irq-notifier.yaml
- driver: core/drivers/stm32_irq_notif.c
3.2. Linux configuration[edit | edit source]
Linux does not handle the wake-up pin directly, but it can handle an OP-TEE notification as an interrupt.
This is configured via the interrupts-extended device tree property[1] and the notification index defined in the OP-TEE device tree with st,notif-it-id.
See Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.yaml for details.
4. Examples[edit | edit source]
4.1. wake-up pin 2[edit | edit source]
In the simple example below, OP-TEE configures wake-up pin 2 (EXTI 56 and GPIO PI3) to trigger on a falling edge with a pull-up. The interrupt is forwarded to Linux with notification ID 4, where the "gpio-keys" driver uses it to generate a key press.
OP-TEE device tree:
wakeup_button: wakeup-button {
compatible = "st,stm32-irq-notifier";
interrupts-extended = <&exti 56 IRQ_TYPE_EDGE_FALLING>;
wakeup-source;
status = "okay";
};
};
&pwr_irq {
wakeup-gpios = <0>, <&gpioi 3 GPIO_PULL_UP>, <0>, <0>, <0>, <0>;
status = "okay";
};
Linux device tree:
wake_up {
compatible = "gpio-keys";
status = "okay";
button {
label = "wake-up";
linux,code = <KEY_WAKEUP>;
interrupts-extended = <&optee 4>;
status = "okay";
};
};
4.2. STM32MP135F-DK
[edit | edit source]
You can also find an example of PWR IRQ usage in the OP-TEE device tree for the board STM32MP135F-DK
: core/arch/arm/dts/stm32mp135f-dk.dts
\ {
magic_wol: magic_wol {
compatible = "st,stm32-irq-notifier";
interrupts-extended = <&exti 56 IRQ_TYPE_EDGE_FALLING>; interrupt for WKUP2
wakeup-source;
status = "okay";
};
typec_wakeup: typec_wakeup {
compatible = "st,stm32-irq-notifier";
interrupts-extended = <&exti 59 IRQ_TYPE_EDGE_FALLING>; interrupt for WKUP5
wakeup-source;
st,notif-it-id = <1>; notification identifier for Linux
status = "okay";
};
};
&i2c4 {
pinctrl-names = "default";
pinctrl-0 = <&i2c4_pins_a>;
i2c-scl-rising-time-ns = <185>;
i2c-scl-falling-time-ns = <20>;
clock-frequency = <400000>;
status = "okay";
pmic: stpmic@33 {
compatible = "st,stpmic1";
reg = <0x33>;
status = "okay";
interrupts-extended = <&exti 55 IRQ_TYPE_EDGE_FALLING>; interrupt for WKUP1
...
};
};
&pwr_irq {
status = "okay";
wakeup-gpios = <&gpiof 8 GPIO_ACTIVE_HIGH>, GPIO configuration for WKUP1
<&gpioi 3 GPIO_ACTIVE_HIGH>, GPIO configuration for WKUP2
<0>,
<0>,
<&gpioi 2 GPIO_PULL_UP>, GPIO configuration for WKUP5
<0>;
};
In the Linux device tree arch/arm/boot/dts/st/stm32mp135f-dk.dts :
&i2c1 {
...
typec@53 {
compatible = "st,stm32g0-typec";
reg = <0x53>;
/* Alert pin on PI2 (PWR wakeup pin), managed by optee */
interrupts-extended = <&optee 1>;
firmware-name = "stm32g0-ucsi.mp135f-dk.fw";
wakeup-source;
connector {
compatible = "usb-c-connector";
label = "USB-C";
port {
con_usb_c_g0_ep: endpoint {
remote-endpoint = <&usbotg_hs_ep>;
};
};
};
};
};
5. Source code location[edit | edit source]
The source files are located in the OP-TEE source tree.
- OP-TEE PWR IRQ driver:
- core/arch/arm/plat-stm32mp1/drivers/stm32mp1_pwr_irq.c for STM32MP1 series
- core/arch/arm/plat-stm32mp2/drivers/stm32mp25_pwr_irq.c for STM32MP2 series
- OP-TEE STM32 IRQ notifier:
6. References[edit | edit source]
- ↑ Generic interrupts bindings documentation: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt