From patchwork Fri Oct 28 15:51:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 79970 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1246322qge; Fri, 28 Oct 2016 08:52:01 -0700 (PDT) X-Received: by 10.98.69.151 with SMTP id n23mr25947914pfi.60.1477669921903; Fri, 28 Oct 2016 08:52:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xz9si11841915pac.183.2016.10.28.08.52.01; Fri, 28 Oct 2016 08:52:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756517AbcJ1Pv7 (ORCPT + 4 others); Fri, 28 Oct 2016 11:51:59 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36052 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751856AbcJ1Pv6 (ORCPT ); Fri, 28 Oct 2016 11:51:58 -0400 Received: by mail-pf0-f179.google.com with SMTP id e6so39252812pfk.3 for ; Fri, 28 Oct 2016 08:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=k3IaK0lH7KP+4MbLfAW01qo+P9ZZomzaAsQnpYYReaA=; b=eDTqgn2MZXSw6+y0zlmNbys0Ita35rW78EDndtlAcDfoXH8YiHm0gcd5j70f06OgH1 hEUzlzqfxladXjgEZ2l1TiECP8xJ3nfh4T6kiatT39V2vuhgezBlXq/6BlO+P1fsvhAV +Qhv60CSeS+PlW27ER6vrAWdUCNyKmAAE4pQ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=k3IaK0lH7KP+4MbLfAW01qo+P9ZZomzaAsQnpYYReaA=; b=O2wsnHN8mbXGaeoGVED7Zxs93bocOFCi8xoa9xj1cWOB1IGMz0bS0BFrMVuRCWZr4Q Gjq17ND1qIcSROiS9+5GImpx3mMffk6hLkAkyQF5gGfv98KFZjINAl6+s1pkHgYyLL8s mQZa9FgR3H7gXFtO5IavPj0cf5Ron5LRXTA4veUoBwfuVofL1K/ei/espcuSxY10l8xX i/wT7gy23bvv23EIJwfbRY44K2rWSxlHOJasHmYuTRtr9irwlr+KInAxDE9Ih0jmq93G PPK3RYhnFJwlaNFLoBOztiWoWBaQCVxUnAYJzWZ4mxf4I1u/Sb1PP7EMyh1GQLYnvffL sADA== X-Gm-Message-State: ABUngvd15cZyAeafQIU52HfTFTdaKYLvXCDdSB528Ck7mQ4D/DZSTRVYgnw35EIF8SoXy4kZ X-Received: by 10.99.143.70 with SMTP id r6mr21232308pgn.54.1477669918062; Fri, 28 Oct 2016 08:51:58 -0700 (PDT) Received: from localhost.localdomain ([69.46.80.35]) by smtp.gmail.com with ESMTPSA id v6sm17951057paz.45.2016.10.28.08.51.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Oct 2016 08:51:57 -0700 (PDT) From: Leo Yan To: John Youn , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, John Stultz , Guodong Xu , zhangfei.gao@linaro.org, Vincent Guittot , Steve Muckle , Dietmar Eggemann , Robert Baldyga Cc: Leo Yan Subject: [PATCH] Revert "usb: dwc2: gadget: fix TX FIFO size and address initialization" Date: Fri, 28 Oct 2016 23:51:42 +0800 Message-Id: <1477669902-24032-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit aa381a7259c3f53727bcaa8c5f9359e940a0e3fd. Reverting this patch, as it incorrectly assumes TX FIFO size is fixed and cannot change FIFO size; it removes all related dt binding code and have no chance to set FIFO size at init phase. As result, Hi6220 cannot set correct FIFO size for gadget driver and ethernet on USB function driver is easily to hang. And in the kernel there also have other platforms set FIFO size for usb controller, e.g. arch/arm64/boot/dts/rockchip/rk3368.dtsi. This patch re-enables dt binding to set FIFO size. Signed-off-by: Leo Yan --- drivers/usb/dwc2/core.h | 7 +++++++ drivers/usb/dwc2/gadget.c | 53 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 11 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index aad4107..2a21a04 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -259,6 +259,13 @@ enum dwc2_lx_state { DWC2_L3, /* Off state */ }; +/* + * Gadget periodic tx fifo sizes as used by legacy driver + * EP0 is not included + */ +#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \ + 768, 0, 0, 0, 0, 0, 0, 0} + /* Gadget ep0 states */ enum dwc2_ep0_state { DWC2_EP0_SETUP, diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 4cd6403..24fbebc 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -186,10 +186,9 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, */ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) { - unsigned int fifo; + unsigned int ep; unsigned int addr; int timeout; - u32 dptxfsizn; u32 val; /* Reset fifo map if not correctly cleared during previous session */ @@ -217,16 +216,16 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) * them to endpoints dynamically according to maxpacket size value of * given endpoint. */ - for (fifo = 1; fifo < MAX_EPS_CHANNELS; fifo++) { - dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)); - - val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr; - addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT; - - if (addr > hsotg->fifo_mem) - break; + for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) { + if (!hsotg->g_tx_fifo_sz[ep]) + continue; + val = addr; + val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT; + WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem, + "insufficient fifo memory"); + addr += hsotg->g_tx_fifo_sz[ep]; - dwc2_writel(val, hsotg->regs + DPTXFSIZN(fifo)); + dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep)); } /* @@ -3807,10 +3806,36 @@ static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg) static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) { struct device_node *np = hsotg->dev->of_node; + u32 len = 0; + u32 i = 0; /* Enable dma if requested in device tree */ hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); + /* + * Register TX periodic fifo size per endpoint. + * EP0 is excluded since it has no fifo configuration. + */ + if (!of_find_property(np, "g-tx-fifo-size", &len)) + goto rx_fifo; + + len /= sizeof(u32); + + /* Read tx fifo sizes other than ep0 */ + if (of_property_read_u32_array(np, "g-tx-fifo-size", + &hsotg->g_tx_fifo_sz[1], len)) + goto rx_fifo; + + /* Add ep0 */ + len++; + + /* Make remaining TX fifos unavailable */ + if (len < MAX_EPS_CHANNELS) { + for (i = len; i < MAX_EPS_CHANNELS; i++) + hsotg->g_tx_fifo_sz[i] = 0; + } + +rx_fifo: /* Register RX fifo size */ of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); @@ -3832,10 +3857,13 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) struct device *dev = hsotg->dev; int epnum; int ret; + int i; + u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE; /* Initialize to legacy fifo configuration values */ hsotg->g_rx_fifo_sz = 2048; hsotg->g_np_g_tx_fifo_sz = 1024; + memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); /* Device tree specific probe */ dwc2_hsotg_of_probe(hsotg); @@ -3853,6 +3881,9 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", hsotg->g_np_g_tx_fifo_sz); dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); + for (i = 0; i < MAX_EPS_CHANNELS; i++) + dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i, + hsotg->g_tx_fifo_sz[i]); hsotg->gadget.max_speed = USB_SPEED_HIGH; hsotg->gadget.ops = &dwc2_hsotg_gadget_ops;