ohci_arbus.c revision 1.5
11.5Sthorpej/* $NetBSD: ohci_arbus.c,v 1.5 2021/08/07 16:18:59 thorpej Exp $ */ 21.1Smatt 31.1Smatt/*- 41.1Smatt * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * This code is derived from software contributed to The NetBSD Foundation 81.1Smatt * by Herb Peyerl of Middle Digital Inc. 91.1Smatt * 101.1Smatt * Redistribution and use in source and binary forms, with or without 111.1Smatt * modification, are permitted provided that the following conditions 121.1Smatt * are met: 131.1Smatt * 1. Redistributions of source code must retain the above copyright 141.1Smatt * notice, this list of conditions and the following disclaimer. 151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 161.1Smatt * notice, this list of conditions and the following disclaimer in the 171.1Smatt * documentation and/or other materials provided with the distribution. 181.1Smatt * 191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smatt * POSSIBILITY OF SUCH DAMAGE. 301.1Smatt */ 311.1Smatt 321.1Smatt#include "locators.h" 331.1Smatt 341.1Smatt#include <sys/cdefs.h> 351.5Sthorpej__KERNEL_RCSID(0, "$NetBSD: ohci_arbus.c,v 1.5 2021/08/07 16:18:59 thorpej Exp $"); 361.1Smatt 371.1Smatt#include <sys/param.h> 381.1Smatt#include <sys/systm.h> 391.1Smatt#include <sys/device.h> 401.1Smatt#include <sys/bus.h> 411.1Smatt 421.3Sskrll#include <dev/usb/usb.h> 431.1Smatt#include <dev/usb/usbdi.h> 441.1Smatt#include <dev/usb/usbdivar.h> 451.1Smatt#include <dev/usb/usb_mem.h> 461.1Smatt 471.1Smatt#include <dev/usb/ohcireg.h> 481.1Smatt#include <dev/usb/ohcivar.h> 491.1Smatt 501.2Smatt#include <mips/locore.h> 511.2Smatt 521.1Smatt#include <mips/atheros/include/arbusvar.h> 531.1Smatt 541.1Smattstatic int ohci_arbus_match(device_t, cfdata_t, void *); 551.1Smattstatic void ohci_arbus_attach(device_t, device_t, void *); 561.1Smatt 571.1SmattCFATTACH_DECL_NEW(ohci_arbus, sizeof (ohci_softc_t), 581.1Smatt ohci_arbus_match, ohci_arbus_attach, NULL, NULL); 591.1Smatt 601.1Smattint 611.1Smattohci_arbus_match(device_t parent, cfdata_t cf, void *aux) 621.1Smatt{ 631.1Smatt struct arbus_attach_args *aa = aux; 641.1Smatt bus_space_handle_t bsh; 651.1Smatt 661.1Smatt if (strcmp(aa->aa_name, cf->cf_name)) 671.1Smatt return 0; 681.1Smatt 691.1Smatt if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, &bsh) != 0) 701.1Smatt return 0; 711.1Smatt 721.1Smatt return 0; /* XXX */ 731.1Smatt 741.1Smatt if (badaddr((void *)bsh, 4) == -1) { 751.1Smatt bus_space_unmap(aa->aa_bst, bsh, aa->aa_size); 761.1Smatt return 0; 771.1Smatt } 781.1Smatt 791.1Smatt bus_space_unmap(aa->aa_bst, bsh, aa->aa_size); 801.1Smatt return 1; 811.1Smatt} 821.1Smatt 831.1Smattvoid 841.1Smattohci_arbus_attach(device_t parent, device_t self, void *aux) 851.1Smatt{ 861.1Smatt ohci_softc_t * const sc = device_private(self); 871.1Smatt struct arbus_attach_args * const aa = aux; 881.1Smatt void *ih = NULL; 891.1Smatt 901.1Smatt sc->sc_dev = self; 911.1Smatt sc->iot = aa->aa_bst; 921.1Smatt sc->sc_size = aa->aa_size; 931.3Sskrll sc->sc_bus.ub_dmatag = aa->aa_dmat; 941.3Sskrll sc->sc_bus.ub_hcpriv = sc; 951.1Smatt 961.1Smatt if (bus_space_map(sc->iot, aa->aa_addr, sc->sc_size, 0, &sc->ioh)) { 971.1Smatt aprint_error_dev(self, "unable to map registers\n"); 981.1Smatt return; 991.1Smatt } 1001.1Smatt 1011.1Smatt /* Disable OHCI interrupts */ 1021.1Smatt bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 1031.1Smatt OHCI_ALL_INTRS); 1041.1Smatt 1051.1Smatt /* establish interrupt */ 1061.1Smatt ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ohci_intr, sc); 1071.1Smatt if (ih == NULL) 1081.1Smatt panic("%s: couldn't establish interrupt", device_xname(self)); 1091.1Smatt 1101.1Smatt /* we don't handle endianess in bus space */ 1111.1Smatt sc->sc_endian = OHCI_LITTLE_ENDIAN; 1121.1Smatt 1131.3Sskrll int err = ohci_init(sc); 1141.3Sskrll if (err) { 1151.3Sskrll aprint_error_dev(self, "init failed, error=%d\n", err); 1161.1Smatt if (ih != NULL) 1171.1Smatt arbus_intr_disestablish(ih); 1181.1Smatt return; 1191.1Smatt } 1201.1Smatt 1211.1Smatt#if 0 1221.1Smatt if (psc->sc_ohci_devs[0] == NULL) { 1231.1Smatt psc->sc_ohci_devs[0] = self; 1241.1Smatt } else if (psc->sc_ohci_devs[1] == NULL) { 1251.1Smatt psc->sc_ohci_devs[1] = self; 1261.1Smatt } else { 1271.1Smatt panic("%s: too many ohci devices", __func__); 1281.1Smatt } 1291.1Smatt#endif 1301.1Smatt 1311.1Smatt /* Attach USB device */ 1321.5Sthorpej sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE); 1331.1Smatt} 134