ohci_ps3.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include <sys/cdefs.h>
  30. __FBSDID("$FreeBSD$");
  31. #include <sys/stdint.h>
  32. #include <sys/stddef.h>
  33. #include <sys/param.h>
  34. #include <sys/queue.h>
  35. #include <sys/types.h>
  36. #include <sys/systm.h>
  37. #include <sys/kernel.h>
  38. #include <sys/bus.h>
  39. #include <sys/linker_set.h>
  40. #include <sys/module.h>
  41. #include <sys/lock.h>
  42. #include <sys/mutex.h>
  43. #include <sys/condvar.h>
  44. #include <sys/sysctl.h>
  45. #include <sys/sx.h>
  46. #include <sys/unistd.h>
  47. #include <sys/callout.h>
  48. #include <sys/malloc.h>
  49. #include <sys/priv.h>
  50. #include <sys/rman.h>
  51. #include <dev/usb/usb.h>
  52. #include <dev/usb/usbdi.h>
  53. #include <dev/usb/usb_core.h>
  54. #include <dev/usb/usb_busdma.h>
  55. #include <dev/usb/usb_process.h>
  56. #include <dev/usb/usb_util.h>
  57. #include <dev/usb/usb_controller.h>
  58. #include <dev/usb/usb_bus.h>
  59. #include <dev/usb/controller/ohci.h>
  60. #include <dev/usb/controller/ohcireg.h>
  61. #include "ps3bus.h"
  62. static int
  63. ohci_ps3_probe(device_t dev)
  64. {
  65. if (ps3bus_get_bustype(dev) != PS3_BUSTYPE_SYSBUS ||
  66. ps3bus_get_devtype(dev) != PS3_DEVTYPE_USB)
  67. return (ENXIO);
  68. device_set_desc(dev, "Playstation 3 USB 2.0 controller");
  69. return (BUS_PROBE_SPECIFIC);
  70. }
  71. static int
  72. ohci_ps3_attach(device_t dev)
  73. {
  74. ohci_softc_t *sc = device_get_softc(dev);
  75. int rid, err;
  76. sc->sc_bus.parent = dev;
  77. sc->sc_bus.devices = sc->sc_devices;
  78. sc->sc_bus.devices_max = OHCI_MAX_DEVICES;
  79. sc->sc_bus.dma_bits = 32;
  80. /* get all DMA memory */
  81. if (usb_bus_mem_alloc_all(&sc->sc_bus,
  82. USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc))
  83. return (ENOMEM);
  84. rid = 0;
  85. sc->sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
  86. &rid, RF_ACTIVE);
  87. if (!sc->sc_io_res) {
  88. device_printf(dev, "Could not map memory\n");
  89. goto error;
  90. }
  91. sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
  92. sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
  93. sc->sc_io_size = rman_get_size(sc->sc_io_res);
  94. rid = 0;
  95. sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
  96. RF_SHAREABLE | RF_ACTIVE);
  97. if (sc->sc_irq_res == NULL) {
  98. device_printf(dev, "Could not allocate irq\n");
  99. return (ENXIO);
  100. }
  101. sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
  102. if (!sc->sc_bus.bdev) {
  103. device_printf(dev, "Could not add USB device\n");
  104. return (ENXIO);
  105. }
  106. device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
  107. sprintf(sc->sc_vendor, "Sony");
  108. err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
  109. NULL, (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl);
  110. if (err) {
  111. device_printf(dev, "Could not setup error irq, %d\n", err);
  112. goto error;
  113. }
  114. //sc->sc_flags |= EHCI_SCFLG_BIGEMMIO;
  115. bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl,
  116. OHCI_CONTROL, 0);
  117. err = ohci_init(sc);
  118. if (err) {
  119. device_printf(dev, "USB init failed err=%d\n", err);
  120. goto error;
  121. }
  122. err = device_probe_and_attach(sc->sc_bus.bdev);
  123. if (err == 0)
  124. return (0);
  125. error:
  126. return (ENXIO);
  127. }
  128. static device_method_t ohci_ps3_methods[] = {
  129. /* Device interface */
  130. DEVMETHOD(device_probe, ohci_ps3_probe),
  131. DEVMETHOD(device_attach, ohci_ps3_attach),
  132. DEVMETHOD(device_resume, bus_generic_resume),
  133. DEVMETHOD(device_suspend, bus_generic_suspend),
  134. DEVMETHOD(device_shutdown, bus_generic_shutdown),
  135. DEVMETHOD_END
  136. };
  137. static driver_t ohci_ps3_driver = {
  138. .name = "ohci",
  139. .methods = ohci_ps3_methods,
  140. .size = sizeof(ohci_softc_t),
  141. };
  142. static devclass_t ohci_ps3_devclass;
  143. DRIVER_MODULE(ohci_ps3, ps3bus, ohci_ps3_driver, ohci_ps3_devclass, 0, 0);
  144. MODULE_DEPEND(ohci_ps3, usb, 1, 1, 1);