ehci-ps3.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev)
  63. {
  64. int result;
  65. struct usb_hcd *hcd;
  66. unsigned int virq;
  67. static u64 dummy_mask = DMA_32BIT_MASK;
  68. if (usb_disabled()) {
  69. result = -ENODEV;
  70. goto fail_start;
  71. }
  72. result = ps3_mmio_region_create(dev->m_region);
  73. if (result) {
  74. dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
  75. __func__, __LINE__);
  76. result = -EPERM;
  77. goto fail_mmio;
  78. }
  79. dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
  80. __LINE__, dev->m_region->lpar_addr);
  81. result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
  82. if (result) {
  83. dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
  84. __func__, __LINE__, virq);
  85. result = -EPERM;
  86. goto fail_irq;
  87. }
  88. dev->core.power.power_state = PMSG_ON;
  89. dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
  90. hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id);
  91. if (!hcd) {
  92. dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
  93. __LINE__);
  94. result = -ENOMEM;
  95. goto fail_create_hcd;
  96. }
  97. hcd->rsrc_start = dev->m_region->lpar_addr;
  98. hcd->rsrc_len = dev->m_region->len;
  99. hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
  100. if (!hcd->regs) {
  101. dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
  102. __LINE__);
  103. result = -EPERM;
  104. goto fail_ioremap;
  105. }
  106. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
  107. (unsigned long)hcd->rsrc_start);
  108. dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
  109. (unsigned long)hcd->rsrc_len);
  110. dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
  111. (unsigned long)hcd->regs);
  112. dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
  113. (unsigned long)virq);
  114. ps3_system_bus_set_driver_data(dev, hcd);
  115. result = usb_add_hcd(hcd, virq, IRQF_DISABLED);
  116. if (result) {
  117. dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
  118. __func__, __LINE__, result);
  119. goto fail_add_hcd;
  120. }
  121. return result;
  122. fail_add_hcd:
  123. iounmap(hcd->regs);
  124. fail_ioremap:
  125. usb_put_hcd(hcd);
  126. fail_create_hcd:
  127. ps3_io_irq_destroy(virq);
  128. fail_irq:
  129. ps3_free_mmio_region(dev->m_region);
  130. fail_mmio:
  131. fail_start:
  132. return result;
  133. }
  134. static int ps3_ehci_sb_remove(struct ps3_system_bus_device *dev)
  135. {
  136. struct usb_hcd *hcd =
  137. (struct usb_hcd *)ps3_system_bus_get_driver_data(dev);
  138. usb_put_hcd(hcd);
  139. ps3_system_bus_set_driver_data(dev, NULL);
  140. return 0;
  141. }
  142. MODULE_ALIAS("ps3-ehci");
  143. static struct ps3_system_bus_driver ps3_ehci_sb_driver = {
  144. .match_id = PS3_MATCH_ID_EHCI,
  145. .core = {
  146. .name = "ps3-ehci-driver",
  147. },
  148. .probe = ps3_ehci_sb_probe,
  149. .remove = ps3_ehci_sb_remove,
  150. };