ohci-au1xxx.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for AMD Alchemy Au1xxx
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. * Modified for AMD Alchemy Au1xxx
  16. * by Matt Porter <mporter@kernel.crashing.org>
  17. *
  18. * This file is licenced under the GPL.
  19. */
  20. #include <linux/platform_device.h>
  21. #include <linux/signal.h>
  22. #include <asm/mach-au1x00/au1000.h>
  23. extern int usb_disabled(void);
  24. static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
  25. {
  26. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  27. int ret;
  28. ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
  29. if ((ret = ohci_init(ohci)) < 0)
  30. return ret;
  31. if ((ret = ohci_run(ohci)) < 0) {
  32. err ("can't start %s", hcd->self.bus_name);
  33. ohci_stop(hcd);
  34. return ret;
  35. }
  36. return 0;
  37. }
  38. static const struct hc_driver ohci_au1xxx_hc_driver = {
  39. .description = hcd_name,
  40. .product_desc = "Au1xxx OHCI",
  41. .hcd_priv_size = sizeof(struct ohci_hcd),
  42. /*
  43. * generic hardware linkage
  44. */
  45. .irq = ohci_irq,
  46. .flags = HCD_USB11 | HCD_MEMORY,
  47. /*
  48. * basic lifecycle operations
  49. */
  50. .start = ohci_au1xxx_start,
  51. .stop = ohci_stop,
  52. .shutdown = ohci_shutdown,
  53. /*
  54. * managing i/o requests and associated device resources
  55. */
  56. .urb_enqueue = ohci_urb_enqueue,
  57. .urb_dequeue = ohci_urb_dequeue,
  58. .endpoint_disable = ohci_endpoint_disable,
  59. /*
  60. * scheduling support
  61. */
  62. .get_frame_number = ohci_get_frame,
  63. /*
  64. * root hub support
  65. */
  66. .hub_status_data = ohci_hub_status_data,
  67. .hub_control = ohci_hub_control,
  68. #ifdef CONFIG_PM
  69. .bus_suspend = ohci_bus_suspend,
  70. .bus_resume = ohci_bus_resume,
  71. #endif
  72. .start_port_reset = ohci_start_port_reset,
  73. };
  74. static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  75. {
  76. int ret;
  77. struct usb_hcd *hcd;
  78. if (usb_disabled())
  79. return -ENODEV;
  80. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  81. pr_debug("resource[1] is not IORESOURCE_IRQ\n");
  82. return -ENOMEM;
  83. }
  84. hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
  85. if (!hcd)
  86. return -ENOMEM;
  87. hcd->rsrc_start = pdev->resource[0].start;
  88. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  89. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  90. pr_debug("request_mem_region failed\n");
  91. ret = -EBUSY;
  92. goto err1;
  93. }
  94. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  95. if (!hcd->regs) {
  96. pr_debug("ioremap failed\n");
  97. ret = -ENOMEM;
  98. goto err2;
  99. }
  100. if (alchemy_usb_control(ALCHEMY_USB_OHCI0, 1)) {
  101. printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
  102. ret = -ENODEV;
  103. goto err3;
  104. }
  105. ohci_hcd_init(hcd_to_ohci(hcd));
  106. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  107. IRQF_SHARED);
  108. if (ret == 0) {
  109. platform_set_drvdata(pdev, hcd);
  110. return ret;
  111. }
  112. alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
  113. err3:
  114. iounmap(hcd->regs);
  115. err2:
  116. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  117. err1:
  118. usb_put_hcd(hcd);
  119. return ret;
  120. }
  121. static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  122. {
  123. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  124. usb_remove_hcd(hcd);
  125. alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
  126. iounmap(hcd->regs);
  127. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  128. usb_put_hcd(hcd);
  129. platform_set_drvdata(pdev, NULL);
  130. return 0;
  131. }
  132. #ifdef CONFIG_PM
  133. static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
  134. {
  135. struct usb_hcd *hcd = dev_get_drvdata(dev);
  136. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  137. unsigned long flags;
  138. int rc;
  139. rc = 0;
  140. /* Root hub was already suspended. Disable irq emission and
  141. * mark HW unaccessible, bail out if RH has been resumed. Use
  142. * the spinlock to properly synchronize with possible pending
  143. * RH suspend or resume activity.
  144. */
  145. spin_lock_irqsave(&ohci->lock, flags);
  146. if (ohci->rh_state != OHCI_RH_SUSPENDED) {
  147. rc = -EINVAL;
  148. goto bail;
  149. }
  150. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  151. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  152. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  153. alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
  154. bail:
  155. spin_unlock_irqrestore(&ohci->lock, flags);
  156. return rc;
  157. }
  158. static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
  159. {
  160. struct usb_hcd *hcd = dev_get_drvdata(dev);
  161. alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
  162. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  163. ohci_finish_controller_resume(hcd);
  164. return 0;
  165. }
  166. static const struct dev_pm_ops au1xxx_ohci_pmops = {
  167. .suspend = ohci_hcd_au1xxx_drv_suspend,
  168. .resume = ohci_hcd_au1xxx_drv_resume,
  169. };
  170. #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
  171. #else
  172. #define AU1XXX_OHCI_PMOPS NULL
  173. #endif
  174. static struct platform_driver ohci_hcd_au1xxx_driver = {
  175. .probe = ohci_hcd_au1xxx_drv_probe,
  176. .remove = ohci_hcd_au1xxx_drv_remove,
  177. .shutdown = usb_hcd_platform_shutdown,
  178. .driver = {
  179. .name = "au1xxx-ohci",
  180. .owner = THIS_MODULE,
  181. .pm = AU1XXX_OHCI_PMOPS,
  182. },
  183. };
  184. MODULE_ALIAS("platform:au1xxx-ohci");