Home | History | Annotate | Line # | Download | only in dev
ehci_hollywood.c revision 1.3
      1 /* $NetBSD: ehci_hollywood.c,v 1.3 2024/09/22 13:56:25 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: ehci_hollywood.c,v 1.3 2024/09/22 13:56:25 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/ehcireg.h>
     42 #include <dev/usb/ehcivar.h>
     43 
     44 #include <machine/wii.h>
     45 #include "hollywood.h"
     46 
     47 extern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag;
     48 
     49 static int	ehci_hollywood_match(device_t, cfdata_t, void *);
     50 static void	ehci_hollywood_attach(device_t, device_t, void *);
     51 
     52 CFATTACH_DECL_NEW(ehci_hollywood, sizeof(struct ehci_softc),
     53 	ehci_hollywood_match, ehci_hollywood_attach, NULL, NULL);
     54 
     55 static int
     56 ehci_hollywood_match(device_t parent, cfdata_t cf, void *aux)
     57 {
     58 	return 1;
     59 }
     60 
     61 static void
     62 ehci_hollywood_attach(device_t parent, device_t self, void *aux)
     63 {
     64 	struct hollywood_attach_args *haa = aux;
     65 	struct ehci_softc *sc = device_private(self);
     66 	int error;
     67 
     68 	sc->sc_dev = self;
     69 	sc->sc_bus.ub_hcpriv = sc;
     70 	sc->sc_bus.ub_dmatag = &wii_mem2_bus_dma_tag;
     71 	sc->sc_bus.ub_revision = USBREV_2_0;
     72 	sc->sc_flags = EHCIF_32BIT_ACCESS;
     73 	sc->sc_ncomp = 2;
     74 	sc->sc_size = 0x100;
     75 	sc->iot = haa->haa_bst;
     76 	if (bus_space_map(sc->iot, haa->haa_addr, sc->sc_size, 0, &sc->ioh)) {
     77 		aprint_error(": couldn't map registers\n");
     78 		return;
     79 	}
     80 
     81 	aprint_naive("\n");
     82 	aprint_normal(": EHCI\n");
     83 
     84 	hollywood_claim_device(self, IOPEHCEN);
     85 
     86 	sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
     87 	EOWRITE4(sc, EHCI_USBINTR, 0);
     88 
     89 	hollywood_intr_establish(haa->haa_irq, IPL_USB, ehci_intr, sc,
     90 	    device_xname(self));
     91 
     92 	error = ehci_init(sc);
     93 	if (error != 0) {
     94 		aprint_error_dev(self, "init failed, error = %d\n", error);
     95 		return;
     96 	}
     97 
     98 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint,
     99 	    CFARGS_NONE);
    100 }
    101