ehci-ps3.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/ps3.h>
  21. static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
  22. {
  23. int result;
  24. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  25. ehci->big_endian_mmio = 1;
  26. ehci->caps = hcd->regs;
  27. ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci,
  28. &ehci->caps->hc_capbase));
  29. dbg_hcs_params(ehci, "reset");
  30. dbg_hcc_params(ehci, "reset");
  31. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  32. result = ehci_halt(ehci);
  33. if (result)
  34. return result;
  35. result = ehci_init(hcd);
  36. if (result)
  37. return result;
  38. ehci_port_power(ehci, 0);
  39. return result;
  40. }
  41. static const struct hc_driver ps3_ehci_hc_driver = {
  42. .description = hcd_name,
  43. .product_desc = "PS3 EHCI Host Controller",
  44. .hcd_priv_size = sizeof(struct ehci_hcd),
  45. .irq = ehci_irq,
  46. .flags = HCD_MEMORY | HCD_USB2,
  47. .reset = ps3_ehci_hc_reset,
  48. .start = ehci_run,
  49. .stop = ehci_stop,
  50. .shutdown = ehci_shutdown,
  51. .urb_enqueue = ehci_urb_enqueue,
  52. .urb_dequeue = ehci_urb_dequeue,
  53. .endpoint_disable = ehci_endpoint_disable,
  54. .get_frame_number = ehci_get_frame,
  55. .hub_status_data = ehci_hub_status_data,
  56. .hub_control = ehci_hub_control,
  57. #if defined(CONFIG_PM)
  58. .bus_suspend = ehci_bus_suspend,
  59. .bus_resume = ehci_bus_resume,
  60. #endif
  61. };
  62. #if !defined(DEBUG)
  63. #undef dev_dbg
  64. static inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
  65. const struct device *_dev, const char *fmt, ...) {return 0;}
  66. #endif
  67. static int ps3_ehci_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_alloc_io_irq(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_ehci_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_free_io_irq(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_ehci_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-ehci");
  148. static struct ps3_system_bus_driver ps3_ehci_sb_driver = {
  149. .match_id = PS3_MATCH_ID_EHCI,
  150. .core = {
  151. .name = "ps3-ehci-driver",
  152. },
  153. .probe = ps3_ehci_sb_probe,
  154. .remove = ps3_ehci_sb_remove,
  155. };