ohci-platform.c 4.3 KB

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