Line data Source code
1 1 : /*
2 : * Copyright (c) 2025 Renesas Electronics Corporation
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief Public APIs for the Renesas ELC driver
10 : * @ingroup renesas_elc_interface
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_ELC_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_ELC_H_
15 :
16 : /**
17 : * @brief Interfaces for Renesas Event Link Controller (ELC).
18 : * @defgroup renesas_elc_interface Renesas ELC
19 : * @ingroup misc_interfaces
20 : * @{
21 : */
22 :
23 : #include <stdint.h>
24 : #include <zephyr/sys/slist.h>
25 : #include <zephyr/device.h>
26 : #include <zephyr/kernel.h>
27 : #include <zephyr/internal/syscall_handler.h>
28 :
29 : #ifdef __cplusplus
30 : extern "C" {
31 : #endif
32 :
33 : /**
34 : * @brief Container for Renesas ELC information specified in devicetree.
35 : *
36 : * This type contains a pointer to a Renesas ELC device, along with the
37 : * peripheral ID and event ID used to configure a link between peripherals
38 : * via the Event Link Controller.
39 : *
40 : * This structure is typically initialized using devicetree macros that parse
41 : * phandle-array properties referencing ELC instances.
42 : */
43 1 : struct renesas_elc_dt_spec {
44 : /** Renesas ELC device instance. */
45 1 : const struct device *dev;
46 : /** Renesas ELC peripheral ID. */
47 1 : uint32_t peripheral;
48 : /** Renesas ELC event ID. */
49 1 : uint32_t event;
50 : };
51 :
52 : /**
53 : * @brief Get the device pointer from the "renesas-elcs" property by element name.
54 : *
55 : * @param node_id Devicetree node identifier.
56 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
57 : *
58 : * @return Device pointer.
59 : */
60 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_GET_BY_NAME(node_id, name) \
61 : DEVICE_DT_GET(DT_PHANDLE_BY_NAME(node_id, renesas_elcs, name))
62 :
63 : /**
64 : * @brief Get the device pointer from the "renesas-elcs" property by index.
65 : *
66 : * @param node_id Devicetree node identifier.
67 : * @param idx Logical index into the renesas-elcs property.
68 : *
69 : * @return Device pointer.
70 : */
71 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_GET_BY_IDX(node_id, idx) \
72 : DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, renesas_elcs, idx))
73 :
74 : /**
75 : * @brief Get the device pointer from the "renesas-elcs" property by element name,
76 : * or return NULL if the property does not exist.
77 : *
78 : * @param node_id Devicetree node identifier.
79 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
80 : *
81 : * @return Device pointer or NULL.
82 : */
83 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_GET_BY_NAME_OR_NULL(node_id, name) \
84 : DEVICE_DT_GET_OR_NULL(DT_PHANDLE_BY_NAME(node_id, renesas_elcs, name))
85 :
86 : /**
87 : * @brief Get the device pointer from the "renesas-elcs" property by index,
88 : * or return NULL if the property does not exist.
89 : *
90 : * @param node_id Devicetree node identifier.
91 : * @param idx Logical index into the renesas-elcs property.
92 : *
93 : * @return Device pointer or NULL.
94 : */
95 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_GET_BY_IDX_OR_NULL(node_id, idx) \
96 : DEVICE_DT_GET_OR_NULL(DT_PHANDLE_BY_IDX(node_id, renesas_elcs, idx))
97 :
98 : /**
99 : * @brief Get the device pointer from the "renesas-elcs" property by element name for a
100 : * DT_DRV_COMPAT instance.
101 : *
102 : * @param inst DT_DRV_COMPAT instance number.
103 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
104 : *
105 : * @return Device pointer.
106 : */
107 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_INST_GET_BY_NAME(inst, name) \
108 : DEVICE_DT_GET(DT_PHANDLE_BY_NAME(DT_DRV_INST(inst), renesas_elcs, name))
109 :
110 : /**
111 : * @brief Get the device pointer from the "renesas-elcs" property by index for a DT_DRV_COMPAT
112 : * instance.
113 : *
114 : * @param inst DT_DRV_COMPAT instance number.
115 : * @param idx Logical index into the renesas-elcs property.
116 : *
117 : * @return Device pointer.
118 : */
119 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_INST_GET_BY_IDX(inst, idx) \
120 : DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_DRV_INST(inst), renesas_elcs, idx))
121 :
122 : /**
123 : * @brief Get the device pointer from the "renesas-elcs" property by element name
124 : * for a DT_DRV_COMPAT instance, or return NULL if the property does not exist.
125 : *
126 : * @param inst DT_DRV_COMPAT instance number.
127 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
128 : *
129 : * @return Device pointer or NULL.
130 : */
131 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_INST_GET_BY_NAME_OR_NULL(inst, name) \
132 : DEVICE_DT_GET_OR_NULL(DT_PHANDLE_BY_NAME(DT_DRV_INST(inst), renesas_elcs, name))
133 :
134 : /**
135 : * @brief Get the device pointer from the "renesas-elcs" property by index
136 : * for a DT_DRV_COMPAT instance, or return NULL if the property does not exist.
137 : *
138 : * @param inst DT_DRV_COMPAT instance number.
139 : * @param idx Logical index into the renesas-elcs property.
140 : *
141 : * @return Device pointer or NULL.
142 : */
143 1 : #define RENESAS_ELC_DT_SPEC_DEVICE_INST_GET_BY_IDX_OR_NULL(inst, idx) \
144 : DEVICE_DT_GET_OR_NULL(DT_PHANDLE_BY_IDX(DT_DRV_INST(inst), renesas_elcs, idx))
145 :
146 : /**
147 : * @brief Get the peripheral cell value from the "renesas-elcs" property by element name.
148 : *
149 : * @param node_id Devicetree node identifier.
150 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
151 : *
152 : * @return Peripheral cell value.
153 : */
154 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_NAME(node_id, name) \
155 : DT_PHA_BY_NAME(node_id, renesas_elcs, name, peripheral)
156 :
157 : /**
158 : * @brief Get the peripheral cell value from the "renesas-elcs" property by index.
159 : *
160 : * @param node_id Devicetree node identifier.
161 : * @param idx Logical index into the renesas-elcs property.
162 : *
163 : * @return Peripheral cell value.
164 : */
165 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_IDX(node_id, idx) \
166 : DT_PHA_BY_IDX(node_id, renesas_elcs, idx, peripheral)
167 :
168 : /**
169 : * @brief Get the peripheral cell value from the "renesas-elcs" property by element name,
170 : * or return a default value if the property does not exist.
171 : *
172 : * @param node_id Devicetree node identifier.
173 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
174 : * @param default_value Value to return if the property is not present.
175 : *
176 : * @return Peripheral cell value or default_value.
177 : */
178 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_NAME_OR(node_id, name, default_value) \
179 : COND_CODE_1(DT_NODE_HAS_PROP(node_id, renesas_elcs), \
180 : (RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_NAME(node_id, name)), \
181 : (default_value))
182 :
183 : /**
184 : * @brief Get the peripheral cell value from the "renesas-elcs" property by index,
185 : * or return a default value if the property does not exist.
186 : *
187 : * @param node_id Devicetree node identifier.
188 : * @param idx Logical index into the renesas-elcs property.
189 : * @param default_value Value to return if the property is not present.
190 : *
191 : * @return Peripheral cell value or default_value.
192 : */
193 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_IDX_OR(node_id, idx, default_value) \
194 : COND_CODE_1(DT_NODE_HAS_PROP(node_id, renesas_elcs), \
195 : (RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_IDX(node_id, idx)), \
196 : (default_value))
197 :
198 : /**
199 : * @brief Get the peripheral cell value by element name for a DT_DRV_COMPAT instance.
200 : *
201 : * @param inst DT_DRV_COMPAT instance number.
202 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
203 : *
204 : * @return Peripheral cell value.
205 : */
206 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_INST_GET_BY_NAME(inst, name) \
207 : RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_NAME(DT_DRV_INST(inst), name)
208 :
209 : /**
210 : * @brief Get the peripheral cell value by index for a DT_DRV_COMPAT instance.
211 : *
212 : * @param inst DT_DRV_COMPAT instance number.
213 : * @param idx Logical index into the renesas-elcs property.
214 : *
215 : * @return Peripheral cell value.
216 : */
217 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_INST_GET_BY_IDX(inst, idx) \
218 : RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_IDX(DT_DRV_INST(inst), idx)
219 :
220 : /**
221 : * @brief Get the peripheral cell value by element name for a DT_DRV_COMPAT instance,
222 : * or return a default value if the property does not exist.
223 : *
224 : * @param inst DT_DRV_COMPAT instance number.
225 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
226 : * @param default_value Value to return if the property is not present.
227 : *
228 : * @return Peripheral cell value or default_value.
229 : */
230 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_INST_GET_BY_NAME_OR(inst, name, default_value) \
231 : RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
232 :
233 : /**
234 : * @brief Get the peripheral cell value by index for a DT_DRV_COMPAT instance,
235 : * or return a default value if the property does not exist.
236 : *
237 : * @param inst DT_DRV_COMPAT instance number.
238 : * @param idx Logical index into the renesas-elcs property.
239 : * @param default_value Value to return if the property is not present.
240 : *
241 : * @return Peripheral cell value or default_value.
242 : */
243 1 : #define RENESAS_ELC_DT_SPEC_PERIPHERAL_INST_GET_BY_IDX_OR(inst, idx, default_value) \
244 : RENESAS_ELC_DT_SPEC_PERIPHERAL_GET_BY_IDX_OR(DT_DRV_INST(inst), idx, default_value)
245 :
246 : /**
247 : * @brief Get the event cell value from the "renesas-elcs" property by element name.
248 : *
249 : * @param node_id Devicetree node identifier.
250 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
251 : *
252 : * @return Event cell value.
253 : */
254 1 : #define RENESAS_ELC_DT_SPEC_EVENT_GET_BY_NAME(node_id, name) \
255 : DT_PHA_BY_NAME(node_id, renesas_elcs, name, event)
256 :
257 : /**
258 : * @brief Get the event cell value from the "renesas-elcs" property by index.
259 : *
260 : * @param node_id Devicetree node identifier.
261 : * @param idx Logical index into the renesas-elcs property.
262 : *
263 : * @return Event cell value.
264 : */
265 1 : #define RENESAS_ELC_DT_SPEC_EVENT_GET_BY_IDX(node_id, idx) \
266 : DT_PHA_BY_IDX(node_id, renesas_elcs, idx, event)
267 :
268 : /**
269 : * @brief Get the event cell value from the "renesas-elcs" property by element name,
270 : * or return a default value if the property does not exist.
271 : *
272 : * @param node_id Devicetree node identifier.
273 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
274 : * @param default_value Value to return if the property is not present.
275 : *
276 : * @return Event cell value or default_value.
277 : */
278 1 : #define RENESAS_ELC_DT_SPEC_EVENT_GET_BY_NAME_OR(node_id, name, default_value) \
279 : COND_CODE_1(DT_NODE_HAS_PROP(node_id, renesas_elcs), \
280 : (RENESAS_ELC_DT_SPEC_EVENT_GET_BY_NAME(node_id, name)), \
281 : (default_value))
282 :
283 : /**
284 : * @brief Get the event cell value from the "renesas-elcs" property by index,
285 : * or return a default value if the property does not exist.
286 : *
287 : * @param node_id Devicetree node identifier.
288 : * @param idx Logical index into the renesas-elcs property.
289 : * @param default_value Value to return if the property is not present.
290 : *
291 : * @return Event cell value or default_value.
292 : */
293 1 : #define RENESAS_ELC_DT_SPEC_EVENT_GET_BY_IDX_OR(node_id, idx, default_value) \
294 : COND_CODE_1(DT_NODE_HAS_PROP(node_id, renesas_elcs), \
295 : (RENESAS_ELC_DT_SPEC_EVENT_GET_BY_IDX(node_id, idx)), \
296 : (default_value))
297 :
298 : /**
299 : * @brief Get the event cell value by element name for a DT_DRV_COMPAT instance.
300 : *
301 : * @param inst DT_DRV_COMPAT instance number.
302 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
303 : *
304 : * @return Event cell value.
305 : */
306 1 : #define RENESAS_ELC_DT_SPEC_EVENT_INST_GET_BY_NAME(inst, name) \
307 : RENESAS_ELC_DT_SPEC_EVENT_GET_BY_NAME(DT_DRV_INST(inst), name)
308 :
309 : /**
310 : * @brief Get the event cell value by index for a DT_DRV_COMPAT instance.
311 : *
312 : * @param inst DT_DRV_COMPAT instance number.
313 : * @param idx Logical index into the renesas-elcs property.
314 : *
315 : * @return Event cell value.
316 : */
317 1 : #define RENESAS_ELC_DT_SPEC_EVENT_INST_GET_BY_IDX(inst, idx) \
318 : RENESAS_ELC_DT_SPEC_EVENT_GET_BY_IDX(DT_DRV_INST(inst), idx)
319 :
320 : /**
321 : * @brief Get the event cell value by element name for a DT_DRV_COMPAT instance,
322 : * or return a default value if the property does not exist.
323 : *
324 : * @param inst DT_DRV_COMPAT instance number.
325 : * @param name Lowercase-and-underscores name as specified in the renesas-elcs-names property.
326 : * @param default_value Value to return if the property is not present.
327 : *
328 : * @return Event cell value or default_value.
329 : */
330 1 : #define RENESAS_ELC_DT_SPEC_EVENT_INST_GET_BY_NAME_OR(inst, name, default_value) \
331 : RENESAS_ELC_DT_SPEC_EVENT_GET_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
332 :
333 : /**
334 : * @brief Get the event cell value by index for a DT_DRV_COMPAT instance,
335 : * or return a default value if the property does not exist.
336 : *
337 : * @param inst DT_DRV_COMPAT instance number.
338 : * @param idx Logical index into the renesas-elcs property.
339 : * @param default_value Value to return if the property is not present.
340 : *
341 : * @return Event cell value or default_value.
342 : */
343 1 : #define RENESAS_ELC_DT_SPEC_EVENT_INST_GET_BY_IDX_OR(inst, idx, default_value) \
344 : RENESAS_ELC_DT_SPEC_EVENT_GET_BY_IDX_OR(DT_DRV_INST(inst), idx, default_value)
345 :
346 : /**
347 : * @cond INTERNAL_HIDDEN
348 : *
349 : * Renesas ELC driver API definition and system call entry points
350 : *
351 : * (Internal use only.)
352 : */
353 : __subsystem struct renesas_elc_driver_api {
354 : int (*software_event_generate)(const struct device *dev, uint32_t event);
355 : int (*link_set)(const struct device *dev, uint32_t peripheral, uint32_t signal);
356 : int (*link_break)(const struct device *dev, uint32_t peripheral);
357 : int (*enable)(const struct device *dev);
358 : int (*disable)(const struct device *dev);
359 : };
360 :
361 : /**
362 : * @endcond
363 : */
364 :
365 : /**
366 : * @brief Generate a software event in the Event Link Controller.
367 : *
368 : * This function requests the Renesas ELC to generate a software event
369 : * identified by @p event.
370 : *
371 : * @param dev The Event Link Controller device.
372 : * @param event Software event ID to generate.
373 : *
374 : * @return 0 if successful.
375 : * @return A negative errno code on failure.
376 : */
377 1 : __syscall int renesas_elc_software_event_generate(const struct device *dev, uint32_t event);
378 :
379 : static inline int z_impl_renesas_elc_software_event_generate(const struct device *dev,
380 : uint32_t event)
381 : {
382 : return DEVICE_API_GET(renesas_elc, dev)->software_event_generate(dev, event);
383 : }
384 :
385 : /**
386 : * @brief Create a single event link.
387 : *
388 : * This function configures an event link by associating a peripheral with
389 : * a specific event signal.
390 : *
391 : * @param dev Event Link Controller device.
392 : * @param peripheral Peripheral ID to be linked to the event signal.
393 : * @param event Event signal ID to be associated with the peripheral.
394 : *
395 : * @return 0 if successful.
396 : * @return A negative errno code on failure.
397 : */
398 1 : __syscall int renesas_elc_link_set(const struct device *dev, uint32_t peripheral, uint32_t event);
399 :
400 : static inline int z_impl_renesas_elc_link_set(const struct device *dev, uint32_t peripheral,
401 : uint32_t event)
402 : {
403 : return DEVICE_API_GET(renesas_elc, dev)->link_set(dev, peripheral, event);
404 : }
405 :
406 : /**
407 : * @brief Break an event link.
408 : *
409 : * This function breaks an existing event link for the given peripheral.
410 : *
411 : * @param dev Event Link Controller device.
412 : * @param peripheral Peripheral ID whose link is to be broken.
413 : *
414 : * @return 0 if successful.
415 : * @return A negative errno code on failure.
416 : */
417 1 : __syscall int renesas_elc_link_break(const struct device *dev, uint32_t peripheral);
418 :
419 : static inline int z_impl_renesas_elc_link_break(const struct device *dev, uint32_t peripheral)
420 : {
421 : return DEVICE_API_GET(renesas_elc, dev)->link_break(dev, peripheral);
422 : }
423 :
424 : /**
425 : * @brief Enable the operation of the Event Link Controller.
426 : *
427 : * This function enables the ELC so that it can process events.
428 : *
429 : * @param dev Event Link Controller device.
430 : *
431 : * @return 0 if successful.
432 : * @return A negative errno code on failure.
433 : */
434 1 : __syscall int renesas_elc_enable(const struct device *dev);
435 :
436 : static inline int z_impl_renesas_elc_enable(const struct device *dev)
437 : {
438 : return DEVICE_API_GET(renesas_elc, dev)->enable(dev);
439 : }
440 :
441 : /**
442 : * @brief Disable the operation of the Event Link Controller.
443 : *
444 : * This function disables the ELC, stopping event processing.
445 : *
446 : * @param dev Event Link Controller device.
447 : *
448 : * @return 0 if successful.
449 : * @return A negative errno code on failure.
450 : */
451 1 : __syscall int renesas_elc_disable(const struct device *dev);
452 :
453 : static inline int z_impl_renesas_elc_disable(const struct device *dev)
454 : {
455 : return DEVICE_API_GET(renesas_elc, dev)->disable(dev);
456 : }
457 :
458 : /**
459 : * @}
460 : */
461 :
462 : #ifdef __cplusplus
463 : }
464 : #endif
465 :
466 : #include <zephyr/syscalls/renesas_elc.h>
467 :
468 : #endif /* ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_ELC_H_ */
|