ehci-ath79.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Bus Glue for Atheros AR7XXX/AR9XXX built-in EHCI controller.
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * Parts of this file are based on Atheros' 2.6.15 BSP
  8. * Copyright (C) 2007 Atheros Communications, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/platform_device.h>
  15. enum {
  16. EHCI_ATH79_IP_V1 = 0,
  17. EHCI_ATH79_IP_V2,
  18. };
  19. static const struct platform_device_id ehci_ath79_id_table[] = {
  20. {
  21. .name = "ar71xx-ehci",
  22. .driver_data = EHCI_ATH79_IP_V1,
  23. },
  24. {
  25. .name = "ar724x-ehci",
  26. .driver_data = EHCI_ATH79_IP_V2,
  27. },
  28. {
  29. .name = "ar913x-ehci",
  30. .driver_data = EHCI_ATH79_IP_V2,
  31. },
  32. {
  33. .name = "ar933x-ehci",
  34. .driver_data = EHCI_ATH79_IP_V2,
  35. },
  36. {
  37. /* terminating entry */
  38. },
  39. };
  40. MODULE_DEVICE_TABLE(platform, ehci_ath79_id_table);
  41. static int ehci_ath79_init(struct usb_hcd *hcd)
  42. {
  43. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  44. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  45. const struct platform_device_id *id;
  46. int ret;
  47. id = platform_get_device_id(pdev);
  48. if (!id) {
  49. dev_err(hcd->self.controller, "missing device id\n");
  50. return -EINVAL;
  51. }
  52. switch (id->driver_data) {
  53. case EHCI_ATH79_IP_V1:
  54. ehci->has_synopsys_hc_bug = 1;
  55. ehci->caps = hcd->regs;
  56. ehci->regs = hcd->regs +
  57. HC_LENGTH(ehci,
  58. ehci_readl(ehci, &ehci->caps->hc_capbase));
  59. break;
  60. case EHCI_ATH79_IP_V2:
  61. hcd->has_tt = 1;
  62. ehci->caps = hcd->regs + 0x100;
  63. ehci->regs = hcd->regs + 0x100 +
  64. HC_LENGTH(ehci,
  65. ehci_readl(ehci, &ehci->caps->hc_capbase));
  66. break;
  67. default:
  68. BUG();
  69. }
  70. dbg_hcs_params(ehci, "reset");
  71. dbg_hcc_params(ehci, "reset");
  72. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  73. ehci->sbrn = 0x20;
  74. ehci_reset(ehci);
  75. ret = ehci_init(hcd);
  76. if (ret)
  77. return ret;
  78. ehci_port_power(ehci, 0);
  79. return 0;
  80. }
  81. static const struct hc_driver ehci_ath79_hc_driver = {
  82. .description = hcd_name,
  83. .product_desc = "Atheros built-in EHCI controller",
  84. .hcd_priv_size = sizeof(struct ehci_hcd),
  85. .irq = ehci_irq,
  86. .flags = HCD_MEMORY | HCD_USB2,
  87. .reset = ehci_ath79_init,
  88. .start = ehci_run,
  89. .stop = ehci_stop,
  90. .shutdown = ehci_shutdown,
  91. .urb_enqueue = ehci_urb_enqueue,
  92. .urb_dequeue = ehci_urb_dequeue,
  93. .endpoint_disable = ehci_endpoint_disable,
  94. .endpoint_reset = ehci_endpoint_reset,
  95. .get_frame_number = ehci_get_frame,
  96. .hub_status_data = ehci_hub_status_data,
  97. .hub_control = ehci_hub_control,
  98. .relinquish_port = ehci_relinquish_port,
  99. .port_handed_over = ehci_port_handed_over,
  100. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  101. };
  102. static int ehci_ath79_probe(struct platform_device *pdev)
  103. {
  104. struct usb_hcd *hcd;
  105. struct resource *res;
  106. int irq;
  107. int ret;
  108. if (usb_disabled())
  109. return -ENODEV;
  110. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  111. if (!res) {
  112. dev_dbg(&pdev->dev, "no IRQ specified\n");
  113. return -ENODEV;
  114. }
  115. irq = res->start;
  116. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  117. if (!res) {
  118. dev_dbg(&pdev->dev, "no base address specified\n");
  119. return -ENODEV;
  120. }
  121. hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev,
  122. dev_name(&pdev->dev));
  123. if (!hcd)
  124. return -ENOMEM;
  125. hcd->rsrc_start = res->start;
  126. hcd->rsrc_len = resource_size(res);
  127. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  128. dev_dbg(&pdev->dev, "controller already in use\n");
  129. ret = -EBUSY;
  130. goto err_put_hcd;
  131. }
  132. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  133. if (!hcd->regs) {
  134. dev_dbg(&pdev->dev, "error mapping memory\n");
  135. ret = -EFAULT;
  136. goto err_release_region;
  137. }
  138. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  139. if (ret)
  140. goto err_iounmap;
  141. return 0;
  142. err_iounmap:
  143. iounmap(hcd->regs);
  144. err_release_region:
  145. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  146. err_put_hcd:
  147. usb_put_hcd(hcd);
  148. return ret;
  149. }
  150. static int ehci_ath79_remove(struct platform_device *pdev)
  151. {
  152. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  153. usb_remove_hcd(hcd);
  154. iounmap(hcd->regs);
  155. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  156. usb_put_hcd(hcd);
  157. return 0;
  158. }
  159. static struct platform_driver ehci_ath79_driver = {
  160. .probe = ehci_ath79_probe,
  161. .remove = ehci_ath79_remove,
  162. .id_table = ehci_ath79_id_table,
  163. .driver = {
  164. .owner = THIS_MODULE,
  165. .name = "ath79-ehci",
  166. }
  167. };
  168. MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci");