ohci-au1xxx.c 5.3 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:%p", ohci);
  29. if ((ret = ohci_init(ohci)) < 0)
  30. return ret;
  31. if ((ret = ohci_run(ohci)) < 0) {
  32. dev_err(hcd->self.controller, "can't start %s",
  33. hcd->self.bus_name);
  34. ohci_stop(hcd);
  35. return ret;
  36. }
  37. return 0;
  38. }
  39. static const struct hc_driver ohci_au1xxx_hc_driver = {
  40. .description = hcd_name,
  41. .product_desc = "Au1xxx OHCI",
  42. .hcd_priv_size = sizeof(struct ohci_hcd),
  43. /*
  44. * generic hardware linkage
  45. */
  46. .irq = ohci_irq,
  47. .flags = HCD_USB11 | HCD_MEMORY,
  48. /*
  49. * basic lifecycle operations
  50. */
  51. .start = ohci_au1xxx_start,
  52. .stop = ohci_stop,
  53. .shutdown = ohci_shutdown,
  54. /*
  55. * managing i/o requests and associated device resources
  56. */
  57. .urb_enqueue = ohci_urb_enqueue,
  58. .urb_dequeue = ohci_urb_dequeue,
  59. .endpoint_disable = ohci_endpoint_disable,
  60. /*
  61. * scheduling support
  62. */
  63. .get_frame_number = ohci_get_frame,
  64. /*
  65. * root hub support
  66. */
  67. .hub_status_data = ohci_hub_status_data,
  68. .hub_control = ohci_hub_control,
  69. #ifdef CONFIG_PM
  70. .bus_suspend = ohci_bus_suspend,
  71. .bus_resume = ohci_bus_resume,
  72. #endif
  73. .start_port_reset = ohci_start_port_reset,
  74. };
  75. static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  76. {
  77. int ret, unit;
  78. struct usb_hcd *hcd;
  79. if (usb_disabled())
  80. return -ENODEV;
  81. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  82. pr_debug("resource[1] is not IORESOURCE_IRQ\n");
  83. return -ENOMEM;
  84. }
  85. hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
  86. if (!hcd)
  87. return -ENOMEM;
  88. hcd->rsrc_start = pdev->resource[0].start;
  89. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  90. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  91. pr_debug("request_mem_region failed\n");
  92. ret = -EBUSY;
  93. goto err1;
  94. }
  95. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  96. if (!hcd->regs) {
  97. pr_debug("ioremap failed\n");
  98. ret = -ENOMEM;
  99. goto err2;
  100. }
  101. unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ?
  102. ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
  103. if (alchemy_usb_control(unit, 1)) {
  104. printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
  105. ret = -ENODEV;
  106. goto err3;
  107. }
  108. ohci_hcd_init(hcd_to_ohci(hcd));
  109. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  110. IRQF_SHARED);
  111. if (ret == 0) {
  112. platform_set_drvdata(pdev, hcd);
  113. return ret;
  114. }
  115. alchemy_usb_control(unit, 0);
  116. err3:
  117. iounmap(hcd->regs);
  118. err2:
  119. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  120. err1:
  121. usb_put_hcd(hcd);
  122. return ret;
  123. }
  124. static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  125. {
  126. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  127. int unit;
  128. unit = (hcd->rsrc_start == AU1300_USB_OHCI1_PHYS_ADDR) ?
  129. ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
  130. usb_remove_hcd(hcd);
  131. alchemy_usb_control(unit, 0);
  132. iounmap(hcd->regs);
  133. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  134. usb_put_hcd(hcd);
  135. platform_set_drvdata(pdev, NULL);
  136. return 0;
  137. }
  138. #ifdef CONFIG_PM
  139. static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
  140. {
  141. struct usb_hcd *hcd = dev_get_drvdata(dev);
  142. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  143. unsigned long flags;
  144. int rc;
  145. rc = 0;
  146. /* Root hub was already suspended. Disable irq emission and
  147. * mark HW unaccessible, bail out if RH has been resumed. Use
  148. * the spinlock to properly synchronize with possible pending
  149. * RH suspend or resume activity.
  150. */
  151. spin_lock_irqsave(&ohci->lock, flags);
  152. if (ohci->rh_state != OHCI_RH_SUSPENDED) {
  153. rc = -EINVAL;
  154. goto bail;
  155. }
  156. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  157. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  158. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  159. alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
  160. bail:
  161. spin_unlock_irqrestore(&ohci->lock, flags);
  162. return rc;
  163. }
  164. static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
  165. {
  166. struct usb_hcd *hcd = dev_get_drvdata(dev);
  167. alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
  168. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  169. ohci_finish_controller_resume(hcd);
  170. return 0;
  171. }
  172. static const struct dev_pm_ops au1xxx_ohci_pmops = {
  173. .suspend = ohci_hcd_au1xxx_drv_suspend,
  174. .resume = ohci_hcd_au1xxx_drv_resume,
  175. };
  176. #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
  177. #else
  178. #define AU1XXX_OHCI_PMOPS NULL
  179. #endif
  180. static struct platform_driver ohci_hcd_au1xxx_driver = {
  181. .probe = ohci_hcd_au1xxx_drv_probe,
  182. .remove = ohci_hcd_au1xxx_drv_remove,
  183. .shutdown = usb_hcd_platform_shutdown,
  184. .driver = {
  185. .name = "au1xxx-ohci",
  186. .owner = THIS_MODULE,
  187. .pm = AU1XXX_OHCI_PMOPS,
  188. },
  189. };
  190. MODULE_ALIAS("platform:au1xxx-ohci");