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 global hsfll request for fast PWM #82133

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mstasiaknordic
Copy link
Contributor

@mstasiaknordic mstasiaknordic commented Nov 27, 2024

Added clock control api for global hsfll used in fast PWM120 driver.

@mstasiaknordic mstasiaknordic force-pushed the pwm_global_hsfll branch 3 times, most recently from e94eb66 to 1e59406 Compare December 4, 2024 08:08
@mstasiaknordic mstasiaknordic marked this pull request as ready for review December 11, 2024 09:56
@zephyrbot zephyrbot added platform: nRF Nordic nRFx area: PWM Pulse Width Modulation labels Dec 11, 2024
@mstasiaknordic
Copy link
Contributor Author

@bjarki-andreasen You can have a look

Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

Looks good

@@ -20,3 +20,8 @@ config PWM_NRFX
select PINCTRL
help
Enable support for nrfx Hardware PWM driver for nRF52 MCU series.

config PWM_NRFX_INIT_PRIORITY
int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int
int "NRFX PWM init priority"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want it to be user-assignable? In my opinion, CONFIG_PWM_INIT_PRIORITY can still be set and used if the PWM instance is not 120, in which case priority needs to be 99 to match clock device

Copy link
Contributor

Choose a reason for hiding this comment

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

You assume here that clock control has 99 priority but this may change.
I used approach where in the code I'm trying to pick CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY+1 for fast instance (similar approach is in spim, too):

(UTIL_INC(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY)), \

@bjarki-andreasen bjarki-andreasen removed the DNM This PR should not be merged (Do Not Merge) label Dec 17, 2024
@decsny decsny removed their request for review December 17, 2024 17:33
Copy link
Contributor

@nordic-krch nordic-krch left a comment

Choose a reason for hiding this comment

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

You can also add
select CLOCK_CONTROL if HAS_HW_NRF_PWM120 to PWM_NRFX Kconfig.

@@ -20,3 +20,8 @@ config PWM_NRFX
select PINCTRL
help
Enable support for nrfx Hardware PWM driver for nRF52 MCU series.

config PWM_NRFX_INIT_PRIORITY
int
Copy link
Contributor

Choose a reason for hiding this comment

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

You assume here that clock control has 99 priority but this may change.
I used approach where in the code I'm trying to pick CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY+1 for fast instance (similar approach is in spim, too):

(UTIL_INC(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY)), \

@mstasiaknordic
Copy link
Contributor Author

select CLOCK_CONTROL if HAS_HW_NRF_PWM120

This would work best, however, it results in dependency loop

@mstasiaknordic mstasiaknordic force-pushed the pwm_global_hsfll branch 2 times, most recently from f2732b0 to e8a4f1c Compare January 3, 2025 12:08
nika-nordic
nika-nordic previously approved these changes Jan 7, 2025
nika-nordic
nika-nordic previously approved these changes Jan 8, 2025
Comment on lines 16 to 18
#ifdef CONFIG_CLOCK_CONTROL
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This #ifdef here is superfluous.

(IS_EQ(DT_PHA(PWM(idx), power_domains, id), NRF_GPD_FAST_ACTIVE1)), \
(0))), (0))

#if (NRFX_FOREACH_PRESENT(PWM, PWM_NRFX_IS_FAST, (||), (0))) && CONFIG_CLOCK_CONTROL
Copy link
Member

@anangl anangl Jan 8, 2025

Choose a reason for hiding this comment

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

I'd rather use CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL, as this is what is actually used by this driver.

Comment on lines 324 to 396
pwm_resume(dev);
ret = pwm_resume(dev);
} else if (IS_ENABLED(CONFIG_PM_DEVICE) && (action == PM_DEVICE_ACTION_SUSPEND)) {
pwm_suspend(dev);
ret = pwm_suspend(dev);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just add return in these two lines (and remove that unneeded then return 0 at the of the function) instead of introducing the ret variable?

Comment on lines 473 to 475
.accuracy = 0, \
.precision = \
NRF_CLOCK_CONTROL_PRECISION_DEFAULT, \
Copy link
Member

Choose a reason for hiding this comment

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

This is unneeded. Only the specified frequency is requested anyway.

@@ -248,6 +284,20 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,
* until another playback is requested (new values will be
* loaded then) or the PWM peripheral is stopped.
*/
#if PWM_NRFX_USE_CLOCK_CONTROL
if (!data->clock_requested) {
int ret = nrf_clock_control_request_sync(config->clk_dev,
Copy link
Member

Choose a reason for hiding this comment

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

This is only needed for the fast instances. You could have clk_dev set to NULL for others and avoid this call.

Added clock control api for global hsfll used in fast PWM120 driver.

Signed-off-by: Michał Stasiak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Base OS Base OS Library (lib/os) area: Clock Control area: PWM Pulse Width Modulation platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants