ehci_arbus.c revision 1.1
1/* $NetBSD: ehci_arbus.c,v 1.1 2011/07/10 06:26:02 matt Exp $ */ 2 3/*- 4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 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: ehci_arbus.c,v 1.1 2011/07/10 06:26:02 matt Exp $"); 34 35#include "locators.h" 36 37#include <sys/param.h> 38#include <sys/bus.h> 39#include <sys/device.h> 40#include <sys/systm.h> 41 42#include <mips/atheros/include/ar9344reg.h> 43#include <mips/atheros/include/arbusvar.h> 44 45#include <dev/usb/usb.h> 46#include <dev/usb/usbdi.h> 47#include <dev/usb/usbdivar.h> 48#include <dev/usb/usb_mem.h> 49 50#include <dev/usb/ehcireg.h> 51#include <dev/usb/ehcivar.h> 52 53static int ehci_arbus_match(device_t, cfdata_t, void *); 54static void ehci_arbus_attach(device_t, device_t, void *); 55 56CFATTACH_DECL_NEW(ehci_arbus, sizeof (ehci_softc_t), 57 ehci_arbus_match, ehci_arbus_attach, NULL, NULL); 58 59int 60ehci_arbus_match(device_t parent, cfdata_t cf, void *aux) 61{ 62 struct arbus_attach_args *aa = aux; 63 64 if (strcmp(aa->aa_name, cf->cf_name) != 0) 65 return 0; 66 67 if (badaddr((void *)MIPS_PHYS_TO_KSEG1(aa->aa_addr), 4)) 68 return 0; 69 70 return 1; /* XXX */ 71} 72 73void 74ehci_arbus_attach(device_t parent, device_t self, void *aux) 75{ 76 ehci_softc_t *sc = device_private(self); 77 struct arbus_attach_args * const aa = aux; 78 void *ih = NULL; 79 int error; 80 int status; 81 82 sc->iot = aa->aa_bst_le; 83 sc->sc_size = aa->aa_size; 84 //sc->sc_bus.hci_private = sc; 85 sc->sc_bus.dmatag = aa->aa_dmat; 86 sc->sc_bus.usbrev = USBREV_1_0; 87 sc->sc_flags |= EHCIF_ETTF; 88 89 error = bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, 90 &sc->ioh); 91 92 if (error) { 93 aprint_error(": failed to map registers: %d\n", error); 94 return; 95 } 96 97 /* The recommended value is 0x20 for both ports and the host */ 98 REGVAL(AR9344_USB_CONFIG_BASE) = 0x20c00; /* magic */ 99 DELAY(1000); 100 101 /* get offset to operational regs */ 102 uint32_t r = bus_space_read_4(aa->aa_bst, sc->ioh, 0); 103 if (r != 0x40) { 104 aprint_error(": error: CAPLENGTH (%#x) != 0x40\n", sc->sc_offs); 105 return; 106 } 107 108 sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 109 110 aprint_normal("\n"); 111 112 /* Disable EHCI interrupts */ 113 EOWRITE2(sc, EHCI_USBINTR, 0); 114 115 /* establish interrupt */ 116 ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ehci_intr, sc); 117 if (ih == NULL) 118 panic("%s: couldn't establish interrupt", 119 device_xname(self)); 120 121 /* 122 * There are no companion controllers 123 */ 124 sc->sc_ncomp = 0; 125 126 status = ehci_init(sc); 127 if (status != USBD_NORMAL_COMPLETION) { 128 aprint_error("%s: init failed, error=%d\n", device_xname(self), 129 status); 130 if (ih != NULL) 131 arbus_intr_disestablish(ih); 132 return; 133 } 134 135 /* Attach USB device */ 136 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 137} 138 139