ehci-ath79.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /* terminating entry */
  34. },
  35. };
  36. MODULE_DEVICE_TABLE(platform, ehci_ath79_id_table);
  37. static int ehci_ath79_init(struct usb_hcd *hcd)
  38. {
  39. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  40. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  41. const struct platform_device_id *id;
  42. int hclength;
  43. int ret;
  44. id = platform_get_device_id(pdev);
  45. if (!id) {
  46. dev_err(hcd->self.controller, "missing device id\n");
  47. return -EINVAL;
  48. }
  49. hclength = HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  50. switch (id->driver_data) {
  51. case EHCI_ATH79_IP_V1:
  52. ehci->has_synopsys_hc_bug = 1;
  53. ehci->caps = hcd->regs;
  54. ehci->regs = hcd->regs + hclength;
  55. break;
  56. case EHCI_ATH79_IP_V2:
  57. hcd->has_tt = 1;
  58. ehci->caps = hcd->regs + 0x100;
  59. ehci->regs = hcd->regs + 0x100 + hclength;
  60. break;
  61. default:
  62. BUG();
  63. }
  64. dbg_hcs_params(ehci, "reset");
  65. dbg_hcc_params(ehci, "reset");
  66. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  67. ehci->sbrn = 0x20;
  68. ehci_reset(ehci);
  69. ret = ehci_init(hcd);
  70. if (ret)
  71. return ret;
  72. ehci_port_power(ehci, 0);
  73. return 0;
  74. }
  75. static const struct hc_driver ehci_ath79_hc_driver = {
  76. .description = hcd_name,
  77. .product_desc = "Atheros built-in EHCI controller",
  78. .hcd_priv_size = sizeof(struct ehci_hcd),
  79. .irq = ehci_irq,
  80. .flags = HCD_MEMORY | HCD_USB2,
  81. .reset = ehci_ath79_init,
  82. .start = ehci_run,
  83. .stop = ehci_stop,
  84. .shutdown = ehci_shutdown,
  85. .urb_enqueue = ehci_urb_enqueue,
  86. .urb_dequeue = ehci_urb_dequeue,
  87. .endpoint_disable = ehci_endpoint_disable,
  88. .endpoint_reset = ehci_endpoint_reset,
  89. .get_frame_number = ehci_get_frame,
  90. .hub_status_data = ehci_hub_status_data,
  91. .hub_control = ehci_hub_control,
  92. .relinquish_port = ehci_relinquish_port,
  93. .port_handed_over = ehci_port_handed_over,
  94. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  95. };
  96. static int ehci_ath79_probe(struct platform_device *pdev)
  97. {
  98. struct usb_hcd *hcd;
  99. struct resource *res;
  100. int irq;
  101. int ret;
  102. if (usb_disabled())
  103. return -ENODEV;
  104. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  105. if (!res) {
  106. dev_dbg(&pdev->dev, "no IRQ specified\n");
  107. return -ENODEV;
  108. }
  109. irq = res->start;
  110. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  111. if (!res) {
  112. dev_dbg(&pdev->dev, "no base address specified\n");
  113. return -ENODEV;
  114. }
  115. hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev,
  116. dev_name(&pdev->dev));
  117. if (!hcd)
  118. return -ENOMEM;
  119. hcd->rsrc_start = res->start;
  120. hcd->rsrc_len = res->end - res->start + 1;
  121. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  122. dev_dbg(&pdev->dev, "controller already in use\n");
  123. ret = -EBUSY;
  124. goto err_put_hcd;
  125. }
  126. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  127. if (!hcd->regs) {
  128. dev_dbg(&pdev->dev, "error mapping memory\n");
  129. ret = -EFAULT;
  130. goto err_release_region;
  131. }
  132. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  133. if (ret)
  134. goto err_iounmap;
  135. return 0;
  136. err_iounmap:
  137. iounmap(hcd->regs);
  138. err_release_region:
  139. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  140. err_put_hcd:
  141. usb_put_hcd(hcd);
  142. return ret;
  143. }
  144. static int ehci_ath79_remove(struct platform_device *pdev)
  145. {
  146. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  147. usb_remove_hcd(hcd);
  148. iounmap(hcd->regs);
  149. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  150. usb_put_hcd(hcd);
  151. return 0;
  152. }
  153. static struct platform_driver ehci_ath79_driver = {
  154. .probe = ehci_ath79_probe,
  155. .remove = ehci_ath79_remove,
  156. .id_table = ehci_ath79_id_table,
  157. .driver = {
  158. .owner = THIS_MODULE,
  159. .name = "ath79-ehci",
  160. }
  161. };
  162. MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci");