uhci-platform.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Generic UHCI HCD (Host Controller Driver) for Platform Devices
  3. *
  4. * Copyright (c) 2011 Tony Prisk <linux@prisktech.co.nz>
  5. *
  6. * This file is based on uhci-grlib.c
  7. * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
  8. */
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. static int uhci_platform_init(struct usb_hcd *hcd)
  12. {
  13. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  14. uhci->rh_numports = uhci_count_ports(hcd);
  15. /* Set up pointers to to generic functions */
  16. uhci->reset_hc = uhci_generic_reset_hc;
  17. uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
  18. /* No special actions need to be taken for the functions below */
  19. uhci->configure_hc = NULL;
  20. uhci->resume_detect_interrupts_are_broken = NULL;
  21. uhci->global_suspend_mode_is_broken = NULL;
  22. /* Reset if the controller isn't already safely quiescent. */
  23. check_and_reset_hc(uhci);
  24. return 0;
  25. }
  26. static const struct hc_driver uhci_platform_hc_driver = {
  27. .description = hcd_name,
  28. .product_desc = "Generic UHCI Host Controller",
  29. .hcd_priv_size = sizeof(struct uhci_hcd),
  30. /* Generic hardware linkage */
  31. .irq = uhci_irq,
  32. .flags = HCD_MEMORY | HCD_USB11,
  33. /* Basic lifecycle operations */
  34. .reset = uhci_platform_init,
  35. .start = uhci_start,
  36. #ifdef CONFIG_PM
  37. .pci_suspend = NULL,
  38. .pci_resume = NULL,
  39. .bus_suspend = uhci_rh_suspend,
  40. .bus_resume = uhci_rh_resume,
  41. #endif
  42. .stop = uhci_stop,
  43. .urb_enqueue = uhci_urb_enqueue,
  44. .urb_dequeue = uhci_urb_dequeue,
  45. .endpoint_disable = uhci_hcd_endpoint_disable,
  46. .get_frame_number = uhci_hcd_get_frame_number,
  47. .hub_status_data = uhci_hub_status_data,
  48. .hub_control = uhci_hub_control,
  49. };
  50. static int __devinit uhci_hcd_platform_probe(struct platform_device *pdev)
  51. {
  52. struct usb_hcd *hcd;
  53. struct uhci_hcd *uhci;
  54. struct resource *res;
  55. int ret;
  56. if (usb_disabled())
  57. return -ENODEV;
  58. hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
  59. pdev->name);
  60. if (!hcd)
  61. return -ENOMEM;
  62. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  63. hcd->rsrc_start = res->start;
  64. hcd->rsrc_len = resource_size(res);
  65. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  66. pr_err("%s: request_mem_region failed\n", __func__);
  67. ret = -EBUSY;
  68. goto err_rmr;
  69. }
  70. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  71. if (!hcd->regs) {
  72. pr_err("%s: ioremap failed\n", __func__);
  73. ret = -ENOMEM;
  74. goto err_irq;
  75. }
  76. uhci = hcd_to_uhci(hcd);
  77. uhci->regs = hcd->regs;
  78. ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED |
  79. IRQF_SHARED);
  80. if (ret)
  81. goto err_uhci;
  82. return 0;
  83. err_uhci:
  84. iounmap(hcd->regs);
  85. err_irq:
  86. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  87. err_rmr:
  88. usb_put_hcd(hcd);
  89. return ret;
  90. }
  91. static int uhci_hcd_platform_remove(struct platform_device *pdev)
  92. {
  93. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  94. usb_remove_hcd(hcd);
  95. iounmap(hcd->regs);
  96. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  97. usb_put_hcd(hcd);
  98. platform_set_drvdata(pdev, NULL);
  99. return 0;
  100. }
  101. /* Make sure the controller is quiescent and that we're not using it
  102. * any more. This is mainly for the benefit of programs which, like kexec,
  103. * expect the hardware to be idle: not doing DMA or generating IRQs.
  104. *
  105. * This routine may be called in a damaged or failing kernel. Hence we
  106. * do not acquire the spinlock before shutting down the controller.
  107. */
  108. static void uhci_hcd_platform_shutdown(struct platform_device *op)
  109. {
  110. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  111. uhci_hc_died(hcd_to_uhci(hcd));
  112. }
  113. static const struct of_device_id platform_uhci_ids[] = {
  114. { .compatible = "platform-uhci", },
  115. {}
  116. };
  117. static struct platform_driver uhci_platform_driver = {
  118. .probe = uhci_hcd_platform_probe,
  119. .remove = uhci_hcd_platform_remove,
  120. .shutdown = uhci_hcd_platform_shutdown,
  121. .driver = {
  122. .name = "platform-uhci",
  123. .owner = THIS_MODULE,
  124. .of_match_table = of_match_ptr(platform_uhci_ids),
  125. },
  126. };