ohci-platform.c 4.8 KB

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