LCOV - code coverage report
Current view: top level - zephyr/drivers/i3c - devicetree.h Coverage Total Hit
Test: new.info Lines: 94.1 % 17 16
Test Date: 2025-09-05 16:43:28

            Line data    Source code
       1            0 : /*
       2              :  * Copyright 2022 Intel Corporation
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : #ifndef ZEPHYR_INCLUDE_DRIVERS_I3C_DEVICETREE_H_
       8              : #define ZEPHYR_INCLUDE_DRIVERS_I3C_DEVICETREE_H_
       9              : 
      10              : /**
      11              :  * @brief I3C Devicetree related bits
      12              :  * @defgroup i3c_devicetree I3C Devicetree related bits
      13              :  * @ingroup i3c_interface
      14              :  * @{
      15              :  */
      16              : 
      17              : #include <stdint.h>
      18              : 
      19              : #include <zephyr/device.h>
      20              : #include <zephyr/devicetree.h>
      21              : #include <zephyr/sys/util.h>
      22              : 
      23              : #ifdef __cplusplus
      24              : extern "C" {
      25              : #endif
      26              : 
      27              : /**
      28              :  * @brief Structure initializer for i3c_device_id from devicetree
      29              :  *
      30              :  * This helper macro expands to a static initializer for a <tt>struct
      31              :  * i3c_device_id</tt> by reading the relevant device data from devicetree.
      32              :  *
      33              :  * @param node_id Devicetree node identifier for the I3C device whose
      34              :  *                struct i3c_device_id to create an initializer for
      35              :  */
      36            1 : #define I3C_DEVICE_ID_DT(node_id)                                       \
      37              :         {                                                               \
      38              :                 .pid = ((uint64_t)DT_PROP_BY_IDX(node_id, reg, 1) << 32)\
      39              :                        | DT_PROP_BY_IDX(node_id, reg, 2),               \
      40              :         }
      41              : 
      42              : /**
      43              :  * @brief Structure initializer for i3c_device_id from devicetree instance
      44              :  *
      45              :  * This is equivalent to
      46              :  * @code{.c}
      47              :  * I3C_DEVICE_ID_DT(DT_DRV_INST(inst))
      48              :  * @endcode
      49              :  *
      50              :  * @param inst Devicetree instance number
      51              :  */
      52            1 : #define I3C_DEVICE_ID_DT_INST(inst)                                     \
      53              :         I3C_DEVICE_ID_DT(DT_DRV_INST(inst))
      54              : 
      55              : /**
      56              :  * @name I3C device flags.
      57              :  * @anchor I3C_DEVICE_FLAGS
      58              :  * @{
      59              :  */
      60              : 
      61              : /** Device supports SETAASA CCC */
      62            1 : #define I3C_SUPPORTS_SETAASA            BIT(0)
      63              : /** Device supports I3C v1.0 */
      64            1 : #define I3C_V1P0_SUPPORT                BIT(1)
      65              : 
      66              : /** @} */
      67              : 
      68              : /**
      69              :  * @brief Structure initializer for i3c_device_desc from devicetree
      70              :  *
      71              :  * This helper macro expands to a static initializer for a <tt>struct
      72              :  * i3c_device_desc</tt> by reading the relevant bus and device data
      73              :  * from the devicetree.
      74              :  *
      75              :  * @param node_id Devicetree node identifier for the I3C device whose
      76              :  *                struct i3c_device_desc to create an initializer for
      77              :  */
      78            1 : #define I3C_DEVICE_DESC_DT(node_id)                                                                \
      79              :         {                                                                                          \
      80              :                 .bus = DEVICE_DT_GET(DT_BUS(node_id)),                                             \
      81              :                 .dev = DEVICE_DT_GET(node_id),                                                     \
      82              :                 .static_addr = DT_PROP_BY_IDX(node_id, reg, 0),                                    \
      83              :                 .pid = ((uint64_t)DT_PROP_BY_IDX(node_id, reg, 1) << 32) |                         \
      84              :                        DT_PROP_BY_IDX(node_id, reg, 2),                                            \
      85              :                 .init_dynamic_addr = DT_PROP_OR(node_id, assigned_address, 0),                     \
      86              :                 .flags = FIELD_PREP(I3C_SUPPORTS_SETAASA, DT_PROP(node_id, supports_setaasa)) |    \
      87              :                          FIELD_PREP(I3C_V1P0_SUPPORT, DT_PROP(node_id, v1p0_support)),             \
      88              :         },
      89              : 
      90              : /**
      91              :  * @brief Structure initializer for i3c_device_desc from devicetree instance
      92              :  *
      93              :  * This is equivalent to
      94              :  *
      95              :  * @code{.c}
      96              :  * I3C_DEVICE_DESC_DT(DT_DRV_INST(inst))
      97              :  * @endcode
      98              :  *
      99              :  * @param inst Devicetree instance number
     100              :  */
     101            1 : #define I3C_DEVICE_DESC_DT_INST(inst)                                   \
     102              :         I3C_DEVICE_DESC_DT(DT_DRV_INST(inst))
     103              : 
     104              : /**
     105              :  * @brief Structure initializer for i3c_device_desc from devicetree
     106              :  *
     107              :  * This is mainly used by I3C_DEVICE_ARRAY_DT() to only
     108              :  * create a struct if and only if it is an I3C device.
     109              :  */
     110            1 : #define I3C_DEVICE_DESC_DT_FILTERED(node_id)                            \
     111              :         COND_CODE_0(DT_PROP_BY_IDX(node_id, reg, 1),                    \
     112              :                     (), (I3C_DEVICE_DESC_DT(node_id)))
     113              : 
     114              : /**
     115              :  * @brief Array initializer for a list of i3c_device_desc from devicetree
     116              :  *
     117              :  * This is a helper macro to generate an array for a list of i3c_device_desc
     118              :  * from device tree.
     119              :  *
     120              :  * @param node_id Devicetree node identifier of the I3C controller
     121              :  */
     122            1 : #define I3C_DEVICE_ARRAY_DT(node_id)                                    \
     123              :         {                                                               \
     124              :                 DT_FOREACH_CHILD_STATUS_OKAY(                           \
     125              :                         node_id,                                        \
     126              :                         I3C_DEVICE_DESC_DT_FILTERED)                    \
     127              :         }
     128              : 
     129              : /**
     130              :  * @brief Array initializer for a list of i3c_device_desc from devicetree instance
     131              :  *
     132              :  * This is equivalent to
     133              :  * @code{.c}
     134              :  * I3C_DEVICE_ARRAY_DT(DT_DRV_INST(inst))
     135              :  * @endcode
     136              :  *
     137              :  * @param inst Devicetree instance number of the I3C controller
     138              :  */
     139            1 : #define I3C_DEVICE_ARRAY_DT_INST(inst)                                  \
     140              :         I3C_DEVICE_ARRAY_DT(DT_DRV_INST(inst))
     141              : 
     142              : /**
     143              :  * @brief Like DEVICE_DT_DEFINE() with I3C target device specifics.
     144              :  *
     145              :  * Defines a I3C target device which implements the I3C target device API.
     146              :  *
     147              :  * @param node_id The devicetree node identifier.
     148              :  *
     149              :  * @param init_fn Name of the init function of the driver.
     150              :  *
     151              :  * @param pm PM device resources reference (`NULL` if device does not use PM).
     152              :  *
     153              :  * @param data Pointer to the device's private data.
     154              :  *
     155              :  * @param config The address to the structure containing the
     156              :  *               configuration information for this instance of the driver.
     157              :  *
     158              :  * @param level The initialization level. See SYS_INIT() for
     159              :  *              details.
     160              :  *
     161              :  * @param prio Priority within the selected initialization level. See
     162              :  *             SYS_INIT() for details.
     163              :  *
     164              :  * @param api Provides an initial pointer to the API function struct
     165              :  *            used by the driver. Can be NULL.
     166              :  */
     167              : #define I3C_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
     168            1 :                              prio, api, ...)                            \
     169              :         DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level,     \
     170              :                          prio, api, __VA_ARGS__)
     171              : 
     172              : /**
     173              :  * @brief Like I3C_TARGET_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible
     174              :  *
     175              :  * @param inst instance number. This is replaced by
     176              :  * `DT_DRV_COMPAT(inst)` in the call to I3C_TARGET_DT_DEFINE().
     177              :  *
     178              :  * @param ... other parameters as expected by I3C_TARGET_DT_DEFINE().
     179              :  */
     180            1 : #define I3C_DEVICE_DT_INST_DEFINE(inst, ...)                            \
     181              :         I3C_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
     182              : 
     183              : /**
     184              :  * @brief Structure initializer for i3c_i2c_device_desc from devicetree
     185              :  *
     186              :  * This helper macro expands to a static initializer for a i3c_i2c_device_desc
     187              :  * by reading the relevant bus and device data from the devicetree.
     188              :  *
     189              :  * @param node_id Devicetree node identifier for the I3C device whose
     190              :  *                struct i3c_i2c_device_desc to create an initializer for
     191              :  */
     192            1 : #define I3C_I2C_DEVICE_DESC_DT(node_id)                                 \
     193              :         {                                                               \
     194              :                 .bus = DEVICE_DT_GET(DT_BUS(node_id)),                  \
     195              :                 .addr = DT_PROP_BY_IDX(node_id, reg, 0),                \
     196              :                 .lvr = DT_PROP_BY_IDX(node_id, reg, 2),                 \
     197              :         },
     198              : 
     199              : /**
     200              :  * @brief Structure initializer for i3c_i2c_device_desc from devicetree instance
     201              :  *
     202              :  * This is equivalent to
     203              :  * @code{.c}
     204              :  * I3C_I2C_DEVICE_DESC_DT(DT_DRV_INST(inst))
     205              :  * @endcode
     206              :  *
     207              :  * @param inst Devicetree instance number
     208              :  */
     209            1 : #define I3C_I2C_DEVICE_DESC_DT_INST(inst) \
     210              :         I3C_I2C_DEVICE_DESC_DT(DT_DRV_INST(inst))
     211              : 
     212              : 
     213              : /**
     214              :  * @brief Structure initializer for i3c_i2c_device_desc from devicetree
     215              :  *
     216              :  * This is mainly used by I3C_I2C_DEVICE_ARRAY_DT() to only
     217              :  * create a struct if and only if it is an I2C device.
     218              :  */
     219            1 : #define I3C_I2C_DEVICE_DESC_DT_FILTERED(node_id)                        \
     220              :         COND_CODE_0(DT_PROP_BY_IDX(node_id, reg, 1),                    \
     221              :                     (I3C_I2C_DEVICE_DESC_DT(node_id)), ())
     222              : 
     223              : /**
     224              :  * @brief Array initializer for a list of i3c_i2c_device_desc from devicetree
     225              :  *
     226              :  * This is a helper macro to generate an array for a list of
     227              :  * i3c_i2c_device_desc from device tree.
     228              :  *
     229              :  * @param node_id Devicetree node identifier of the I3C controller
     230              :  */
     231            1 : #define I3C_I2C_DEVICE_ARRAY_DT(node_id)                                \
     232              :         {                                                               \
     233              :                 DT_FOREACH_CHILD_STATUS_OKAY(                           \
     234              :                         node_id,                                        \
     235              :                         I3C_I2C_DEVICE_DESC_DT_FILTERED)                \
     236              :         }
     237              : 
     238              : /**
     239              :  * @brief Array initializer for a list of i3c_i2c_device_desc from devicetree instance
     240              :  *
     241              :  * This is equivalent to
     242              :  * @code{.c}
     243              :  * I3C_I2C_DEVICE_ARRAY_DT(DT_DRV_INST(inst))
     244              :  * @endcode
     245              :  *
     246              :  * @param inst Devicetree instance number of the I3C controller
     247              :  */
     248            1 : #define I3C_I2C_DEVICE_ARRAY_DT_INST(inst)                              \
     249              :         I3C_I2C_DEVICE_ARRAY_DT(DT_DRV_INST(inst))
     250              : 
     251              : #ifdef __cplusplus
     252              : }
     253              : #endif
     254              : 
     255              : /**
     256              :  * @}
     257              :  */
     258              : 
     259              : #endif /* ZEPHYR_INCLUDE_DRIVERS_I3C_DEVICETREE_H_ */
        

Generated by: LCOV version 2.0-1