xref: /netbsd-src/sys/arch/mips/atheros/dev/ohci_arbus.c (revision 567219e1d7461bff1b180e494a9674a287b057a7)
1 /*	$NetBSD: ohci_arbus.c,v 1.1 2011/07/07 05:06:44 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Herb Peyerl of Middle Digital Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "locators.h"
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ohci_arbus.c,v 1.1 2011/07/07 05:06:44 matt Exp $");
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 
41 #include <sys/bus.h>
42 
43 #include <dev/usb/usb.h>
44 #include <dev/usb/usbdi.h>
45 #include <dev/usb/usbdivar.h>
46 #include <dev/usb/usb_mem.h>
47 
48 #include <dev/usb/ohcireg.h>
49 #include <dev/usb/ohcivar.h>
50 
51 #include <mips/atheros/include/arbusvar.h>
52 
53 static int	ohci_arbus_match(device_t, cfdata_t, void *);
54 static void	ohci_arbus_attach(device_t, device_t, void *);
55 
56 CFATTACH_DECL_NEW(ohci_arbus, sizeof (ohci_softc_t),
57     ohci_arbus_match, ohci_arbus_attach, NULL, NULL);
58 
59 int
60 ohci_arbus_match(device_t parent, cfdata_t cf, void *aux)
61 {
62 	struct arbus_attach_args *aa = aux;
63 	bus_space_handle_t bsh;
64 
65 	if (strcmp(aa->aa_name, cf->cf_name))
66 		return 0;
67 
68 	if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, &bsh) != 0)
69 		return 0;
70 
71 	return 0; /* XXX */
72 
73 	if (badaddr((void *)bsh, 4) == -1) {
74 		bus_space_unmap(aa->aa_bst, bsh, aa->aa_size);
75 		return 0;
76 	}
77 
78 	bus_space_unmap(aa->aa_bst, bsh, aa->aa_size);
79 	return 1;
80 }
81 
82 void
83 ohci_arbus_attach(device_t parent, device_t self, void *aux)
84 {
85 	ohci_softc_t * const sc = device_private(self);
86 	struct arbus_attach_args * const aa = aux;
87 	void *ih = NULL;
88 	usbd_status status;
89 
90 	sc->sc_dev = self;
91 	sc->iot = aa->aa_bst;
92 	sc->sc_size = aa->aa_size;
93 	sc->sc_bus.dmatag = aa->aa_dmat;
94 	sc->sc_bus.hci_private = sc;
95 
96 	if (bus_space_map(sc->iot, aa->aa_addr, sc->sc_size, 0, &sc->ioh)) {
97 		aprint_error_dev(self, "unable to map registers\n");
98 		return;
99 	}
100 
101 	/* Disable OHCI interrupts */
102 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
103 	    OHCI_ALL_INTRS);
104 
105 	/* establish interrupt */
106 	ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ohci_intr, sc);
107 	if (ih == NULL)
108 		panic("%s: couldn't establish interrupt", device_xname(self));
109 
110 	/* we don't handle endianess in bus space */
111 	sc->sc_endian = OHCI_LITTLE_ENDIAN;
112 
113 	status = ohci_init(sc);
114 	if (status != USBD_NORMAL_COMPLETION) {
115 		aprint_error_dev(self, "init failed, error=%d\n", status);
116 		if (ih != NULL)
117 			arbus_intr_disestablish(ih);
118 		return;
119 	}
120 
121 #if 0
122 	if (psc->sc_ohci_devs[0] == NULL) {
123 		psc->sc_ohci_devs[0] = self;
124 	} else if (psc->sc_ohci_devs[1] == NULL) {
125 		psc->sc_ohci_devs[1] = self;
126 	} else {
127 		panic("%s: too many ohci devices", __func__);
128 	}
129 #endif
130 
131 	/* Attach USB device */
132 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
133 }
134