ohci-ps3.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/ps3.h>
  21. static int ps3_ohci_hc_reset(struct usb_hcd *hcd)
  22. {
  23. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  24. ohci->flags |= OHCI_QUIRK_BE_MMIO;
  25. ohci_hcd_init(ohci);
  26. return ohci_init(ohci);
  27. }
  28. static int __devinit ps3_ohci_hc_start(struct usb_hcd *hcd)
  29. {
  30. int result;
  31. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  32. /* Handle root hub init quirk in spider south bridge. */
  33. /* Also set PwrOn2PwrGood to 0x7f (254ms). */
  34. ohci_writel(ohci, 0x7f000000 | RH_A_PSM | RH_A_OCPM,
  35. &ohci->regs->roothub.a);
  36. ohci_writel(ohci, 0x00060000, &ohci->regs->roothub.b);
  37. result = ohci_run(ohci);
  38. if (result < 0) {
  39. err("can't start %s", hcd->self.bus_name);
  40. ohci_stop(hcd);
  41. }
  42. return result;
  43. }
  44. static const struct hc_driver ps3_ohci_hc_driver = {
  45. .description = hcd_name,
  46. .product_desc = "PS3 OHCI Host Controller",
  47. .hcd_priv_size = sizeof(struct ohci_hcd),
  48. .irq = ohci_irq,
  49. .flags = HCD_MEMORY | HCD_USB11,
  50. .reset = ps3_ohci_hc_reset,
  51. .start = ps3_ohci_hc_start,
  52. .stop = ohci_stop,
  53. .shutdown = ohci_shutdown,
  54. .urb_enqueue = ohci_urb_enqueue,
  55. .urb_dequeue = ohci_urb_dequeue,
  56. .endpoint_disable = ohci_endpoint_disable,
  57. .get_frame_number = ohci_get_frame,
  58. .hub_status_data = ohci_hub_status_data,
  59. .hub_control = ohci_hub_control,
  60. .hub_irq_enable = ohci_rhsc_enable,
  61. .start_port_reset = ohci_start_port_reset,
  62. #if defined(CONFIG_PM)
  63. .bus_suspend = ohci_bus_suspend,
  64. .bus_resume = ohci_bus_resume,
  65. #endif
  66. };
  67. static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev)
  68. {
  69. int result;
  70. struct usb_hcd *hcd;
  71. unsigned int virq;
  72. static u64 dummy_mask = DMA_32BIT_MASK;
  73. if (usb_disabled()) {
  74. result = -ENODEV;
  75. goto fail_start;
  76. }
  77. result = ps3_mmio_region_create(dev->m_region);
  78. if (result) {
  79. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  80. __func__, __LINE__);
  81. result = -EPERM;
  82. goto fail_mmio;
  83. }
  84. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  85. __LINE__, dev->m_region->lpar_addr);
  86. result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  87. if (result) {
  88. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  89. __func__, __LINE__, virq);
  90. result = -EPERM;
  91. goto fail_irq;
  92. }
  93. dev->core.power.power_state = PMSG_ON;
  94. dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
  95. hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev->core.bus_id);
  96. if (!hcd) {
  97. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  98. __LINE__);
  99. result = -ENOMEM;
  100. goto fail_create_hcd;
  101. }
  102. hcd->rsrc_start = dev->m_region->lpar_addr;
  103. hcd->rsrc_len = dev->m_region->len;
  104. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  105. if (!hcd->regs) {
  106. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  107. __LINE__);
  108. result = -EPERM;
  109. goto fail_ioremap;
  110. }
  111. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  112. (unsigned long)hcd->rsrc_start);
  113. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  114. (unsigned long)hcd->rsrc_len);
  115. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  116. (unsigned long)hcd->regs);
  117. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  118. (unsigned long)virq);
  119. ps3_system_bus_set_driver_data(dev, hcd);
  120. result = usb_add_hcd(hcd, virq, IRQF_DISABLED);
  121. if (result) {
  122. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  123. __func__, __LINE__, result);
  124. goto fail_add_hcd;
  125. }
  126. return result;
  127. fail_add_hcd:
  128. iounmap(hcd->regs);
  129. fail_ioremap:
  130. usb_put_hcd(hcd);
  131. fail_create_hcd:
  132. ps3_io_irq_destroy(virq);
  133. fail_irq:
  134. ps3_free_mmio_region(dev->m_region);
  135. fail_mmio:
  136. fail_start:
  137. return result;
  138. }
  139. static int ps3_ohci_sb_remove (struct ps3_system_bus_device *dev)
  140. {
  141. struct usb_hcd *hcd =
  142. (struct usb_hcd *)ps3_system_bus_get_driver_data(dev);
  143. usb_put_hcd(hcd);
  144. ps3_system_bus_set_driver_data(dev, NULL);
  145. return 0;
  146. }
  147. MODULE_ALIAS("ps3-ohci");
  148. static struct ps3_system_bus_driver ps3_ohci_sb_driver = {
  149. .match_id = PS3_MATCH_ID_OHCI,
  150. .core = {
  151. .name = "ps3-ohci-driver",
  152. },
  153. .probe = ps3_ohci_sb_probe,
  154. .remove = ps3_ohci_sb_remove,
  155. };