-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Specify and document current PM_DEVICE behavior, including PM_DEVICE=n and device_deinit() #90275
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
base: main
Are you sure you want to change the base?
Specify and document current PM_DEVICE behavior, including PM_DEVICE=n and device_deinit() #90275
Conversation
537633f
to
4ea0b00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this function? It seems odd that it is running functions when CONFIG_PM_DEVICE=n
but doesn't do anything when CONFIG_PM_DEVICE=y
?
Check out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, this is a simple check ensuring the device is not in use
What is stopping a final implementation from being implemented now? The function should have defined semantics, and they should be implemented properly when the function is introduced, not modified at some point in "the future".
This is all we need for now, I don't think there is a "final" implementation, its just a hook for doing whatever is required of PM at a given time :) |
include/zephyr/pm/device.h
Outdated
return rc; | ||
} | ||
|
||
rc = action_cb(dev, PM_DEVICE_ACTION_TURN_OFF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right, the device is not literally being turned off, just the software construct destroyed.
This would lead to GPIO's being put into incorrect states if used generically, which the PM API is.
Overloading the meaning of PM_DEVICE_ACTION_TURN_OFF
is a bad idea IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with removing the call to TURN_OFF
, given that all resources like GPIOs are released as part of device_deinit()
, I think you are right that it makes little sense to act as if the driver is being turned off before being deinitialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree about it
4ea0b00
to
0f5a01c
Compare
0f5a01c
to
4a6a1d6
Compare
@JordanYates could you revisit this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still not clear to me how this helps to reliably implement the requirements of the device_deinit
API.
zephyr/include/zephyr/device.h
Lines 880 to 885 in af46f62
* When a device is de-initialized, it will release any resources it has | |
* acquired (e.g. pins, memory, clocks, DMA channels, etc.) and its status will | |
* be left as in its reset state. | |
* | |
* @warning It is the responsibility of the caller to ensure that the device is | |
* ready to be de-initialized. |
It's on the caller to determine whether the device can be de-initialized, not the implementation.
Why is STATE_SUSPENDED
any more likely to be the "reset state" of a device than STATE_ACTIVE
? In many cases the suspend state is explicitly not the reset state of a device.
This to my knowledge was intended to clearly indicate that there is no reference counting or other tracking of who is using the device built in to the device model (which there was with an early version of device_deinit()), not that no checks are allowed to make sure it makes sense. Otherwise surely Lines 150 to 152 in 600cae6
If |
As a concrete request, please document what the function is actually supposed to be doing beyond just |
d6b30b7
to
5e0d6a2
Compare
@decsny can you take a look as well? |
I trust that it's probably fine, I won't be able to review it properly this week, don't wait on me |
doc/releases/release-notes-4.2.rst
Outdated
@@ -221,6 +221,7 @@ New APIs and options | |||
* :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME_DEDICATED_WQ_PRIO` | |||
* :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME_DEDICATED_WQ_INIT_PRIO` | |||
* :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME_ASYNC` | |||
* :c:func:`pm_device_driver_deinit` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this modify the 4.3 release notes? or is it meant as a backport?
(Feel free to disregard this review if all it needs is a backport label)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not meant to be backported :) Release notes will be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated :)
Rewrite the docstring for pm_device_driver_init() to align with documentation, especially covering the case where CONFIG_PM_DEVICE=n Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Introduce pm_device_driver_deinit() which is required to fully support device_deinit(). This function shall be called by drivers when device_deinit() is called. If PM_DEVICE is enabled, it will simply check whether the device is either SUSPENDED or OFF, this will prevent device_deinit() on a device which is currently in use, and ensure the device is in the correct state if device_init() is called later. If PM_DEVICE is not enabled, it will invoke the SUSPEND action which mirrors the pm_device_driver_init() behavior. Note that TURN_OFF action is not called since the device is deinitialized after this call. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Extend test suite to cover pm_device_driver_deinit() resulting from call to device_deinit(). Signed-off-by: Bjarki Arge Andreasen <[email protected]>
- Specify "Device" Power Management Support in sections covering CONFIG_PM_DEVICE=y or n - Extend the enum pm_device_state docstrings to define and detail expectations of devices in each enum pm_device_state state. - Extend pm device driver code example with more concise comments and include pm_device_driver_init, pm_device_driver_deinit, and DEVICE_DT_INST_DEINIT_DEFINE() (device deinit feature) - Describe the device driver PM states used if PM_DEVICE is not enabled. - Note which states a device driver is initialized from and can be deinitialized in and why. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
5e0d6a2
to
cc8e50b
Compare
Mention introduction of pm_device_driver_deinit() in the 4.3 release notes. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
cc8e50b
to
2814832
Compare
Rebased and moved mention of introduction of |
|
ping @JordanYates @decsny |
This PR aims to document the status quo of device power management to provide a foundation for current driver development, and future refactoring discussions, since we need to agree on the current state before being able to discuss the future state :)
The PR also adds the missing counterpart to
pm_device_driver_init()
.