Skip to content

Commit e1f9de7

Browse files
nordic-krchkartben
authored andcommitted
drivers: clock_control: nrf: Fix missing clock started callback
804e502 fix got reverted as it introduced a bug where callback with HFCLK started indication was not called because state is not correctly indicated. BT-dedicated API does not set state and does not expect to get the callback when HFCLK is started. 804e502 was intended to fix the bug that was visible on nrf54lx. It was not visible on nrf52 because of a errata workaround which was calling HFCLK started callback only when state was set to STARTING and that was not the case when BT-dedicated API was used. Applying this `workaround` approach to all cases. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 04464f5 commit e1f9de7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

drivers/clock_control/clock_control_nrf.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int async_start(const struct device *dev, clock_control_subsys_t subsys,
494494
subdata->cb = cb;
495495
subdata->user_data = user_data;
496496

497-
get_sub_config(dev, type)->start();
497+
get_sub_config(dev, type)->start();
498498

499499
return 0;
500500
}
@@ -695,14 +695,28 @@ void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode)
695695
}
696696
}
697697

698+
static void hfclkstarted_handle(const struct device *dev)
699+
{
700+
struct nrf_clock_control_sub_data *data =
701+
get_sub_data(dev, CLOCK_CONTROL_NRF_TYPE_HFCLK);
702+
703+
if (GET_STATUS(data->flags) == CLOCK_CONTROL_STATUS_STARTING) {
704+
/* Handler is called only if state is set. BT specific API
705+
* does not set this state and does not require handler to
706+
* be called.
707+
*/
708+
clkstarted_handle(dev, CLOCK_CONTROL_NRF_TYPE_HFCLK);
709+
}
710+
}
711+
698712
static void clock_event_handler(nrfx_clock_evt_type_t event)
699713
{
700714
const struct device *dev = CLOCK_DEVICE;
701715

702716
switch (event) {
703717
#if NRF_CLOCK_HAS_XO_TUNE
704718
case NRFX_CLOCK_EVT_XO_TUNED:
705-
clkstarted_handle(dev, CLOCK_CONTROL_NRF_TYPE_HFCLK);
719+
hfclkstarted_handle(dev);
706720
break;
707721
case NRFX_CLOCK_EVT_XO_TUNE_ERROR:
708722
case NRFX_CLOCK_EVT_XO_TUNE_FAILED:
@@ -716,19 +730,8 @@ static void clock_event_handler(nrfx_clock_evt_type_t event)
716730
#else
717731
/* HFCLK started should be used only if tune operation is done implicitly. */
718732
case NRFX_CLOCK_EVT_HFCLK_STARTED:
719-
{
720-
struct nrf_clock_control_sub_data *data =
721-
get_sub_data(dev, CLOCK_CONTROL_NRF_TYPE_HFCLK);
722-
723-
/* Check needed due to anomaly 201:
724-
* HFCLKSTARTED may be generated twice.
725-
*/
726-
if (GET_STATUS(data->flags) == CLOCK_CONTROL_STATUS_STARTING) {
727-
clkstarted_handle(dev, CLOCK_CONTROL_NRF_TYPE_HFCLK);
728-
}
729-
733+
hfclkstarted_handle(dev);
730734
break;
731-
}
732735
#endif
733736
#if NRF_CLOCK_HAS_HFCLK24M
734737
case NRFX_CLOCK_EVT_HFCLK24M_STARTED:

0 commit comments

Comments
 (0)