Skip to content

Commit

Permalink
drivers: i3c: specify start addr when searching for a free addr
Browse files Browse the repository at this point in the history
For example, if a driver needed to reserve address before it does a
ENTDAA, it would need to get free address in a loop, but the get
free address func would return the same address everytime. It needs
the start address, which would be the last free address it go, to
be passed in to get the next free address.

Signed-off-by: Ryan McClelland <[email protected]>
  • Loading branch information
XenuIsWatching committed Oct 28, 2023
1 parent e734028 commit 9a5a926
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drivers/i3c/i3c_cdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static void cdns_i3c_program_controller_retaining_reg(const struct device *dev)

if (!i3c_addr_slots_is_free(&data->common.attached_dev.addr_slots, controller_da)) {
controller_da =
i3c_addr_slots_next_free_find(&data->common.attached_dev.addr_slots);
i3c_addr_slots_next_free_find(&data->common.attached_dev.addr_slots, 0);
LOG_DBG("%s: 0x%02x DA selected for controller", dev->name, controller_da);
}
sys_write32(prepare_rr0_dev_address(controller_da), config->base + DEV_ID_RR0(0));
Expand Down
10 changes: 5 additions & 5 deletions drivers/i3c/i3c_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ bool i3c_addr_slots_is_free(struct i3c_addr_slots *slots,
return (status == I3C_ADDR_SLOT_STATUS_FREE);
}

uint8_t i3c_addr_slots_next_free_find(struct i3c_addr_slots *slots)
uint8_t i3c_addr_slots_next_free_find(struct i3c_addr_slots *slots, uint8_t start_addr)
{
uint8_t addr;
enum i3c_addr_slot_status status;

/* Addresses 0 to 7 are reserved. So start at 8. */
for (addr = 8; addr < I3C_MAX_ADDR; addr++) {
for (addr = MAX(start_addr, 8); addr < I3C_MAX_ADDR; addr++) {
status = i3c_addr_slots_status(slots, addr);
if (status == I3C_ADDR_SLOT_STATUS_FREE) {
return addr;
Expand Down Expand Up @@ -252,7 +252,7 @@ int i3c_determine_default_addr(struct i3c_device_desc *target, uint8_t *addr)
} else {
/* address is not free, get the next one */
*addr = i3c_addr_slots_next_free_find(
&data->attached_dev.addr_slots);
&data->attached_dev.addr_slots, 0);
}
} else {
/* Use the init dynamic address as it's DA, but the RR will need to
Expand Down Expand Up @@ -281,7 +281,7 @@ int i3c_determine_default_addr(struct i3c_device_desc *target, uint8_t *addr)
} else {
/* pick a DA to use */
*addr = i3c_addr_slots_next_free_find(
&data->attached_dev.addr_slots);
&data->attached_dev.addr_slots, 0);
}
}
} else {
Expand Down Expand Up @@ -488,7 +488,7 @@ int i3c_dev_list_daa_addr_helper(struct i3c_addr_slots *addr_slots,
/*
* Find the next available address.
*/
dyn_addr = i3c_addr_slots_next_free_find(addr_slots);
dyn_addr = i3c_addr_slots_next_free_find(addr_slots, 0);

if (dyn_addr == 0U) {
/* No free addresses available */
Expand Down
3 changes: 2 additions & 1 deletion include/zephyr/drivers/i3c/addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ bool i3c_addr_slots_is_free(struct i3c_addr_slots *slots,
* assigned to a new device.
*
* @param slots Pointer to the address slots structure.
* @param start_addr Where to start searching
*
* @return The next free address, or 0 if none found.
*/
uint8_t i3c_addr_slots_next_free_find(struct i3c_addr_slots *slots);
uint8_t i3c_addr_slots_next_free_find(struct i3c_addr_slots *slots, uint8_t start_addr);

/**
* @brief Mark the address as free (not used) in device list.
Expand Down

0 comments on commit 9a5a926

Please sign in to comment.