From patchwork Thu Aug 1 23:27:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 264155 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3EE9C2C008C for ; Fri, 2 Aug 2013 09:30:06 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BADBD4A088; Fri, 2 Aug 2013 01:29:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0Lx1mda+1HMh; Fri, 2 Aug 2013 01:29:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 075454A08A; Fri, 2 Aug 2013 01:28:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E5FDF4A049 for ; Fri, 2 Aug 2013 01:28:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PHOM77pJAx5i for ; Fri, 2 Aug 2013 01:28:13 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by theia.denx.de (Postfix) with ESMTPS id B01814A051 for ; Fri, 2 Aug 2013 01:27:52 +0200 (CEST) Received: by mail-pa0-f51.google.com with SMTP id lf11so2686898pab.24 for ; Thu, 01 Aug 2013 16:27:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=vN6l3Kzo+W6G7j8S7ypE+5T6WIpA5x6Lsp6hDiTNeV0=; b=mLCD9jpPMYdLLdqxP9VlZOq3DGlwZqLnaUFvAMRwhRU4PaDJgjpZuV/GSvGwYgH9s5 q8gLM4PYVLrq5akaUKR9QNkviXtazDVcTp+J5YrOqDSx36IK2NfuJ00FdQ5HfSZPITNm QYA4O0ukzJVffObvKGPIHI7ELzwD4UosaDvT9yFUEeFY1+IXesWqQCcNlJ+rouVL3WLP e87g1PQijWuva2yKQ3ZmgjGyzlNfKz2XQIZTWjbxFVNo7oTTaWmqo8N1ouz0kzLA1e7s TfdfbeG+dCTMS+H/ev4w2nPACPN7mi9DTcHFwYICviou8DQRfXrOyqVBG2HAVkHW7qBM b1BQ== X-Received: by 10.66.242.17 with SMTP id wm17mr7237419pac.102.1375399670795; Thu, 01 Aug 2013 16:27:50 -0700 (PDT) Received: from officeserver-2 ([70.96.116.236]) by mx.google.com with ESMTPSA id lk9sm5305899pab.2.2013.08.01.16.27.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 01 Aug 2013 16:27:49 -0700 (PDT) Received: from tkisky by officeserver-2 with local (Exim 4.80) (envelope-from ) id 1V52HX-0006hU-OC; Thu, 01 Aug 2013 16:27:43 -0700 From: Troy Kisky To: marek.vasut@gmail.com Date: Thu, 1 Aug 2013 16:27:32 -0700 Message-Id: <1375399657-25642-16-git-send-email-troy.kisky@boundarydevices.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375399657-25642-1-git-send-email-troy.kisky@boundarydevices.com> References: <1375399657-25642-1-git-send-email-troy.kisky@boundarydevices.com> X-Gm-Message-State: ALoCoQkaMSFWWnPeQFfzCqBuFwzjfvehrVtpAvXlXqC8yYxvH4pMIZjI+7Q0F/+BA5LU6mF4qoyP Cc: fabio.estevam@freescale.com, otavio@ossystems.com.br, leiwen@marvell.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH V3 15/20] usb: gadget: mv_udc: fix full speed connections X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Set maximum packet length in queue header to wMaxPacketSize of endpoint. Signed-off-by: Troy Kisky --- drivers/usb/gadget/mv_udc.c | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index fcfbfa3..c9bd0a7 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -228,7 +229,7 @@ static void mv_ep_free_request(struct usb_ep *ep, struct usb_request *_req) return; } -static void ep_enable(int num, int in) +static void ep_enable(int num, int in, int maxpacket) { struct ept_queue_head *head; struct mv_udc *udc = get_mv_udc(); @@ -242,7 +243,7 @@ static void ep_enable(int num, int in) n |= (CTRL_RXE | CTRL_RXR | CTRL_RXT_BULK); if (num != 0) { - head->config = CONFIG_MAX_PKT(EP_MAX_PACKET_SIZE) | CONFIG_ZLT; + head->config = CONFIG_MAX_PKT(maxpacket) | CONFIG_ZLT; mv_flush_qh(num); } writel(n, &udc->epctrl[num]); @@ -255,8 +256,21 @@ static int mv_ep_enable(struct usb_ep *ep, int num, in; num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; in = (desc->bEndpointAddress & USB_DIR_IN) != 0; - ep_enable(num, in); mv_ep->desc = desc; + + if (num) { + int max = get_unaligned_le16(&desc->wMaxPacketSize); + + if ((max > 64) && (controller.gadget.speed == USB_SPEED_FULL)) + max = 64; + if (ep->maxpacket != max) { + DBG("%s: from %d to %d\n", __func__, + ep->maxpacket, max); + ep->maxpacket = max; + } + } + ep_enable(num, in, ep->maxpacket); + DBG("%s: num=%d maxpacket=%d\n", __func__, num, ep->maxpacket); return 0; } @@ -429,14 +443,16 @@ static void handle_setup(void) if ((r.wValue == 0) && (r.wLength == 0)) { req->length = 0; for (i = 0; i < NUM_ENDPOINTS; i++) { - if (!controller.ep[i].desc) + struct mv_ep *ep = &controller.ep[i]; + + if (!ep->desc) continue; - num = controller.ep[i].desc->bEndpointAddress + num = ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; - in = (controller.ep[i].desc->bEndpointAddress + in = (ep->desc->bEndpointAddress & USB_DIR_IN) != 0; if ((num == _num) && (in == _in)) { - ep_enable(num, in); + ep_enable(num, in, ep->ep.maxpacket); usb_ep_queue(controller.gadget.ep0, req, 0); break; @@ -520,15 +536,19 @@ void udc_irq(void) DBG("-- suspend --\n"); if (n & STS_PCI) { - DBG("-- portchange --\n"); + int max = 64; + int speed = USB_SPEED_FULL; + bit = (readl(&udc->portsc) >> 26) & 3; + DBG("-- portchange %x %s\n", bit, (bit == 2) ? "High" : "Full"); if (bit == 2) { - controller.gadget.speed = USB_SPEED_HIGH; - for (i = 1; i < NUM_ENDPOINTS && n; i++) - if (controller.ep[i].desc) - controller.ep[i].ep.maxpacket = 512; - } else { - controller.gadget.speed = USB_SPEED_FULL; + speed = USB_SPEED_HIGH; + max = 512; + } + controller.gadget.speed = speed; + for (i = 1; i < NUM_ENDPOINTS; i++) { + if (controller.ep[i].ep.maxpacket > max) + controller.ep[i].ep.maxpacket = max; } }