1 /* $NetBSD: rmixl_ehci.c,v 1.5 2012/07/20 02:14:01 matt 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 <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: rmixl_ehci.c,v 1.5 2012/07/20 02:14:01 matt Exp $"); 34 35 #include "locators.h" 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/ehcireg.h> 54 #include <dev/usb/ehcivar.h> 55 56 57 static int rmixl_ehci_match(device_t, cfdata_t, void *); 58 static void rmixl_ehci_attach(device_t, device_t, void *); 59 60 61 CFATTACH_DECL_NEW(rmixl_ehci, sizeof (ehci_softc_t), 62 rmixl_ehci_match, rmixl_ehci_attach, NULL, NULL); 63 64 int 65 rmixl_ehci_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_EHCI_BASE)) 70 return rmixl_probe_4((volatile uint32_t *) 71 RMIXL_IOREG_VADDR(usbi->usbi_addr)); 72 73 return 0; 74 } 75 76 void 77 rmixl_ehci_attach(device_t parent, device_t self, void *aux) 78 { 79 ehci_softc_t * const sc = device_private(self); 80 rmixl_usbi_softc_t * const psc = device_private(parent); 81 struct rmixl_usbi_attach_args * const usbi = aux; 82 void *ih = NULL; 83 uint32_t r; 84 usbd_status status; 85 86 /* check state of IO_AD9 signal latched in GPIO Reset Config reg */ 87 r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG); 88 if ((r & RMIXL_GPIO_RESET_CFG_USB_DEV) == 0) { 89 aprint_error_dev(self, 90 "IO_AD9 selects Device mode, abort Host attach\n"); 91 return; 92 } 93 94 sc->sc_dev = self; 95 sc->sc_bus.hci_private = sc; 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.usbrev = USBREV_1_0; 100 101 /* 102 * Grab the companion OHCI devices from our parent. 103 */ 104 if (psc->sc_ohci_devs[1] != NULL) { 105 sc->sc_comps[0] = psc->sc_ohci_devs[0]; 106 sc->sc_comps[1] = psc->sc_ohci_devs[1]; 107 sc->sc_ncomp = 2; 108 } else { 109 sc->sc_comps[0] = psc->sc_ohci_devs[0]; 110 sc->sc_ncomp = 1; 111 } 112 113 if (bus_space_map(sc->iot, usbi->usbi_addr, sc->sc_size, 0, &sc->ioh)) { 114 aprint_error_dev(self, "unable to map registers\n"); 115 return; 116 } 117 118 /* get offset to operational regs */ 119 sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 120 121 /* Disable EHCI interrupts */ 122 EOWRITE4(sc, EHCI_USBINTR, 0); 123 124 /* establish interrupt */ 125 if (usbi->usbi_intr != RMIXL_USBICF_INTR_DEFAULT) { 126 ih = rmixl_usbi_intr_establish(device_private(parent), 127 usbi->usbi_intr, ehci_intr, sc); 128 if (ih == NULL) 129 panic("%s: couldn't establish interrupt", 130 device_xname(self)); 131 } 132 133 status = ehci_init(sc); 134 if (status != USBD_NORMAL_COMPLETION) { 135 aprint_error_dev(self, "init failed, error=%d\n", status); 136 if (ih != NULL) 137 rmixl_intr_disestablish(ih); 138 return; 139 } 140 141 /* Attach USB device */ 142 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 143 } 144 145