7#ifndef ZEPHYR_INCLUDE_DRIVERS_I3C_H_
8#define ZEPHYR_INCLUDE_DRIVERS_I3C_H_
59#define I3C_BCR_MAX_DATA_SPEED_LIMIT BIT(0)
60#define I3C_BCR_IBI_REQUEST_CAPABLE BIT(1)
61#define I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE BIT(2)
62#define I3C_BCR_OFFLINE_CAPABLE BIT(3)
63#define I3C_BCR_VIRTUAL_TARGET BIT(4)
64#define I3C_BCR_ADV_CAPABILITIES BIT(5)
66#define I3C_BCR_DEVICE_ROLE_I3C_TARGET 0U
67#define I3C_BCR_DEVICE_ROLE_I3C_CONTROLLER_CAPABLE 1U
69#define I3C_BCR_DEVICE_ROLE_SHIFT 6U
70#define I3C_BCR_DEVICE_ROLE_MASK (0x03U << I3C_BCR_DEVICE_ROLE_SHIFT)
72#define I3C_BCR_DEVICE_ROLE(bcr) \
73 (((bcr) & I3C_BCR_DEVICE_ROLE_MASK) >> I3C_BCR_DEVICE_ROLE_SHIFT)
89#define I3C_DCR_I2C_FM_PLUS_MODE 0
90#define I3C_DCR_I2C_FM_MODE 1
92#define I3C_DCR_I2C_MODE_SHIFT 4
93#define I3C_DCR_I2C_MODE_MASK BIT(4)
95#define I3C_DCR_I2C_MODE(dcr) \
96 (((mode) & I3C_DCR_I2C_MODE_MASK) >> I3C_DCR_I2C_MODE_SHIFT)
98#define I3C_DCR_I2C_DEV_IDX_0 0
99#define I3C_DCR_I2C_DEV_IDX_1 1
100#define I3C_DCR_I2C_DEV_IDX_2 2
102#define I3C_DCR_I2C_DEV_IDX_SHIFT 5
103#define I3C_DCR_I2C_DEV_IDX_MASK (0x07U << I3C_DCR_I2C_DEV_IDX_SHIFT)
105#define I3C_DCR_I2C_DEV_IDX(dcr) \
106 (((dcr) & I3C_DCR_I2C_DEV_IDX_MASK) >> I3C_DCR_I2C_DEV_IDX_SHIFT)
266#define I3C_MSG_WRITE (0U << 0U)
269#define I3C_MSG_READ BIT(0)
272#define I3C_MSG_RW_MASK BIT(0)
276#define I3C_MSG_STOP BIT(1)
287#define I3C_MSG_RESTART BIT(2)
290#define I3C_MSG_HDR BIT(3)
293#define I3C_MSG_NBCH BIT(4)
296#define I3C_MSG_HDR_MODE0 BIT(0)
299#define I3C_MSG_HDR_MODE1 BIT(1)
302#define I3C_MSG_HDR_MODE2 BIT(2)
305#define I3C_MSG_HDR_MODE3 BIT(3)
308#define I3C_MSG_HDR_MODE4 BIT(4)
311#define I3C_MSG_HDR_MODE5 BIT(5)
314#define I3C_MSG_HDR_MODE6 BIT(6)
317#define I3C_MSG_HDR_MODE7 BIT(7)
320#define I3C_MSG_HDR_DDR I3C_MSG_HDR_MODE0
323#define I3C_MSG_HDR_TSP I3C_MSG_HDR_MODE1
326#define I3C_MSG_HDR_TSL I3C_MSG_HDR_MODE2
329#define I3C_MSG_HDR_BT I3C_MSG_HDR_MODE3
437__subsystem
struct i3c_driver_api {
445 struct i2c_driver_api i2c_api;
459 int (*configure)(
const struct device *dev,
474 int (*config_get)(
const struct device *dev,
488 int (*recover_bus)(
const struct device *dev);
503 int (*attach_i3c_device)(
const struct device *dev,
520 int (*reattach_i3c_device)(
const struct device *dev,
536 int (*detach_i3c_device)(
const struct device *dev,
551 int (*attach_i2c_device)(
const struct device *dev,
566 int (*detach_i2c_device)(
const struct device *dev,
580 int (*do_daa)(
const struct device *dev);
594 int (*do_ccc)(
const struct device *dev,
609 int (*i3c_xfers)(
const struct device *dev,
642 int (*ibi_raise)(
const struct device *dev,
657 int (*ibi_enable)(
const struct device *dev,
672 int (*ibi_disable)(
const struct device *dev,
690 int (*target_register)(
const struct device *dev,
708 int (*target_unregister)(
const struct device *dev,
726 int (*target_tx_write)(
const struct device *dev,
750#define I3C_DEVICE_ID(pid) \
825#if defined(CONFIG_I3C_USE_GROUP_ADDR) || defined(__DOXYGEN__)
900#if defined(CONFIG_I3C_USE_IBI) || defined(__DOXYGEN__)
1167 const struct i3c_driver_api *api =
1168 (
const struct i3c_driver_api *)dev->
api;
1170 if (api->configure == NULL) {
1174 return api->configure(dev, type, config);
1200 const struct i3c_driver_api *api =
1201 (
const struct i3c_driver_api *)dev->
api;
1203 if (api->config_get == NULL) {
1207 return api->config_get(dev, type, config);
1222 const struct i3c_driver_api *api =
1223 (
const struct i3c_driver_api *)dev->
api;
1225 if (api->recover_bus == NULL) {
1229 return api->recover_bus(dev);
1364 const struct i3c_driver_api *api =
1365 (
const struct i3c_driver_api *)dev->
api;
1367 if (api->do_daa == NULL) {
1371 return api->do_daa(dev);
1390static inline int z_impl_i3c_do_ccc(
const struct device *dev,
1393 const struct i3c_driver_api *api =
1394 (
const struct i3c_driver_api *)dev->
api;
1396 if (api->do_ccc == NULL) {
1400 return api->do_ccc(dev, payload);
1435 const struct i3c_driver_api *api =
1436 (
const struct i3c_driver_api *)
target->bus->api;
1438 return api->i3c_xfers(
target->bus,
target, msgs, num_msgs);
1459 const struct i3c_driver_api *api =
1460 (
const struct i3c_driver_api *)dev->
api;
1462 if (api->i3c_device_find == NULL) {
1466 return api->i3c_device_find(dev,
id);
1483 const struct i3c_driver_api *api =
1484 (
const struct i3c_driver_api *)dev->
api;
1486 if (api->ibi_raise == NULL) {
1490 return api->ibi_raise(dev, request);
1509 const struct i3c_driver_api *api =
1510 (
const struct i3c_driver_api *)
target->bus->api;
1512 if (api->ibi_enable == NULL) {
1533 const struct i3c_driver_api *api =
1534 (
const struct i3c_driver_api *)
target->bus->api;
1536 if (api->ibi_disable == NULL) {
1596 msg.len = num_bytes;
1621 msg.len = num_bytes;
1645 const void *write_buf,
size_t num_write,
1646 void *read_buf,
size_t num_read)
1651 msg[0].len = num_write;
1655 msg[1].len = num_read;
1684 &start_addr,
sizeof(start_addr),
1715 msg[0].buf = &start_addr;
1720 msg[1].len = num_bytes;
1744 ®_addr,
sizeof(reg_addr),
1745 value,
sizeof(*value));
1768 uint8_t tx_buf[2] = {reg_addr, value};
1803 new_value = (old_value & ~mask) | (value & mask);
1804 if (new_value == old_value) {
1892#include <syscalls/i3c.h>
Public APIs for the I2C drivers.
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:148
static int i3c_ibi_disable(struct i3c_device_desc *target)
Disable IBI of a target device.
Definition: i3c.h:1531
int i3c_attach_i3c_device(struct i3c_device_desc *target)
Attach an I3C device.
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_BCR_IBI_REQUEST_CAPABLE
Definition: i3c.h:60
#define I3C_MSG_STOP
Definition: i3c.h:276
static struct i3c_device_desc * i3c_device_find(const struct device *dev, const struct i3c_device_id *id)
Definition: i3c.h:1456
static int i3c_ibi_has_payload(struct i3c_device_desc *target)
Check if target's IBI has payload.
Definition: i3c.h:1554
i3c_sdr_target_error_codes
I3C SDR Target Error Codes.
Definition: i3c.h:223
static int i3c_configure(const struct device *dev, enum i3c_config_type type, void *config)
Configure the I3C hardware.
Definition: i3c.h:1164
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 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:1644
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:1678
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:1791
static int i3c_ibi_raise(const struct device *dev, struct i3c_ibi *request)
Raise an In-Band Interrupt (IBI).
Definition: i3c.h:1480
i3c_config_type
Type of configuration being passed to configure function.
Definition: i3c.h:367
int i3c_attach_i2c_device(struct i3c_i2c_device_desc *target)
Attach an I2C device.
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.
int i3c_determine_default_addr(struct i3c_device_desc *target, uint8_t *addr)
Helper function to find the default address an i3c device is attached with.
i3c_i2c_speed_type
I2C bus speed under I3C bus.
Definition: i3c.h:144
#define I3C_MSG_READ
Definition: i3c.h:269
static int i3c_device_is_ibi_capable(struct i3c_device_desc *target)
Check if device is IBI capable.
Definition: i3c.h:1571
int i3c_detach_i3c_device(struct i3c_device_desc *target)
Detach I3C Device.
#define I3C_MSG_WRITE
Definition: i3c.h:266
static int i3c_ibi_enable(struct i3c_device_desc *target)
Enable IBI of a target device.
Definition: i3c.h:1507
i3c_bus_mode
I3C bus mode.
Definition: i3c.h:111
static int i3c_recover_bus(const struct device *dev)
Attempt bus recovery on the I3C bus.
Definition: i3c.h:1220
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:1197
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:1740
int i3c_detach_i2c_device(struct i3c_i2c_device_desc *target)
Detach I2C Device.
struct i3c_i2c_device_desc * i3c_dev_list_i2c_addr_find(struct i3c_dev_attached_list *dev_list, uint16_t addr)
Find a I2C target device descriptor by address.
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.
i3c_sdr_controller_error_codes
I3C SDR Controller Error Codes.
Definition: i3c.h:190
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:1590
int i3c_do_ccc(const struct device *dev, struct i3c_ccc_payload *payload)
Send CCC to the bus.
struct i3c_device_desc * i3c_dev_list_i3c_addr_find(struct i3c_dev_attached_list *dev_list, uint8_t addr)
Find a I3C target device descriptor by dynamic address.
int i3c_device_basic_info_get(struct i3c_device_desc *target)
Get basic information from device and update device descriptor.
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:1615
static int i3c_do_daa(const struct device *dev)
Perform Dynamic Address Assignment on the I3C bus.
Definition: i3c.h:1362
#define I3C_MSG_RESTART
Definition: i3c.h:287
#define I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE
Definition: i3c.h:61
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:160
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:1708
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:1765
@ I3C_ERROR_TE_UNKNOWN
Definition: i3c.h:252
@ I3C_ERROR_TE6
Definition: i3c.h:246
@ I3C_ERROR_TE4
Definition: i3c.h:240
@ I3C_ERROR_TE3
Definition: i3c.h:237
@ I3C_ERROR_TE_NONE
Definition: i3c.h:255
@ I3C_ERROR_TE_MAX
Definition: i3c.h:257
@ I3C_ERROR_TE1
Definition: i3c.h:231
@ I3C_ERROR_TE5
Definition: i3c.h:243
@ I3C_ERROR_DBR
Definition: i3c.h:249
@ I3C_ERROR_TE2
Definition: i3c.h:234
@ I3C_ERROR_TE_INVALID
Definition: i3c.h:258
@ I3C_ERROR_TE0
Definition: i3c.h:228
@ I3C_CONFIG_TARGET
Definition: i3c.h:369
@ I3C_CONFIG_CUSTOM
Definition: i3c.h:370
@ I3C_CONFIG_CONTROLLER
Definition: i3c.h:368
@ I3C_I2C_SPEED_INVALID
Definition: i3c.h:152
@ I3C_I2C_SPEED_MAX
Definition: i3c.h:151
@ I3C_I2C_SPEED_FMPLUS
Definition: i3c.h:149
@ I3C_I2C_SPEED_FM
Definition: i3c.h:146
@ I3C_BUS_MODE_INVALID
Definition: i3c.h:136
@ I3C_BUS_MODE_PURE
Definition: i3c.h:113
@ I3C_BUS_MODE_MIXED_FAST
Definition: i3c.h:119
@ I3C_BUS_MODE_MAX
Definition: i3c.h:135
@ I3C_BUS_MODE_MIXED_LIMITED
Definition: i3c.h:126
@ I3C_BUS_MODE_MIXED_SLOW
Definition: i3c.h:133
@ I3C_ERROR_CE0
Definition: i3c.h:192
@ I3C_ERROR_CE2
Definition: i3c.h:198
@ I3C_ERROR_CE_INVALID
Definition: i3c.h:210
@ I3C_ERROR_CE_MAX
Definition: i3c.h:209
@ I3C_ERROR_CE_UNKNOWN
Definition: i3c.h:204
@ I3C_ERROR_CE3
Definition: i3c.h:201
@ I3C_ERROR_CE1
Definition: i3c.h:195
@ I3C_ERROR_CE_NONE
Definition: i3c.h:207
@ I3C_DATA_RATE_MAX
Definition: i3c.h:176
@ I3C_DATA_RATE_INVALID
Definition: i3c.h:177
@ I3C_DATA_RATE_HDR_TSP
Definition: i3c.h:171
@ I3C_DATA_RATE_HDR_DDR
Definition: i3c.h:165
@ I3C_DATA_RATE_SDR
Definition: i3c.h:162
@ I3C_DATA_RATE_HDR_TSL
Definition: i3c.h:168
@ I3C_DATA_RATE_HDR_BT
Definition: i3c.h:174
#define ENOSYS
Definition: errno.h:83
int target
Definition: main.c:68
struct _slist sys_slist_t
Definition: slist.h:40
struct _snode sys_snode_t
Definition: slist.h:33
__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:380
const void * api
Definition: device.h:386
const void * config
Definition: device.h:384
Structure to keep track of addresses on I3C bus.
Definition: addresses.h:41
Payload structure for one CCC transaction.
Definition: ccc.h:256
Configuration parameters for I3C hardware to act as controller.
Definition: i3c.h:376
uint32_t i3c
Definition: i3c.h:385
uint8_t supported_hdr
Definition: i3c.h:397
struct i3c_config_controller::@155 scl
bool is_secondary
Definition: i3c.h:381
uint32_t i2c
Definition: i3c.h:388
Custom I3C configuration parameters.
Definition: i3c.h:408
void * ptr
Definition: i3c.h:422
uint32_t id
Definition: i3c.h:410
uintptr_t val
Definition: i3c.h:414
Structure for describing attached devices for a controller.
Definition: i3c.h:959
sys_slist_t i3c
Definition: i3c.h:972
struct i3c_dev_attached_list::@160 devices
sys_slist_t i2c
Definition: i3c.h:977
struct i3c_addr_slots addr_slots
Definition: i3c.h:966
Structure for describing known devices for a controller.
Definition: i3c.h:989
struct i3c_i2c_device_desc *const i2c
Definition: i3c.h:998
const uint8_t num_i3c
Definition: i3c.h:1003
struct i3c_device_desc *const i3c
Definition: i3c.h:993
const uint8_t num_i2c
Definition: i3c.h:1008
Structure describing a I3C target device.
Definition: i3c.h:772
uint8_t maxwr
Definition: i3c.h:880
const uint8_t init_dynamic_addr
Definition: i3c.h:808
uint32_t max_read_turnaround
Definition: i3c.h:883
const uint8_t static_addr
Definition: i3c.h:797
uint8_t max_ibi
Definition: i3c.h:894
i3c_target_ibi_cb_t ibi_cb
Definition: i3c.h:904
uint8_t group_addr
Definition: i3c.h:833
uint16_t mwl
Definition: i3c.h:891
struct i3c_device_desc::@158 data_speed
uint8_t dynamic_addr
Definition: i3c.h:823
void * controller_priv
Definition: i3c.h:898
const struct device *const dev
Definition: i3c.h:780
sys_snode_t node
Definition: i3c.h:774
struct i3c_device_desc::@159 data_length
uint16_t mrl
Definition: i3c.h:888
const uint64_t pid
Definition: i3c.h:783
uint8_t maxrd
Definition: i3c.h:877
uint8_t bcr
Definition: i3c.h:865
uint8_t dcr
Definition: i3c.h:873
const struct device *const bus
Definition: i3c.h:777
Structure used for matching I3C devices.
Definition: i3c.h:737
const uint64_t pid
Definition: i3c.h:739
struct i3c_dev_list dev_list
Definition: i3c.h:1018
struct i3c_config_controller ctrl_config
Definition: i3c.h:1027
struct i3c_dev_attached_list attached_dev
Definition: i3c.h:1030
Structure describing a I2C device on I3C bus.
Definition: i3c.h:921
const struct device * bus
Definition: i3c.h:926
const uint16_t addr
Definition: i3c.h:929
const uint8_t lvr
Definition: i3c.h:945
void * controller_priv
Definition: i3c.h:948
sys_snode_t node
Definition: i3c.h:923
Struct for IBI request.
Definition: ibi.h:57
One I3C Message.
Definition: i3c.h:345
uint8_t flags
Definition: i3c.h:353
uint8_t hdr_mode
Definition: i3c.h:361
uint8_t * buf
Definition: i3c.h:347
uint32_t len
Definition: i3c.h:350
Structure describing a device that supports the I3C target API.
Definition: target_device.h:92
static void msg(uint64_t c64)
Definition: main.c:17