LCOV - code coverage report
Current view: top level - zephyr/drivers/misc/interconn/renesas_elc - renesas_elc.h Coverage Total Hit
Test: new.info Lines: 100.0 % 34 34
Test Date: 2025-09-05 16:43:28

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

Generated by: LCOV version 2.0-1