ehci-ps3.c 6.8 KB

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