rmixl_ehci.c revision 1.2 1 /* $NetBSD: rmixl_ehci.c,v 1.2 2011/02/20 07:48:37 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 <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: rmixl_ehci.c,v 1.2 2011/02/20 07:48:37 matt Exp $");
34
35 #include "locators.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40
41 #include <machine/bus.h>
42
43 #include <mips/rmi/rmixlreg.h>
44 #include <mips/rmi/rmixlvar.h>
45 #include <mips/rmi/rmixl_intr.h>
46 #include <mips/rmi/rmixl_usbivar.h>
47
48 #include <dev/usb/usb.h>
49 #include <dev/usb/usbdi.h>
50 #include <dev/usb/usbdivar.h>
51 #include <dev/usb/usb_mem.h>
52
53 #include <dev/usb/ehcireg.h>
54 #include <dev/usb/ehcivar.h>
55
56
57 static int rmixl_ehci_match(device_t, cfdata_t, void *);
58 static void rmixl_ehci_attach(device_t, device_t, void *);
59
60
61 CFATTACH_DECL_NEW(rmixl_ehci, sizeof (ehci_softc_t),
62 rmixl_ehci_match, rmixl_ehci_attach, NULL, NULL);
63
64 int
65 rmixl_ehci_match(device_t parent, cfdata_t match, void *aux)
66 {
67 struct rmixl_usbi_attach_args *usbi = aux;
68
69 if (usbi->usbi_addr == (RMIXL_IO_DEV_USB_A + RMIXL_USB_HOST_EHCI_BASE))
70 return rmixl_probe_4((volatile uint32_t *)
71 RMIXL_IOREG_VADDR(usbi->usbi_addr));
72
73 return 0;
74 }
75
76 void
77 rmixl_ehci_attach(device_t parent, device_t self, void *aux)
78 {
79 ehci_softc_t *sc = device_private(self);
80 struct rmixl_usbi_attach_args *usbi = aux;
81 void *ih = NULL;
82 uint32_t r;
83 usbd_status status;
84
85 /* check state of IO_AD9 signal latched in GPIO Reset Config reg */
86 r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
87 if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) {
88 aprint_error_dev(self,
89 "IO_AD9 selects Device mode, abort Host attach\n");
90 return;
91 }
92
93 sc->sc_dev = self;
94 sc->sc_bus.hci_private = sc;
95 sc->iot = usbi->usbi_el_bst;
96 sc->sc_size = usbi->usbi_size;
97 sc->sc_bus.dmatag = usbi->usbi_dmat;
98 sc->sc_bus.usbrev = USBREV_1_0;
99
100 if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) {
101 aprint_error_dev(self, "unable to map registers\n");
102 return;
103 }
104
105 /* get offset to operational regs */
106 sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
107
108 /* Disable EHCI interrupts */
109 EOWRITE2(sc, EHCI_USBINTR, 0);
110
111 /* establish interrupt */
112 if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) {
113 ih = rmixl_usbi_intr_establish(device_private(parent),
114 usbi->usbi_intr, ehci_intr, sc);
115 if (ih == NULL)
116 panic("%s: couldn't establish interrupt",
117 device_xname(self));
118 }
119
120 status = ehci_init(sc);
121 if (status != USBD_NORMAL_COMPLETION) {
122 aprint_error_dev(self, "init failed, error=%d\n", status);
123 if (ih != NULL)
124 rmixl_intr_disestablish(ih);
125 return;
126 }
127
128 /* Attach USB device */
129 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
130 }
131
132