Module Name:    src
Committed By:   macallan
Date:           Tue Mar 17 07:25:08 UTC 2015

Modified Files:
        src/sys/arch/mips/ingenic: apbus.c ingenic_dwctwo.c ingenic_ehci.c
            ingenic_ohci.c ingenic_var.h

Log Message:
- keep a list of devices, addresses and interrupts in apbus.c
- pass irq numbers to devices
- reduce magic numbers in device drivers
- allow multiple instances of device drivers


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/mips/ingenic/apbus.c \
    src/sys/arch/mips/ingenic/ingenic_dwctwo.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/mips/ingenic/ingenic_ehci.c \
    src/sys/arch/mips/ingenic/ingenic_ohci.c \
    src/sys/arch/mips/ingenic/ingenic_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/mips/ingenic/apbus.c
diff -u src/sys/arch/mips/ingenic/apbus.c:1.7 src/sys/arch/mips/ingenic/apbus.c:1.8
--- src/sys/arch/mips/ingenic/apbus.c:1.7	Mon Mar  9 13:24:21 2015
+++ src/sys/arch/mips/ingenic/apbus.c	Tue Mar 17 07:25:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: apbus.c,v 1.7 2015/03/09 13:24:21 macallan Exp $ */
+/*	$NetBSD: apbus.c,v 1.8 2015/03/17 07:25:07 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014 Michael Lorenz
@@ -29,7 +29,7 @@
 /* catch-all for on-chip peripherals */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apbus.c,v 1.7 2015/03/09 13:24:21 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apbus.c,v 1.8 2015/03/17 07:25:07 macallan Exp $");
 
 #include "locators.h"
 #define	_MIPS_BUS_DMA_PRIVATE
@@ -62,14 +62,30 @@ struct mips_bus_dma_tag	apbus_dmat = {
 	._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
 };
 
-static const char *apbus_devs[] = {
-	"dwctwo",
-	"ohci",
-	"ehci",
-	"dme",
-	"jzgpio",
-	"jzfb",
-	NULL
+typedef struct apbus_dev {
+	const char *name;
+	bus_addr_t addr;
+	uint32_t irq;
+} apbus_dev_t;
+
+static const apbus_dev_t apbus_devs[] = {
+	{ "dwctwo",	JZ_DWC2_BASE,   21},
+	{ "ohci",	JZ_OHCI_BASE,    5 },
+	{ "ehci",	JZ_EHCI_BASE,   20},
+	{ "dme",	JZ_DME_BASE,    -1},	/* irq via gpio abuse */
+	{ "jzgpio",	JZ_GPIO_A_BASE, 17},
+	{ "jzgpio",	JZ_GPIO_B_BASE, 16},
+	{ "jzgpio",	JZ_GPIO_C_BASE, 15},
+	{ "jzgpio",	JZ_GPIO_D_BASE, 14},
+	{ "jzgpio",	JZ_GPIO_E_BASE, 13},
+	{ "jzgpio",	JZ_GPIO_F_BASE, 12},
+	{ "jziic",	JZ_SMB0_BASE,   60},
+	{ "jziic",	JZ_SMB1_BASE,   59},
+	{ "jziic",	JZ_SMB2_BASE,   58},
+	{ "jziic",	JZ_SMB3_BASE,   57},
+	{ "jziic",	JZ_SMB4_BASE,   56},
+	{ "jzfb",	-1,           -1},
+	{ NULL,		-1,           -1}
 };
 
 void
@@ -135,10 +151,11 @@ apbus_attach(device_t parent, device_t s
 	printf("JZ_UHCCDR %08x\n", readreg(JZ_UHCCDR));
 #endif
 
-	for (const char **adv = apbus_devs; *adv != NULL; adv++) {
+	for (const apbus_dev_t *adv = apbus_devs; adv->name != NULL; adv++) {
 		struct apbus_attach_args aa;
-		aa.aa_name = *adv;
-		aa.aa_addr = 0;
+		aa.aa_name = adv->name;
+		aa.aa_addr = adv->addr;
+		aa.aa_irq  = adv->irq;
 		aa.aa_dmat = &apbus_dmat;
 		aa.aa_bst = apbus_memt;
 
@@ -151,12 +168,13 @@ apbus_print(void *aux, const char *pnp)
 {
 	struct apbus_attach_args *aa = aux;
 
-	if (pnp)
+	if (pnp) {
 		aprint_normal("%s at %s", aa->aa_name, pnp);
-
-	if (aa->aa_addr)
-		aprint_normal(" addr 0x%" PRIxBUSADDR, aa->aa_addr);
-
+		if (aa->aa_addr != -1)
+			aprint_normal(" addr 0x%" PRIxBUSADDR, aa->aa_addr);
+		if (aa->aa_irq != -1)
+			aprint_normal(" irq %d", aa->aa_irq);
+	}
 	return (UNCONF);
 }
 
Index: src/sys/arch/mips/ingenic/ingenic_dwctwo.c
diff -u src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.7 src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.8
--- src/sys/arch/mips/ingenic/ingenic_dwctwo.c:1.7	Tue Mar 10 18:03:17 2015
+++ src/sys/arch/mips/ingenic/ingenic_dwctwo.c	Tue Mar 17 07:25:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ingenic_dwctwo.c,v 1.7 2015/03/10 18:03:17 macallan Exp $ */
+/*	$NetBSD: ingenic_dwctwo.c,v 1.8 2015/03/17 07:25:07 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ingenic_dwctwo.c,v 1.7 2015/03/10 18:03:17 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ingenic_dwctwo.c,v 1.8 2015/03/17 07:25:07 macallan Exp $");
 
 /*
  * adapted from bcm2835_dwctwo.c
@@ -176,11 +176,11 @@ ingenic_dwc2_attach(device_t parent, dev
 
 	delay(10000);
 
-	sc->sc_ih = evbmips_intr_establish(21, dwc2_intr, &sc->sc_dwc2);
+	sc->sc_ih = evbmips_intr_establish(aa->aa_irq, dwc2_intr, &sc->sc_dwc2);
 
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(self, "failed to establish interrupt %d\n",
-		     21);
+		     aa->aa_irq);
 		goto fail;
 	}
 

Index: src/sys/arch/mips/ingenic/ingenic_ehci.c
diff -u src/sys/arch/mips/ingenic/ingenic_ehci.c:1.1 src/sys/arch/mips/ingenic/ingenic_ehci.c:1.2
--- src/sys/arch/mips/ingenic/ingenic_ehci.c:1.1	Sun Mar  8 17:14:27 2015
+++ src/sys/arch/mips/ingenic/ingenic_ehci.c	Tue Mar 17 07:25:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ingenic_ehci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $ */
+/*	$NetBSD: ingenic_ehci.c,v 1.2 2015/03/17 07:25:07 macallan Exp $ */
 
 /*-
  * Copyright (c) 2015 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ingenic_ehci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ingenic_ehci.c,v 1.2 2015/03/17 07:25:07 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -114,11 +114,11 @@ ingenic_ehci_attach(device_t parent, dev
 	/* Disable EHCI interrupts */
 	bus_space_write_4(sc->iot, sc->ioh, EHCI_USBINTR, 0);
 
-	ih = evbmips_intr_establish(20, ehci_intr, sc);
+	ih = evbmips_intr_establish(aa->aa_irq, ehci_intr, sc);
 		
 	if (ih == NULL) {
 		aprint_error_dev(self, "failed to establish interrupt %d\n",
-		     20);
+		     aa->aa_irq);
 		goto fail;
 	}
 
Index: src/sys/arch/mips/ingenic/ingenic_ohci.c
diff -u src/sys/arch/mips/ingenic/ingenic_ohci.c:1.1 src/sys/arch/mips/ingenic/ingenic_ohci.c:1.2
--- src/sys/arch/mips/ingenic/ingenic_ohci.c:1.1	Sun Mar  8 17:14:27 2015
+++ src/sys/arch/mips/ingenic/ingenic_ohci.c	Tue Mar 17 07:25:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ingenic_ohci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $ */
+/*	$NetBSD: ingenic_ohci.c,v 1.2 2015/03/17 07:25:07 macallan Exp $ */
 
 /*-
  * Copyright (c) 2015 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ingenic_ohci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ingenic_ohci.c,v 1.2 2015/03/17 07:25:07 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -102,11 +102,11 @@ ingenic_ohci_attach(device_t parent, dev
 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
 	    OHCI_ALL_INTRS);
 
-	ih = evbmips_intr_establish(5, ohci_intr, sc);
+	ih = evbmips_intr_establish(aa->aa_irq, ohci_intr, sc);
 
 	if (ih == NULL) {
 		aprint_error_dev(self, "failed to establish interrupt %d\n",
-		     5);
+		     aa->aa_irq);
 		goto fail;
 	}
 
Index: src/sys/arch/mips/ingenic/ingenic_var.h
diff -u src/sys/arch/mips/ingenic/ingenic_var.h:1.1 src/sys/arch/mips/ingenic/ingenic_var.h:1.2
--- src/sys/arch/mips/ingenic/ingenic_var.h:1.1	Sat Dec  6 14:34:56 2014
+++ src/sys/arch/mips/ingenic/ingenic_var.h	Tue Mar 17 07:25:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ingenic_var.h,v 1.1 2014/12/06 14:34:56 macallan Exp $ */
+/*	$NetBSD: ingenic_var.h,v 1.2 2015/03/17 07:25:07 macallan Exp $ */
 
 /*-
  * Copyright (c) 2014 Michael Lorenz
@@ -36,6 +36,7 @@ struct apbus_attach_args {
 	bus_space_tag_t	aa_bst;
 	bus_dma_tag_t	aa_dmat;
 	bus_addr_t	aa_addr;
+	uint32_t	aa_irq;
 };
 
 extern bus_space_tag_t ingenic_memt;

Reply via email to