1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (C) 2010 Nathan Whitehorn 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 TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 #include <sys/stdint.h> 34 #include <sys/stddef.h> 35 #include <sys/param.h> 36 #include <sys/queue.h> 37 #include <sys/types.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/bus.h> 41 #include <sys/linker_set.h> 42 #include <sys/module.h> 43 #include <sys/lock.h> 44 #include <sys/mutex.h> 45 #include <sys/condvar.h> 46 #include <sys/sysctl.h> 47 #include <sys/sx.h> 48 #include <sys/unistd.h> 49 #include <sys/callout.h> 50 #include <sys/malloc.h> 51 #include <sys/priv.h> 52 53 #include <sys/rman.h> 54 55 #include <dev/usb/usb.h> 56 #include <dev/usb/usbdi.h> 57 58 #include <dev/usb/usb_core.h> 59 #include <dev/usb/usb_busdma.h> 60 #include <dev/usb/usb_process.h> 61 #include <dev/usb/usb_util.h> 62 63 #include <dev/usb/usb_controller.h> 64 #include <dev/usb/usb_bus.h> 65 #include <dev/usb/controller/ohci.h> 66 #include <dev/usb/controller/ohcireg.h> 67 68 #include "ps3bus.h" 69 70 static int 71 ohci_ps3_probe(device_t dev) 72 { 73 if (ps3bus_get_bustype(dev) != PS3_BUSTYPE_SYSBUS || 74 ps3bus_get_devtype(dev) != PS3_DEVTYPE_USB) 75 return (ENXIO); 76 77 device_set_desc(dev, "Playstation 3 USB 2.0 controller"); 78 return (BUS_PROBE_SPECIFIC); 79 } 80 81 static int 82 ohci_ps3_attach(device_t dev) 83 { 84 ohci_softc_t *sc = device_get_softc(dev); 85 int rid, err; 86 87 sc->sc_bus.parent = dev; 88 sc->sc_bus.devices = sc->sc_devices; 89 sc->sc_bus.devices_max = OHCI_MAX_DEVICES; 90 sc->sc_bus.dma_bits = 32; 91 92 /* get all DMA memory */ 93 if (usb_bus_mem_alloc_all(&sc->sc_bus, 94 USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc)) 95 return (ENOMEM); 96 97 rid = 0; 98 sc->sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 99 &rid, RF_ACTIVE); 100 101 if (!sc->sc_io_res) { 102 device_printf(dev, "Could not map memory\n"); 103 goto error; 104 } 105 106 sc->sc_io_tag = rman_get_bustag(sc->sc_io_res); 107 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); 108 sc->sc_io_size = rman_get_size(sc->sc_io_res); 109 110 rid = 0; 111 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 112 RF_SHAREABLE | RF_ACTIVE); 113 114 if (sc->sc_irq_res == NULL) { 115 device_printf(dev, "Could not allocate irq\n"); 116 return (ENXIO); 117 } 118 119 sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); 120 if (!sc->sc_bus.bdev) { 121 device_printf(dev, "Could not add USB device\n"); 122 return (ENXIO); 123 } 124 125 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 126 127 sprintf(sc->sc_vendor, "Sony"); 128 129 err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, 130 NULL, (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl); 131 if (err) { 132 device_printf(dev, "Could not setup error irq, %d\n", err); 133 goto error; 134 } 135 136 //sc->sc_flags |= EHCI_SCFLG_BIGEMMIO; 137 bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl, 138 OHCI_CONTROL, 0); 139 err = ohci_init(sc); 140 if (err) { 141 device_printf(dev, "USB init failed err=%d\n", err); 142 goto error; 143 } 144 145 err = device_probe_and_attach(sc->sc_bus.bdev); 146 if (err == 0) 147 return (0); 148 149 error: 150 return (ENXIO); 151 } 152 153 static device_method_t ohci_ps3_methods[] = { 154 /* Device interface */ 155 DEVMETHOD(device_probe, ohci_ps3_probe), 156 DEVMETHOD(device_attach, ohci_ps3_attach), 157 DEVMETHOD(device_resume, bus_generic_resume), 158 DEVMETHOD(device_suspend, bus_generic_suspend), 159 DEVMETHOD(device_shutdown, bus_generic_shutdown), 160 161 DEVMETHOD_END 162 }; 163 164 static driver_t ohci_ps3_driver = { 165 .name = "ohci", 166 .methods = ohci_ps3_methods, 167 .size = sizeof(ohci_softc_t), 168 }; 169 170 static devclass_t ohci_ps3_devclass; 171 172 DRIVER_MODULE(ohci_ps3, ps3bus, ohci_ps3_driver, ohci_ps3_devclass, 0, 0); 173 MODULE_DEPEND(ohci_ps3, usb, 1, 1, 1); 174