Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /* clock_control.h - public clock controller driver API */ /* * Copyright (c) 2015 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ #define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ #include <zephyr/types.h> #include <stddef.h> #include <device.h> #include <sys/__assert.h> #include <sys/slist.h> #ifdef __cplusplus extern "C" { #endif /* Clock control API */ /* Used to select all subsystem of a clock controller */ #define CLOCK_CONTROL_SUBSYS_ALL NULL /** * @brief Current clock status. */ enum clock_control_status { CLOCK_CONTROL_STATUS_STARTING, CLOCK_CONTROL_STATUS_OFF, CLOCK_CONTROL_STATUS_ON, CLOCK_CONTROL_STATUS_UNKNOWN }; typedef void (*clock_control_cb_t)(struct device *dev, void *user_data); /** * @cond INTERNAL_HIDDEN */ #define Z_CLOCK_CONTROL_ASYNC_DATA_INITIALIZER(_cb, _user_data) \ { \ .cb = cb, \ .user_data = _user_data \ } /** * INTERNAL_HIDDEN @endcond */ /** * Define and initialize clock_control async data. * * @param name Name of the data. * @param cb Callback. * @param user_data User data */ #define CLOCK_CONTROL_ASYNC_DATA_DEFINE(name, cb, user_data) \ struct clock_control_async_data name = \ Z_CLOCK_CONTROL_ASYNC_DATA_INITIALIZER(cb, user_data) /** * @brief Clock control data used for asynchronous clock enabling. * * @param node Used internally for linking asynchronous requests. * @param cb Callback called when clock is started. * @param user_data User data passed as an argument in the callback. */ struct clock_control_async_data { sys_snode_t node; clock_control_cb_t cb; void *user_data; }; /** * clock_control_subsys_t is a type to identify a clock controller sub-system. * Such data pointed is opaque and relevant only to the clock controller * driver instance being used. */ typedef void *clock_control_subsys_t; typedef int (*clock_control)(struct device *dev, clock_control_subsys_t sys); typedef int (*clock_control_get)(struct device *dev, clock_control_subsys_t sys, u32_t *rate); typedef int (*clock_control_async_on_fn)(struct device *dev, clock_control_subsys_t sys, struct clock_control_async_data *data); typedef enum clock_control_status (*clock_control_get_status_fn)( struct device *dev, clock_control_subsys_t sys); struct clock_control_driver_api { clock_control on; clock_control off; clock_control_async_on_fn async_on; clock_control_get get_rate; clock_control_get_status_fn get_status; }; /** * @brief Enable the clock of a sub-system controlled by the device * @param dev Pointer to the device structure for the clock controller driver * instance * @param sys A pointer to an opaque data representing the sub-system */ static inline int clock_control_on(struct device *dev, clock_control_subsys_t sys) { const struct clock_control_driver_api *api = (const struct clock_control_driver_api *)dev->driver_api; return api->on(dev, sys); } /** * @brief Disable the clock of a sub-system controlled by the device. * * Function is non-blocking and can be called from any context. * * @param dev Pointer to the device structure for the clock controller driver * instance * @param sys A pointer to an opaque data representing the sub-system */ static inline int clock_control_off(struct device *dev, clock_control_subsys_t sys) { const struct clock_control_driver_api *api = (const struct clock_control_driver_api *)dev->driver_api; return api->off(dev, sys); } /** * @brief Request clock to start with notification when clock has been started. * * Function is non-blocking and can be called from any context. * When clock is already running user callback will be called from the context * of the function call else it is called from other context (e.g. clock * interrupt). * * @param dev Device. * @param sys A pointer to an opaque data representing the sub-system. * @param data Data structure containing a callback that is called when * action is performed. Structure content must be valid until * clock is started and user callback is called. Can be NULL. * * @retval 0 if clock is started or already running. * @retval -EBUSY if same request already scheduled and not yet completed. * @retval -ENOTSUP if not supported. */ static inline int clock_control_async_on(struct device *dev, clock_control_subsys_t sys, struct clock_control_async_data *data) { const struct clock_control_driver_api *api = (const struct clock_control_driver_api *)dev->driver_api; if (!api->async_on) { return -ENOTSUP; } return api->async_on(dev, sys, data); } /** * @brief Get clock status. * * @param dev Device. * @param sys A pointer to an opaque data representing the sub-system. * * @return Status. */ static inline enum clock_control_status clock_control_get_status( struct device *dev, clock_control_subsys_t sys) { const struct clock_control_driver_api *api = (const struct clock_control_driver_api *)dev->driver_api; if (!api->get_status) { return CLOCK_CONTROL_STATUS_UNKNOWN; } return api->get_status(dev, sys); } /** * @brief Obtain the clock rate of given sub-system * @param dev Pointer to the device structure for the clock controller driver * instance * @param sys A pointer to an opaque data representing the sub-system * @param[out] rate Subsystem clock rate */ static inline int clock_control_get_rate(struct device *dev, clock_control_subsys_t sys, u32_t *rate) { const struct clock_control_driver_api *api = (const struct clock_control_driver_api *)dev->driver_api; __ASSERT(api->get_rate != NULL, "%s not implemented for device %s", __func__, dev->config->name); return api->get_rate(dev, sys, rate); } #ifdef __cplusplus } #endif #endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ */ |