ohci-platform.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 __devinit 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. pr_err("no irq provided");
  85. return irq;
  86. }
  87. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  88. if (!res_mem) {
  89. pr_err("no memory recourse 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. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  106. pr_err("controller already in use");
  107. err = -EBUSY;
  108. goto err_put_hcd;
  109. }
  110. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  111. if (!hcd->regs) {
  112. err = -ENOMEM;
  113. goto err_release_region;
  114. }
  115. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  116. if (err)
  117. goto err_iounmap;
  118. platform_set_drvdata(dev, hcd);
  119. return err;
  120. err_iounmap:
  121. iounmap(hcd->regs);
  122. err_release_region:
  123. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  124. err_put_hcd:
  125. usb_put_hcd(hcd);
  126. err_power:
  127. if (pdata->power_off)
  128. pdata->power_off(dev);
  129. return err;
  130. }
  131. static int __devexit ohci_platform_remove(struct platform_device *dev)
  132. {
  133. struct usb_hcd *hcd = platform_get_drvdata(dev);
  134. struct usb_ohci_pdata *pdata = dev->dev.platform_data;
  135. usb_remove_hcd(hcd);
  136. iounmap(hcd->regs);
  137. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  138. usb_put_hcd(hcd);
  139. platform_set_drvdata(dev, NULL);
  140. if (pdata->power_off)
  141. pdata->power_off(dev);
  142. return 0;
  143. }
  144. #ifdef CONFIG_PM
  145. static int ohci_platform_suspend(struct device *dev)
  146. {
  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_suspend)
  151. pdata->power_suspend(pdev);
  152. return 0;
  153. }
  154. static int ohci_platform_resume(struct device *dev)
  155. {
  156. struct usb_hcd *hcd = dev_get_drvdata(dev);
  157. struct usb_ohci_pdata *pdata = dev->platform_data;
  158. struct platform_device *pdev =
  159. container_of(dev, struct platform_device, dev);
  160. if (pdata->power_on) {
  161. int err = pdata->power_on(pdev);
  162. if (err < 0)
  163. return err;
  164. }
  165. ohci_resume(hcd, false);
  166. return 0;
  167. }
  168. #else /* !CONFIG_PM */
  169. #define ohci_platform_suspend NULL
  170. #define ohci_platform_resume NULL
  171. #endif /* CONFIG_PM */
  172. static const struct platform_device_id ohci_platform_table[] = {
  173. { "ohci-platform", 0 },
  174. { }
  175. };
  176. MODULE_DEVICE_TABLE(platform, ohci_platform_table);
  177. static const struct dev_pm_ops ohci_platform_pm_ops = {
  178. .suspend = ohci_platform_suspend,
  179. .resume = ohci_platform_resume,
  180. };
  181. static struct platform_driver ohci_platform_driver = {
  182. .id_table = ohci_platform_table,
  183. .probe = ohci_platform_probe,
  184. .remove = __devexit_p(ohci_platform_remove),
  185. .shutdown = usb_hcd_platform_shutdown,
  186. .driver = {
  187. .owner = THIS_MODULE,
  188. .name = "ohci-platform",
  189. .pm = &ohci_platform_pm_ops,
  190. }
  191. };