-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
base: main
Are you sure you want to change the base?
drivers: pwm: nrfx: add global hsfll request for fast PWM #82133
Conversation
e94eb66
to
1e59406
Compare
@bjarki-andreasen You can have a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
98008da
to
89e31f4
Compare
drivers/pwm/Kconfig.nrfx
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int | |
int "NRFX PWM init priority" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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):
zephyr/drivers/serial/uart_nrfx_uarte.c
Line 2437 in f8f9ed7
(UTIL_INC(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY)), \ |
4279eb6
to
00114e6
Compare
There was a problem hiding this 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.
drivers/pwm/Kconfig.nrfx
Outdated
@@ -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 |
There was a problem hiding this comment.
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):
zephyr/drivers/serial/uart_nrfx_uarte.c
Line 2437 in f8f9ed7
(UTIL_INC(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL_INIT_PRIORITY)), \ |
This would work best, however, it results in dependency loop |
f2732b0
to
e8a4f1c
Compare
7e65732
e8a4f1c
to
7e65732
Compare
drivers/pwm/pwm_nrfx.c
Outdated
#ifdef CONFIG_CLOCK_CONTROL | ||
#include <zephyr/drivers/clock_control/nrf_clock_control.h> | ||
#endif |
There was a problem hiding this comment.
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.
drivers/pwm/pwm_nrfx.c
Outdated
(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 |
There was a problem hiding this comment.
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.
drivers/pwm/pwm_nrfx.c
Outdated
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); |
There was a problem hiding this comment.
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?
drivers/pwm/pwm_nrfx.c
Outdated
.accuracy = 0, \ | ||
.precision = \ | ||
NRF_CLOCK_CONTROL_PRECISION_DEFAULT, \ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
189c159
7e65732
to
189c159
Compare
Added clock control api for global hsfll used in fast PWM120 driver. Signed-off-by: Michał Stasiak <[email protected]>
189c159
to
6f113f8
Compare
Added clock control api for global hsfll used in fast PWM120 driver.