After the removal of pm_device_get_async, the pm_device_wait API has
become redundant. Its usage after pm_device_put_async should not be
considered a valid usecase, since after that call what will happen is a
pm_device_get (which is blocking).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
As of today there is no clear usage of asynchronous gets, since in
general, a resume operation should be synchronous (we are about to use
the device immediately after resuming it). Removing this API simplifies
the runtime implementation in a significant way (refer to future
commits).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
List of improvements:
- The PM logging module was only available if CONFIG_PM=y, however, it
was also used by Device PM (which can be selected without PM). A new
logging module has been created for Device PM.
- Log level is passed to LOG_MODULE_(DECLARE|REGISTER)
- Logger name has been adjusted to `pm` (was `power`)
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
- Rename to "action" to make its purpose more clear
- Use the _cb suffix to align with naming used for callbacks in other
areas.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Accessing members from pm_device improves code readability, since it
removes dev-> from most accesses.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Some includes were already performed by the device(_runtime).h header/s,
others like were not necessary.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
PM_DEVICE_STATE_RESUMING and PM_DEVICE_STATE_SUSPENDING
are transitional states and are only used in device runtime. Remove it
and use device flag to keep track of a transition.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The runtime API is referenced count and uses a uint32_t.
Avoid underflow when dealing with put requests.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Return 0 in cases where the request does not trigger a device state
change, only incremented or to decremented the reference count.
Fixes#37821
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The verb tense for the suspended state was not consistent with other
states. The likely reason: state was being used as a command/action.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
If the device is already at the given state, do not call the device PM
control function. This makes sure that devices are only called to change
from one state to another.
Even though asynchronous device PM is completely broken, transitional
states are considered too.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The callback is not used anymore, so just delete it from the pm_control
callback signature.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The callback used by the device runtime PM can be easily replaced by a
simple state set after calling the state set/get calls. Broadcast logic
is simplified too, leading to the same previous behavior.
Since this is the only place where this callback was used, it can now be
removed from all devices and so pm_control callback signature
simplified.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.
All drivers and tests have been adjusted accordingly.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
pm_device_runtime_state_set takes care of the check the reference count
and take the right action. It is not necessary check it in
pm_device_request.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Assuming that pm_device_state_set is synchronous it is possible to
simplify the mutex usage. Now there are two places where the lock is
held, one in the worqueue handler and other in pm_device_request to
cover the synchronous path. It is no longer needed held the lock in the
pm_device_state_set callback and not needed to wait on the conditional
variable after set the state in the synchronous path.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Most APIs have the default synchronous and an asynchronous version
with the sufix _async because that is the most common use.
All devices in tree right now are using the synchronous version, so
just change it to be consistent with the rest of the system.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Since we are using mutex to protect critical sections and mutexes are
reentrant, it is possible to get rid of atomic for the state because
we can lock the mutex in device_pm_callback.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Protect critical sections using the mutex.
The mutex is required to use the conditional variable and since we
need to atomically check the pm state and the workqueue before wait
the condition, it is necessary to protect them using the same mutex.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Protect critical sessions using the spinlock available. The atomic
usage was not properly protecting the critical section and was
possible to have a race condition between the usage check and state
set.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Add a function that properly uses a mutex to check a condition before
wait on the conditional variable.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Avoid confusion with device runtime idle pm states and just use device
pm states.
This simplify the code a little bit and prepare the ground for having
a better definition of device pm states. Right now this code needed to
hijack two transitional states to not break the current code logic but
the goal is avoid it and have everything in one single place.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Devices may be initialized but started powered down for this reason
is necessary to power a device on if requested even if in pre-kernel
state.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Device pm runtime was using semaphore to protect critical section but
enable / disable functions were waiting on the semaphore. So, just
replace it with a spin lock.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The sync API was using k_poll_signal and in certain conditions is
possible multiple threads waiting on a signal leading to an undefined
behavior.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The context parameter used across device power management is
actually the power state. Just use it and avoid a lot of
unnecessary casts.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>