1*c7fb772bSthorpej /* $NetBSD: rmixl_ehci.c,v 1.8 2021/08/07 16:18:59 thorpej Exp $ */
23e67b512Smatt
33e67b512Smatt /*-
43e67b512Smatt * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
53e67b512Smatt * All rights reserved.
63e67b512Smatt *
73e67b512Smatt * This code is derived from software contributed to The NetBSD Foundation
83e67b512Smatt * by Herb Peyerl of Middle Digital Inc.
93e67b512Smatt *
103e67b512Smatt * Redistribution and use in source and binary forms, with or without
113e67b512Smatt * modification, are permitted provided that the following conditions
123e67b512Smatt * are met:
133e67b512Smatt * 1. Redistributions of source code must retain the above copyright
143e67b512Smatt * notice, this list of conditions and the following disclaimer.
153e67b512Smatt * 2. Redistributions in binary form must reproduce the above copyright
163e67b512Smatt * notice, this list of conditions and the following disclaimer in the
173e67b512Smatt * documentation and/or other materials provided with the distribution.
183e67b512Smatt *
193e67b512Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203e67b512Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213e67b512Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223e67b512Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233e67b512Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243e67b512Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253e67b512Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263e67b512Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273e67b512Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283e67b512Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293e67b512Smatt * POSSIBILITY OF SUCH DAMAGE.
303e67b512Smatt */
313e67b512Smatt
323e67b512Smatt #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: rmixl_ehci.c,v 1.8 2021/08/07 16:18:59 thorpej Exp $");
343e67b512Smatt
353e67b512Smatt #include "locators.h"
363e67b512Smatt
373e67b512Smatt #include <sys/param.h>
383e67b512Smatt #include <sys/systm.h>
393e67b512Smatt #include <sys/device.h>
403e67b512Smatt
41cf10107dSdyoung #include <sys/bus.h>
423e67b512Smatt
433e67b512Smatt #include <mips/rmi/rmixlreg.h>
443e67b512Smatt #include <mips/rmi/rmixlvar.h>
453e67b512Smatt #include <mips/rmi/rmixl_intr.h>
463e67b512Smatt #include <mips/rmi/rmixl_usbivar.h>
473e67b512Smatt
483e67b512Smatt #include <dev/usb/usb.h>
493e67b512Smatt #include <dev/usb/usbdi.h>
503e67b512Smatt #include <dev/usb/usbdivar.h>
513e67b512Smatt #include <dev/usb/usb_mem.h>
523e67b512Smatt
533e67b512Smatt #include <dev/usb/ehcireg.h>
543e67b512Smatt #include <dev/usb/ehcivar.h>
553e67b512Smatt
563e67b512Smatt
573e67b512Smatt static int rmixl_ehci_match(device_t, cfdata_t, void *);
583e67b512Smatt static void rmixl_ehci_attach(device_t, device_t, void *);
593e67b512Smatt
603e67b512Smatt
613e67b512Smatt CFATTACH_DECL_NEW(rmixl_ehci, sizeof (ehci_softc_t),
623e67b512Smatt rmixl_ehci_match, rmixl_ehci_attach, NULL, NULL);
633e67b512Smatt
643e67b512Smatt int
rmixl_ehci_match(device_t parent,cfdata_t match,void * aux)653e67b512Smatt rmixl_ehci_match(device_t parent, cfdata_t match, void *aux)
663e67b512Smatt {
673e67b512Smatt struct rmixl_usbi_attach_args *usbi = aux;
683e67b512Smatt
693e67b512Smatt if (usbi->usbi_addr == (RMIXL_IO_DEV_USB_A + RMIXL_USB_HOST_EHCI_BASE))
703e67b512Smatt return rmixl_probe_4((volatile uint32_t *)
713e67b512Smatt RMIXL_IOREG_VADDR(usbi->usbi_addr));
723e67b512Smatt
733e67b512Smatt return 0;
743e67b512Smatt }
753e67b512Smatt
763e67b512Smatt void
rmixl_ehci_attach(device_t parent,device_t self,void * aux)773e67b512Smatt rmixl_ehci_attach(device_t parent, device_t self, void *aux)
783e67b512Smatt {
79294e5e26Smatt ehci_softc_t * const sc = device_private(self);
80294e5e26Smatt rmixl_usbi_softc_t * const psc = device_private(parent);
81294e5e26Smatt struct rmixl_usbi_attach_args * const usbi = aux;
823e67b512Smatt void *ih = NULL;
833e67b512Smatt uint32_t r;
843e67b512Smatt
853e67b512Smatt /* check state of IO_AD9 signal latched in GPIO Reset Config reg */
863e67b512Smatt r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
873e67b512Smatt if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) {
883e67b512Smatt aprint_error_dev(self,
893e67b512Smatt "IO_AD9 selects Device mode, abort Host attach\n");
903e67b512Smatt return;
913e67b512Smatt }
923e67b512Smatt
933e67b512Smatt sc->sc_dev = self;
944e8e6643Sskrll sc->sc_bus.ub_hcpriv = sc;
953e67b512Smatt sc->iot = usbi->usbi_el_bst;
963e67b512Smatt sc->sc_size = usbi->usbi_size;
974e8e6643Sskrll sc->sc_bus.ub_dmatag = usbi->usbi_dmat;
984e8e6643Sskrll sc->sc_bus.ub_revision = USBREV_1_0;
993e67b512Smatt
100294e5e26Smatt /*
101294e5e26Smatt * Grab the companion OHCI devices from our parent.
102294e5e26Smatt */
103294e5e26Smatt if (psc->sc_ohci_devs[1] != NULL) {
104294e5e26Smatt sc->sc_comps[0] = psc->sc_ohci_devs[0];
105294e5e26Smatt sc->sc_comps[1] = psc->sc_ohci_devs[1];
106294e5e26Smatt sc->sc_ncomp = 2;
107294e5e26Smatt } else {
108294e5e26Smatt sc->sc_comps[0] = psc->sc_ohci_devs[0];
109294e5e26Smatt sc->sc_ncomp = 1;
110294e5e26Smatt }
111294e5e26Smatt
1123e67b512Smatt if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) {
1133e67b512Smatt aprint_error_dev(self, "unable to map registers\n");
1143e67b512Smatt return;
1153e67b512Smatt }
1163e67b512Smatt
1173e67b512Smatt /* get offset to operational regs */
1183e67b512Smatt sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
1193e67b512Smatt
1203e67b512Smatt /* Disable EHCI interrupts */
12109fca0b7Smatt EOWRITE4(sc, EHCI_USBINTR, 0);
1223e67b512Smatt
1233e67b512Smatt /* establish interrupt */
1243e67b512Smatt if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) {
1253e67b512Smatt ih = rmixl_usbi_intr_establish(device_private(parent),
1263e67b512Smatt usbi->usbi_intr, ehci_intr, sc);
1273e67b512Smatt if (ih == NULL)
1283e67b512Smatt panic("%s: couldn't establish interrupt",
1293e67b512Smatt device_xname(self));
1303e67b512Smatt }
1313e67b512Smatt
1324e8e6643Sskrll int err = ehci_init(sc);
1334e8e6643Sskrll if (err) {
1344e8e6643Sskrll aprint_error_dev(self, "init failed, error=%d\n", err);
1353e67b512Smatt if (ih != NULL)
1363e67b512Smatt rmixl_intr_disestablish(ih);
1373e67b512Smatt return;
1383e67b512Smatt }
1393e67b512Smatt
1403e67b512Smatt /* Attach USB device */
141*c7fb772bSthorpej sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE);
1423e67b512Smatt }
1433e67b512Smatt
144