Source-Changes-HG archive

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

[src/trunk]: src/sys/arch i.MX USB host code re-arrangement.



details:   https://anonhg.NetBSD.org/src/rev/9bd2007f1ed0
branches:  trunk
changeset: 1000402:9bd2007f1ed0
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Wed Jul 24 11:20:55 2019 +0000

description:
i.MX USB host code re-arrangement.

diffstat:

 sys/arch/arm/imx/imx23_usb.c              |   12 ++-
 sys/arch/arm/imx/imx51_usb.c              |   30 ++++---
 sys/arch/arm/imx/imx6_reg.h               |    4 +-
 sys/arch/arm/imx/imx6_usb.c               |   19 +++-
 sys/arch/arm/imx/imx6_usbreg.h            |   21 ++--
 sys/arch/arm/imx/imx7_usb.c               |   25 ++++--
 sys/arch/arm/imx/imx7_usbreg.h            |   20 ++--
 sys/arch/arm/imx/imxusb.c                 |  115 ++++++++++++-----------------
 sys/arch/arm/imx/imxusbvar.h              |   13 ++-
 sys/arch/evbarm/kobo/kobo_usb.c           |   22 +++--
 sys/arch/evbarm/netwalker/netwalker_usb.c |   21 ++--
 sys/arch/evbarm/nitrogen6/nitrogen6_usb.c |   36 +++++----
 12 files changed, 182 insertions(+), 156 deletions(-)

diffs (truncated from 930 to 300 lines):

diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx23_usb.c
--- a/sys/arch/arm/imx/imx23_usb.c      Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx23_usb.c      Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/* $Id: imx23_usb.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */
+/* $Id: imx23_usb.c,v 1.2 2019/07/24 11:20:55 hkenken Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -43,6 +43,7 @@
 #include <dev/usb/ehcireg.h>
 #include <dev/usb/ehcivar.h>
 #include <arm/imx/imxusbvar.h>
+#include <arm/imx/imxusbreg.h>
 
 #include <arm/mainbus/mainbus.h>
 
@@ -54,7 +55,7 @@
 #include "locators.h"
 
 struct imx23_usb_softc {
-       struct imxusbc_softc  sc_imxusbc;
+       struct imxusbc_softc  sc_imxusbc; /* Must be first */
 };
 
 static int     imx23_usb_match(device_t, cfdata_t, void *);
@@ -94,9 +95,14 @@
 {
        struct imxusbc_softc *sc = device_private(self);
 
+       sc->sc_dev = self;
+       sc->sc_iot = &imx23_bus_space;
+       sc->sc_ehci_size = IMXUSB_EHCI_SIZE;
+       sc->sc_ehci_offset = IMXUSB_EHCI_SIZE;
+
        sc->sc_init_md_hook = imx23_usb_init;
+       sc->sc_intr_establish_md_hook = NULL;
        sc->sc_setup_md_hook = NULL;
-       sc->sc_iot = &imx23_bus_space;
 
        if (bus_space_map(sc->sc_iot, AHB_USB, AHB_USB_SIZE, 0, &sc->sc_ioh)) {
                aprint_error_dev(sc->sc_dev, "Unable to map bus space");
diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx51_usb.c
--- a/sys/arch/arm/imx/imx51_usb.c      Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx51_usb.c      Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx51_usb.c,v 1.4 2018/03/17 18:34:09 ryo Exp $        */
+/*     $NetBSD: imx51_usb.c,v 1.5 2019/07/24 11:20:55 hkenken Exp $    */
 /*
  * Copyright (c) 2010  Genetec Corporation.  All rights reserved.
  * Written by Hiroyuki Bessho for Genetec Corporation.
@@ -25,8 +25,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx51_usb.c,v 1.4 2018/03/17 18:34:09 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx51_usb.c,v 1.5 2019/07/24 11:20:55 hkenken Exp $");
 
+#include "locators.h"
 #include "opt_imx.h"
 
 #include <sys/param.h>
@@ -48,22 +49,25 @@
 #include <arm/imx/imx51reg.h>
 #include <arm/imx/imx51var.h>
 #include <arm/imx/imxusbvar.h>
-#include "locators.h"
+#include <arm/imx/imxusbreg.h>
 
-static int     imxusbc_search(device_t, cfdata_t, const int *, void *);
-static int     imxusbc_print(void *, const char *);
-
+static int imxusbc_search(device_t, cfdata_t, const int *, void *);
+static int imxusbc_print(void *, const char *);
 
 int
-imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot)
+imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot,
+    bus_addr_t addr, bus_size_t size)
 {
        struct imxusbc_softc *sc = device_private(self);
 
+       sc->sc_dev = self;
        sc->sc_iot = iot;
+       sc->sc_ehci_size = IMXUSB_EHCI_SIZE;
+       sc->sc_ehci_offset = IMXUSB_EHCI_SIZE;
 
        /* Map entire USBOH3 registers.  Host controller drivers
         * re-use subregions of this. */
-       if (bus_space_map(iot, USBOH3_BASE, USBOH3_SIZE, 0, &sc->sc_ioh))
+       if (bus_space_map(iot, addr, size, 0, &sc->sc_ioh))
                return -1;
 
        /* attach OTG/EHCI host controllers */
@@ -78,16 +82,16 @@
        struct imxusbc_softc *sc = device_private(parent);
        struct imxusbc_attach_args aa;
 
-        aa.aa_iot = sc->sc_iot;
+       aa.aa_iot = sc->sc_iot;
        aa.aa_ioh = sc->sc_ioh;
        aa.aa_dmat = &arm_generic_dma_tag;
-        aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT];
+       aa.aa_unit = cf->cf_loc[IMXUSBCCF_UNIT];
        aa.aa_irq = cf->cf_loc[IMXUSBCCF_IRQ];
 
-        if (config_match(parent, cf, &aa) > 0)
-                config_attach(parent, cf, &aa, imxusbc_print);
+       if (config_match(parent, cf, &aa) > 0)
+               config_attach(parent, cf, &aa, imxusbc_print);
 
-        return 0;
+       return 0;
 }
 
 /* ARGSUSED */
diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx6_reg.h
--- a/sys/arch/arm/imx/imx6_reg.h       Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx6_reg.h       Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_reg.h,v 1.8 2018/06/20 07:05:37 hkenken Exp $     */
+/*     $NetBSD: imx6_reg.h,v 1.9 2019/07/24 11:20:55 hkenken Exp $     */
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -220,7 +220,7 @@
 #define        AIPS2_MLB150_BASE       0x0008c000
 #define        AIPS2_ENET_BASE         0x00088000
 #define        AIPS2_USBOH_BASE        0x00084000
-#define        AIPS2_USBOH_SIZE        0x00000820
+#define        AIPS2_USBOH_SIZE        0x00000800
 #define        AIPS2_CONFIG_BASE       0x0007c000
 #define        AIPS2_DAP_BASE          0x00040000
 #define        AIPS2_CAAM_BASE         0x00000000
diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx6_usb.c
--- a/sys/arch/arm/imx/imx6_usb.c       Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx6_usb.c       Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_usb.c,v 1.5 2019/06/20 08:16:19 hkenken Exp $     */
+/*     $NetBSD: imx6_usb.c,v 1.6 2019/07/24 11:20:55 hkenken Exp $     */
 
 /*
  * Copyright (c) 2012  Genetec Corporation.  All rights reserved.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_usb.c,v 1.5 2019/06/20 08:16:19 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_usb.c,v 1.6 2019/07/24 11:20:55 hkenken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,6 +50,7 @@
 #include <arm/imx/imx6_ccmvar.h>
 #include <arm/imx/imx6_usbreg.h>
 #include <arm/imx/imxusbvar.h>
+#include <arm/imx/imxusbreg.h>
 
 #include "locators.h"
 
@@ -58,17 +59,21 @@
 static int imxusbc_init_clocks(struct imxusbc_softc *);
 
 int
-imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot)
+imxusbc_attach_common(device_t parent, device_t self, bus_space_tag_t iot,
+    bus_addr_t addr, bus_size_t size)
 {
-       struct imxusbc_softc *sc;
+       struct imxusbc_softc *sc = device_private(self);
 
-       sc = device_private(self);
+       sc->sc_dev = self;
        sc->sc_iot = iot;
+       sc->sc_ehci_size = IMXUSB_EHCI_SIZE;
+       sc->sc_ehci_offset = IMXUSB_EHCI_SIZE;
 
        /* Map entire USBOH registers.  Host controller drivers
         * re-use subregions of this. */
-       if (bus_space_map(iot, IMX6_AIPS2_BASE + AIPS2_USBOH_BASE,
-           AIPS2_USBOH_SIZE, 0, &sc->sc_ioh))
+       if (bus_space_map(iot, addr, size, 0, &sc->sc_ioh))
+               return -1;
+       if (bus_space_subregion(iot, sc->sc_ioh, USBNC_BASE, USBNC_SIZE, &sc->sc_ioh_usbnc))
                return -1;
 
        sc->sc_clk = imx6_get_clock("usboh3");
diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx6_usbreg.h
--- a/sys/arch/arm/imx/imx6_usbreg.h    Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx6_usbreg.h    Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_usbreg.h,v 1.1 2014/09/25 05:05:28 ryo Exp $      */
+/*     $NetBSD: imx6_usbreg.h,v 1.2 2019/07/24 11:20:55 hkenken Exp $  */
 
 /*
  * Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -63,8 +63,9 @@
 #define USBC_UH3_PORTSC1                       0x00000784
 #define USBC_UH3_USBMODE                       0x000007a8
 
-
-#define USBNC_USB_OTG_CTRL                     0x00000800
+#define USBNC_BASE                             0x00000800
+#define USBNC_SIZE                             0x00000020
+#define USBNC_USB_OTG_CTRL                     0x00000000
 #define  USBNC_USB_OTG_CTRL_WIR                        __BIT(31)
 #define  USBNC_USB_OTG_CTRL_WKUP_VBUS_EN       __BIT(17)
 #define  USBNC_USB_OTG_CTRL_WKUP_ID_EN         __BIT(16)
@@ -75,7 +76,7 @@
 #define  USBNC_USB_OTG_CTRL_PWR_POL            __BIT(9)
 #define  USBNC_USB_OTG_CTRL_OVER_CUR_POL       __BIT(8)
 #define  USBNC_USB_OTG_CTRL_OVER_CUR_DIS       __BIT(7)
-#define USBNC_USB_UH1_CTRL                     0x00000804
+#define USBNC_USB_UH1_CTRL                     0x00000004
 #define  USBNC_USB_UH1_CTRL_WIR                        __BIT(31)
 #define  USBNC_USB_UH1_CTRL_WKUP_VBUS_EN       __BIT(17)
 #define  USBNC_USB_UH1_CTRL_WKUP_ID_EN         __BIT(16)
@@ -86,27 +87,27 @@
 #define  USBNC_USB_UH1_CTRL_PWR_POL            __BIT(9)
 #define  USBNC_USB_UH1_CTRL_OVER_CUR_POL       __BIT(8)
 #define  USBNC_USB_UH1_CTRL_OVER_CUR_DIS       __BIT(7)
-#define USBNC_USB_UH2_CTRL                     0x00000808
+#define USBNC_USB_UH2_CTRL                     0x00000008
 #define  USBNC_USB_UH2_CTRL_WKUP_SW            __BIT(15)
 #define  USBNC_USB_UH2_CTRL_WKUP_SW_EN         __BIT(14)
 #define  USBNC_USB_UH2_CTRL_UTMI_ON_CLOCK      __BIT(13)
 #define  USBNC_USB_UH2_CTRL_WIE                        __BIT(10)
-#define USBNC_USB_UH3_CTRL                     0x0000080c
+#define USBNC_USB_UH3_CTRL                     0x0000000c
 #define  USBNC_USB_UH3_CTRL_WKUP_SW            __BIT(15)
 #define  USBNC_USB_UH3_CTRL_WKUP_SW_EN         __BIT(14)
 #define  USBNC_USB_UH3_CTRL_UTMI_ON_CLOCK      __BIT(13)
 #define  USBNC_USB_UH3_CTRL_WIE                        __BIT(10)
-#define USBNC_USB_UH2_HSIC_CTRL                        0x00000810
+#define USBNC_USB_UH2_HSIC_CTRL                        0x00000010
 #define  USBNC_USB_UH2_HSIC_CTRL_CLK_VLK       __BIT(31)
 #define  USBNC_USB_UH2_HSIC_CTRL_HSIC_EN       __BIT(12)
 #define  USBNC_USB_UH2_HSIC_CTRL_HSIC_CLK_ON   __BIT(11)
-#define USBNC_USB_UH3_HSIC_CTRL                        0x00000814
+#define USBNC_USB_UH3_HSIC_CTRL                        0x00000014
 #define  USBNC_USB_UH3_HSIC_CTRL_CLK_VLK       __BIT(31)
 #define  USBNC_USB_UH3_HSIC_CTRL_HSIC_EN       __BIT(12)
 #define  USBNC_USB_UH3_HSIC_CTRL_HSIC_CLK_ON   __BIT(11)
-#define USBNC_USB_OTG_PHY_CTRL_0               0x00000818
+#define USBNC_USB_OTG_PHY_CTRL_0               0x00000018
 #define  USBNC_USB_OTG_PHY_CTRL_0_UTMI_CLK_VLD __BIT(31)
-#define USBNC_USB_UH1_PHY_CTRL_0               0x0000081c
+#define USBNC_USB_UH1_PHY_CTRL_0               0x0000001c
 #define  USBNC_USB_UH1_PHY_CTRL_0_UTMI_CLK_VLD __BIT(31)
 
 #endif /* _IMX6_USBREG_H_ */
diff -r fa47c816c22a -r 9bd2007f1ed0 sys/arch/arm/imx/imx7_usb.c
--- a/sys/arch/arm/imx/imx7_usb.c       Wed Jul 24 11:12:30 2019 +0000
+++ b/sys/arch/arm/imx/imx7_usb.c       Wed Jul 24 11:20:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx7_usb.c,v 1.3 2018/03/17 18:34:09 ryo Exp $ */
+/*     $NetBSD: imx7_usb.c,v 1.4 2019/07/24 11:20:55 hkenken Exp $     */
 
 /*
  * Copyright (c) 2013  Genetec Corporation.  All rights reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx7_usb.c,v 1.3 2018/03/17 18:34:09 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx7_usb.c,v 1.4 2019/07/24 11:20:55 hkenken Exp $");
 
 #include "locators.h"
 
@@ -56,7 +56,6 @@
 #include <arm/imx/imx7_srcreg.h>
 #include <arm/imx/imxusbreg.h>
 #include <arm/imx/imxusbvar.h>
-#include <arm/imx/imxgpiovar.h>
 
 static int imx7_usbc_match(device_t, cfdata_t, void *);
 static void imx7_usbc_attach(device_t, device_t, void *);
@@ -127,6 +126,7 @@
        sc->sc_init_md_hook = imx7_usb_init;
        sc->sc_setup_md_hook = NULL;
        sc->sc_ehci_size = IMX7_USBC_EHCISIZE;  /* ehci register stride */
+       sc->sc_ehci_offset = IMX7_USBC_EHCISIZE;
 
        if (aa->aa_size == AXICF_SIZE_DEFAULT)
                aa->aa_size = IMX7_USBC_SIZE;
@@ -141,12 +141,17 @@
                aprint_error_dev(self, "cannot map registers\n");
                return;
        }
+       if (bus_space_map(sc->sc_iot, aa->aa_addr + USBNC_BASE, aa->aa_size, 0,
+           &sc->sc_ioh_usbnc)) {
+               aprint_error_dev(self, "cannot map registers\n");
+               return;
+       }
 
        /* disable clock */
        imx7_ccm_write(CCM_CCGR_USB_HSIC_CLR, CCM_CCGR_MASK);
 
        /* set freq */
-       imx7_ccm_write(CCM_CLKROOT_USB_HSIC_CLK_ROOT, 



Home | Main Index | Thread Index | Old Index