From patchwork Fri Nov 7 14:49:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 40420 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 94DBA240F7 for ; Fri, 7 Nov 2014 14:50:30 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id k14sf1960460wgh.11 for ; Fri, 07 Nov 2014 06:50:29 -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=uds1BesY5Qkj1M6jE+9J0CMcCcVRKFZUtRHrOChkwPg=; b=LLrE0MzjZkL8qp3oCM+pJUYqAO6rGPaU4B5aKmNAeUE608fzRfh7GV0/aKc05qOFpd i8aX/K0dFlj1itQSOOfTRk9KqHVA0gt7wDhyOca/qpH/BFEfP5yZro8145ceqx2IPytN Oy2SfNRStK7NFB4yT4WaWLrLmIvpSRGqZ6GTEle4TPwvUGU3yFWQK/c83ZD2WtOT8wFZ YD6n87rdTxRrkBlXvdSvr5+g2JHnJkrLGTMHd3r+Y4IlcyZJtr5yRoBEoYgvH0qTXxjq gBCUzf68KZc7u38Zz73f/UmzLZL6YHVjs5MZPqnr2iNnPWzBnYitmfBFZqBszXi8vq8u 6ogQ== X-Gm-Message-State: ALoCoQn71vyxZnvJChZrU7yGYNsWVSq4tx7p1mUobrN3hmg2QzvlXT3SC2xKZL9LZB5ANNJVicoP X-Received: by 10.112.146.104 with SMTP id tb8mr81875lbb.22.1415371829299; Fri, 07 Nov 2014 06:50:29 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.72 with SMTP id li8ls232832lab.101.gmail; Fri, 07 Nov 2014 06:50:28 -0800 (PST) X-Received: by 10.152.3.229 with SMTP id f5mr2653288laf.94.1415371828776; Fri, 07 Nov 2014 06:50:28 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id uf2si15246399lbb.103.2014.11.07.06.50.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Nov 2014 06:50:28 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so3064482lbj.37 for ; Fri, 07 Nov 2014 06:50:28 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr11624599lbo.32.1415371828595; Fri, 07 Nov 2014 06:50:28 -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 ew9csp210481lbc; Fri, 7 Nov 2014 06:50:27 -0800 (PST) X-Received: by 10.69.16.99 with SMTP id fv3mr3658965pbd.43.1415371826512; Fri, 07 Nov 2014 06:50:26 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jy15si9211546pad.148.2014.11.07.06.50.25 for ; Fri, 07 Nov 2014 06:50:26 -0800 (PST) Received-SPF: none (google.com: linux-omap-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 S1752997AbaKGOuX (ORCPT + 5 others); Fri, 7 Nov 2014 09:50:23 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:48054 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752978AbaKGOuU (ORCPT ); Fri, 7 Nov 2014 09:50:20 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id sA7Eo1sx010665; Fri, 7 Nov 2014 08:50:01 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id sA7Eo10N013172; Fri, 7 Nov 2014 08:50:01 -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; Fri, 7 Nov 2014 08:50:00 -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 sA7EnX7I007870; Fri, 7 Nov 2014 08:49:56 -0600 From: Roger Quadros To: , CC: , , , , , , , , , , , , Roger Quadros Subject: [PATCH v4 6/8] net: can: c_can: Disable pins when CAN interface is down Date: Fri, 7 Nov 2014 16:49:20 +0200 Message-ID: <1415371762-29885-7-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415371762-29885-1-git-send-email-rogerq@ti.com> References: <1415371762-29885-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-omap@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.178 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 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: