ohci-au1xxx.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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:%pK", 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, unit;
  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. unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ?
  101. ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
  102. if (alchemy_usb_control(unit, 1)) {
  103. printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
  104. ret = -ENODEV;
  105. goto err3;
  106. }
  107. ohci_hcd_init(hcd_to_ohci(hcd));
  108. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  109. IRQF_SHARED);
  110. if (ret == 0) {
  111. platform_set_drvdata(pdev, hcd);
  112. return ret;
  113. }
  114. alchemy_usb_control(unit, 0);
  115. err3:
  116. iounmap(hcd->regs);
  117. err2:
  118. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  119. err1:
  120. usb_put_hcd(hcd);
  121. return ret;
  122. }
  123. static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  124. {
  125. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  126. int unit;
  127. unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ?
  128. ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
  129. usb_remove_hcd(hcd);
  130. alchemy_usb_control(unit, 0);
  131. iounmap(hcd->regs);
  132. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  133. usb_put_hcd(hcd);
  134. platform_set_drvdata(pdev, NULL);
  135. return 0;
  136. }
  137. #ifdef CONFIG_PM
  138. static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
  139. {
  140. struct usb_hcd *hcd = dev_get_drvdata(dev);
  141. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  142. unsigned long flags;
  143. int rc;
  144. rc = 0;
  145. /* Root hub was already suspended. Disable irq emission and
  146. * mark HW unaccessible, bail out if RH has been resumed. Use
  147. * the spinlock to properly synchronize with possible pending
  148. * RH suspend or resume activity.
  149. */
  150. spin_lock_irqsave(&ohci->lock, flags);
  151. if (ohci->rh_state != OHCI_RH_SUSPENDED) {
  152. rc = -EINVAL;
  153. goto bail;
  154. }
  155. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  156. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  157. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  158. alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
  159. bail:
  160. spin_unlock_irqrestore(&ohci->lock, flags);
  161. return rc;
  162. }
  163. static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
  164. {
  165. struct usb_hcd *hcd = dev_get_drvdata(dev);
  166. alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
  167. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  168. ohci_finish_controller_resume(hcd);
  169. return 0;
  170. }
  171. static const struct dev_pm_ops au1xxx_ohci_pmops = {
  172. .suspend = ohci_hcd_au1xxx_drv_suspend,
  173. .resume = ohci_hcd_au1xxx_drv_resume,
  174. };
  175. #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
  176. #else
  177. #define AU1XXX_OHCI_PMOPS NULL
  178. #endif
  179. static struct platform_driver ohci_hcd_au1xxx_driver = {
  180. .probe = ohci_hcd_au1xxx_drv_probe,
  181. .remove = ohci_hcd_au1xxx_drv_remove,
  182. .shutdown = usb_hcd_platform_shutdown,
  183. .driver = {
  184. .name = "au1xxx-ohci",
  185. .owner = THIS_MODULE,
  186. .pm = AU1XXX_OHCI_PMOPS,
  187. },
  188. };
  189. MODULE_ALIAS("platform:au1xxx-ohci");