Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96789dc

Browse files
Lucas Tanurewsakernel
authored andcommitted
i2c: cadence: Increase timeout per message if necessary
Timeout as 1 second sets an upper limit on the length of the transfer executed, but there is no maximum length of a write or read message set in i2c_adapter_quirks for this controller. This upper limit affects devices that require sending large firmware blobs over I2C. To remove that limitation, calculate the minimal time necessary, plus some wiggle room, for every message and use it instead of the default one second, if more than one second. Signed-off-by: Lucas Tanure <[email protected]> Acked-by: Michal Simek <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent e17daa3 commit 96789dc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/i2c/busses/i2c-cadence.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static void cdns_i2c_master_reset(struct i2c_adapter *adap)
760760
static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
761761
struct i2c_adapter *adap)
762762
{
763-
unsigned long time_left;
763+
unsigned long time_left, msg_timeout;
764764
u32 reg;
765765

766766
id->p_msg = msg;
@@ -785,8 +785,16 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
785785
else
786786
cdns_i2c_msend(id);
787787

788+
/* Minimal time to execute this message */
789+
msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk);
790+
/* Plus some wiggle room */
791+
msg_timeout += msecs_to_jiffies(500);
792+
793+
if (msg_timeout < adap->timeout)
794+
msg_timeout = adap->timeout;
795+
788796
/* Wait for the signal of completion */
789-
time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
797+
time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout);
790798
if (time_left == 0) {
791799
cdns_i2c_master_reset(adap);
792800
dev_err(id->adap.dev.parent,

0 commit comments

Comments
 (0)