1 /* $NetBSD: gcscehci.c,v 1.5 2009/05/04 12:15:51 cegger Exp $ */
4 * Copyright (c) 2001, 2002, 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net)
9 * and Jared D. McNeill (jmcneill@invisible.ca)
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: gcscehci.c,v 1.5 2009/05/04 12:15:51 cegger Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/device.h>
41 #include <sys/queue.h>
43 #include <machine/bus.h>
44 #include <machine/cpufunc.h>
46 #include <dev/pci/pcidevs.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/usb_pci.h>
50 #include <dev/usb/usb.h>
51 #include <dev/usb/usbdi.h>
52 #include <dev/usb/usbdivar.h>
53 #include <dev/usb/usb_mem.h>
55 #include <dev/usb/ehcireg.h>
56 #include <dev/usb/ehcivar.h>
59 #define DPRINTF(x) if (ehcidebug) printf x
65 #define GCSCUSB_MSR_BASE 0x51200000
66 #define GCSCUSB_MSR_EHCB (GCSCUSB_MSR_BASE + 0x09)
68 struct gcscehci_softc
{
70 pci_chipset_tag_t sc_pc
;
72 void *sc_ih
; /* interrupt vectoring */
76 gcscehci_match(device_t parent
, cfdata_t match
, void *aux
)
78 struct pci_attach_args
*pa
= (struct pci_attach_args
*) aux
;
80 if (PCI_CLASS(pa
->pa_class
) == PCI_CLASS_SERIALBUS
&&
81 PCI_SUBCLASS(pa
->pa_class
) == PCI_SUBCLASS_SERIALBUS_USB
&&
82 PCI_INTERFACE(pa
->pa_class
) == PCI_INTERFACE_EHCI
&&
83 PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_AMD
&&
84 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_AMD_CS5536_EHCI
)
85 return (10); /* beat ehci_pci */
91 gcscehci_attach(device_t parent
, device_t self
, void *aux
)
93 struct gcscehci_softc
*sc
= device_private(self
);
94 struct pci_attach_args
*pa
= (struct pci_attach_args
*)aux
;
95 pci_chipset_tag_t pc
= pa
->pa_pc
;
96 pcitag_t tag
= pa
->pa_tag
;
100 const char *devname
= device_xname(self
);
107 sc
->sc
.sc_dev
= self
;
108 sc
->sc
.sc_bus
.hci_private
= sc
;
110 aprint_naive(": USB controller\n");
112 pci_devinfo(pa
->pa_id
, pa
->pa_class
, 0, devinfo
, sizeof(devinfo
));
113 aprint_normal(": %s (rev. 0x%02x)\n", devinfo
,
114 PCI_REVISION(pa
->pa_class
));
116 /* Map I/O registers */
117 ehcibase
= rdmsr(GCSCUSB_MSR_EHCB
) & 0xffffff00;
118 sc
->sc
.iot
= pa
->pa_memt
;
119 sc
->sc
.sc_size
= 256;
120 if (bus_space_map(sc
->sc
.iot
, ehcibase
, 256, 0, &sc
->sc
.ioh
)) {
121 aprint_error("%s: can't map memory space\n", devname
);
127 sc
->sc
.sc_bus
.dmatag
= pa
->pa_dmat
;
129 /* Disable interrupts, so we don't get any spurious ones. */
130 sc
->sc
.sc_offs
= EREAD1(&sc
->sc
, EHCI_CAPLENGTH
);
131 DPRINTF(("%s: offs=%d\n", devname
, sc
->sc
.sc_offs
));
132 EOWRITE2(&sc
->sc
, EHCI_USBINTR
, 0);
134 /* Map and establish the interrupt. */
135 if (pci_intr_map(pa
, &ih
)) {
136 aprint_error("%s: couldn't map interrupt\n", devname
);
139 intrstr
= pci_intr_string(pc
, ih
);
140 sc
->sc_ih
= pci_intr_establish(pc
, ih
, IPL_USB
, ehci_intr
, sc
);
141 if (sc
->sc_ih
== NULL
) {
142 aprint_error("%s: couldn't establish interrupt", devname
);
144 aprint_error(" at %s", intrstr
);
148 aprint_normal("%s: interrupting at %s\n", devname
, intrstr
);
150 sc
->sc
.sc_bus
.usbrev
= USBREV_2_0
;
152 /* Figure out vendor for root hub descriptor. */
153 vendor
= pci_findvendor(pa
->pa_id
);
154 sc
->sc
.sc_id_vendor
= PCI_VENDOR(pa
->pa_id
);
156 strlcpy(sc
->sc
.sc_vendor
, vendor
, sizeof(sc
->sc
.sc_vendor
));
158 snprintf(sc
->sc
.sc_vendor
, sizeof(sc
->sc
.sc_vendor
),
159 "vendor 0x%04x", PCI_VENDOR(pa
->pa_id
));
162 * Find companion controllers. According to the spec they always
163 * have lower function numbers so they should be enumerated already.
166 TAILQ_FOREACH(up
, &ehci_pci_alldevs
, next
) {
167 if (up
->bus
== pa
->pa_bus
&& up
->device
== pa
->pa_device
) {
168 DPRINTF(("gcscehci_attach: companion %s\n",
169 device_xname(up
->usb
)));
170 sc
->sc
.sc_comps
[ncomp
++] = up
->usb
;
171 if (ncomp
>= EHCI_COMPANION_MAX
)
175 sc
->sc
.sc_ncomp
= ncomp
;
177 r
= ehci_init(&sc
->sc
);
178 if (r
!= USBD_NORMAL_COMPLETION
) {
179 aprint_error("%s: init failed, error=%d\n", devname
, r
);
183 /* Attach usb device. */
184 sc
->sc
.sc_child
= config_found(self
, &sc
->sc
.sc_bus
, usbctlprint
);
187 CFATTACH_DECL_NEW(gcscehci
, sizeof(struct gcscehci_softc
),
188 gcscehci_match
, gcscehci_attach
, NULL
, ehci_activate
);