ehci-platform.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. .update_device = ehci_update_device,
  67. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  68. };
  69. static int __devinit ehci_platform_probe(struct platform_device *dev)
  70. {
  71. struct usb_hcd *hcd;
  72. struct resource *res_mem;
  73. int irq;
  74. int err = -ENOMEM;
  75. BUG_ON(!dev->dev.platform_data);
  76. if (usb_disabled())
  77. return -ENODEV;
  78. irq = platform_get_irq(dev, 0);
  79. if (irq < 0) {
  80. pr_err("no irq provieded");
  81. return irq;
  82. }
  83. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  84. if (!res_mem) {
  85. pr_err("no memory recourse provieded");
  86. return -ENXIO;
  87. }
  88. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  89. dev_name(&dev->dev));
  90. if (!hcd)
  91. return -ENOMEM;
  92. hcd->rsrc_start = res_mem->start;
  93. hcd->rsrc_len = resource_size(res_mem);
  94. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  95. pr_err("controller already in use");
  96. err = -EBUSY;
  97. goto err_put_hcd;
  98. }
  99. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  100. if (!hcd->regs)
  101. goto err_release_region;
  102. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  103. if (err)
  104. goto err_iounmap;
  105. platform_set_drvdata(dev, hcd);
  106. return err;
  107. err_iounmap:
  108. iounmap(hcd->regs);
  109. err_release_region:
  110. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  111. err_put_hcd:
  112. usb_put_hcd(hcd);
  113. return err;
  114. }
  115. static int __devexit ehci_platform_remove(struct platform_device *dev)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(dev);
  118. usb_remove_hcd(hcd);
  119. iounmap(hcd->regs);
  120. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  121. usb_put_hcd(hcd);
  122. platform_set_drvdata(dev, NULL);
  123. return 0;
  124. }
  125. #ifdef CONFIG_PM
  126. static int ehci_platform_suspend(struct device *dev)
  127. {
  128. struct usb_hcd *hcd = dev_get_drvdata(dev);
  129. bool wakeup = device_may_wakeup(dev);
  130. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
  131. return 0;
  132. }
  133. static int ehci_platform_resume(struct device *dev)
  134. {
  135. struct usb_hcd *hcd = dev_get_drvdata(dev);
  136. ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
  137. return 0;
  138. }
  139. #else /* !CONFIG_PM */
  140. #define ehci_platform_suspend NULL
  141. #define ehci_platform_resume NULL
  142. #endif /* CONFIG_PM */
  143. static const struct platform_device_id ehci_platform_table[] = {
  144. { "ehci-platform", 0 },
  145. { }
  146. };
  147. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  148. static const struct dev_pm_ops ehci_platform_pm_ops = {
  149. .suspend = ehci_platform_suspend,
  150. .resume = ehci_platform_resume,
  151. };
  152. static struct platform_driver ehci_platform_driver = {
  153. .id_table = ehci_platform_table,
  154. .probe = ehci_platform_probe,
  155. .remove = __devexit_p(ehci_platform_remove),
  156. .shutdown = usb_hcd_platform_shutdown,
  157. .driver = {
  158. .owner = THIS_MODULE,
  159. .name = "ehci-platform",
  160. .pm = &ehci_platform_pm_ops,
  161. }
  162. };