uhci-platform.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 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. /*
  59. * Right now device-tree probed devices don't get dma_mask set.
  60. * Since shared usb code relies on it, set it here for now.
  61. * Once we have dma capability bindings this can go away.
  62. */
  63. if (!pdev->dev.dma_mask)
  64. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  65. if (!pdev->dev.coherent_dma_mask)
  66. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  67. hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
  68. pdev->name);
  69. if (!hcd)
  70. return -ENOMEM;
  71. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  72. hcd->rsrc_start = res->start;
  73. hcd->rsrc_len = resource_size(res);
  74. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  75. pr_err("%s: request_mem_region failed\n", __func__);
  76. ret = -EBUSY;
  77. goto err_rmr;
  78. }
  79. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  80. if (!hcd->regs) {
  81. pr_err("%s: ioremap failed\n", __func__);
  82. ret = -ENOMEM;
  83. goto err_irq;
  84. }
  85. uhci = hcd_to_uhci(hcd);
  86. uhci->regs = hcd->regs;
  87. ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED |
  88. IRQF_SHARED);
  89. if (ret)
  90. goto err_uhci;
  91. return 0;
  92. err_uhci:
  93. iounmap(hcd->regs);
  94. err_irq:
  95. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  96. err_rmr:
  97. usb_put_hcd(hcd);
  98. return ret;
  99. }
  100. static int uhci_hcd_platform_remove(struct platform_device *pdev)
  101. {
  102. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  103. usb_remove_hcd(hcd);
  104. iounmap(hcd->regs);
  105. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  106. usb_put_hcd(hcd);
  107. return 0;
  108. }
  109. /* Make sure the controller is quiescent and that we're not using it
  110. * any more. This is mainly for the benefit of programs which, like kexec,
  111. * expect the hardware to be idle: not doing DMA or generating IRQs.
  112. *
  113. * This routine may be called in a damaged or failing kernel. Hence we
  114. * do not acquire the spinlock before shutting down the controller.
  115. */
  116. static void uhci_hcd_platform_shutdown(struct platform_device *op)
  117. {
  118. struct usb_hcd *hcd = platform_get_drvdata(op);
  119. uhci_hc_died(hcd_to_uhci(hcd));
  120. }
  121. static const struct of_device_id platform_uhci_ids[] = {
  122. { .compatible = "platform-uhci", },
  123. {}
  124. };
  125. static struct platform_driver uhci_platform_driver = {
  126. .probe = uhci_hcd_platform_probe,
  127. .remove = uhci_hcd_platform_remove,
  128. .shutdown = uhci_hcd_platform_shutdown,
  129. .driver = {
  130. .name = "platform-uhci",
  131. .owner = THIS_MODULE,
  132. .of_match_table = platform_uhci_ids,
  133. },
  134. };