From patchwork Tue Nov 25 13:11:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Cherian X-Patchwork-Id: 5379441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 55FFB9F39D for ; Tue, 25 Nov 2014 13:25:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD1BF200E1 for ; Tue, 25 Nov 2014 13:24:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B065201C7 for ; Tue, 25 Nov 2014 13:24:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtG3t-00018s-SH; Tue, 25 Nov 2014 13:21:45 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtFyc-0003wF-HY for linux-arm-kernel@lists.infradead.org; Tue, 25 Nov 2014 13:16:19 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id sAPDFTC8022786; Tue, 25 Nov 2014 07:15:29 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAPDFT46021167; Tue, 25 Nov 2014 07:15:29 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Tue, 25 Nov 2014 07:15:29 -0600 Received: from george-pc.apr.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAPDEBE5020093; Tue, 25 Nov 2014 07:15:24 -0600 From: George Cherian To: , , , , Subject: [PATCH 12/19] usb: dwc3: gadget: Adapt gadget to drd library Date: Tue, 25 Nov 2014 18:41:48 +0530 Message-ID: <1416921115-10467-13-git-send-email-george.cherian@ti.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1416921115-10467-1-git-send-email-george.cherian@ti.com> References: <1416921115-10467-1-git-send-email-george.cherian@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141125_051618_762047_C9A037F8 X-CRM114-Status: GOOD ( 14.82 ) X-Spam-Score: -5.0 (-----) Cc: mark.rutland@arm.com, George Cherian , kgene.kim@samsung.com, linux@arm.linux.org.uk, ben-linux@fluff.org, mathias.nyman@intel.com, ijc+devicetree@hellion.org.uk, tony@atomide.com, gregkh@linuxfoundation.org, sojka@merica.cz, balbi@ti.com, robh+dt@kernel.org, pawel.moll@arm.com, peter.chen@freescale.com, bcousson@baylibre.com, galak@codeaurora.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adapt the dwc3 gadget to use drd library functions. In prepration to support DRD on dwc3. Signed-off-by: George Cherian --- drivers/usb/dwc3/gadget.c | 128 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 100 insertions(+), 28 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2c54d45..a75fae5 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -29,6 +29,7 @@ #include #include +#include #include "debug.h" #include "core.h" @@ -2681,6 +2682,89 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc) return ret; } +void dwc3_gadget_release(struct device *dev) +{ + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(gadget); + struct dwc3 *dwc = dwc_gadget->dwc; + + dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); + dwc3_gadget_free_endpoints(dwc); + dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, + dwc->ep0_bounce, dwc->ep0_bounce_addr); + kfree(dwc->setup_buf); + dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), + dwc->ep0_trb, dwc->ep0_trb_addr); + dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), + dwc->ctrl_req, dwc->ctrl_req_addr); + usb_drd_unregister_udc(dwc->dev); + kfree(dwc_gadget); +} + +int dwc3_gadget_setup(void *data) +{ + struct dwc3 *dwc = data; + struct dwc3_gadget *dwc_gadget; + struct usb_drd_gadget *drd_gadget; + struct usb_drd_setup *gadget_setup; + int ret; + + drd_gadget = kzalloc(sizeof(*drd_gadget), GFP_KERNEL); + if (!drd_gadget) { + ret = -ENOMEM; + goto err1; + } + + gadget_setup = kzalloc(sizeof(*gadget_setup), GFP_KERNEL); + if (!gadget_setup) { + ret = -ENOMEM; + goto err2; + } + + dwc_gadget = kzalloc(sizeof(*dwc_gadget), GFP_KERNEL); + if (!dwc_gadget) { + ret = -ENOMEM; + goto err3; + } + + drd_gadget->g_driver = dwc->gadget_driver; + + /* + * Pass the DWC3 specific routines for + * switching roles to the drd library + */ + gadget_setup->ll_start = NULL; + gadget_setup->ll_stop = NULL; + gadget_setup->ll_release = dwc3_gadget_release; + gadget_setup->data = (void *)dwc; + drd_gadget->gadget_setup = gadget_setup; + + dwc_gadget->gadget.ops = &dwc3_gadget_ops; + dwc_gadget->gadget.max_speed = USB_SPEED_SUPER; + dwc_gadget->gadget.speed = USB_SPEED_UNKNOWN; + dwc_gadget->gadget.sg_supported = true; + dwc_gadget->gadget.name = "dwc3-gadget"; + dwc_gadget->dwc = dwc; + drd_gadget->gadget = &dwc_gadget->gadget; + + /* + * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize + * on ep out. + */ + dwc_gadget->gadget.quirk_ep_out_aligned_size = true; + dwc->dwc_gadget = dwc_gadget; + usb_drd_register_udc(dwc->dev, drd_gadget); + + return 0; + +err3: + kfree(gadget_setup); +err2: + kfree(drd_gadget); +err1: + return ret; +} + /** * dwc3_gadget_init - Initializes gadget related registers * @dwc: pointer to our controller context structure @@ -2690,7 +2774,6 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc) int dwc3_gadget_init(struct dwc3 *dwc) { int ret; - struct dwc3_gadget *dwc_gadget; dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), &dwc->ctrl_req_addr, GFP_KERNEL); @@ -2723,24 +2806,9 @@ int dwc3_gadget_init(struct dwc3 *dwc) goto err3; } - dwc_gadget = kzalloc(sizeof(*dwc_gadget), GFP_KERNEL); - if (!dwc_gadget) { - ret = -ENOMEM; + ret = dwc3_gadget_setup(dwc); + if (ret) goto err3; - } - - dwc_gadget->gadget.ops = &dwc3_gadget_ops; - dwc_gadget->gadget.max_speed = USB_SPEED_SUPER; - dwc_gadget->gadget.speed = USB_SPEED_UNKNOWN; - dwc_gadget->gadget.sg_supported = true; - dwc_gadget->gadget.name = "dwc3-gadget"; - dwc_gadget->dwc = dwc; - - /* - * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize - * on ep out. - */ - dwc_gadget->gadget.quirk_ep_out_aligned_size = true; /* * REVISIT: Here we should clear all pending IRQs to be @@ -2751,7 +2819,8 @@ int dwc3_gadget_init(struct dwc3 *dwc) if (ret) goto err4; - ret = usb_add_gadget_udc(dwc->dev, &dwc_gadget->gadget); + ret = usb_add_gadget_udc_release(dwc->dev, &dwc->dwc_gadget->gadget, + dwc3_gadget_release); if (ret) { dev_err(dwc->dev, "failed to register udc\n"); goto err4; @@ -2760,6 +2829,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) return 0; err4: + usb_drd_unregister_udc(dwc->dev); dwc3_gadget_free_endpoints(dwc); dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, dwc->ep0_bounce, dwc->ep0_bounce_addr); @@ -2785,20 +2855,22 @@ void dwc3_gadget_exit(struct dwc3 *dwc) { struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; - usb_del_gadget_udc(&dwc_gadget->gadget); + if (usb_drd_get_state(dwc->dev) & DRD_DEVICE_REGISTERED) { + usb_del_gadget_udc(&dwc_gadget->gadget); - dwc3_gadget_free_endpoints(dwc); + dwc3_gadget_free_endpoints(dwc); - dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, - dwc->ep0_bounce, dwc->ep0_bounce_addr); + dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, + dwc->ep0_bounce, dwc->ep0_bounce_addr); - kfree(dwc->setup_buf); + kfree(dwc->setup_buf); - dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), - dwc->ep0_trb, dwc->ep0_trb_addr); + dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), + dwc->ep0_trb, dwc->ep0_trb_addr); - dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), - dwc->ctrl_req, dwc->ctrl_req_addr); + dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), + dwc->ctrl_req, dwc->ctrl_req_addr); + } } int dwc3_gadget_suspend(struct dwc3 *dwc)