ehci_arbus.c revision 1.5
11.5Sskrll/* $NetBSD: ehci_arbus.c,v 1.5 2015/09/21 10:10:19 skrll Exp $ */ 21.1Smatt 31.1Smatt/*- 41.1Smatt * Copyright (c) 2011 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 Matt Thomas of 3am Software Foundry. 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 <sys/cdefs.h> 331.5Sskrll__KERNEL_RCSID(0, "$NetBSD: ehci_arbus.c,v 1.5 2015/09/21 10:10:19 skrll Exp $"); 341.1Smatt 351.1Smatt#include "locators.h" 361.1Smatt 371.1Smatt#include <sys/param.h> 381.1Smatt#include <sys/bus.h> 391.1Smatt#include <sys/device.h> 401.1Smatt#include <sys/systm.h> 411.1Smatt 421.1Smatt#include <mips/atheros/include/ar9344reg.h> 431.1Smatt#include <mips/atheros/include/arbusvar.h> 441.1Smatt 451.4Sskrll#include <dev/usb/usb.h> 461.1Smatt#include <dev/usb/usbdi.h> 471.1Smatt#include <dev/usb/usbdivar.h> 481.1Smatt#include <dev/usb/usb_mem.h> 491.1Smatt 501.1Smatt#include <dev/usb/ehcireg.h> 511.1Smatt#include <dev/usb/ehcivar.h> 521.1Smatt 531.3Sskrll/* 541.3Sskrll * This is relative to the start of the unreserved registers in USB contoller 551.3Sskrll * block and not the full USB block which would be 0x1a8. 561.3Sskrll */ 571.3Sskrll#define ARBUS_USBMODE 0xa8 /* USB mode */ 581.3Sskrll#define USBMODE_CM __BITS(0,1) /* Controller Mode */ 591.3Sskrll#define USBMODE_CM_IDLE __SHIFTIN(0,USBMODE_CM) /* Idle (both) */ 601.3Sskrll#define USBMODE_CM_DEVICE __SHIFTIN(2,USBMODE_CM) /* Device Controller */ 611.3Sskrll#define USBMODE_CM_HOST __SHIFTIN(3,USBMODE_CM) /* Host Controller */ 621.3Sskrll 631.1Smattstatic int ehci_arbus_match(device_t, cfdata_t, void *); 641.1Smattstatic void ehci_arbus_attach(device_t, device_t, void *); 651.1Smatt 661.1SmattCFATTACH_DECL_NEW(ehci_arbus, sizeof (ehci_softc_t), 671.1Smatt ehci_arbus_match, ehci_arbus_attach, NULL, NULL); 681.1Smatt 691.5Sskrllstatic void ehci_arbus_init(struct ehci_softc *); 701.3Sskrll 711.1Smattint 721.1Smattehci_arbus_match(device_t parent, cfdata_t cf, void *aux) 731.1Smatt{ 741.1Smatt struct arbus_attach_args *aa = aux; 751.1Smatt 761.1Smatt if (strcmp(aa->aa_name, cf->cf_name) != 0) 771.1Smatt return 0; 781.1Smatt 791.1Smatt if (badaddr((void *)MIPS_PHYS_TO_KSEG1(aa->aa_addr), 4)) 801.1Smatt return 0; 811.1Smatt 821.1Smatt return 1; /* XXX */ 831.1Smatt} 841.1Smatt 851.1Smattvoid 861.1Smattehci_arbus_attach(device_t parent, device_t self, void *aux) 871.1Smatt{ 881.1Smatt ehci_softc_t *sc = device_private(self); 891.1Smatt struct arbus_attach_args * const aa = aux; 901.1Smatt void *ih = NULL; 911.1Smatt int error; 921.1Smatt int status; 931.1Smatt 941.1Smatt sc->iot = aa->aa_bst_le; 951.1Smatt sc->sc_size = aa->aa_size; 961.1Smatt //sc->sc_bus.hci_private = sc; 971.1Smatt sc->sc_bus.dmatag = aa->aa_dmat; 981.1Smatt sc->sc_bus.usbrev = USBREV_1_0; 991.1Smatt sc->sc_flags |= EHCIF_ETTF; 1001.3Sskrll sc->sc_vendor_init = ehci_arbus_init; 1011.1Smatt 1021.1Smatt error = bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, 1031.1Smatt &sc->ioh); 1041.1Smatt 1051.1Smatt if (error) { 1061.1Smatt aprint_error(": failed to map registers: %d\n", error); 1071.1Smatt return; 1081.1Smatt } 1091.1Smatt 1101.1Smatt /* The recommended value is 0x20 for both ports and the host */ 1111.1Smatt REGVAL(AR9344_USB_CONFIG_BASE) = 0x20c00; /* magic */ 1121.1Smatt DELAY(1000); 1131.1Smatt 1141.1Smatt /* get offset to operational regs */ 1151.1Smatt uint32_t r = bus_space_read_4(aa->aa_bst, sc->ioh, 0); 1161.1Smatt if (r != 0x40) { 1171.1Smatt aprint_error(": error: CAPLENGTH (%#x) != 0x40\n", sc->sc_offs); 1181.1Smatt return; 1191.1Smatt } 1201.1Smatt 1211.1Smatt sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 1221.1Smatt 1231.1Smatt aprint_normal("\n"); 1241.1Smatt 1251.1Smatt /* Disable EHCI interrupts */ 1261.2Smatt EOWRITE4(sc, EHCI_USBINTR, 0); 1271.1Smatt 1281.1Smatt /* establish interrupt */ 1291.1Smatt ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ehci_intr, sc); 1301.1Smatt if (ih == NULL) 1311.1Smatt panic("%s: couldn't establish interrupt", 1321.1Smatt device_xname(self)); 1331.1Smatt 1341.1Smatt /* 1351.1Smatt * There are no companion controllers 1361.1Smatt */ 1371.1Smatt sc->sc_ncomp = 0; 1381.1Smatt 1391.1Smatt status = ehci_init(sc); 1401.1Smatt if (status != USBD_NORMAL_COMPLETION) { 1411.1Smatt aprint_error("%s: init failed, error=%d\n", device_xname(self), 1421.1Smatt status); 1431.1Smatt if (ih != NULL) 1441.1Smatt arbus_intr_disestablish(ih); 1451.1Smatt return; 1461.1Smatt } 1471.1Smatt 1481.1Smatt /* Attach USB device */ 1491.1Smatt sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 1501.1Smatt} 1511.1Smatt 1521.3Sskrllstatic void 1531.3Sskrllehci_arbus_init(struct ehci_softc *sc) 1541.3Sskrll{ 1551.3Sskrll /* Set host mode */ 1561.3Sskrll uint32_t old = bus_space_read_4(sc->iot, sc->ioh, ARBUS_USBMODE); 1571.3Sskrll uint32_t reg = old; 1581.3Sskrll 1591.3Sskrll reg &= ~USBMODE_CM; 1601.3Sskrll reg |= USBMODE_CM_HOST; 1611.3Sskrll if (reg != old) 1621.3Sskrll bus_space_write_4(sc->iot, sc->ioh, ARBUS_USBMODE, reg); 1631.3Sskrll 1641.3Sskrll} 165