Skip to content

Commit 5f186c2

Browse files
Joakim Zhangmarckleinebudde
authored andcommitted
can: flexcan: fix stop mode acknowledgment
To enter stop mode, the CPU should manually assert a global Stop Mode request and check the acknowledgment asserted by FlexCAN. The CPU must only consider the FlexCAN in stop mode when both request and acknowledgment conditions are satisfied. Fixes: de3578c ("can: flexcan: add self wakeup support") Reported-by: Marc Kleine-Budde <[email protected]> Signed-off-by: Joakim Zhang <[email protected]> Cc: linux-stable <[email protected]> # >= v5.0 Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e9f2a85 commit 5f186c2

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

drivers/net/can/flexcan.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ static void flexcan_enable_wakeup_irq(struct flexcan_priv *priv, bool enable)
400400
priv->write(reg_mcr, &regs->mcr);
401401
}
402402

403-
static inline void flexcan_enter_stop_mode(struct flexcan_priv *priv)
403+
static inline int flexcan_enter_stop_mode(struct flexcan_priv *priv)
404404
{
405405
struct flexcan_regs __iomem *regs = priv->regs;
406+
unsigned int ackval;
406407
u32 reg_mcr;
407408

408409
reg_mcr = priv->read(&regs->mcr);
@@ -412,20 +413,37 @@ static inline void flexcan_enter_stop_mode(struct flexcan_priv *priv)
412413
/* enable stop request */
413414
regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
414415
1 << priv->stm.req_bit, 1 << priv->stm.req_bit);
416+
417+
/* get stop acknowledgment */
418+
if (regmap_read_poll_timeout(priv->stm.gpr, priv->stm.ack_gpr,
419+
ackval, ackval & (1 << priv->stm.ack_bit),
420+
0, FLEXCAN_TIMEOUT_US))
421+
return -ETIMEDOUT;
422+
423+
return 0;
415424
}
416425

417-
static inline void flexcan_exit_stop_mode(struct flexcan_priv *priv)
426+
static inline int flexcan_exit_stop_mode(struct flexcan_priv *priv)
418427
{
419428
struct flexcan_regs __iomem *regs = priv->regs;
429+
unsigned int ackval;
420430
u32 reg_mcr;
421431

422432
/* remove stop request */
423433
regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
424434
1 << priv->stm.req_bit, 0);
425435

436+
/* get stop acknowledgment */
437+
if (regmap_read_poll_timeout(priv->stm.gpr, priv->stm.ack_gpr,
438+
ackval, !(ackval & (1 << priv->stm.ack_bit)),
439+
0, FLEXCAN_TIMEOUT_US))
440+
return -ETIMEDOUT;
441+
426442
reg_mcr = priv->read(&regs->mcr);
427443
reg_mcr &= ~FLEXCAN_MCR_SLF_WAK;
428444
priv->write(reg_mcr, &regs->mcr);
445+
446+
return 0;
429447
}
430448

431449
static inline void flexcan_error_irq_enable(const struct flexcan_priv *priv)
@@ -1614,7 +1632,9 @@ static int __maybe_unused flexcan_suspend(struct device *device)
16141632
*/
16151633
if (device_may_wakeup(device)) {
16161634
enable_irq_wake(dev->irq);
1617-
flexcan_enter_stop_mode(priv);
1635+
err = flexcan_enter_stop_mode(priv);
1636+
if (err)
1637+
return err;
16181638
} else {
16191639
err = flexcan_chip_disable(priv);
16201640
if (err)
@@ -1664,10 +1684,13 @@ static int __maybe_unused flexcan_noirq_resume(struct device *device)
16641684
{
16651685
struct net_device *dev = dev_get_drvdata(device);
16661686
struct flexcan_priv *priv = netdev_priv(dev);
1687+
int err;
16671688

16681689
if (netif_running(dev) && device_may_wakeup(device)) {
16691690
flexcan_enable_wakeup_irq(priv, false);
1670-
flexcan_exit_stop_mode(priv);
1691+
err = flexcan_exit_stop_mode(priv);
1692+
if (err)
1693+
return err;
16711694
}
16721695

16731696
return 0;

0 commit comments

Comments
 (0)