Skip to content

Commit c365fbb

Browse files
ananglkartben
authored andcommitted
drivers: clock_control_nrf2_common: Add resetting of the on-off services
If an on-off service records an error while transitioning to the on state, it stays in the error state and does not allow new requests to be made until its state is reset. Add resetting of the services associated with particular clock controllers so that requests can be retried after failures. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
1 parent 009201e commit c365fbb

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

drivers/clock_control/clock_control_nrf2_common.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ static void onoff_stop_option(struct onoff_manager *mgr,
8181
notify(mgr, 0);
8282
}
8383

84+
static void onoff_reset_option(struct onoff_manager *mgr,
85+
onoff_notify_fn notify)
86+
{
87+
notify(mgr, 0);
88+
}
89+
8490
static inline uint8_t get_index_of_highest_bit(uint32_t value)
8591
{
8692
return value ? (uint8_t)(31 - __builtin_clz(value)) : 0;
@@ -129,7 +135,8 @@ int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_
129135
for (int i = 0; i < onoff_cnt; ++i) {
130136
static const struct onoff_transitions transitions = {
131137
.start = onoff_start_option,
132-
.stop = onoff_stop_option
138+
.stop = onoff_stop_option,
139+
.reset = onoff_reset_option,
133140
};
134141
int rc;
135142

@@ -148,6 +155,22 @@ int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_
148155
return 0;
149156
}
150157

158+
int clock_config_request(struct onoff_manager *mgr, struct onoff_client *cli)
159+
{
160+
/* If the on-off service recorded earlier an error, its state must be
161+
* reset before a new request is made, otherwise the request would fail
162+
* immediately.
163+
*/
164+
if (onoff_has_error(mgr)) {
165+
struct onoff_client reset_cli;
166+
167+
sys_notify_init_spinwait(&reset_cli.notify);
168+
onoff_reset(mgr, &reset_cli);
169+
}
170+
171+
return onoff_request(mgr, cli);
172+
}
173+
151174
uint8_t clock_config_update_begin(struct k_work *work)
152175
{
153176
struct clock_config_generic *cfg =

drivers/clock_control/clock_control_nrf2_common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ int lfosc_get_accuracy(uint16_t *accuracy);
5959
*/
6060
int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_work_handler);
6161

62+
/**
63+
* @brief Helper function for requesting a clock configuration handled by
64+
* a given on-off manager.
65+
*
66+
* If needed, the function resets the on-off service prior to making the new
67+
* request.
68+
*
69+
* @param mgr pointer to the manager for which the request is to be done.
70+
* @param cli pointer to a client state structure to be used for the request.
71+
*
72+
* @return result returned by onoff_request().
73+
*/
74+
int clock_config_request(struct onoff_manager *mgr, struct onoff_client *cli);
75+
6276
/**
6377
* @brief Starts a clock configuration update.
6478
*

drivers/clock_control/clock_control_nrf2_fll16m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int api_request_fll16m(const struct device *dev,
178178
struct onoff_manager *mgr = fll16m_find_mgr(dev, spec);
179179

180180
if (mgr) {
181-
return onoff_request(mgr, cli);
181+
return clock_config_request(mgr, cli);
182182
}
183183

184184
return -EINVAL;

drivers/clock_control/clock_control_nrf2_global_hsfll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int api_request_global_hsfll(const struct device *dev,
101101
struct onoff_manager *mgr = global_hsfll_find_mgr(dev, spec);
102102

103103
if (mgr) {
104-
return onoff_request(mgr, cli);
104+
return clock_config_request(mgr, cli);
105105
}
106106

107107
return -EINVAL;

drivers/clock_control/clock_control_nrf2_hsfll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int api_request_hsfll(const struct device *dev,
140140
struct onoff_manager *mgr = hsfll_find_mgr(dev, spec);
141141

142142
if (mgr) {
143-
return onoff_request(mgr, cli);
143+
return clock_config_request(mgr, cli);
144144
}
145145

146146
return -EINVAL;

drivers/clock_control/clock_control_nrf2_lfclk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int api_request_lfclk(const struct device *dev,
146146
struct onoff_manager *mgr = lfclk_find_mgr(dev, spec);
147147

148148
if (mgr) {
149-
return onoff_request(mgr, cli);
149+
return clock_config_request(mgr, cli);
150150
}
151151

152152
return -EINVAL;

0 commit comments

Comments
 (0)