Commit 01a80d68 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

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.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 06db5dbc
......@@ -349,34 +349,29 @@ 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;
err = mcp251xfd_chip_get_mode(priv, &mode);
if (err)
return err;
if (mode != MCP251XFD_REG_CON_MODE_CONFIG) {
netdev_info(priv->ndev,
"Controller not in Config Mode after reset, but in %s Mode (%u).\n",
mcp251xfd_get_mode_str(mode), mode);
return -ETIMEDOUT;
}
/* 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;
/* check reset defaults of OSC reg */
err = regmap_read(priv->map_reg, MCP251XFD_REG_OSC, &osc);
err = mcp251xfd_chip_get_mode(priv, &mode);
if (err)
return err;
if (osc != osc_reference) {
if (mode != MCP251XFD_REG_CON_MODE_CONFIG) {
netdev_info(priv->ndev,
"Controller failed to reset. osc=0x%08x, reference value=0x%08x.\n",
osc, osc_reference);
"Controller not in Config Mode after reset, but in %s Mode (%u).\n",
mcp251xfd_get_mode_str(mode), mode);
return -ETIMEDOUT;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment