a5863dff3bd5eb469418c9e6521a1b14f62ace09
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0726-can-mcp251x-Allow-more-time-after-a-reset.patch
1 From 9f29c6c8865de6f2dc200cb4c59a447d0884a6b3 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Thu, 1 Aug 2019 08:58:48 +0100
4 Subject: [PATCH 726/806] can: mcp251x: Allow more time after a reset
5
6 Some boards take longer than 5ms to power up after a reset, so allow
7 a few retry attempts before giving up.
8
9 See: https://github.com/raspberrypi/linux/issues/2767
10
11 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
12 ---
13  drivers/net/can/spi/mcp251x.c | 15 ++++++++++++---
14  1 file changed, 12 insertions(+), 3 deletions(-)
15
16 --- a/drivers/net/can/spi/mcp251x.c
17 +++ b/drivers/net/can/spi/mcp251x.c
18 @@ -628,6 +628,7 @@ static int mcp251x_hw_reset(struct spi_d
19         struct mcp251x_priv *priv = spi_get_drvdata(spi);
20         u8 reg;
21         int ret;
22 +       int retries = 10;
23  
24         /* Wait for oscillator startup timer after power up */
25         mdelay(MCP251X_OST_DELAY_MS);
26 @@ -637,10 +638,18 @@ static int mcp251x_hw_reset(struct spi_d
27         if (ret)
28                 return ret;
29  
30 -       /* Wait for oscillator startup timer after reset */
31 -       mdelay(MCP251X_OST_DELAY_MS);
32 +       /*
33 +        * Wait for oscillator startup timer after reset
34 +        *
35 +        * Some devices can take longer than the expected 5ms to wake
36 +        * up, so allow a few retries.
37 +        */
38 +
39 +       do {
40 +               mdelay(MCP251X_OST_DELAY_MS);
41 +               reg = mcp251x_read_reg(spi, CANSTAT);
42 +       } while (!reg && retries--);
43  
44 -       reg = mcp251x_read_reg(spi, CANSTAT);
45         if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
46                 return -ENODEV;
47