Module Name:    src
Committed By:   reinoud
Date:           Tue Apr 29 16:47:10 UTC 2014

Modified Files:
        src/sys/arch/arm/samsung: exynos4_loc.c exynos4_reg.h exynos5_loc.c
            exynos_io.c exynos_soc.c exynos_var.h files.exynos
        src/sys/arch/evbarm/conf: ODROID-U
Added Files:
        src/sys/arch/arm/samsung: exynos_dma.c exynos_usb.c

Log Message:
Commit initial USB adapter support and associated DMA tags


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/samsung/exynos4_loc.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/samsung/exynos4_reg.h \
    src/sys/arch/arm/samsung/exynos5_loc.c \
    src/sys/arch/arm/samsung/exynos_io.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/samsung/exynos_dma.c \
    src/sys/arch/arm/samsung/exynos_usb.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/samsung/exynos_soc.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/samsung/exynos_var.h \
    src/sys/arch/arm/samsung/files.exynos
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/conf/ODROID-U

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/samsung/exynos4_loc.c
diff -u src/sys/arch/arm/samsung/exynos4_loc.c:1.2 src/sys/arch/arm/samsung/exynos4_loc.c:1.3
--- src/sys/arch/arm/samsung/exynos4_loc.c:1.2	Sun Apr 27 20:43:19 2014
+++ src/sys/arch/arm/samsung/exynos4_loc.c	Tue Apr 29 16:47:10 2014
@@ -260,8 +260,8 @@
 #define IRQ_MDNIE_LCD0_1		EXYNOS_COMBINERIRQ(0, 1)
 #define IRQ_MDNIE_LCD0_0		EXYNOS_COMBINERIRQ(0, 0)
 
-#define	OFFANDSIZE(p,n) EXYNOS4##p##_##n##_OFFSET, 0x10000
-
+#define	OFFANDSIZE(p,n) \
+	EXYNOS4##p##_##n##_OFFSET, 0x10000
 
 static const struct exyo_locators exynos4_locators[] = {
 	{ "mct", OFFANDSIZE(,MCT), NOPORT, IRQ_G0_IRQ, 0 },
@@ -270,6 +270,7 @@ static const struct exyo_locators exynos
 	{ "sscom", OFFANDSIZE(,UART1), 1, IRQ_UART1, 0 },
 	{ "sscom", OFFANDSIZE(,UART2), 2, IRQ_UART2, 0 },
 	{ "sscom", OFFANDSIZE(,UART3), 3, IRQ_UART3, 0 },
+	{ "exyousb", OFFANDSIZE(,USBHOST0), 0, IRQ_UHOST, 0},	/* ehci+ohci */
 };
 
 const struct exyo_locinfo exynos4_locinfo = {

Index: src/sys/arch/arm/samsung/exynos4_reg.h
diff -u src/sys/arch/arm/samsung/exynos4_reg.h:1.1 src/sys/arch/arm/samsung/exynos4_reg.h:1.2
--- src/sys/arch/arm/samsung/exynos4_reg.h:1.1	Sun Apr 13 02:26:26 2014
+++ src/sys/arch/arm/samsung/exynos4_reg.h	Tue Apr 29 16:47:10 2014
@@ -204,8 +204,8 @@
 #define EXYNOS4_SDMMC4_OFFSET		0x02550000
 #define EXYNOS4_MIPI_HSI_OFFSET		0x02560000	/* LCD0 */
 #define EXYNOS4_SROMC_OFFSET		0x02570000
-#define EXYNOS4_USBHOST0_OFFSET		0x02580000	/* USB interface 0 */
-#define EXYNOS4_USBHOST1_OFFSET		0x02590000	/* USB interface 1 */
+#define EXYNOS4_USBHOST0_OFFSET		0x02580000	/* USB EHCI */
+#define EXYNOS4_USBHOST1_OFFSET		0x02590000	/* USB OHCI companion to EHCI (paired) */
 #define EXYNOS4_USBOTG1_OFFSET		0x025B0000	/* USB On The Go interface */
 #define EXYNOS4_PDMA0_OFFSET		0x02680000	/* Peripheral DMA */
 #define EXYNOS4_PDMA1_OFFSET		0x02690000
Index: src/sys/arch/arm/samsung/exynos5_loc.c
diff -u src/sys/arch/arm/samsung/exynos5_loc.c:1.1 src/sys/arch/arm/samsung/exynos5_loc.c:1.2
--- src/sys/arch/arm/samsung/exynos5_loc.c:1.1	Sun Apr 13 02:26:26 2014
+++ src/sys/arch/arm/samsung/exynos5_loc.c	Tue Apr 29 16:47:10 2014
@@ -209,7 +209,8 @@
 #define IRQ_TZASC_CBXR			EXYNOS_COMBINERIRQ(0, 0)
 
 
-#define	OFFANDSIZE(p,n) EXYNOS5##p##_##n##_OFFSET, 0x10000
+#define	OFFANDSIZE(p,n) \
+	EXYNOS5##p##_##n##_OFFSET, 0x10000
 
 static const struct exyo_locators exynos5_locators[] = {
 	{ "exywdt", OFFANDSIZE(,WDT), NOPORT, IRQ_WDT, 0 },
Index: src/sys/arch/arm/samsung/exynos_io.c
diff -u src/sys/arch/arm/samsung/exynos_io.c:1.1 src/sys/arch/arm/samsung/exynos_io.c:1.2
--- src/sys/arch/arm/samsung/exynos_io.c:1.1	Sun Apr 13 02:26:26 2014
+++ src/sys/arch/arm/samsung/exynos_io.c	Tue Apr 29 16:47:10 2014
@@ -34,7 +34,7 @@
 #include "opt_exynos.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_io.c,v 1.1 2014/04/13 02:26:26 matt Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_io.c,v 1.2 2014/04/29 16:47:10 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -58,12 +58,12 @@ static int  exyo_match(device_t, cfdata_
 static void exyo_attach(device_t, device_t, void *);
 
 static struct exyo_softc {
-	device_t sc_dev;
-	bus_space_tag_t sc_bst;
-	bus_space_tag_t sc_a4x_bst;
-	bus_space_handle_t sc_bsh;
-	bus_dma_tag_t sc_dmat;
-	bus_dma_tag_t sc_coherent_dmat;
+	device_t		sc_dev;
+	bus_space_tag_t		sc_bst;
+	bus_space_tag_t		sc_a4x_bst;
+	bus_space_handle_t	sc_bsh;
+	bus_dma_tag_t		sc_dmat;
+	bus_dma_tag_t		sc_coherent_dmat;
 } exyo_sc;
 
 CFATTACH_DECL_NEW(exyo_io, 0, exyo_match, exyo_attach, NULL, NULL);
@@ -119,27 +119,29 @@ exyo_find(device_t parent, cfdata_t cf, 
 	return config_match(parent, cf, aux);
 }
 
+
+#if !defined(EXYNOS4) && !defined(EXYNOS5)
+#error Must define a SoC
+#endif
 static void
 exyo_attach(device_t parent, device_t self, void *aux)
 {
+	const struct exyo_locators *l = NULL;
 	struct exyo_softc * const sc = &exyo_sc;
 	prop_dictionary_t dict = device_properties(self);
+	size_t nl = 0;
 
 	sc->sc_dev = self;
-
 	sc->sc_bst = &exynos_bs_tag;
 	sc->sc_a4x_bst = &exynos_a4x_bs_tag;
 	sc->sc_bsh = exynos_core_bsh;
-//	sc->sc_dmat = &exynos_dma_tag;
-//	sc->sc_coherent_dmat = &exynos_coherent_dma_tag;
+	sc->sc_dmat = &exynos_bus_dma_tag;
+	sc->sc_coherent_dmat = &exynos_coherent_bus_dma_tag;
 
 	const uint16_t product_id = EXYNOS_PRODUCT_ID(exynos_soc_id);
 	aprint_naive(": Exynos %x\n", product_id);
 	aprint_normal(": Exynos %x\n", product_id);
 
-	const struct exyo_locators *l = NULL;
-	size_t nl = 0;
-
 #if defined(EXYNOS4)
 	if (IS_EXYNOS4_P()) {
 		l = exynos4_locinfo.locators;
@@ -152,9 +154,6 @@ exyo_attach(device_t parent, device_t se
 		nl = exynos5_locinfo.nlocators;
 	}	
 #endif 
-#if !defined(EXYNOS4) && !defined(EXYNOS5)
-#error Must define a SoC
-#endif
 	KASSERT(l != NULL);
 	KASSERT(nl > 0);
 

Index: src/sys/arch/arm/samsung/exynos_soc.c
diff -u src/sys/arch/arm/samsung/exynos_soc.c:1.6 src/sys/arch/arm/samsung/exynos_soc.c:1.7
--- src/sys/arch/arm/samsung/exynos_soc.c:1.6	Tue Apr 22 16:10:48 2014
+++ src/sys/arch/arm/samsung/exynos_soc.c	Tue Apr 29 16:47:10 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: exynos_soc.c,v 1.6 2014/04/22 16:10:48 reinoud Exp $	*/
+/*	$NetBSD: exynos_soc.c,v 1.7 2014/04/29 16:47:10 reinoud Exp $	*/
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #define	_ARM32_BUS_DMA_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.6 2014/04/22 16:10:48 reinoud Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.7 2014/04/29 16:47:10 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -231,6 +231,9 @@ exynos_bootstrap(vaddr_t iobase, vaddr_t
 		panic("%s: failed to map in Exynos io registers: %d",
 			__func__, error);
 	KASSERT(exynos_core_bsh == iobase);
+
+	/* init bus dma tags */
+	exynos_dma_bootstrap(physmem * PAGE_SIZE);
 }
 
 

Index: src/sys/arch/arm/samsung/exynos_var.h
diff -u src/sys/arch/arm/samsung/exynos_var.h:1.3 src/sys/arch/arm/samsung/exynos_var.h:1.4
--- src/sys/arch/arm/samsung/exynos_var.h:1.3	Sun Apr 13 20:45:25 2014
+++ src/sys/arch/arm/samsung/exynos_var.h	Tue Apr 29 16:47:10 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: exynos_var.h,v 1.3 2014/04/13 20:45:25 reinoud Exp $ */
+/* $NetBSD: exynos_var.h,v 1.4 2014/04/29 16:47:10 reinoud Exp $ */
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -75,8 +75,6 @@ struct exyo_locators {
 	int loc_flags;
 };
 
-#define EXYO_INTR_DEFAULT 0
-
 #if 0
 #define EXYO_E4410	__BIT(0)
 #define EXYO_E4412	__BIT(1)
@@ -100,12 +98,17 @@ struct exyo_attach_args {
 
 extern struct bus_space exynos_bs_tag;
 extern struct bus_space exynos_a4x_bs_tag;
+extern struct arm32_bus_dma_tag exynos_bus_dma_tag;
+extern struct arm32_bus_dma_tag exynos_coherent_bus_dma_tag;
+
 extern bus_space_handle_t exynos_core_bsh;
 
 extern void exynos_bootstrap(vaddr_t, vaddr_t);
 extern void exynos_device_register(device_t self, void *aux);
 extern void exyo_device_register(device_t self, void *aux);
 extern void exynos_wdt_reset(void);
+extern void exynos_dma_bootstrap(psize_t memsize);
+
 
 #ifdef ARM_TRUSTZONE_FIRMWARE
 /* trustzone calls */
Index: src/sys/arch/arm/samsung/files.exynos
diff -u src/sys/arch/arm/samsung/files.exynos:1.3 src/sys/arch/arm/samsung/files.exynos:1.4
--- src/sys/arch/arm/samsung/files.exynos:1.3	Tue Apr 22 16:08:24 2014
+++ src/sys/arch/arm/samsung/files.exynos	Tue Apr 29 16:47:10 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.exynos,v 1.3 2014/04/22 16:08:24 reinoud Exp $
+#	$NetBSD: files.exynos,v 1.4 2014/04/29 16:47:10 reinoud Exp $
 #
 # Configuration info for Samsung Exynos SoC ARM Peripherals
 #
@@ -15,7 +15,7 @@ file	arch/arm/arm32/irq_dispatch.S
 
 file	arch/arm/samsung/exynos_soc.c
 file	arch/arm/samsung/exynos_space.c
-#file	arch/arm/samsung/primecell.c
+file	arch/arm/samsung/exynos_dma.c
 file	arch/arm/samsung/exynos_smc.S		arm_trustzone_firmware
 
 file	arch/arm/arm/bus_space_a4x.S		exyo
@@ -56,19 +56,23 @@ device	mct { } : bus_space_generic
 attach	mct at exyo with exyo_mct
 file	arch/arm/samsung/mct.c		exyo_mct
 
-# watchdog
+# Watchdog
 device	exywdt : sysmon_wdog
 attach	exywdt at exyo with exynos_wdt
 file	arch/arm/samsung/exynos_wdt.c	exynos_wdt | exyo_io needs-flag
 
 # UARTs
-#
-# built-in UART
-#
-device	sscom
+device	sscom { } : bus_space_generic
 attach	sscom at exyo with exynos_sscom
 file	arch/arm/samsung/sscom.c	sscom needs-flag
 file	arch/arm/samsung/exynos_sscom.c	exynos_sscom 
 defflag opt_sscom.h     SSCOM0CONSOLE SSCOM1CONSOLE
 defparam opt_sscom.h    SSCOM_FREQ 
 
+# USB2 Host Controller (EHCI/OHCI)
+device	exyousb { }
+attach	exyousb at exyo with exyo_usb
+attach	ohci at exyousb with ohci_exyousb
+attach	ehci at exyousb with ehci_exyousb
+file	arch/arm/samsung/exynos_usb.c		exyo_usb
+

Index: src/sys/arch/evbarm/conf/ODROID-U
diff -u src/sys/arch/evbarm/conf/ODROID-U:1.2 src/sys/arch/evbarm/conf/ODROID-U:1.3
--- src/sys/arch/evbarm/conf/ODROID-U:1.2	Sat Apr 19 15:32:18 2014
+++ src/sys/arch/evbarm/conf/ODROID-U	Tue Apr 29 16:47:10 2014
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: ODROID-U,v 1.2 2014/04/19 15:32:18 reinoud Exp $
+#	$NetBSD: ODROID-U,v 1.3 2014/04/29 16:47:10 reinoud Exp $
 #
 #	ODROID-U -- ODROID-U series Exynos Kernel
 #
@@ -138,6 +138,7 @@ options 	KTRACE		# system call tracing, 
 #options 	PERFCTRS	# performance counters
 options 	DIAGNOSTIC	# internally consistency checks
 options 	DEBUG
+options		LOCKDEBUG
 #options 	PMAP_DEBUG	# Enable pmap_debug_level code
 #options 	IPKDB		# remote kernel debugging
 #options 	VERBOSE_INIT_ARM # verbose bootstraping messages
@@ -192,12 +193,11 @@ sscom1		at exyo0  port 1		# UART1
 exywdt0 	at exyo0 flags 1		# watchdog
 
 # On-board USB
-#exyousb0	at exyo0 port 0
-#exyousb1	at exyo0 port 1
-#ohci*		at exyousb?
-#ehci*		at exyousb?
-#usb*		at ohci?
-#usb*		at ehci?
+exyousb*	at exyo0
+ohci*		at exyousb?
+ehci*		at exyousb?
+usb*		at ohci?
+usb*		at ehci?
 
 
 # Odroid-U connectivity
@@ -207,7 +207,7 @@ exywdt0 	at exyo0 flags 1		# watchdog
 options		SSCOM1CONSOLE, CONSPEED=115200
 
 # include all USB devices
-#include "dev/usb/usbdevices.config"
+include "dev/usb/usbdevices.config"
 
 
 # Pseudo-Devices

Added files:

Index: src/sys/arch/arm/samsung/exynos_dma.c
diff -u /dev/null src/sys/arch/arm/samsung/exynos_dma.c:1.1
--- /dev/null	Tue Apr 29 16:47:10 2014
+++ src/sys/arch/arm/samsung/exynos_dma.c	Tue Apr 29 16:47:10 2014
@@ -0,0 +1,85 @@
+/*	$NetBSD: exynos_dma.c,v 1.1 2014/04/29 16:47:10 reinoud Exp $	*/
+
+/*-
+ * Copyright (c) 2012 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 "opt_exynos.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: exynos_dma.c,v 1.1 2014/04/29 16:47:10 reinoud Exp $");
+
+#define _ARM32_BUS_DMA_PRIVATE
+
+#include <sys/param.h>
+#include <sys/bus.h>
+
+#include <arm/samsung/exynos_reg.h>
+#include <arm/samsung/exynos_var.h>
+
+struct arm32_bus_dma_tag exynos_bus_dma_tag = {
+	_BUS_DMAMAP_FUNCS,
+	_BUS_DMAMEM_FUNCS,
+	_BUS_DMATAG_FUNCS,
+};
+
+struct arm32_dma_range exynos_coherent_dma_ranges[1] = {
+	[0] = {
+		.dr_sysbase = 0,	/* filled in */
+		.dr_busbase = 0,	/* filled in */
+		.dr_flags = _BUS_DMAMAP_COHERENT,
+	},
+};
+
+struct arm32_bus_dma_tag exynos_coherent_bus_dma_tag = {
+	._ranges  = exynos_coherent_dma_ranges,
+	._nranges = __arraycount(exynos_coherent_dma_ranges),
+	_BUS_DMAMAP_FUNCS,
+	_BUS_DMAMEM_FUNCS,
+	_BUS_DMATAG_FUNCS,
+};
+
+
+#ifndef EXYNOS4
+#	define EXYNOS4_SDRAM_PBASE 0
+#endif
+#ifndef EXYNOS5
+#	define EXYNOS5_SDRAM_PBASE 0
+#endif
+void
+exynos_dma_bootstrap(psize_t memsize)
+{
+	bus_addr_t dram_base = IS_EXYNOS4_P() ?
+		EXYNOS4_SDRAM_PBASE : EXYNOS5_SDRAM_PBASE;
+
+	KASSERT(dram_base);
+	exynos_coherent_dma_ranges[0].dr_sysbase = dram_base;
+	exynos_coherent_dma_ranges[0].dr_busbase = dram_base;
+	exynos_coherent_dma_ranges[0].dr_len = memsize;
+}
+
Index: src/sys/arch/arm/samsung/exynos_usb.c
diff -u /dev/null src/sys/arch/arm/samsung/exynos_usb.c:1.1
--- /dev/null	Tue Apr 29 16:47:10 2014
+++ src/sys/arch/arm/samsung/exynos_usb.c	Tue Apr 29 16:47:10 2014
@@ -0,0 +1,331 @@
+/*	$NetBSD: exynos_usb.c,v 1.1 2014/04/29 16:47:10 reinoud Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Reinoud Zandijk.
+ *
+ * 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 "locators.h"
+#include "ohci.h"
+#include "ehci.h"
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(1, "$NetBSD: exynos_usb.c,v 1.1 2014/04/29 16:47:10 reinoud Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/intr.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/queue.h>
+#include <sys/kmem.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdivar.h>
+#include <dev/usb/usb_mem.h>
+
+#if NOHCI > 0
+#include <dev/usb/ohcireg.h>
+#include <dev/usb/ohcivar.h>
+#endif
+
+#if NEHCI > 0
+#include <dev/usb/ehcireg.h>
+#include <dev/usb/ehcivar.h>
+#endif
+
+#include <arm/samsung/exynos_reg.h>
+#include <arm/samsung/exynos_var.h>
+
+
+static int exynos_usb_ports = 0;
+
+struct exynos_usb_softc {
+	device_t	 sc_self;
+	int		 sc_port;
+	int		 sc_irq;
+
+	/* keep our tags here */
+	bus_dma_tag_t	 sc_dmat;
+	bus_space_tag_t  sc_bst;
+
+	bus_space_handle_t sc_ehci_bsh;
+	bus_space_handle_t sc_ohci_bsh;
+
+	device_t	 sc_ohci_dev;
+	device_t	 sc_ehci_dev;
+
+	void		*sc_intrh;
+};
+
+struct exynos_usb_attach_args {
+	const char *name;
+};
+
+static int exynos_usb_intr(void *arg);
+
+
+static int	exynos_usb_match(device_t, cfdata_t, void *);
+static void	exynos_usb_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(exyo_usb, sizeof(struct exynos_usb_softc),
+    exynos_usb_match, exynos_usb_attach, NULL, NULL);
+
+
+static int
+exynos_usb_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct exyo_attach_args *exyoaa = (struct exyo_attach_args *) aux;
+
+	/* no multiple attachments on same port nr */
+	if (exynos_usb_ports & __BIT(exyoaa->exyo_loc.loc_port))
+		return 0;
+
+	return 1;
+}
+
+
+#define OHCI_OFFSET 0x10000
+static void
+exynos_usb_attach(device_t parent, device_t self, void *aux)
+{
+	struct exynos_usb_softc * const sc = device_private(self);
+	struct exyo_attach_args *exyoaa = (struct exyo_attach_args *) aux;
+
+	/* mark we're here */
+	exynos_usb_ports |= __BIT(exyoaa->exyo_loc.loc_port);
+
+	/* copy our attachment info */
+	sc->sc_self = self;
+	sc->sc_port = exyoaa->exyo_loc.loc_port;
+	sc->sc_irq  = exyoaa->exyo_loc.loc_intr;
+
+	/* get our bushandles */
+	sc->sc_bst  = exyoaa->exyo_core_bst;
+	sc->sc_dmat = exyoaa->exyo_dmat;
+
+	bus_space_subregion(sc->sc_bst, exyoaa->exyo_core_bsh,
+		exyoaa->exyo_loc.loc_offset, exyoaa->exyo_loc.loc_size,
+		&sc->sc_ehci_bsh);
+	bus_space_subregion(sc->sc_bst, exyoaa->exyo_core_bsh,
+		exyoaa->exyo_loc.loc_offset + OHCI_OFFSET,
+		exyoaa->exyo_loc.loc_size,
+		&sc->sc_ohci_bsh);
+
+	aprint_naive("\n");
+	aprint_normal("\n");
+
+	/*
+	 * Disable interrupts
+	 */
+#if NOHCI > 0
+	bus_space_write_4(sc->sc_bst, sc->sc_ohci_bsh,
+	    OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS);
+#endif
+#if NEHCI > 0
+	bus_size_t caplength = bus_space_read_1(sc->sc_bst,
+	    sc->sc_ehci_bsh, EHCI_CAPLENGTH);
+	bus_space_write_4(sc->sc_bst, sc->sc_ehci_bsh,
+	    caplength + EHCI_USBINTR, 0);
+#endif
+
+	/* TBD enable USB phy  */
+	/* TBD program USB hub */
+
+	/* claim shared interrupt for OHCI/EHCI */
+	sc->sc_intrh = intr_establish(sc->sc_irq, IPL_USB, IST_LEVEL,
+		exynos_usb_intr, sc);
+	if (!sc->sc_intrh) {
+		aprint_error(": unable to establish interrupt at irq %d\n",
+			sc->sc_irq);
+		/* disable? TBD */
+		return;
+	}
+	aprint_normal_dev(sc->sc_self, "interrupting on irq %d\n", sc->sc_irq);
+
+#if NOHCI > 0
+	/* attach OHCI */
+	struct exynos_usb_attach_args usb_ohci = {
+		.name = "ohci",
+	};
+	sc->sc_ohci_dev = config_found(self, &usb_ohci, NULL);
+#endif
+
+#if NEHCI > 0
+	/* attach EHCI */
+	struct exynos_usb_attach_args usb_ehci = {
+		.name = "ehci",
+	};
+	sc->sc_ehci_dev = config_found(self, &usb_ehci, NULL);
+#endif
+}
+
+
+static int
+exynos_usb_intr(void *arg)
+{
+	struct exynos_usb_softc *sc = (struct exynos_usb_softc *) arg;
+	void *private;
+	int ret = 0;
+
+#if NEHCI > 0
+	private = device_private(sc->sc_ehci_dev);
+	if (private)
+		ret = ehci_intr(private);
+#endif
+	/* XXX should we always deliver to ohci even if ehci takes it? */
+//	if (ret)
+//		return ret;
+#if NOHCI > 0
+	private = device_private(sc->sc_ohci_dev);
+	if (private)
+		ret = ohci_intr(private);
+#endif
+
+	return ret;
+}
+
+
+#if NOHCI > 0
+static int	exynos_ohci_match(device_t, cfdata_t, void *);
+static void	exynos_ohci_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(ohci_exyousb, sizeof(struct ohci_softc),
+    exynos_ohci_match, exynos_ohci_attach, NULL, NULL);
+
+
+static int
+exynos_ohci_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct exynos_usb_attach_args *euaa = aux;
+
+	if (strcmp(euaa->name, "ohci"))
+		return 0;
+
+	return 1;
+}
+
+
+static void
+exynos_ohci_attach(device_t parent, device_t self, void *aux)
+{
+	struct exynos_usb_softc *usbsc = device_private(parent);
+	struct ohci_softc *sc = device_private(self);
+	int r;
+
+	sc->sc_dev = self;
+	sc->iot = usbsc->sc_bst;
+	sc->ioh = usbsc->sc_ohci_bsh;
+	sc->sc_size = EXYNOS_BLOCK_SIZE;
+	sc->sc_bus.dmatag = usbsc->sc_dmat;
+	sc->sc_bus.hci_private = sc;
+
+//sc->sc_bus.use_polling=1;
+
+	strlcpy(sc->sc_vendor, "exynos", sizeof(sc->sc_vendor));
+
+	aprint_naive(": OHCI USB controller\n");
+	aprint_normal(": OHCI USB controller\n");
+
+	/* enable things ? extra settings? TBD */
+
+	/* attach */
+	r = ohci_init(sc);
+	if (r != USBD_NORMAL_COMPLETION) {
+		aprint_error_dev(self, "init failed, errpr = %d\n", r);
+		/* disable : TBD */
+		return;
+	}
+	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
+	aprint_normal_dev(sc->sc_dev, "interrupting on irq %d\n", usbsc->sc_irq);
+}
+#endif
+
+
+#if NEHCI > 0
+static int	exynos_ehci_match(device_t, cfdata_t, void *);
+static void	exynos_ehci_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(ehci_exyousb, sizeof(struct ehci_softc),
+    exynos_ehci_match, exynos_ehci_attach, NULL, NULL);
+
+
+static int
+exynos_ehci_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct exynos_usb_attach_args *euaa = aux;
+
+	if (strcmp(euaa->name, "ehci"))
+		return 0;
+
+	return 1;
+}
+
+
+static void
+exynos_ehci_attach(device_t parent, device_t self, void *aux)
+{
+	struct exynos_usb_softc *usbsc = device_private(parent);
+	struct ehci_softc *sc = device_private(self);
+	int r;
+
+	sc->sc_dev = self;
+	sc->iot = usbsc->sc_bst;
+	sc->ioh = usbsc->sc_ehci_bsh;
+	sc->sc_size = EXYNOS_BLOCK_SIZE;
+	sc->sc_bus.dmatag = usbsc->sc_dmat;
+	sc->sc_bus.hci_private = sc;
+	sc->sc_bus.usbrev = USBREV_2_0;
+	sc->sc_ncomp = 0;
+	if (usbsc->sc_ohci_dev != NULL)
+		sc->sc_comps[sc->sc_ncomp++] = usbsc->sc_ohci_dev;
+
+//sc->sc_bus.use_polling=1;
+
+	strlcpy(sc->sc_vendor, "exynos", sizeof(sc->sc_vendor));
+
+	aprint_naive(": EHCI USB controller\n");
+	aprint_normal(": EHCI USB controller\n");
+
+	/* enable things ? extra settings? TBD */
+
+	/* attach */
+	r = ehci_init(sc);
+	if (r != USBD_NORMAL_COMPLETION) {
+		aprint_error_dev(self, "init failed, errpr = %d\n", r);
+		/* disable : TBD */
+		return;
+	}
+	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
+	aprint_normal_dev(sc->sc_dev, "interrupting on irq %d\n", usbsc->sc_irq);
+}
+#endif
+

Reply via email to