ohci-ps3.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * PS3 OHCI 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_ohci_hc_reset(struct usb_hcd *hcd)
  23. {
  24. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  25. ohci->flags |= OHCI_QUIRK_BE_MMIO;
  26. ohci_hcd_init(ohci);
  27. return ohci_init(ohci);
  28. }
  29. static int ps3_ohci_hc_start(struct usb_hcd *hcd)
  30. {
  31. int result;
  32. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  33. /* Handle root hub init quirk in spider south bridge. */
  34. /* Also set PwrOn2PwrGood to 0x7f (254ms). */
  35. ohci_writel(ohci, 0x7f000000 | RH_A_PSM | RH_A_OCPM,
  36. &ohci->regs->roothub.a);
  37. ohci_writel(ohci, 0x00060000, &ohci->regs->roothub.b);
  38. result = ohci_run(ohci);
  39. if (result < 0) {
  40. dev_err(hcd->self.controller, "can't start %s\n",
  41. hcd->self.bus_name);
  42. ohci_stop(hcd);
  43. }
  44. return result;
  45. }
  46. static const struct hc_driver ps3_ohci_hc_driver = {
  47. .description = hcd_name,
  48. .product_desc = "PS3 OHCI Host Controller",
  49. .hcd_priv_size = sizeof(struct ohci_hcd),
  50. .irq = ohci_irq,
  51. .flags = HCD_MEMORY | HCD_USB11,
  52. .reset = ps3_ohci_hc_reset,
  53. .start = ps3_ohci_hc_start,
  54. .stop = ohci_stop,
  55. .shutdown = ohci_shutdown,
  56. .urb_enqueue = ohci_urb_enqueue,
  57. .urb_dequeue = ohci_urb_dequeue,
  58. .endpoint_disable = ohci_endpoint_disable,
  59. .get_frame_number = ohci_get_frame,
  60. .hub_status_data = ohci_hub_status_data,
  61. .hub_control = ohci_hub_control,
  62. .start_port_reset = ohci_start_port_reset,
  63. #if defined(CONFIG_PM)
  64. .bus_suspend = ohci_bus_suspend,
  65. .bus_resume = ohci_bus_resume,
  66. #endif
  67. };
  68. static int ps3_ohci_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 = DMA_BIT_MASK(32);
  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: %s\n",
  81. __func__, __LINE__, ps3_result(result));
  82. result = -EPERM;
  83. goto fail_open;
  84. }
  85. result = ps3_dma_region_create(dev->d_region);
  86. if (result) {
  87. dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
  88. "(%d)\n", __func__, __LINE__, result);
  89. BUG_ON("check region type");
  90. goto fail_dma_region;
  91. }
  92. result = ps3_mmio_region_create(dev->m_region);
  93. if (result) {
  94. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  95. __func__, __LINE__);
  96. result = -EPERM;
  97. goto fail_mmio_region;
  98. }
  99. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  100. __LINE__, dev->m_region->lpar_addr);
  101. result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  102. if (result) {
  103. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  104. __func__, __LINE__, virq);
  105. result = -EPERM;
  106. goto fail_irq;
  107. }
  108. dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
  109. hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev_name(&dev->core));
  110. if (!hcd) {
  111. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  112. __LINE__);
  113. result = -ENOMEM;
  114. goto fail_create_hcd;
  115. }
  116. hcd->rsrc_start = dev->m_region->lpar_addr;
  117. hcd->rsrc_len = dev->m_region->len;
  118. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
  119. dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
  120. __func__, __LINE__);
  121. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  122. if (!hcd->regs) {
  123. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  124. __LINE__);
  125. result = -EPERM;
  126. goto fail_ioremap;
  127. }
  128. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  129. (unsigned long)hcd->rsrc_start);
  130. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  131. (unsigned long)hcd->rsrc_len);
  132. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  133. (unsigned long)hcd->regs);
  134. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  135. (unsigned long)virq);
  136. ps3_system_bus_set_drvdata(dev, hcd);
  137. result = usb_add_hcd(hcd, virq, 0);
  138. if (result) {
  139. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  140. __func__, __LINE__, result);
  141. goto fail_add_hcd;
  142. }
  143. device_wakeup_enable(hcd->self.controller);
  144. return result;
  145. fail_add_hcd:
  146. iounmap(hcd->regs);
  147. fail_ioremap:
  148. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  149. usb_put_hcd(hcd);
  150. fail_create_hcd:
  151. ps3_io_irq_destroy(virq);
  152. fail_irq:
  153. ps3_free_mmio_region(dev->m_region);
  154. fail_mmio_region:
  155. ps3_dma_region_free(dev->d_region);
  156. fail_dma_region:
  157. ps3_close_hv_device(dev);
  158. fail_open:
  159. fail_start:
  160. return result;
  161. }
  162. static int ps3_ohci_remove(struct ps3_system_bus_device *dev)
  163. {
  164. unsigned int tmp;
  165. struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
  166. BUG_ON(!hcd);
  167. dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
  168. dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
  169. tmp = hcd->irq;
  170. ohci_shutdown(hcd);
  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_ohci_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_ohci_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_OHCI);
  195. static struct ps3_system_bus_driver ps3_ohci_driver = {
  196. .core.name = "ps3-ohci-driver",
  197. .core.owner = THIS_MODULE,
  198. .match_id = PS3_MATCH_ID_OHCI,
  199. .probe = ps3_ohci_probe,
  200. .remove = ps3_ohci_remove,
  201. .shutdown = ps3_ohci_remove,
  202. };