11.1Sjmcneill/* $NetBSD: ehci_ahb.c,v 1.1 2026/01/09 22:54:29 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2024 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.1Sjmcneill__KERNEL_RCSID(0, "$NetBSD: ehci_ahb.c,v 1.1 2026/01/09 22:54:29 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/systm.h> 361.1Sjmcneill 371.1Sjmcneill#include <dev/usb/usb.h> 381.1Sjmcneill#include <dev/usb/usbdi.h> 391.1Sjmcneill#include <dev/usb/usbdivar.h> 401.1Sjmcneill#include <dev/usb/usb_mem.h> 411.1Sjmcneill#include <dev/usb/ehcireg.h> 421.1Sjmcneill#include <dev/usb/ehcivar.h> 431.1Sjmcneill 441.1Sjmcneill#include <machine/wii.h> 451.1Sjmcneill#include <machine/wiiu.h> 461.1Sjmcneill#include "ahb.h" 471.1Sjmcneill 481.1Sjmcneill#define USB_CHICKENBITS 0x0d0400cc 491.1Sjmcneill#define EHCI_INTR_ENABLE 0x00008000 501.1Sjmcneill 511.1Sjmcneillextern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag; 521.1Sjmcneill 531.1Sjmcneillstatic int ehci_ahb_match(device_t, cfdata_t, void *); 541.1Sjmcneillstatic void ehci_ahb_attach(device_t, device_t, void *); 551.1Sjmcneill 561.1SjmcneillCFATTACH_DECL_NEW(ehci_ahb, sizeof(struct ehci_softc), 571.1Sjmcneill ehci_ahb_match, ehci_ahb_attach, NULL, NULL); 581.1Sjmcneill 591.1Sjmcneillstatic int 601.1Sjmcneillehci_ahb_match(device_t parent, cfdata_t cf, void *aux) 611.1Sjmcneill{ 621.1Sjmcneill struct ahb_attach_args *aaa = aux; 631.1Sjmcneill 641.1Sjmcneill return wiiu_native || aaa->aaa_irq < 32; 651.1Sjmcneill} 661.1Sjmcneill 671.1Sjmcneillstatic void 681.1Sjmcneillehci_ahb_attach(device_t parent, device_t self, void *aux) 691.1Sjmcneill{ 701.1Sjmcneill struct ahb_attach_args *aaa = aux; 711.1Sjmcneill struct ehci_softc *sc = device_private(self); 721.1Sjmcneill int error; 731.1Sjmcneill 741.1Sjmcneill sc->sc_dev = self; 751.1Sjmcneill sc->sc_bus.ub_hcpriv = sc; 761.1Sjmcneill sc->sc_bus.ub_dmatag = &wii_mem2_bus_dma_tag; 771.1Sjmcneill sc->sc_bus.ub_revision = USBREV_2_0; 781.1Sjmcneill sc->sc_flags = EHCIF_32BIT_ACCESS; 791.1Sjmcneill sc->sc_ncomp = aaa->aaa_irq < 32 ? 2 : 1; 801.1Sjmcneill sc->sc_size = 0x100; 811.1Sjmcneill sc->iot = aaa->aaa_bst; 821.1Sjmcneill if (bus_space_map(sc->iot, aaa->aaa_addr, sc->sc_size, 0, &sc->ioh)) { 831.1Sjmcneill aprint_error(": couldn't map registers\n"); 841.1Sjmcneill return; 851.1Sjmcneill } 861.1Sjmcneill 871.1Sjmcneill aprint_naive("\n"); 881.1Sjmcneill aprint_normal(": EHCI\n"); 891.1Sjmcneill 901.1Sjmcneill ahb_claim_device(self, IOPEHCEN); 911.1Sjmcneill 921.1Sjmcneill sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); 931.1Sjmcneill EOWRITE4(sc, EHCI_USBINTR, 0); 941.1Sjmcneill 951.1Sjmcneill out32(USB_CHICKENBITS, in32(USB_CHICKENBITS) | EHCI_INTR_ENABLE); 961.1Sjmcneill 971.1Sjmcneill error = ehci_init(sc); 981.1Sjmcneill if (error != 0) { 991.1Sjmcneill aprint_error_dev(self, "init failed, error = %d\n", error); 1001.1Sjmcneill return; 1011.1Sjmcneill } 1021.1Sjmcneill 1031.1Sjmcneill ahb_intr_establish(aaa->aaa_irq, IPL_USB, ehci_intr, sc, 1041.1Sjmcneill device_xname(self)); 1051.1Sjmcneill 1061.1Sjmcneill sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, 1071.1Sjmcneill CFARGS_NONE); 1081.1Sjmcneill} 109