Skip to content

Commit 35f63f5

Browse files
marckleinebuddegregkh
authored andcommitted
can: mcp251x: mcp251x_hw_reset(): allow more time after a reset
commit d84ea21 upstream. Some boards take longer than 5ms to power up after a reset, so allow some retries attempts before giving up. Fixes: ff06d61 ("can: mcp251x: Improve mcp251x_hw_reset()") Cc: linux-stable <[email protected]> Tested-by: Sean Nyekjaer <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0e31027 commit 35f63f5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/net/can/spi/mcp251x.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
627627
static int mcp251x_hw_reset(struct spi_device *spi)
628628
{
629629
struct mcp251x_priv *priv = spi_get_drvdata(spi);
630-
u8 reg;
630+
unsigned long timeout;
631631
int ret;
632632

633633
/* Wait for oscillator startup timer after power up */
@@ -641,10 +641,19 @@ static int mcp251x_hw_reset(struct spi_device *spi)
641641
/* Wait for oscillator startup timer after reset */
642642
mdelay(MCP251X_OST_DELAY_MS);
643643

644-
reg = mcp251x_read_reg(spi, CANSTAT);
645-
if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
646-
return -ENODEV;
647-
644+
/* Wait for reset to finish */
645+
timeout = jiffies + HZ;
646+
while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK) !=
647+
CANCTRL_REQOP_CONF) {
648+
usleep_range(MCP251X_OST_DELAY_MS * 1000,
649+
MCP251X_OST_DELAY_MS * 1000 * 2);
650+
651+
if (time_after(jiffies, timeout)) {
652+
dev_err(&spi->dev,
653+
"MCP251x didn't enter in conf mode after reset\n");
654+
return -EBUSY;
655+
}
656+
}
648657
return 0;
649658
}
650659

0 commit comments

Comments
 (0)