-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Device runtime support uart ns16550 #94375
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?
Device runtime support uart ns16550 #94375
Conversation
The following west manifest projects have changed revision in this Pull Request:
⛔ DNM label due to: 1 project with PR revision Note: This message is automatically posted and updated by the Manifest GitHub Action. |
a9a1391
to
177bba3
Compare
177bba3
to
7aac2b3
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.
The main issue with this is that if it used on a system with PM=y and PM_DEVICE_SYSTEM_MANAGED=y (which is the default) then this is going to call uart_ns16550_configure
every time the cpu springs back to life, aka potentially multiple times per second, that is unless the device is either flagged as wakeup source or set up for pm device runtime. That said, there's nothing you can do about it, at least UART_NS16550_ENABLE_DEVICE_PM
is disabled by default so one would have to explicitly turn it on to shot themselves in the foot.
case PM_DEVICE_ACTION_RESUME: | ||
return uart_ns16550_configure(dev, uart_cfg); | ||
case PM_DEVICE_ACTION_SUSPEND: | ||
return 0; |
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.
ok so what's the story exactly? suspend does nothing, resume just reconfigures? both platforms I tried using this driver did not seem to like this at all, is it a silabs specific thing? does this have a hope of being useful on other platforms using this driver?
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.
Yes, this behavior is specific to devices where the peripheral is fully powered down during sleep states. To address this, I’ve updated the code to explicitly disable the peripheral clock and restore pin states when entering sleep mode
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.
Ok but then now we end up with a kconfig option that a user is expected to set and the only thing we are attaching to it is a very vague description:
This enables support device PM implementation for ns16550 driver.
that does not really help explaining, it sounds like "of course I want it wherever possible" but it's really "I need it for this class of devices"
How about having this behavior controlled by a devicetree property instead, with a proper description of what it does and when should it be enabled instead, and then you can have it set on the dts files for all silabs devices and the user would not have to worry about it.
This commit enables the pm device runtime driver support for the uart_ns16550 driver. Signed-off-by: Sai Santhosh Malae <[email protected]>
1. Remove CMSIS files from wiseconnect CMakeLists 2. Update west.yml Signed-off-by: Sai Santhosh Malae <[email protected]>
7aac2b3
to
339ef4c
Compare
I agree—calling |
|
Yup seems like we are exposing the user to something that should be automatic, see #94375 (comment), I think this should be a property and set for the affected platforms. |
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.
Please check out https://docs.zephyrproject.org/latest/services/pm/device.html#device-model-with-device-power-management-support
The implementation in this PR is quite a bit away from the expected implementation.
#if defined(CONFIG_UART_NS16550_ENABLE_DEVICE_PM) | ||
#include <zephyr/pm/device.h> | ||
#endif |
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.
not needed, the file can be safely included regardless
}; | ||
|
||
#if defined(CONFIG_UART_NS16550_ENABLE_DEVICE_PM) | ||
__maybe_unused static int uart_ns16550_pm_action(const struct device *dev, |
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 should not be needed. The pm action needs to be directly referenced by pm_device_driver_init()
, it will always be used.
Please check out the example code here https://docs.zephyrproject.org/latest/services/pm/device.html#device-model-with-device-power-management-support which describes how the driver should implement power management
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 believe the reasoning for making it conditional is to avoid something like #93568 happening again by making it opt-in, since the ns16550 driver is used by several slightly different HW IPs that have the same register interface, instantiated in several different SoCs with differing integration.
That said, I'm wondering if it would be better for this to be implemented as TURN_ON instead of RESUME, and to add a power domain driver for SiWx91x (or is there already a generic one for SoC PDs that does nothing but dispatch on/off events to its children when suspended/resumed? I don't recall). This would model what actually happens in hardware better (register unretention upon sleep), and would allow SoC-level opt-in to the PM behavior: SoCs that need register repainting on wakeup need to associate the UART to a power domain, while those that don't leave it out. The PM subsystem will call TURN_ON once at init if no power domain exists, and behavior will be identical to the status quo.
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 mean, per device power management opt-in is definitely not the intended design, sure its possible to add a bunch of ifdefs, but even if you do so, the implementation when CONFIG_UART_NS16550_ENABLE_DEVICE_PM=y
should still follow the documentation.
Device runtime support for uart_ns16550 driver by enabling CONFIG_UART_NS16550_ENABLE_DEVICE_PM
This is a second attempt after #92507 got reverted in #93568