ohci_aubus.c revision 1.16 1 1.16 skrll /* $NetBSD: ohci_aubus.c,v 1.16 2016/04/23 10:15:29 skrll Exp $ */
2 1.1 hpeyerl
3 1.1 hpeyerl /*-
4 1.1 hpeyerl * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
5 1.1 hpeyerl * All rights reserved.
6 1.1 hpeyerl *
7 1.1 hpeyerl * This code is derived from software contributed to The NetBSD Foundation
8 1.1 hpeyerl * by Herb Peyerl of Middle Digital Inc.
9 1.1 hpeyerl *
10 1.1 hpeyerl * Redistribution and use in source and binary forms, with or without
11 1.1 hpeyerl * modification, are permitted provided that the following conditions
12 1.1 hpeyerl * are met:
13 1.1 hpeyerl * 1. Redistributions of source code must retain the above copyright
14 1.1 hpeyerl * notice, this list of conditions and the following disclaimer.
15 1.1 hpeyerl * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 hpeyerl * notice, this list of conditions and the following disclaimer in the
17 1.1 hpeyerl * documentation and/or other materials provided with the distribution.
18 1.1 hpeyerl *
19 1.1 hpeyerl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 hpeyerl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 hpeyerl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 hpeyerl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 hpeyerl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 hpeyerl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 hpeyerl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 hpeyerl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 hpeyerl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 hpeyerl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 hpeyerl * POSSIBILITY OF SUCH DAMAGE.
30 1.1 hpeyerl */
31 1.3 lukem
32 1.3 lukem #include <sys/cdefs.h>
33 1.16 skrll __KERNEL_RCSID(0, "$NetBSD: ohci_aubus.c,v 1.16 2016/04/23 10:15:29 skrll Exp $");
34 1.1 hpeyerl
35 1.1 hpeyerl #include <sys/param.h>
36 1.1 hpeyerl #include <sys/systm.h>
37 1.1 hpeyerl #include <sys/device.h>
38 1.1 hpeyerl
39 1.15 dyoung #include <sys/bus.h>
40 1.1 hpeyerl
41 1.1 hpeyerl #include <mips/alchemy/include/aureg.h>
42 1.1 hpeyerl #include <mips/alchemy/include/auvar.h>
43 1.1 hpeyerl #include <mips/alchemy/include/aubusvar.h>
44 1.10 gdamore #include <mips/alchemy/dev/ohcireg.h>
45 1.1 hpeyerl
46 1.16 skrll #include <dev/usb/usb.h>
47 1.1 hpeyerl #include <dev/usb/usbdi.h>
48 1.1 hpeyerl #include <dev/usb/usbdivar.h>
49 1.1 hpeyerl #include <dev/usb/usb_mem.h>
50 1.1 hpeyerl
51 1.1 hpeyerl #include <dev/usb/ohcireg.h>
52 1.1 hpeyerl #include <dev/usb/ohcivar.h>
53 1.1 hpeyerl
54 1.1 hpeyerl
55 1.12 dogcow static int ohci_aubus_match(device_t, cfdata_t, void *);
56 1.12 dogcow static void ohci_aubus_attach(device_t, device_t, void *);
57 1.1 hpeyerl
58 1.12 dogcow CFATTACH_DECL_NEW(ohci_aubus, sizeof (ohci_softc_t),
59 1.1 hpeyerl ohci_aubus_match, ohci_aubus_attach, NULL, NULL);
60 1.1 hpeyerl
61 1.1 hpeyerl int
62 1.12 dogcow ohci_aubus_match(device_t parent, cfdata_t match, void *aux)
63 1.1 hpeyerl {
64 1.1 hpeyerl struct aubus_attach_args *aa = aux;
65 1.1 hpeyerl
66 1.1 hpeyerl if (strcmp(aa->aa_name, match->cf_name) == 0)
67 1.16 skrll return 1;
68 1.1 hpeyerl
69 1.16 skrll return 0;
70 1.1 hpeyerl }
71 1.1 hpeyerl
72 1.1 hpeyerl void
73 1.12 dogcow ohci_aubus_attach(device_t parent, device_t self, void *aux)
74 1.1 hpeyerl {
75 1.12 dogcow ohci_softc_t *sc = device_private(self);
76 1.5 simonb void *ih;
77 1.1 hpeyerl uint32_t x, tmp;
78 1.8 tron bus_addr_t usbh_base, usbh_enable;
79 1.1 hpeyerl struct aubus_attach_args *aa = aux;
80 1.1 hpeyerl
81 1.8 tron usbh_base = aa->aa_addrs[0];
82 1.8 tron usbh_enable = aa->aa_addrs[1];
83 1.8 tron sc->sc_size = aa->aa_addrs[2];
84 1.5 simonb sc->iot = aa->aa_st;
85 1.16 skrll sc->sc_bus.ub_dmatag = (bus_dma_tag_t)aa->aa_dt;
86 1.1 hpeyerl
87 1.13 drochner sc->sc_dev = self;
88 1.16 skrll sc->sc_bus.ub_hcpriv = sc;
89 1.13 drochner
90 1.8 tron if (bus_space_map(sc->iot, usbh_base, sc->sc_size, 0, &sc->ioh)) {
91 1.11 dogcow aprint_error_dev(self, "unable to map USBH registers\n");
92 1.1 hpeyerl return;
93 1.1 hpeyerl }
94 1.1 hpeyerl /*
95 1.1 hpeyerl * Enable the USB Host controller here.
96 1.1 hpeyerl * As per 7.2 in the Au1500 manual:
97 1.1 hpeyerl *
98 1.1 hpeyerl * (1) Set CE bit to enable clocks.
99 1.1 hpeyerl * (2) Set E to enable OHCI
100 1.1 hpeyerl * (3) Clear HCFS in OHCI_CONTROL.
101 1.1 hpeyerl * (4) Wait for RD bit to be set.
102 1.1 hpeyerl */
103 1.8 tron x = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
104 1.1 hpeyerl x |= UE_CE;
105 1.8 tron bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
106 1.1 hpeyerl delay(10);
107 1.4 simonb x |= UE_E;
108 1.4 simonb #ifdef __MIPSEB__
109 1.4 simonb x |= UE_BE;
110 1.4 simonb #endif
111 1.8 tron bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
112 1.1 hpeyerl delay(10);
113 1.5 simonb x = bus_space_read_4(sc->iot, sc->ioh, OHCI_CONTROL);
114 1.1 hpeyerl x &= ~(OHCI_HCFS_MASK);
115 1.5 simonb bus_space_write_4(sc->iot, sc->ioh, OHCI_CONTROL, x);
116 1.1 hpeyerl delay(10);
117 1.2 hpeyerl /* Need to read USBH_ENABLE twice in succession according to
118 1.2 hpeyerl * au1500 Errata #7.
119 1.2 hpeyerl */
120 1.1 hpeyerl for (x = 100; x; x--) {
121 1.8 tron bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
122 1.8 tron tmp = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
123 1.1 hpeyerl if (tmp&UE_RD)
124 1.1 hpeyerl break;
125 1.1 hpeyerl delay(1000);
126 1.1 hpeyerl }
127 1.16 skrll
128 1.16 skrll if (x == 0) {
129 1.16 skrll aprint_error_dev(self, "device not ready\n");
130 1.16 skrll return;
131 1.16 skrll }
132 1.16 skrll
133 1.8 tron printf(": Alchemy OHCI\n");
134 1.1 hpeyerl
135 1.1 hpeyerl /* Disable OHCI interrupts */
136 1.5 simonb bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
137 1.1 hpeyerl OHCI_ALL_INTRS);
138 1.1 hpeyerl /* hook interrupt */
139 1.5 simonb ih = au_intr_establish(aa->aa_irq[0], 0, IPL_USB, IST_LEVEL_LOW,
140 1.1 hpeyerl ohci_intr, sc);
141 1.5 simonb if (ih == NULL) {
142 1.11 dogcow aprint_error_dev(self,"couldn't establish interrupt\n");
143 1.1 hpeyerl }
144 1.1 hpeyerl
145 1.7 tron sc->sc_endian = OHCI_HOST_ENDIAN;
146 1.7 tron
147 1.16 skrll int err = ohci_init(sc);
148 1.16 skrll if (err != USBD_NORMAL_COMPLETION) {
149 1.16 skrll aprint_error_dev(self, "init failed, error=%d\n", err);
150 1.5 simonb au_intr_disestablish(ih);
151 1.1 hpeyerl return;
152 1.1 hpeyerl }
153 1.1 hpeyerl
154 1.1 hpeyerl /* Attach USB device */
155 1.13 drochner sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
156 1.1 hpeyerl
157 1.1 hpeyerl }
158