From patchwork Wed Nov 12 14:16:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 40676 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 14880206A5 for ; Wed, 12 Nov 2014 14:17:57 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf8156704eek.5 for ; Wed, 12 Nov 2014 06:17:56 -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:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=WRM80NiPYQwM57kHiRalLZ24L2G2bLxsab7vqK/RgoI=; b=Qi7Dluz2sa+e4TmJ8NZGu4630DxF3JG0UGxDA2s+2KT1/jmAZWDrE0pMEzb4F7WIx2 eR9059QrawjaMWw0rCm40dYm+/LyrttRmkZ7uGi+bKW5p2utHTlROfbjoBKuTdrlxwGl LPy7mJv8ZVydjehwjBGR3rjpcJRgKCTD/uTCxL4b3gaWPWywPoNDilNwG4r2cEV/83/S MbkdguJUBuOgiv6EcRUezjiNmkqYtd2A8zVgHGU5heKwHg5KpVE5bTAadtF4prFeUUXW /dn3lfzNaB3RxAIDiUYFNSAXixYRnO5tx2yCnLdFro90uzIGGWVlsTwYeBlMAdiCUikj Lwgw== X-Gm-Message-State: ALoCoQnI+ncjCC79JeEbHozxWZqF9UwrTriq3GAW9wNFhd2Znf3nNq879w9ZxC2+gcKdQ41qm+e/ X-Received: by 10.152.10.233 with SMTP id l9mr22621lab.0.1415801876237; Wed, 12 Nov 2014 06:17:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.5.43 with SMTP id cj11ls685359lad.85.gmail; Wed, 12 Nov 2014 06:17:55 -0800 (PST) X-Received: by 10.112.151.70 with SMTP id uo6mr42005449lbb.2.1415801875634; Wed, 12 Nov 2014 06:17:55 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id k5si17689964lag.75.2014.11.12.06.17.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 06:17:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id gm9so11203404lab.5 for ; Wed, 12 Nov 2014 06:17:55 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr42568629lah.56.1415801875493; Wed, 12 Nov 2014 06:17:55 -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 ew9csp431181lbc; Wed, 12 Nov 2014 06:17:54 -0800 (PST) X-Received: by 10.70.96.162 with SMTP id dt2mr47575078pdb.29.1415801873716; Wed, 12 Nov 2014 06:17:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bt3si4568247pbd.196.2014.11.12.06.17.52 for ; Wed, 12 Nov 2014 06:17:53 -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 S1752994AbaKLORo (ORCPT + 3 others); Wed, 12 Nov 2014 09:17:44 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:41937 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752409AbaKLORm (ORCPT ); Wed, 12 Nov 2014 09:17:42 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id sACEHPBk003267; Wed, 12 Nov 2014 08:17:25 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id sACEHPVk027501; Wed, 12 Nov 2014 08:17:25 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Wed, 12 Nov 2014 08:17:24 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id sACEHJ0e010557; Wed, 12 Nov 2014 08:17:20 -0600 Message-ID: <54636BD0.2010208@ti.com> Date: Wed, 12 Nov 2014 16:16:48 +0200 From: Roger Quadros User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: , CC: , , , , , , , , , , , , Roger Quadros Subject: [PATCH v5 6/8] net: can: c_can: Disable pins when CAN interface is down References: <1415371762-29885-1-git-send-email-rogerq@ti.com> <1415371762-29885-7-git-send-email-rogerq@ti.com> In-Reply-To: <1415371762-29885-7-git-send-email-rogerq@ti.com> 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.215.46 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 | 21 +++++++++++++++++++++ drivers/net/can/c_can/c_can.h | 1 + drivers/net/can/c_can/c_can_platform.c | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 8e78bb4..a950eea 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 @@ -587,6 +588,21 @@ static int c_can_chip_config(struct net_device *dev) return c_can_set_bittiming(dev); } +/* + * Selects the pinctrl state specified in the name. + */ +static void c_can_pinctrl_select_state(struct c_can_priv *priv, + const char *name) +{ + if (!IS_ERR(priv->pinctrl)) { + struct pinctrl_state *s; + + s = pinctrl_lookup_state(priv->pinctrl, name); + if (!IS_ERR(s)) + pinctrl_select_state(priv->pinctrl, s); + } +} + static int c_can_start(struct net_device *dev) { struct c_can_priv *priv = netdev_priv(dev); @@ -603,6 +619,8 @@ static int c_can_start(struct net_device *dev) priv->can.state = CAN_STATE_ERROR_ACTIVE; + /* activate pins */ + c_can_pinctrl_select_state(priv, PINCTRL_STATE_DEFAULT); return 0; } @@ -611,6 +629,9 @@ 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 */ + c_can_pinctrl_select_state(priv, PINCTRL_STATE_SLEEP); 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 c6715ca..3cedf48 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h @@ -210,6 +210,7 @@ struct c_can_priv { u32 comm_rcv_high; u32 rxmasked; u32 dlc[C_CAN_MSG_OBJ_TX_NUM]; + 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 b838c6b..71b9063 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)) { @@ -270,6 +289,7 @@ static int c_can_plat_probe(struct platform_device *pdev) } priv = netdev_priv(dev); + priv->pinctrl = pinctrl; switch (drvdata->id) { case BOSCH_C_CAN: