From patchwork Sat Aug 20 13:02:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 9291719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 10BFE600CB for ; Sat, 20 Aug 2016 13:06:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB61028E63 for ; Sat, 20 Aug 2016 13:06:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE5C428E96; Sat, 20 Aug 2016 13:06:02 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D1A2428E63 for ; Sat, 20 Aug 2016 13:06:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bb5vx-00055W-VY; Sat, 20 Aug 2016 13:03:34 +0000 Received: from mout.kundenserver.de ([212.227.126.134]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bb5vs-00054Z-49; Sat, 20 Aug 2016 13:03:29 +0000 Received: from oxbsltgw03.schlund.de ([172.19.249.20]) by mrelayeu.kundenserver.de (mreue005) with ESMTPSA (Nemesis) id 0MMrhT-1bWPU81wwp-008bp5; Sat, 20 Aug 2016 15:02:55 +0200 Date: Sat, 20 Aug 2016 15:02:50 +0200 (CEST) From: Stefan Wahren To: John Youn Message-ID: <907297251.436328.d9cd30e0-7476-4a28-8bab-dde17515cd9c.open-xchange@email.1und1.de> Subject: [Bug] usb: dwc2: host function broken in OTG mode on bcm283x MIME-Version: 1.0 X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.0-Rev36 X-Originating-Client: open-xchange-appsuite X-Provags-ID: V03:K0:k6pUYJ7rf62v80m0Q6T5n8Fh4UP4b6g8ygA5LZd/Big1H3cGYBh g2TId6mCjsBQvX1ZmEqV8yxN7SfQQLm66Wa3+ZUr9hc0RHaTZTQJNze9dykjYBVmxIXe+xc foYT/GvbG/4waBO0G5HUdBr2UKdRVhn0DX/xmwjySDEPrLEZ+CJwN461pN66owOhQW9TCTI 14r4fif53jDW64dAeb0qw== X-UI-Out-Filterresults: notjunk:1; V01:K0:siYWsWyoxDo=:JvnSqZfsOJsW64ZRmz18OW dPvYwFnUOnVVtcbfuGjNpHl99wugK168pbB7enj24hXwPxecAJqdfzFDRcaZcWGYyIYGPbgKw cv00bhAFVrC4PqqlLkxwpLZdJq+NbnyhWLPz0TOnekaFl6zSg6MvZKgx0PlwnAmqkziWtA08R tj98H3ImJzsVL+EnomS2FMTeVNUWvQ/blcY+/PRA1tVbWaKg/08bEjijTDRE06qmil2e+VN4X R+LabBSCpMZHqp0/h7WoWeu3W2/MwMdyJjJty4lne1Sms0TQ3B9HH14Mqz40MZNmY64IZAgLl Req9MghCAPlKy/AjU8GuCKfHBkBtzZglbfOSnGkfCnQl2loPzU4g169bz29Mghw6edGK9JT4W HeJMHAzKCNBVXw3WT5h4I2uy+qgXYGwYAfDimLPIsI5BMK9YJLZgmp6bu0R1Qh3ZmvxbFZJU3 GBgn4DcolTuvFhWQBoEK6ZWahMxG+luKyquiARTGdp4ET4Pe6m/6VPiBvCeAVvWSAEyVS7E3f ZyplvEkFlYvmytd2mvVoLNm2z4zm5FxTp5YekJEUj+Y8Swrif4SZiIPp8AKMGbW05rxifD/2H IbkQBe9zBv781QIGPfdy8CVJNiqIJaRgknZkcZZU/k3tZqU860syDffpnEkYgE2qLuImPZQev MDDoOfLp9J1yrcidIer/6y6BqN+bvXILnrxnErPMhOmATmdnWNkv+YJ2M70Hbqk7QLwCqOisg nmcH7xZlc9aUWV0Y X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160820_060328_507417_180EB49D X-CRM114-Status: GOOD ( 11.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Felipe Balbi , Vardan Mikayelyan , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Eric Anholt , linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi John, on bcm2835 in OTG mode the USB host function broken (USB devices don't enumerate) with the following settings: CONFIG_USB=y CONFIG_USB_OTG=y CONFIG_USB_DWC2=y CONFIG_USB_DWC2_DUAL_ROLE=y CONFIG_USB_PHY=y CONFIG_NOP_USB_XCEIV=y CONFIG_USB_GADGET=y CONFIG_USB_ZERO=y and DT don't provide any optional gadget fifo settings. During boot the kernel give a warning about insufficient fifo memory. Here is the relevant log with some debug messages: [ 2.373718] dwc2_lowlevel_hw_init() [ 2.389306] dwc2_set_all_params() [ 2.404927] dwc2_lowlevel_hw_enable() [ 2.420331] dwc2_get_dr_mode() [ 2.434894] dwc2_get_dr_mode: OF suggests 3 [ 2.450592] dwc2_get_dr_mode: No PHY found [ 2.466161] dwc2_core_reset_and_force_dr_mode() [ 2.517779] mmc0: new SDHC card at address 1234 [ 2.535005] mmcblk0: mmc0:1234 SA32G 29.3 GiB [ 2.553421] mmcblk0: p1 p2 [ 2.619213] dwc2_get_hwparams() [ 2.633611] dwc2 20980000.usb: Core Release: 2.80a (snpsid=4f54280a) [ 2.633628] dwc2 20980000.usb: hwcfg1=00000000 [ 2.633640] dwc2 20980000.usb: hwcfg2=228ddd50 [ 2.633651] dwc2 20980000.usb: hwcfg3=0ff000e8 [ 2.633663] dwc2 20980000.usb: hwcfg4=1ff00020 [ 2.633674] dwc2 20980000.usb: grxfsiz=00001000 [ 2.633688] dwc2 20980000.usb: gnptxfsiz=01001000 [ 2.633698] dwc2 20980000.usb: hptxfsiz=02002000 [ 2.633710] dwc2 20980000.usb: Forcing mode to device [ 2.679241] dwc2 20980000.usb: gnptxfsiz=01001000 [ 2.729220] dwc2 20980000.usb: Detected values from hardware: [ 2.729237] dwc2 20980000.usb: op_mode=0 [ 2.729249] dwc2 20980000.usb: arch=2 [ 2.729259] dwc2 20980000.usb: dma_desc_enable=0 [ 2.729271] dwc2 20980000.usb: power_optimized=0 [ 2.729285] dwc2 20980000.usb: i2c_enable=0 [ 2.729294] dwc2 20980000.usb: hs_phy_type=1 [ 2.729305] dwc2 20980000.usb: fs_phy_type=1 [ 2.729315] dwc2 20980000.usb: utmi_phy_data_width=0 [ 2.729325] dwc2 20980000.usb: num_dev_ep=7 [ 2.729335] dwc2 20980000.usb: num_dev_perio_in_ep=0 [ 2.729345] dwc2 20980000.usb: host_channels=8 [ 2.729356] dwc2 20980000.usb: max_transfer_size=524287 [ 2.729367] dwc2 20980000.usb: max_packet_count=1023 [ 2.729377] dwc2 20980000.usb: nperio_tx_q_depth=0x4 [ 2.729387] dwc2 20980000.usb: host_perio_tx_q_depth=0x4 [ 2.729398] dwc2 20980000.usb: dev_token_q_depth=0x8 [ 2.729408] dwc2 20980000.usb: enable_dynamic_fifo=1 [ 2.729418] dwc2 20980000.usb: en_multiple_tx_fifo=1 [ 2.729429] dwc2 20980000.usb: total_fifo_size=4080 [ 2.729439] dwc2 20980000.usb: host_rx_fifo_size=4096 [ 2.729450] dwc2 20980000.usb: host_nperio_tx_fifo_size=256 [ 2.729461] dwc2 20980000.usb: host_perio_tx_fifo_size=512 [ 2.729469] dwc2 20980000.usb: [ 2.729474] dwc2_set_parameters() [ 2.743824] dwc2 20980000.usb: dwc2_set_parameters() [ 2.743848] dwc2 20980000.usb: Setting dma_desc_fs_enable to 0 [ 2.743881] dwc2 20980000.usb: Setting external_id_pin_ctl to 0 [ 2.743895] dwc2 20980000.usb: Setting hibernation to 0 [ 2.743899] dwc2_force_dr_mode() [ 2.869216] dwc2_gadget_init() [ 2.883027] dwc2 20980000.usb: Specified GNPTXFDEP=1024 > 256 [ 2.899480] dwc2 20980000.usb: NonPeriodic TXFIFO size: 256 [ 2.899497] dwc2 20980000.usb: RXFIFO size: 2048 [ 2.899511] dwc2 20980000.usb: Periodic TXFIFO 0 size: 0 [ 2.899523] dwc2 20980000.usb: Periodic TXFIFO 1 size: 256 [ 2.899536] dwc2 20980000.usb: Periodic TXFIFO 2 size: 256 [ 2.899547] dwc2 20980000.usb: Periodic TXFIFO 3 size: 256 [ 2.899559] dwc2 20980000.usb: Periodic TXFIFO 4 size: 256 [ 2.899572] dwc2 20980000.usb: Periodic TXFIFO 5 size: 768 [ 2.899584] dwc2 20980000.usb: Periodic TXFIFO 6 size: 768 [ 2.899595] dwc2 20980000.usb: Periodic TXFIFO 7 size: 768 [ 2.899607] dwc2 20980000.usb: Periodic TXFIFO 8 size: 768 [ 2.899619] dwc2 20980000.usb: Periodic TXFIFO 9 size: 0 [ 2.899630] dwc2 20980000.usb: Periodic TXFIFO10 size: 0 [ 2.899640] dwc2 20980000.usb: Periodic TXFIFO11 size: 0 [ 2.899652] dwc2 20980000.usb: Periodic TXFIFO12 size: 0 [ 2.899662] dwc2 20980000.usb: Periodic TXFIFO13 size: 0 [ 2.899674] dwc2 20980000.usb: Periodic TXFIFO14 size: 0 [ 2.899686] dwc2 20980000.usb: Periodic TXFIFO15 size: 0 [ 2.899720] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM [ 2.918197] zero gadget: Gadget Zero, version: Cinco de Mayo 2008 [ 2.935109] zero gadget: zero ready [ 2.949235] ------------[ cut here ]------------ [ 2.964357] WARNING: CPU: 0 PID: 6 at drivers/usb/dwc2/gadget.c:227 dwc2_hsotg_init_fifo+0xd0/0x1ac [ 2.984089] insufficient fifo memory [ 2.987649] CPU: 0 PID: 6 Comm: kworker/u2:0 Not tainted 4.7.0-rc7-next-20160719+ #29 [ 3.016940] Hardware name: BCM2835 [ 3.031145] Workqueue: deferwq deferred_probe_work_func [ 3.047436] [] (unwind_backtrace) from [] (show_stack+0x20/0x24) [ 3.066350] [] (show_stack) from [] (dump_stack+0x20/0x28) [ 3.084726] [] (dump_stack) from [] (__warn+0xe0/0x10c) [ 3.102866] [] (__warn) from [] (warn_slowpath_fmt+0x48/0x50) [ 3.121564] [] (warn_slowpath_fmt) from [] (dwc2_hsotg_init_fifo+0xd0/0x1ac) [ 3.141678] [] (dwc2_hsotg_init_fifo) from [] (dwc2_hsotg_udc_start+0x1e4/0x2b8) [ 3.162222] [] (dwc2_hsotg_udc_start) from [] (udc_bind_to_driver+0x60/0x108) [ 3.182462] [] (udc_bind_to_driver) from [] (usb_add_gadget_udc_release+0x144/0x244) [ 3.203338] [] (usb_add_gadget_udc_release) from [] (usb_add_gadget_udc+0x1c/0x20) [ 3.224024] [] (usb_add_gadget_udc) from [] (dwc2_gadget_init+0x460/0x4f8) [ 3.244022] [] (dwc2_gadget_init) from [] (dwc2_driver_probe+0x360/0x4bc) [ 3.264058] [] (dwc2_driver_probe) from [] (platform_drv_probe+0x68/0xb0) [ 3.284186] [] (platform_drv_probe) from [] (driver_probe_device+0x180/0x42c) [ 3.304727] [] (driver_probe_device) from [] (__device_attach_driver+0xc0/0x108) [ 3.325628] [] (__device_attach_driver) from [] (bus_for_each_drv+0x5c/0xa4) [ 3.346260] [] (bus_for_each_drv) from [] (__device_attach+0x9c/0x138) [ 3.366460] [] (__device_attach) from [] (device_initial_probe+0x1c/0x20) [ 3.386971] [] (device_initial_probe) from [] (bus_probe_device+0x38/0x90) [ 3.407720] [] (bus_probe_device) from [] (deferred_probe_work_func+0x5c/0xa4) [ 3.429054] [] (deferred_probe_work_func) from [] (process_one_work+0x1d0/0x37c) [ 3.450717] [] (process_one_work) from [] (worker_thread+0x294/0x414) [ 3.471563] [] (worker_thread) from [] (kthread+0xec/0x100) [ 3.491662] [] (kthread) from [] (ret_from_fork+0x14/0x3c) [ 3.511770] ---[ end trace 00841c75e25fed43 ]--- [ 3.532627] dwc2 20980000.usb: bound driver zero ... [ 4.092616] dwc2_hcd_init() [ 4.108117] dwc2 20980000.usb: DWC OTG Controller [ 4.125318] dwc2 20980000.usb: new USB bus registered, assigned bus number 1 [ 4.144876] dwc2 20980000.usb: irq 33, io mem 0x00000000 [ 4.164367] hub 1-0:1.0: USB hub found [ 4.180746] hub 1-0:1.0: 1 port detected Since there are no gadget fifo sizes specified the dwc2 drivers uses legacy settings. I think there are 2 causes for this warning: 1. The array behind DWC2_G_P_LEGACY_TX_FIFO_SIZE specify 8 values plus the separate ep0 which makes in sum 9 EPs. So dwc2_hsotg_init_fifo tries to setup 9 EPs with legacy settings. But bcm2835 only support 8 EPs. I don't know of any platform with less EPs. 2. The legacy settings for gadget are to high. They need to be adjusted to the "smallest" platform. Here is a patch which fixes the problem (USB devices enumerate and warning disappear) for me: diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 9fae029..289ad3c 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -263,8 +263,8 @@ enum dwc2_lx_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} +#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 128, 128, 64, 64, 64, 64, \ + 0, 0, 0, 0, 0, 0, 0, 0} /* Gadget ep0 states */ enum dwc2_ep0_state { diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index af46adf..2d0bc2a 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3868,8 +3868,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) 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; + hsotg->g_rx_fifo_sz = 256; + hsotg->g_np_g_tx_fifo_sz = 128; memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); /* Device tree specific probe */ dwc2_hsotg_of_probe(hsotg);