ehci_arbus.c revision 1.4
1/* $NetBSD: ehci_arbus.c,v 1.4 2015/09/11 06:55:45 skrll 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.4 2015/09/11 06:55:45 skrll 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 53/* 54 * This is relative to the start of the unreserved registers in USB contoller 55 * block and not the full USB block which would be 0x1a8. 56 */ 57#define ARBUS_USBMODE 0xa8 /* USB mode */ 58#define USBMODE_CM __BITS(0,1) /* Controller Mode */ 59#define USBMODE_CM_IDLE __SHIFTIN(0,USBMODE_CM) /* Idle (both) */ 60#define USBMODE_CM_DEVICE __SHIFTIN(2,USBMODE_CM) /* Device Controller */ 61#define USBMODE_CM_HOST __SHIFTIN(3,USBMODE_CM) /* Host Controller */ 62 63static int ehci_arbus_match(device_t, cfdata_t, void *); 64static void ehci_arbus_attach(device_t, device_t, void *); 65 66CFATTACH_DECL_NEW(ehci_arbus, sizeof (ehci_softc_t), 67 ehci_arbus_match, ehci_arbus_attach, NULL, NULL); 68 69static void ehci_arbus_init(struct ehci_soft *); 70 71int 72ehci_arbus_match(device_t parent, cfdata_t cf, void *aux) 73{ 74 struct arbus_attach_args *aa = aux; 75 76 if (strcmp(aa->aa_name, cf->cf_name) != 0) 77 return 0; 78 79 if (badaddr((void *)MIPS_PHYS_TO_KSEG1(aa->aa_addr), 4)) 80 return 0; 81 82 return 1; /* XXX */ 83} 84 85void 86ehci_arbus_attach(device_t parent, device_t self, void *aux) 87{ 88 ehci_softc_t *sc = device_private(self); 89 struct arbus_attach_args * const aa = aux; 90 void *ih = NULL; 91 int error; 92 int status; 93 94 sc->iot = aa->aa_bst_le; 95 sc->sc_size = aa->aa_size; 96 //sc->sc_bus.hci_private = sc; 97 sc->sc_bus.dmatag = aa->aa_dmat; 98 sc->sc_bus.usbrev = USBREV_1_0; 99 sc->sc_flags |= EHCIF_ETTF; 100 sc->sc_vendor_init = ehci_arbus_init; 101 102 error = bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, 103 &sc->ioh); 104 105 if (error) { 106 aprint_error(": failed to map registers: %d\n", error); 107 return; 108 } 109 110 /* The recommended value is 0x20 for both ports and the host */ 111 REGVAL(AR9344_USB_CONFIG_BASE) = 0x20c00; /* magic */ 112 DELAY(1000); 113 114 /* get offset to operational regs */ 115 uint32_t r = bus_space_read_4(aa->aa_bst, sc->ioh, 0); 116 if (r != 0x40) { 117 aprint_error(": error: CAPLENGTH (%#x) != 0x40\n", sc->sc_offs); 118 return; 119 } 120 121 sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 122 123 aprint_normal("\n"); 124 125 /* Disable EHCI interrupts */ 126 EOWRITE4(sc, EHCI_USBINTR, 0); 127 128 /* establish interrupt */ 129 ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ehci_intr, sc); 130 if (ih == NULL) 131 panic("%s: couldn't establish interrupt", 132 device_xname(self)); 133 134 /* 135 * There are no companion controllers 136 */ 137 sc->sc_ncomp = 0; 138 139 status = ehci_init(sc); 140 if (status != USBD_NORMAL_COMPLETION) { 141 aprint_error("%s: init failed, error=%d\n", device_xname(self), 142 status); 143 if (ih != NULL) 144 arbus_intr_disestablish(ih); 145 return; 146 } 147 148 /* Attach USB device */ 149 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 150} 151 152static void 153ehci_arbus_init(struct ehci_softc *sc) 154{ 155 /* Set host mode */ 156 uint32_t old = bus_space_read_4(sc->iot, sc->ioh, ARBUS_USBMODE); 157 uint32_t reg = old; 158 159 reg &= ~USBMODE_CM; 160 reg |= USBMODE_CM_HOST; 161 if (reg != old) 162 bus_space_write_4(sc->iot, sc->ioh, ARBUS_USBMODE, reg); 163 164} 165