Commit graph

74 commits

Author SHA1 Message Date
Francois Ramu fd5ce64db4 soc: arm: st_stm32 add low power to stm32wb series
This patch introduces the support of low power modes
for the STM32WBxx from STMicroelectronics based on the lptim
Here, the power modes are sleep modes have lptimer as wakeup source.
The sleep modes are configured by the SYS_POWER_MANAGEMENT.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-07-02 08:45:40 -04:00
Peter Bigot 219a3ca96d device: provide internal access to static device array
Device objects in Zephyr are currently placed into an array by linker
scripts, making it easy to iterate over all devices if the array
address and size can be obtained.  This has applications in device
power management, but the existing API for this was available only
when that feature was enabled.  It also uses a signed type to hold the
device count.

Provide a new API that is generally available, but marked as internal
since normally applications should not iterate over all devices.  Mark
the PM API approach deprecated.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-23 13:27:14 +02:00
Francois Ramu bd17ff7a51 soc: arm: st_stm32 add low power to stm32l4 series
This patch introduces the support of low power modes
for the STM32L4xx from STMicroelectronics based on the lptim
Here, the power modes are sleep modes with lptimer as wakeup.
Depending on the SYS_POWER_MANAGEMENT configuration.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2020-06-15 16:54:04 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Tomasz Bursztyka d2a139ee9b power: Let's have core device setup in case of CONFIG_NET_TEST
This will be useful to test network stack's power management support.
There is no other way to do it, so far, but to hardcode such config
option test there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-26 21:41:00 +02:00
Peter Bigot d99aa367f6 power: device: adapt to new behavior for devices with nop pm ctrl
For backwards compatibility ignore not-supported errors for devices
that don't support power management.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-21 20:32:12 +02:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Carles Cufi 04d1104ee5 timeouts: Fix power _sys_suspend invocation
Use K_TICKS_FOREVER instead of K_FOREVER after the timeout API rework.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 11:01:55 +02:00
Carles Cufi 0d2b74bc6f power: ti: Port to the new timeouts API
Port the TI-related code in subsys/power so it complies with the new
timeouts API.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 11:01:55 +02:00
Peter Bigot cce7165ea4 power: device: reduce space required to identify pm-capable devices
Use a smaller ordinal type than int to hold the global index
identifying devices that support power management.

Use an upper bound instead of an array of flags to identify the
devices that were successfully suspended.

Only attempt pm on devices that provide a non-default pm control
function.

Use shorter more descriptive names for state variables.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-27 15:36:48 +02:00
Kumar Gala 9c6c1f966c drivers: ethernet: eth_mcux: Convert to using DT_INST macros
Convert driver to use instance macro's instead of dts_fixup.h based
macros.  This moves us closer to removing both dts_fixup.h and per
instance Kconfig symbols.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 07:40:37 -05:00
Andy Ross 7832738ae9 kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument.  Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created.  This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.

The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.

The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.

Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.

For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided.  When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.

Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions.  These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig.  These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.

k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.

Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate.  Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure.  But k_poll() does not fail
spuriously, so the loop was removed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Vincent Wan 4a8cfe02a3 power: policy: cc13x2_cc26x2: remove unnecessary sleep state conditions
Minor clean up to remove unnecessary references in the code to
CONFIG_HAS_SYS_POWER_STATE_SLEEP_1 and
CONFIG_HAS_SYS_POWER_STATE_SLEEP_2, as they are always defined for this
SoC.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-31 07:38:31 -05:00
Vincent Wan 8cf74c8e02 power: policy: cc13x2_cc26x2: guard references to sleep states
Use of macros such as SYS_POWER_STATE_SLEEP_2 needs to be guarded by
making sure CONFIG_SYS_POWER_SLEEP_STATES is defined.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-31 07:38:31 -05:00
Tomasz Bursztyka 839bacc0f0 power management: Add k6x SOC core list
Just inserting mcux's ethernet device there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Vincent Wan 61625366c9 power: policy: only bring devices to low-power when in sleep mode 2
Sleep mode 1 is supposed to be a low-latency sleep mode where devices
are left in active mode. Thus we should only bring devices to low-power
when in sleep mode 2 in sys_pm_policy_low_power_devices().

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-25 16:21:33 -04:00
Vincent Wan 41cc9b2c2a power: device: add core device list for cc13xx/cc26xx
Update the core device list to support device power management.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-25 16:21:33 -04:00
Peter Bigot e70de6ee82 power: device: fix name for Nordic clock driver
The device power management infrastructure maintains a hard-coded list
of critical devices to ensure suspend and resume are performed in the
proper order.  PR #21298 combined the 32 KiHz and 16 MHz clock devices
into a single driver, changing the name so the clock driver is not
handled at the correct time, but rather at whatever point it appears
in the general device list.

Update the list to the current clock driver name.  Also store the
device names as standard strings rather than padding them to a fixed
length.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-03-16 15:54:36 +01:00
Vincent Wan 5637def2b3 power: policy: add PM policy function for TI CC13X2/CC26X2
Create a residency-based system power policy function for TI
CC13X2/CC26X2 that uses TI's Power module.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-12 19:22:53 -06:00
Marcin Niestroj 21409494d1 power: device: deduplicate suspending code
Function to put devices in lower power mode were all implemented in the
same way. Deduplicate code there by implementing single function to
handle all cases.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-02-02 09:05:15 -05:00
Marcin Niestroj 8224a449a2 power: device: use ARRAY_SIZE() for getting number of core_devices
There is no point to specify number of core devices explicitly, as it
can be done by compiler with ARRAY_SIZE() macro.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-02-02 09:05:15 -05:00
Wentong Wu ac2b117acd power: policy: recover deep sleep states from residency policy.
Commit c248cdf17e remove deep sleep states
from residency policy based on SoC loses context in deep sleep states to
avoid a "forever timeout" power-off the whole system. It's right if deep
sleep means power off whole system only.

One of deep sleep states is that most power domains are shut off, but
except a few that retain just enough logic to allow the CPU to resume
from the same point of execution where it went to sleep. This is well
documented and implementations also have same behavior.

For another deep sleep state, system off, sys_pm_ctrl_disable_state can
prevent system off unexpectedly from being entered on long timeout. And
sys_pm_force_power_state can help power off whole system.

This reverts commit c248cdf17e.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-26 11:13:22 -08:00
Wentong Wu 7cb74655da power: add system power management direct force mode.
Add system power management direct force trigger mode. In this
mode application thread can directly put system in sleep or deep
sleep mode instead of waiting for idle thread to do it, so that
it can reduce latency to enter low power mode.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-24 21:37:40 -05:00
Wentong Wu a9bd208b5b Power: change sys_pm_force_power_state only works for one shot
Change sys_pm_force_power_state only works for the current ongoing
suspend operation, before the end of syspend state forced_pm_state
will be cleared.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-24 21:37:40 -05:00
Marcin Szymczyk 2d6c6959f9 soc: nrf91: add power management
Only System OFF mode is supported.

Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
2020-01-10 13:09:44 +01:00
Marcin Szymczyk 32b3ab2354 soc: nrf53: add power management
Only System OFF mode is supported.

Signed-off-by: Marcin Szymczyk <marcin.szymczyk@nordicsemi.no>
2020-01-10 13:09:44 +01:00
Wentong Wu 7d2586533d power: add DEVICE_PM_LOW_POWER_STATE for device power management
When system going to sleep state, make peripherals go to state
DEVICE_PM_LOW_POWER_STATE which needs less time than state
DEVICE_PM_SUSPEND_STATE to save more power.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-04 09:23:15 -05:00
Wentong Wu e71485e8ff power: active all devices if not all devices enter suspend state
Active all devices if not all devices enter suspend state when system
decide going to suspend state.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-04 09:23:15 -05:00
Wentong Wu 9989e5ee06 power: correct log level for power management
Current PM policy allow devices make the decision if going to
sleep/deep sleep state, so it's not error message if some
devices don't enter suspend state, change it to debug level.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-04 09:23:15 -05:00
Wentong Wu de931d501e Style: remove extern on the function declarations in the header
Remove extern on the function declarations in the header file to
keep consistent with others.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-01-04 09:23:15 -05:00
Peter Bigot c248cdf17e power: policy: remove deep sleep states from residency policy
Deep sleep states are documented to include SoC-level power gating,
i.e. the SoC loses context.  In practice entering a deep sleep state
requires an external wakeup mechanism that may need to restart the
application.

Such states are too dangerous to enter automatically based on an
expected duration of sleep, especially since a "forever" sleep that
would normally be woken as a result of a peripheral event would select
the deepest sleep state available.  Limit the sleep levels selected by
a residency policy to ones in which the CPU may be stopped, but will
not lose execution context.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-12-03 14:46:15 -06:00
Anas Nashif 5b0aa794b2 cleanup: include/: move misc/reboot.h to power/reboot.h
move misc/reboot.h to power/reboot.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 190e368275 cleanup: include/: move power.h to power/power.h
move power.h to power/power.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 68c389c1f8 include: move system timer headers to include/drivers/timer/
Move internal and architecture specific headers from include/drivers to
subfolder for timer:

   include/drivers/timer

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-25 15:27:00 -04:00
Benjamin Lindqvist f194982fa3 Power: Fix various spurious LOG_ERR calls
These events aren't errors at all, but rather part of normal operation.
They shouldn't trigger error messages, especially given that the console
gets absolutely flooded with them if power management is activated.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2019-06-04 09:20:37 -04:00
Carles Cufi 201fdf0aec kernel: Fix usage of CONFIG_SYS_CLOCK_EXISTS
When compiling the kernel with CONFIG_SYS_CLOCK_TICKS_PER_SEC=0,
the CONFIG_SYS_CLOCK_EXISTS internal variable is unset.
This completely disables timer handling in the kernel, but a couple of
spots missed the required conditional compilation.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-15 10:44:59 +02:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Piotr Mienkowski 155e11ca2d power: rename residency policy Kconfig options
Rename power managment subsystem Kconfig options describing minimum
residency to make them easier to identify with respective policy.

Following is a detailed list of string replacements used:
s/SYS_PM_SLEEP_(\d)_MIN_RES/SYS_PM_MIN_RESIDENCY_SLEEP_$1/
s/SYS_PM_DEEP_SLEEP_(\d)_MIN_RES/SYS_PM_MIN_RESIDENCY_DEEP_SLEEP_$1/

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Piotr Mienkowski a3082e49a1 power: modify HAS_STATE_SLEEP_ Kconfig options
Add SYS_POWER_ prefix to HAS_STATE_SLEEP_, HAS_STATE_DEEP_SLEEP_
options to align them with names of power states they control.
Following is a detailed list of string replacements used:
s/HAS_STATE_SLEEP_(\d)/HAS_SYS_POWER_STATE_SLEEP_$1/
s/HAS_STATE_DEEP_SLEEP_(\d)/HAS_SYS_POWER_STATE_DEEP_SLEEP_$1/

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Piotr Mienkowski 17b08ceca5 power: clean up system power managment function names
This commit cleans up names of system power management functions by
assuring that:
- all functions start with 'sys_pm_' prefix
- API functions which should not be exposed to the user start with '_'
- name of the function hints at its purpose

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Piotr Mienkowski 204311d004 power: rename Low Power States to Sleep States
There exists SoCs, e.g. STM32L4, where one of the low power modes
reduces CPU frequency and supply voltage but does not stop the CPU. Such
power modes are currently not supported by Zephyr.

To facilitate adding support for such class of power modes in the future
and to ensure the naming convention makes it clear that the currently
supported power modes stop the CPU this commit renames Low Power States
to Slep States and updates the documentation.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Ulf Magnusson 781e554cbd power: Fix reference to CONFIG_SYS_PM_LOG_LEVEL
CONFIG_PM_LOG_LEVEL was renamed to CONFIG_SYS_PM_LOG_LEVEL in commit
c45961daae ("power: Rework OS <-> Application interface"), but the old
name is still used here. Fix the name.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-26 07:57:00 -05:00
Ramakrishna Pallala 6b21e1b7a7 power: Add device idle power management support
Add framework for device Idle Power Management(IPM)
for suspending devices based on device idle. This will
help in saving power even while system(CPU) is active.

The framework uses device_set_power_state() API set the
device power state accordingly based on the usage count.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2019-03-14 14:26:15 +01:00
Ramakrishna Pallala e1639b5345 device: Extend device_set_power_state API to support async requests
The existing device_set_power_state() API works only in synchronous
mode and this is not desirable for devices(ex: Gyro) which take
longer time (few 100 mSec) to suspend/resume.

To support async mode, a new callback argument is added to the API.
The device drivers can asynchronously suspend/resume and call the
callback function upon completion of the async request.

This commit adds the missing callback parameter to all the drivers
to make it compliant with the new API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2019-03-14 14:26:15 +01:00
Benjamin Valentin 4dc672fc19 power: don't switch to power modes not enabled in Kconfig
Disable low power/deep sleep modes when they are not enabled in Kconfig.
Otherwise if only low power modes are enabled (but no deep sleep),
Zephyr will try to swich to the lowest power mode (deep sleep) anyway,
only to discover that it's not availiable, resulting in no low power
mode at all being used.

By disabling the modes here if they are not enabled in Kconfig,
policy_residency will switch to the lowest low power mode instead.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2019-03-07 07:18:10 -05:00
David B. Kinder e731bdc81a doc: fix docs, include, and Kconfig misspellings
Fix misspellings missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-02-28 09:32:12 +01:00
Piotr Mienkowski f04a4c9deb power: rename CPU_LPS_n power states
CPU_LPS_n name used to indicate a low power state is cryptic and
incorrect. The low power states act on the whole SoC and not exclusively
on the CPU. This patch renames CPU_LPS_n states to LOW_POWER_n. Also
HAS_ pattern for Kconfig options is used in favor of a non standard
_SUPPORTED. Naming of deep sleep states was adjusted accordingly.

Following is a detailed list of string replacements used:
s/SYS_POWER_STATE_CPU_LPS_(\d)_SUPPORTED/HAS_STATE_LOW_POWER_$1/
s/SYS_POWER_STATE_CPU_LPS_(\d)/SYS_POWER_STATE_LOW_POWER_$1/
s/SYS_POWER_STATE_DEEP_SLEEP_(\d)_SUPPORTED/HAS_STATE_DEEP_SLEEP_$1/

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-02-26 02:30:13 +01:00