ohci-platform.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Generic platform ohci driver
  3. *
  4. * Copyright 2007 Michael Buesch <m@bues.ch>
  5. * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
  6. *
  7. * Derived from the OCHI-SSB driver
  8. * Derived from the OHCI-PCI driver
  9. * Copyright 1999 Roman Weissgaerber
  10. * Copyright 2000-2002 David Brownell
  11. * Copyright 1999 Linus Torvalds
  12. * Copyright 1999 Gregory P. Smith
  13. *
  14. * Licensed under the GNU/GPL. See COPYING for details.
  15. */
  16. #include <linux/platform_device.h>
  17. #include <linux/usb/ohci_pdriver.h>
  18. static int ohci_platform_reset(struct usb_hcd *hcd)
  19. {
  20. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  21. struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
  22. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  23. int err;
  24. if (pdata->big_endian_desc)
  25. ohci->flags |= OHCI_QUIRK_BE_DESC;
  26. if (pdata->big_endian_mmio)
  27. ohci->flags |= OHCI_QUIRK_BE_MMIO;
  28. if (pdata->no_big_frame_no)
  29. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  30. ohci_hcd_init(ohci);
  31. if (pdata->num_ports)
  32. ohci->num_ports = pdata->num_ports;
  33. err = ohci_init(ohci);
  34. return err;
  35. }
  36. static int ohci_platform_start(struct usb_hcd *hcd)
  37. {
  38. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  39. int err;
  40. err = ohci_run(ohci);
  41. if (err < 0) {
  42. ohci_err(ohci, "can't start\n");
  43. ohci_stop(hcd);
  44. }
  45. return err;
  46. }
  47. static const struct hc_driver ohci_platform_hc_driver = {
  48. .description = hcd_name,
  49. .product_desc = "Generic Platform OHCI Controller",
  50. .hcd_priv_size = sizeof(struct ohci_hcd),
  51. .irq = ohci_irq,
  52. .flags = HCD_MEMORY | HCD_USB11,
  53. .reset = ohci_platform_reset,
  54. .start = ohci_platform_start,
  55. .stop = ohci_stop,
  56. .shutdown = ohci_shutdown,
  57. .urb_enqueue = ohci_urb_enqueue,
  58. .urb_dequeue = ohci_urb_dequeue,
  59. .endpoint_disable = ohci_endpoint_disable,
  60. .get_frame_number = ohci_get_frame,
  61. .hub_status_data = ohci_hub_status_data,
  62. .hub_control = ohci_hub_control,
  63. #ifdef CONFIG_PM
  64. .bus_suspend = ohci_bus_suspend,
  65. .bus_resume = ohci_bus_resume,
  66. #endif
  67. .start_port_reset = ohci_start_port_reset,
  68. };
  69. static int ohci_platform_probe(struct platform_device *dev)
  70. {
  71. struct usb_hcd *hcd;
  72. struct resource *res_mem;
  73. struct usb_ohci_pdata *pdata = dev->dev.platform_data;
  74. int irq;
  75. int err = -ENOMEM;
  76. if (!pdata) {
  77. WARN_ON(1);
  78. return -ENODEV;
  79. }
  80. if (usb_disabled())
  81. return -ENODEV;
  82. irq = platform_get_irq(dev, 0);
  83. if (irq < 0) {
  84. dev_err(&dev->dev, "no irq provided");
  85. return irq;
  86. }
  87. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  88. if (!res_mem) {
  89. dev_err(&dev->dev, "no memory resource provided");
  90. return -ENXIO;
  91. }
  92. if (pdata->power_on) {
  93. err = pdata->power_on(dev);
  94. if (err < 0)
  95. return err;
  96. }
  97. hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
  98. dev_name(&dev->dev));
  99. if (!hcd) {
  100. err = -ENOMEM;
  101. goto err_power;
  102. }
  103. hcd->rsrc_start = res_mem->start;
  104. hcd->rsrc_len = resource_size(res_mem);
  105. hcd->regs = devm_request_and_ioremap(&dev->dev, res_mem);
  106. if (!hcd->regs) {
  107. err = -ENOMEM;
  108. goto err_put_hcd;
  109. }
  110. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  111. if (err)
  112. goto err_put_hcd;
  113. platform_set_drvdata(dev, hcd);
  114. return err;
  115. err_put_hcd:
  116. usb_put_hcd(hcd);
  117. err_power:
  118. if (pdata->power_off)
  119. pdata->power_off(dev);
  120. return err;
  121. }
  122. static int ohci_platform_remove(struct platform_device *dev)
  123. {
  124. struct usb_hcd *hcd = platform_get_drvdata(dev);
  125. struct usb_ohci_pdata *pdata = dev->dev.platform_data;
  126. usb_remove_hcd(hcd);
  127. usb_put_hcd(hcd);
  128. platform_set_drvdata(dev, NULL);
  129. if (pdata->power_off)
  130. pdata->power_off(dev);
  131. return 0;
  132. }
  133. #ifdef CONFIG_PM
  134. static int ohci_platform_suspend(struct device *dev)
  135. {
  136. struct usb_ohci_pdata *pdata = dev->platform_data;
  137. struct platform_device *pdev =
  138. container_of(dev, struct platform_device, dev);
  139. if (pdata->power_suspend)
  140. pdata->power_suspend(pdev);
  141. return 0;
  142. }
  143. static int ohci_platform_resume(struct device *dev)
  144. {
  145. struct usb_hcd *hcd = dev_get_drvdata(dev);
  146. struct usb_ohci_pdata *pdata = dev->platform_data;
  147. struct platform_device *pdev =
  148. container_of(dev, struct platform_device, dev);
  149. if (pdata->power_on) {
  150. int err = pdata->power_on(pdev);
  151. if (err < 0)
  152. return err;
  153. }
  154. ohci_resume(hcd, false);
  155. return 0;
  156. }
  157. #else /* !CONFIG_PM */
  158. #define ohci_platform_suspend NULL
  159. #define ohci_platform_resume NULL
  160. #endif /* CONFIG_PM */
  161. static const struct platform_device_id ohci_platform_table[] = {
  162. { "ohci-platform", 0 },
  163. { }
  164. };
  165. MODULE_DEVICE_TABLE(platform, ohci_platform_table);
  166. static const struct dev_pm_ops ohci_platform_pm_ops = {
  167. .suspend = ohci_platform_suspend,
  168. .resume = ohci_platform_resume,
  169. };
  170. static struct platform_driver ohci_platform_driver = {
  171. .id_table = ohci_platform_table,
  172. .probe = ohci_platform_probe,
  173. .remove = ohci_platform_remove,
  174. .shutdown = usb_hcd_platform_shutdown,
  175. .driver = {
  176. .owner = THIS_MODULE,
  177. .name = "ohci-platform",
  178. .pm = &ohci_platform_pm_ops,
  179. }
  180. };