ehci-ps3.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
  50. &ehci->caps->hc_capbase));
  51. dbg_hcs_params(ehci, "reset");
  52. dbg_hcc_params(ehci, "reset");
  53. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  54. result = ehci_halt(ehci);
  55. if (result)
  56. return result;
  57. result = ehci_init(hcd);
  58. if (result)
  59. return result;
  60. ehci_reset(ehci);
  61. ps3_ehci_setup_insnreg(ehci);
  62. return result;
  63. }
  64. static const struct hc_driver ps3_ehci_hc_driver = {
  65. .description = hcd_name,
  66. .product_desc = "PS3 EHCI Host Controller",
  67. .hcd_priv_size = sizeof(struct ehci_hcd),
  68. .irq = ehci_irq,
  69. .flags = HCD_MEMORY | HCD_USB2,
  70. .reset = ps3_ehci_hc_reset,
  71. .start = ehci_run,
  72. .stop = ehci_stop,
  73. .shutdown = ehci_shutdown,
  74. .urb_enqueue = ehci_urb_enqueue,
  75. .urb_dequeue = ehci_urb_dequeue,
  76. .endpoint_disable = ehci_endpoint_disable,
  77. .endpoint_reset = ehci_endpoint_reset,
  78. .get_frame_number = ehci_get_frame,
  79. .hub_status_data = ehci_hub_status_data,
  80. .hub_control = ehci_hub_control,
  81. #if defined(CONFIG_PM)
  82. .bus_suspend = ehci_bus_suspend,
  83. .bus_resume = ehci_bus_resume,
  84. #endif
  85. .relinquish_port = ehci_relinquish_port,
  86. .port_handed_over = ehci_port_handed_over,
  87. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  88. };
  89. static int __devinit ps3_ehci_probe(struct ps3_system_bus_device *dev)
  90. {
  91. int result;
  92. struct usb_hcd *hcd;
  93. unsigned int virq;
  94. static u64 dummy_mask = DMA_BIT_MASK(32);
  95. if (usb_disabled()) {
  96. result = -ENODEV;
  97. goto fail_start;
  98. }
  99. result = ps3_open_hv_device(dev);
  100. if (result) {
  101. dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n",
  102. __func__, __LINE__);
  103. goto fail_open;
  104. }
  105. result = ps3_dma_region_create(dev->d_region);
  106. if (result) {
  107. dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
  108. "(%d)\n", __func__, __LINE__, result);
  109. BUG_ON("check region type");
  110. goto fail_dma_region;
  111. }
  112. result = ps3_mmio_region_create(dev->m_region);
  113. if (result) {
  114. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  115. __func__, __LINE__);
  116. result = -EPERM;
  117. goto fail_mmio_region;
  118. }
  119. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  120. __LINE__, dev->m_region->lpar_addr);
  121. result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  122. if (result) {
  123. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  124. __func__, __LINE__, virq);
  125. result = -EPERM;
  126. goto fail_irq;
  127. }
  128. dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
  129. hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core));
  130. if (!hcd) {
  131. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  132. __LINE__);
  133. result = -ENOMEM;
  134. goto fail_create_hcd;
  135. }
  136. hcd->rsrc_start = dev->m_region->lpar_addr;
  137. hcd->rsrc_len = dev->m_region->len;
  138. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
  139. dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
  140. __func__, __LINE__);
  141. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  142. if (!hcd->regs) {
  143. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  144. __LINE__);
  145. result = -EPERM;
  146. goto fail_ioremap;
  147. }
  148. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  149. (unsigned long)hcd->rsrc_start);
  150. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  151. (unsigned long)hcd->rsrc_len);
  152. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  153. (unsigned long)hcd->regs);
  154. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  155. (unsigned long)virq);
  156. ps3_system_bus_set_drvdata(dev, hcd);
  157. result = usb_add_hcd(hcd, virq, 0);
  158. if (result) {
  159. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  160. __func__, __LINE__, result);
  161. goto fail_add_hcd;
  162. }
  163. return result;
  164. fail_add_hcd:
  165. iounmap(hcd->regs);
  166. fail_ioremap:
  167. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  168. usb_put_hcd(hcd);
  169. fail_create_hcd:
  170. ps3_io_irq_destroy(virq);
  171. fail_irq:
  172. ps3_free_mmio_region(dev->m_region);
  173. fail_mmio_region:
  174. ps3_dma_region_free(dev->d_region);
  175. fail_dma_region:
  176. ps3_close_hv_device(dev);
  177. fail_open:
  178. fail_start:
  179. return result;
  180. }
  181. static int ps3_ehci_remove(struct ps3_system_bus_device *dev)
  182. {
  183. unsigned int tmp;
  184. struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
  185. BUG_ON(!hcd);
  186. dev_dbg(&dev->core, "%s:%d: regs %pK\n", __func__, __LINE__, hcd->regs);
  187. dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
  188. tmp = hcd->irq;
  189. ehci_shutdown(hcd);
  190. usb_remove_hcd(hcd);
  191. ps3_system_bus_set_drvdata(dev, NULL);
  192. BUG_ON(!hcd->regs);
  193. iounmap(hcd->regs);
  194. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  195. usb_put_hcd(hcd);
  196. ps3_io_irq_destroy(tmp);
  197. ps3_free_mmio_region(dev->m_region);
  198. ps3_dma_region_free(dev->d_region);
  199. ps3_close_hv_device(dev);
  200. return 0;
  201. }
  202. static int __init ps3_ehci_driver_register(struct ps3_system_bus_driver *drv)
  203. {
  204. return firmware_has_feature(FW_FEATURE_PS3_LV1)
  205. ? ps3_system_bus_driver_register(drv)
  206. : 0;
  207. }
  208. static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv)
  209. {
  210. if (firmware_has_feature(FW_FEATURE_PS3_LV1))
  211. ps3_system_bus_driver_unregister(drv);
  212. }
  213. MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI);
  214. static struct ps3_system_bus_driver ps3_ehci_driver = {
  215. .core.name = "ps3-ehci-driver",
  216. .core.owner = THIS_MODULE,
  217. .match_id = PS3_MATCH_ID_EHCI,
  218. .probe = ps3_ehci_probe,
  219. .remove = ps3_ehci_remove,
  220. .shutdown = ps3_ehci_remove,
  221. };