ohci-ps3.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. /* redefine dev_dbg to do a syntax check */
  68. #if !defined(DEBUG)
  69. #undef dev_dbg
  70. static inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
  71. const struct device *_dev, const char *fmt, ...) {return 0;}
  72. #endif
  73. static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev)
  74. {
  75. int result;
  76. struct usb_hcd *hcd;
  77. unsigned int virq;
  78. static u64 dummy_mask = DMA_32BIT_MASK;
  79. if (usb_disabled()) {
  80. result = -ENODEV;
  81. goto fail_start;
  82. }
  83. result = ps3_mmio_region_create(dev->m_region);
  84. if (result) {
  85. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  86. __func__, __LINE__);
  87. result = -EPERM;
  88. goto fail_mmio;
  89. }
  90. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  91. __LINE__, dev->m_region->lpar_addr);
  92. result = ps3_alloc_io_irq(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  93. if (result) {
  94. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  95. __func__, __LINE__, virq);
  96. result = -EPERM;
  97. goto fail_irq;
  98. }
  99. dev->core.power.power_state = PMSG_ON;
  100. dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
  101. hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev->core.bus_id);
  102. if (!hcd) {
  103. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  104. __LINE__);
  105. result = -ENOMEM;
  106. goto fail_create_hcd;
  107. }
  108. hcd->rsrc_start = dev->m_region->lpar_addr;
  109. hcd->rsrc_len = dev->m_region->len;
  110. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  111. if (!hcd->regs) {
  112. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  113. __LINE__);
  114. result = -EPERM;
  115. goto fail_ioremap;
  116. }
  117. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  118. (unsigned long)hcd->rsrc_start);
  119. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  120. (unsigned long)hcd->rsrc_len);
  121. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  122. (unsigned long)hcd->regs);
  123. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  124. (unsigned long)virq);
  125. ps3_system_bus_set_driver_data(dev, hcd);
  126. result = usb_add_hcd(hcd, virq, IRQF_DISABLED);
  127. if (result) {
  128. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  129. __func__, __LINE__, result);
  130. goto fail_add_hcd;
  131. }
  132. return result;
  133. fail_add_hcd:
  134. iounmap(hcd->regs);
  135. fail_ioremap:
  136. usb_put_hcd(hcd);
  137. fail_create_hcd:
  138. ps3_free_io_irq(virq);
  139. fail_irq:
  140. ps3_free_mmio_region(dev->m_region);
  141. fail_mmio:
  142. fail_start:
  143. return result;
  144. }
  145. static int ps3_ohci_sb_remove (struct ps3_system_bus_device *dev)
  146. {
  147. struct usb_hcd *hcd =
  148. (struct usb_hcd *)ps3_system_bus_get_driver_data(dev);
  149. usb_put_hcd(hcd);
  150. ps3_system_bus_set_driver_data(dev, NULL);
  151. return 0;
  152. }
  153. MODULE_ALIAS("ps3-ohci");
  154. static struct ps3_system_bus_driver ps3_ohci_sb_driver = {
  155. .match_id = PS3_MATCH_ID_OHCI,
  156. .core = {
  157. .name = "ps3-ohci-driver",
  158. },
  159. .probe = ps3_ohci_sb_probe,
  160. .remove = ps3_ohci_sb_remove,
  161. };