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: 40106 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2C7EE21894 for ; Tue, 4 Nov 2014 10:22:33 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id mc6sf438677lab.3 for ; Tue, 04 Nov 2014 02:22:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=Na/QGK5O7vT1pCd45iGTKX7kFSW5+0K4ZINe3IfSMSg=; b=WV7YLge+a0jxyPLXFCdQuX4UmYfq+zD2mnjWD74HaiTg++XuRHs0lTijTUT413uBR9 4N4Az3MIZQZek0c5KJKpF8RIp8wqPLTuskqS1SFKt06V22VOO9PCKb1hPJyOo9N6OGVj rqvw3a1c3/lliCei62N9pKQxQEkA8W8GeC687GQ29bBmxlI6y/MCW+eAgS2ck+e+UV23 qG+RsQPiZmROJnDU0FOTzJOUVe1S1dkK2lKR2PpojrKTuwbT+Sa7EVOtH1YELllglJsx u3hjkYEHm4bfE8i+ksme4wX8z62kxIs/SSmOt7zOReBdpyi3BRQAddQgzRJqhMO5w0ok BPCw== X-Gm-Message-State: ALoCoQnMpz9ZnDbOYmpCnj6hyFk05oZAF2IXgrYzu42OIZ6J9+cEGDSf8fj6GOLepo/La/FSecAp X-Received: by 10.112.77.9 with SMTP id o9mr4986288lbw.6.1415096550974; Tue, 04 Nov 2014 02:22:30 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.5 with SMTP id o5ls213635lao.3.gmail; Tue, 04 Nov 2014 02:22:30 -0800 (PST) X-Received: by 10.152.10.143 with SMTP id i15mr58507085lab.5.1415096550764; Tue, 04 Nov 2014 02:22:30 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id k1si14132lbv.25.2014.11.04.02.22.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 02:22:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id w7so3695768lbi.17 for ; Tue, 04 Nov 2014 02:22:30 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr57746037lbc.34.1415096550538; Tue, 04 Nov 2014 02:22:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp92862lbc; Tue, 4 Nov 2014 02:22:29 -0800 (PST) X-Received: by 10.70.43.229 with SMTP id z5mr42248072pdl.25.1415096548951; Tue, 04 Nov 2014 02:22:28 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sd1si17612288pbb.115.2014.11.04.02.22.28 for ; Tue, 04 Nov 2014 02:22:28 -0800 (PST) Received-SPF: none (google.com: netdev-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753012AbaKDKWX (ORCPT + 3 others); 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: list List-ID: X-Mailing-List: netdev@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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: