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: flash: spi_nor: support device PM #59647

Merged
merged 2 commits into from Jul 5, 2023

Conversation

JordanYates
Copy link
Collaborator

Support device power management in spi_nor driver. Only use SUSPEND/RESUME if CONFIG_SPI_NOR_IDLE_IN_DPD is not enabled to avoid state conflicts.

Jordan Yates added 2 commits June 23, 2023 17:18
Support device power management in spi_nor driver. Only use
SUSPEND/RESUME if `CONFIG_SPI_NOR_IDLE_IN_DPD` is not enabled to avoid
state conflicts.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Exit DPD on init in all cases, even when `CONFIG_SPI_NOR_IDLE_IN_DPD` is
not enabled.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
@Laczen
Copy link
Collaborator

Laczen commented Jun 23, 2023

@JordanYates, this is a very nice addition to spi_nor. I'm wondering if this needs no protection to avoid switching of during ongoing writes/reads.

Comment on lines +1270 to +1272
acquire_device(dev);
rc = enter_dpd(dev);
release_device(dev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case when CONFIG_SPI_NOR_IDLE_IN_DPD is enabled, this wakes up device in acquire_device then puts it to sleep twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If that is enabled this code isn't run, see the enclosing #ifdef. Same for the second location

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry, somehow missed that.
Shouldn't this check k_sem_count_get before putting device to sleep? Because there may be something scheduled just after PM event, and it will wake up device anyway.
In case this locks on acquire_device, is it possible that more than one PM event get scheduled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checking the semaphore isn't required because it is only taken for the duration of an API call (if it is held longer that is a bug), and therefore our own call to acquire_device ensures that no other action is running.

The higher level "Device PM" API is responsible for ensuring that PM events are only run in the correct state, and "Device Runtime PM" is the correct API to use if you want multiple users for the driver with PM.

@Laczen
Copy link
Collaborator

Laczen commented Jun 23, 2023

@JordanYates, this is a very nice addition to spi_nor. I'm wondering if this needs no protection to avoid switching of during ongoing writes/reads.

Nevermind, I thought that acquire_device() and release_device() were pm routines/kernel routines, it is clear now that this protection is there.

@carlescufi carlescufi merged commit b0db69d into zephyrproject-rtos:main Jul 5, 2023
15 checks passed
@JordanYates JordanYates deleted the 230623_spi_nor branch July 5, 2023 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants