ohci-ath79.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Bus Glue for Atheros AR71XX/AR724X built-in OHCI controller.
  5. *
  6. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  7. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  8. *
  9. * Parts of this file are based on Atheros' 2.6.15 BSP
  10. * Copyright (C) 2007 Atheros Communications, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published
  14. * by the Free Software Foundation.
  15. */
  16. #include <linux/platform_device.h>
  17. static int __devinit ohci_ath79_start(struct usb_hcd *hcd)
  18. {
  19. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  20. int ret;
  21. ret = ohci_init(ohci);
  22. if (ret < 0)
  23. return ret;
  24. ret = ohci_run(ohci);
  25. if (ret < 0)
  26. goto err;
  27. return 0;
  28. err:
  29. ohci_stop(hcd);
  30. return ret;
  31. }
  32. static const struct hc_driver ohci_ath79_hc_driver = {
  33. .description = hcd_name,
  34. .product_desc = "Atheros built-in OHCI controller",
  35. .hcd_priv_size = sizeof(struct ohci_hcd),
  36. .irq = ohci_irq,
  37. .flags = HCD_USB11 | HCD_MEMORY,
  38. .start = ohci_ath79_start,
  39. .stop = ohci_stop,
  40. .shutdown = ohci_shutdown,
  41. .urb_enqueue = ohci_urb_enqueue,
  42. .urb_dequeue = ohci_urb_dequeue,
  43. .endpoint_disable = ohci_endpoint_disable,
  44. /*
  45. * scheduling support
  46. */
  47. .get_frame_number = ohci_get_frame,
  48. /*
  49. * root hub support
  50. */
  51. .hub_status_data = ohci_hub_status_data,
  52. .hub_control = ohci_hub_control,
  53. .start_port_reset = ohci_start_port_reset,
  54. };
  55. static int ohci_ath79_probe(struct platform_device *pdev)
  56. {
  57. struct usb_hcd *hcd;
  58. struct resource *res;
  59. int irq;
  60. int ret;
  61. if (usb_disabled())
  62. return -ENODEV;
  63. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  64. if (!res) {
  65. dev_dbg(&pdev->dev, "no IRQ specified\n");
  66. return -ENODEV;
  67. }
  68. irq = res->start;
  69. hcd = usb_create_hcd(&ohci_ath79_hc_driver, &pdev->dev,
  70. dev_name(&pdev->dev));
  71. if (!hcd)
  72. return -ENOMEM;
  73. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  74. if (!res) {
  75. dev_dbg(&pdev->dev, "no base address specified\n");
  76. ret = -ENODEV;
  77. goto err_put_hcd;
  78. }
  79. hcd->rsrc_start = res->start;
  80. hcd->rsrc_len = res->end - res->start + 1;
  81. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  82. dev_dbg(&pdev->dev, "controller already in use\n");
  83. ret = -EBUSY;
  84. goto err_put_hcd;
  85. }
  86. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  87. if (!hcd->regs) {
  88. dev_dbg(&pdev->dev, "error mapping memory\n");
  89. ret = -EFAULT;
  90. goto err_release_region;
  91. }
  92. ohci_hcd_init(hcd_to_ohci(hcd));
  93. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  94. if (ret)
  95. goto err_stop_hcd;
  96. return 0;
  97. err_stop_hcd:
  98. iounmap(hcd->regs);
  99. err_release_region:
  100. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  101. err_put_hcd:
  102. usb_put_hcd(hcd);
  103. return ret;
  104. }
  105. static int ohci_ath79_remove(struct platform_device *pdev)
  106. {
  107. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  108. usb_remove_hcd(hcd);
  109. iounmap(hcd->regs);
  110. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  111. usb_put_hcd(hcd);
  112. return 0;
  113. }
  114. static struct platform_driver ohci_hcd_ath79_driver = {
  115. .probe = ohci_ath79_probe,
  116. .remove = ohci_ath79_remove,
  117. .shutdown = usb_hcd_platform_shutdown,
  118. .driver = {
  119. .name = "ath79-ohci",
  120. .owner = THIS_MODULE,
  121. },
  122. };
  123. MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ohci");