1 /* $NetBSD: ohci_plb.c,v 1.2 2026/06/19 18:55:23 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.2 2026/06/19 18:55:23 rkujawa Exp $"); 37 38 #include "opt_ppc4xx.h" 39 40 #include <sys/param.h> 41 #include <sys/bus.h> 42 #include <sys/device.h> 43 #include <sys/extent.h> 44 45 #include <powerpc/ibm4xx/cpu.h> 46 #include <powerpc/ibm4xx/dev/plbvar.h> 47 #ifdef PPC4XX_L2CACHE 48 #include <powerpc/ibm4xx/ibm4xx_460ex_l2.h> 49 #endif 50 51 #include <dev/usb/usb.h> 52 #include <dev/usb/usbdi.h> 53 #include <dev/usb/usbdivar.h> 54 #include <dev/usb/usb_mem.h> 55 #include <dev/usb/ohcireg.h> 56 #include <dev/usb/ohcivar.h> 57 58 #define OHCI_PLB_SIZE 0x400 /* EHCI follows at +0x400 */ 59 60 #include "locators.h" 61 62 static int ohci_plb_match(device_t, cfdata_t, void *); 63 static void ohci_plb_attach(device_t, device_t, void *); 64 65 CFATTACH_DECL_NEW(ohci_plb, sizeof(struct ohci_softc), 66 ohci_plb_match, ohci_plb_attach, NULL, NULL); 67 68 static struct powerpc_bus_space ohci_plb_tag = { 69 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE, 70 0x00000000, 71 }; 72 static char ohci_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)] 73 __attribute__((aligned(8))); 74 75 static int 76 ohci_plb_match(device_t parent, cfdata_t match, void *aux) 77 { 78 struct plb_attach_args *paa = aux; 79 80 if (strcmp(paa->plb_name, match->cf_name) != 0) 81 return 0; 82 83 if (match->cf_loc[PLBCF_ADDR] == PLBCF_ADDR_DEFAULT) 84 panic("ohci_plb_match: wildcard addr not allowed"); 85 if (match->cf_loc[PLBCF_IRQ] == PLBCF_IRQ_DEFAULT) 86 panic("ohci_plb_match: wildcard IRQ not allowed"); 87 88 paa->plb_addr = match->cf_loc[PLBCF_ADDR]; 89 paa->plb_irq = match->cf_loc[PLBCF_IRQ]; 90 return 1; 91 } 92 93 static void 94 ohci_plb_attach(device_t parent, device_t self, void *aux) 95 { 96 struct ohci_softc *sc = device_private(self); 97 struct plb_attach_args *paa = aux; 98 int error; 99 100 sc->sc_dev = self; 101 sc->sc_bus.ub_hcpriv = sc; 102 #ifdef PPC4XX_L2CACHE 103 /* USB DMA needs software L2 invalidation (hardware snoop misses it). */ 104 sc->sc_bus.ub_dmatag = ibm4xx_460ex_l2_dmatag(); 105 #else 106 sc->sc_bus.ub_dmatag = paa->plb_dmat; 107 #endif 108 sc->sc_bus.ub_revision = USBREV_1_0; 109 110 ohci_plb_tag.pbs_base = paa->plb_addr; 111 ohci_plb_tag.pbs_limit = paa->plb_addr + OHCI_PLB_SIZE; 112 sc->iot = &ohci_plb_tag; 113 114 if (bus_space_init(&ohci_plb_tag, "ohciplb", ohci_ex_storage, 115 sizeof(ohci_ex_storage)) || 116 bus_space_map(sc->iot, paa->plb_addr, OHCI_PLB_SIZE, 0, 117 &sc->ioh)) { 118 aprint_error(": can't map registers\n"); 119 return; 120 } 121 sc->sc_size = OHCI_PLB_SIZE; 122 123 aprint_normal(": OHCI USB controller\n"); 124 125 bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE, 126 OHCI_ALL_INTRS); 127 128 intr_establish_xname(paa->plb_irq, IST_LEVEL, IPL_USB, ohci_intr, 129 sc, device_xname(self)); 130 131 error = ohci_init(sc); 132 if (error) { 133 aprint_error_dev(self, "init failed, error=%d\n", error); 134 return; 135 } 136 137 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, 138 CFARGS_NONE); 139 } 140