Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
transport.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
14#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
15
16#include <zephyr/device.h>
17#include <zephyr/kernel.h>
18
25
26struct scmi_message;
27struct scmi_channel;
28
43typedef void (*scmi_channel_cb)(struct scmi_channel *chan);
44
55 void *data;
70 struct k_mutex lock;
71
77 struct k_sem sem;
78
80 bool ready;
82};
83
105 int (*init)(const struct device *transport);
106
124 int (*send_message)(const struct device *transport,
125 struct scmi_channel *chan,
126 struct scmi_message *msg,
127 bool use_polling);
128
142 int (*setup_chan)(const struct device *transport,
143 struct scmi_channel *chan,
144 bool tx);
145
159 int (*read_message)(const struct device *transport,
160 struct scmi_channel *chan,
161 struct scmi_message *msg);
162
177 bool (*channel_is_free)(const struct device *transport,
178 struct scmi_channel *chan);
179
197 struct scmi_channel *(*request_channel)(const struct device *transport,
198 uint32_t proto, bool tx);
199};
200
202
206static inline struct scmi_channel *
207scmi_transport_request_channel(const struct device *transport,
208 uint32_t proto, bool tx)
209{
210 const struct scmi_transport_api *api =
211 (const struct scmi_transport_api *)transport->api;
212
213 if (api->request_channel) {
214 return api->request_channel(transport, proto, tx);
215 }
216
217 return NULL;
218}
219
223static inline int scmi_transport_init(const struct device *transport)
224{
225 const struct scmi_transport_api *api =
226 (const struct scmi_transport_api *)transport->api;
227
228 if (api->init) {
229 return api->init(transport);
230 }
231
232 return 0;
233}
234
238static inline int scmi_transport_setup_chan(const struct device *transport,
239 struct scmi_channel *chan,
240 bool tx)
241{
242 const struct scmi_transport_api *api =
243 (const struct scmi_transport_api *)transport->api;
244
245 if (!api || !api->setup_chan) {
246 return -ENOSYS;
247 }
248
249 return api->setup_chan(transport, chan, tx);
250}
251
255static inline int scmi_transport_send_message(const struct device *transport,
256 struct scmi_channel *chan,
257 struct scmi_message *msg,
258 bool use_polling)
259{
260 const struct scmi_transport_api *api =
261 (const struct scmi_transport_api *)transport->api;
262
263 if (!api || !api->send_message) {
264 return -ENOSYS;
265 }
266
267 return api->send_message(transport, chan, msg, use_polling);
268}
269
273static inline int scmi_transport_read_message(const struct device *transport,
274 struct scmi_channel *chan,
275 struct scmi_message *msg)
276{
277 const struct scmi_transport_api *api =
278 (const struct scmi_transport_api *)transport->api;
279
280 if (!api || !api->read_message) {
281 return -ENOSYS;
282 }
283
284 return api->read_message(transport, chan, msg);
285}
286
290static inline bool scmi_transport_channel_is_free(const struct device *transport,
291 struct scmi_channel *chan)
292{
293 const struct scmi_transport_api *api =
294 (const struct scmi_transport_api *)transport->api;
295
296 if (!api || !api->channel_is_free) {
297 return -ENOSYS;
298 }
299
300 return api->channel_is_free(transport, chan);
301}
302
312int scmi_core_transport_init(const struct device *transport);
313
315
319
320#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_ */
void(* scmi_channel_cb)(struct scmi_channel *chan)
Callback function for message replies.
Definition transport.h:43
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Mutex Structure.
Definition kernel.h:3402
Semaphore structure.
Definition kernel.h:3607
SCMI channel structure.
Definition transport.h:53
void * data
channel private data
Definition transport.h:55
scmi_channel_cb cb
callback function.
Definition transport.h:62
SCMI message structure.
Definition protocol.h:110
SCMI transport driver operations.
Definition transport.h:91
int(* init)(const struct device *transport)
Initialize the transport driver.
Definition transport.h:105
int(* setup_chan)(const struct device *transport, struct scmi_channel *chan, bool tx)
Prepare a channel for communication.
Definition transport.h:142
struct scmi_channel *(* request_channel)(const struct device *transport, uint32_t proto, bool tx)
Request a channel dynamically.
Definition transport.h:197
bool(* channel_is_free)(const struct device *transport, struct scmi_channel *chan)
Check if a TX channel is free.
Definition transport.h:177
int(* read_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Read a message from the platform.
Definition transport.h:159
int(* send_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg, bool use_polling)
Send a message to the platform.
Definition transport.h:124