No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / ep93xx / epohci.c
blobc8667e8bd9c4f0b2ab2b2f408135eb975c7434c5
1 /* $NetBSD: epohci.c,v 1.3 2008/04/03 15:08:58 drochner Exp $ */
3 /*-
4 * Copyright (c) 2004 Jesse Off
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
30 * USB Open Host Controller driver.
32 * OHCI spec: ftp://ftp.compaq.com/pub/supportinformation/papers/hcir1_0a.exe
33 * USB spec: http://www.usb.org/developers/data/usb11.pdf
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: epohci.c,v 1.3 2008/04/03 15:08:58 drochner Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/device.h>
43 #include <sys/proc.h>
44 #include <sys/queue.h>
46 /* busdma */
47 #include <sys/mbuf.h>
48 #include <uvm/uvm_extern.h>
50 #include <machine/bus.h>
52 #include <dev/usb/usb.h>
53 #include <dev/usb/usbdi.h>
54 #include <dev/usb/usbdivar.h>
55 #include <dev/usb/usb_mem.h>
57 #include <dev/usb/ohcireg.h>
58 #include <dev/usb/ohcivar.h>
60 #include <arm/ep93xx/ep93xxreg.h>
61 #include <arm/ep93xx/ep93xxvar.h>
62 #include <arm/ep93xx/epsocvar.h>
64 int epohci_match(struct device *, struct cfdata *, void *);
65 void epohci_attach(struct device *, struct device *, void *);
66 void epohci_callback(struct device *);
68 struct epohci_softc {
69 struct ohci_softc sc;
70 void *sc_ih;
71 int sc_intr;
74 CFATTACH_DECL_NEW(epohci, sizeof(struct epohci_softc),
75 epohci_match, epohci_attach, NULL, NULL);
77 int
78 epohci_match(struct device *parent, struct cfdata *match, void *aux)
80 /* EP93xx builtin OHCI module */
82 return (1);
85 void
86 epohci_attach(struct device *parent, struct device *self, void *aux)
88 struct epohci_softc *sc = device_private(self);
89 struct epsoc_attach_args *sa = aux;
90 u_int32_t i;
91 bus_space_handle_t syscon_ioh;
93 sc->sc.sc_dev = self;
94 sc->sc.sc_bus.hci_private = sc;
96 sc->sc.iot = sa->sa_iot;
97 sc->sc.sc_bus.dmatag = sa->sa_dmat;
98 sc->sc_intr = sa->sa_intr;
100 /* Map I/O space */
101 if (bus_space_map(sc->sc.iot, sa->sa_addr, sa->sa_size,
102 0, &sc->sc.ioh)) {
103 printf(": cannot map mem space\n");
104 return;
107 /* Enable hclk clock gating to the USB block. */
109 bus_space_map(sc->sc.iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
110 EP93XX_APB_SYSCON_SIZE, 0, &syscon_ioh);
111 i = bus_space_read_4(sc->sc.iot, syscon_ioh, EP93XX_SYSCON_PwrCnt);
112 i |= 0x10000000;
113 bus_space_write_4(sc->sc.iot, syscon_ioh, EP93XX_SYSCON_PwrCnt, i);
116 * Not sure if I understand the datasheet here, but we must wait a
117 * few instructions and also make certain PLL2 is stable before
118 * continuing. Hopefully, the check for PLL2 is enough, as the
119 * datasheet is elusive to actually how many insns we need.
122 do {
123 i = bus_space_read_4(sc->sc.iot, syscon_ioh,
124 EP93XX_SYSCON_PwrSts);
125 } while ((i & 0x100) == 0);
126 bus_space_unmap(sc->sc.iot, syscon_ioh, EP93XX_APB_SYSCON_SIZE);
128 printf("\n");
130 /* Defer the rest until later */
131 config_defer(self, epohci_callback);
134 void
135 epohci_callback(struct device *self)
137 struct epohci_softc *sc = device_private(self);
138 usbd_status r;
140 /* Disable interrupts, so we don't get any spurious ones. */
141 bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
142 OHCI_ALL_INTRS);
144 strlcpy(sc->sc.sc_vendor, "Cirrus Logic", sizeof sc->sc.sc_vendor);
146 sc->sc_ih = ep93xx_intr_establish(sc->sc_intr, IPL_USB,
147 ohci_intr, sc);
148 r = ohci_init(&sc->sc);
150 if (r != USBD_NORMAL_COMPLETION) {
151 printf("%s: init failed, error=%d\n", device_xname(self), r);
153 ep93xx_intr_disestablish(sc->sc_ih);
154 return;
157 /* Attach usb device. */
158 sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint);