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