summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDong Aisheng <b29396@freescale.com>2012-08-03 22:20:57 +0800
committerStefan Agner <stefan.agner@toradex.com>2014-06-17 09:27:13 +0200
commit475c9a1a1db659948185a2bd1d434f1419a02235 (patch)
treea3e7e42b7dcf7e34b6c7cecf49837e4ad14da0e5
parentb8adb5492113e3b1e421e967e2060a061bc85975 (diff)
ENGR00217318-2 flexcan: create abstract api to enter and exit stop mode
Clean up duplicated code and hide the details of enter/exit stop mode into API. Signed-off-by: Dong Aisheng <b29396@freescale.com>
-rw-r--r--drivers/net/can/flexcan.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 0f0b76f0f566..1d1c224c8854 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -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;