ohci-platform.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
  91. dev_name(&dev->dev));
  92. if (!hcd)
  93. return -ENOMEM;
  94. hcd->rsrc_start = res_mem->start;
  95. hcd->rsrc_len = resource_size(res_mem);
  96. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  97. pr_err("controller already in use");
  98. err = -EBUSY;
  99. goto err_put_hcd;
  100. }
  101. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  102. if (!hcd->regs)
  103. goto err_release_region;
  104. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  105. if (err)
  106. goto err_iounmap;
  107. platform_set_drvdata(dev, hcd);
  108. return err;
  109. err_iounmap:
  110. iounmap(hcd->regs);
  111. err_release_region:
  112. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  113. err_put_hcd:
  114. usb_put_hcd(hcd);
  115. return err;
  116. }
  117. static int __devexit ohci_platform_remove(struct platform_device *dev)
  118. {
  119. struct usb_hcd *hcd = platform_get_drvdata(dev);
  120. usb_remove_hcd(hcd);
  121. iounmap(hcd->regs);
  122. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  123. usb_put_hcd(hcd);
  124. platform_set_drvdata(dev, NULL);
  125. return 0;
  126. }
  127. #ifdef CONFIG_PM
  128. static int ohci_platform_suspend(struct device *dev)
  129. {
  130. return 0;
  131. }
  132. static int ohci_platform_resume(struct device *dev)
  133. {
  134. struct usb_hcd *hcd = dev_get_drvdata(dev);
  135. ohci_finish_controller_resume(hcd);
  136. return 0;
  137. }
  138. #else /* !CONFIG_PM */
  139. #define ohci_platform_suspend NULL
  140. #define ohci_platform_resume NULL
  141. #endif /* CONFIG_PM */
  142. static const struct platform_device_id ohci_platform_table[] = {
  143. { "ohci-platform", 0 },
  144. { }
  145. };
  146. MODULE_DEVICE_TABLE(platform, ohci_platform_table);
  147. static const struct dev_pm_ops ohci_platform_pm_ops = {
  148. .suspend = ohci_platform_suspend,
  149. .resume = ohci_platform_resume,
  150. };
  151. static struct platform_driver ohci_platform_driver = {
  152. .id_table = ohci_platform_table,
  153. .probe = ohci_platform_probe,
  154. .remove = __devexit_p(ohci_platform_remove),
  155. .shutdown = usb_hcd_platform_shutdown,
  156. .driver = {
  157. .owner = THIS_MODULE,
  158. .name = "ohci-platform",
  159. .pm = &ohci_platform_pm_ops,
  160. }
  161. };