Skip to content

Commit ee352d6

Browse files
committed
include/drivers: clock_control.h: Add configure() to api
Add configure() function to clock_control API. This function allows caller to configure a given clock. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent ca217fe commit ee352d6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

include/drivers/clock_control.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,18 @@ typedef int (*clock_control_set)(const struct device *dev,
9292
clock_control_subsys_t sys,
9393
clock_control_subsys_rate_t rate);
9494

95+
typedef int (*clock_control_configure_fn)(const struct device *dev,
96+
clock_control_subsys_t sys,
97+
void *data);
98+
9599
struct clock_control_driver_api {
96100
clock_control on;
97101
clock_control off;
98102
clock_control_async_on_fn async_on;
99103
clock_control_get get_rate;
100104
clock_control_get_status_fn get_status;
101105
clock_control_set set_rate;
106+
clock_control_configure_fn configure;
102107
};
103108

104109
/**
@@ -270,6 +275,45 @@ static inline int clock_control_set_rate(const struct device *dev,
270275
return api->set_rate(dev, sys, rate);
271276
}
272277

278+
/**
279+
* @brief Configure a source clock
280+
*
281+
* This function is non-blocking and can be called from any context.
282+
* On success, the selected clock is configured as per caller's request.
283+
*
284+
* It is caller's responsibility to ensure that subsequent calls to the API
285+
* provide the right information to allows clock_control driver to perform
286+
* the right action (such as using the right clock source on clock_control_get_rate
287+
* call).
288+
*
289+
* @p data is implementation specific and could be used to convey
290+
* supplementary information required for expected clock configuration.
291+
*
292+
* @param dev Device structure whose driver controls the clock
293+
* @param sys Opaque data representing the clock
294+
* @param data Opaque data providing additional input for clock configuration
295+
*
296+
* @retval 0 On success
297+
* @retval -ENOSYS If the device driver does not implement this call
298+
* @retval -errno Other negative errno on failure.
299+
*/
300+
static inline int clock_control_configure(const struct device *dev,
301+
clock_control_subsys_t sys,
302+
void *data)
303+
{
304+
if (!device_is_ready(dev)) {
305+
return -ENODEV;
306+
}
307+
308+
const struct clock_control_driver_api *api =
309+
(const struct clock_control_driver_api *)dev->api;
310+
311+
if (api->configure == NULL) {
312+
return -ENOSYS;
313+
}
314+
315+
return api->configure(dev, sys, data);
316+
}
273317

274318
#ifdef __cplusplus
275319
}

0 commit comments

Comments
 (0)