Module Name: src
Committed By: hkenken
Date: Wed Jul 24 11:20:55 UTC 2019
Modified Files:
src/sys/arch/arm/imx: imx23_usb.c imx51_usb.c imx6_reg.h imx6_usb.c
imx6_usbreg.h imx7_usb.c imx7_usbreg.h imxusb.c imxusbvar.h
src/sys/arch/evbarm/kobo: kobo_usb.c
src/sys/arch/evbarm/netwalker: netwalker_usb.c
src/sys/arch/evbarm/nitrogen6: nitrogen6_usb.c
Log Message:
i.MX USB host code re-arrangement.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/imx/imx23_usb.c \
src/sys/arch/arm/imx/imx6_usbreg.h src/sys/arch/arm/imx/imx7_usbreg.h
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/imx/imx51_usb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/imx/imx6_reg.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/imx/imx6_usb.c \
src/sys/arch/arm/imx/imxusbvar.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/imx/imx7_usb.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/imx/imxusb.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/kobo/kobo_usb.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbarm/netwalker/netwalker_usb.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/imx/imx23_usb.c
diff -u src/sys/arch/arm/imx/imx23_usb.c:1.1 src/sys/arch/arm/imx/imx23_usb.c:1.2
--- src/sys/arch/arm/imx/imx23_usb.c:1.1 Mon Oct 7 17:36:40 2013
+++ src/sys/arch/arm/imx/imx23_usb.c Wed Jul 24 11:20:55 2019
@@ -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 @@ imx23_usb_attach(device_t parent, device
{
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");
Index: src/sys/arch/arm/imx/imx6_usbreg.h
diff -u src/sys/arch/arm/imx/imx6_usbreg.h:1.1 src/sys/arch/arm/imx/imx6_usbreg.h:1.2
--- src/sys/arch/arm/imx/imx6_usbreg.h:1.1 Thu Sep 25 05:05:28 2014
+++ src/sys/arch/arm/imx/imx6_usbreg.h Wed Jul 24 11:20:55 2019
@@ -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 <[email protected]>
@@ -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_ */
Index: src/sys/arch/arm/imx/imx7_usbreg.h
diff -u src/sys/arch/arm/imx/imx7_usbreg.h:1.1 src/sys/arch/arm/imx/imx7_usbreg.h:1.2
--- src/sys/arch/arm/imx/imx7_usbreg.h:1.1 Tue May 17 06:44:45 2016
+++ src/sys/arch/arm/imx/imx7_usbreg.h Wed Jul 24 11:20:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: imx7_usbreg.h,v 1.1 2016/05/17 06:44:45 ryo Exp $ */
+/* $NetBSD: imx7_usbreg.h,v 1.2 2019/07/24 11:20:55 hkenken Exp $ */
/*
* Copyright (c) 2016 Ryo Shimizu <[email protected]>
@@ -83,7 +83,9 @@
#define USB_X_USBMODE_CM __BITS(1,0)
/* USB Non-Core */
-#define USBNC_N_CTRL1 0x00000200
+#define USBNC_BASE 0x00000200
+#define USBNC_SIZE 0x00000060
+#define USBNC_N_CTRL1 0x00000000
#define USBNC_N_CTRL1_WIR __BIT(31)
#define USBNC_N_CTRL1_WKUP_DPDM_EN __BIT(29)
#define USBNC_N_CTRL1_WKUP_VBUS_EN __BIT(17)
@@ -94,13 +96,13 @@
#define USBNC_N_CTRL1_PWR_POL __BIT(9)
#define USBNC_N_CTRL1_OVER_CUR_POL __BIT(8)
#define USBNC_N_CTRL1_OVER_CUR_DIS __BIT(7)
-#define USBNC_N_CTRL2 0x00000204
-#define USBNC_N_PHY_CFG1 0x00000230
-#define USBNC_N_PHY_CFG2 0x00000234
-#define USBNC_N_PHY_STATUS 0x0000023c
-
-#define USBNC_ADP_CFG1 0x00000250
-#define USBNC_ADP_CFG2 0x00000254
-#define USBNC_ADP_STATUS 0x00000258
+#define USBNC_N_CTRL2 0x00000004
+#define USBNC_N_PHY_CFG1 0x00000030
+#define USBNC_N_PHY_CFG2 0x00000034
+#define USBNC_N_PHY_STATUS 0x0000003c
+
+#define USBNC_ADP_CFG1 0x00000050
+#define USBNC_ADP_CFG2 0x00000054
+#define USBNC_ADP_STATUS 0x00000058
#endif /* _ARM_IMX_IMX7_USBREG_H_ */
Index: src/sys/arch/arm/imx/imx51_usb.c
diff -u src/sys/arch/arm/imx/imx51_usb.c:1.4 src/sys/arch/arm/imx/imx51_usb.c:1.5
--- src/sys/arch/arm/imx/imx51_usb.c:1.4 Sat Mar 17 18:34:09 2018
+++ src/sys/arch/arm/imx/imx51_usb.c Wed Jul 24 11:20:55 2019
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: imx51_usb.c,
#include <arm/imx/imx51reg.h>
#include <arm/imx/imx51var.h>
#include <arm/imx/imxusbvar.h>
-#include "locators.h"
-
-static int imxusbc_search(device_t, cfdata_t, const int *, void *);
-static int imxusbc_print(void *, const char *);
+#include <arm/imx/imxusbreg.h>
+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 @@ imxusbc_search(device_t parent, cfdata_t
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 */
Index: src/sys/arch/arm/imx/imx6_reg.h
diff -u src/sys/arch/arm/imx/imx6_reg.h:1.8 src/sys/arch/arm/imx/imx6_reg.h:1.9
--- src/sys/arch/arm/imx/imx6_reg.h:1.8 Wed Jun 20 07:05:37 2018
+++ src/sys/arch/arm/imx/imx6_reg.h Wed Jul 24 11:20:55 2019
@@ -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
Index: src/sys/arch/arm/imx/imx6_usb.c
diff -u src/sys/arch/arm/imx/imx6_usb.c:1.5 src/sys/arch/arm/imx/imx6_usb.c:1.6
--- src/sys/arch/arm/imx/imx6_usb.c:1.5 Thu Jun 20 08:16:19 2019
+++ src/sys/arch/arm/imx/imx6_usb.c Wed Jul 24 11:20:55 2019
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: imx6_usb.c,v
#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_print(void *, const c
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");
Index: src/sys/arch/arm/imx/imxusbvar.h
diff -u src/sys/arch/arm/imx/imxusbvar.h:1.5 src/sys/arch/arm/imx/imxusbvar.h:1.6
--- src/sys/arch/arm/imx/imxusbvar.h:1.5 Thu Jun 20 08:16:19 2019
+++ src/sys/arch/arm/imx/imxusbvar.h Wed Jul 24 11:20:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: imxusbvar.h,v 1.5 2019/06/20 08:16:19 hkenken Exp $ */
+/* $NetBSD: imxusbvar.h,v 1.6 2019/07/24 11:20:55 hkenken Exp $ */
/*
* Copyright (c) 2019 Genetec Corporation. All rights reserved.
* Written by Hashimoto Kenichi for Genetec Corporation.
@@ -37,14 +37,19 @@ enum imx_usb_role {
struct imxusbc_softc {
device_t sc_dev;
+
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
+ bus_space_handle_t sc_ioh_usbnc;
struct clk *sc_clk;
/* filled in by platform dependent param & routine */
+ 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);
};
@@ -68,14 +73,18 @@ enum imx_usb_if {
struct imxehci_softc {
ehci_softc_t sc_hsc;
+ device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
+ void *sc_ih;
+
struct imxusbc_softc *sc_usbc;
+
uint sc_unit;
enum imx_usb_if sc_iftype;
};
-int imxusbc_attach_common(device_t, device_t, bus_space_tag_t);
+int imxusbc_attach_common(device_t, device_t, bus_space_tag_t, bus_addr_t, bus_size_t);
void imxehci_reset(struct imxehci_softc *);
#endif /* _ARM_IMX_IMXUSBVAR_H */
Index: src/sys/arch/arm/imx/imx7_usb.c
diff -u src/sys/arch/arm/imx/imx7_usb.c:1.3 src/sys/arch/arm/imx/imx7_usb.c:1.4
--- src/sys/arch/arm/imx/imx7_usb.c:1.3 Sat Mar 17 18:34:09 2018
+++ src/sys/arch/arm/imx/imx7_usb.c Wed Jul 24 11:20:55 2019
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: imx7_usb.c,v
#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 @@ imx7_usbc_attach(device_t parent __unuse
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 @@ imx7_usbc_attach(device_t parent __unuse
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,
+ imx7_ccm_write(CCM_CLKROOT_USB_HSIC_CLK_ROOT,
CCM_TARGET_ROOT_ENABLE |
__SHIFTIN(1, CCM_TARGET_ROOT_MUX) |
__SHIFTIN(0, CCM_TARGET_ROOT_PRE_PODF) |
@@ -170,6 +175,10 @@ imx7_usbc_attach(device_t parent __unuse
bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, reg)
#define EHCIREG_WRITE(sc, reg, value) \
bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, reg, value)
+#define USBNC_READ(sc, reg) \
+ bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh_usbnc, reg)
+#define USBNC_WRITE(sc, reg, value) \
+ bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh_usbnc, reg, value)
static void
imx7_usb_init(struct imxehci_softc *sc)
@@ -182,13 +191,13 @@ imx7_usb_init(struct imxehci_softc *sc)
usbc = sc->sc_usbc;
/* setup overcurrent */
- v = EHCIREG_READ(sc, USBNC_N_CTRL1);
+ v = USBNC_READ(usbc, USBNC_N_CTRL1);
v |= USBNC_N_CTRL1_OVER_CUR_POL;
- EHCIREG_WRITE(sc, USBNC_N_CTRL1, v);
+ USBNC_WRITE(usbc, USBNC_N_CTRL1, v);
- v = EHCIREG_READ(sc, USBNC_N_CTRL1);
+ v = USBNC_READ(usbc, USBNC_N_CTRL1);
v |= USBNC_N_CTRL1_OVER_CUR_DIS | USBNC_N_CTRL1_PWR_POL;
- EHCIREG_WRITE(sc, USBNC_N_CTRL1, v);
+ USBNC_WRITE(usbc, USBNC_N_CTRL1, v);
/* set host mode */
v = EHCIREG_READ(sc, USB_X_USBMODE);
Index: src/sys/arch/arm/imx/imxusb.c
diff -u src/sys/arch/arm/imx/imxusb.c:1.13 src/sys/arch/arm/imx/imxusb.c:1.14
--- src/sys/arch/arm/imx/imxusb.c:1.13 Mon Apr 9 16:21:09 2018
+++ src/sys/arch/arm/imx/imxusb.c Wed Jul 24 11:20:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: imxusb.c,v 1.13 2018/04/09 16:21:09 jakllsch Exp $ */
+/* $NetBSD: imxusb.c,v 1.14 2019/07/24 11:20:55 hkenken Exp $ */
/*
* Copyright (c) 2009, 2010 Genetec Corporation. All rights reserved.
* Written by Hashimoto Kenichi and Hiroyuki Bessho for Genetec Corporation.
@@ -25,8 +25,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imxusb.c,v 1.13 2018/04/09 16:21:09 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxusb.c,v 1.14 2019/07/24 11:20:55 hkenken Exp $");
+#include "locators.h"
#include "opt_imx.h"
#include <sys/param.h>
@@ -49,8 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: imxusb.c,v 1
#include <arm/imx/imxusbreg.h>
#include <arm/imx/imxusbvar.h>
-#include <arm/imx/imxgpiovar.h>
-#include "locators.h"
#include <dev/usb/ulpireg.h> /* for test */
@@ -73,9 +72,8 @@ imxehci_match(device_t parent, cfdata_t
{
struct imxusbc_attach_args *aa = aux;
- if (aa->aa_unit < 0 || 3 < aa->aa_unit) {
+ if (aa->aa_unit < 0 || 3 < aa->aa_unit)
return 0;
- }
return 1;
}
@@ -92,11 +90,17 @@ imxehci_attach(device_t parent, device_t
uint32_t id, hwhost, hwdevice;
const char *comma;
- sc->sc_hsc.sc_dev = self;
- iot = sc->sc_iot = sc->sc_hsc.iot = aa->aa_iot;
+ iot = aa->aa_iot;
+
+ sc->sc_dev = self;
sc->sc_unit = aa->aa_unit;
sc->sc_usbc = usbc;
+ sc->sc_iot = iot;
+
+ hsc->sc_dev = self;
+ hsc->iot = iot;
hsc->sc_bus.ub_hcpriv = sc;
+ hsc->sc_bus.ub_dmatag = aa->aa_dmat;
hsc->sc_flags |= EHCIF_ETTF;
hsc->sc_vendor_init = imxehci_init;
@@ -108,19 +112,19 @@ imxehci_attach(device_t parent, device_t
/* per unit registers */
if (bus_space_subregion(iot, aa->aa_ioh,
- aa->aa_unit * usbc->sc_ehci_size, usbc->sc_ehci_size,
+ sc->sc_unit * usbc->sc_ehci_offset, usbc->sc_ehci_size,
&sc->sc_ioh) ||
bus_space_subregion(iot, aa->aa_ioh,
- aa->aa_unit * usbc->sc_ehci_size + IMXUSB_EHCIREGS,
+ sc->sc_unit * usbc->sc_ehci_offset + IMXUSB_EHCIREGS,
usbc->sc_ehci_size - IMXUSB_EHCIREGS,
- &sc->sc_hsc.ioh)) {
+ &hsc->ioh)) {
aprint_error_dev(self, "can't subregion\n");
return;
}
id = bus_space_read_4(iot, sc->sc_ioh, IMXUSB_ID);
- hcirev = bus_space_read_2(iot, sc->sc_hsc.ioh, EHCI_HCIVERSION);
+ hcirev = bus_space_read_2(iot, hsc->ioh, EHCI_HCIVERSION);
aprint_normal_dev(self,
"id=%d revision=%d HCI revision=0x%x\n",
@@ -149,9 +153,7 @@ imxehci_attach(device_t parent, device_t
}
aprint_normal("\n");
- sc->sc_hsc.sc_bus.ub_dmatag = aa->aa_dmat;
-
- sc->sc_hsc.sc_offs = bus_space_read_1(iot, sc->sc_hsc.ioh,
+ hsc->sc_offs = bus_space_read_1(iot, hsc->ioh,
EHCI_CAPLENGTH);
/* Platform dependent setup */
@@ -193,14 +195,17 @@ imxehci_attach(device_t parent, device_t
OTG_CONTROL_USEEXTVBUSIND |
OTG_CONTROL_DRVVBUSEXT |
OTG_CONTROL_DRVVBUS |
- OTG_CONTROL_CHRGVBUS
- );
+ OTG_CONTROL_CHRGVBUS);
}
/* Disable interrupts, so we don't get any spurious ones. */
EOWRITE4(hsc, EHCI_USBINTR, 0);
- intr_establish(aa->aa_irq, IPL_USB, IST_LEVEL, ehci_intr, hsc);
+ if (usbc->sc_intr_establish_md_hook)
+ sc->sc_ih = usbc->sc_intr_establish_md_hook(sc);
+ 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);
int err = ehci_init(hsc);
if (err) {
@@ -245,25 +250,25 @@ imxehci_select_interface(struct imxehci_
static uint32_t
ulpi_wakeup(struct imxehci_softc *sc, int tout)
{
+ struct ehci_softc *hsc = &sc->sc_hsc;
uint32_t ulpi_view;
- int i = 0;
+
ulpi_view = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW);
- if ( !(ulpi_view & ULPI_SS) ) {
+ if (!(ulpi_view & ULPI_SS)) {
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
IMXUSB_ULPIVIEW, ULPI_WU);
- for (i = 0; (tout < 0) || (i < tout); i++) {
+ while (tout-- > 0) {
ulpi_view = bus_space_read_4(sc->sc_iot,
sc->sc_ioh, IMXUSB_ULPIVIEW);
- if ( !(ulpi_view & ULPI_WU) )
+ if (!(ulpi_view & ULPI_WU))
break;
delay(1);
};
}
- if ((tout > 0) && (i >= tout)) {
- aprint_error_dev(sc->sc_hsc.sc_dev, "%s: timeout\n", __func__);
- }
+ if (tout == 0)
+ aprint_error_dev(hsc->sc_dev, "%s: timeout\n", __func__);
return ulpi_view;
}
@@ -271,11 +276,12 @@ ulpi_wakeup(struct imxehci_softc *sc, in
static uint32_t
ulpi_wait(struct imxehci_softc *sc, int tout)
{
+ struct ehci_softc *hsc = &sc->sc_hsc;
uint32_t ulpi_view;
- int i;
+
ulpi_view = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW);
- for (i = 0; (tout < 0) | (i < tout); i++) {
+ while (tout-- > 0) {
ulpi_view = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
IMXUSB_ULPIVIEW);
if (!(ulpi_view & ULPI_RUN))
@@ -283,9 +289,8 @@ ulpi_wait(struct imxehci_softc *sc, int
delay(1);
}
- if ((tout > 0) && (i >= tout)) {
- aprint_error_dev(sc->sc_hsc.sc_dev, "%s: timeout\n", __func__);
- }
+ if (tout == 0)
+ aprint_error_dev(hsc->sc_dev, "%s: timeout\n", __func__);
return ulpi_view;
}
@@ -295,16 +300,16 @@ ulpi_wait(struct imxehci_softc *sc, int
uint8_t
imxusb_ulpi_read(struct imxehci_softc *sc, int addr)
{
- uint32_t data;
+ uint32_t reg;
ulpi_wakeup(sc, TIMEOUT);
- data = ULPI_RUN | __SHIFTIN(addr, ULPI_ADDR);
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW, data);
+ reg = ULPI_RUN | __SHIFTIN(addr, ULPI_ADDR);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW, reg);
- data = ulpi_wait(sc, TIMEOUT);
+ reg = ulpi_wait(sc, TIMEOUT);
- return __SHIFTOUT(data, ULPI_DATRD);
+ return __SHIFTOUT(reg, ULPI_DATRD);
}
void
@@ -322,34 +327,10 @@ imxusb_ulpi_write(struct imxehci_softc *
return;
}
-#if 0
-static int
-ulpi_scratch_test(struct imxehci_softc *sc)
-{
- uint32_t ulpi_view;
-
- ulpi_view = ulpi_wakeup(sc, 1000);
- if (ulpi_view & ULPI_WU) {
- return -1;
- }
-
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW,
- (ULPI_RUN | ULPI_RW |
- (ULPI_SCRATCH << ULPI_ADDR_SHIFT) | 0xAA));
-
- ulpi_view = ulpi_wait(sc, 1000);
-
- if (ulpi_view & ULPI_RUN) {
- return -1;
- }
-
- return 0;
-}
-#endif
-
static void
ulpi_reset(struct imxehci_softc *sc)
{
+ struct ehci_softc *hsc = &sc->sc_hsc;
uint8_t data;
int timo = 1000 * 1000; /* XXXX: 1sec */
@@ -362,8 +343,9 @@ ulpi_reset(struct imxehci_softc *sc)
delay(100);
timo -= 100;
} while (timo > 0);
+
if (timo <= 0) {
- aprint_error_dev(sc->sc_hsc.sc_dev, "%s: reset failed!!\n",
+ aprint_error_dev(hsc->sc_dev, "%s: reset failed!!\n",
__func__);
return;
}
@@ -375,15 +357,15 @@ void
imxehci_reset(struct imxehci_softc *sc)
{
uint32_t reg;
- int i;
struct ehci_softc *hsc = &sc->sc_hsc;
+ int tout;
#define RESET_TIMEOUT 100
reg = EOREAD4(hsc, EHCI_USBCMD);
reg &= ~EHCI_CMD_RS;
EOWRITE4(hsc, EHCI_USBCMD, reg);
- for (i=0; i < RESET_TIMEOUT; ++i) {
+ for (tout = RESET_TIMEOUT; tout > 0; tout--) {
reg = EOREAD4(hsc, EHCI_USBCMD);
if ((reg & EHCI_CMD_RS) == 0)
break;
@@ -391,15 +373,16 @@ imxehci_reset(struct imxehci_softc *sc)
}
EOWRITE4(hsc, EHCI_USBCMD, reg | EHCI_CMD_HCRESET);
- for (i = 0; i < RESET_TIMEOUT; i++) {
+
+ for (tout = RESET_TIMEOUT; tout > 0; tout--) {
reg = EOREAD4(hsc, EHCI_USBCMD);
if ((reg & EHCI_CMD_HCRESET) == 0)
break;
usb_delay_ms(&hsc->sc_bus, 1);
}
- if (i >= RESET_TIMEOUT) {
+
+ if (tout == 0)
aprint_error_dev(hsc->sc_dev, "reset timeout (%x)\n", reg);
- }
usb_delay_ms(&hsc->sc_bus, 100);
}
Index: src/sys/arch/evbarm/kobo/kobo_usb.c
diff -u src/sys/arch/evbarm/kobo/kobo_usb.c:1.2 src/sys/arch/evbarm/kobo/kobo_usb.c:1.3
--- src/sys/arch/evbarm/kobo/kobo_usb.c:1.2 Fri Sep 22 15:37:13 2017
+++ src/sys/arch/evbarm/kobo/kobo_usb.c Wed Jul 24 11:20:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: kobo_usb.c,v 1.2 2017/09/22 15:37:13 khorben Exp $ */
+/* $NetBSD: kobo_usb.c,v 1.3 2019/07/24 11:20:55 hkenken Exp $ */
/*
* Copyright (c) 2012 Genetec Corporation. All rights reserved.
@@ -27,7 +27,7 @@
*
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kobo_usb.c,v 1.2 2017/09/22 15:37:13 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobo_usb.c,v 1.3 2019/07/24 11:20:55 hkenken Exp $");
#include "opt_imx.h"
@@ -39,7 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: kobo_usb.c,v
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/bus.h>
-#include <sys/gpio.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
@@ -54,14 +53,13 @@ __KERNEL_RCSID(0, "$NetBSD: kobo_usb.c,v
#include <arm/imx/imxusbreg.h>
#include <arm/imx/imxusbvar.h>
#include <arm/imx/imx50_iomuxreg.h>
-#include <arm/imx/imxgpiovar.h>
#include <arm/imx/imx51_ccmreg.h>
#include <arm/imx/imx51_ccmvar.h>
#include "locators.h"
struct kobo_usbc_softc {
- struct imxusbc_softc sc_imxusbc;
+ struct imxusbc_softc sc_imxusbc; /* Must be first */
};
static int imxusbc_match(device_t, cfdata_t, void *);
@@ -90,16 +88,20 @@ imxusbc_match(device_t parent, cfdata_t
static void
imxusbc_attach(device_t parent, device_t self, void *aux)
{
+ struct imxusbc_softc *sc = device_private(self);
struct axi_attach_args *aa = aux;
- struct kobo_usbc_softc *sc = device_private(self);
aprint_normal("\n");
- aprint_naive("\n");
+ aprint_normal(": Universal Serial Bus Controller\n");
- sc->sc_imxusbc.sc_init_md_hook = kobo_usb_init;
- sc->sc_imxusbc.sc_setup_md_hook = NULL;
+ if (aa->aa_size == AXICF_SIZE_DEFAULT)
+ aa->aa_size = USBOH3_SIZE;
- imxusbc_attach_common(parent, self, aa->aa_iot);
+ sc->sc_init_md_hook = kobo_usb_init;
+ sc->sc_intr_establish_md_hook = NULL;
+ sc->sc_setup_md_hook = NULL;
+
+ imxusbc_attach_common(parent, self, aa->aa_iot, aa->aa_addr, aa->aa_size);
}
static void
Index: src/sys/arch/evbarm/netwalker/netwalker_usb.c
diff -u src/sys/arch/evbarm/netwalker/netwalker_usb.c:1.4 src/sys/arch/evbarm/netwalker/netwalker_usb.c:1.5
--- src/sys/arch/evbarm/netwalker/netwalker_usb.c:1.4 Fri Sep 22 15:37:13 2017
+++ src/sys/arch/evbarm/netwalker/netwalker_usb.c Wed Jul 24 11:20:55 2019
@@ -25,7 +25,7 @@
*
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netwalker_usb.c,v 1.4 2017/09/22 15:37:13 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netwalker_usb.c,v 1.5 2019/07/24 11:20:55 hkenken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -51,12 +51,10 @@ __KERNEL_RCSID(0, "$NetBSD: netwalker_us
#include <arm/imx/imxgpiovar.h>
#include "locators.h"
-
struct netwalker_usbc_softc {
- struct imxusbc_softc sc_imxusbc;
+ struct imxusbc_softc sc_imxusbc; /* Must be first */
};
-
static int imxusbc_match(device_t, cfdata_t, void *);
static void imxusbc_attach(device_t, device_t, void *);
static void netwalker_usb_init(struct imxehci_softc *);
@@ -85,14 +83,20 @@ imxusbc_match(device_t parent, cfdata_t
static void
imxusbc_attach(device_t parent, device_t self, void *aux)
{
- struct axi_attach_args *aa = aux;
struct imxusbc_softc *sc = device_private(self);
+ struct axi_attach_args *aa = aux;
+
+ aprint_normal("\n");
+ aprint_normal(": Universal Serial Bus Controller\n");
+
+ if (aa->aa_size == AXICF_SIZE_DEFAULT)
+ aa->aa_size = USBOH3_SIZE;
sc->sc_init_md_hook = netwalker_usb_init;
+ sc->sc_intr_establish_md_hook = NULL;
sc->sc_setup_md_hook = NULL;
- imxusbc_attach_common(parent, self, aa->aa_iot);
-
+ imxusbc_attach_common(parent, self, aa->aa_iot, aa->aa_addr, aa->aa_size);
}
static void
@@ -134,9 +138,6 @@ init_otg(struct imxehci_softc *sc)
bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_PHYCTRL1, reg);
}
-
-
-
static void
init_h1(struct imxehci_softc *sc)
{
Index: src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c
diff -u src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c:1.5 src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c:1.6
--- src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c:1.5 Thu Jun 20 08:16:19 2019
+++ src/sys/arch/evbarm/nitrogen6/nitrogen6_usb.c Wed Jul 24 11:20:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: nitrogen6_usb.c,v 1.5 2019/06/20 08:16:19 hkenken Exp $ */
+/* $NetBSD: nitrogen6_usb.c,v 1.6 2019/07/24 11:20:55 hkenken Exp $ */
/*
* Copyright (c) 2013 Genetec Corporation. All rights reserved.
@@ -27,7 +27,9 @@
*
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nitrogen6_usb.c,v 1.5 2019/06/20 08:16:19 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nitrogen6_usb.c,v 1.6 2019/07/24 11:20:55 hkenken Exp $");
+
+#include "locators.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -53,11 +55,9 @@ __KERNEL_RCSID(0, "$NetBSD: nitrogen6_us
#include <arm/imx/imx6_iomuxreg.h>
#include <arm/imx/imxusbreg.h>
#include <arm/imx/imxusbvar.h>
-#include <arm/imx/imxgpiovar.h>
-#include "locators.h"
struct nitrogen6_usbc_softc {
- struct imxusbc_softc sc_imxusbc;
+ struct imxusbc_softc sc_imxusbc; /* Must be first */
};
static int nitrogen6_usbc_match(device_t, cfdata_t, void *);
@@ -85,16 +85,20 @@ nitrogen6_usbc_match(device_t parent, cf
static void
nitrogen6_usbc_attach(device_t parent, device_t self, void *aux)
{
- struct axi_attach_args *aa = aux;
struct imxusbc_softc *sc = device_private(self);
-
- sc->sc_init_md_hook = nitrogen6_usb_init;
- sc->sc_setup_md_hook = NULL;
+ struct axi_attach_args *aa = aux;
aprint_naive("\n");
aprint_normal(": Universal Serial Bus Controller\n");
- imxusbc_attach_common(parent, self, aa->aa_iot);
+ if (aa->aa_size == AXICF_SIZE_DEFAULT)
+ aa->aa_size = AIPS2_USBOH_SIZE + USBNC_SIZE;
+
+ sc->sc_init_md_hook = nitrogen6_usb_init;
+ sc->sc_intr_establish_md_hook = NULL;
+ sc->sc_setup_md_hook = NULL;
+
+ imxusbc_attach_common(parent, self, aa->aa_iot, aa->aa_addr, aa->aa_size);
}
static void
@@ -125,12 +129,12 @@ init_otg(struct imxehci_softc *sc)
imxehci_reset(sc);
- v = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBNC_USB_OTG_CTRL);
+ v = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh_usbnc, USBNC_USB_OTG_CTRL);
v |= USBNC_USB_OTG_CTRL_WKUP_VBUS_EN;
v |= USBNC_USB_OTG_CTRL_OVER_CUR_DIS;
v |= USBNC_USB_OTG_CTRL_PWR_POL;
v &= ~USBNC_USB_OTG_CTRL_UTMI_ON_CLOCK;
- bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBNC_USB_OTG_CTRL, v);
+ bus_space_write_4(usbc->sc_iot, usbc->sc_ioh_usbnc, USBNC_USB_OTG_CTRL, v);
}
static void
@@ -141,17 +145,17 @@ init_h1(struct imxehci_softc *sc)
sc->sc_iftype = IMXUSBC_IF_UTMI_WIDE;
- v = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBNC_USB_UH1_CTRL);
+ v = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh_usbnc, USBNC_USB_UH1_CTRL);
v |= USBNC_USB_UH1_CTRL_OVER_CUR_POL;
v |= USBNC_USB_UH1_CTRL_OVER_CUR_DIS;
- bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBNC_USB_UH1_CTRL, v);
+ bus_space_write_4(usbc->sc_iot, usbc->sc_ioh_usbnc, USBNC_USB_UH1_CTRL, v);
/* do reset */
imxehci_reset(sc);
/* set mode */
v = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBC_UH1_USBMODE);
- v &= ~__SHIFTIN(USBC_UH_USBMODE_CM, 3);
- v |= __SHIFTIN(USBC_UH_USBMODE_CM, USBC_UH_USBMODE_CM_HOST_CONTROLLER);
+ v &= ~USBC_UH_USBMODE_CM;
+ v |= __SHIFTIN(USBC_UH_USBMODE_CM_HOST_CONTROLLER, USBC_UH_USBMODE_CM);
bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBC_UH1_USBMODE, v);
}