ohci_arbus.c revision 1.2
11.2Smatt/* $NetBSD: ohci_arbus.c,v 1.2 2015/06/26 22:20:58 matt 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.2Smatt__KERNEL_RCSID(0, "$NetBSD: ohci_arbus.c,v 1.2 2015/06/26 22:20:58 matt 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.1Smatt#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 usbd_status status; 901.1Smatt 911.1Smatt sc->sc_dev = self; 921.1Smatt sc->iot = aa->aa_bst; 931.1Smatt sc->sc_size = aa->aa_size; 941.1Smatt sc->sc_bus.dmatag = aa->aa_dmat; 951.1Smatt sc->sc_bus.hci_private = sc; 961.1Smatt 971.1Smatt if (bus_space_map(sc->iot, aa->aa_addr, sc->sc_size, 0, &sc->ioh)) { 981.1Smatt aprint_error_dev(self, "unable to map registers\n"); 991.1Smatt return; 1001.1Smatt } 1011.1Smatt 1021.1Smatt /* Disable OHCI interrupts */ 1031.1Smatt bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 1041.1Smatt OHCI_ALL_INTRS); 1051.1Smatt 1061.1Smatt /* establish interrupt */ 1071.1Smatt ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ohci_intr, sc); 1081.1Smatt if (ih == NULL) 1091.1Smatt panic("%s: couldn't establish interrupt", device_xname(self)); 1101.1Smatt 1111.1Smatt /* we don't handle endianess in bus space */ 1121.1Smatt sc->sc_endian = OHCI_LITTLE_ENDIAN; 1131.1Smatt 1141.1Smatt status = ohci_init(sc); 1151.1Smatt if (status != USBD_NORMAL_COMPLETION) { 1161.1Smatt aprint_error_dev(self, "init failed, error=%d\n", status); 1171.1Smatt if (ih != NULL) 1181.1Smatt arbus_intr_disestablish(ih); 1191.1Smatt return; 1201.1Smatt } 1211.1Smatt 1221.1Smatt#if 0 1231.1Smatt if (psc->sc_ohci_devs[0] == NULL) { 1241.1Smatt psc->sc_ohci_devs[0] = self; 1251.1Smatt } else if (psc->sc_ohci_devs[1] == NULL) { 1261.1Smatt psc->sc_ohci_devs[1] = self; 1271.1Smatt } else { 1281.1Smatt panic("%s: too many ohci devices", __func__); 1291.1Smatt } 1301.1Smatt#endif 1311.1Smatt 1321.1Smatt /* Attach USB device */ 1331.1Smatt sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 1341.1Smatt} 135