drivers: i3c: add iterate through i3c/i2c devices macros
Add i3c_bus_for_each_i3cdev and i3c_bus_for_each_i2cdev to more easily iterate through each i3c or i2c device on the bus. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
This commit is contained in:
parent
ffb60c08e9
commit
e602590931
|
@ -79,6 +79,8 @@ ForEachMacros:
|
|||
- 'HTTP_SERVER_CONTENT_TYPE_FOREACH'
|
||||
- 'HTTP_SERVICE_FOREACH'
|
||||
- 'HTTP_SERVICE_FOREACH_RESOURCE'
|
||||
- 'I3C_BUS_FOR_EACH_I3CDEV'
|
||||
- 'I3C_BUS_FOR_EACH_I2CDEV'
|
||||
IfMacros:
|
||||
- 'CHECKIF'
|
||||
# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520
|
||||
|
|
|
@ -2294,8 +2294,6 @@ static int cdns_i3c_read_ibi_fifo(const struct cdns_i3c_config *config, void *bu
|
|||
static void cdns_i3c_handle_ibi(const struct device *dev, uint32_t ibir)
|
||||
{
|
||||
const struct cdns_i3c_config *config = dev->config;
|
||||
struct cdns_i3c_data *data = dev->data;
|
||||
|
||||
uint8_t ibi_data[CONFIG_I3C_IBI_MAX_PAYLOAD_SIZE];
|
||||
|
||||
/* The slave ID returned here is the device ID in the SIR map NOT the device ID
|
||||
|
@ -2310,8 +2308,7 @@ static void cdns_i3c_handle_ibi(const struct device *dev, uint32_t ibir)
|
|||
|
||||
uint32_t dev_id_rr0 = sys_read32(config->base + DEV_ID_RR0(slave_id + 1));
|
||||
uint8_t dyn_addr = DEV_ID_RR0_GET_DEV_ADDR(dev_id_rr0);
|
||||
struct i3c_device_desc *desc =
|
||||
i3c_dev_list_i3c_addr_find(&data->common.attached_dev, dyn_addr);
|
||||
struct i3c_device_desc *desc = i3c_dev_list_i3c_addr_find(dev, dyn_addr);
|
||||
|
||||
/*
|
||||
* Check for NAK or error conditions.
|
||||
|
@ -2989,9 +2986,7 @@ static struct i3c_device_desc *cdns_i3c_device_find(const struct device *dev,
|
|||
*/
|
||||
static struct i3c_i2c_device_desc *cdns_i3c_i2c_device_find(const struct device *dev, uint16_t addr)
|
||||
{
|
||||
struct cdns_i3c_data *data = dev->data;
|
||||
|
||||
return i3c_dev_list_i2c_addr_find(&data->common.attached_dev, addr);
|
||||
return i3c_dev_list_i2c_addr_find(dev, addr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,17 +198,15 @@ struct i3c_device_desc *i3c_dev_list_find(const struct i3c_dev_list *dev_list,
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct i3c_device_desc *i3c_dev_list_i3c_addr_find(struct i3c_dev_attached_list *dev_list,
|
||||
struct i3c_device_desc *i3c_dev_list_i3c_addr_find(const struct device *dev,
|
||||
uint8_t addr)
|
||||
{
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *ret = NULL;
|
||||
struct i3c_device_desc *desc;
|
||||
|
||||
__ASSERT_NO_MSG(dev_list != NULL);
|
||||
|
||||
SYS_SLIST_FOR_EACH_NODE(&dev_list->devices.i3c, node) {
|
||||
struct i3c_device_desc *desc = (void *)node;
|
||||
__ASSERT_NO_MSG(dev != NULL);
|
||||
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
if (desc->dynamic_addr == addr) {
|
||||
ret = desc;
|
||||
break;
|
||||
|
@ -218,17 +216,15 @@ struct i3c_device_desc *i3c_dev_list_i3c_addr_find(struct i3c_dev_attached_list
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct i3c_i2c_device_desc *i3c_dev_list_i2c_addr_find(struct i3c_dev_attached_list *dev_list,
|
||||
struct i3c_i2c_device_desc *i3c_dev_list_i2c_addr_find(const struct device *dev,
|
||||
uint16_t addr)
|
||||
{
|
||||
sys_snode_t *node;
|
||||
struct i3c_i2c_device_desc *ret = NULL;
|
||||
struct i3c_i2c_device_desc *desc;
|
||||
|
||||
__ASSERT_NO_MSG(dev_list != NULL);
|
||||
|
||||
SYS_SLIST_FOR_EACH_NODE(&dev_list->devices.i2c, node) {
|
||||
struct i3c_i2c_device_desc *desc = (void *)node;
|
||||
__ASSERT_NO_MSG(dev != NULL);
|
||||
|
||||
I3C_BUS_FOR_EACH_I2CDEV(dev, desc) {
|
||||
if (desc->addr == addr) {
|
||||
ret = desc;
|
||||
break;
|
||||
|
@ -664,12 +660,9 @@ static int i3c_bus_setdasa(const struct device *dev,
|
|||
|
||||
bool i3c_bus_has_sec_controller(const struct device *dev)
|
||||
{
|
||||
struct i3c_driver_data *data = (struct i3c_driver_data *)dev->data;
|
||||
sys_snode_t *node;
|
||||
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *i3c_desc = CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
struct i3c_device_desc *i3c_desc;
|
||||
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, i3c_desc) {
|
||||
if (i3c_device_is_controller_capable(i3c_desc)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -683,7 +676,8 @@ int i3c_bus_deftgts(const struct device *dev)
|
|||
struct i3c_driver_data *data = (struct i3c_driver_data *)dev->data;
|
||||
struct i3c_config_target config_target;
|
||||
struct i3c_ccc_deftgts *deftgts;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *i3c_desc;
|
||||
struct i3c_i2c_device_desc *i3c_i2c_desc;
|
||||
int ret;
|
||||
uint8_t n = 0;
|
||||
size_t num_of_targets = sys_slist_len(&data->attached_dev.devices.i3c) +
|
||||
|
@ -723,9 +717,7 @@ int i3c_bus_deftgts(const struct device *dev)
|
|||
/*
|
||||
* Loop through each attached I3C device and add it to the payload
|
||||
*/
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *i3c_desc = CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, i3c_desc) {
|
||||
deftgts->targets[n].addr = i3c_desc->dynamic_addr << 1;
|
||||
deftgts->targets[n].dcr = i3c_desc->dcr;
|
||||
deftgts->targets[n].bcr = i3c_desc->bcr;
|
||||
|
@ -736,10 +728,7 @@ int i3c_bus_deftgts(const struct device *dev)
|
|||
/*
|
||||
* Loop through each attached I2C device and add it to the payload
|
||||
*/
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i2c, node) {
|
||||
struct i3c_i2c_device_desc *i3c_i2c_desc =
|
||||
CONTAINER_OF(node, struct i3c_i2c_device_desc, node);
|
||||
|
||||
I3C_BUS_FOR_EACH_I2CDEV(dev, i3c_i2c_desc) {
|
||||
deftgts->targets[n].addr = 0;
|
||||
deftgts->targets[n].lvr = i3c_i2c_desc->lvr;
|
||||
deftgts->targets[n].bcr = 0;
|
||||
|
|
|
@ -1459,7 +1459,6 @@ static void mcux_i3c_ibi_work(struct k_work *work)
|
|||
const struct device *dev = i3c_ibi_work->controller;
|
||||
const struct mcux_i3c_config *config = dev->config;
|
||||
struct mcux_i3c_data *data = dev->data;
|
||||
struct i3c_dev_attached_list *dev_list = &data->common.attached_dev;
|
||||
I3C_Type *base = config->base;
|
||||
struct i3c_device_desc *target = NULL;
|
||||
uint32_t mstatus, ibitype, ibiaddr;
|
||||
|
@ -1517,7 +1516,7 @@ static void mcux_i3c_ibi_work(struct k_work *work)
|
|||
|
||||
switch (ibitype) {
|
||||
case I3C_MSTATUS_IBITYPE_IBI:
|
||||
target = i3c_dev_list_i3c_addr_find(dev_list, (uint8_t)ibiaddr);
|
||||
target = i3c_dev_list_i3c_addr_find(dev, (uint8_t)ibiaddr);
|
||||
if (target != NULL) {
|
||||
ret = mcux_i3c_do_one_xfer_read(base, &payload[0],
|
||||
sizeof(payload), true);
|
||||
|
|
|
@ -1455,7 +1455,6 @@ static void npcx_i3c_ibi_work(struct k_work *work)
|
|||
const struct device *dev = i3c_ibi_work->controller;
|
||||
const struct npcx_i3c_config *config = dev->config;
|
||||
struct npcx_i3c_data *data = dev->data;
|
||||
struct i3c_dev_attached_list *dev_list = &data->common.attached_dev;
|
||||
struct i3c_reg *inst = config->base;
|
||||
struct i3c_device_desc *target = NULL;
|
||||
uint32_t ibitype, ibiaddr;
|
||||
|
@ -1530,7 +1529,7 @@ static void npcx_i3c_ibi_work(struct k_work *work)
|
|||
|
||||
switch (ibitype) {
|
||||
case MSTATUS_IBITYPE_IBI:
|
||||
target = i3c_dev_list_i3c_addr_find(dev_list, (uint8_t)ibiaddr);
|
||||
target = i3c_dev_list_i3c_addr_find(dev, (uint8_t)ibiaddr);
|
||||
if (target != NULL) {
|
||||
if (i3c_ibi_work_enqueue_target_irq(target, &payload[0], payload_sz) != 0) {
|
||||
LOG_ERR("Error enqueue IBI IRQ work");
|
||||
|
|
|
@ -36,8 +36,7 @@ struct i3c_ctrl {
|
|||
static void node_id##cmd_i3c_attached_get(size_t idx, struct shell_static_entry *entry) \
|
||||
{ \
|
||||
const struct device *dev = DEVICE_DT_GET(node_id); \
|
||||
struct i3c_driver_data *data; \
|
||||
sys_snode_t *node; \
|
||||
struct i3c_device_desc *i3c_desc; \
|
||||
size_t cnt = 0; \
|
||||
\
|
||||
entry->syntax = NULL; \
|
||||
|
@ -45,17 +44,12 @@ struct i3c_ctrl {
|
|||
entry->subcmd = NULL; \
|
||||
entry->help = NULL; \
|
||||
\
|
||||
data = (struct i3c_driver_data *)dev->data; \
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) { \
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) { \
|
||||
if (cnt == idx) { \
|
||||
struct i3c_device_desc *desc = \
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node); \
|
||||
entry->syntax = desc->dev->name; \
|
||||
return; \
|
||||
} \
|
||||
cnt++; \
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, i3c_desc) { \
|
||||
if (cnt == idx) { \
|
||||
entry->syntax = i3c_desc->dev->name; \
|
||||
return; \
|
||||
} \
|
||||
cnt++; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -116,23 +110,6 @@ static int get_bytes_count_for_hex(char *arg)
|
|||
return MIN(MAX_BYTES_FOR_REGISTER_INDEX, length);
|
||||
}
|
||||
|
||||
static struct i3c_i2c_device_desc *get_i3c_i2c_list_desc_from_addr(const struct device *dev,
|
||||
uint16_t addr)
|
||||
{
|
||||
struct i3c_driver_config *config;
|
||||
uint8_t i;
|
||||
|
||||
config = (struct i3c_driver_config *)dev->config;
|
||||
for (i = 0; i < config->dev_list.num_i2c; i++) {
|
||||
if (config->dev_list.i2c[i].addr == addr) {
|
||||
/* only look for a device with the addr */
|
||||
return &config->dev_list.i2c[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct i3c_device_desc *get_i3c_list_desc_from_dev_name(const struct device *dev,
|
||||
const char *tdev_name)
|
||||
{
|
||||
|
@ -153,18 +130,12 @@ static struct i3c_device_desc *get_i3c_list_desc_from_dev_name(const struct devi
|
|||
static struct i3c_device_desc *get_i3c_attached_desc_from_dev_name(const struct device *dev,
|
||||
const char *tdev_name)
|
||||
{
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *i3c_desc;
|
||||
|
||||
data = (struct i3c_driver_data *)dev->data;
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
/* only look for a device with the same name */
|
||||
if (strcmp(desc->dev->name, tdev_name) == 0) {
|
||||
return desc;
|
||||
}
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, i3c_desc) {
|
||||
/* only look for a device with the same name */
|
||||
if (strcmp(i3c_desc->dev->name, tdev_name) == 0) {
|
||||
return i3c_desc;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +147,8 @@ static int cmd_i3c_info(const struct shell *sh, size_t argc, char **argv)
|
|||
{
|
||||
const struct device *dev, *tdev;
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *desc;
|
||||
struct i3c_i2c_device_desc *i2c_desc;
|
||||
bool found = false;
|
||||
|
||||
dev = device_get_binding(argv[ARGV_DEV]);
|
||||
|
@ -191,15 +163,11 @@ static int cmd_i3c_info(const struct shell *sh, size_t argc, char **argv)
|
|||
/* TODO: is this needed? */
|
||||
tdev = device_get_binding(argv[ARGV_TDEV]);
|
||||
if (!tdev) {
|
||||
shell_error(sh, "I3C: Target Device driver %s not found.",
|
||||
argv[ARGV_DEV]);
|
||||
shell_error(sh, "I3C: Target Device driver %s not found.", argv[ARGV_DEV]);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
/* only look for a device with the same name */
|
||||
if (strcmp(desc->dev->name, tdev->name) == 0) {
|
||||
shell_print(sh,
|
||||
|
@ -247,9 +215,7 @@ static int cmd_i3c_info(const struct shell *sh, size_t argc, char **argv)
|
|||
/* This gets all "currently attached" I3C and I2C devices */
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
shell_print(sh, "I3C: Devices found:");
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
shell_print(sh,
|
||||
"name: %s\n"
|
||||
"\tpid: 0x%012llx\n"
|
||||
|
@ -285,13 +251,11 @@ static int cmd_i3c_info(const struct shell *sh, size_t argc, char **argv)
|
|||
}
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i2c)) {
|
||||
shell_print(sh, "I2C: Devices found:");
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i2c, node) {
|
||||
struct i3c_i2c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_i2c_device_desc, node);
|
||||
I3C_BUS_FOR_EACH_I2CDEV(dev, i2c_desc) {
|
||||
shell_print(sh,
|
||||
"addr: 0x%02x\n"
|
||||
"\tlvr: 0x%02x",
|
||||
desc->addr, desc->lvr);
|
||||
i2c_desc->addr, i2c_desc->lvr);
|
||||
}
|
||||
} else {
|
||||
shell_print(sh, "I2C: No devices found.");
|
||||
|
@ -416,15 +380,15 @@ static int i3c_write_from_buffer(const struct shell *sh, char *s_dev_name, char
|
|||
/* i3c write <device> <dev_addr> <reg_addr> [<byte1>, ...] */
|
||||
static int cmd_i3c_write(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
return i3c_write_from_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG],
|
||||
&argv[4], argc - 4);
|
||||
return i3c_write_from_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG], &argv[4],
|
||||
argc - 4);
|
||||
}
|
||||
|
||||
/* i3c write_byte <device> <dev_addr> <reg_addr> <value> */
|
||||
static int cmd_i3c_write_byte(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
return i3c_write_from_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG],
|
||||
&argv[4], 1);
|
||||
return i3c_write_from_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG], &argv[4],
|
||||
1);
|
||||
}
|
||||
|
||||
static int i3c_read_to_buffer(const struct shell *sh, char *s_dev_name, char *s_tdev_name,
|
||||
|
@ -474,8 +438,7 @@ static int cmd_i3c_read_byte(const struct shell *sh, size_t argc, char **argv)
|
|||
uint8_t out;
|
||||
int ret;
|
||||
|
||||
ret = i3c_read_to_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG], &out,
|
||||
1);
|
||||
ret = i3c_read_to_buffer(sh, argv[ARGV_DEV], argv[ARGV_TDEV], argv[ARGV_REG], &out, 1);
|
||||
if (ret == 0) {
|
||||
shell_print(sh, "Output: 0x%x", out);
|
||||
}
|
||||
|
@ -607,8 +570,7 @@ static int cmd_i3c_hdr_ddr_read(const struct shell *sh, size_t argc, char **argv
|
|||
static int cmd_i3c_ccc_rstdaa(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
const struct device *dev;
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *desc;
|
||||
int ret;
|
||||
|
||||
dev = device_get_binding(argv[ARGV_DEV]);
|
||||
|
@ -616,7 +578,6 @@ static int cmd_i3c_ccc_rstdaa(const struct shell *sh, size_t argc, char **argv)
|
|||
shell_error(sh, "I3C: Device driver %s not found.", argv[ARGV_DEV]);
|
||||
return -ENODEV;
|
||||
}
|
||||
data = (struct i3c_driver_data *)dev->data;
|
||||
|
||||
ret = i3c_ccc_do_rstdaa_all(dev);
|
||||
if (ret < 0) {
|
||||
|
@ -625,14 +586,9 @@ static int cmd_i3c_ccc_rstdaa(const struct shell *sh, size_t argc, char **argv)
|
|||
}
|
||||
|
||||
/* reset all devices DA */
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
desc->dynamic_addr = 0;
|
||||
shell_print(sh, "Reset dynamic address for device %s",
|
||||
desc->dev->name);
|
||||
}
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
desc->dynamic_addr = 0;
|
||||
shell_print(sh, "Reset dynamic address for device %s", desc->dev->name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -656,8 +612,7 @@ static int cmd_i3c_ccc_entdaa(const struct shell *sh, size_t argc, char **argv)
|
|||
static int cmd_i3c_ccc_setaasa(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
const struct device *dev;
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *desc;
|
||||
int ret;
|
||||
|
||||
dev = device_get_binding(argv[ARGV_DEV]);
|
||||
|
@ -665,7 +620,6 @@ static int cmd_i3c_ccc_setaasa(const struct shell *sh, size_t argc, char **argv)
|
|||
shell_error(sh, "I3C: Device driver %s not found.", argv[ARGV_DEV]);
|
||||
return -ENODEV;
|
||||
}
|
||||
data = (struct i3c_driver_data *)dev->data;
|
||||
|
||||
ret = i3c_ccc_do_setaasa_all(dev);
|
||||
if (ret < 0) {
|
||||
|
@ -674,14 +628,10 @@ static int cmd_i3c_ccc_setaasa(const struct shell *sh, size_t argc, char **argv)
|
|||
}
|
||||
|
||||
/* set all devices DA to SA */
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
if ((desc->supports_setaasa) && (desc->dynamic_addr == 0) &&
|
||||
(desc->static_addr != 0)) {
|
||||
desc->dynamic_addr = desc->static_addr;
|
||||
}
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
if ((desc->supports_setaasa) && (desc->dynamic_addr == 0) &&
|
||||
(desc->static_addr != 0)) {
|
||||
desc->dynamic_addr = desc->static_addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1057,8 +1007,7 @@ static int cmd_i3c_ccc_setmwl(const struct shell *sh, size_t argc, char **argv)
|
|||
static int cmd_i3c_ccc_setmrl_bc(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
const struct device *dev;
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *desc;
|
||||
struct i3c_ccc_mrl mrl;
|
||||
int ret;
|
||||
|
||||
|
@ -1067,7 +1016,6 @@ static int cmd_i3c_ccc_setmrl_bc(const struct shell *sh, size_t argc, char **arg
|
|||
shell_error(sh, "I3C: Device driver %s not found.", argv[ARGV_DEV]);
|
||||
return -ENODEV;
|
||||
}
|
||||
data = (struct i3c_driver_data *)dev->data;
|
||||
|
||||
mrl.len = strtol(argv[2], NULL, 16);
|
||||
if (argc > 3) {
|
||||
|
@ -1080,14 +1028,10 @@ static int cmd_i3c_ccc_setmrl_bc(const struct shell *sh, size_t argc, char **arg
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
desc->data_length.mrl = mrl.len;
|
||||
if ((argc > 3) && (desc->bcr & I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE)) {
|
||||
desc->data_length.max_ibi = mrl.ibi_len;
|
||||
}
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
desc->data_length.mrl = mrl.len;
|
||||
if ((argc > 3) && (desc->bcr & I3C_BCR_IBI_PAYLOAD_HAS_DATA_BYTE)) {
|
||||
desc->data_length.max_ibi = mrl.ibi_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1098,8 +1042,7 @@ static int cmd_i3c_ccc_setmrl_bc(const struct shell *sh, size_t argc, char **arg
|
|||
static int cmd_i3c_ccc_setmwl_bc(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
const struct device *dev;
|
||||
struct i3c_driver_data *data;
|
||||
sys_snode_t *node;
|
||||
struct i3c_device_desc *desc;
|
||||
struct i3c_ccc_mwl mwl;
|
||||
int ret;
|
||||
|
||||
|
@ -1108,7 +1051,6 @@ static int cmd_i3c_ccc_setmwl_bc(const struct shell *sh, size_t argc, char **arg
|
|||
shell_error(sh, "I3C: Device driver %s not found.", argv[ARGV_DEV]);
|
||||
return -ENODEV;
|
||||
}
|
||||
data = (struct i3c_driver_data *)dev->data;
|
||||
|
||||
mwl.len = strtol(argv[3], NULL, 16);
|
||||
|
||||
|
@ -1118,12 +1060,8 @@ static int cmd_i3c_ccc_setmwl_bc(const struct shell *sh, size_t argc, char **arg
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (!sys_slist_is_empty(&data->attached_dev.devices.i3c)) {
|
||||
SYS_SLIST_FOR_EACH_NODE(&data->attached_dev.devices.i3c, node) {
|
||||
struct i3c_device_desc *desc =
|
||||
CONTAINER_OF(node, struct i3c_device_desc, node);
|
||||
desc->data_length.mwl = mwl.len;
|
||||
}
|
||||
I3C_BUS_FOR_EACH_I3CDEV(dev, desc) {
|
||||
desc->data_length.mwl = mwl.len;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1709,9 +1647,8 @@ static int cmd_i3c_ccc_getcaps(const struct shell *sh, size_t argc, char **argv)
|
|||
caps.fmt2.vtcaps[1]);
|
||||
}
|
||||
} else {
|
||||
shell_print(sh, "GETCAPS: 0x%02x; 0x%02x; 0x%02x; 0x%02x",
|
||||
caps.fmt1.getcaps[0], caps.fmt1.getcaps[1], caps.fmt1.getcaps[2],
|
||||
caps.fmt1.getcaps[3]);
|
||||
shell_print(sh, "GETCAPS: 0x%02x; 0x%02x; 0x%02x; 0x%02x", caps.fmt1.getcaps[0],
|
||||
caps.fmt1.getcaps[1], caps.fmt1.getcaps[2], caps.fmt1.getcaps[3]);
|
||||
memcpy(&desc->getcaps, &caps, sizeof(desc->getcaps));
|
||||
}
|
||||
|
||||
|
@ -1911,8 +1848,7 @@ static int cmd_i3c_ccc_getmxds(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
if (fmt == GETMXDS_FORMAT_3) {
|
||||
if (defbyte == GETMXDS_FORMAT_3_WRRDTURN) {
|
||||
shell_print(sh,
|
||||
"WRRDTURN: maxwr 0x%02x; maxrd 0x%02x; maxrdturn 0x%06x",
|
||||
shell_print(sh, "WRRDTURN: maxwr 0x%02x; maxrd 0x%02x; maxrdturn 0x%06x",
|
||||
mxds.fmt3.wrrdturn[0], mxds.fmt3.wrrdturn[1],
|
||||
sys_get_le24(&mxds.fmt3.wrrdturn[2]));
|
||||
/* Update values in descriptor */
|
||||
|
@ -2042,7 +1978,7 @@ static int cmd_i3c_i2c_attach(const struct shell *sh, size_t argc, char **argv)
|
|||
return -ENODEV;
|
||||
}
|
||||
addr = strtol(argv[2], NULL, 16);
|
||||
desc = get_i3c_i2c_list_desc_from_addr(dev, addr);
|
||||
desc = i3c_dev_list_i2c_addr_find(dev, addr);
|
||||
if (!desc) {
|
||||
shell_error(sh, "I3C: I2C addr 0x%02x not listed with the bus.", addr);
|
||||
return -ENODEV;
|
||||
|
@ -2069,7 +2005,7 @@ static int cmd_i3c_i2c_detach(const struct shell *sh, size_t argc, char **argv)
|
|||
return -ENODEV;
|
||||
}
|
||||
addr = strtol(argv[2], NULL, 16);
|
||||
desc = get_i3c_i2c_list_desc_from_addr(dev, addr);
|
||||
desc = i3c_dev_list_i2c_addr_find(dev, addr);
|
||||
if (!desc) {
|
||||
shell_error(sh, "I3C: I2C addr 0x%02x not listed with the bus.", addr);
|
||||
return -ENODEV;
|
||||
|
@ -2143,8 +2079,7 @@ static int cmd_i3c_i2c_scan(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
ret = i3c_attach_i2c_device(&desc);
|
||||
if (ret < 0) {
|
||||
shell_error(sh,
|
||||
"I3C: unable to attach I2C addr 0x%02x.",
|
||||
shell_error(sh, "I3C: unable to attach I2C addr 0x%02x.",
|
||||
desc.addr);
|
||||
}
|
||||
|
||||
|
@ -2161,8 +2096,7 @@ static int cmd_i3c_i2c_scan(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
ret = i3c_detach_i2c_device(&desc);
|
||||
if (ret < 0) {
|
||||
shell_error(sh,
|
||||
"I3C: unable to detach I2C addr 0x%02x.",
|
||||
shell_error(sh, "I3C: unable to detach I2C addr 0x%02x.",
|
||||
desc.addr);
|
||||
}
|
||||
} else if (slot == I3C_ADDR_SLOT_STATUS_I3C_DEV) {
|
||||
|
|
|
@ -1206,6 +1206,28 @@ struct i3c_driver_data {
|
|||
struct i3c_dev_attached_list attached_dev;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief iterate over all I3C devices present on the bus
|
||||
*
|
||||
* @param bus: the I3C bus device pointer
|
||||
* @param desc: an I3C device descriptor pointer updated to point to the current slot
|
||||
* at each iteration of the loop
|
||||
*/
|
||||
#define I3C_BUS_FOR_EACH_I3CDEV(bus, desc) \
|
||||
SYS_SLIST_FOR_EACH_CONTAINER( \
|
||||
&((struct i3c_driver_data *)(bus->data))->attached_dev.devices.i3c, desc, node)
|
||||
|
||||
/**
|
||||
* @brief iterate over all I2C devices present on the bus
|
||||
*
|
||||
* @param bus: the I3C bus device pointer
|
||||
* @param desc: an I2C device descriptor pointer updated to point to the current slot
|
||||
* at each iteration of the loop
|
||||
*/
|
||||
#define I3C_BUS_FOR_EACH_I2CDEV(bus, desc) \
|
||||
SYS_SLIST_FOR_EACH_CONTAINER( \
|
||||
&((struct i3c_driver_data *)(bus->data))->attached_dev.devices.i2c, desc, node)
|
||||
|
||||
/**
|
||||
* @brief Find a I3C target device descriptor by ID.
|
||||
*
|
||||
|
@ -1227,13 +1249,13 @@ struct i3c_device_desc *i3c_dev_list_find(const struct i3c_dev_list *dev_list,
|
|||
* This finds the I3C target device descriptor in the attached
|
||||
* device list matching the dynamic address (@p addr)
|
||||
*
|
||||
* @param dev_list Pointer to the device list struct.
|
||||
* @param dev Pointer to controller device driver instance.
|
||||
* @param addr Dynamic address to be matched.
|
||||
*
|
||||
* @return Pointer to the I3C target device descriptor, or
|
||||
* `NULL` if none is found.
|
||||
*/
|
||||
struct i3c_device_desc *i3c_dev_list_i3c_addr_find(struct i3c_dev_attached_list *dev_list,
|
||||
struct i3c_device_desc *i3c_dev_list_i3c_addr_find(const struct device *dev,
|
||||
uint8_t addr);
|
||||
|
||||
/**
|
||||
|
@ -1242,13 +1264,13 @@ struct i3c_device_desc *i3c_dev_list_i3c_addr_find(struct i3c_dev_attached_list
|
|||
* This finds the I2C target device descriptor in the attached
|
||||
* device list matching the address (@p addr)
|
||||
*
|
||||
* @param dev_list Pointer to the device list struct.
|
||||
* @param dev Pointer to controller device driver instance.
|
||||
* @param addr Address to be matched.
|
||||
*
|
||||
* @return Pointer to the I2C target device descriptor, or
|
||||
* `NULL` if none is found.
|
||||
*/
|
||||
struct i3c_i2c_device_desc *i3c_dev_list_i2c_addr_find(struct i3c_dev_attached_list *dev_list,
|
||||
struct i3c_i2c_device_desc *i3c_dev_list_i2c_addr_find(const struct device *dev,
|
||||
uint16_t addr);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue