From patchwork Thu Nov 13 15:23:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 40774 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 51A1E240ED for ; Thu, 13 Nov 2014 15:24:19 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id bs8sf1859470wib.4 for ; Thu, 13 Nov 2014 07:24:18 -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=SWaOFQU2F4CNWzNIWj5d49sYzFl8hGy7glPfDVhx32I=; b=RHjZoUThfLQcDe/Am2gTaImgRqoPSQ0kZUwN6ibarfvaw74CBFvuha80F59P2EL8k/ 2Bnw2E2ChlOA/uv0+FhCsxwmmK/ItU4W/K3fL/U1a7X10BXgLoMYQHkTn55OUwMXamIy HWyEhNPjQ3IRhIiRHJliDZJU4NZLLtWTV4FpioPWZZvcCnor+64aYePj3bIFBzjE/P2r SO6RrO4qo9QlsN6dqmF0bg65n+1er4wXbRL5Kh5D+Lw1vYOmsnrg/ZlaNgP+VPU5Z6W+ wgKm7Y3c0TNfCCCVFjx7fM1KDIMiE1VUvpUo9zgljXV/kDsqQsfyP/uz5sgzk2H/3r/Z er5w== X-Gm-Message-State: ALoCoQm5wmXvF0QSVVb67W9zKm4DNI23kGmeLWeRB4PqC2muHBYyDh7siTMC65wTmytYrJr7OjNk X-Received: by 10.152.27.38 with SMTP id q6mr3392536lag.5.1415892258550; Thu, 13 Nov 2014 07:24:18 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.200 with SMTP id n8ls702547lag.10.gmail; Thu, 13 Nov 2014 07:24:18 -0800 (PST) X-Received: by 10.112.219.3 with SMTP id pk3mr3101037lbc.18.1415892258371; Thu, 13 Nov 2014 07:24:18 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id n1si34366882laj.114.2014.11.13.07.24.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Nov 2014 07:24:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id 10so11089728lbg.21 for ; Thu, 13 Nov 2014 07:24:18 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr3002165lbc.23.1415892258180; Thu, 13 Nov 2014 07:24:18 -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 ew9csp605233lbc; Thu, 13 Nov 2014 07:24:17 -0800 (PST) X-Received: by 10.68.197.170 with SMTP id iv10mr3204994pbc.135.1415892256259; Thu, 13 Nov 2014 07:24:16 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ub9si25937771pab.102.2014.11.13.07.24.15 for ; Thu, 13 Nov 2014 07:24:16 -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 S933215AbaKMPYN (ORCPT + 3 others); Thu, 13 Nov 2014 10:24:13 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:47864 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932596AbaKMPYL (ORCPT ); Thu, 13 Nov 2014 10:24:11 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id sADFNmG9010545; Thu, 13 Nov 2014 09:23:48 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id sADFNmcs009430; Thu, 13 Nov 2014 09:23:48 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 13 Nov 2014 09:23:47 -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 sADFNivx006725; Thu, 13 Nov 2014 09:23:44 -0600 Message-ID: <5464CCFF.5010004@ti.com> Date: Thu, 13 Nov 2014 17:23:43 +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: , , , , , , , , , , , 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.217.176 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 | 37 +++++++++++++++++++++++++++++++++++++ drivers/net/can/c_can/c_can.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 8e78bb4..c80cb3d 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; } @@ -1244,6 +1265,22 @@ int register_c_can_dev(struct net_device *dev) struct c_can_priv *priv = netdev_priv(dev); int err; + priv->pinctrl = devm_pinctrl_get(dev->dev.parent); + if (!IS_ERR(priv->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(priv->pinctrl, PINCTRL_STATE_SLEEP); + if (!IS_ERR(s)) + pinctrl_select_state(priv->pinctrl, s); + } else { + netdev_dbg(dev, "failed to get pinctrl\n"); + } + c_can_pm_runtime_enable(priv); dev->flags |= IFF_ECHO; /* we support local echo */ 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);