Commit 06db5dbc authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

can: mcp251xfd: mcp251xfd_chip_wait_for_osc_ready(): prepare for PLL support

The function mcp251xfd_chip_wait_for_osc_ready() polls the Oscillator
Control Register for the oscillator to get ready. By passing the
appropriate parameters (osc_reference and osc_mask) it can also poll
for PLL ready.

This patch adjusts the error message if the Oscillator and/or PLL fail
to get ready.

Link: https://lore.kernel.org/all/20220207131047.282110-9-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 197656de
...@@ -112,6 +112,22 @@ static const char *mcp251xfd_get_mode_str(const u8 mode) ...@@ -112,6 +112,22 @@ static const char *mcp251xfd_get_mode_str(const u8 mode)
return "<unknown>"; return "<unknown>";
} }
static const char *
mcp251xfd_get_osc_str(const u32 osc, const u32 osc_reference)
{
switch (~osc & osc_reference &
(MCP251XFD_REG_OSC_OSCRDY | MCP251XFD_REG_OSC_PLLRDY)) {
case MCP251XFD_REG_OSC_PLLRDY:
return "PLL";
case MCP251XFD_REG_OSC_OSCRDY:
return "Oscillator";
case MCP251XFD_REG_OSC_PLLRDY | MCP251XFD_REG_OSC_OSCRDY:
return "Oscillator/PLL";
}
return "<unknown>";
}
static inline int mcp251xfd_vdd_enable(const struct mcp251xfd_priv *priv) static inline int mcp251xfd_vdd_enable(const struct mcp251xfd_priv *priv)
{ {
if (!priv->reg_vdd) if (!priv->reg_vdd)
...@@ -269,8 +285,9 @@ mcp251xfd_chip_wait_for_osc_ready(const struct mcp251xfd_priv *priv, ...@@ -269,8 +285,9 @@ mcp251xfd_chip_wait_for_osc_ready(const struct mcp251xfd_priv *priv,
} }
netdev_err(priv->ndev, netdev_err(priv->ndev,
"Timeout waiting for Oscillator Ready (osc=0x%08x, osc_reference=0x%08x)\n", "Timeout waiting for %s ready (osc=0x%08x, osc_reference=0x%08x, osc_mask=0x%08x).\n",
osc, osc_reference); mcp251xfd_get_osc_str(osc, osc_reference),
osc, osc_reference, osc_mask);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -298,6 +315,10 @@ static int mcp251xfd_chip_clock_enable(const struct mcp251xfd_priv *priv) ...@@ -298,6 +315,10 @@ static int mcp251xfd_chip_clock_enable(const struct mcp251xfd_priv *priv)
if (err) if (err)
return err; return err;
/* Sometimes the PLL is stuck enabled, the controller never
* sets the OSC Ready bit, and we get an -ETIMEDOUT. Our
* caller takes care of retry.
*/
return mcp251xfd_chip_wait_for_osc_ready(priv, osc_reference, osc_mask); return mcp251xfd_chip_wait_for_osc_ready(priv, osc_reference, osc_mask);
} }
......
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