@@ -582,6 +582,8 @@ int MXC_I3C_RevA_Controller_Transaction(mxc_i3c_reva_regs_t *i3c, const mxc_i3c_
582
582
int ret ;
583
583
uint8_t readCount ;
584
584
uint16_t remaining ;
585
+ uint32_t timeout ;
586
+ uint32_t freq ;
585
587
586
588
if (MXC_I3C_RevA_Controller_GetState (i3c ) != MXC_V_I3C_REVA_CONT_STATUS_STATE_IDLE &&
587
589
MXC_I3C_RevA_Controller_GetState (i3c ) != MXC_V_I3C_REVA_CONT_STATUS_STATE_SDR_NORM ) {
@@ -598,10 +600,12 @@ int MXC_I3C_RevA_Controller_Transaction(mxc_i3c_reva_regs_t *i3c, const mxc_i3c_
598
600
if (!req -> is_i2c ) {
599
601
ret = MXC_I3C_RevA_EmitStart (i3c , req -> is_i2c , MXC_I3C_TRANSFER_TYPE_WRITE ,
600
602
MXC_I3C_BROADCAST_ADDR , 0 );
601
-
602
603
if (ret < 0 ) {
603
604
goto err ;
604
605
}
606
+ freq = MXC_I3C_RevA_GetPPFrequency (i3c );
607
+ } else {
608
+ freq = MXC_I3C_RevA_GetI2CFrequency (i3c );
605
609
}
606
610
607
611
/* Restart with write */
@@ -612,7 +616,13 @@ int MXC_I3C_RevA_Controller_Transaction(mxc_i3c_reva_regs_t *i3c, const mxc_i3c_
612
616
goto err ;
613
617
}
614
618
615
- ret = MXC_I3C_RevA_WriteTXFIFO (i3c , req -> tx_buf , req -> tx_len , true, 100 );
619
+ /* A simple linear estimation to find a reasonable write timeout value,
620
+ proportional to clock period and buffer size. Coefficient value has
621
+ been found by trial-and-error.
622
+ */
623
+ timeout = (uint32_t )(40 * 1000000 / freq ) * req -> tx_len ;
624
+
625
+ ret = MXC_I3C_RevA_WriteTXFIFO (i3c , req -> tx_buf , req -> tx_len , true, timeout );
616
626
if (ret < 0 ) {
617
627
goto err ;
618
628
}
@@ -633,8 +643,14 @@ int MXC_I3C_RevA_Controller_Transaction(mxc_i3c_reva_regs_t *i3c, const mxc_i3c_
633
643
goto err ;
634
644
}
635
645
646
+ /* A simple linear estimation to find a reasonable read timeout value,
647
+ proportional to clock period and buffer size. Coefficient value has
648
+ been found by trial-and-error.
649
+ */
650
+ timeout = (uint32_t )(80 * 1000000 / freq ) * readCount ;
651
+
636
652
ret = MXC_I3C_RevA_ReadRXFIFO (i3c , req -> rx_buf + (req -> rx_len - remaining ), readCount ,
637
- 1000 );
653
+ timeout );
638
654
if (ret == readCount ) {
639
655
remaining -= readCount ;
640
656
} else {
0 commit comments