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