ohci_aubus.c revision 1.4 1 /* $NetBSD: ohci_aubus.c,v 1.4 2003/10/18 04:34:30 simonb 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: ohci_aubus.c,v 1.4 2003/10/18 04:34:30 simonb Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45
46 #include <machine/bus.h>
47
48 #include <mips/alchemy/include/aureg.h>
49 #include <mips/alchemy/include/auvar.h>
50 #include <mips/alchemy/include/aubusvar.h>
51
52 #include <evbmips/alchemy/pb1000reg.h>
53 #include <evbmips/alchemy/pb1000_obiovar.h>
54
55 #include <dev/usb/usb.h>
56 #include <dev/usb/usbdi.h>
57 #include <dev/usb/usbdivar.h>
58 #include <dev/usb/usb_mem.h>
59
60 #include <dev/usb/ohcireg.h>
61 #include <dev/usb/ohcivar.h>
62
63
64 static int ohci_aubus_match(struct device *, struct cfdata *, void *);
65 static void ohci_aubus_attach(struct device *, struct device *, void *);
66
67 CFATTACH_DECL(ohci_aubus, sizeof (ohci_softc_t),
68 ohci_aubus_match, ohci_aubus_attach, NULL, NULL);
69
70 struct aubus_ohci_softc {
71 ohci_softc_t sc;
72 void *sc_ih;
73 };
74
75 int
76 ohci_aubus_match(struct device *parent, struct cfdata *match, void *aux)
77 {
78 struct aubus_attach_args *aa = aux;
79
80 if (strcmp(aa->aa_name, match->cf_name) == 0)
81 return (1);
82
83 return (0);
84 }
85
86 void
87 ohci_aubus_attach(struct device *parent, struct device *self, void *aux)
88 {
89 struct aubus_ohci_softc *sc = (struct aubus_ohci_softc *)self;
90 usbd_status r;
91 uint32_t x, tmp;
92 struct aubus_attach_args *aa = aux;
93
94 r = 0;
95
96 sc->sc.sc_size = USBH_SIZE;
97 sc->sc.iot = aa->aa_st;
98 sc->sc.sc_bus.dmatag = (bus_dma_tag_t)aa->aa_dt;
99
100 if (bus_space_map(sc->sc.iot, USBH_BASE, USBH_SIZE, 0, &sc->sc.ioh)) {
101 printf("%s: Unable to map USBH registers\n",
102 sc->sc.sc_bus.bdev.dv_xname);
103 return;
104 }
105 /*
106 * Enable the USB Host controller here.
107 * As per 7.2 in the Au1500 manual:
108 *
109 * (1) Set CE bit to enable clocks.
110 * (2) Set E to enable OHCI
111 * (3) Clear HCFS in OHCI_CONTROL.
112 * (4) Wait for RD bit to be set.
113 */
114 x = bus_space_read_4(sc->sc.iot, sc->sc.ioh, USBH_ENABLE);
115 x |= UE_CE;
116 bus_space_write_4(sc->sc.iot, sc->sc.ioh, USBH_ENABLE, x);
117 delay(10);
118 x |= UE_E;
119 #ifdef __MIPSEB__
120 x |= UE_BE;
121 #endif
122 bus_space_write_4(sc->sc.iot, sc->sc.ioh, USBH_ENABLE, x);
123 delay(10);
124 x = bus_space_read_4(sc->sc.iot, sc->sc.ioh, OHCI_CONTROL);
125 x &= ~(OHCI_HCFS_MASK);
126 bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_CONTROL, x);
127 delay(10);
128 /* Need to read USBH_ENABLE twice in succession according to
129 * au1500 Errata #7.
130 */
131 for (x = 100; x; x--) {
132 bus_space_read_4(sc->sc.iot, sc->sc.ioh, USBH_ENABLE);
133 tmp = bus_space_read_4(sc->sc.iot, sc->sc.ioh, USBH_ENABLE);
134 if (tmp&UE_RD)
135 break;
136 delay(1000);
137 }
138 printf(": Au1X00 OHCI\n");
139
140 /* Disable OHCI interrupts */
141 bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
142 OHCI_ALL_INTRS);
143 /* hook interrupt */
144 sc->sc_ih = au_intr_establish(aa->aa_irq[0], 0, IPL_USB, IST_LEVEL_LOW,
145 ohci_intr, sc);
146 if (sc->sc_ih == NULL) {
147 printf("%s: couldn't establish interrupt\n",
148 sc->sc.sc_bus.bdev.dv_xname);
149 }
150
151 if (x)
152 r = ohci_init(&sc->sc);
153 if (r != USBD_NORMAL_COMPLETION) {
154 printf("%s: init failed, error=%d\n",
155 sc->sc.sc_bus.bdev.dv_xname, r);
156 return;
157 }
158
159 /* Attach USB device */
160 sc->sc.sc_child = config_found((void *)sc, &sc->sc.sc_bus,
161 usbctlprint);
162
163 }
164