Home | History | Annotate | Line # | Download | only in dev
      1 /* $NetBSD: ohci_ahb.c,v 1.1 2026/01/09 22:54:30 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2024 Jared McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: ohci_ahb.c,v 1.1 2026/01/09 22:54:30 jmcneill Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/systm.h>
     36 
     37 #include <dev/usb/usb.h>
     38 #include <dev/usb/usbdi.h>
     39 #include <dev/usb/usbdivar.h>
     40 #include <dev/usb/usb_mem.h>
     41 #include <dev/usb/ohcireg.h>
     42 #include <dev/usb/ohcivar.h>
     43 
     44 #include <machine/wii.h>
     45 #include <machine/wiiu.h>
     46 #include <machine/pio.h>
     47 #include "ahb.h"
     48 
     49 #define	USB_CHICKENBITS		0x0d0400cc
     50 #define	 OHCI_INTR_ENABLE	0x000e1800
     51 
     52 extern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag;
     53 
     54 static int	ohci_ahb_match(device_t, cfdata_t, void *);
     55 static void	ohci_ahb_attach(device_t, device_t, void *);
     56 
     57 CFATTACH_DECL_NEW(ohci_ahb, sizeof(struct ohci_softc),
     58 	ohci_ahb_match, ohci_ahb_attach, NULL, NULL);
     59 
     60 static int
     61 ohci_ahb_match(device_t parent, cfdata_t cf, void *aux)
     62 {
     63 	struct ahb_attach_args *aaa = aux;
     64 
     65 	return wiiu_native || aaa->aaa_irq < 32;
     66 }
     67 
     68 static void
     69 ohci_ahb_attach(device_t parent, device_t self, void *aux)
     70 {
     71 	struct ahb_attach_args *aaa = aux;
     72 	struct ohci_softc *sc = device_private(self);
     73 	int error;
     74 
     75 	sc->sc_dev = self;
     76 	sc->sc_bus.ub_hcpriv = sc;
     77 	sc->sc_bus.ub_dmatag = &wii_mem2_bus_dma_tag;
     78 	sc->sc_flags = 0;
     79 	sc->sc_size = 0x200;
     80 	sc->iot = aaa->aaa_bst;
     81 	error = bus_space_map(sc->iot, aaa->aaa_addr, sc->sc_size, 0, &sc->ioh);
     82 	if (error != 0) {
     83 		aprint_error(": couldn't map registers (%d)\n", error);
     84 		return;
     85 	}
     86 
     87 	aprint_naive("\n");
     88 	aprint_normal(": OHCI\n");
     89 
     90 	ahb_claim_device(self,
     91 	    device_unit(self) == 0 ? IOPOH0EN : IOPOH1EN);
     92 
     93 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
     94 	    OHCI_ALL_INTRS);
     95 
     96 	out32(USB_CHICKENBITS, in32(USB_CHICKENBITS) | OHCI_INTR_ENABLE);
     97 
     98 	error = ohci_init(sc);
     99 	if (error != 0) {
    100 		aprint_error_dev(self, "init failed, error = %d\n", error);
    101 		return;
    102 	}
    103 
    104 	ahb_intr_establish(aaa->aaa_irq, IPL_USB, ohci_intr, sc,
    105 	    device_xname(self));
    106 
    107 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint,
    108 	    CFARGS_NONE);
    109 }
    110