From owner-freebsd-usb@FreeBSD.ORG Wed Apr 16 07:20:01 2014 Return-Path: Delivered-To: freebsd-usb@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A34F99D0 for ; Wed, 16 Apr 2014 07:20:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 803451774 for ; Wed, 16 Apr 2014 07:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s3G7K1g1041135 for ; Wed, 16 Apr 2014 07:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s3G7K1Ds041134; Wed, 16 Apr 2014 07:20:01 GMT (envelope-from gnats) Resent-Date: Wed, 16 Apr 2014 07:20:01 GMT Resent-Message-Id: <201404160720.s3G7K1Ds041134@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-usb@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, John Wehle Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 419F2988 for ; Wed, 16 Apr 2014 07:17:06 +0000 (UTC) Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 217B8174E for ; Wed, 16 Apr 2014 07:17:06 +0000 (UTC) Received: from cgiserv.freebsd.org ([127.0.1.6]) by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s3G7H5mu018192 for ; Wed, 16 Apr 2014 07:17:05 GMT (envelope-from nobody@cgiserv.freebsd.org) Received: (from nobody@localhost) by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s3G7H5Sw018185; Wed, 16 Apr 2014 07:17:05 GMT (envelope-from nobody) Message-Id: <201404160717.s3G7H5Sw018185@cgiserv.freebsd.org> Date: Wed, 16 Apr 2014 07:17:05 GMT From: John Wehle To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: usb/188683: dwc_otg FDT support for specifying usb controller mode X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Apr 2014 07:20:01 -0000 >Number: 188683 >Category: usb >Synopsis: dwc_otg FDT support for specifying usb controller mode >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-usb >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Apr 16 07:20:01 UTC 2014 >Closed-Date: >Last-Modified: >Originator: John Wehle >Release: 11 r264251 >Organization: Personal >Environment: Not Yet >Description: In my spare time I'm working on bringing FreeBSD up on amlogic based arm processors. The amlogic SoC contains a dwc USB controller. If I enable the controller on a Visson ATV-102 box (mine appears to be based on the aml8726-m6 SoC) which uses a GL850G usb hub chip the driver fails to detect GOTGCTL_ASESVLD so it doesn't work. The attached patch allows the mode to be specifed in the FDT ... if the mode is set to host, then the driver doesn't looks for GOTGCTL_ASESVLD ... it assumes VBUS is driven. This suffices for basic USB functionality on the Visson ATV-102. >How-To-Repeat: Build FreeBSD 11 for the Visson ATV-102 (this requires code for the amlogic platform which I'll be supplying in the future) and attempt to use USB. >Fix: Apply the patch to optionally specify the controller mode and added mode = "host"; to the usb block in vsatv102-m6.dts. Patch attached with submission follows: Index: sys/dev/usb/controller/dwc_otg_fdt.c =================================================================== --- sys/dev/usb/controller/dwc_otg_fdt.c (revision 264251) +++ sys/dev/usb/controller/dwc_otg_fdt.c (working copy) @@ -91,9 +91,27 @@ dwc_otg_attach(device_t dev) { struct dwc_otg_super_softc *sc = device_get_softc(dev); + pcell_t *prop; + phandle_t node; + ssize_t len; int err; int rid; + node = ofw_bus_get_node(dev); + len = OF_getprop_alloc(node, "mode", sizeof(char), (void **)&prop); + if (len >= 0) { + if (strcmp((char *)prop, "host") == 0) + sc->sc_otg.sc_mode = DWC_MODE_HOST; + else if (strcmp((char *)prop, "device") == 0) + sc->sc_otg.sc_mode = DWC_MODE_DEVICE; + else if (strcmp((char *)prop, "otg") == 0) + ; + else + device_printf(dev, + "ignoring unknown value for mode attribute in FDT\n"); + } + free(prop, M_OFWPROP); + /* initialise some bus fields */ sc->sc_otg.sc_bus.parent = dev; sc->sc_otg.sc_bus.devices = sc->sc_otg.sc_devices; Index: sys/dev/usb/controller/dwc_otg.c =================================================================== --- sys/dev/usb/controller/dwc_otg.c (revision 264251) +++ sys/dev/usb/controller/dwc_otg.c (working copy) @@ -2332,7 +2332,7 @@ DPRINTFN(5, "GOTGCTL=0x%08x\n", temp); - dwc_otg_vbus_interrupt(sc, + dwc_otg_vbus_interrupt(sc, (sc->sc_mode == DWC_MODE_HOST) ? 1 : (temp & (GOTGCTL_ASESVLD | GOTGCTL_BSESVLD)) ? 1 : 0); } @@ -3182,7 +3182,7 @@ sc->sc_host_ch_max); /* setup FIFO */ - if (dwc_otg_init_fifo(sc, DWC_MODE_OTG)) + if (dwc_otg_init_fifo(sc, sc->sc_mode)) return (EINVAL); /* enable interrupts */ @@ -3233,7 +3233,7 @@ DPRINTFN(5, "GOTCTL=0x%08x\n", temp); - dwc_otg_vbus_interrupt(sc, + dwc_otg_vbus_interrupt(sc, (sc->sc_mode == DWC_MODE_HOST) ? 1 : (temp & (GOTGCTL_ASESVLD | GOTGCTL_BSESVLD)) ? 1 : 0); USB_BUS_UNLOCK(&sc->sc_bus); >Release-Note: >Audit-Trail: >Unformatted: