From patchwork Thu Jul 3 09:22:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Qiang X-Patchwork-Id: 366702 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 86A7F14010A for ; Thu, 3 Jul 2014 19:26:45 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 3C5741A013B for ; Thu, 3 Jul 2014 19:26:45 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2lp0239.outbound.protection.outlook.com [207.46.163.239]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 88A5A1A0005 for ; Thu, 3 Jul 2014 19:25:55 +1000 (EST) Received: from BY2PR03CA034.namprd03.prod.outlook.com (10.242.234.155) by DM2PR03MB400.namprd03.prod.outlook.com (10.141.84.153) with Microsoft SMTP Server (TLS) id 15.0.974.11; Thu, 3 Jul 2014 09:25:48 +0000 Received: from BN1BFFO11FD038.protection.gbl (2a01:111:f400:7c10::1:150) by BY2PR03CA034.outlook.office365.com (2a01:111:e400:2c2c::27) with Microsoft SMTP Server (TLS) id 15.0.974.11 via Frontend Transport; Thu, 3 Jul 2014 09:25:47 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD038.mail.protection.outlook.com (10.58.144.101) with Microsoft SMTP Server (TLS) id 15.0.969.12 via Frontend Transport; Thu, 3 Jul 2014 09:25:47 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s639PfUd026279; Thu, 3 Jul 2014 02:25:44 -0700 From: Zhao Qiang To: , , , , Subject: [PATCH v6] flexcan: add err_irq handler for flexcan Date: Thu, 3 Jul 2014 17:22:17 +0800 Message-ID: <1404379337-15351-1-git-send-email-B45475@freescale.com> X-Mailer: git-send-email 1.8.5 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(189002)(199002)(81342001)(47776003)(95666004)(104166001)(64706001)(88136002)(76482001)(85306003)(46102001)(77156001)(87936001)(81542001)(87286001)(105606002)(107046002)(80022001)(109986001)(89996001)(229853001)(26826002)(20776003)(79102001)(83322001)(19580395003)(48376002)(44976005)(19580405001)(6806004)(2201001)(84676001)(68736004)(69596002)(92566001)(92726001)(74662001)(4396001)(62966002)(85852003)(31966008)(81156004)(50986999)(97736001)(99396002)(83072002)(36756003)(77982001)(102836001)(93916002)(74502001)(104016002)(50226001)(106466001)(50466002)(21056001)(42262001); DIR:OUT; SFP:; SCL:1; SRVR:DM2PR03MB400; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID: X-Forefront-PRVS: 0261CCEEDF 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=qiang.zhao@freescale.com; X-OriginatorOrg: freescale.com Cc: Zhao Qiang X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it. Signed-off-by: Zhao Qiang --- Changes for v2: - use a space instead of tab - use flexcan_poll_state instead of print Changes for v3: - return IRQ_HANDLED if err is triggered - stop transmitted packets when there is an err_interrupt Changes for v4: - call flexcan_irq Changes for v5: - move err_int_handling code from flexcan_irq to flexcan_err_irq - call flexcan_err_irq from flexcan_irq Changes for v6: - move RX_IRQ handling back to flexcan_irq drivers/net/can/flexcan.c | 52 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index f425ec2..f6c92bc 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -208,6 +208,7 @@ struct flexcan_priv { void __iomem *base; u32 reg_esr; u32 reg_ctrl_default; + int err_irq; struct clk *clk_ipg; struct clk *clk_per; @@ -690,6 +691,28 @@ static int flexcan_poll(struct napi_struct *napi, int quota) return work_done; } +static irqreturn_t flexcan_err_irq(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct flexcan_priv *priv = netdev_priv(dev); + struct flexcan_regs __iomem *regs = priv->base; + u32 reg_ctrl, reg_esr; + irqreturn_t ret = IRQ_NONE; + + reg_esr = flexcan_read(®s->esr); + reg_ctrl = flexcan_read(®s->ctrl); + + if (reg_esr & FLEXCAN_ESR_ALL_INT) { + flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, ®s->esr); + ret = IRQ_HANDLED; + } + + if (reg_esr & FLEXCAN_ESR_ERR_INT) + flexcan_write(reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK, ®s->ctrl); + + return ret; +} + static irqreturn_t flexcan_irq(int irq, void *dev_id) { struct net_device *dev = dev_id; @@ -698,11 +721,10 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id) struct flexcan_regs __iomem *regs = priv->base; u32 reg_iflag1, reg_esr; - reg_iflag1 = flexcan_read(®s->iflag1); reg_esr = flexcan_read(®s->esr); - /* ACK all bus error and state change IRQ sources */ - if (reg_esr & FLEXCAN_ESR_ALL_INT) - flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, ®s->esr); + reg_iflag1 = flexcan_read(®s->iflag1); + + flexcan_err_irq(irq, dev); /* * schedule NAPI in case of: @@ -944,10 +966,17 @@ static int flexcan_open(struct net_device *dev) if (err) goto out_close; + if (priv->err_irq) { + err = request_irq(priv->err_irq, flexcan_err_irq, IRQF_SHARED, + dev->name, dev); + if (err) + goto out_free_irq; + } + /* start chip and queuing */ err = flexcan_chip_start(dev); if (err) - goto out_free_irq; + goto out_free_err_irq; can_led_event(dev, CAN_LED_EVENT_OPEN); @@ -956,6 +985,9 @@ static int flexcan_open(struct net_device *dev) return 0; + out_free_err_irq: + if (priv->err_irq) + free_irq(priv->err_irq, dev); out_free_irq: free_irq(dev->irq, dev); out_close: @@ -977,6 +1009,9 @@ static int flexcan_close(struct net_device *dev) flexcan_chip_stop(dev); free_irq(dev->irq, dev); + if (priv->err_irq) + free_irq(priv->err_irq, dev); + clk_disable_unprepare(priv->clk_per); clk_disable_unprepare(priv->clk_ipg); @@ -1099,7 +1134,7 @@ static int flexcan_probe(struct platform_device *pdev) struct resource *mem; struct clk *clk_ipg = NULL, *clk_per = NULL; void __iomem *base; - int err, irq; + int err, irq, err_irq; u32 clock_freq = 0; if (pdev->dev.of_node) @@ -1126,6 +1161,10 @@ static int flexcan_probe(struct platform_device *pdev) if (irq <= 0) return -ENODEV; + err_irq = platform_get_irq(pdev, 1); + if (err_irq <= 0) + err_irq = 0; + base = devm_ioremap_resource(&pdev->dev, mem); if (IS_ERR(base)) return PTR_ERR(base); @@ -1149,6 +1188,7 @@ static int flexcan_probe(struct platform_device *pdev) dev->flags |= IFF_ECHO; priv = netdev_priv(dev); + priv->err_irq = err_irq; priv->can.clock.freq = clock_freq; priv->can.bittiming_const = &flexcan_bittiming_const; priv->can.do_set_mode = flexcan_set_mode;