|
183 | 183 | DEVICE_DT_INST_DEFINE(inst, &scmi_core_transport_init, \ |
184 | 184 | pm, data, config, level, prio, api) |
185 | 185 |
|
| 186 | +/** |
| 187 | + * @brief Define an SCMI transport driver |
| 188 | + * |
| 189 | + * This is merely a wrapper over DEVICE_INSTANCE_FROM_DT_INST(), but is |
| 190 | + * required since transport layer drivers are not allowed to place |
| 191 | + * their own init() function in the init section. Instead, transport |
| 192 | + * layer drivers place the scmi_core_transport_init() function in the |
| 193 | + * init section, which, in turn, will call the transport layer driver |
| 194 | + * init() function. This is required because the SCMI core needs to |
| 195 | + * perform channel binding and setup during the transport layer driver's |
| 196 | + * initialization. |
| 197 | + */ |
| 198 | +#define SCMI_TRANSPORT_INSTANCE_FROM_DT_INST(inst, pm, data, config, \ |
| 199 | + level, api) \ |
| 200 | + DEVICE_INSTANCE_FROM_DT_INST(inst, &scmi_core_transport_init, \ |
| 201 | + pm, data, config, level, api) |
| 202 | + |
186 | 203 | /** |
187 | 204 | * @brief Define an SCMI protocol |
188 | 205 | * |
|
216 | 233 | &SCMI_PROTOCOL_NAME(DT_REG_ADDR_RAW(node_id)), \ |
217 | 234 | config, level, prio, api) |
218 | 235 |
|
| 236 | +/** |
| 237 | + * @brief Define an SCMI protocol |
| 238 | + * |
| 239 | + * This macro performs three important functions: |
| 240 | + * 1) It defines a `struct scmi_protocol`, which is |
| 241 | + * needed by all protocol drivers to work with the SCMI API. |
| 242 | + * |
| 243 | + * 2) It declares the static channels bound to the protocol. |
| 244 | + * This is only applicable if the transport layer driver |
| 245 | + * supports static channels. |
| 246 | + * |
| 247 | + * 3) It creates a `struct device` a sets the `data` field |
| 248 | + * to the newly defined `struct scmi_protocol`. This is |
| 249 | + * needed because the protocol driver needs to work with the |
| 250 | + * SCMI API **and** the subsystem API. |
| 251 | + * |
| 252 | + * @param node_id protocol node identifier |
| 253 | + * @param init_fn pointer to protocol's initialization function |
| 254 | + * @param api pointer to protocol's subsystem API |
| 255 | + * @param pm pointer to the protocol's power management resources |
| 256 | + * @param data pointer to protocol's private data |
| 257 | + * @param config pointer to protocol's private constant data |
| 258 | + * @param level protocol initialization level |
| 259 | + * @param api pointer to driver's api |
| 260 | + */ |
| 261 | +#define SCMI_PROTOCOL_INSTANCE(node_id, init_fn, pm, data, config, \ |
| 262 | + level, api) \ |
| 263 | + DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \ |
| 264 | + DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR(node_id), data); \ |
| 265 | + DEVICE_INSTANCE(node_id, init_fn, pm, \ |
| 266 | + &SCMI_PROTOCOL_NAME(DT_REG_ADDR(node_id)), \ |
| 267 | + config, level, api) |
| 268 | + |
219 | 269 | /** |
220 | 270 | * @brief Just like DT_SCMI_PROTOCOL_DEFINE(), but uses an instance |
221 | 271 | * of a `DT_DRV_COMPAT` compatible instead of a node identifier |
|
233 | 283 | level, prio, api) \ |
234 | 284 | DT_SCMI_PROTOCOL_DEFINE(DT_INST(inst, DT_DRV_COMPAT), init_fn, pm, \ |
235 | 285 | data, config, level, prio, api) |
| 286 | +/** |
| 287 | + * @brief Just like SCMI_PROTOCOL_INSTANCE(), but uses an instance |
| 288 | + * of a `DT_DRV_COMPAT` compatible instead of a node identifier |
| 289 | + * |
| 290 | + * @param inst instance number |
| 291 | + * @param ... Other parameters as expected by SCMI_PROTOCOL_INSTANCE |
| 292 | + */ |
| 293 | +#define SCMI_PROTOCOL_INSTANCE_FROM_DT_INST(inst, ...) \ |
| 294 | + SCMI_PROTOCOL_INSTANCE(DT_INST(inst, DT_DRV_COMPAT), __VA_ARGS__) |
236 | 295 |
|
237 | 296 | /** |
238 | 297 | * @brief Define an SCMI protocol with no device |
|
0 commit comments