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 clock requests for fast SPIM instances #82994

Merged
merged 3 commits into from
Dec 21, 2024

Conversation

anangl
Copy link
Member

@anangl anangl commented Dec 14, 2024

Based on #75715 and #81735. Only the last three commits are actually added by this PR.

drivers: clock_control_nrf2: Add missing cancelation of request

This is a follow-up to commit fe0e2db.

If nrf_clock_control_request_sync() ends up with a timeout, before returning it must cancel the request that was not fulfilled on time. Otherwise, the request may actually finish successfully a bit later, but the caller will not be aware that the clock needs to be released (since the call resulted in an error). And actually even more serious problem is that because the req structure is placed on stack, after the function returns, the contents of this structure will be probably overwritten with some other data, so if the request finishes at that point, an attempt to execute the callback function pointed by this structure will most likely cause a crash.

dts: nrf54h20: Add clocks property in fast SPIM nodes

Fast SPIM instances in nRF54H20 (SPIM120 and SPIM121) are driven by the global HSFLL (HSFLL120). Add clocks property in these nodes to reflect this.

drivers: spi_nrfx_spim: Add clock requests for fast SPIM instances

Fast SPIM instances (SPIM120 and SPIM121) for correct operation require the highest frequency from the global HSFLL. This commit adds needed clock controller requests to the driver. When the runtime device power management is enabled, the frequency is requested as long as the SPIM is resumed, otherwise it is requested for the duration of transfers.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Dec 14, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

nika-nordic
nika-nordic previously approved these changes Dec 16, 2024
};

static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context);

static inline int request_clock(const struct 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.

won't the compiler complain about unused dev parameter when USE_CLOCK_REQUESTS is undefined? same for release_clock

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think it may complain, depending on the enabled warnings. I'll add ARG_UNUSED() macro calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@anangl anangl force-pushed the req_hsfll_spim branch 2 times, most recently from ecf7509 to 7b94b4d Compare December 16, 2024 09:26
@anangl anangl requested a review from nika-nordic December 16, 2024 09:26
This is a follow-up to commit fe0e2db.

If `nrf_clock_control_request_sync()` ends up with a timeout, before
returning it must cancel the request that was not fulfilled on time.
Otherwise, the request may actually finish successfully a bit later,
but the caller will not be aware that the clock needs to be released
(since the call resulted in an error). And actually even more serious
problem is that because the `req` structure is placed on stack, after
the function returns, the contents of this structure will be probably
overwritten with some other data, so if the request finishes at that
point, an attempt to execute the callback function pointed by this
structure will most likely cause a crash.

Signed-off-by: Andrzej Głąbek <[email protected]>
Fast SPIM instances in nRF54H20 (SPIM120 and SPIM121) are driven by
the global HSFLL (HSFLL120). Add `clocks` property in these nodes
to reflect this.

Signed-off-by: Andrzej Głąbek <[email protected]>
@anangl
Copy link
Member Author

anangl commented Dec 17, 2024

Rebased.

Fast SPIM instances (SPIM120 and SPIM121) for correct operation require
the highest frequency from the global HSFLL. This commit adds needed
clock controller requests to the driver. When the runtime device power
management is enabled, the frequency is requested as long as the SPIM
is resumed, otherwise it is requested for the duration of transfers.

This commit also adds a missing call to `pm_device_runtime_put()` when
SPIM reconfiguration fails.

Signed-off-by: Andrzej Głąbek <[email protected]>
@kartben kartben merged commit 59c94db into zephyrproject-rtos:main Dec 21, 2024
26 checks passed
@anangl anangl deleted the req_hsfll_spim branch December 21, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Clock Control area: Power Management area: Samples Samples area: SPI SPI bus area: UART Universal Asynchronous Receiver-Transmitter platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants