Module Name:    src
Committed By:   jmcneill
Date:           Sat Feb 28 15:20:43 UTC 2015

Modified Files:
        src/sys/arch/arm/amlogic: amlogic_board.c amlogic_crureg.h
            amlogic_intr.h amlogic_io.c amlogic_reg.h amlogic_var.h
            files.amlogic
Added Files:
        src/sys/arch/arm/amlogic: amlogic_dwctwo.c

Log Message:
add dwc2 attachment, doesnt quite work yet


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/amlogic/amlogic_board.c \
    src/sys/arch/arm/amlogic/amlogic_crureg.h \
    src/sys/arch/arm/amlogic/amlogic_intr.h \
    src/sys/arch/arm/amlogic/amlogic_io.c \
    src/sys/arch/arm/amlogic/amlogic_reg.h \
    src/sys/arch/arm/amlogic/files.amlogic
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/amlogic/amlogic_dwctwo.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/amlogic/amlogic_var.h

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/amlogic/amlogic_board.c
diff -u src/sys/arch/arm/amlogic/amlogic_board.c:1.2 src/sys/arch/arm/amlogic/amlogic_board.c:1.3
--- src/sys/arch/arm/amlogic/amlogic_board.c:1.2	Fri Feb 27 19:57:10 2015
+++ src/sys/arch/arm/amlogic/amlogic_board.c	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_board.c,v 1.2 2015/02/27 19:57:10 jmcneill Exp $ */
+/* $NetBSD: amlogic_board.c,v 1.3 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -29,7 +29,7 @@
 #include "opt_amlogic.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.2 2015/02/27 19:57:10 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.3 2015/02/28 15:20:43 jmcneill Exp $");
 
 #define	_ARM32_BUS_DMA_PRIVATE
 #include <sys/param.h>
@@ -54,13 +54,12 @@ struct arm32_bus_dma_tag amlogic_dma_tag
 	_BUS_DMATAG_FUNCS,
 };
 
-#define CBUS_READ(x)	\
-	bus_space_read_4(&amlogic_bs_tag, amlogic_core_bsh, (x))
-
-static uint32_t	amlogic_get_rate_xtal(void);
-static uint32_t	amlogic_get_rate_sys(void);
-static uint32_t	amlogic_get_rate_a9(void);
-
+#define CBUS_READ(x)		\
+	bus_space_read_4(&amlogic_bs_tag, amlogic_core_bsh, \
+			 AMLOGIC_CBUS_OFFSET + (x))
+#define CBUS_WRITE(x, v)	\
+	bus_space_write_4(&amlogic_bs_tag, amlogic_core_bsh, \
+			 AMLOGIC_CBUS_OFFSET + (x), (v))
 
 void
 amlogic_bootstrap(void)
@@ -75,7 +74,7 @@ amlogic_bootstrap(void)
 	curcpu()->ci_data.cpu_cc_freq = amlogic_get_rate_a9();
 }
 
-static uint32_t
+uint32_t
 amlogic_get_rate_xtal(void)
 {
 	uint32_t ctlreg0;
@@ -85,7 +84,7 @@ amlogic_get_rate_xtal(void)
 	return __SHIFTOUT(ctlreg0, PREG_CTLREG0_ADDR_CLKRATE) * 1000000;
 }
 
-static uint32_t
+uint32_t
 amlogic_get_rate_sys(void)
 {
 	uint32_t cntl;
@@ -105,7 +104,7 @@ amlogic_get_rate_sys(void)
 	return (uint32_t)clk;
 }
 
-static uint32_t
+uint32_t
 amlogic_get_rate_a9(void)
 {
 	uint32_t cntl0, cntl1;
@@ -147,3 +146,98 @@ amlogic_get_rate_a9(void)
 
 	return rate;
 }
+
+uint32_t
+amlogic_get_rate_a9periph(void)
+{
+	const uint32_t cntl1 = CBUS_READ(HHI_SYS_CPU_CLK_CNTL1_REG);
+	const u_int div = __SHIFTOUT(cntl1,
+				     HHI_SYS_CPU_CLK_CNTL1_PERIPH_CLK_MUX) + 2;
+
+	return amlogic_get_rate_a9() / div;
+}
+
+void
+amlogic_usbphy_init(int port)
+{
+	bus_space_tag_t bst = &amlogic_bs_tag;
+	bus_space_handle_t bsh = amlogic_core_bsh;
+	bus_size_t ctrl_reg, cfg_reg, gpioao_reg;
+	uint32_t ctrl, cfg, gpioao;
+	u_int pin, pol;
+	bool gpio_power = false, gpio_reset = false;
+
+	gpioao_reg = AMLOGIC_GPIOAO_OFFSET;
+
+	switch (port) {
+	case 0:
+		cfg_reg = PREI_USB_PHY_A_CFG_REG;
+		ctrl_reg = PREI_USB_PHY_A_CTRL_REG;
+		pin = 5;
+		pol = 1;
+		gpio_power = true;
+		break;
+	case 1:
+		cfg_reg = PREI_USB_PHY_B_CFG_REG;
+		ctrl_reg = PREI_USB_PHY_B_CTRL_REG;
+		pin = 4;
+		pol = 0;
+		gpio_reset = true;
+		break;
+	default:
+		return;
+	}
+
+	if (gpio_power) {
+		gpioao = bus_space_read_4(bst, bsh, gpioao_reg);
+		gpioao |= __BIT(pin);		/* OEN */
+		if (pol) {
+			gpioao |= __BIT(pin + 16);	/* OUT */
+		} else {
+			gpioao &= ~__BIT(pin + 16);	/* OUT */
+		}
+		bus_space_write_4(bst, bsh, gpioao_reg, gpioao);
+	}
+
+	CBUS_WRITE(RESET1_REG, RESET1_USB);
+
+	delay(1000);
+
+	cfg = CBUS_READ(cfg_reg);
+	cfg |= PREI_USB_PHY_CFG_CLK_32K_ALT_SEL;
+	CBUS_WRITE(cfg_reg, cfg);
+
+	ctrl = CBUS_READ(ctrl_reg);
+	ctrl &= ~PREI_USB_PHY_CTRL_FSEL;
+	ctrl |= __SHIFTIN(PREI_USB_PHY_CTRL_FSEL_24M,
+			  PREI_USB_PHY_CTRL_FSEL);
+	ctrl |= PREI_USB_PHY_CTRL_POR;
+	CBUS_WRITE(ctrl_reg, ctrl);
+
+	delay(1000);
+
+	ctrl = CBUS_READ(ctrl_reg);
+	ctrl &= ~PREI_USB_PHY_CTRL_POR;
+	CBUS_WRITE(ctrl_reg, ctrl);
+
+	delay(50000);
+
+	ctrl = CBUS_READ(ctrl_reg);
+
+	printf("USBPHY: port %d, ctrl %#x\n", port, ctrl);
+
+	if ((ctrl & PREI_USB_PHY_CTRL_CLK_DET) == 0)
+		printf("WARNING: USB PHY port %d clock not detected\n", port);
+
+	if (gpio_reset) {
+		/* Reset */
+		gpioao = bus_space_read_4(bst, bsh, gpioao_reg);
+		gpioao |= __BIT(pin);		/* OEN */
+		if (pol) {
+			gpioao |= __BIT(pin + 16);	/* OUT */
+		} else {
+			gpioao &= ~__BIT(pin + 16);	/* OUT */
+		}
+		bus_space_write_4(bst, bsh, gpioao_reg, gpioao);
+	}
+}
Index: src/sys/arch/arm/amlogic/amlogic_crureg.h
diff -u src/sys/arch/arm/amlogic/amlogic_crureg.h:1.2 src/sys/arch/arm/amlogic/amlogic_crureg.h:1.3
--- src/sys/arch/arm/amlogic/amlogic_crureg.h:1.2	Fri Feb 27 21:13:52 2015
+++ src/sys/arch/arm/amlogic/amlogic_crureg.h	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_crureg.h,v 1.2 2015/02/27 21:13:52 jmcneill Exp $ */
+/* $NetBSD: amlogic_crureg.h,v 1.3 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -33,6 +33,7 @@
 
 #define HHI_SYS_CPU_CLK_CNTL1_REG	CBUS_REG(0x1057)
 #define HHI_SYS_CPU_CLK_CNTL1_SDIV	__BITS(29,20)
+#define HHI_SYS_CPU_CLK_CNTL1_PERIPH_CLK_MUX __BITS(8,6)
 
 #define HHI_SYS_CPU_CLK_CNTL0_REG	CBUS_REG(0x1067)
 #define HHI_SYS_CPU_CLK_CNTL0_CLKSEL	__BIT(7)
@@ -44,9 +45,25 @@
 #define HHI_SYS_PLL_CNTL_DIV		__BITS(14,9)
 #define HHI_SYS_PLL_CNTL_OD		__BITS(17,16)
 
+#define RESET1_REG			CBUS_REG(0x1102)
+#define RESET1_USB			__BIT(2)
+
 #define PREG_CTLREG0_ADDR_REG		CBUS_REG(0x2000)
 #define PREG_CTLREG0_ADDR_CLKRATE	__BITS(9,4)
 
+#define PREI_USB_PHY_A_CFG_REG		CBUS_REG(0x2200)
+#define PREI_USB_PHY_A_CTRL_REG		CBUS_REG(0x2201)
+#define PREI_USB_PHY_B_CFG_REG		CBUS_REG(0x2208)
+#define PREI_USB_PHY_B_CTRL_REG		CBUS_REG(0x2209)
+
+#define PREI_USB_PHY_CFG_CLK_32K_ALT_SEL __BIT(15)
+
+#define PREI_USB_PHY_CTRL_FSEL		__BITS(24,22)
+#define PREI_USB_PHY_CTRL_FSEL_24M	5
+#define PREI_USB_PHY_CTRL_FSEL_12M	2
+#define PREI_USB_PHY_CTRL_POR		__BIT(15)
+#define PREI_USB_PHY_CTRL_CLK_DET	__BIT(8)
+
 #define WATCHDOG_TC_REG			CBUS_REG(0x2640)
 #define WATCHDOG_TC_CPUS		__BITS(27,24)
 #define WATCHDOG_TC_ENABLE		__BIT(19)
Index: src/sys/arch/arm/amlogic/amlogic_intr.h
diff -u src/sys/arch/arm/amlogic/amlogic_intr.h:1.2 src/sys/arch/arm/amlogic/amlogic_intr.h:1.3
--- src/sys/arch/arm/amlogic/amlogic_intr.h:1.2	Fri Feb 27 19:56:07 2015
+++ src/sys/arch/arm/amlogic/amlogic_intr.h	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_intr.h,v 1.2 2015/02/27 19:56:07 jmcneill Exp $ */
+/* $NetBSD: amlogic_intr.h,v 1.3 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -35,6 +35,8 @@
 #include <arm/cortex/gic_intr.h>
 #include <arm/cortex/a9tmr_intr.h>
 
+#define AMLOGIC_INTR_USB0	62
+#define AMLOGIC_INTR_USB1	63
 #define AMLOGIC_INTR_UART2AO	70
 #define AMLOGIC_INTR_UART0AO	122
 
Index: src/sys/arch/arm/amlogic/amlogic_io.c
diff -u src/sys/arch/arm/amlogic/amlogic_io.c:1.2 src/sys/arch/arm/amlogic/amlogic_io.c:1.3
--- src/sys/arch/arm/amlogic/amlogic_io.c:1.2	Fri Feb 27 21:34:40 2015
+++ src/sys/arch/arm/amlogic/amlogic_io.c	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_io.c,v 1.2 2015/02/27 21:34:40 jmcneill Exp $ */
+/* $NetBSD: amlogic_io.c,v 1.3 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -29,7 +29,7 @@
 #include "opt_amlogic.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.2 2015/02/27 21:34:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.3 2015/02/28 15:20:43 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -60,6 +60,14 @@ static const struct amlogic_locators aml
     AMLOGIC_UART0AO_OFFSET, AMLOGIC_UART_SIZE, 0, AMLOGIC_INTR_UART0AO },
   { "amlogiccom",
     AMLOGIC_UART2AO_OFFSET, AMLOGIC_UART_SIZE, 2, AMLOGIC_INTR_UART2AO },
+  { "dwctwo",
+    AMLOGIC_USB0_OFFSET, AMLOGIC_USB_SIZE, 0, AMLOGIC_INTR_USB0 },
+  { "dwctwo",
+    AMLOGIC_USB1_OFFSET, AMLOGIC_USB_SIZE, 1, AMLOGIC_INTR_USB1 },
+#if notyet
+  { "amlogicmmc",
+    AMLOGIC_MMC_OFFSET, AMLOGIC_MMC_SIZE, 0, AMLOGIC_INTR_MMC },
+#endif
 };
 
 int
@@ -78,6 +86,9 @@ amlogicio_attach(device_t parent, device
 	aprint_naive("\n");
 	aprint_normal("\n");
 
+	amlogic_usbphy_init(0);
+	amlogic_usbphy_init(1);
+
 	const struct amlogic_locators * const eloc =
 	    amlogic_locators + __arraycount(amlogic_locators);
 	for (const struct amlogic_locators *loc = amlogic_locators;
Index: src/sys/arch/arm/amlogic/amlogic_reg.h
diff -u src/sys/arch/arm/amlogic/amlogic_reg.h:1.2 src/sys/arch/arm/amlogic/amlogic_reg.h:1.3
--- src/sys/arch/arm/amlogic/amlogic_reg.h:1.2	Fri Feb 27 19:57:10 2015
+++ src/sys/arch/arm/amlogic/amlogic_reg.h	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_reg.h,v 1.2 2015/02/27 19:57:10 jmcneill Exp $ */
+/* $NetBSD: amlogic_reg.h,v 1.3 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -36,6 +36,7 @@
 #define AMLOGIC_CORE_VBASE	0xe0000000
 
 #define AMLOGIC_CBUS_OFFSET	0x01100000
+
 #define AMLOGIC_UART0_OFFSET	0x01102130
 #define AMLOGIC_UART1_OFFSET	0x01102137
 #define AMLOGIC_UART2_OFFSET	0x011021c0
@@ -44,6 +45,15 @@
 #define AMLOGIC_UART_SIZE	0x20
 #define AMLOGIC_UART_FREQ	24000000
 
+#define AMLOGIC_MMC_OFFSET	0x01108e00
+#define AMLOGIC_MMC_SIZE	0x30
+
 #define AMLOGIC_PL310_OFFSET	0x04200000
 
+#define AMLOGIC_GPIOAO_OFFSET	0x08100024
+
+#define AMLOGIC_USB0_OFFSET	0x09040000
+#define AMLOGIC_USB1_OFFSET	0x090c0000
+#define AMLOGIC_USB_SIZE	0x40000
+
 #endif /* _ARM_AMLOGIC_REG_H */
Index: src/sys/arch/arm/amlogic/files.amlogic
diff -u src/sys/arch/arm/amlogic/files.amlogic:1.2 src/sys/arch/arm/amlogic/files.amlogic:1.3
--- src/sys/arch/arm/amlogic/files.amlogic:1.2	Fri Feb 27 17:35:08 2015
+++ src/sys/arch/arm/amlogic/files.amlogic	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amlogic,v 1.2 2015/02/27 17:35:08 jmcneill Exp $
+#	$NetBSD: files.amlogic,v 1.3 2015/02/28 15:20:43 jmcneill Exp $
 #
 # Configuration info for Amlogic ARM Peripherals
 #
@@ -21,10 +21,19 @@ attach	amlogicio at mainbus with amlogic
 file	arch/arm/amlogic/amlogic_io.c		amlogic_io
 
 # serial
-device	amlogiccom { } : bus_space_generic
+device	amlogiccom
 attach	amlogiccom at amlogicio with amlogic_com
 file	arch/arm/amlogic/amlogic_com.c		amlogic_com needs-flag
 
+# mmc/sd/sdio
+device	amlogicmmc: sdmmcbus
+attach	amlogicmmc at amlogicio with amlogic_mmc
+file	arch/arm/amlogic/amlogic_mmc.c		amlogic_mmc
+
+# usb otg
+attach	dwctwo at amlogicio with amlogic_dwctwo
+file	arch/arm/amlogic/amlogic_dwctwo.c	amlogic_dwctwo
+
 # Console parameters
 defparam opt_amlogic.h			CONADDR
 defparam opt_amlogic.h			CONSPEED

Index: src/sys/arch/arm/amlogic/amlogic_var.h
diff -u src/sys/arch/arm/amlogic/amlogic_var.h:1.1 src/sys/arch/arm/amlogic/amlogic_var.h:1.2
--- src/sys/arch/arm/amlogic/amlogic_var.h:1.1	Sat Feb  7 17:20:17 2015
+++ src/sys/arch/arm/amlogic/amlogic_var.h	Sat Feb 28 15:20:43 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_var.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */
+/* $NetBSD: amlogic_var.h,v 1.2 2015/02/28 15:20:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -56,4 +56,11 @@ extern struct arm32_bus_dma_tag amlogic_
 
 void	amlogic_bootstrap(void);
 
+void	amlogic_usbphy_init(int);
+
+uint32_t amlogic_get_rate_xtal(void);
+uint32_t amlogic_get_rate_sys(void);
+uint32_t amlogic_get_rate_a9(void);
+uint32_t amlogic_get_rate_a9periph(void);
+
 #endif /* _ARM_AMLOGIC_VAR_H */

Added files:

Index: src/sys/arch/arm/amlogic/amlogic_dwctwo.c
diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_dwctwo.c:1.1
--- /dev/null	Sat Feb 28 15:20:43 2015
+++ src/sys/arch/arm/amlogic/amlogic_dwctwo.c	Sat Feb 28 15:20:43 2015
@@ -0,0 +1,153 @@
+/*	$NetBSD: amlogic_dwctwo.c,v 1.1 2015/02/28 15:20:43 jmcneill Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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>
+__KERNEL_RCSID(0, "$NetBSD: amlogic_dwctwo.c,v 1.1 2015/02/28 15:20:43 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/mutex.h>
+#include <sys/bus.h>
+#include <sys/workqueue.h>
+
+#include <arm/amlogic/amlogic_reg.h>
+#include <arm/amlogic/amlogic_crureg.h>
+#include <arm/amlogic/amlogic_var.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdivar.h>
+#include <dev/usb/usb_mem.h>
+
+#include <dwc2/dwc2var.h>
+
+#include <dwc2/dwc2.h>
+#include "dwc2_core.h"
+
+struct amlogic_dwctwo_softc {
+	struct dwc2_softc	sc_dwc2;
+
+	void			*sc_ih;
+};
+
+static struct dwc2_core_params amlogic_dwctwo_params = {
+	.otg_cap			= 2,	/* 0 - HNP/SRP capable */
+	.otg_ver			= 1,	/* 1 - 2.0 */
+	.dma_enable			= 1,	/* 1 - DMA (default, if available) */
+	.dma_desc_enable		= 1,	/* 1 - Descriptor DMA (default, if available) */
+	.speed				= 0,	/* 0 - High Speed */
+	.enable_dynamic_fifo		= 1,	/* 1 - Allow dynamic FIFO sizing (default, if available) */
+	.en_multiple_tx_fifo		= 1,	/* Specifies whether dedicated per-endpoint transmit FIFOs are enabled */
+	.host_rx_fifo_size		= 520,	/* 520 DWORDs */
+	.host_nperio_tx_fifo_size	= 128,	/* 128 DWORDs */
+	.host_perio_tx_fifo_size	= 256,	/* 256 DWORDs */
+	.max_transfer_size		= 65535,/* 2047 to 65,535 */ 
+	.max_packet_count		= 511,  /* 15 to 511 */
+	.host_channels			= 8,	/* 1 to 16 */
+	.phy_type			= 1, 	/* 1- UTMI+ Phy */
+	.phy_utmi_width			= 8,	/* 8 bits */
+	.phy_ulpi_ddr			= 0,	/* Single */
+	.phy_ulpi_ext_vbus		= 0,
+	.i2c_enable			= 0,
+	.ulpi_fs_ls			= 0,	/* 0 - No (default) */
+	.host_support_fs_ls_low_power	= 0,	/* 0 - Don't support low power mode (default) */
+	.host_ls_low_power_phy_clk	= 0,	/* 1 - 48 MHz  default when phy_type is UTMI+ or ULPI*/
+	.ts_dline			= 0,	/* 0 - No (default) */
+	.reload_ctl			= 0,	/* 0 - No (default for core < 2.92a) */
+	.ahbcfg				= 0x7,	/* INCR16 */
+	.uframe_sched			= 1,	/* True to enable microframe scheduler */
+};
+
+static int amlogic_dwctwo_match(device_t, struct cfdata *, void *);
+static void amlogic_dwctwo_attach(device_t, device_t, void *);
+static void amlogic_dwctwo_deferred(device_t);
+
+CFATTACH_DECL_NEW(amlogic_dwctwo, sizeof(struct amlogic_dwctwo_softc),
+    amlogic_dwctwo_match, amlogic_dwctwo_attach, NULL, NULL);
+
+static int
+amlogic_dwctwo_match(device_t parent, struct cfdata *match, void *aux)
+{
+	return 1;
+}
+
+static void
+amlogic_dwctwo_attach(device_t parent, device_t self, void *aux)
+{
+	struct amlogic_dwctwo_softc * const sc = device_private(self);
+	struct amlogicio_attach_args * const aio = aux;
+	const struct amlogic_locators * const loc = &aio->aio_loc;
+
+	sc->sc_dwc2.sc_dev = self;
+
+	sc->sc_dwc2.sc_iot = aio->aio_core_bst;
+	bus_space_subregion(aio->aio_core_bst, aio->aio_bsh,
+            loc->loc_offset, loc->loc_size, &sc->sc_dwc2.sc_ioh);
+	sc->sc_dwc2.sc_bus.dmatag = aio->aio_dmat;
+	sc->sc_dwc2.sc_params = &amlogic_dwctwo_params;
+
+	aprint_naive("\n");
+	aprint_normal(": USB controller\n");
+
+	sc->sc_ih = intr_establish(loc->loc_intr, IPL_SCHED,
+	   IST_LEVEL, dwc2_intr, &sc->sc_dwc2);
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "failed to establish interrupt %d\n",
+		     loc->loc_intr);
+		goto fail;
+	}
+	config_defer(self, amlogic_dwctwo_deferred);
+
+	return;
+
+fail:
+	if (sc->sc_ih) {
+		intr_disestablish(sc->sc_ih);
+		sc->sc_ih = NULL;
+	}
+}
+
+static void
+amlogic_dwctwo_deferred(device_t self)
+{
+	struct amlogic_dwctwo_softc *sc = device_private(self);
+	int error;
+
+	error = dwc2_init(&sc->sc_dwc2);
+	if (error != 0) {
+		aprint_error_dev(self, "couldn't initialize host, error=%d\n",
+		    error);
+		return;
+	}
+	sc->sc_dwc2.sc_child = config_found(sc->sc_dwc2.sc_dev,
+	    &sc->sc_dwc2.sc_bus, usbctlprint);
+}

Reply via email to