ohci-platform.c 5.0 KB

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