2021-08-07 19:18:40 +03:00
|
|
|
/* $NetBSD: gcscehci.c,v 1.15 2021/08/07 16:18:55 thorpej Exp $ */
|
2007-07-08 05:13:26 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001, 2002, 2007 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Lennart Augustsson (lennart@augustsson.net)
|
|
|
|
* and Jared D. McNeill (jmcneill@invisible.ca)
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2021-08-07 19:18:40 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: gcscehci.c,v 1.15 2021/08/07 16:18:55 thorpej Exp $");
|
2007-07-08 05:13:26 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
2011-07-01 21:37:26 +04:00
|
|
|
#include <sys/bus.h>
|
2007-07-08 05:13:26 +04:00
|
|
|
#include <machine/cpufunc.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/usb_pci.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdivar.h>
|
|
|
|
#include <dev/usb/usb_mem.h>
|
|
|
|
|
|
|
|
#include <dev/usb/ehcireg.h>
|
|
|
|
#include <dev/usb/ehcivar.h>
|
|
|
|
|
|
|
|
#ifdef EHCI_DEBUG
|
|
|
|
#define DPRINTF(x) if (ehcidebug) printf x
|
|
|
|
extern int ehcidebug;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GCSCUSB_MSR_BASE 0x51200000
|
|
|
|
#define GCSCUSB_MSR_EHCB (GCSCUSB_MSR_BASE + 0x09)
|
|
|
|
|
|
|
|
struct gcscehci_softc {
|
|
|
|
ehci_softc_t sc;
|
|
|
|
pci_chipset_tag_t sc_pc;
|
|
|
|
pcitag_t sc_tag;
|
|
|
|
void *sc_ih; /* interrupt vectoring */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2009-05-04 16:15:51 +04:00
|
|
|
gcscehci_match(device_t parent, cfdata_t match, void *aux)
|
2007-07-08 05:13:26 +04:00
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = (struct pci_attach_args *) aux;
|
|
|
|
|
|
|
|
if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS &&
|
|
|
|
PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_USB &&
|
|
|
|
PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_EHCI &&
|
|
|
|
PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
|
|
|
|
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_CS5536_EHCI)
|
2016-04-23 13:15:27 +03:00
|
|
|
return 10; /* beat ehci_pci */
|
2007-07-08 05:13:26 +04:00
|
|
|
|
2016-04-23 13:15:27 +03:00
|
|
|
return 0;
|
2007-07-08 05:13:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-04 16:15:51 +04:00
|
|
|
gcscehci_attach(device_t parent, device_t self, void *aux)
|
2007-07-08 05:13:26 +04:00
|
|
|
{
|
2008-03-28 20:14:45 +03:00
|
|
|
struct gcscehci_softc *sc = device_private(self);
|
2007-07-08 05:13:26 +04:00
|
|
|
struct pci_attach_args *pa = (struct pci_attach_args *)aux;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
pcitag_t tag = pa->pa_tag;
|
|
|
|
char const *intrstr;
|
|
|
|
pci_intr_handle_t ih;
|
2008-03-28 20:14:45 +03:00
|
|
|
const char *devname = device_xname(self);
|
2007-07-08 05:13:26 +04:00
|
|
|
char devinfo[256];
|
|
|
|
bus_addr_t ehcibase;
|
|
|
|
int ncomp;
|
|
|
|
struct usb_pci *up;
|
2014-03-29 23:28:24 +04:00
|
|
|
char buf[PCI_INTRSTR_LEN];
|
2007-07-08 05:13:26 +04:00
|
|
|
|
2008-03-28 20:14:45 +03:00
|
|
|
sc->sc.sc_dev = self;
|
2016-04-23 13:15:27 +03:00
|
|
|
sc->sc.sc_bus.ub_hcpriv = sc;
|
2008-03-28 20:14:45 +03:00
|
|
|
|
2007-07-08 05:13:26 +04:00
|
|
|
aprint_naive(": USB controller\n");
|
|
|
|
|
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
|
|
|
|
aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
|
|
|
|
PCI_REVISION(pa->pa_class));
|
|
|
|
|
|
|
|
/* Map I/O registers */
|
|
|
|
ehcibase = rdmsr(GCSCUSB_MSR_EHCB) & 0xffffff00;
|
|
|
|
sc->sc.iot = pa->pa_memt;
|
|
|
|
sc->sc.sc_size = 256;
|
|
|
|
if (bus_space_map(sc->sc.iot, ehcibase, 256, 0, &sc->sc.ioh)) {
|
|
|
|
aprint_error("%s: can't map memory space\n", devname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_pc = pc;
|
|
|
|
sc->sc_tag = tag;
|
2016-04-23 13:15:27 +03:00
|
|
|
sc->sc.sc_bus.ub_dmatag = pa->pa_dmat;
|
2007-07-08 05:13:26 +04:00
|
|
|
|
|
|
|
/* Disable interrupts, so we don't get any spurious ones. */
|
|
|
|
sc->sc.sc_offs = EREAD1(&sc->sc, EHCI_CAPLENGTH);
|
|
|
|
DPRINTF(("%s: offs=%d\n", devname, sc->sc.sc_offs));
|
|
|
|
EOWRITE2(&sc->sc, EHCI_USBINTR, 0);
|
|
|
|
|
|
|
|
/* Map and establish the interrupt. */
|
|
|
|
if (pci_intr_map(pa, &ih)) {
|
|
|
|
aprint_error("%s: couldn't map interrupt\n", devname);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-29 23:28:24 +04:00
|
|
|
intrstr = pci_intr_string(pc, ih, buf, sizeof(buf));
|
2007-07-08 05:13:26 +04:00
|
|
|
sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ehci_intr, sc);
|
|
|
|
if (sc->sc_ih == NULL) {
|
|
|
|
aprint_error("%s: couldn't establish interrupt", devname);
|
|
|
|
if (intrstr != NULL)
|
2009-12-04 14:13:04 +03:00
|
|
|
aprint_error(" at %s", intrstr);
|
|
|
|
aprint_error("\n");
|
2007-07-08 05:13:26 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
aprint_normal("%s: interrupting at %s\n", devname, intrstr);
|
|
|
|
|
2016-04-23 13:15:27 +03:00
|
|
|
sc->sc.sc_bus.ub_revision = USBREV_2_0;
|
2007-07-08 05:13:26 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find companion controllers. According to the spec they always
|
|
|
|
* have lower function numbers so they should be enumerated already.
|
|
|
|
*/
|
|
|
|
ncomp = 0;
|
|
|
|
TAILQ_FOREACH(up, &ehci_pci_alldevs, next) {
|
|
|
|
if (up->bus == pa->pa_bus && up->device == pa->pa_device) {
|
|
|
|
DPRINTF(("gcscehci_attach: companion %s\n",
|
2008-03-28 20:14:45 +03:00
|
|
|
device_xname(up->usb)));
|
2007-07-08 05:13:26 +04:00
|
|
|
sc->sc.sc_comps[ncomp++] = up->usb;
|
|
|
|
if (ncomp >= EHCI_COMPANION_MAX)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc.sc_ncomp = ncomp;
|
|
|
|
|
2016-04-23 13:15:27 +03:00
|
|
|
int err = ehci_init(&sc->sc);
|
|
|
|
if (err) {
|
|
|
|
aprint_error("%s: init failed, error=%d\n", devname, err);
|
2007-07-08 05:13:26 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach usb device. */
|
Merge thorpej-cfargs branch:
Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.
Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)
Remove unnecessary or redundant interface attributes where they're not
needed.
There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)
...and a sentinel value CFARG_EOL.
Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.
Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
2021-04-25 02:36:23 +03:00
|
|
|
sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint,
|
2021-08-07 19:18:40 +03:00
|
|
|
CFARGS_NONE);
|
2007-07-08 05:13:26 +04:00
|
|
|
}
|
|
|
|
|
2008-03-28 20:14:45 +03:00
|
|
|
CFATTACH_DECL_NEW(gcscehci, sizeof(struct gcscehci_softc),
|
2007-07-08 05:13:26 +04:00
|
|
|
gcscehci_match, gcscehci_attach, NULL, ehci_activate);
|