From patchwork Thu Jun 20 17:34:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 11007549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D64971580 for ; Thu, 20 Jun 2019 17:34:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6B3B2864E for ; Thu, 20 Jun 2019 17:34:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B72AB28756; Thu, 20 Jun 2019 17:34:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D4F12864E for ; Thu, 20 Jun 2019 17:34:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726975AbfFTRe1 (ORCPT ); Thu, 20 Jun 2019 13:34:27 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:35142 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbfFTRe0 (ORCPT ); Thu, 20 Jun 2019 13:34:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1561052064; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=E70txaQVeQ35IPllzxWF/GQYSC2d6WRJoscFzLL+Pro=; b=WmkExzN7SmRo4Y/pgJxjvC5cF3nMvzTCVyJJ6hRZIvalune6rLjXPcdyIiirKXDZYZ+aPI 407F9CjetA8x7TCD2TLbHwoGBNQwVLMcAT6F9x0ru13T518/tg7jjroV7bQwVY8HMC6WCf gzSmbMgdO6GeVvb+YuCle50LVck+UJo= From: Paul Cercueil To: Bin Liu Cc: od@zcrc.me, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Artur Rojek Subject: [PATCH 1/3] usb: musb: dma: Correct parameter passed to IRQ handler Date: Thu, 20 Jun 2019 19:34:12 +0200 Message-Id: <20190620173414.3201-1-paul@crapouillou.net> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The IRQ handler was passed a pointer to a struct dma_controller, but the argument was then casted to a pointer to a struct musb_dma_controller. Signed-off-by: Paul Cercueil Tested-by: Artur Rojek --- drivers/usb/musb/musbhsdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index 5fc6825745f2..2d3751d885b4 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c @@ -425,7 +425,7 @@ struct dma_controller *musbhs_dma_controller_create(struct musb *musb, controller->controller.channel_abort = dma_channel_abort; if (request_irq(irq, dma_controller_irq, 0, - dev_name(musb->controller), &controller->controller)) { + dev_name(musb->controller), controller)) { dev_err(dev, "request_irq %d failed!\n", irq); musb_dma_controller_destroy(&controller->controller); From patchwork Thu Jun 20 17:34:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 11007545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCCAA76 for ; Thu, 20 Jun 2019 17:34:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABB272864E for ; Thu, 20 Jun 2019 17:34:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DEDF28756; Thu, 20 Jun 2019 17:34:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 051CF2864E for ; Thu, 20 Jun 2019 17:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732042AbfFTRe2 (ORCPT ); Thu, 20 Jun 2019 13:34:28 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:35164 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbfFTRe1 (ORCPT ); Thu, 20 Jun 2019 13:34:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1561052065; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nQcUA6uRF64oTEhHKy4DTkYHoyfvf5gGLlWhsIzDT68=; b=AagneN5lZED+jVsPvIvbteSZYwCFL4dT+jmOiVdeJXpxDY5M59Sx39uUPRR1ylpjleofHc D5q508MI/y940lvz3JTfPxtsoROP80Bqd+JP3l3aH3sOOUAzZ/GN+B1mzsKyD4/UlMZOsO B/yiwcbS4rz9VRqsMAp4ib1AN7pqdVg= From: Paul Cercueil To: Bin Liu Cc: od@zcrc.me, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Artur Rojek Subject: [PATCH 2/3] usb: musb: dma: Add support for shared IRQ Date: Thu, 20 Jun 2019 19:34:13 +0200 Message-Id: <20190620173414.3201-2-paul@crapouillou.net> In-Reply-To: <20190620173414.3201-1-paul@crapouillou.net> References: <20190620173414.3201-1-paul@crapouillou.net> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The implementation of the Inventra IP in some of the Ingenic JZ47xx SoCs does not use a separate IRQ line for DMA transfers. Allow these SoCs to be supported by adding a flag 'dma_share_usb_irq' in the struct musb. If set, no extra IRQ line is required, and the musb glue will need to call the API function musbhs_dma_controller_irq() within its interrupt handler. Signed-off-by: Paul Cercueil Tested-by: Artur Rojek --- drivers/usb/musb/musb_core.h | 2 ++ drivers/usb/musb/musb_dma.h | 1 + drivers/usb/musb/musbhsdma.c | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 04203b7126d5..b7c31c717800 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -392,6 +392,8 @@ struct musb { unsigned flush_irq_work:1; + unsigned dma_share_usb_irq:1; + u8 address; u8 test_mode_nr; u16 ackpend; /* ep0 */ diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h index 8f60271c0a9d..b3f65016a972 100644 --- a/drivers/usb/musb/musb_dma.h +++ b/drivers/usb/musb/musb_dma.h @@ -191,6 +191,7 @@ extern void (*musb_dma_controller_destroy)(struct dma_controller *); extern struct dma_controller * musbhs_dma_controller_create(struct musb *musb, void __iomem *base); extern void musbhs_dma_controller_destroy(struct dma_controller *c); +extern irqreturn_t musbhs_dma_controller_irq(struct dma_controller *c); extern struct dma_controller * tusb_dma_controller_create(struct musb *musb, void __iomem *base); diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index 2d3751d885b4..898856e9974e 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c @@ -268,7 +268,7 @@ static int dma_channel_abort(struct dma_channel *channel) return 0; } -static irqreturn_t dma_controller_irq(int irq, void *private_data) +static irqreturn_t dma_controller_irq_cb(int irq, void *private_data) { struct musb_dma_controller *controller = private_data; struct musb *musb = controller->private_data; @@ -292,6 +292,9 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) int_hsdma = musb_readb(mbase, MUSB_HSDMA_INTR); if (!int_hsdma) { + if (musb->dma_share_usb_irq) + goto done; + musb_dbg(musb, "spurious DMA irq"); for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) { @@ -384,6 +387,15 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) return retval; } +irqreturn_t musbhs_dma_controller_irq(struct dma_controller *c) +{ + struct musb_dma_controller *controller = container_of(c, + struct musb_dma_controller, controller); + + return dma_controller_irq_cb(controller->irq, controller); +} +EXPORT_SYMBOL_GPL(musbhs_dma_controller_irq); + void musbhs_dma_controller_destroy(struct dma_controller *c) { struct musb_dma_controller *controller = container_of(c, @@ -404,9 +416,14 @@ struct dma_controller *musbhs_dma_controller_create(struct musb *musb, struct musb_dma_controller *controller; struct device *dev = musb->controller; struct platform_device *pdev = to_platform_device(dev); - int irq = platform_get_irq_byname(pdev, "dma"); + int irq; + + if (musb->dma_share_usb_irq) + irq = 0; + else + irq = platform_get_irq_byname(pdev, "dma"); - if (irq <= 0) { + if (irq < 0) { dev_err(dev, "No DMA interrupt line!\n"); return NULL; } @@ -424,8 +441,8 @@ struct dma_controller *musbhs_dma_controller_create(struct musb *musb, controller->controller.channel_program = dma_channel_program; controller->controller.channel_abort = dma_channel_abort; - if (request_irq(irq, dma_controller_irq, 0, - dev_name(musb->controller), controller)) { + if (irq > 0 && request_irq(irq, dma_controller_irq_cb, 0, + dev_name(musb->controller), controller)) { dev_err(dev, "request_irq %d failed!\n", irq); musb_dma_controller_destroy(&controller->controller); From patchwork Thu Jun 20 17:34:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 11007547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7309276 for ; Thu, 20 Jun 2019 17:34:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 652212864E for ; Thu, 20 Jun 2019 17:34:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 582B228756; Thu, 20 Jun 2019 17:34:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA0B82864E for ; Thu, 20 Jun 2019 17:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732115AbfFTRee (ORCPT ); Thu, 20 Jun 2019 13:34:34 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:35182 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbfFTRe2 (ORCPT ); Thu, 20 Jun 2019 13:34:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1561052066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2PvY1i8PHpawEPAEre7rKVHvj4003Eq08vSuPmhlQE8=; b=MVZxD8zLgTvEFE/SngL1ktTiRa4VmJDUUAq189XSupv1g7kpty1X11R30k1kJuUwCk3c6J GesZAoufKKR8KtB8SBfQXq8uQLiHp6qXKkjFCURr6oZlsEorJQD6NRwLqB4zJhlxt+GlUr Pe2xADZuXE0oidJ7+N6Qk31VjF1Ayek= From: Paul Cercueil To: Bin Liu Cc: od@zcrc.me, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Artur Rojek Subject: [PATCH 3/3] usb: musb: jz4740: Add support for DMA Date: Thu, 20 Jun 2019 19:34:14 +0200 Message-Id: <20190620173414.3201-3-paul@crapouillou.net> In-Reply-To: <20190620173414.3201-1-paul@crapouillou.net> References: <20190620173414.3201-1-paul@crapouillou.net> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for using the DMA channels built into the Inventra IP. Signed-off-by: Paul Cercueil Tested-by: Artur Rojek --- drivers/usb/musb/Kconfig | 2 +- drivers/usb/musb/jz4740.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 52f8e2b57ad5..210e4844c92a 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig @@ -142,7 +142,7 @@ config USB_UX500_DMA config USB_INVENTRA_DMA bool 'Inventra' - depends on USB_MUSB_OMAP2PLUS + depends on USB_MUSB_OMAP2PLUS || USB_MUSB_JZ4740 help Enable DMA transfers using Mentor's engine. diff --git a/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c index 5261f8dfedec..bbecfdee6ea1 100644 --- a/drivers/usb/musb/jz4740.c +++ b/drivers/usb/musb/jz4740.c @@ -25,11 +25,14 @@ struct jz4740_glue { static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) { unsigned long flags; - irqreturn_t retval = IRQ_NONE; + irqreturn_t retval = IRQ_NONE, retval_dma = IRQ_NONE; struct musb *musb = __hci; spin_lock_irqsave(&musb->lock, flags); + if (IS_ENABLED(CONFIG_USB_INVENTRA_DMA) && musb->dma_controller) + retval_dma = musbhs_dma_controller_irq(musb->dma_controller); + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); @@ -47,7 +50,10 @@ static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) spin_unlock_irqrestore(&musb->lock, flags); - return retval; + if (retval == IRQ_HANDLED || retval_dma == IRQ_HANDLED) + return IRQ_HANDLED; + + return IRQ_NONE; } static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { @@ -91,18 +97,19 @@ static int jz4740_musb_init(struct musb *musb) musb->dyn_fifo = true; musb->isr = jz4740_musb_interrupt; + musb->dma_share_usb_irq = true; return 0; } -/* - * DMA has not been confirmed to work with CONFIG_USB_INVENTRA_DMA, - * so let's not set up the dma function pointers yet. - */ static const struct musb_platform_ops jz4740_musb_ops = { .quirks = MUSB_DMA_INVENTRA | MUSB_INDEXED_EP, .fifo_mode = 2, .init = jz4740_musb_init, +#ifdef CONFIG_USB_INVENTRA_DMA + .dma_init = musbhs_dma_controller_create, + .dma_exit = musbhs_dma_controller_destroy, +#endif }; static int jz4740_probe(struct platform_device *pdev) @@ -137,6 +144,8 @@ static int jz4740_probe(struct platform_device *pdev) } musb->dev.parent = &pdev->dev; + musb->dev.dma_mask = &musb->dev.coherent_dma_mask; + musb->dev.coherent_dma_mask = DMA_BIT_MASK(32); glue->dev = &pdev->dev; glue->musb = musb;