1 /* $NetBSD: ohci_aubus.c,v 1.13 2008/04/03 15:12:43 drochner Exp $ */
4 * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Herb Peyerl of Middle Digital Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: ohci_aubus.c,v 1.13 2008/04/03 15:12:43 drochner Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <machine/bus.h>
41 #include <mips/alchemy/include/aureg.h>
42 #include <mips/alchemy/include/auvar.h>
43 #include <mips/alchemy/include/aubusvar.h>
44 #include <mips/alchemy/dev/ohcireg.h>
46 #include <dev/usb/usb.h>
47 #include <dev/usb/usbdi.h>
48 #include <dev/usb/usbdivar.h>
49 #include <dev/usb/usb_mem.h>
51 #include <dev/usb/ohcireg.h>
52 #include <dev/usb/ohcivar.h>
55 static int ohci_aubus_match(device_t
, cfdata_t
, void *);
56 static void ohci_aubus_attach(device_t
, device_t
, void *);
58 CFATTACH_DECL_NEW(ohci_aubus
, sizeof (ohci_softc_t
),
59 ohci_aubus_match
, ohci_aubus_attach
, NULL
, NULL
);
62 ohci_aubus_match(device_t parent
, cfdata_t match
, void *aux
)
64 struct aubus_attach_args
*aa
= aux
;
66 if (strcmp(aa
->aa_name
, match
->cf_name
) == 0)
73 ohci_aubus_attach(device_t parent
, device_t self
, void *aux
)
75 ohci_softc_t
*sc
= device_private(self
);
79 bus_addr_t usbh_base
, usbh_enable
;
80 struct aubus_attach_args
*aa
= aux
;
84 usbh_base
= aa
->aa_addrs
[0];
85 usbh_enable
= aa
->aa_addrs
[1];
86 sc
->sc_size
= aa
->aa_addrs
[2];
88 sc
->sc_bus
.dmatag
= (bus_dma_tag_t
)aa
->aa_dt
;
91 sc
->sc_bus
.hci_private
= sc
;
93 if (bus_space_map(sc
->iot
, usbh_base
, sc
->sc_size
, 0, &sc
->ioh
)) {
94 aprint_error_dev(self
, "unable to map USBH registers\n");
98 * Enable the USB Host controller here.
99 * As per 7.2 in the Au1500 manual:
101 * (1) Set CE bit to enable clocks.
102 * (2) Set E to enable OHCI
103 * (3) Clear HCFS in OHCI_CONTROL.
104 * (4) Wait for RD bit to be set.
106 x
= bus_space_read_4(sc
->iot
, sc
->ioh
, usbh_enable
);
108 bus_space_write_4(sc
->iot
, sc
->ioh
, usbh_enable
, x
);
114 bus_space_write_4(sc
->iot
, sc
->ioh
, usbh_enable
, x
);
116 x
= bus_space_read_4(sc
->iot
, sc
->ioh
, OHCI_CONTROL
);
117 x
&= ~(OHCI_HCFS_MASK
);
118 bus_space_write_4(sc
->iot
, sc
->ioh
, OHCI_CONTROL
, x
);
120 /* Need to read USBH_ENABLE twice in succession according to
123 for (x
= 100; x
; x
--) {
124 bus_space_read_4(sc
->iot
, sc
->ioh
, usbh_enable
);
125 tmp
= bus_space_read_4(sc
->iot
, sc
->ioh
, usbh_enable
);
130 printf(": Alchemy OHCI\n");
132 /* Disable OHCI interrupts */
133 bus_space_write_4(sc
->iot
, sc
->ioh
, OHCI_INTERRUPT_DISABLE
,
136 ih
= au_intr_establish(aa
->aa_irq
[0], 0, IPL_USB
, IST_LEVEL_LOW
,
139 aprint_error_dev(self
,"couldn't establish interrupt\n");
142 sc
->sc_endian
= OHCI_HOST_ENDIAN
;
146 if (r
!= USBD_NORMAL_COMPLETION
) {
147 aprint_error_dev(self
, "init failed, error=%d\n", r
);
148 au_intr_disestablish(ih
);
152 /* Attach USB device */
153 sc
->sc_child
= config_found(self
, &sc
->sc_bus
, usbctlprint
);