1 /* $NetBSD: rmixl_ohci.c,v 1.4 2011/07/01 19:01:31 dyoung 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: rmixl_ohci.c,v 1.4 2011/07/01 19:01:31 dyoung Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/device.h> 40 41 #include <sys/bus.h> 42 43 #include <mips/rmi/rmixlreg.h> 44 #include <mips/rmi/rmixlvar.h> 45 #include <mips/rmi/rmixl_intr.h> 46 #include <mips/rmi/rmixl_usbivar.h> 47 48 #include <dev/usb/usb.h> 49 #include <dev/usb/usbdi.h> 50 #include <dev/usb/usbdivar.h> 51 #include <dev/usb/usb_mem.h> 52 53 #include <dev/usb/ohcireg.h> 54 #include <dev/usb/ohcivar.h> 55 56 57 static int rmixl_ohci_match(device_t, cfdata_t, void *); 58 static void rmixl_ohci_attach(device_t, device_t, void *); 59 60 61 CFATTACH_DECL_NEW(rmixl_ohci, sizeof (ohci_softc_t), 62 rmixl_ohci_match, rmixl_ohci_attach, NULL, NULL); 63 64 int 65 rmixl_ohci_match(device_t parent, cfdata_t match, void *aux) 66 { 67 struct rmixl_usbi_attach_args *usbi = aux; 68 69 if ((usbi->usbi_addr == (RMIXL_IO_DEV_USB_A+RMIXL_USB_HOST_0HCI0_BASE)) 70 || (usbi->usbi_addr == (RMIXL_IO_DEV_USB_A+RMIXL_USB_HOST_0HCI1_BASE))) 71 return rmixl_probe_4((volatile uint32_t *) 72 RMIXL_IOREG_VADDR(usbi->usbi_addr)); 73 74 return 0; 75 } 76 77 void 78 rmixl_ohci_attach(device_t parent, device_t self, void *aux) 79 { 80 ohci_softc_t * const sc = device_private(self); 81 rmixl_usbi_softc_t * const psc = device_private(parent); 82 struct rmixl_usbi_attach_args * const usbi = aux; 83 void *ih = NULL; 84 uint32_t r; 85 usbd_status status; 86 87 /* check state of IO_AD9 signal latched in GPIO Reset Config reg */ 88 r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG); 89 if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) { 90 aprint_error_dev(self, 91 "IO_AD9 selects Device mode, abort Host attach\n"); 92 return; 93 } 94 95 sc->sc_dev = self; 96 sc->iot = usbi->usbi_el_bst; 97 sc->sc_size = usbi->usbi_size; 98 sc->sc_bus.dmatag = usbi->usbi_dmat; 99 sc->sc_bus.hci_private = sc; 100 101 if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) { 102 aprint_error_dev(self, "unable to map registers\n"); 103 return; 104 } 105 106 /* Disable OHCI interrupts */ 107 bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 108 OHCI_ALL_INTRS); 109 110 /* establish interrupt */ 111 if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) { 112 ih = rmixl_usbi_intr_establish(device_private(parent), 113 usbi->usbi_intr, ohci_intr, sc); 114 if (ih == NULL) 115 panic("%s: couldn't establish interrupt", 116 device_xname(self)); 117 } 118 119 /* we handle endianess in bus space */ 120 sc->sc_endian = OHCI_HOST_ENDIAN; 121 122 status = ohci_init(sc); 123 if (status != USBD_NORMAL_COMPLETION) { 124 aprint_error_dev(self, "init failed, error=%d\n", status); 125 if (ih != NULL) 126 rmixl_intr_disestablish(ih); 127 return; 128 } 129 130 if (psc->sc_ohci_devs[0] == NULL) { 131 psc->sc_ohci_devs[0] = self; 132 } else if (psc->sc_ohci_devs[1] == NULL) { 133 psc->sc_ohci_devs[1] = self; 134 } else { 135 panic("%s: too many ohci devices", __func__); 136 } 137 138 /* Attach USB device */ 139 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 140 } 141