ehci-ps3.c 6.2 KB

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