Skip to content

dts: bindings: Add st,reinit-power-states DT property #60369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dts/bindings/adc/st,stm32-adc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: ST STM32 family ADC

compatible: "st,stm32-adc"

include: [adc-controller.yaml, pinctrl-device.yaml]
include: [adc-controller.yaml, pinctrl-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/crypto/st,stm32-crypto-common.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2020, Markus Fuchs <markus.fuchs@de.sauter-bc.com>
# SPDX-License-Identifier: Apache-2.0

include: base.yaml
include: [base.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/dac/st,stm32-dac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: ST STM32 family DAC

compatible: "st,stm32-dac"

include: [dac-controller.yaml, pinctrl-device.yaml]
include: [dac-controller.yaml, pinctrl-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/dma/st,stm32-dma.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: |

compatible: "st,stm32-dma"

include: dma-controller.yaml
include: [dma-controller.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/dma/st,stm32-dmamux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ description: |

compatible: "st,stm32-dmamux"

include: dmamux-controller.yaml
include: [dmamux-controller.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/i2c/st,stm32-i2c-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: STM32 I2C V2 controller

compatible: "st,stm32-i2c-v2"

include: [i2c-controller.yaml, pinctrl-device.yaml]
include: [i2c-controller.yaml, pinctrl-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
12 changes: 12 additions & 0 deletions dts/bindings/power/st,power-management.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023 Kenneth J. Miller <ken@miller.ec>
# SPDX-License-Identifier: Apache-2.0

properties:
st,reinit-power-states:
type: phandles
description: |
Specifies special power states where a peripheral requires
reinitialization due to configuration loss.

While states at or beyond S2RAM are naturally assumed to need
reinitialization, this property highlights the exceptions to that rule.
2 changes: 1 addition & 1 deletion dts/bindings/rng/st,stm32-rng.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: STM32 Random Number Generator

compatible: "st,stm32-rng"

include: base.yaml
include: [base.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/serial/st,stm32-uart-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Common fields for STM32 UART peripherals.
description: STM32 UART-BASE

include: [uart-controller.yaml, pinctrl-device.yaml, reset-device.yaml]
include: [uart-controller.yaml, pinctrl-device.yaml, reset-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/spi/st,stm32-spi-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Common fields for STM32 SPI peripherals.

include: [spi-controller.yaml, pinctrl-device.yaml]
include: [spi-controller.yaml, pinctrl-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
2 changes: 1 addition & 1 deletion dts/bindings/timer/st,stm32-timers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: STM32 timers

compatible: "st,stm32-timers"

include: [base.yaml, reset-device.yaml]
include: [base.yaml, reset-device.yaml, "st,power-management.yaml"]

properties:
reg:
Expand Down
91 changes: 91 additions & 0 deletions include/zephyr/devicetree/pm_stm32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2023 Kenneth J. Miller
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_DEVICETREE_PM_STM32_H_
#define ZEPHYR_INCLUDE_DEVICETREE_PM_STM32_H_

#include <zephyr/pm/state.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Helper macro to initialize an entry of a struct pm_state_info array
* when using UTIL_LISTIFY in PM_STATE_INFO_LIST_FROM_DT_REINIT.
*
* @note Only enabled states are initialized.
*
* @param i UTIL_LISTIFY entry index.
* @param node_id A node identifier with compatible zephyr,power-state
*/
#define Z_PM_STATE_INFO_FROM_DT_REINIT(i, node_id) \
COND_CODE_1( \
DT_NODE_HAS_STATUS(DT_PHANDLE_BY_IDX(node_id, st_reinit_power_states, i), okay), \
(PM_STATE_INFO_DT_INIT(DT_PHANDLE_BY_IDX(node_id, st_reinit_power_states, i)),), \
())
Comment on lines +25 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't exactly your current concern, but as we discussed, for 90-ish % of cases, reinit-power-state will be standby.
I wonder where we'll be able to get it taken into account:
I don't think this should be added in each peripheral driver since we'll just be duplicating information
Should/Could it be done directly in current macro ?


/**
* @brief Initialize an array of struct pm_state_info with information from all
* the states present and enabled in the given device node identifier.
*
* Example devicetree fragment:
*
* @code{.dts}
*
* cpus {
* cpu0: cpu@0 {
* device_type = "cpu";
* ...
* cpu-power-states = <&state0 &state1>;
* };
*
* power-states {
stop1: state1 {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
substate-id = <2>;
...
};
stop2: state2 {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
substate-id = <3>;
...
};
* };
* };
*
* soc {
* i2c1: i2c@50000000 {
* ...
* compatible = "st,stm32-i2c-v2";
* st,reinit-power-states = <&stop2>;
* };
* };
*
* @endcode
*
* Example usage:
*
* @code{.c}
* const struct pm_state_info states[] =
* PM_STATE_INFO_LIST_FROM_DT_REINIT(DT_NODELABEL(i2c1));
* @endcode
*
* @param node_id A device node identifier.
*/
#define PM_STATE_INFO_LIST_FROM_DT_REINIT(node_id) \
{ \
LISTIFY(DT_PROP_LEN_OR(node_id, st_reinit_power_states, 0), \
Z_PM_STATE_INFO_FROM_DT_REINIT, (), node_id) \
}

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_INCLUDE_DEVICETREE_PM_STM32_H_ */