Home | History | Annotate | Line # | Download | only in dev
ohci_plb.c revision 1.1
      1 /*	$NetBSD: ohci_plb.c,v 1.1 2026/06/14 00:02:35 rkujawa Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2026 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Radoslaw Kujawa.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * OHCI companion of on-chip EHCI
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: ohci_plb.c,v 1.1 2026/06/14 00:02:35 rkujawa Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/bus.h>
     40 #include <sys/device.h>
     41 #include <sys/extent.h>
     42 
     43 #include <powerpc/ibm4xx/cpu.h>
     44 #include <powerpc/ibm4xx/dev/plbvar.h>
     45 
     46 #include <dev/usb/usb.h>
     47 #include <dev/usb/usbdi.h>
     48 #include <dev/usb/usbdivar.h>
     49 #include <dev/usb/usb_mem.h>
     50 #include <dev/usb/ohcireg.h>
     51 #include <dev/usb/ohcivar.h>
     52 
     53 #define OHCI_PLB_SIZE	0x400	/* EHCI follows at +0x400 */
     54 
     55 #include "locators.h"
     56 
     57 static int	ohci_plb_match(device_t, cfdata_t, void *);
     58 static void	ohci_plb_attach(device_t, device_t, void *);
     59 
     60 CFATTACH_DECL_NEW(ohci_plb, sizeof(struct ohci_softc),
     61     ohci_plb_match, ohci_plb_attach, NULL, NULL);
     62 
     63 static struct powerpc_bus_space ohci_plb_tag = {
     64 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
     65 	0x00000000,
     66 };
     67 static char ohci_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
     68     __attribute__((aligned(8)));
     69 
     70 static int
     71 ohci_plb_match(device_t parent, cfdata_t match, void *aux)
     72 {
     73 	struct plb_attach_args *paa = aux;
     74 
     75 	if (strcmp(paa->plb_name, match->cf_name) != 0)
     76 		return 0;
     77 
     78 	if (match->cf_loc[PLBCF_ADDR] == PLBCF_ADDR_DEFAULT)
     79 		panic("ohci_plb_match: wildcard addr not allowed");
     80 	if (match->cf_loc[PLBCF_IRQ] == PLBCF_IRQ_DEFAULT)
     81 		panic("ohci_plb_match: wildcard IRQ not allowed");
     82 
     83 	paa->plb_addr = match->cf_loc[PLBCF_ADDR];
     84 	paa->plb_irq = match->cf_loc[PLBCF_IRQ];
     85 	return 1;
     86 }
     87 
     88 static void
     89 ohci_plb_attach(device_t parent, device_t self, void *aux)
     90 {
     91 	struct ohci_softc *sc = device_private(self);
     92 	struct plb_attach_args *paa = aux;
     93 	int error;
     94 
     95 	sc->sc_dev = self;
     96 	sc->sc_bus.ub_hcpriv = sc;
     97 	sc->sc_bus.ub_dmatag = paa->plb_dmat;
     98 	sc->sc_bus.ub_revision = USBREV_1_0;
     99 
    100 	ohci_plb_tag.pbs_base = paa->plb_addr;
    101 	ohci_plb_tag.pbs_limit = paa->plb_addr + OHCI_PLB_SIZE;
    102 	sc->iot = &ohci_plb_tag;
    103 
    104 	if (bus_space_init(&ohci_plb_tag, "ohciplb", ohci_ex_storage,
    105 	      sizeof(ohci_ex_storage)) ||
    106 	    bus_space_map(sc->iot, paa->plb_addr, OHCI_PLB_SIZE, 0,
    107 	      &sc->ioh)) {
    108 		aprint_error(": can't map registers\n");
    109 		return;
    110 	}
    111 	sc->sc_size = OHCI_PLB_SIZE;
    112 
    113 	aprint_normal(": OHCI USB controller\n");
    114 
    115 	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
    116 	    OHCI_ALL_INTRS);
    117 
    118 	intr_establish_xname(paa->plb_irq, IST_LEVEL, IPL_USB, ohci_intr,
    119 	    sc, device_xname(self));
    120 
    121 	error = ohci_init(sc);
    122 	if (error) {
    123 		aprint_error_dev(self, "init failed, error=%d\n", error);
    124 		return;
    125 	}
    126 
    127 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint,
    128 	    CFARGS_NONE);
    129 }
    130