ti_ehci.c revision 1.2
11.2Sjmcneill/* $NetBSD: ti_ehci.c,v 1.2 2021/01/15 23:19:33 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2015-2019 Jared McNeill <jmcneill@invisible.ca> 51.1Sjmcneill * All rights reserved. 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice, this list of conditions and the following disclaimer. 121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjmcneill * notice, this list of conditions and the following disclaimer in the 141.1Sjmcneill * documentation and/or other materials provided with the distribution. 151.1Sjmcneill * 161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sjmcneill * SUCH DAMAGE. 271.1Sjmcneill */ 281.1Sjmcneill 291.1Sjmcneill#include <sys/cdefs.h> 301.2Sjmcneill__KERNEL_RCSID(0, "$NetBSD: ti_ehci.c,v 1.2 2021/01/15 23:19:33 jmcneill Exp $"); 311.1Sjmcneill 321.1Sjmcneill#include <sys/param.h> 331.1Sjmcneill#include <sys/bus.h> 341.1Sjmcneill#include <sys/device.h> 351.1Sjmcneill#include <sys/intr.h> 361.1Sjmcneill#include <sys/systm.h> 371.1Sjmcneill#include <sys/kernel.h> 381.1Sjmcneill 391.1Sjmcneill#include <dev/usb/usb.h> 401.1Sjmcneill#include <dev/usb/usbdi.h> 411.1Sjmcneill#include <dev/usb/usbdivar.h> 421.1Sjmcneill#include <dev/usb/usb_mem.h> 431.1Sjmcneill#include <dev/usb/ehcireg.h> 441.1Sjmcneill#include <dev/usb/ehcivar.h> 451.1Sjmcneill 461.1Sjmcneill#include <dev/fdt/fdtvar.h> 471.1Sjmcneill 481.1Sjmcneill#define TI_EHCI_NPORTS 3 491.1Sjmcneill 501.1Sjmcneillstatic int ti_ehci_match(device_t, cfdata_t, void *); 511.1Sjmcneillstatic void ti_ehci_attach(device_t, device_t, void *); 521.1Sjmcneill 531.1SjmcneillCFATTACH_DECL2_NEW(ti_ehci, sizeof(struct ehci_softc), 541.1Sjmcneill ti_ehci_match, ti_ehci_attach, NULL, 551.1Sjmcneill ehci_activate, NULL, ehci_childdet); 561.1Sjmcneill 571.1Sjmcneillstatic int 581.1Sjmcneillti_ehci_match(device_t parent, cfdata_t cf, void *aux) 591.1Sjmcneill{ 601.1Sjmcneill const char * const compatible[] = { 611.1Sjmcneill "ti,ehci-omap", 621.1Sjmcneill NULL 631.1Sjmcneill }; 641.1Sjmcneill struct fdt_attach_args * const faa = aux; 651.1Sjmcneill 661.1Sjmcneill return of_match_compatible(faa->faa_phandle, compatible); 671.1Sjmcneill} 681.1Sjmcneill 691.1Sjmcneillstatic void 701.1Sjmcneillti_ehci_attach(device_t parent, device_t self, void *aux) 711.1Sjmcneill{ 721.1Sjmcneill struct ehci_softc * const sc = device_private(self); 731.1Sjmcneill struct fdt_attach_args * const faa = aux; 741.1Sjmcneill const int phandle = faa->faa_phandle; 751.1Sjmcneill struct fdtbus_reset *rst; 761.1Sjmcneill struct fdtbus_phy *phy; 771.1Sjmcneill struct clk *clk; 781.1Sjmcneill char intrstr[128]; 791.1Sjmcneill bus_addr_t addr; 801.1Sjmcneill bus_size_t size; 811.1Sjmcneill int error; 821.1Sjmcneill void *ih; 831.1Sjmcneill u_int n; 841.1Sjmcneill 851.1Sjmcneill if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 861.1Sjmcneill aprint_error(": couldn't get registers\n"); 871.1Sjmcneill return; 881.1Sjmcneill } 891.1Sjmcneill 901.1Sjmcneill /* Enable clocks */ 911.1Sjmcneill for (n = 0; (clk = fdtbus_clock_get_index(phandle, n)) != NULL; n++) 921.1Sjmcneill if (clk_enable(clk) != 0) { 931.1Sjmcneill aprint_error(": couldn't enable clock #%d\n", n); 941.1Sjmcneill return; 951.1Sjmcneill } 961.1Sjmcneill /* De-assert resets */ 971.1Sjmcneill for (n = 0; (rst = fdtbus_reset_get_index(phandle, n)) != NULL; n++) 981.1Sjmcneill if (fdtbus_reset_deassert(rst) != 0) { 991.1Sjmcneill aprint_error(": couldn't de-assert reset #%d\n", n); 1001.1Sjmcneill return; 1011.1Sjmcneill } 1021.1Sjmcneill 1031.1Sjmcneill sc->sc_dev = self; 1041.1Sjmcneill sc->sc_bus.ub_hcpriv = sc; 1051.1Sjmcneill sc->sc_bus.ub_dmatag = faa->faa_dmat; 1061.1Sjmcneill sc->sc_bus.ub_revision = USBREV_2_0; 1071.1Sjmcneill if (of_hasprop(phandle, "has-transaction-translator")) 1081.1Sjmcneill sc->sc_flags |= EHCIF_ETTF; 1091.1Sjmcneill else 1101.1Sjmcneill sc->sc_ncomp = 1; 1111.1Sjmcneill sc->sc_size = size; 1121.1Sjmcneill sc->iot = faa->faa_bst; 1131.1Sjmcneill if (bus_space_map(sc->iot, addr, size, 0, &sc->ioh) != 0) { 1141.1Sjmcneill aprint_error(": couldn't map registers\n"); 1151.1Sjmcneill return; 1161.1Sjmcneill } 1171.1Sjmcneill 1181.1Sjmcneill aprint_naive("\n"); 1191.1Sjmcneill aprint_normal(": EHCI\n"); 1201.1Sjmcneill 1211.1Sjmcneill /* Enable PHYs */ 1221.1Sjmcneill for (n = 0; n < TI_EHCI_NPORTS; n++) { 1231.1Sjmcneill phy = fdtbus_phy_get_index(phandle, n); 1241.1Sjmcneill if (phy && fdtbus_phy_enable(phy, true) != 0) { 1251.1Sjmcneill aprint_error(": couldn't enable phy\n"); 1261.1Sjmcneill return; 1271.1Sjmcneill } 1281.1Sjmcneill } 1291.1Sjmcneill 1301.1Sjmcneill /* Disable interrupts */ 1311.1Sjmcneill sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 1321.1Sjmcneill EOWRITE4(sc, EHCI_USBINTR, 0); 1331.1Sjmcneill 1341.1Sjmcneill if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) { 1351.1Sjmcneill aprint_error_dev(self, "failed to decode interrupt\n"); 1361.1Sjmcneill return; 1371.1Sjmcneill } 1381.1Sjmcneill 1391.2Sjmcneill ih = fdtbus_intr_establish_xname(phandle, 0, IPL_USB, FDT_INTR_MPSAFE, 1401.2Sjmcneill ehci_intr, sc, device_xname(self)); 1411.1Sjmcneill if (ih == NULL) { 1421.1Sjmcneill aprint_error_dev(self, "couldn't establish interrupt on %s\n", 1431.1Sjmcneill intrstr); 1441.1Sjmcneill return; 1451.1Sjmcneill } 1461.1Sjmcneill aprint_normal_dev(self, "interrupting on %s\n", intrstr); 1471.1Sjmcneill 1481.1Sjmcneill error = ehci_init(sc); 1491.1Sjmcneill if (error) { 1501.1Sjmcneill aprint_error_dev(self, "init failed, error = %d\n", error); 1511.1Sjmcneill return; 1521.1Sjmcneill } 1531.1Sjmcneill 1541.1Sjmcneill pmf_device_register1(self, NULL, NULL, ehci_shutdown); 1551.1Sjmcneill 1561.1Sjmcneill sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 1571.1Sjmcneill} 158