1 /* $NetBSD: ohci_cardbus.c,v 1.31 2008/07/11 20:57:51 dyoung Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * USB Open Host Controller driver.
36 * OHCI spec: http://www.intel.com/design/usb/ohci11d.pdf
37 * USB spec: http://www.teleport.com/cgi-bin/mailmerge.cgi/~usb/cgiform.tpl
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ohci_cardbus.c,v 1.31 2008/07/11 20:57:51 dyoung Exp $");
43 #include "ehci_cardbus.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/device.h>
54 #include <dev/pci/pcidevs.h>
57 #include <dev/cardbus/cardbusvar.h>
58 #include <dev/pci/pcidevs.h>
60 #include <dev/cardbus/usb_cardbus.h>
62 #include <dev/usb/usb.h>
63 #include <dev/usb/usbdi.h>
64 #include <dev/usb/usbdivar.h>
65 #include <dev/usb/usb_mem.h>
67 #include <dev/usb/ohcireg.h>
68 #include <dev/usb/ohcivar.h>
70 int ohci_cardbus_match(device_t
, cfdata_t
, void *);
71 void ohci_cardbus_attach(device_t
, device_t
, void *);
72 int ohci_cardbus_detach(device_t
, int);
74 struct ohci_cardbus_softc
{
77 struct usb_cardbus sc_cardbus
;
79 cardbus_chipset_tag_t sc_cc
;
80 cardbus_function_tag_t sc_cf
;
81 cardbus_devfunc_t sc_ct
;
82 void *sc_ih
; /* interrupt vectoring */
85 CFATTACH_DECL_NEW(ohci_cardbus
, sizeof(struct ohci_cardbus_softc
),
86 ohci_cardbus_match
, ohci_cardbus_attach
, ohci_cardbus_detach
, ohci_activate
);
88 #define CARDBUS_INTERFACE_OHCI PCI_INTERFACE_OHCI
89 #define CARDBUS_CBMEM PCI_CBMEM
90 #define cardbus_findvendor pci_findvendor
91 #define cardbus_devinfo pci_devinfo
94 ohci_cardbus_match(device_t parent
, cfdata_t match
, void *aux
)
96 struct cardbus_attach_args
*ca
= (struct cardbus_attach_args
*)aux
;
98 if (CARDBUS_CLASS(ca
->ca_class
) == CARDBUS_CLASS_SERIALBUS
&&
99 CARDBUS_SUBCLASS(ca
->ca_class
) == CARDBUS_SUBCLASS_SERIALBUS_USB
&&
100 CARDBUS_INTERFACE(ca
->ca_class
) == CARDBUS_INTERFACE_OHCI
)
107 ohci_cardbus_attach(device_t parent
, device_t self
, void *aux
)
109 struct ohci_cardbus_softc
*sc
= device_private(self
);
110 struct cardbus_attach_args
*ca
= aux
;
111 cardbus_devfunc_t ct
= ca
->ca_ct
;
112 cardbus_chipset_tag_t cc
= ct
->ct_cc
;
113 cardbus_function_tag_t cf
= ct
->ct_cf
;
118 const char *devname
= device_xname(self
);
120 sc
->sc
.sc_dev
= self
;
121 sc
->sc
.sc_bus
.hci_private
= sc
;
123 cardbus_devinfo(ca
->ca_id
, ca
->ca_class
, 0, devinfo
, sizeof(devinfo
));
124 printf(": %s (rev. 0x%02x)\n", devinfo
,
125 CARDBUS_REVISION(ca
->ca_class
));
127 /* Map I/O registers */
128 if (Cardbus_mapreg_map(ct
, CARDBUS_CBMEM
, CARDBUS_MAPREG_TYPE_MEM
, 0,
129 &sc
->sc
.iot
, &sc
->sc
.ioh
, NULL
, &sc
->sc
.sc_size
)) {
130 printf("%s: can't map mem space\n", devname
);
137 sc
->sc
.sc_bus
.dmatag
= ca
->ca_dmat
;
141 XXX (ct
->ct_cf
->cardbus_mem_open
)(cc
, 0, iob
, iob
+ 0x40);
143 (ct
->ct_cf
->cardbus_ctrl
)(cc
, CARDBUS_MEM_ENABLE
);
144 (ct
->ct_cf
->cardbus_ctrl
)(cc
, CARDBUS_BM_ENABLE
);
146 /* Enable the device. */
147 csr
= cardbus_conf_read(cc
, cf
, ca
->ca_tag
,
148 CARDBUS_COMMAND_STATUS_REG
);
149 cardbus_conf_write(cc
, cf
, ca
->ca_tag
, CARDBUS_COMMAND_STATUS_REG
,
150 csr
| CARDBUS_COMMAND_MASTER_ENABLE
151 | CARDBUS_COMMAND_MEM_ENABLE
);
153 /* Disable interrupts, so we don't can any spurious ones. */
154 bus_space_write_4(sc
->sc
.iot
, sc
->sc
.ioh
, OHCI_INTERRUPT_DISABLE
,
157 sc
->sc_ih
= cardbus_intr_establish(cc
, cf
, ca
->ca_intrline
,
158 IPL_USB
, ohci_intr
, sc
);
159 if (sc
->sc_ih
== NULL
) {
160 printf("%s: couldn't establish interrupt\n", devname
);
164 /* Figure out vendor for root hub descriptor. */
165 vendor
= cardbus_findvendor(ca
->ca_id
);
166 sc
->sc
.sc_id_vendor
= CARDBUS_VENDOR(ca
->ca_id
);
168 strlcpy(sc
->sc
.sc_vendor
, vendor
, sizeof(sc
->sc
.sc_vendor
));
170 snprintf(sc
->sc
.sc_vendor
, sizeof(sc
->sc
.sc_vendor
),
171 "vendor 0x%04x", CARDBUS_VENDOR(ca
->ca_id
));
173 r
= ohci_init(&sc
->sc
);
174 if (r
!= USBD_NORMAL_COMPLETION
) {
175 printf("%s: init failed, error=%d\n", devname
, r
);
177 /* Avoid spurious interrupts. */
178 cardbus_intr_disestablish(sc
->sc_cc
, sc
->sc_cf
, sc
->sc_ih
);
184 #if NEHCI_CARDBUS > 0
185 usb_cardbus_add(&sc
->sc_cardbus
, ca
, self
);
188 if (!pmf_device_register1(self
, ohci_suspend
, ohci_resume
,
190 aprint_error_dev(self
, "couldn't establish power handler\n");
192 /* Attach usb device. */
193 sc
->sc
.sc_child
= config_found(self
, &sc
->sc
.sc_bus
, usbctlprint
);
197 ohci_cardbus_detach(device_t self
, int flags
)
199 struct ohci_cardbus_softc
*sc
= device_private(self
);
200 struct cardbus_devfunc
*ct
= sc
->sc_ct
;
203 rv
= ohci_detach(&sc
->sc
, flags
);
206 if (sc
->sc_ih
!= NULL
) {
207 cardbus_intr_disestablish(sc
->sc_cc
, sc
->sc_cf
, sc
->sc_ih
);
210 if (sc
->sc
.sc_size
) {
211 Cardbus_mapreg_unmap(ct
, CARDBUS_CBMEM
, sc
->sc
.iot
,
212 sc
->sc
.ioh
, sc
->sc
.sc_size
);
215 #if NEHCI_CARDBUS > 0
216 usb_cardbus_rem(&sc
->sc_cardbus
);