ehci-platform.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Generic platform ehci driver
  3. *
  4. * Copyright 2007 Steven Brown <sbrown@cortland.com>
  5. * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
  6. *
  7. * Derived from the ohci-ssb driver
  8. * Copyright 2007 Michael Buesch <m@bues.ch>
  9. *
  10. * Derived from the EHCI-PCI driver
  11. * Copyright (c) 2000-2004 by David Brownell
  12. *
  13. * Derived from the ohci-pci driver
  14. * Copyright 1999 Roman Weissgaerber
  15. * Copyright 2000-2002 David Brownell
  16. * Copyright 1999 Linus Torvalds
  17. * Copyright 1999 Gregory P. Smith
  18. *
  19. * Licensed under the GNU/GPL. See COPYING for details.
  20. */
  21. #include <linux/platform_device.h>
  22. #include <linux/usb/ehci_pdriver.h>
  23. static int ehci_platform_reset(struct usb_hcd *hcd)
  24. {
  25. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  26. struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
  27. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  28. int retval;
  29. hcd->has_tt = pdata->has_tt;
  30. ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
  31. ehci->big_endian_desc = pdata->big_endian_desc;
  32. ehci->big_endian_mmio = pdata->big_endian_mmio;
  33. ehci->caps = hcd->regs + pdata->caps_offset;
  34. retval = ehci_setup(hcd);
  35. if (retval)
  36. return retval;
  37. if (pdata->port_power_on)
  38. ehci_port_power(ehci, 1);
  39. if (pdata->port_power_off)
  40. ehci_port_power(ehci, 0);
  41. return 0;
  42. }
  43. static const struct hc_driver ehci_platform_hc_driver = {
  44. .description = hcd_name,
  45. .product_desc = "Generic Platform EHCI Controller",
  46. .hcd_priv_size = sizeof(struct ehci_hcd),
  47. .irq = ehci_irq,
  48. .flags = HCD_MEMORY | HCD_USB2,
  49. .reset = ehci_platform_reset,
  50. .start = ehci_run,
  51. .stop = ehci_stop,
  52. .shutdown = ehci_shutdown,
  53. .urb_enqueue = ehci_urb_enqueue,
  54. .urb_dequeue = ehci_urb_dequeue,
  55. .endpoint_disable = ehci_endpoint_disable,
  56. .endpoint_reset = ehci_endpoint_reset,
  57. .get_frame_number = ehci_get_frame,
  58. .hub_status_data = ehci_hub_status_data,
  59. .hub_control = ehci_hub_control,
  60. #if defined(CONFIG_PM)
  61. .bus_suspend = ehci_bus_suspend,
  62. .bus_resume = ehci_bus_resume,
  63. #endif
  64. .relinquish_port = ehci_relinquish_port,
  65. .port_handed_over = ehci_port_handed_over,
  66. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  67. };
  68. static int __devinit ehci_platform_probe(struct platform_device *dev)
  69. {
  70. struct usb_hcd *hcd;
  71. struct resource *res_mem;
  72. int irq;
  73. int err = -ENOMEM;
  74. BUG_ON(!dev->dev.platform_data);
  75. if (usb_disabled())
  76. return -ENODEV;
  77. irq = platform_get_irq(dev, 0);
  78. if (irq < 0) {
  79. pr_err("no irq provieded");
  80. return irq;
  81. }
  82. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  83. if (!res_mem) {
  84. pr_err("no memory recourse provieded");
  85. return -ENXIO;
  86. }
  87. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  88. dev_name(&dev->dev));
  89. if (!hcd)
  90. return -ENOMEM;
  91. hcd->rsrc_start = res_mem->start;
  92. hcd->rsrc_len = resource_size(res_mem);
  93. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  94. pr_err("controller already in use");
  95. err = -EBUSY;
  96. goto err_put_hcd;
  97. }
  98. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  99. if (!hcd->regs)
  100. goto err_release_region;
  101. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  102. if (err)
  103. goto err_iounmap;
  104. platform_set_drvdata(dev, hcd);
  105. return err;
  106. err_iounmap:
  107. iounmap(hcd->regs);
  108. err_release_region:
  109. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  110. err_put_hcd:
  111. usb_put_hcd(hcd);
  112. return err;
  113. }
  114. static int __devexit ehci_platform_remove(struct platform_device *dev)
  115. {
  116. struct usb_hcd *hcd = platform_get_drvdata(dev);
  117. usb_remove_hcd(hcd);
  118. iounmap(hcd->regs);
  119. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  120. usb_put_hcd(hcd);
  121. platform_set_drvdata(dev, NULL);
  122. return 0;
  123. }
  124. #ifdef CONFIG_PM
  125. static int ehci_platform_suspend(struct device *dev)
  126. {
  127. struct usb_hcd *hcd = dev_get_drvdata(dev);
  128. bool wakeup = device_may_wakeup(dev);
  129. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
  130. return 0;
  131. }
  132. static int ehci_platform_resume(struct device *dev)
  133. {
  134. struct usb_hcd *hcd = dev_get_drvdata(dev);
  135. ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
  136. return 0;
  137. }
  138. #else /* !CONFIG_PM */
  139. #define ehci_platform_suspend NULL
  140. #define ehci_platform_resume NULL
  141. #endif /* CONFIG_PM */
  142. static const struct platform_device_id ehci_platform_table[] = {
  143. { "ehci-platform", 0 },
  144. { }
  145. };
  146. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  147. static const struct dev_pm_ops ehci_platform_pm_ops = {
  148. .suspend = ehci_platform_suspend,
  149. .resume = ehci_platform_resume,
  150. };
  151. static struct platform_driver ehci_platform_driver = {
  152. .id_table = ehci_platform_table,
  153. .probe = ehci_platform_probe,
  154. .remove = __devexit_p(ehci_platform_remove),
  155. .shutdown = usb_hcd_platform_shutdown,
  156. .driver = {
  157. .owner = THIS_MODULE,
  158. .name = "ehci-platform",
  159. .pm = &ehci_platform_pm_ops,
  160. }
  161. };