Skip to content

Commit a6cfe14

Browse files
committed
[nrf fromlist] modules: hal_nordic: dvfs: queue request when busy
Added one element queue to change frequency setting function, when previous dvfs sequence is still in progress. Thanks to this EBUSY status will not be longer reported and last frequency setting will be queued and applied as soon as pending change is done. This is needed by clock control. Upstream PR #: 78103 Signed-off-by: Lukasz Stepnicki <[email protected]>
1 parent 6d04ddb commit a6cfe14

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ static K_SEM_DEFINE(dvfs_service_idle_sem, 0, 1);
2020

2121
#define DVFS_SERV_HDL_INIT_DONE_BIT_POS (0)
2222
#define DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS (1)
23+
#define DVFS_SERV_HDL_FREQ_CHANGE_REQ_IN_QUEUE_BIT_POS (2)
2324

2425
static atomic_t dvfs_service_handler_state_bits;
2526
static volatile enum dvfs_frequency_setting current_freq_setting;
2627
static volatile enum dvfs_frequency_setting requested_freq_setting;
28+
static volatile enum dvfs_frequency_setting queued_freq_setting;
2729
static dvfs_service_handler_callback dvfs_frequency_change_applied_clb;
2830

2931
static void dvfs_service_handler_set_state_bit(uint32_t bit_pos)
@@ -51,6 +53,24 @@ static bool dvfs_service_handler_freq_change_req_pending(void)
5153
return dvfs_service_handler_get_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS);
5254
}
5355

56+
static void dvfs_service_handler_add_req_to_queue(enum dvfs_frequency_setting freq_setting)
57+
{
58+
queued_freq_setting = freq_setting;
59+
atomic_set_bit(&dvfs_service_handler_state_bits,
60+
DVFS_SERV_HDL_FREQ_CHANGE_REQ_IN_QUEUE_BIT_POS);
61+
}
62+
63+
static void dvfs_service_handler_check_and_send_request_from_queue(void)
64+
{
65+
if (atomic_test_bit(&dvfs_service_handler_state_bits,
66+
DVFS_SERV_HDL_FREQ_CHANGE_REQ_IN_QUEUE_BIT_POS)) {
67+
atomic_clear_bit(&dvfs_service_handler_state_bits,
68+
DVFS_SERV_HDL_FREQ_CHANGE_REQ_IN_QUEUE_BIT_POS);
69+
70+
dvfs_service_handler_change_freq_setting(queued_freq_setting);
71+
}
72+
}
73+
5474
static void dvfs_service_handler_nrfs_error_check(nrfs_err_t err)
5575
{
5676
if (err != NRFS_SUCCESS) {
@@ -157,6 +177,7 @@ static void dvfs_service_handler_scaling_finish(enum dvfs_frequency_setting oppo
157177
if (dvfs_frequency_change_applied_clb) {
158178
dvfs_frequency_change_applied_clb(current_freq_setting);
159179
}
180+
dvfs_service_handler_check_and_send_request_from_queue();
160181
}
161182

162183
/* Function to set hsfll to highest frequency when switched to ABB. */
@@ -220,6 +241,7 @@ static void nrfs_dvfs_evt_handler(nrfs_dvfs_evt_t const *p_evt, void *context)
220241
dvfs_frequency_change_applied_clb(p_evt->freq);
221242
}
222243
}
244+
dvfs_service_handler_check_and_send_request_from_queue();
223245
break;
224246
case NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE:
225247
/*Target oppoint will be received here.*/
@@ -323,8 +345,9 @@ int32_t dvfs_service_handler_change_freq_setting(enum dvfs_frequency_setting fre
323345
}
324346

325347
if (dvfs_service_handler_freq_change_req_pending()) {
326-
LOG_DBG("Frequency change request pending.");
327-
return -EBUSY;
348+
LOG_DBG("Frequency change request pending, adding request to queue.");
349+
dvfs_service_handler_add_req_to_queue(requested_freq_setting);
350+
return NRFS_SUCCESS;
328351
}
329352

330353
dvfs_service_handler_set_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS);

modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern "C" {
1717
* @brief Function to request LD frequency change.
1818
*
1919
* @param frequency requested frequency setting from enum dvfs_frequency_setting.
20-
* @return EBUSY Frequency change request pending.
2120
* @return EAGAIN DVFS init in progress.
2221
* @return ENXIO Not supported frequency settings.
2322
* @return NRFS_SUCCESS Request sent successfully.

0 commit comments

Comments
 (0)