1 /* $NetBSD: ohci_arbus.c,v 1.6 2021/11/10 17:19:29 msaitoh Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Herb Peyerl of Middle Digital Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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. 18 * 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. 30 */ 31 32 #include "locators.h" 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: ohci_arbus.c,v 1.6 2021/11/10 17:19:29 msaitoh Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/device.h> 40 #include <sys/bus.h> 41 42 #include <dev/usb/usb.h> 43 #include <dev/usb/usbdi.h> 44 #include <dev/usb/usbdivar.h> 45 #include <dev/usb/usb_mem.h> 46 47 #include <dev/usb/ohcireg.h> 48 #include <dev/usb/ohcivar.h> 49 50 #include <mips/locore.h> 51 52 #include <mips/atheros/include/arbusvar.h> 53 54 static int ohci_arbus_match(device_t, cfdata_t, void *); 55 static void ohci_arbus_attach(device_t, device_t, void *); 56 57 CFATTACH_DECL_NEW(ohci_arbus, sizeof (ohci_softc_t), 58 ohci_arbus_match, ohci_arbus_attach, NULL, NULL); 59 60 int 61 ohci_arbus_match(device_t parent, cfdata_t cf, void *aux) 62 { 63 struct arbus_attach_args *aa = aux; 64 bus_space_handle_t bsh; 65 66 if (strcmp(aa->aa_name, cf->cf_name)) 67 return 0; 68 69 if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, &bsh) != 0) 70 return 0; 71 72 return 0; /* XXX */ 73 74 if (badaddr((void *)bsh, 4) == -1) { 75 bus_space_unmap(aa->aa_bst, bsh, aa->aa_size); 76 return 0; 77 } 78 79 bus_space_unmap(aa->aa_bst, bsh, aa->aa_size); 80 return 1; 81 } 82 83 void 84 ohci_arbus_attach(device_t parent, device_t self, void *aux) 85 { 86 ohci_softc_t * const sc = device_private(self); 87 struct arbus_attach_args * const aa = aux; 88 void *ih = NULL; 89 90 sc->sc_dev = self; 91 sc->iot = aa->aa_bst; 92 sc->sc_size = aa->aa_size; 93 sc->sc_bus.ub_dmatag = aa->aa_dmat; 94 sc->sc_bus.ub_hcpriv = sc; 95 96 if (bus_space_map(sc->iot, aa->aa_addr, sc->sc_size, 0, &sc->ioh)) { 97 aprint_error_dev(self, "unable to map registers\n"); 98 return; 99 } 100 101 /* Disable OHCI interrupts */ 102 bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 103 OHCI_ALL_INTRS); 104 105 /* establish interrupt */ 106 ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ohci_intr, sc); 107 if (ih == NULL) 108 panic("%s: couldn't establish interrupt", device_xname(self)); 109 110 /* we don't handle endianness in bus space */ 111 sc->sc_endian = OHCI_LITTLE_ENDIAN; 112 113 int err = ohci_init(sc); 114 if (err) { 115 aprint_error_dev(self, "init failed, error=%d\n", err); 116 if (ih != NULL) 117 arbus_intr_disestablish(ih); 118 return; 119 } 120 121 #if 0 122 if (psc->sc_ohci_devs[0] == NULL) { 123 psc->sc_ohci_devs[0] = self; 124 } else if (psc->sc_ohci_devs[1] == NULL) { 125 psc->sc_ohci_devs[1] = self; 126 } else { 127 panic("%s: too many ohci devices", __func__); 128 } 129 #endif 130 131 /* Attach USB device */ 132 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE); 133 } 134