Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
i3c.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Intel Corporation
3 * Copyright 2023 Meta Platforms, Inc. and its affiliates
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_INCLUDE_DRIVERS_I3C_H_
9#define ZEPHYR_INCLUDE_DRIVERS_I3C_H_
10
20#include <errno.h>
21#include <stdint.h>
22#include <stddef.h>
23
24#include <zephyr/device.h>
30#include <zephyr/drivers/i2c.h>
31#include <zephyr/sys/slist.h>
32#include <zephyr/sys/util.h>
33#include <zephyr/rtio/rtio.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
86#define I3C_BCR_MAX_DATA_SPEED_LIMIT BIT(0)
87
89#define I3C_BCR_IBI_REQUEST_CAPABLE BIT(1)
90
98#define I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE BIT(2)
99
106#define I3C_BCR_OFFLINE_CAPABLE BIT(3)
107
114#define I3C_BCR_VIRTUAL_TARGET BIT(4)
115
123#define I3C_BCR_ADV_CAPABILITIES BIT(5)
124
126#define I3C_BCR_DEVICE_ROLE_I3C_TARGET 0U
127
129#define I3C_BCR_DEVICE_ROLE_I3C_CONTROLLER_CAPABLE 1U
130
132#define I3C_BCR_DEVICE_ROLE_MASK GENMASK(7U, 6U)
133
141#define I3C_BCR_DEVICE_ROLE(bcr) \
142 FIELD_GET(I3C_BCR_DEVICE_ROLE_MASK, (bcr))
143
167#define I3C_LVR_I2C_FM_PLUS_MODE 0
168
170#define I3C_LVR_I2C_FM_MODE 1
171
173#define I3C_LVR_I2C_MODE_MASK BIT(4)
174
182#define I3C_LVR_I2C_MODE(lvr) \
183 FIELD_GET(I3C_LVR_I2C_MODE_MASK, (lvr))
184
191#define I3C_LVR_I2C_DEV_IDX_0 0
192
199#define I3C_LVR_I2C_DEV_IDX_1 1
200
207#define I3C_LVR_I2C_DEV_IDX_2 2
208
210#define I3C_LVR_I2C_DEV_IDX_MASK GENMASK(7U, 5U)
211
219#define I3C_LVR_I2C_DEV_IDX(lvr) \
220 FIELD_GET(I3C_LVR_I2C_DEV_IDX_MASK, (lvr))
221
254
270
295
302/*
303 * I3C_MSG_* are I3C Message flags.
304 */
305
307#define I3C_MSG_WRITE (0U << 0U)
308
310#define I3C_MSG_READ BIT(0)
311
313#define I3C_MSG_RW_MASK BIT(0)
317#define I3C_MSG_STOP BIT(1)
318
328#define I3C_MSG_RESTART BIT(2)
329
331#define I3C_MSG_HDR BIT(3)
332
334#define I3C_MSG_NBCH BIT(4)
335
337#define I3C_MSG_HDR_MODE0 BIT(0)
338
340#define I3C_MSG_HDR_MODE1 BIT(1)
341
343#define I3C_MSG_HDR_MODE2 BIT(2)
344
346#define I3C_MSG_HDR_MODE3 BIT(3)
347
349#define I3C_MSG_HDR_MODE4 BIT(4)
350
352#define I3C_MSG_HDR_MODE5 BIT(5)
353
355#define I3C_MSG_HDR_MODE6 BIT(6)
356
358#define I3C_MSG_HDR_MODE7 BIT(7)
359
361#define I3C_MSG_HDR_DDR I3C_MSG_HDR_MODE0
362
364#define I3C_MSG_HDR_TSP I3C_MSG_HDR_MODE1
365
367#define I3C_MSG_HDR_TSL I3C_MSG_HDR_MODE2
368
370#define I3C_MSG_HDR_BT I3C_MSG_HDR_MODE3
371
431
442
469
481
482 union {
485
492 void *ptr;
493 };
494};
495
502struct i3c_device_desc;
503struct i3c_device_id;
505struct i3c_target_config;
506struct i3c_config_target;
507
508__subsystem struct i3c_driver_api {
518 struct i2c_driver_api i2c_api;
519
532 int (*configure)(const struct device *dev,
533 enum i3c_config_type type, void *config);
534
547 int (*config_get)(const struct device *dev,
548 enum i3c_config_type type, void *config);
549#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
561 int (*recover_bus)(const struct device *dev);
562
575 int (*attach_i3c_device)(const struct device *dev,
576 struct i3c_device_desc *target);
577
591 int (*reattach_i3c_device)(const struct device *dev,
592 struct i3c_device_desc *target,
593 uint8_t old_dyn_addr);
594
607 int (*detach_i3c_device)(const struct device *dev,
608 struct i3c_device_desc *target);
609
622 int (*attach_i2c_device)(const struct device *dev,
623 struct i3c_i2c_device_desc *target);
624
637 int (*detach_i2c_device)(const struct device *dev,
638 struct i3c_i2c_device_desc *target);
639
651 int (*do_daa)(const struct device *dev);
652
665 int (*do_ccc)(const struct device *dev,
666 struct i3c_ccc_payload *payload);
667
680 int (*i3c_xfers)(const struct device *dev,
681 struct i3c_device_desc *target,
682 struct i3c_msg *msgs,
683 uint8_t num_msgs);
684
698 struct i3c_device_desc *(*i3c_device_find)(const struct device *dev,
699 const struct i3c_device_id *id);
700#endif /* CONFIG_I3C_CONTROLLER */
701#ifdef CONFIG_I3C_USE_IBI
702#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
715 int (*ibi_raise)(const struct device *dev,
716 struct i3c_ibi *request);
717#endif /* CONFIG_I3C_TARGET */
718#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
729 int (*ibi_hj_response)(const struct device *dev,
730 bool ack);
731
744 int (*ibi_enable)(const struct device *dev,
745 struct i3c_device_desc *target);
746
759 int (*ibi_disable)(const struct device *dev,
760 struct i3c_device_desc *target);
761#endif /* CONFIG_I3C_CONTROLLER */
762#endif /* CONFIG_I3C_USE_IBI */
763#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
779 int (*target_register)(const struct device *dev,
780 struct i3c_target_config *cfg);
781
797 int (*target_unregister)(const struct device *dev,
798 struct i3c_target_config *cfg);
799
816 int (*target_tx_write)(const struct device *dev,
817 uint8_t *buf, uint16_t len, uint8_t hdr_mode);
818
834 int (*target_controller_handoff)(const struct device *dev,
835 bool accept);
836#endif /* CONFIG_I3C_TARGET */
837#if defined(CONFIG_I3C_RTIO) || defined(__DOXYGEN__)
848 void (*iodev_submit)(const struct device *dev,
849 struct rtio_iodev_sqe *iodev_sqe);
850#endif /* CONFIG_I3C_RTIO */
851};
852
863};
864
873#define I3C_DEVICE_ID(pid) \
874 { \
875 .pid = pid \
876 }
877
896
898 const struct device *bus;
899
901 const struct device *dev;
902
905
919
930
939
954
960
968
969 struct {
972
975
979
980 struct {
983
986
990
993
995 struct {
996 union {
1005
1015 };
1016
1025
1038
1045
1046 /* Describes Controller Feature Capabilities */
1047 struct {
1056
1067
1072 void *controller_priv;
1075#if defined(CONFIG_I3C_USE_IBI) || defined(__DOXYGEN__)
1081#endif /* CONFIG_I3C_USE_IBI */
1082};
1083
1099
1101 const struct device *bus;
1102
1105
1111
1116 void *controller_priv;
1118};
1119
1149
1162 struct i3c_device_desc * const i3c;
1163
1167 struct i3c_i2c_device_desc * const i2c;
1168
1173
1178};
1179
1186#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1189
1192#elif defined(CONFIG_CPP)
1193 /* Empty struct has size 0 in C, size 1 in C++. Force them to be the same. */
1194 uint8_t unused_cpp_size_compatibility;
1195#endif
1196};
1197
1198#if defined(CONFIG_CPP)
1199BUILD_ASSERT(sizeof(struct i3c_driver_config) >= 1);
1200#endif
1201
1209#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1212#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
1215
1218#endif /* CONFIG_I3C_TARGET */
1219#endif /* CONFIG_I3C_CONTROLLER */
1220};
1221#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1229#define I3C_BUS_FOR_EACH_I3CDEV(bus, desc) \
1230 SYS_SLIST_FOR_EACH_CONTAINER( \
1231 &((struct i3c_driver_data *)(bus->data))->attached_dev.devices.i3c, desc, node)
1232
1240#define I3C_BUS_FOR_EACH_I2CDEV(bus, desc) \
1241 SYS_SLIST_FOR_EACH_CONTAINER( \
1242 &((struct i3c_driver_data *)(bus->data))->attached_dev.devices.i2c, desc, node)
1243
1256struct i3c_device_desc *i3c_dev_list_find(const struct i3c_dev_list *dev_list,
1257 const struct i3c_device_id *id);
1258
1272 uint8_t addr);
1273
1287 uint8_t addr);
1288
1302 uint16_t addr);
1303
1356 const struct i3c_dev_list *dev_list,
1357 uint64_t pid, bool must_match,
1358 bool assigned_okay,
1359 struct i3c_device_desc **target,
1360 uint8_t *addr);
1361#endif /* CONFIG_I3C_CONTROLLER */
1375static inline int i3c_configure(const struct device *dev,
1376 enum i3c_config_type type, void *config)
1377{
1378 const struct i3c_driver_api *api =
1379 (const struct i3c_driver_api *)dev->api;
1380
1381 if (api->configure == NULL) {
1382 return -ENOSYS;
1383 }
1384
1385 return api->configure(dev, type, config);
1386}
1387#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1403static inline int i3c_configure_controller(const struct device *dev,
1404 struct i3c_config_controller *config)
1405{
1406 return i3c_configure(dev, I3C_CONFIG_CONTROLLER, config);
1407}
1408#endif /* CONFIG_I3C_CONTROLLER */
1409#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
1425static inline int i3c_configure_target(const struct device *dev,
1426 struct i3c_config_target *config)
1427{
1428 return i3c_configure(dev, I3C_CONFIG_TARGET, config);
1429}
1430#endif /* CONFIG_I3C_TARGET */
1451static inline int i3c_config_get(const struct device *dev,
1452 enum i3c_config_type type, void *config)
1453{
1454 const struct i3c_driver_api *api =
1455 (const struct i3c_driver_api *)dev->api;
1456
1457 if (api->config_get == NULL) {
1458 return -ENOSYS;
1459 }
1460
1461 return api->config_get(dev, type, config);
1462}
1463#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1479static inline int i3c_config_get_controller(const struct device *dev,
1480 struct i3c_config_controller *config)
1481{
1482 return i3c_config_get(dev, I3C_CONFIG_CONTROLLER, config);
1483}
1484#endif /* CONFIG_I3C_CONTROLLER */
1485#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
1501static inline int i3c_config_get_target(const struct device *dev,
1502 struct i3c_config_target *config)
1503{
1504 return i3c_config_get(dev, I3C_CONFIG_TARGET, config);
1505}
1506#endif /* CONFIG_I3C_TARGET */
1507#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1518static inline int i3c_recover_bus(const struct device *dev)
1519{
1520 const struct i3c_driver_api *api =
1521 (const struct i3c_driver_api *)dev->api;
1522
1523 if (api->recover_bus == NULL) {
1524 return -ENOSYS;
1525 }
1526
1527 return api->recover_bus(dev);
1528}
1529
1550
1575int i3c_reattach_i3c_device(struct i3c_device_desc *target, uint8_t old_dyn_addr);
1576
1597
1617
1636
1660static inline int i3c_do_daa(const struct device *dev)
1661{
1662 const struct i3c_driver_api *api =
1663 (const struct i3c_driver_api *)dev->api;
1664
1665 if (api->do_daa == NULL) {
1666 return -ENOSYS;
1667 }
1668
1669 return api->do_daa(dev);
1670}
1671
1685__syscall int i3c_do_ccc(const struct device *dev,
1686 struct i3c_ccc_payload *payload);
1687
1688static inline int z_impl_i3c_do_ccc(const struct device *dev,
1689 struct i3c_ccc_payload *payload)
1690{
1691 const struct i3c_driver_api *api =
1692 (const struct i3c_driver_api *)dev->api;
1693
1694 if (api->do_ccc == NULL) {
1695 return -ENOSYS;
1696 }
1697
1698 return api->do_ccc(dev, payload);
1699}
1700
1732__syscall int i3c_transfer(struct i3c_device_desc *target,
1733 struct i3c_msg *msgs, uint8_t num_msgs);
1734
1735static inline int z_impl_i3c_transfer(struct i3c_device_desc *target,
1736 struct i3c_msg *msgs, uint8_t num_msgs)
1737{
1738 const struct i3c_driver_api *api =
1739 (const struct i3c_driver_api *)target->bus->api;
1740
1741 return api->i3c_xfers(target->bus, target, msgs, num_msgs);
1742}
1743
1760static inline
1762 const struct i3c_device_id *id)
1763{
1764 const struct i3c_driver_api *api =
1765 (const struct i3c_driver_api *)dev->api;
1766
1767 if (api->i3c_device_find == NULL) {
1768 return NULL;
1769 }
1770
1771 return api->i3c_device_find(dev, id);
1772}
1773#endif /* CONFIG_I3C_CONTROLLER */
1774#if defined(CONFIG_I3C_USE_IBI) || defined(__DOXYGEN__)
1780#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1793static inline int i3c_ibi_hj_response(const struct device *dev,
1794 bool ack)
1795{
1796 const struct i3c_driver_api *api =
1797 (const struct i3c_driver_api *)dev->api;
1798
1799 if (api->ibi_hj_response == NULL) {
1800 return -ENOSYS;
1801 }
1802
1803 return api->ibi_hj_response(dev, ack);
1804}
1805#endif /* CONFIG_I3C_CONTROLLER */
1806#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
1818static inline int i3c_ibi_raise(const struct device *dev,
1819 struct i3c_ibi *request)
1820{
1821 const struct i3c_driver_api *api =
1822 (const struct i3c_driver_api *)dev->api;
1823
1824 if (api->ibi_raise == NULL) {
1825 return -ENOSYS;
1826 }
1827
1828 return api->ibi_raise(dev, request);
1829}
1830#endif /* CONFIG_I3C_TARGET */
1831#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1846static inline int i3c_ibi_enable(struct i3c_device_desc *target)
1847{
1848 const struct i3c_driver_api *api =
1849 (const struct i3c_driver_api *)target->bus->api;
1850
1851 if (api->ibi_enable == NULL) {
1852 return -ENOSYS;
1853 }
1854
1855 return api->ibi_enable(target->bus, target);
1856}
1857
1870static inline int i3c_ibi_disable(struct i3c_device_desc *target)
1871{
1872 const struct i3c_driver_api *api =
1873 (const struct i3c_driver_api *)target->bus->api;
1874
1875 if (api->ibi_disable == NULL) {
1876 return -ENOSYS;
1877 }
1878
1879 return api->ibi_disable(target->bus, target);
1880}
1881#endif /* CONFIG_I3C_CONTROLLER */
1882#endif /* CONFIG_I3C_USE_IBI */
1894static inline int i3c_ibi_has_payload(struct i3c_device_desc *target)
1895{
1896 return (target->bcr & I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE)
1898}
1899
1911static inline int i3c_device_is_ibi_capable(struct i3c_device_desc *target)
1912{
1913 return (target->bcr & I3C_BCR_IBI_REQUEST_CAPABLE)
1915}
1916
1928static inline int i3c_device_is_controller_capable(struct i3c_device_desc *target)
1929{
1930 return I3C_BCR_DEVICE_ROLE(target->bcr)
1932}
1933
1935#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
1954static inline int i3c_write(struct i3c_device_desc *target,
1955 const uint8_t *buf, uint32_t num_bytes)
1956{
1957 struct i3c_msg msg;
1958
1959 msg.buf = (uint8_t *)buf;
1960 msg.len = num_bytes;
1962 msg.hdr_mode = 0;
1963 msg.hdr_cmd_code = 0;
1964
1965 return i3c_transfer(target, &msg, 1);
1966}
1967
1981static inline int i3c_read(struct i3c_device_desc *target,
1982 uint8_t *buf, uint32_t num_bytes)
1983{
1984 struct i3c_msg msg;
1985
1986 msg.buf = buf;
1987 msg.len = num_bytes;
1989 msg.hdr_mode = 0;
1990 msg.hdr_cmd_code = 0;
1991
1992 return i3c_transfer(target, &msg, 1);
1993}
1994
2012static inline int i3c_write_read(struct i3c_device_desc *target,
2013 const void *write_buf, size_t num_write,
2014 void *read_buf, size_t num_read)
2015{
2016 struct i3c_msg msg[2];
2017
2018 msg[0].buf = (uint8_t *)write_buf;
2019 msg[0].len = num_write;
2020 msg[0].flags = I3C_MSG_WRITE;
2021 msg[0].hdr_mode = 0;
2022 msg[0].hdr_cmd_code = 0;
2023
2024 msg[1].buf = (uint8_t *)read_buf;
2025 msg[1].len = num_read;
2027 msg[1].hdr_mode = 0;
2028 msg[1].hdr_cmd_code = 0;
2029
2030 return i3c_transfer(target, msg, 2);
2031}
2032
2050static inline int i3c_burst_read(struct i3c_device_desc *target,
2051 uint8_t start_addr,
2052 uint8_t *buf,
2053 uint32_t num_bytes)
2054{
2055 return i3c_write_read(target,
2056 &start_addr, sizeof(start_addr),
2057 buf, num_bytes);
2058}
2059
2080static inline int i3c_burst_write(struct i3c_device_desc *target,
2081 uint8_t start_addr,
2082 const uint8_t *buf,
2083 uint32_t num_bytes)
2084{
2085 struct i3c_msg msg[2];
2086
2087 msg[0].buf = &start_addr;
2088 msg[0].len = 1U;
2089 msg[0].flags = I3C_MSG_WRITE;
2090 msg[0].hdr_mode = 0;
2091 msg[0].hdr_cmd_code = 0;
2092
2093 msg[1].buf = (uint8_t *)buf;
2094 msg[1].len = num_bytes;
2095 msg[1].flags = I3C_MSG_WRITE | I3C_MSG_STOP;
2096 msg[1].hdr_mode = 0;
2097 msg[1].hdr_cmd_code = 0;
2098
2099 return i3c_transfer(target, msg, 2);
2100}
2101
2116static inline int i3c_reg_read_byte(struct i3c_device_desc *target,
2117 uint8_t reg_addr, uint8_t *value)
2118{
2119 return i3c_write_read(target,
2120 &reg_addr, sizeof(reg_addr),
2121 value, sizeof(*value));
2122}
2123
2141static inline int i3c_reg_write_byte(struct i3c_device_desc *target,
2142 uint8_t reg_addr, uint8_t value)
2143{
2144 uint8_t tx_buf[2] = {reg_addr, value};
2145
2146 return i3c_write(target, tx_buf, 2);
2147}
2148
2167static inline int i3c_reg_update_byte(struct i3c_device_desc *target,
2168 uint8_t reg_addr, uint8_t mask,
2169 uint8_t value)
2170{
2171 uint8_t old_value, new_value;
2172 int rc;
2173
2174 rc = i3c_reg_read_byte(target, reg_addr, &old_value);
2175 if (rc != 0) {
2176 return rc;
2177 }
2178
2179 new_value = (old_value & ~mask) | (value & mask);
2180 if (new_value == old_value) {
2181 return 0;
2182 }
2183
2184 return i3c_reg_write_byte(target, reg_addr, new_value);
2185}
2186
2211void i3c_dump_msgs(const char *name, const struct i3c_msg *msgs,
2212 uint8_t num_msgs, struct i3c_device_desc *target);
2213
2231int i3c_bus_init(const struct device *dev,
2232 const struct i3c_dev_list *i3c_dev_list);
2233
2252
2276
2298static inline int i3c_device_info_get(struct i3c_device_desc *target)
2299{
2300 int rc;
2301
2302 rc = i3c_device_basic_info_get(target);
2303 if (rc != 0) {
2304 return rc;
2305 }
2306
2307 return i3c_device_adv_info_get(target);
2308}
2309
2320bool i3c_bus_has_sec_controller(const struct device *dev);
2321
2333int i3c_bus_deftgts(const struct device *dev);
2334
2345
2360int i3c_device_controller_handoff(const struct i3c_device_desc *target, bool requested);
2361#endif /* CONFIG_I3C_CONTROLLER */
2362
2363#if defined(CONFIG_I3C_USE_IBI) || defined(__DOXYGEN__)
2364#if (defined(CONFIG_I3C_CONTROLLER) && defined(CONFIG_I3C_TARGET)) || defined(__DOXYGEN__)
2376void i3c_sec_handoffed(struct k_work *work);
2377#endif /* CONFIG_I3C_CONTROLLER && CONFIG_I3C_TARGET */
2378#endif /* CONFIG_I3C_USE_IBI */
2379
2380#if (defined(CONFIG_I3C_NUM_OF_DESC_MEM_SLABS) && CONFIG_I3C_NUM_OF_DESC_MEM_SLABS > 0) || \
2381 defined(__DOXYGEN__)
2382
2392
2401
2412
2413#else
2414
2415static inline struct i3c_device_desc *i3c_device_desc_alloc(void)
2416{
2417 return NULL;
2418}
2419
2420static inline void i3c_device_desc_free(struct i3c_device_desc *desc)
2421{
2422 ARG_UNUSED(desc);
2423}
2424
2425static inline bool i3c_device_desc_in_pool(struct i3c_device_desc *desc)
2426{
2427 ARG_UNUSED(desc);
2428 return false;
2429}
2430
2431#endif /* CONFIG_I3C_NUM_OF_DESC_MEM_SLABS > 0 */
2432
2433#if (defined(CONFIG_I3C_I2C_NUM_OF_DESC_MEM_SLABS) && CONFIG_I3C_I2C_NUM_OF_DESC_MEM_SLABS > 0) || \
2434 defined(__DOXYGEN__)
2435
2445
2454
2465
2466#else
2467
2468static inline struct i3c_i2c_device_desc *i3c_i2c_device_desc_alloc(void)
2469{
2470 return NULL;
2471}
2472
2473static inline void i3c_i2c_device_desc_free(struct i3c_i2c_device_desc *desc)
2474{
2475 ARG_UNUSED(desc);
2476}
2477
2478static inline bool i3c_i2c_device_desc_in_pool(struct i3c_i2c_device_desc *desc)
2479{
2480 ARG_UNUSED(desc);
2481 return false;
2482}
2483
2484#endif /* CONFIG_I3C_I2C_NUM_OF_DESC_MEM_SLABS > 0 */
2485
2486#if defined(CONFIG_I3C_RTIO) || defined(__DOXYGEN__)
2487
2489 const struct device *bus;
2490 const struct i3c_device_id dev_id;
2491};
2492
2503void i3c_iodev_submit_fallback(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe);
2504
2511static inline void i3c_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
2512{
2513 const struct i3c_iodev_data *data =
2514 (const struct i3c_iodev_data *)iodev_sqe->sqe.iodev->data;
2515 const struct i3c_driver_api *api = (const struct i3c_driver_api *)data->bus->api;
2516
2517 if (api->iodev_submit == NULL) {
2518 rtio_iodev_sqe_err(iodev_sqe, -ENOSYS);
2519 return;
2520 }
2521 api->iodev_submit(data->bus, iodev_sqe);
2522}
2523
2524extern const struct rtio_iodev_api i3c_iodev_api;
2525
2535#define I3C_DT_IODEV_DEFINE(name, node_id) \
2536 const struct i3c_iodev_data _i3c_iodev_data_##name = { \
2537 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
2538 .dev_id = I3C_DEVICE_ID_DT(node_id), \
2539 }; \
2540 RTIO_IODEV_DEFINE(name, &i3c_iodev_api, (void *)&_i3c_iodev_data_##name)
2541
2554 struct rtio_iodev *iodev,
2555 const struct i3c_msg *msgs,
2556 uint8_t num_msgs);
2557
2558#endif /* CONFIG_I3C_RTIO */
2559
2560#if defined(CONFIG_I3C_TARGET) || defined(__DOXYGEN__)
2561/*
2562 * This needs to be after declaration of struct i3c_driver_api,
2563 * or else compiler complains about undefined type inside
2564 * the static inline API wrappers.
2565 */
2567#endif /* CONFIG_I3C_TARGET */
2568
2569#if defined(CONFIG_I3C_CONTROLLER) || defined(__DOXYGEN__)
2570/*
2571 * Include High-Data-Rate (HDR) inline helper functions
2572 */
2574#endif /* CONFIG_I3C_CONTROLLER */
2575
2576#ifdef __cplusplus
2577}
2578#endif
2579
2584#include <zephyr/syscalls/i3c.h>
2585
2586#endif /* ZEPHYR_INCLUDE_DRIVERS_I3C_H_ */
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:24
Public APIs for the I2C drivers.
System error numbers.
i3c_sdr_controller_error_types
I3C SDR Controller Error Types.
Definition error_types.h:24
static int i3c_ibi_disable(struct i3c_device_desc *target)
Disable IBI of a target device.
Definition i3c.h:1870
static int i3c_ibi_has_payload(struct i3c_device_desc *target)
Check if target's IBI has payload.
Definition i3c.h:1894
static int i3c_ibi_raise(const struct device *dev, struct i3c_ibi *request)
Raise an In-Band Interrupt (IBI).
Definition i3c.h:1818
static int i3c_device_is_controller_capable(struct i3c_device_desc *target)
Check if the target is controller capable.
Definition i3c.h:1928
static int i3c_device_is_ibi_capable(struct i3c_device_desc *target)
Check if device is IBI capable.
Definition i3c.h:1911
static int i3c_ibi_enable(struct i3c_device_desc *target)
Enable IBI of a target device.
Definition i3c.h:1846
int(* i3c_target_ibi_cb_t)(struct i3c_device_desc *target, struct i3c_ibi_payload *payload)
Function called when In-Band Interrupt received from target device.
Definition ibi.h:146
static int i3c_ibi_hj_response(const struct device *dev, bool ack)
ACK or NACK IBI HJ Requests.
Definition i3c.h:1793
int i3c_attach_i3c_device(struct i3c_device_desc *target)
Attach an I3C device.
#define I3C_BCR_IBI_REQUEST_CAPABLE
IBI Request Capable bit.
Definition i3c.h:89
#define I3C_BCR_DEVICE_ROLE_I3C_CONTROLLER_CAPABLE
Device Role - I3C Controller Capable.
Definition i3c.h:129
struct i3c_device_desc * i3c_dev_list_i3c_addr_find(const struct device *dev, uint8_t addr)
Find a I3C target device descriptor by dynamic address.
static struct i3c_device_desc * i3c_device_find(const struct device *dev, const struct i3c_device_id *id)
Find a registered I3C target device.
Definition i3c.h:1761
bool i3c_bus_has_sec_controller(const struct device *dev)
Check if the bus has a secondary controller.
struct i3c_i2c_device_desc * i3c_i2c_device_desc_alloc(void)
Allocate memory for a i3c i2c device descriptor.
void i3c_sec_handoffed(struct k_work *work)
Call back for when Controllership is Handoffed to itself.
int i3c_device_controller_handoff(const struct i3c_device_desc *target, bool requested)
Perform Controller Handoff.
void i3c_device_desc_free(struct i3c_device_desc *desc)
Free memory from a i3c device descriptor.
static int i3c_configure(const struct device *dev, enum i3c_config_type type, void *config)
Configure the I3C hardware.
Definition i3c.h:1375
static int i3c_device_info_get(struct i3c_device_desc *target)
Get all information from device and update device descriptor.
Definition i3c.h:2298
int i3c_dev_list_daa_addr_helper(struct i3c_addr_slots *addr_slots, const struct i3c_dev_list *dev_list, uint64_t pid, bool must_match, bool assigned_okay, struct i3c_device_desc **target, uint8_t *addr)
Helper function to find a usable address during ENTDAA.
static void i3c_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit request(s) to an I3C device with RTIO.
Definition i3c.h:2511
int i3c_device_adv_info_get(struct i3c_device_desc *target)
Get advanced information from device and update device descriptor.
int i3c_bus_deftgts(const struct device *dev)
Send the CCC DEFTGTS.
i3c_config_type
Type of configuration being passed to configure function.
Definition i3c.h:437
int i3c_attach_i2c_device(struct i3c_i2c_device_desc *target)
Attach an I2C device.
void i3c_i2c_device_desc_free(struct i3c_i2c_device_desc *desc)
Free memory from a i3c i2c device descriptor.
i3c_i2c_speed_type
I2C bus speed under I3C bus.
Definition i3c.h:260
int i3c_detach_i3c_device(struct i3c_device_desc *target)
Detach I3C Device.
i3c_bus_mode
I3C bus mode.
Definition i3c.h:227
static int i3c_recover_bus(const struct device *dev)
Attempt bus recovery on the I3C bus.
Definition i3c.h:1518
static int i3c_configure_target(const struct device *dev, struct i3c_config_target *config)
Get the target device configuration for an I3C device.
Definition i3c.h:1425
static int i3c_config_get(const struct device *dev, enum i3c_config_type type, void *config)
Get configuration of the I3C hardware.
Definition i3c.h:1451
int i3c_detach_i2c_device(struct i3c_i2c_device_desc *target)
Detach I2C Device.
static int i3c_config_get_target(const struct device *dev, struct i3c_config_target *config)
Get the target device configuration for an I3C device.
Definition i3c.h:1501
#define I3C_BCR_DEVICE_ROLE(bcr)
Device Role.
Definition i3c.h:141
void i3c_iodev_submit_fallback(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
Fallback submit implementation.
static int i3c_config_get_controller(const struct device *dev, struct i3c_config_controller *config)
Get the controller device configuration for an I3C device.
Definition i3c.h:1479
struct i3c_device_desc * i3c_dev_list_find(const struct i3c_dev_list *dev_list, const struct i3c_device_id *id)
Find a I3C target device descriptor by ID.
int i3c_bus_init(const struct device *dev, const struct i3c_dev_list *i3c_dev_list)
Generic helper function to perform bus initialization.
int i3c_do_ccc(const struct device *dev, struct i3c_ccc_payload *payload)
Send CCC to the bus.
int i3c_device_basic_info_get(struct i3c_device_desc *target)
Get basic information from device and update device descriptor.
uint8_t i3c_odd_parity(uint8_t p)
Calculate odd parity.
struct rtio_sqe * i3c_rtio_copy(struct rtio *r, struct rtio_iodev *iodev, const struct i3c_msg *msgs, uint8_t num_msgs)
Copy the i3c_msgs into a set of RTIO requests.
struct i3c_device_desc * i3c_device_desc_alloc(void)
Allocate memory for a i3c device descriptor.
static int i3c_do_daa(const struct device *dev)
Perform Dynamic Address Assignment on the I3C bus.
Definition i3c.h:1660
bool i3c_i2c_device_desc_in_pool(struct i3c_i2c_device_desc *desc)
Report if the i3c i2c device descriptor was from a mem slab.
const struct rtio_iodev_api i3c_iodev_api
#define I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE
IBI Payload bit.
Definition i3c.h:98
int i3c_reattach_i3c_device(struct i3c_device_desc *target, uint8_t old_dyn_addr)
Reattach I3C device.
i3c_data_rate
I3C data rate.
Definition i3c.h:276
static int i3c_configure_controller(const struct device *dev, struct i3c_config_controller *config)
Get the controller device configuration for an I3C device.
Definition i3c.h:1403
struct i3c_device_desc * i3c_dev_list_i3c_static_addr_find(const struct device *dev, uint8_t addr)
Find a I3C target device descriptor by static address.
bool i3c_device_desc_in_pool(struct i3c_device_desc *desc)
Report if the i3c device descriptor was from a mem slab.
struct i3c_i2c_device_desc * i3c_dev_list_i2c_addr_find(const struct device *dev, uint16_t addr)
Find a I2C target device descriptor by address.
@ I3C_CONFIG_TARGET
Definition i3c.h:439
@ I3C_CONFIG_CUSTOM
Definition i3c.h:440
@ I3C_CONFIG_CONTROLLER
Definition i3c.h:438
@ I3C_I2C_SPEED_INVALID
Definition i3c.h:268
@ I3C_I2C_SPEED_MAX
Definition i3c.h:267
@ I3C_I2C_SPEED_FMPLUS
I2C FM+ mode.
Definition i3c.h:265
@ I3C_I2C_SPEED_FM
I2C FM mode.
Definition i3c.h:262
@ I3C_BUS_MODE_INVALID
Definition i3c.h:252
@ I3C_BUS_MODE_PURE
Only I3C devices are on the bus.
Definition i3c.h:229
@ I3C_BUS_MODE_MIXED_FAST
Both I3C and legacy I2C devices are on the bus.
Definition i3c.h:235
@ I3C_BUS_MODE_MAX
Definition i3c.h:251
@ I3C_BUS_MODE_MIXED_LIMITED
Both I3C and legacy I2C devices are on the bus.
Definition i3c.h:242
@ I3C_BUS_MODE_MIXED_SLOW
Both I3C and legacy I2C devices are on the bus.
Definition i3c.h:249
@ I3C_DATA_RATE_MAX
Definition i3c.h:292
@ I3C_DATA_RATE_INVALID
Definition i3c.h:293
@ I3C_DATA_RATE_HDR_TSP
High Data Rate - Ternary Symbol for Pure Bus.
Definition i3c.h:287
@ I3C_DATA_RATE_HDR_DDR
High Data Rate - Double Data Rate messaging.
Definition i3c.h:281
@ I3C_DATA_RATE_SDR
Single Data Rate messaging.
Definition i3c.h:278
@ I3C_DATA_RATE_HDR_TSL
High Data Rate - Ternary Symbol Legacy-inclusive-Bus.
Definition i3c.h:284
@ I3C_DATA_RATE_HDR_BT
High Data Rate - Bulk Transport.
Definition i3c.h:290
int i3c_transfer(struct i3c_device_desc *target, struct i3c_msg *msgs, uint8_t num_msgs)
Perform data transfer from the controller to a I3C target device.
#define I3C_MSG_STOP
Send STOP after this message.
Definition i3c.h:317
static int i3c_write_read(struct i3c_device_desc *target, const void *write_buf, size_t num_write, void *read_buf, size_t num_read)
Write then read data from an I3C target device.
Definition i3c.h:2012
static int i3c_burst_read(struct i3c_device_desc *target, uint8_t start_addr, uint8_t *buf, uint32_t num_bytes)
Read multiple bytes from an internal address of an I3C target device.
Definition i3c.h:2050
static int i3c_reg_update_byte(struct i3c_device_desc *target, uint8_t reg_addr, uint8_t mask, uint8_t value)
Update internal register of an I3C target device.
Definition i3c.h:2167
void i3c_dump_msgs(const char *name, const struct i3c_msg *msgs, uint8_t num_msgs, struct i3c_device_desc *target)
Dump out an I3C message.
#define I3C_MSG_READ
Read message from I3C bus.
Definition i3c.h:310
#define I3C_MSG_WRITE
Write message to I3C bus.
Definition i3c.h:307
static int i3c_reg_read_byte(struct i3c_device_desc *target, uint8_t reg_addr, uint8_t *value)
Read internal register of an I3C target device.
Definition i3c.h:2116
static int i3c_write(struct i3c_device_desc *target, const uint8_t *buf, uint32_t num_bytes)
Write a set amount of data to an I3C target device.
Definition i3c.h:1954
static int i3c_read(struct i3c_device_desc *target, uint8_t *buf, uint32_t num_bytes)
Read a set amount of data from an I3C target device.
Definition i3c.h:1981
#define I3C_MSG_RESTART
RESTART I3C transaction for this message.
Definition i3c.h:328
static int i3c_burst_write(struct i3c_device_desc *target, uint8_t start_addr, const uint8_t *buf, uint32_t num_bytes)
Write multiple bytes to an internal address of an I3C target device.
Definition i3c.h:2080
static int i3c_reg_write_byte(struct i3c_device_desc *target, uint8_t reg_addr, uint8_t value)
Write internal register of an I3C target device.
Definition i3c.h:2141
static void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submissions completion with error.
Definition rtio.h:1233
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
Real-Time IO device API for moving bytes with low effort.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510
Structure to keep track of addresses on I3C bus.
Definition addresses.h:58
Payload for DEFTGTS CCC (Define List of Targets).
Definition ccc.h:477
Payload structure for one CCC transaction.
Definition ccc.h:283
Configuration parameters for I3C hardware to act as controller.
Definition i3c.h:446
struct i3c_config_controller::@213 scl
uint32_t i3c
SCL frequency (in Hz) for I3C transfers.
Definition i3c.h:455
uint8_t supported_hdr
Bit mask of supported HDR modes (0 - 7).
Definition i3c.h:467
bool is_secondary
True if the controller is to be the secondary controller of the bus.
Definition i3c.h:451
uint32_t i2c
SCL frequency (in Hz) for I2C transfers.
Definition i3c.h:458
Custom I3C configuration parameters.
Definition i3c.h:478
void * ptr
Pointer to configuration parameter.
Definition i3c.h:492
uint32_t id
ID of the configuration parameter.
Definition i3c.h:480
uintptr_t val
Value of configuration parameter.
Definition i3c.h:484
Configuration parameters for I3C hardware to act as target device.
Definition target_device.h:36
Structure for describing attached devices for a controller.
Definition i3c.h:1128
sys_slist_t i3c
Linked list of attached I3C devices.
Definition i3c.h:1141
sys_slist_t i2c
Linked list of attached I2C devices.
Definition i3c.h:1146
struct i3c_addr_slots addr_slots
Address slots:
Definition i3c.h:1135
struct i3c_dev_attached_list::@222 devices
Structure for describing known devices for a controller.
Definition i3c.h:1158
struct i3c_i2c_device_desc *const i2c
Pointer to array of known I2C devices.
Definition i3c.h:1167
const uint8_t num_i3c
Number of I3C devices in array.
Definition i3c.h:1172
struct i3c_device_desc *const i3c
Pointer to array of known I3C devices.
Definition i3c.h:1162
const uint8_t num_i2c
Number of I2C devices in array.
Definition i3c.h:1177
Structure describing a I3C target device.
Definition i3c.h:894
uint8_t maxwr
Maximum Write Speed.
Definition i3c.h:974
const uint8_t init_dynamic_addr
Initial dynamic address.
Definition i3c.h:929
uint8_t getcap1
I3C v1.1+ GETCAPS1 (I3C_CCC_GETCAPS1_*)
Definition i3c.h:1014
uint8_t static_addr
Static address for this target device.
Definition i3c.h:918
uint8_t getcap2
GETCAPS2 (I3C_CCC_GETCAPS2_*)
Definition i3c.h:1024
uint8_t crcaps2
CRCAPS2.
Definition i3c.h:1065
uint32_t max_read_turnaround
Maximum Read turnaround time in microseconds.
Definition i3c.h:977
uint8_t getcap4
GETCAPS4.
Definition i3c.h:1043
uint64_t pid
Device Provisioned ID.
Definition i3c.h:904
uint8_t max_ibi
Maximum IBI Payload Size.
Definition i3c.h:988
i3c_target_ibi_cb_t ibi_cb
In-Band Interrupt (IBI) callback.
Definition i3c.h:1080
uint16_t mwl
Maximum Write Length.
Definition i3c.h:985
uint8_t crhdly1
Controller Handoff Delay Parameters.
Definition i3c.h:992
uint8_t getcap3
GETCAPS3 (I3C_CCC_GETCAPS3_*)
Definition i3c.h:1037
uint8_t dynamic_addr
Dynamic Address for this target device used for communication.
Definition i3c.h:953
uint8_t crcaps1
CRCAPS1.
Definition i3c.h:1055
const uint8_t flags
Device Flags.
Definition i3c.h:938
sys_snode_t node
Definition i3c.h:895
struct i3c_device_desc::@219 crcaps
const struct device * bus
I3C bus to which this target device is attached.
Definition i3c.h:898
struct i3c_device_desc::@217 data_length
uint16_t mrl
Maximum Read Length.
Definition i3c.h:982
uint8_t maxrd
Maximum Read Speed.
Definition i3c.h:971
struct i3c_device_desc::@218 getcaps
Describes advanced (Target) capabilities and features.
uint8_t gethdrcap
I3C v1.0 HDR Capabilities (I3C_CCC_GETCAPS1_*)
Definition i3c.h:1004
uint8_t bcr
Bus Characteristic Register (BCR)
Definition i3c.h:959
uint8_t dcr
Device Characteristic Register (DCR)
Definition i3c.h:967
struct i3c_device_desc::@216 data_speed
const struct device * dev
Device driver instance of the I3C device.
Definition i3c.h:901
Structure used for matching I3C devices.
Definition i3c.h:860
uint64_t pid
Device Provisioned ID.
Definition i3c.h:862
This structure is common to all I3C drivers and is expected to be the first element in the object poi...
Definition i3c.h:1185
uint8_t primary_controller_da
I3C Primary Controller Dynamic Address.
Definition i3c.h:1191
struct i3c_dev_list dev_list
I3C/I2C device list struct.
Definition i3c.h:1188
This structure is common to all I3C drivers and is expected to be the first element in the driver's s...
Definition i3c.h:1206
struct i3c_config_controller ctrl_config
Controller Configuration.
Definition i3c.h:1208
struct i3c_ccc_deftgts * deftgts
Received DEFTGTS Pointer.
Definition i3c.h:1214
bool deftgts_refreshed
DEFTGTS refreshed.
Definition i3c.h:1217
struct i3c_dev_attached_list attached_dev
Attached I3C/I2C devices and addresses.
Definition i3c.h:1211
Structure describing a I2C device on I3C bus.
Definition i3c.h:1097
const struct device * bus
I3C bus to which this I2C device is attached.
Definition i3c.h:1101
uint8_t lvr
Legacy Virtual Register (LVR)
Definition i3c.h:1110
uint16_t addr
Static address for this I2C device.
Definition i3c.h:1104
sys_snode_t node
Definition i3c.h:1098
Struct for IBI request.
Definition ibi.h:58
Definition i3c.h:2488
const struct device * bus
Definition i3c.h:2489
const struct i3c_device_id dev_id
Definition i3c.h:2490
One I3C Message.
Definition i3c.h:393
uint8_t flags
Flags for this message.
Definition i3c.h:418
uint8_t hdr_mode
HDR mode (I3C_MSG_HDR_MODE*) for transfer if any I3C_MSG_HDR_* is set in flags.
Definition i3c.h:426
uint32_t num_xfer
Total number of bytes transferred.
Definition i3c.h:407
uint8_t * buf
Data buffer in bytes.
Definition i3c.h:395
uint8_t hdr_cmd_code
HDR command code field (7-bit) for HDR-DDR, HDR-TSP and HDR-TSL.
Definition i3c.h:429
uint32_t len
Length of buffer in bytes.
Definition i3c.h:398
enum i3c_sdr_controller_error_types err
SDR Error Type.
Definition i3c.h:415
Structure describing a device that supports the I3C target API.
Definition target_device.h:102
A structure used to submit work.
Definition kernel.h:4035
API that an RTIO IO device should implement.
Definition rtio.h:502
Compute the mempool block index for a given pointer.
Definition rtio.h:492
struct rtio_sqe sqe
Definition rtio.h:493
An IO device with a function table for submitting requests.
Definition rtio.h:517
void * data
Definition rtio.h:522
A submission queue event.
Definition rtio.h:286
const struct rtio_iodev * iodev
Device to operation on.
Definition rtio.h:295
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:396
Misc utilities.