rmixl_ehci.c revision 1.3 1 1.3 matt /* $NetBSD: rmixl_ehci.c,v 1.3 2011/04/29 21:54:14 matt Exp $ */
2 1.2 matt
3 1.2 matt /*-
4 1.2 matt * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
5 1.2 matt * All rights reserved.
6 1.2 matt *
7 1.2 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.2 matt * by Herb Peyerl of Middle Digital Inc.
9 1.2 matt *
10 1.2 matt * Redistribution and use in source and binary forms, with or without
11 1.2 matt * modification, are permitted provided that the following conditions
12 1.2 matt * are met:
13 1.2 matt * 1. Redistributions of source code must retain the above copyright
14 1.2 matt * notice, this list of conditions and the following disclaimer.
15 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 matt * notice, this list of conditions and the following disclaimer in the
17 1.2 matt * documentation and/or other materials provided with the distribution.
18 1.2 matt *
19 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.2 matt */
31 1.2 matt
32 1.2 matt #include <sys/cdefs.h>
33 1.3 matt __KERNEL_RCSID(0, "$NetBSD: rmixl_ehci.c,v 1.3 2011/04/29 21:54:14 matt Exp $");
34 1.2 matt
35 1.2 matt #include "locators.h"
36 1.2 matt
37 1.2 matt #include <sys/param.h>
38 1.2 matt #include <sys/systm.h>
39 1.2 matt #include <sys/device.h>
40 1.2 matt
41 1.2 matt #include <machine/bus.h>
42 1.2 matt
43 1.2 matt #include <mips/rmi/rmixlreg.h>
44 1.2 matt #include <mips/rmi/rmixlvar.h>
45 1.2 matt #include <mips/rmi/rmixl_intr.h>
46 1.2 matt #include <mips/rmi/rmixl_usbivar.h>
47 1.2 matt
48 1.2 matt #include <dev/usb/usb.h>
49 1.2 matt #include <dev/usb/usbdi.h>
50 1.2 matt #include <dev/usb/usbdivar.h>
51 1.2 matt #include <dev/usb/usb_mem.h>
52 1.2 matt
53 1.2 matt #include <dev/usb/ehcireg.h>
54 1.2 matt #include <dev/usb/ehcivar.h>
55 1.2 matt
56 1.2 matt
57 1.2 matt static int rmixl_ehci_match(device_t, cfdata_t, void *);
58 1.2 matt static void rmixl_ehci_attach(device_t, device_t, void *);
59 1.2 matt
60 1.2 matt
61 1.2 matt CFATTACH_DECL_NEW(rmixl_ehci, sizeof (ehci_softc_t),
62 1.2 matt rmixl_ehci_match, rmixl_ehci_attach, NULL, NULL);
63 1.2 matt
64 1.2 matt int
65 1.2 matt rmixl_ehci_match(device_t parent, cfdata_t match, void *aux)
66 1.2 matt {
67 1.2 matt struct rmixl_usbi_attach_args *usbi = aux;
68 1.2 matt
69 1.2 matt if (usbi->usbi_addr == (RMIXL_IO_DEV_USB_A + RMIXL_USB_HOST_EHCI_BASE))
70 1.2 matt return rmixl_probe_4((volatile uint32_t *)
71 1.2 matt RMIXL_IOREG_VADDR(usbi->usbi_addr));
72 1.2 matt
73 1.2 matt return 0;
74 1.2 matt }
75 1.2 matt
76 1.2 matt void
77 1.2 matt rmixl_ehci_attach(device_t parent, device_t self, void *aux)
78 1.2 matt {
79 1.3 matt ehci_softc_t * const sc = device_private(self);
80 1.3 matt rmixl_usbi_softc_t * const psc = device_private(parent);
81 1.3 matt struct rmixl_usbi_attach_args * const usbi = aux;
82 1.2 matt void *ih = NULL;
83 1.2 matt uint32_t r;
84 1.2 matt usbd_status status;
85 1.2 matt
86 1.2 matt /* check state of IO_AD9 signal latched in GPIO Reset Config reg */
87 1.2 matt r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
88 1.2 matt if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) {
89 1.2 matt aprint_error_dev(self,
90 1.2 matt "IO_AD9 selects Device mode, abort Host attach\n");
91 1.2 matt return;
92 1.2 matt }
93 1.2 matt
94 1.2 matt sc->sc_dev = self;
95 1.2 matt sc->sc_bus.hci_private = sc;
96 1.2 matt sc->iot = usbi->usbi_el_bst;
97 1.2 matt sc->sc_size = usbi->usbi_size;
98 1.2 matt sc->sc_bus.dmatag = usbi->usbi_dmat;
99 1.2 matt sc->sc_bus.usbrev = USBREV_1_0;
100 1.2 matt
101 1.3 matt /*
102 1.3 matt * Grab the companion OHCI devices from our parent.
103 1.3 matt */
104 1.3 matt if (psc->sc_ohci_devs[1] != NULL) {
105 1.3 matt sc->sc_comps[0] = psc->sc_ohci_devs[0];
106 1.3 matt sc->sc_comps[1] = psc->sc_ohci_devs[1];
107 1.3 matt sc->sc_ncomp = 2;
108 1.3 matt } else {
109 1.3 matt sc->sc_comps[0] = psc->sc_ohci_devs[0];
110 1.3 matt sc->sc_ncomp = 1;
111 1.3 matt }
112 1.3 matt
113 1.2 matt if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) {
114 1.2 matt aprint_error_dev(self, "unable to map registers\n");
115 1.2 matt return;
116 1.2 matt }
117 1.2 matt
118 1.2 matt /* get offset to operational regs */
119 1.2 matt sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
120 1.2 matt
121 1.2 matt /* Disable EHCI interrupts */
122 1.2 matt EOWRITE2(sc, EHCI_USBINTR, 0);
123 1.2 matt
124 1.2 matt /* establish interrupt */
125 1.2 matt if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) {
126 1.2 matt ih = rmixl_usbi_intr_establish(device_private(parent),
127 1.2 matt usbi->usbi_intr, ehci_intr, sc);
128 1.2 matt if (ih == NULL)
129 1.2 matt panic("%s: couldn't establish interrupt",
130 1.2 matt device_xname(self));
131 1.2 matt }
132 1.2 matt
133 1.2 matt status = ehci_init(sc);
134 1.2 matt if (status != USBD_NORMAL_COMPLETION) {
135 1.2 matt aprint_error_dev(self, "init failed, error=%d\n", status);
136 1.2 matt if (ih != NULL)
137 1.2 matt rmixl_intr_disestablish(ih);
138 1.2 matt return;
139 1.2 matt }
140 1.2 matt
141 1.2 matt /* Attach USB device */
142 1.2 matt sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
143 1.2 matt }
144 1.2 matt
145