ehci-ps3.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PS3 EHCI Host Controller driver
  4. *
  5. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  6. * Copyright 2006 Sony Corp.
  7. */
  8. #include <asm/firmware.h>
  9. #include <asm/ps3.h>
  10. static void ps3_ehci_setup_insnreg(struct ehci_hcd *ehci)
  11. {
  12. /* PS3 HC internal setup register offsets. */
  13. enum ps3_ehci_hc_insnreg {
  14. ps3_ehci_hc_insnreg01 = 0x084,
  15. ps3_ehci_hc_insnreg02 = 0x088,
  16. ps3_ehci_hc_insnreg03 = 0x08c,
  17. };
  18. /* PS3 EHCI HC errata fix 316 - The PS3 EHCI HC will reset its
  19. * internal INSNREGXX setup regs back to the chip default values
  20. * on Host Controller Reset (CMD_RESET) or Light Host Controller
  21. * Reset (CMD_LRESET). The work-around for this is for the HC
  22. * driver to re-initialise these regs when ever the HC is reset.
  23. */
  24. /* Set burst transfer counts to 256 out, 32 in. */
  25. writel_be(0x01000020, (void __iomem *)ehci->regs +
  26. ps3_ehci_hc_insnreg01);
  27. /* Enable burst transfer counts. */
  28. writel_be(0x00000001, (void __iomem *)ehci->regs +
  29. ps3_ehci_hc_insnreg03);
  30. }
  31. static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
  32. {
  33. int result;
  34. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  35. ehci->big_endian_mmio = 1;
  36. ehci->caps = hcd->regs;
  37. result = ehci_setup(hcd);
  38. if (result)
  39. return result;
  40. ps3_ehci_setup_insnreg(ehci);
  41. return result;
  42. }
  43. static const struct hc_driver ps3_ehci_hc_driver = {
  44. .description = hcd_name,
  45. .product_desc = "PS3 EHCI Host Controller",
  46. .hcd_priv_size = sizeof(struct ehci_hcd),
  47. .irq = ehci_irq,
  48. .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
  49. .reset = ps3_ehci_hc_reset,
  50. .start = ehci_run,
  51. .stop = ehci_stop,
  52. .shutdown = ehci_shutdown,
  53. .urb_enqueue = ehci_urb_enqueue,
  54. .urb_dequeue = ehci_urb_dequeue,
  55. .endpoint_disable = ehci_endpoint_disable,
  56. .endpoint_reset = ehci_endpoint_reset,
  57. .get_frame_number = ehci_get_frame,
  58. .hub_status_data = ehci_hub_status_data,
  59. .hub_control = ehci_hub_control,
  60. #if defined(CONFIG_PM)
  61. .bus_suspend = ehci_bus_suspend,
  62. .bus_resume = ehci_bus_resume,
  63. #endif
  64. .relinquish_port = ehci_relinquish_port,
  65. .port_handed_over = ehci_port_handed_over,
  66. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  67. };
  68. static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
  69. {
  70. int result;
  71. struct usb_hcd *hcd;
  72. unsigned int virq;
  73. static u64 dummy_mask;
  74. if (usb_disabled()) {
  75. result = -ENODEV;
  76. goto fail_start;
  77. }
  78. result = ps3_open_hv_device(dev);
  79. if (result) {
  80. dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n",
  81. __func__, __LINE__);
  82. goto fail_open;
  83. }
  84. result = ps3_dma_region_create(dev->d_region);
  85. if (result) {
  86. dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
  87. "(%d)\n", __func__, __LINE__, result);
  88. BUG_ON("check region type");
  89. goto fail_dma_region;
  90. }
  91. result = ps3_mmio_region_create(dev->m_region);
  92. if (result) {
  93. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  94. __func__, __LINE__);
  95. result = -EPERM;
  96. goto fail_mmio_region;
  97. }
  98. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  99. __LINE__, dev->m_region->lpar_addr);
  100. result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  101. if (result) {
  102. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  103. __func__, __LINE__, virq);
  104. result = -EPERM;
  105. goto fail_irq;
  106. }
  107. dummy_mask = DMA_BIT_MASK(32);
  108. dev->core.dma_mask = &dummy_mask;
  109. dma_set_coherent_mask(&dev->core, dummy_mask);
  110. hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core));
  111. if (!hcd) {
  112. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  113. __LINE__);
  114. result = -ENOMEM;
  115. goto fail_create_hcd;
  116. }
  117. hcd->rsrc_start = dev->m_region->lpar_addr;
  118. hcd->rsrc_len = dev->m_region->len;
  119. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
  120. dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
  121. __func__, __LINE__);
  122. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  123. if (!hcd->regs) {
  124. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  125. __LINE__);
  126. result = -EPERM;
  127. goto fail_ioremap;
  128. }
  129. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  130. (unsigned long)hcd->rsrc_start);
  131. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  132. (unsigned long)hcd->rsrc_len);
  133. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  134. (unsigned long)hcd->regs);
  135. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  136. (unsigned long)virq);
  137. ps3_system_bus_set_drvdata(dev, hcd);
  138. result = usb_add_hcd(hcd, virq, 0);
  139. if (result) {
  140. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  141. __func__, __LINE__, result);
  142. goto fail_add_hcd;
  143. }
  144. device_wakeup_enable(hcd->self.controller);
  145. return result;
  146. fail_add_hcd:
  147. iounmap(hcd->regs);
  148. fail_ioremap:
  149. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  150. usb_put_hcd(hcd);
  151. fail_create_hcd:
  152. ps3_io_irq_destroy(virq);
  153. fail_irq:
  154. ps3_free_mmio_region(dev->m_region);
  155. fail_mmio_region:
  156. ps3_dma_region_free(dev->d_region);
  157. fail_dma_region:
  158. ps3_close_hv_device(dev);
  159. fail_open:
  160. fail_start:
  161. return result;
  162. }
  163. static int ps3_ehci_remove(struct ps3_system_bus_device *dev)
  164. {
  165. unsigned int tmp;
  166. struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
  167. BUG_ON(!hcd);
  168. dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
  169. dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
  170. tmp = hcd->irq;
  171. usb_remove_hcd(hcd);
  172. ps3_system_bus_set_drvdata(dev, NULL);
  173. BUG_ON(!hcd->regs);
  174. iounmap(hcd->regs);
  175. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  176. usb_put_hcd(hcd);
  177. ps3_io_irq_destroy(tmp);
  178. ps3_free_mmio_region(dev->m_region);
  179. ps3_dma_region_free(dev->d_region);
  180. ps3_close_hv_device(dev);
  181. return 0;
  182. }
  183. static int __init ps3_ehci_driver_register(struct ps3_system_bus_driver *drv)
  184. {
  185. return firmware_has_feature(FW_FEATURE_PS3_LV1)
  186. ? ps3_system_bus_driver_register(drv)
  187. : 0;
  188. }
  189. static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv)
  190. {
  191. if (firmware_has_feature(FW_FEATURE_PS3_LV1))
  192. ps3_system_bus_driver_unregister(drv);
  193. }
  194. MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI);
  195. static struct ps3_system_bus_driver ps3_ehci_driver = {
  196. .core.name = "ps3-ehci-driver",
  197. .core.owner = THIS_MODULE,
  198. .match_id = PS3_MATCH_ID_EHCI,
  199. .probe = ps3_ehci_probe,
  200. .remove = ps3_ehci_remove,
  201. .shutdown = ps3_ehci_remove,
  202. };