From patchwork Tue Nov 4 10:20:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 406494 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D439B1400A6 for ; Tue, 4 Nov 2014 21:22:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753012AbaKDKWX (ORCPT ); Tue, 4 Nov 2014 05:22:23 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:46367 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594AbaKDKWE (ORCPT ); Tue, 4 Nov 2014 05:22:04 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id sA4ALgsk029825; Tue, 4 Nov 2014 04:21:42 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id sA4ALgtp028904; Tue, 4 Nov 2014 04:21:42 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Tue, 4 Nov 2014 04:21:41 -0600 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id sA4ALEGG020969; Tue, 4 Nov 2014 04:21:38 -0600 From: Roger Quadros To: , CC: , , , , , , , , , , , , Roger Quadros Subject: [PATCH v3 6/8] net: can: c_can: Disable pins when CAN interface is down Date: Tue, 4 Nov 2014 12:20:59 +0200 Message-ID: <1415096461-25576-7-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415096461-25576-1-git-send-email-rogerq@ti.com> References: <1415096461-25576-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org DRA7 CAN IP suffers from a problem which causes it to be prevented from fully turning OFF (i.e. stuck in transition) if the module was disabled while there was traffic on the CAN_RX line. To work around this issue we select the SLEEP pin state by default on probe and use the DEFAULT pin state on CAN up and back to the SLEEP pin state on CAN down. Signed-off-by: Roger Quadros --- drivers/net/can/c_can/c_can.c | 20 ++++++++++++++++++++ drivers/net/can/c_can/c_can.h | 1 + drivers/net/can/c_can/c_can_platform.c | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 8e78bb4..4dfc3ce 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -603,6 +604,15 @@ static int c_can_start(struct net_device *dev) priv->can.state = CAN_STATE_ERROR_ACTIVE; + /* activate pins */ + if (!IS_ERR(priv->pinctrl)) { + struct pinctrl_state *s; + + s = pinctrl_lookup_state(priv->pinctrl, PINCTRL_STATE_DEFAULT); + if (!IS_ERR(s)) + pinctrl_select_state(priv->pinctrl, s); + } + return 0; } @@ -611,6 +621,16 @@ static void c_can_stop(struct net_device *dev) struct c_can_priv *priv = netdev_priv(dev); c_can_irq_control(priv, false); + + /* deactivate pins */ + if (!IS_ERR(priv->pinctrl)) { + struct pinctrl_state *s; + + s = pinctrl_lookup_state(priv->pinctrl, PINCTRL_STATE_SLEEP); + if (!IS_ERR(s)) + pinctrl_select_state(priv->pinctrl, s); + } + priv->can.state = CAN_STATE_STOPPED; } diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h index b5067bd..6b4ed1f 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h @@ -207,6 +207,7 @@ struct c_can_priv { u32 rxmasked; u32 dlc[C_CAN_MSG_OBJ_TX_NUM]; const struct c_can_driver_data *drvdata; + struct pinctrl *pinctrl; }; struct net_device *alloc_c_can_dev(void); diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c index ef1f5ce..d058820 100644 --- a/drivers/net/can/c_can/c_can_platform.c +++ b/drivers/net/can/c_can/c_can_platform.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -230,6 +231,7 @@ static int c_can_plat_probe(struct platform_device *pdev) struct clk *clk; const struct c_can_driver_data *drvdata; struct device_node *np = pdev->dev.of_node; + struct pinctrl *pinctrl; match = of_match_device(c_can_of_table, &pdev->dev); if (match) { @@ -241,6 +243,23 @@ static int c_can_plat_probe(struct platform_device *pdev) return -ENODEV; } + pinctrl = devm_pinctrl_get(&pdev->dev); + if (!IS_ERR(pinctrl)) { + struct pinctrl_state *s; + + /* Deactivate pins to prevent DRA7 DCAN IP from being + * stuck in transition when module is disabled. + * Pins are activated in c_can_start() and deactivated + * in c_can_stop() + */ + s = pinctrl_lookup_state(pinctrl, PINCTRL_STATE_SLEEP); + if (!IS_ERR(s)) + pinctrl_select_state(pinctrl, s); + } else { + dev_warn(&pdev->dev, + "failed to get pinctrl\n"); + } + /* get the appropriate clk */ clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { @@ -271,6 +290,7 @@ static int c_can_plat_probe(struct platform_device *pdev) priv = netdev_priv(dev); priv->drvdata = drvdata; + priv->pinctrl = pinctrl; switch (drvdata->id) { case BOSCH_C_CAN: