can: mcp251xfd: mcp251xfd_chip_softreset_check(): wait for OSC ready before accessing chip

This patch changes the order of reading the Mode and Oscillator Ready
bits.

Instead of reading the Mode of the chip directly after reset, first
wait for the oscillator to get ready and the chip to fully start up.
Read the Mode after this.

Link: https://lore.kernel.org/all/20220207131047.282110-10-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
Marc Kleine-Budde 2020-10-27 16:05:19 +01:00
parent 06db5dbc8e
commit 01a80d688a

View file

@ -349,10 +349,21 @@ static int mcp251xfd_chip_softreset_do(const struct mcp251xfd_priv *priv)
static int mcp251xfd_chip_softreset_check(const struct mcp251xfd_priv *priv)
{
u32 osc, osc_reference;
u32 osc_reference, osc_mask;
u8 mode;
int err;
/* Check for reset defaults of OSC reg.
* This will take care of stabilization period.
*/
osc_reference = MCP251XFD_REG_OSC_OSCRDY |
FIELD_PREP(MCP251XFD_REG_OSC_CLKODIV_MASK,
MCP251XFD_REG_OSC_CLKODIV_10);
osc_mask = osc_reference | MCP251XFD_REG_OSC_PLLRDY;
err = mcp251xfd_chip_wait_for_osc_ready(priv, osc_reference, osc_mask);
if (err)
return err;
err = mcp251xfd_chip_get_mode(priv, &mode);
if (err)
return err;
@ -364,22 +375,6 @@ static int mcp251xfd_chip_softreset_check(const struct mcp251xfd_priv *priv)
return -ETIMEDOUT;
}
osc_reference = MCP251XFD_REG_OSC_OSCRDY |
FIELD_PREP(MCP251XFD_REG_OSC_CLKODIV_MASK,
MCP251XFD_REG_OSC_CLKODIV_10);
/* check reset defaults of OSC reg */
err = regmap_read(priv->map_reg, MCP251XFD_REG_OSC, &osc);
if (err)
return err;
if (osc != osc_reference) {
netdev_info(priv->ndev,
"Controller failed to reset. osc=0x%08x, reference value=0x%08x.\n",
osc, osc_reference);
return -ETIMEDOUT;
}
return 0;
}