]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00217318-2 flexcan: create abstract api to enter and exit stop mode
authorDong Aisheng <b29396@freescale.com>
Fri, 3 Aug 2012 14:20:57 +0000 (22:20 +0800)
committerOliver Wendt <ow@karo-electronics.de>
Mon, 30 Sep 2013 12:12:37 +0000 (14:12 +0200)
Clean up duplicated code and hide the details of enter/exit
stop mode into API.

Signed-off-by: Dong Aisheng <b29396@freescale.com>
drivers/net/can/flexcan.c

index 0f0b76f0f5668ab15692fefa2eb20a14d6ad34fc..1d1c224c885491fca5bfc9680ad40a851d422692 100644 (file)
@@ -226,6 +226,26 @@ static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
                (reg_esr & FLEXCAN_ESR_ERR_BUS);
 }
 
+static inline void flexcan_enter_stop(struct flexcan_priv *priv)
+{
+       /* enable stop request for wakeup */
+       if (priv->version >= FLEXCAN_VER_10_0_12)
+               /* CAN1/CAN2_STOP_REQ bit 28/29 in group 13 */
+               mxc_iomux_set_gpr_register(13, 28 + priv->id, 1, 1);
+
+       udelay(10);
+}
+
+static inline void flexcan_exit_stop(struct flexcan_priv *priv)
+{
+       /* remove stop request */
+       if (priv->version >= FLEXCAN_VER_10_0_12)
+               /* CAN1/CAN2_STOP_REQ bit 28/29 in group 13 */
+               mxc_iomux_set_gpr_register(13, 28 + priv->id, 1, 0);
+
+       udelay(10);
+}
+
 static inline void flexcan_chip_enable(struct flexcan_priv *priv)
 {
        struct flexcan_regs __iomem *regs = priv->base;
@@ -579,10 +599,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
        writel(FLEXCAN_ESR_ERR_INT, &regs->esr);        /* ACK err IRQ */
 
        if (reg_esr & FLEXCAN_ESR_WAK_INT) {
-               /* first clear stop request then wakeup irq status */
-               if (priv->version >= FLEXCAN_VER_10_0_12)
-                       /* CAN1/CAN2_STOP_REQ bit 28/29 in group 13 */
-                       mxc_iomux_set_gpr_register(13, 28 + priv->id, 1, 0);
+               flexcan_exit_stop(priv);
                writel(FLEXCAN_ESR_WAK_INT, &regs->esr);
        }
 
@@ -1078,10 +1095,7 @@ static int flexcan_suspend(struct platform_device *pdev, pm_message_t state)
 
        priv->can.state = CAN_STATE_SLEEPING;
 
-       /* enable stop request for wakeup */
-       if (priv->version >= FLEXCAN_VER_10_0_12)
-               /* CAN1/CAN2_STOP_REQ bit 28/29 in group 13 */
-               mxc_iomux_set_gpr_register(13, 28 + priv->id, 1, 1);
+       flexcan_enter_stop(priv);
 
        ret = irq_set_irq_wake(dev->irq, 1);
        if (ret)
@@ -1100,10 +1114,7 @@ static int flexcan_resume(struct platform_device *pdev)
        if (ret)
                return ret;
 
-       /* remove stop request */
-       if (priv->version >= FLEXCAN_VER_10_0_12)
-               /* CAN1/CAN2_STOP_REQ bit 28/29 in group 13 */
-               mxc_iomux_set_gpr_register(13, 28 + priv->id, 1, 0);
+       flexcan_exit_stop(priv);
 
        priv->can.state = CAN_STATE_ERROR_ACTIVE;