Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm The i.mx6sx has 2 OTG and one host-only USB con...



details:   https://anonhg.NetBSD.org/src/rev/a36756b822bb
branches:  trunk
changeset: 374570:a36756b822bb
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu May 04 17:09:44 2023 +0000

description:
The i.mx6sx has 2 OTG and one host-only USB controller, while the 6q has
only one OTG.
Add a "uintptr_t data" argument to all sc_*_md_hook callbacks, which
gets the sc_md_hook_data value when called.
In imx6_usb.c use this to pass the number of OTG controllers to the callbacks.
imx6_usb_init() can then properly call init_otg() or init_h1() for unit 1.

In imx6_usb_attach(), test if there is a vbus-supply property in the fdt,
and enable the regulator if present.

Now the USB port of the UDOO Neo works.

diffstat:

 sys/arch/arm/imx/imx23_usb.c |   4 ++--
 sys/arch/arm/imx/imxusb.c    |  11 ++++++-----
 sys/arch/arm/imx/imxusbvar.h |  10 ++++++----
 sys/arch/arm/nxp/imx6_usb.c  |  42 ++++++++++++++++++++++++++++++++----------
 4 files changed, 46 insertions(+), 21 deletions(-)

diffs (201 lines):

diff -r b91f9ee85a36 -r a36756b822bb sys/arch/arm/imx/imx23_usb.c
--- a/sys/arch/arm/imx/imx23_usb.c      Thu May 04 17:07:56 2023 +0000
+++ b/sys/arch/arm/imx/imx23_usb.c      Thu May 04 17:09:44 2023 +0000
@@ -1,4 +1,4 @@
-/* $Id: imx23_usb.c,v 1.5 2021/08/07 16:18:44 thorpej Exp $ */
+/* $Id: imx23_usb.c,v 1.6 2023/05/04 17:09:44 bouyer Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -152,7 +152,7 @@ imxusbc_search(device_t parent, cfdata_t
 }
 
 static
-void imx23_usb_init(struct imxehci_softc *sc)
+void imx23_usb_init(struct imxehci_softc *sc, uintptr_t data)
 {
 
        sc->sc_iftype = IMXUSBC_IF_UTMI;
diff -r b91f9ee85a36 -r a36756b822bb sys/arch/arm/imx/imxusb.c
--- a/sys/arch/arm/imx/imxusb.c Thu May 04 17:07:56 2023 +0000
+++ b/sys/arch/arm/imx/imxusb.c Thu May 04 17:09:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxusb.c,v 1.18 2021/08/07 16:18:44 thorpej Exp $      */
+/*     $NetBSD: imxusb.c,v 1.19 2023/05/04 17:09:44 bouyer Exp $       */
 /*
  * Copyright (c) 2009, 2010  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi and Hiroyuki Bessho for Genetec Corporation.
@@ -25,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imxusb.c,v 1.18 2021/08/07 16:18:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxusb.c,v 1.19 2023/05/04 17:09:44 bouyer Exp $");
 
 #include "locators.h"
 #include "opt_imx.h"
@@ -158,7 +158,7 @@ imxehci_attach(device_t parent, device_t
 
        /* Platform dependent setup */
        if (usbc->sc_init_md_hook)
-               usbc->sc_init_md_hook(sc);
+               usbc->sc_init_md_hook(sc, usbc->sc_md_hook_data);
 
        imxehci_reset(sc);
        imxehci_select_interface(sc, sc->sc_iftype);
@@ -178,7 +178,7 @@ imxehci_attach(device_t parent, device_t
        }
 
        if (usbc->sc_setup_md_hook)
-               usbc->sc_setup_md_hook(sc, IMXUSB_HOST);
+               usbc->sc_setup_md_hook(sc, IMXUSB_HOST, usbc->sc_md_hook_data);
 
        if (sc->sc_iftype == IMXUSBC_IF_ULPI) {
 #if 0
@@ -202,7 +202,8 @@ imxehci_attach(device_t parent, device_t
        EOWRITE4(hsc, EHCI_USBINTR, 0);
 
        if (usbc->sc_intr_establish_md_hook)
-               sc->sc_ih = usbc->sc_intr_establish_md_hook(sc);
+               sc->sc_ih = usbc->sc_intr_establish_md_hook(sc,
+                   usbc->sc_md_hook_data);
        else if (aa->aa_irq > 0)
                sc->sc_ih = intr_establish(aa->aa_irq, IPL_USB, IST_LEVEL, ehci_intr, hsc);
        KASSERT(sc->sc_ih != NULL);
diff -r b91f9ee85a36 -r a36756b822bb sys/arch/arm/imx/imxusbvar.h
--- a/sys/arch/arm/imx/imxusbvar.h      Thu May 04 17:07:56 2023 +0000
+++ b/sys/arch/arm/imx/imxusbvar.h      Thu May 04 17:09:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxusbvar.h,v 1.6 2019/07/24 11:20:55 hkenken Exp $    */
+/*     $NetBSD: imxusbvar.h,v 1.7 2023/05/04 17:09:44 bouyer Exp $     */
 /*
  * Copyright (c) 2019  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -48,9 +48,11 @@ struct imxusbc_softc {
        bus_addr_t sc_ehci_offset;
        bus_size_t sc_ehci_size;
 
-       void (* sc_init_md_hook)(struct imxehci_softc *);
-       void *(* sc_intr_establish_md_hook)(struct imxehci_softc *);
-       void (* sc_setup_md_hook)(struct imxehci_softc *, enum imx_usb_role);
+       void (* sc_init_md_hook)(struct imxehci_softc *, uintptr_t);
+       void *(* sc_intr_establish_md_hook)(struct imxehci_softc *, uintptr_t);
+       void (* sc_setup_md_hook)(struct imxehci_softc *, enum imx_usb_role,
+                                 uintptr_t);
+       uintptr_t sc_md_hook_data;
 };
 
 struct imxusbc_attach_args {
diff -r b91f9ee85a36 -r a36756b822bb sys/arch/arm/nxp/imx6_usb.c
--- a/sys/arch/arm/nxp/imx6_usb.c       Thu May 04 17:07:56 2023 +0000
+++ b/sys/arch/arm/nxp/imx6_usb.c       Thu May 04 17:09:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_usb.c,v 1.7 2023/05/04 13:29:33 bouyer Exp $      */
+/*     $NetBSD: imx6_usb.c,v 1.8 2023/05/04 17:09:45 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_usb.c,v 1.7 2023/05/04 13:29:33 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_usb.c,v 1.8 2023/05/04 17:09:45 bouyer Exp $");
 
 #include "opt_fdt.h"
 
@@ -63,20 +63,20 @@ struct imxusbc_fdt_softc {
 static int imx6_usb_match(device_t, struct cfdata *, void *);
 static void imx6_usb_attach(device_t, device_t, void *);
 static int imx6_usb_init_clocks(struct imxusbc_softc *);
-static void imx6_usb_init(struct imxehci_softc *);
+static void imx6_usb_init(struct imxehci_softc *, uintptr_t);
 static void init_otg(struct imxehci_softc *);
 static void init_h1(struct imxehci_softc *);
 static int imxusbc_print(void *, const char *);
-static void *imx6_usb_intr_establish(struct imxehci_softc *);
+static void *imx6_usb_intr_establish(struct imxehci_softc *, uintptr_t);
 
 /* attach structures */
 CFATTACH_DECL_NEW(imxusbc_fdt, sizeof(struct imxusbc_fdt_softc),
     imx6_usb_match, imx6_usb_attach, NULL, NULL);
 
 static const struct device_compatible_entry compat_data[] = {
-       { .compat = "fsl,imx6q-usb" },
-       { .compat = "fsl,imx6sx-usb" },
-       { .compat = "fsl,imx7d-usb" },
+       { .compat = "fsl,imx6q-usb", .value = 1 },
+       { .compat = "fsl,imx6sx-usb", .value = 2 },
+       { .compat = "fsl,imx7d-usb", .value = 1 },
        DEVICE_COMPAT_EOL
 };
 
@@ -100,6 +100,7 @@ imx6_usb_attach(device_t parent, device_
        bus_addr_t addr;
        bus_size_t size;
        int error;
+       struct fdtbus_regulator *reg;
 
        aprint_naive("\n");
        aprint_normal("\n");
@@ -126,6 +127,7 @@ imx6_usb_attach(device_t parent, device_
        sc->sc_init_md_hook = imx6_usb_init;
        sc->sc_intr_establish_md_hook = imx6_usb_intr_establish;
        sc->sc_setup_md_hook = NULL;
+       sc->sc_md_hook_data = of_compatible_lookup(phandle, compat_data)->value;
 
        sc->sc_dev = self;
        sc->sc_iot = bst;
@@ -168,6 +170,21 @@ imx6_usb_attach(device_t parent, device_
        config_found(self, &iaa, imxusbc_print,
            CFARGS_NONE);
 
+       if (of_hasprop(phandle, "vbus-supply")) {
+               reg = fdtbus_regulator_acquire(phandle, "vbus-supply");
+               if (reg == NULL) {
+                       aprint_error_dev(self,
+                           "couldn't acquire vbus-supply\n");
+               } else {
+                       error = fdtbus_regulator_enable(reg);
+                       if (error != 0) {
+                               aprint_error_dev(self,
+                                   "couldn't enable vbus-supply\n");
+                       }
+               }
+       } else {
+               aprint_verbose_dev(self, "no regulator\n");
+       }
        return;
 }
 
@@ -198,14 +215,19 @@ imx6_usb_init_clocks(struct imxusbc_soft
 }
 
 static void
-imx6_usb_init(struct imxehci_softc *sc)
+imx6_usb_init(struct imxehci_softc *sc, uintptr_t data)
 {
+       int notg = data;
+
        switch (sc->sc_unit) {
        case 0: /* OTG controller */
                init_otg(sc);
                break;
        case 1: /* EHCI Host 1 */
-               init_h1(sc);
+               if (notg >= 2)
+                       init_otg(sc);
+               else
+                       init_h1(sc);
                break;
        case 2: /* EHCI Host 2 */
        case 3: /* EHCI Host 3 */
@@ -257,7 +279,7 @@ init_h1(struct imxehci_softc *sc)
 }
 
 static void *
-imx6_usb_intr_establish(struct imxehci_softc *sc)
+imx6_usb_intr_establish(struct imxehci_softc *sc, uintptr_t data)
 {
        struct imxusbc_fdt_softc *ifsc = (struct imxusbc_fdt_softc *)sc->sc_usbc;
        ehci_softc_t *hsc = &sc->sc_hsc;



Home | Main Index | Thread Index | Old Index