ohci_hollywood.c revision 1.3
11.3Sjmcneill/* $NetBSD: ohci_hollywood.c,v 1.3 2024/09/22 13:56:25 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.3Sjmcneill__KERNEL_RCSID(0, "$NetBSD: ohci_hollywood.c,v 1.3 2024/09/22 13:56:25 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/ohcireg.h> 421.1Sjmcneill#include <dev/usb/ohcivar.h> 431.1Sjmcneill 441.1Sjmcneill#include <machine/wii.h> 451.1Sjmcneill#include <machine/pio.h> 461.1Sjmcneill#include "hollywood.h" 471.1Sjmcneill 481.1Sjmcneill#define USB_CHICKENBITS 0x0d0400cc 491.1Sjmcneill#define OHCI_INTR_ENABLE 0x000e1800 501.1Sjmcneill 511.1Sjmcneillextern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag; 521.1Sjmcneill 531.1Sjmcneillstatic int ohci_hollywood_match(device_t, cfdata_t, void *); 541.1Sjmcneillstatic void ohci_hollywood_attach(device_t, device_t, void *); 551.1Sjmcneill 561.1SjmcneillCFATTACH_DECL_NEW(ohci_hollywood, sizeof(struct ohci_softc), 571.1Sjmcneill ohci_hollywood_match, ohci_hollywood_attach, NULL, NULL); 581.1Sjmcneill 591.1Sjmcneillstatic int 601.1Sjmcneillohci_hollywood_match(device_t parent, cfdata_t cf, void *aux) 611.1Sjmcneill{ 621.1Sjmcneill return 1; 631.1Sjmcneill} 641.1Sjmcneill 651.1Sjmcneillstatic void 661.1Sjmcneillohci_hollywood_attach(device_t parent, device_t self, void *aux) 671.1Sjmcneill{ 681.1Sjmcneill struct hollywood_attach_args *haa = aux; 691.1Sjmcneill struct ohci_softc *sc = device_private(self); 701.1Sjmcneill int error; 711.1Sjmcneill 721.1Sjmcneill sc->sc_dev = self; 731.1Sjmcneill sc->sc_bus.ub_hcpriv = sc; 741.1Sjmcneill sc->sc_bus.ub_dmatag = &wii_mem2_bus_dma_tag; 751.1Sjmcneill sc->sc_flags = 0; 761.1Sjmcneill sc->sc_size = 0x200; 771.1Sjmcneill sc->iot = haa->haa_bst; 781.1Sjmcneill error = bus_space_map(sc->iot, haa->haa_addr, sc->sc_size, 0, &sc->ioh); 791.1Sjmcneill if (error != 0) { 801.1Sjmcneill aprint_error(": couldn't map registers (%d)\n", error); 811.1Sjmcneill return; 821.1Sjmcneill } 831.1Sjmcneill 841.1Sjmcneill aprint_naive("\n"); 851.1Sjmcneill aprint_normal(": OHCI\n"); 861.1Sjmcneill 871.3Sjmcneill hollywood_claim_device(self, 881.3Sjmcneill device_unit(self) == 0 ? IOPOH0EN : IOPOH1EN); 891.3Sjmcneill 901.1Sjmcneill bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 911.1Sjmcneill OHCI_ALL_INTRS); 921.1Sjmcneill 931.1Sjmcneill out32(USB_CHICKENBITS, in32(USB_CHICKENBITS) | OHCI_INTR_ENABLE); 941.1Sjmcneill 951.2Sjmcneill hollywood_intr_establish(haa->haa_irq, IPL_USB, ohci_intr, sc, 961.2Sjmcneill device_xname(self)); 971.1Sjmcneill 981.1Sjmcneill error = ohci_init(sc); 991.1Sjmcneill if (error != 0) { 1001.1Sjmcneill aprint_error_dev(self, "init failed, error = %d\n", error); 1011.1Sjmcneill return; 1021.1Sjmcneill } 1031.1Sjmcneill 1041.1Sjmcneill sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, 1051.1Sjmcneill CFARGS_NONE); 1061.1Sjmcneill} 107