Skip to content
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

drivers: pwm: nrfx: Add runtime PM and fix case when PWM is not disabled when not used #78759

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

nordic-krch
Copy link
Contributor

PWM not disabled when not used
Shim was not correctly disabling PWM when it was not used. Task STOP was triggered but PWM->ENABLE remained set which caused increased current. Added interrupt and enabled event handler in the nrfx driver to allow disabling PWM on STOPPED event.

Add runtime PM support
Rework PM handling to use pm_device_driver_init(). Shim is not using put and get internally as there is no api that disables or stops pwm so it is hard to determine when to put the device. There are cases when PWM peripheral is stopped but PWM is still active because duty cycle is 100% or 0% and pin is driven by GPIO and not PWM.

If user want to use runtime PM with PWM it is possible and getting the device will initialize internal data and putting will suspend by forcing PWM stop if used and setting pins to sleep state. However, from power consumption perspective it is enough to set 0% or 100% duty cycle on all channels.

nika-nordic
nika-nordic previously approved these changes Sep 30, 2024
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
Use NRFX_FOREACH_PRESENT macro to iterate over all PWM instances
and create device only for those enabled in the devicetree.
This approach removes need of changing driver code when new
instance id is added.

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 8, 2024
Use NRFX_FOREACH_PRESENT macro to iterate over all PWM instances
and create device only for those enabled in the devicetree.
This approach removes need of changing driver code when new
instance id is added.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 8, 2024
Shim was not correctly disabling PWM when it was not used. Task
STOP was triggered but PWM->ENABLE remained set which caused
increased current. Added interrupt and enabled event handler in
the nrfx driver to allow disabling PWM on STOPPED event.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 8, 2024
Rework PM handling to use pm_device_driver_init(). Shim is not using
put and get internally as there is no api that disables or stops
pwm so it is hard to determine when to put the device. There are cases
when PWM peripheral is stopped but PWM is still active because
duty cycle is 100% or 0% and pin is driven by GPIO and not PWM.

If user want to use runtime PM with PWM it is possible and getting
the device will initialize internal data and putting will suspend
by forcing PWM stop if used and setting pins to sleep state. However,
from power consumption perspective it is enough to set 0% or 100%
duty cycle on all channels.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 9, 2024
Use NRFX_FOREACH_PRESENT macro to iterate over all PWM instances
and create device only for those enabled in the devicetree.
This approach removes need of changing driver code when new
instance id is added.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 9, 2024
Shim was not correctly disabling PWM when it was not used. Task
STOP was triggered but PWM->ENABLE remained set which caused
increased current. Added interrupt and enabled event handler in
the nrfx driver to allow disabling PWM on STOPPED event.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 9, 2024
Rework PM handling to use pm_device_driver_init(). Shim is not using
put and get internally as there is no api that disables or stops
pwm so it is hard to determine when to put the device. There are cases
when PWM peripheral is stopped but PWM is still active because
duty cycle is 100% or 0% and pin is driven by GPIO and not PWM.

If user want to use runtime PM with PWM it is possible and getting
the device will initialize internal data and putting will suspend
by forcing PWM stop if used and setting pins to sleep state. However,
from power consumption perspective it is enough to set 0% or 100%
duty cycle on all channels.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
@nordic-krch nordic-krch force-pushed the pwm_rt_pm branch 2 times, most recently from c1dfbbf to 0ef0e0c Compare October 9, 2024 12:52
Shim was not correctly disabling PWM when it was not used. Task
STOP was triggered but PWM->ENABLE remained set which caused
increased current. Added interrupt and enabled event handler in
the nrfx driver to allow disabling PWM on STOPPED event.

Signed-off-by: Krzysztof Chruściński <[email protected]>
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved
drivers/pwm/pwm_nrfx.c Outdated Show resolved Hide resolved

default:
return -ENOTSUP;
if (IS_ENABLED(CONFIG_PM_DEVICE)) {
Copy link
Member

Choose a reason for hiding this comment

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

One last thing, this should rather be CONFIG_PM_DEVICE_RUNTIME, because only then the device is expected to be initialized as suspended (when the runtime PM is auto-enabled for it) but the SUSPEND action is not called, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, when runtime PM is off pins will be changed to default because resume action will be called always so it's redundant to set sleep state.

Rework PM handling to use pm_device_driver_init(). Shim is not using
put and get internally as there is no api that disables or stops
pwm so it is hard to determine when to put the device. There are cases
when PWM peripheral is stopped but PWM is still active because
duty cycle is 100% or 0% and pin is driven by GPIO and not PWM.

If user want to use runtime PM with PWM it is possible and getting
the device will initialize internal data and putting will suspend
by forcing PWM stop if used and setting pins to sleep state. However,
from power consumption perspective it is enough to set 0% or 100%
duty cycle on all channels.

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 11, 2024
Use NRFX_FOREACH_PRESENT macro to iterate over all PWM instances
and create device only for those enabled in the devicetree.
This approach removes need of changing driver code when new
instance id is added.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 11, 2024
Shim was not correctly disabling PWM when it was not used. Task
STOP was triggered but PWM->ENABLE remained set which caused
increased current. Added interrupt and enabled event handler in
the nrfx driver to allow disabling PWM on STOPPED event.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
nordic-krch added a commit to nordic-krch/fw-nrfconnect-zephyr that referenced this pull request Oct 11, 2024
Rework PM handling to use pm_device_driver_init(). Shim is not using
put and get internally as there is no api that disables or stops
pwm so it is hard to determine when to put the device. There are cases
when PWM peripheral is stopped but PWM is still active because
duty cycle is 100% or 0% and pin is driven by GPIO and not PWM.

If user want to use runtime PM with PWM it is possible and getting
the device will initialize internal data and putting will suspend
by forcing PWM stop if used and setting pins to sleep state. However,
from power consumption perspective it is enough to set 0% or 100%
duty cycle on all channels.

Upstream PR: zephyrproject-rtos/zephyr#78759

Signed-off-by: Krzysztof Chruściński <[email protected]>
@nashif nashif merged commit e11d050 into zephyrproject-rtos:main Oct 11, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: PWM Pulse Width Modulation platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants