ohci-mcs814x.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 Moschip MCS814x.
  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. *
  16. * Modified for pxa27x from ohci-lh7a404.c
  17. * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
  18. *
  19. * Modified for mcs814x from ohci-mcs814x.c
  20. * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
  21. * Based on an earlier driver by Ray Lehtiniemi
  22. *
  23. * This file is licenced under the GPL.
  24. */
  25. #include <linux/device.h>
  26. #include <linux/signal.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/of.h>
  29. static int usb_hcd_mcs814x_probe(const struct hc_driver *driver,
  30. struct platform_device *pdev)
  31. {
  32. int retval;
  33. struct usb_hcd *hcd;
  34. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  35. pr_debug("resource[1] is not IORESOURCE_IRQ");
  36. return -ENOMEM;
  37. }
  38. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  39. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  40. hcd = usb_create_hcd(driver, &pdev->dev, "mcs814x");
  41. if (hcd == NULL)
  42. return -ENOMEM;
  43. hcd->rsrc_start = pdev->resource[0].start;
  44. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  45. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  46. usb_put_hcd(hcd);
  47. retval = -EBUSY;
  48. goto err1;
  49. }
  50. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  51. if (hcd->regs == NULL) {
  52. pr_debug("ioremap failed");
  53. retval = -ENOMEM;
  54. goto err2;
  55. }
  56. ohci_hcd_init(hcd_to_ohci(hcd));
  57. retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
  58. if (retval == 0)
  59. return retval;
  60. iounmap(hcd->regs);
  61. err2:
  62. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  63. err1:
  64. usb_put_hcd(hcd);
  65. return retval;
  66. }
  67. static void usb_hcd_mcs814x_remove(struct usb_hcd *hcd,
  68. struct platform_device *pdev)
  69. {
  70. usb_remove_hcd(hcd);
  71. iounmap(hcd->regs);
  72. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  73. usb_put_hcd(hcd);
  74. }
  75. static int ohci_mcs814x_start(struct usb_hcd *hcd)
  76. {
  77. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  78. int ret;
  79. ret = ohci_init(ohci);
  80. if (ret < 0)
  81. return ret;
  82. ret = ohci_run(ohci);
  83. if (ret < 0) {
  84. ohci_err(ohci, "can't start %s", hcd->self.bus_name);
  85. ohci_stop(hcd);
  86. return ret;
  87. }
  88. return 0;
  89. }
  90. static struct hc_driver ohci_mcs814x_hc_driver = {
  91. .description = hcd_name,
  92. .product_desc = "MCS814X OHCI",
  93. .hcd_priv_size = sizeof(struct ohci_hcd),
  94. .irq = ohci_irq,
  95. .flags = HCD_USB11 | HCD_MEMORY,
  96. .start = ohci_mcs814x_start,
  97. .stop = ohci_stop,
  98. .shutdown = ohci_shutdown,
  99. .urb_enqueue = ohci_urb_enqueue,
  100. .urb_dequeue = ohci_urb_dequeue,
  101. .endpoint_disable = ohci_endpoint_disable,
  102. .get_frame_number = ohci_get_frame,
  103. .hub_status_data = ohci_hub_status_data,
  104. .hub_control = ohci_hub_control,
  105. #ifdef CONFIG_PM
  106. .bus_suspend = ohci_bus_suspend,
  107. .bus_resume = ohci_bus_resume,
  108. #endif
  109. .start_port_reset = ohci_start_port_reset,
  110. };
  111. extern int usb_disabled(void);
  112. static int ohci_hcd_mcs814x_drv_probe(struct platform_device *pdev)
  113. {
  114. int ret;
  115. ret = -ENODEV;
  116. if (!usb_disabled())
  117. ret = usb_hcd_mcs814x_probe(&ohci_mcs814x_hc_driver, pdev);
  118. return ret;
  119. }
  120. static int ohci_hcd_mcs814x_drv_remove(struct platform_device *pdev)
  121. {
  122. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  123. usb_hcd_mcs814x_remove(hcd, pdev);
  124. return 0;
  125. }
  126. #ifdef CONFIG_PM
  127. static int ohci_hcd_mcs814x_drv_suspend(struct platform_device *pdev, pm_message_t state)
  128. {
  129. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  130. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  131. if (time_before(jiffies, ohci->next_statechange))
  132. msleep(5);
  133. ohci->next_statechange = jiffies;
  134. hcd->state = HC_STATE_SUSPENDED;
  135. return 0;
  136. }
  137. static int ohci_hcd_mcs814x_drv_resume(struct platform_device *pdev)
  138. {
  139. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  140. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  141. int status;
  142. if (time_before(jiffies, ohci->next_statechange))
  143. msleep(5);
  144. ohci->next_statechange = jiffies;
  145. ohci_finish_controller_resume(hcd);
  146. return 0;
  147. }
  148. #endif
  149. static const struct of_device_id mcs814x_ohci_id[] = {
  150. { .compatible = "moschip,mcs814x-ohci" },
  151. { .compatible = "ohci-le" },
  152. { /* sentinel */ },
  153. };
  154. static struct platform_driver ohci_hcd_mcs814x_driver = {
  155. .probe = ohci_hcd_mcs814x_drv_probe,
  156. .remove = ohci_hcd_mcs814x_drv_remove,
  157. .shutdown = usb_hcd_platform_shutdown,
  158. #ifdef CONFIG_PM
  159. .suspend = ohci_hcd_mcs814x_drv_suspend,
  160. .resume = ohci_hcd_mcs814x_drv_resume,
  161. #endif
  162. .driver = {
  163. .name = "mcs814x-ohci",
  164. .owner = THIS_MODULE,
  165. .of_match_table = mcs814x_ohci_id,
  166. },
  167. };
  168. MODULE_ALIAS("platform:mcs814x-ohci");