From nobody Wed Aug 23 07:00:28 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RVxth4HvBz4rCgy; Wed, 23 Aug 2023 07:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RVxth3mndz4St5; Wed, 23 Aug 2023 07:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692774028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NmTUTwIuefMjnsR0cQ+ijXD+yyg4RwQ/v7yeIQK69Og=; b=lV7FRfS3i1Fm4Nf2DNEAhc1ZyBWb88tagD4aCy11JIvvMwun3ay+kow2eaOBRj8fPX7f8u 7mH0ZGj1sWOHO6ZjNq6kN/2xsjE02WntM8gVFzj5xZ2tZL6ewVmHeoacGJZHLLoDPIRaXt 1yY8pPFRSWxroaClV3WlGWm8wCUmgvFi37BmZV931wTBHD/FVO7Dk/SJQ39BIhwR422/Di 21orUdaB+j08i3ZBYAkh1VpcY/VhkmVG+Hbq7jH1lYJiaYQYmloLISTlzqX+mP/mAcNOCa lNwDxJhSNppOEJoFPLhVPgWIgH3W5Y8mGWlm7Yvx2HtrqTiRvNpieL9RvXQjhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692774028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NmTUTwIuefMjnsR0cQ+ijXD+yyg4RwQ/v7yeIQK69Og=; b=q/61zGU1TT++OVPnddbF/i8zELiHeeTKcCJxD2WlGM4NhbmyXfLOW6SdiPWXgbhGeyX2GL sFLjR2vSdKuItXD2X8+nFJ+pp30nxf+sUCYViQZ7dIZDl0h/ap48bkDngLE5wCeXoK2oT9 Fh7QiBlw0Ix0MDwFl3h+hc0wuwsactaDI2Sa8a+uW1D/VUuMmJksDDhLmiI1JYlNq2ZkSM OVxJKF1DKOv7rM016v6wlUokOo2Ya7DyhbwVnZkE+gPtAjP102I9nhwYiOHkLAPj9IVfgV x953l4fTFyT58rQsZQ+RYXVd7nz13rctUIEjS1MEg4SSsV7mtB+ix2TV1MmDvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692774028; a=rsa-sha256; cv=none; b=joNBYRynmWKn7Zgu1nsBgj1H3W1LVEyvwEbsV8potzG+WQxwgdb3cDDPxFyRWuiuBekSTa btLYZhsr6Ve/UH1NUkTYJkc7KQXpmejqHToQIHcs0aeNhvEs+wF5E4vZNjFiC8DyMUj4Ts 0VCWFS3y6tjiSYQh/sloSv3zGWqyf38b/Y9olvzVvFLnzXUmooGLmAEytEHqWU4YMZZEL+ R+t0muPxSWq7fOq+0GZRWFR9nKpFW2UpHOxaV9rWSbCh3C8874N/qXhH+GuHMO0W+EJGJD YHceQNw7K2CY1qsuMK0v87UndNJ9F9HiYQrKf+Bh/lIswCb90rzy/PanPEIgiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RVxth2rK2zbS9; Wed, 23 Aug 2023 07:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37N70SEi072509; Wed, 23 Aug 2023 07:00:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37N70Sm9072506; Wed, 23 Aug 2023 07:00:28 GMT (envelope-from git) Date: Wed, 23 Aug 2023 07:00:28 GMT Message-Id: <202308230700.37N70Sm9072506@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 29bfcb3a286f - main - arm64: xilinx: Add glue driver for usb3 controller List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 29bfcb3a286fcf53ae6479f735d8ed49bd4a7c1f Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=29bfcb3a286fcf53ae6479f735d8ed49bd4a7c1f commit 29bfcb3a286fcf53ae6479f735d8ed49bd4a7c1f Author: Emmanuel Vadot AuthorDate: 2023-08-23 06:58:03 +0000 Commit: Emmanuel Vadot CommitDate: 2023-08-23 07:00:05 +0000 arm64: xilinx: Add glue driver for usb3 controller Like other dwc3 controller, on Xilinx ZynqMP the base node is just here to provide resets, the main dwc3 controller node is a child node. Sponsored by: Beckhoff Automation GmbH & Co. KG --- sys/conf/files.arm64 | 1 + sys/dev/usb/controller/xlnx_dwc3.c | 149 +++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 2036bbe918ba..390d9e5db487 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -697,3 +697,4 @@ arm64/rockchip/clk/rk3568_pmucru.c optional fdt soc_rockchip_rk3568 # Xilinx arm/xilinx/uart_dev_cdnc.c optional uart soc_xilinx_zynq fdt arm/xilinx/zy7_gpio.c optional gpio soc_xilinx_zynq fdt +dev/usb/controller/xlnx_dwc3.c optional fdt xhci soc_xilinx_zynq fdt diff --git a/sys/dev/usb/controller/xlnx_dwc3.c b/sys/dev/usb/controller/xlnx_dwc3.c new file mode 100644 index 000000000000..aad929663eed --- /dev/null +++ b/sys/dev/usb/controller/xlnx_dwc3.c @@ -0,0 +1,149 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Xilinx DWC3 glue + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +static struct ofw_compat_data compat_data[] = { + { "xlnx,zynqmp-dwc3", 1 }, + { NULL, 0 } +}; + +struct xlnx_dwc3_softc { + struct simplebus_softc sc; + device_t dev; + hwreset_t rst_crst; + hwreset_t rst_hibrst; + hwreset_t rst_apbrst; +}; + +static int +xlnx_dwc3_probe(device_t dev) +{ + phandle_t node; + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + /* Binding says that we need a child node for the actual dwc3 controller */ + node = ofw_bus_get_node(dev); + if (OF_child(node) <= 0) + return (ENXIO); + + device_set_desc(dev, "Xilinx ZYNQMP DWC3"); + return (BUS_PROBE_DEFAULT); +} + +static int +xlnx_dwc3_attach(device_t dev) +{ + struct xlnx_dwc3_softc *sc; + device_t cdev; + phandle_t node, child; + + sc = device_get_softc(dev); + sc->dev = dev; + node = ofw_bus_get_node(dev); + + /* + * Put module out of reset + * Based on the bindings this should be mandatory to have + * but reality shows that they aren't always there. + * This is the case on the DTB in the AVnet Ultra96 + */ + if (hwreset_get_by_ofw_name(dev, node, "usb_crst", &sc->rst_crst) == 0) { + if (hwreset_deassert(sc->rst_crst) != 0) { + device_printf(dev, "Cannot deassert reset\n"); + return (ENXIO); + } + } + if (hwreset_get_by_ofw_name(dev, node, "usb_hibrst", &sc->rst_hibrst) == 0) { + if (hwreset_deassert(sc->rst_crst) != 0) { + device_printf(dev, "Cannot deassert reset\n"); + return (ENXIO); + } + } + if (hwreset_get_by_ofw_name(dev, node, "usb_apbrst", &sc->rst_apbrst) == 0) { + if (hwreset_deassert(sc->rst_crst) != 0) { + device_printf(dev, "Cannot deassert reset\n"); + return (ENXIO); + } + } + + simplebus_init(dev, node); + if (simplebus_fill_ranges(node, &sc->sc) < 0) { + device_printf(dev, "could not get ranges\n"); + return (ENXIO); + } + + for (child = OF_child(node); child > 0; child = OF_peer(child)) { + cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL); + if (cdev != NULL) + device_probe_and_attach(cdev); + } + + return (bus_generic_attach(dev)); +} + +static device_method_t xlnx_dwc3_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, xlnx_dwc3_probe), + DEVMETHOD(device_attach, xlnx_dwc3_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(xlnx_dwc3, xlnx_dwc3_driver, xlnx_dwc3_methods, + sizeof(struct xlnx_dwc3_softc), simplebus_driver); +DRIVER_MODULE(xlnx_dwc3, simplebus, xlnx_dwc3_driver, 0, 0);