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: spi: nrfx_spim: Add support for device runtime PM #75715

Merged

Conversation

adamkondraciuk
Copy link
Contributor

Enable the device runtime power management on the SPIM shim.

@zephyrbot zephyrbot added area: SPI SPI bus platform: nRF Nordic nRFx labels Jul 10, 2024
@adamkondraciuk adamkondraciuk force-pushed the NRFX-5953-Add-device-PM-to-SPIM branch from b250f29 to 34bda38 Compare July 10, 2024 12:00
@adamkondraciuk adamkondraciuk force-pushed the NRFX-5953-Add-device-PM-to-SPIM branch from 34bda38 to aab48c6 Compare July 11, 2024 07:14
adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Jul 22, 2024
Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Jul 22, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
nordicjm pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request Jul 23, 2024
Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
nordicjm pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request Jul 23, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
rlubos pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request Oct 21, 2024
…e PM

Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
rlubos pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request Oct 21, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
…e PM

Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit 35e51a2)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit b20e5fd)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
…e PM

Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit 35e51a2)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit b20e5fd)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
…e PM

Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit 35e51a2)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 22, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit b20e5fd)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 23, 2024
…e PM

Enable the device runtime power management on the SPIM shim.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit 35e51a2)
rlubos pushed a commit to rlubos/sdk-zephyr that referenced this pull request Oct 23, 2024
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Upstream PR: zephyrproject-rtos/zephyr#75715

Signed-off-by: Adam Kondraciuk <[email protected]>
(cherry picked from commit b20e5fd)
@rda-emcraft
Copy link

This code works incorrectly in the case of SPI_HOLD_ON_CS or/and SPI_LOCK_ON.

Here's what happens when SPI transactions are split into two calls of spi_transceive()

[00:24:15.862,182] <wrn> pm_device: Unbalanced suspend
[00:24:15.863,128] <wrn> pm_device: Unbalanced suspend
[00:24:15.966,217] <wrn> pm_device: Unbalanced suspend
[00:24:15.966,857] <wrn> pm_device: Unbalanced suspend
[00:24:16.816,741] <wrn> pm_device: Unbalanced suspend

And I've got lucky because switching to power down does not break the transaction. Probably idle pin states between the bytes match power down states.

It does not make sense to call pm_device_runtime_put(dev) if SPI lock is not released or if CS hold is requested.
Similarly it does not make sense to call pm_device_runtime_get(dev) if SPI lock or CS is held.

By the way, all zephyr SPI drivers with device runtime support I've seen does not handle this flags. Probably generic solution will be to integrate device runtime calls into spi_context.h.

@nordic-piks
Copy link
Collaborator

This code works incorrectly in the case of SPI_HOLD_ON_CS or/and SPI_LOCK_ON.

Here's what happens when SPI transactions are split into two calls of spi_transceive()

[00:24:15.862,182] <wrn> pm_device: Unbalanced suspend
[00:24:15.863,128] <wrn> pm_device: Unbalanced suspend
[00:24:15.966,217] <wrn> pm_device: Unbalanced suspend
[00:24:15.966,857] <wrn> pm_device: Unbalanced suspend
[00:24:16.816,741] <wrn> pm_device: Unbalanced suspend

And I've got lucky because switching to power down does not break the transaction. Probably idle pin states between the bytes match power down states.

It does not make sense to call pm_device_runtime_put(dev) if SPI lock is not released or if CS hold is requested. Similarly it does not make sense to call pm_device_runtime_get(dev) if SPI lock or CS is held.

By the way, all zephyr SPI drivers with device runtime support I've seen does not handle this flags. Probably generic solution will be to integrate device runtime calls into spi_context.h.

@rda-emcraft Can you rise an issue with this please? That will make easier to implement this.

@nordic-piks
Copy link
Collaborator

Hm, maybe issue is not needed as this is PR only.

@rda-emcraft
Copy link

rda-emcraft commented Oct 25, 2024

@rda-emcraft Can you rise an issue with this please? That will make easier to implement this.

@nordic-piks, @adamkondraciuk
I may raise issue for spi_ambiq.c, spi_ll_stm32.c and spi_smartbond.c that already accepted into the tree and has the same deficiency.

I have read more of spi_context.h and now I think you should call pm_device_runtime_get(dev) along with locking ctx->lock and pm_device_runtime_put(dev) when unlocking ctx->lock. Implementing this might require passing device pointer to spi_context_{lock,release,complete,release,unlock_unconditionally}(). Probably will have this implemented later today.

What I'm trying to say is that part of runtime device PM (_get() and put()) for SPI drivers can be implemented in generic SPI context handling code. Driver only need to supply initialization and code to do real PM operations.

Anyway, I'm really new in Zephyr, so any guidance is appreciated.

And I'm sitting on Zephyr 3.5.99 and calling pm_device_runtime_put(dev) from IRQ context is a no go here. I'm replacing it with pm_device_runtime_put_async(dev).

@rda-emcraft
Copy link

@adamkondraciuk

I've created pull request to your branch implementing proposed changes.

drivers/spi/spi_nrfx_spim.c Outdated Show resolved Hide resolved
drivers/spi/spi_nrfx_spim.c Outdated Show resolved Hide resolved
Enable the device runtime power management on the SPIM shim.

Signed-off-by: Adam Kondraciuk <[email protected]>
Signed-off-by: Nikodem Kastelik <[email protected]>
Add configuration for testing SPI with device runtime PM enabled
for nRF platforms.

Signed-off-by: Adam Kondraciuk <[email protected]>
Signed-off-by: Nikodem Kastelik <[email protected]>
@nika-nordic nika-nordic force-pushed the NRFX-5953-Add-device-PM-to-SPIM branch from 62062bb to dc3d693 Compare December 13, 2024 11:41
@kartben kartben merged commit 7635455 into zephyrproject-rtos:main Dec 16, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.