Author: manu
Date: Thu Oct  3 18:53:03 2019
New Revision: 353062
URL: https://svnweb.freebsd.org/changeset/base/353062

Log:
  Split out the attachment from the generic-ehci driver
  
  Create an attachment file for the existing ACPI attachment, and create a
  new FDT attachment for the generic-ehci driver.
  
  Submitted by: andrew (Original version)
  MFC after:    1 month
  Differential Revision:        https://reviews.freebsd.org/D19389

Added:
  head/sys/dev/usb/controller/generic_ehci.h   (contents, props changed)
  head/sys/dev/usb/controller/generic_ehci_acpi.c   (contents, props changed)
  head/sys/dev/usb/controller/generic_ehci_fdt.c   (contents, props changed)
Modified:
  head/sys/conf/files.arm64
  head/sys/dev/usb/controller/generic_ehci.c

Modified: head/sys/conf/files.arm64
==============================================================================
--- head/sys/conf/files.arm64   Thu Oct  3 18:50:57 2019        (r353061)
+++ head/sys/conf/files.arm64   Thu Oct  3 18:53:03 2019        (r353062)
@@ -245,7 +245,9 @@ dev/uart/uart_dev_mu.c              optional        uart 
uart_mu
 dev/uart/uart_dev_pl011.c      optional        uart pl011
 dev/usb/controller/dwc_otg_hisi.c optional     dwcotg fdt soc_hisi_hi6220
 dev/usb/controller/ehci_mv.c   optional        ehci_mv fdt
-dev/usb/controller/generic_ehci.c optional     ehci acpi
+dev/usb/controller/generic_ehci.c optional     ehci
+dev/usb/controller/generic_ehci_acpi.c optional        ehci acpi
+dev/usb/controller/generic_ehci_fdt.c optional ehci fdt
 dev/usb/controller/generic_ohci.c optional     ohci fdt
 dev/usb/controller/generic_usb_if.m optional   ohci fdt
 dev/usb/controller/usb_nop_xceiv.c     optional fdt ext_resources

Modified: head/sys/dev/usb/controller/generic_ehci.c
==============================================================================
--- head/sys/dev/usb/controller/generic_ehci.c  Thu Oct  3 18:50:57 2019        
(r353061)
+++ head/sys/dev/usb/controller/generic_ehci.c  Thu Oct  3 18:53:03 2019        
(r353062)
@@ -60,27 +60,9 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb/controller/ehci.h>
 #include <dev/usb/controller/ehcireg.h>
 
-#include <contrib/dev/acpica/include/acpi.h>
-#include <contrib/dev/acpica/include/accommon.h>
-#include <dev/acpica/acpivar.h>
+#include "generic_ehci.h"
 
-static device_attach_t generic_ehci_attach;
-static device_detach_t generic_ehci_detach;
-
-static int
-generic_ehci_probe(device_t self)
-{
-       ACPI_HANDLE h;
-
-       if ((h = acpi_get_handle(self)) == NULL ||
-           !acpi_MatchHid(h, "PNP0D20"))
-               return (ENXIO);
-
-       device_set_desc(self, "Generic EHCI Controller");
-       return (BUS_PROBE_DEFAULT);
-}
-
-static int
+int
 generic_ehci_attach(device_t self)
 {
        ehci_softc_t *sc = device_get_softc(self);
@@ -152,7 +134,7 @@ error:
        return (ENXIO);
 }
 
-static int
+int
 generic_ehci_detach(device_t self)
 {
        ehci_softc_t *sc = device_get_softc(self);
@@ -192,7 +174,6 @@ generic_ehci_detach(device_t self)
 
 static device_method_t ehci_methods[] = {
        /* Device interface */
-       DEVMETHOD(device_probe,         generic_ehci_probe),
        DEVMETHOD(device_attach,        generic_ehci_attach),
        DEVMETHOD(device_detach,        generic_ehci_detach),
        DEVMETHOD(device_suspend,       bus_generic_suspend),
@@ -202,13 +183,8 @@ static device_method_t ehci_methods[] = {
        DEVMETHOD_END
 };
 
-static driver_t ehci_driver = {
+driver_t generic_ehci_driver = {
        .name = "ehci",
        .methods = ehci_methods,
        .size = sizeof(ehci_softc_t),
 };
-
-static devclass_t ehci_devclass;
-
-DRIVER_MODULE(ehci, acpi, ehci_driver, ehci_devclass, 0, 0);
-MODULE_DEPEND(ehci, usb, 1, 1, 1);

Added: head/sys/dev/usb/controller/generic_ehci.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/usb/controller/generic_ehci.h  Thu Oct  3 18:53:03 2019        
(r353062)
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2012 Ganbold Tsagaankhuu <ganb...@freebsd.org>
+ * Copyright (c) 2016 The FreeBSD Foundation
+ * Copyright (c) 2019 Andrew Turner <and...@freebsd.org>
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _GENERIC_EHCI_H_
+#define        _GENERIC_EHCI_H_
+
+extern driver_t generic_ehci_driver;
+
+device_attach_t generic_ehci_attach;
+device_detach_t generic_ehci_detach;
+
+#endif /* !_GENERIC_EHCI_H_ */

Added: head/sys/dev/usb/controller/generic_ehci_acpi.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/usb/controller/generic_ehci_acpi.c     Thu Oct  3 18:53:03 
2019        (r353062)
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 2012 Ganbold Tsagaankhuu <ganb...@freebsd.org>
+ * Copyright (c) 2016 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_bus.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+
+#include <dev/usb/usb_core.h>
+#include <dev/usb/usb_busdma.h>
+#include <dev/usb/usb_process.h>
+
+#include <dev/usb/usb_controller.h>
+#include <dev/usb/usb_bus.h>
+#include <dev/usb/controller/ehci.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
+#include <contrib/dev/acpica/include/accommon.h>
+#include <dev/acpica/acpivar.h>
+
+#include "generic_ehci.h"
+
+static int
+generic_ehci_acpi_probe(device_t self)
+{
+       ACPI_HANDLE h;
+
+       if ((h = acpi_get_handle(self)) == NULL ||
+           !acpi_MatchHid(h, "PNP0D20"))
+               return (ENXIO);
+
+       device_set_desc(self, "Generic EHCI Controller");
+       return (BUS_PROBE_DEFAULT);
+}
+
+static device_method_t ehci_acpi_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         generic_ehci_acpi_probe),
+
+       DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(ehci, ehci_acpi_driver, ehci_acpi_methods,
+    sizeof(ehci_softc_t), generic_ehci_driver);
+
+static devclass_t ehci_acpi_devclass;
+
+DRIVER_MODULE(ehci, acpi, ehci_acpi_driver, ehci_acpi_devclass, 0, 0);
+MODULE_DEPEND(ehci, usb, 1, 1, 1);

Added: head/sys/dev/usb/controller/generic_ehci_fdt.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/usb/controller/generic_ehci_fdt.c      Thu Oct  3 18:53:03 
2019        (r353062)
@@ -0,0 +1,255 @@
+/*-
+ * Copyright (c) 2012 Ganbold Tsagaankhuu <ganb...@freebsd.org>
+ * Copyright (c) 2016 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_bus.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+
+#include <dev/usb/usb_core.h>
+#include <dev/usb/usb_busdma.h>
+#include <dev/usb/usb_process.h>
+
+#include <dev/usb/usb_controller.h>
+#include <dev/usb/usb_bus.h>
+#include <dev/usb/controller/ehci.h>
+
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#ifdef EXT_RESOURCES
+#include <dev/extres/clk/clk.h>
+#include <dev/extres/hwreset/hwreset.h>
+#include <dev/extres/phy/phy.h>
+#include <dev/extres/phy/phy_usb.h>
+#endif
+
+#include "generic_ehci.h"
+
+#ifdef EXT_RESOURCES
+struct clk_list {
+       TAILQ_ENTRY(clk_list)   next;
+       clk_t                   clk;
+};
+
+
+struct hwrst_list {
+       TAILQ_ENTRY(hwrst_list) next;
+       hwreset_t               rst;
+};
+
+struct phy_list {
+       TAILQ_ENTRY(phy_list)   next;
+       phy_t                   phy;
+};
+#endif
+
+struct generic_ehci_fdt_softc {
+       ehci_softc_t    ehci_sc;
+
+#ifdef EXT_RESOURCES
+       TAILQ_HEAD(, clk_list)  clk_list;
+       TAILQ_HEAD(, hwrst_list)        rst_list;
+       TAILQ_HEAD(, phy_list)          phy_list;
+#endif
+};
+
+static device_probe_t generic_ehci_fdt_probe;
+static device_attach_t generic_ehci_fdt_attach;
+static device_detach_t generic_ehci_fdt_detach;
+
+static int
+generic_ehci_fdt_probe(device_t self)
+{
+
+       if (!ofw_bus_status_okay(self))
+               return (ENXIO);
+
+       if (!ofw_bus_is_compatible(self, "generic-ehci"))
+               return (ENXIO);
+
+       device_set_desc(self, "Generic EHCI Controller");
+       return (BUS_PROBE_DEFAULT);
+}
+
+static int
+generic_ehci_fdt_attach(device_t dev)
+{
+#ifdef EXT_RESOURCES
+       struct generic_ehci_fdt_softc *sc;
+       struct clk_list *clkp;
+       clk_t clk;
+       struct hwrst_list *rstp;
+       hwreset_t rst;
+       struct phy_list *phyp;
+       phy_t phy;
+       int err, off;
+
+       sc = device_get_softc(dev);
+
+       TAILQ_INIT(&sc->clk_list);
+       /* Enable clock */
+       for (off = 0; clk_get_by_ofw_index(dev, 0, off, &clk) == 0; off++) {
+               err = clk_enable(clk);
+               if (err != 0) {
+                       device_printf(dev, "Could not enable clock %s\n",
+                           clk_get_name(clk));
+                       goto error;
+               }
+               clkp = malloc(sizeof(*clkp), M_DEVBUF, M_WAITOK | M_ZERO);
+               clkp->clk = clk;
+               TAILQ_INSERT_TAIL(&sc->clk_list, clkp, next);
+       }
+
+       /* De-assert reset */
+       TAILQ_INIT(&sc->rst_list);
+       for (off = 0; hwreset_get_by_ofw_idx(dev, 0, off, &rst) == 0; off++) {
+               err = hwreset_deassert(rst);
+               if (err != 0) {
+                       device_printf(dev, "Could not de-assert reset\n");
+                       goto error;
+               }
+               rstp = malloc(sizeof(*rstp), M_DEVBUF, M_WAITOK | M_ZERO);
+               rstp->rst = rst;
+               TAILQ_INSERT_TAIL(&sc->rst_list, rstp, next);
+       }
+
+       /* Enable USB PHY */
+       TAILQ_INIT(&sc->phy_list);
+       for (off = 0; phy_get_by_ofw_idx(dev, 0, off, &phy) == 0; off++) {
+               err = phy_usb_set_mode(phy, PHY_USB_MODE_HOST);
+               if (err != 0) {
+                       device_printf(dev, "Could not set phy to host mode\n");
+                       goto error;
+               }
+               err = phy_enable(phy);
+               if (err != 0) {
+                       device_printf(dev, "Could not enable phy\n");
+                       goto error;
+               }
+               phyp = malloc(sizeof(*phyp), M_DEVBUF, M_WAITOK | M_ZERO);
+               phyp->phy = phy;
+               TAILQ_INSERT_TAIL(&sc->phy_list, phyp, next);
+       }
+#endif
+
+       err = generic_ehci_attach(dev);
+       if (err != 0)
+               goto error;
+
+       return (0);
+
+error:
+       generic_ehci_fdt_detach(dev);
+       return (err);
+}
+
+static int
+generic_ehci_fdt_detach(device_t dev)
+{
+#ifdef EXT_RESOURCES
+       struct generic_ehci_fdt_softc *sc;
+       struct clk_list *clk, *clk_tmp;
+       struct hwrst_list *rst, *rst_tmp;
+       struct phy_list *phy, *phy_tmp;
+#endif
+       int err;
+
+       err = generic_ehci_detach(dev);
+       if (err != 0)
+               return (err);
+
+#ifdef EXT_RESOURCES
+       sc = device_get_softc(dev);
+
+       /* Disable clock */
+       TAILQ_FOREACH_SAFE(clk, &sc->clk_list, next, clk_tmp) {
+               err = clk_disable(clk->clk);
+               if (err != 0)
+                       device_printf(dev, "Could not disable clock %s\n",
+                           clk_get_name(clk->clk));
+               err = clk_release(clk->clk);
+               if (err != 0)
+                       device_printf(dev, "Could not release clock %s\n",
+                           clk_get_name(clk->clk));
+               TAILQ_REMOVE(&sc->clk_list, clk, next);
+               free(clk, M_DEVBUF);
+       }
+
+       /* Assert reset */
+       TAILQ_FOREACH_SAFE(rst, &sc->rst_list, next, rst_tmp) {
+               hwreset_assert(rst->rst);
+               hwreset_release(rst->rst);
+               TAILQ_REMOVE(&sc->rst_list, rst, next);
+               free(rst, M_DEVBUF);
+       }
+
+       /* Disable phys */
+       TAILQ_FOREACH_SAFE(phy, &sc->phy_list, next, phy_tmp) {
+               err = phy_disable(phy->phy);
+               if (err != 0)
+                       device_printf(dev, "Could not disable phy\n");
+               phy_release(phy->phy);
+               TAILQ_REMOVE(&sc->phy_list, phy, next);
+               free(phy, M_DEVBUF);
+       }
+#endif
+
+       return (0);
+}
+
+static device_method_t ehci_fdt_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         generic_ehci_fdt_probe),
+       DEVMETHOD(device_attach,        generic_ehci_fdt_attach),
+       DEVMETHOD(device_detach,        generic_ehci_fdt_detach),
+
+       DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(ehci, ehci_fdt_driver, ehci_fdt_methods,
+    sizeof(ehci_softc_t), generic_ehci_driver);
+
+static devclass_t ehci_fdt_devclass;
+
+DRIVER_MODULE(ehci, simplebus, ehci_fdt_driver, ehci_fdt_devclass, 0, 0);
+MODULE_DEPEND(ehci, usb, 1, 1, 1);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to