From patchwork Fri Jun 27 10:00:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Aisheng X-Patchwork-Id: 364888 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 116261400F6 for ; Fri, 27 Jun 2014 21:31:48 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753562AbaF0Lbn (ORCPT ); Fri, 27 Jun 2014 07:31:43 -0400 Received: from mail-bn1blp0186.outbound.protection.outlook.com ([207.46.163.186]:1266 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753420AbaF0Lbk (ORCPT ); Fri, 27 Jun 2014 07:31:40 -0400 Received: from BN3PR0301CA0045.namprd03.prod.outlook.com (25.160.152.141) by BY2PR03MB091.namprd03.prod.outlook.com (10.255.241.159) with Microsoft SMTP Server (TLS) id 15.0.959.15; Fri, 27 Jun 2014 11:31:37 +0000 Received: from BY2FFO11FD056.protection.gbl (2a01:111:f400:7c0c::133) by BN3PR0301CA0045.outlook.office365.com (2a01:111:e400:401e::13) with Microsoft SMTP Server (TLS) id 15.0.969.15 via Frontend Transport; Fri, 27 Jun 2014 11:31:36 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD056.mail.protection.outlook.com (10.1.15.193) with Microsoft SMTP Server (TLS) id 15.0.969.12 via Frontend Transport; Fri, 27 Jun 2014 11:31:36 +0000 Received: from shlinux1.ap.freescale.net (shlinux1.ap.freescale.net [10.192.225.216]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s5RBVQND023015; Fri, 27 Jun 2014 04:31:34 -0700 From: Dong Aisheng To: CC: , , , Subject: [PATCH 3/3] can: m_can: add loopback and monitor mode support Date: Fri, 27 Jun 2014 18:00:46 +0800 Message-ID: <1403863246-18822-4-git-send-email-b29396@freescale.com> X-Mailer: git-send-email 1.7.8 In-Reply-To: <1403863246-18822-1-git-send-email-b29396@freescale.com> References: <1403863246-18822-1-git-send-email-b29396@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(199002)(189002)(99396002)(21056001)(93916002)(81542001)(89996001)(80022001)(102836001)(85852003)(83072002)(104166001)(76482001)(26826002)(64706001)(36756003)(88136002)(77982001)(74662001)(74502001)(31966008)(92566001)(46102001)(79102001)(50986999)(76176999)(92726001)(47776003)(20776003)(50466002)(19580405001)(83322001)(19580395003)(44976005)(95666004)(68736004)(104016002)(97736001)(69596002)(48376002)(105606002)(81342001)(4396001)(87286001)(107046002)(2351001)(81156004)(50226001)(106466001)(62966002)(87936001)(6806004)(85306003)(77156001)(33646001)(84676001)(42262001); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR03MB091; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BL:0; ACTION:Default; RISK:Low; SCL:0; SPMLVL:NotSpam; PCL:0; RULEID: X-Forefront-PRVS: 0255DF69B9 Received-SPF: Fail (: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=Aisheng.Dong@freescale.com; X-OriginatorOrg: freescale.com Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org add loopback and monitor mode support. Signed-off-by: Dong Aisheng --- drivers/net/can/m_can.c | 24 ++++++++++++++++++++++-- 1 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/m_can.c b/drivers/net/can/m_can.c index e4aed71..bbe8a7d 100644 --- a/drivers/net/can/m_can.c +++ b/drivers/net/can/m_can.c @@ -94,8 +94,12 @@ enum m_can_lec_type { LEC_CRC_ERROR, LEC_UNUSED, }; +/* Test Register (TEST) */ +#define TEST_LBCK BIT(4) /* CC Control Register(CCCR) */ +#define CCCR_TEST BIT(7) +#define CCCR_MON BIT(5) #define CCCR_CCE BIT(1) #define CCCR_INIT BIT(0) @@ -661,13 +665,13 @@ static int m_can_set_bittiming(struct net_device *dev) * - configure rx fifo * - accept non-matching frame into fifo 0 * - configure tx buffer + * - configure mode * - setup bittiming - * - TODO: - * 1) other working modes support like monitor, loopback... */ static void m_can_chip_config(struct net_device *dev) { struct m_can_priv *priv = netdev_priv(dev); + u32 cccr, test; m_can_config_endisable(priv, true); @@ -694,6 +698,22 @@ static void m_can_chip_config(struct net_device *dev) m_can_write(priv, M_CAN_RXF1C, (priv->rxf1_elems << RXFC_FS_OFF) | RXFC_FWM_1 | (priv->mram_off + priv->rxf1_off)); + cccr = m_can_read(priv, M_CAN_CCCR); + cccr &= ~(CCCR_TEST | CCCR_MON); + test = m_can_read(priv, M_CAN_TEST); + test &= ~TEST_LBCK; + + if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) + cccr |= CCCR_MON; + + if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) { + cccr |= CCCR_TEST; + test |= TEST_LBCK; + } + + m_can_write(priv, M_CAN_CCCR, cccr); + m_can_write(priv, M_CAN_TEST, test); + /* enable all interrupts */ m_can_write(priv, M_CAN_IR, IR_ALL_INT); m_can_write(priv, M_CAN_IE, IR_ALL_INT);