Skip to content

Commit 3ca5291

Browse files
nxpfranklialexandrebelloni
authored andcommitted
i3c: master: svc: wait for Manual ACK/NACK Done before next step
Wait for the controller to complete emitting ACK/NACK, otherwise the next command may be omitted by the hardware. Add a "command done" check in svc_i3c_master_nack(ack)_ibi() and change the return type to int to flag possible timeouts. Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20241002-svc-i3c-hj-v6-5-7e6e1d3569ae@nxp.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent f36f662 commit 3ca5291

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

drivers/i3c/master/svc-i3c-master.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
388388
return 0;
389389
}
390390

391-
static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
391+
static int svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
392392
bool mandatory_byte)
393393
{
394394
unsigned int ibi_ack_nack;
395+
u32 reg;
395396

396397
ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
397398
if (mandatory_byte)
@@ -400,18 +401,30 @@ static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
400401
ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
401402

402403
writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
404+
405+
return readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
406+
SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);
407+
403408
}
404409

405-
static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
410+
static int svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
406411
{
412+
int ret;
413+
u32 reg;
414+
407415
writel(SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK |
408416
SVC_I3C_MCTRL_IBIRESP_NACK,
409417
master->regs + SVC_I3C_MCTRL);
418+
419+
ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
420+
SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);
421+
return ret;
410422
}
411423

412424
static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 mstatus)
413425
{
414426
u32 ibitype;
427+
int ret = 0;
415428

416429
ibitype = SVC_I3C_MSTATUS_IBITYPE(mstatus);
417430

@@ -421,10 +434,10 @@ static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 msta
421434
switch (ibitype) {
422435
case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
423436
case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
424-
svc_i3c_master_nack_ibi(master);
437+
ret = svc_i3c_master_nack_ibi(master);
425438
}
426439

427-
return 0;
440+
return ret;
428441
}
429442

430443
static void svc_i3c_master_ibi_work(struct work_struct *work)
@@ -935,7 +948,9 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
935948
if (ret)
936949
break;
937950
} else if (SVC_I3C_MSTATUS_IBIWON(reg)) {
938-
svc_i3c_master_handle_ibi_won(master, reg);
951+
ret = svc_i3c_master_handle_ibi_won(master, reg);
952+
if (ret)
953+
break;
939954
continue;
940955
} else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) {
941956
if (SVC_I3C_MSTATUS_STATE_IDLE(reg) &&
@@ -1209,7 +1224,9 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
12091224
* start.
12101225
*/
12111226
if (SVC_I3C_MSTATUS_IBIWON(reg)) {
1212-
svc_i3c_master_handle_ibi_won(master, reg);
1227+
ret = svc_i3c_master_handle_ibi_won(master, reg);
1228+
if (ret)
1229+
goto emit_stop;
12131230
continue;
12141231
}
12151232

0 commit comments

Comments
 (0)