Skip to contentSkip to conversation

i3c: master: Simplify table prep for ENTDAA

RFC New Aniket 1 participant 1 message Sep 15, 2023

Subsystems (2)
lore
Share & tools
lore

Aniket

author
#0 lore raw

RFC 1/1 i3c: master: Simplify table prep for ENTDAA

Before ENTDAA, device address table is populated with the dynamic addresses to be assigned to the discovered devices.
Since these addresses are referenced using consecutive indices of the table, simply get indices starting from the last unused position of free_pos. Subsequent positions are expected to be empty.

---
The current way of preparing table seems unnecessarily compilcated. The device table index is incremented one by one, so we anyways assume that all positions are empty after the last occupied one. So we can omit those checks.

 drivers/i3c/master/dw-i3c-master.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/i3c/master/dw-i3c-master.c +10 -20
index 9332ae5f6419..dbbc96bc1587 100644
@@ -782,17 +782,15 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 	struct dw_i3c_master *master = to_dw_i3c_master(m);
 	struct dw_i3c_xfer *xfer;
 	struct dw_i3c_cmd *cmd;
-	u32 olddevs, newdevs;
 	u8 p, last_addr = 0;
-	int ret, pos;
+	int ret, pos, start_idx, end_idx;
 
-	olddevs = ~(master->free_pos);
+	start_idx = dw_i3c_master_get_free_pos(master);
+	if (start_idx < 0)
+		return start_idx;
 
 	/* Prepare DAT before launching DAA. */
-	for (pos = 0; pos < master->maxdevs; pos++) {
-		if (olddevs & BIT(pos))
-			continue;
-
+	for (pos = start_idx; pos < master->maxdevs; pos++) {
 		ret = i3c_master_get_free_addr(m, last_addr + 1);
 		if (ret < 0)
 			return -ENOSPC;
@@ -811,15 +809,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 	if (!xfer)
 		return -ENOMEM;
 
-	pos = dw_i3c_master_get_free_pos(master);
-	if (pos < 0) {
-		dw_i3c_master_free_xfer(xfer);
-		return pos;
-	}
 	cmd = &xfer->cmds[0];
 	cmd->cmd_hi = 0x1;
-	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - pos) |
-		      COMMAND_PORT_DEV_INDEX(pos) |
+	cmd->cmd_lo = COMMAND_PORT_DEV_COUNT(master->maxdevs - start_idx) |
+		      COMMAND_PORT_DEV_INDEX(start_idx) |
 		      COMMAND_PORT_CMD(I3C_CCC_ENTDAA) |
 		      COMMAND_PORT_ADDR_ASSGN_CMD |
 		      COMMAND_PORT_TOC |
@@ -829,13 +822,10 @@ static int dw_i3c_master_daa(struct i3c_master_controller *m)
 	if (!wait_for_completion_timeout(&xfer->comp, XFER_TIMEOUT))
 		dw_i3c_master_dequeue_xfer(master, xfer);
 
-	newdevs = GENMASK(master->maxdevs - cmd->rx_len - 1, 0);
-	newdevs &= ~olddevs;
+	end_idx = master->maxdevs - cmd->rx_len;
 
-	for (pos = 0; pos < master->maxdevs; pos++) {
-		if (newdevs & BIT(pos))
-			i3c_master_add_i3c_dev_locked(m, master->devs[pos].addr);
-	}
+	for (pos = start_idx; pos < end_idx; pos++)
+		i3c_master_add_i3c_dev_locked(m, master->devs[pos].addr);
 
 	dw_i3c_master_free_xfer(xfer);
 
Signature · 7 lines
2.42.0.459.ge4e396fd5e-goog


-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c