uhci-platform.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 u64 platform_uhci_dma_mask = DMA_BIT_MASK(32);
  51. static int uhci_hcd_platform_probe(struct platform_device *pdev)
  52. {
  53. struct usb_hcd *hcd;
  54. struct uhci_hcd *uhci;
  55. struct resource *res;
  56. int ret;
  57. if (usb_disabled())
  58. return -ENODEV;
  59. /*
  60. * Right now device-tree probed devices don't get dma_mask set.
  61. * Since shared usb code relies on it, set it here for now.
  62. * Once we have dma capability bindings this can go away.
  63. */
  64. if (!pdev->dev.dma_mask)
  65. pdev->dev.dma_mask = &platform_uhci_dma_mask;
  66. hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
  67. pdev->name);
  68. if (!hcd)
  69. return -ENOMEM;
  70. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  71. hcd->rsrc_start = res->start;
  72. hcd->rsrc_len = resource_size(res);
  73. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  74. pr_err("%s: request_mem_region failed\n", __func__);
  75. ret = -EBUSY;
  76. goto err_rmr;
  77. }
  78. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  79. if (!hcd->regs) {
  80. pr_err("%s: ioremap failed\n", __func__);
  81. ret = -ENOMEM;
  82. goto err_irq;
  83. }
  84. uhci = hcd_to_uhci(hcd);
  85. uhci->regs = hcd->regs;
  86. ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED |
  87. IRQF_SHARED);
  88. if (ret)
  89. goto err_uhci;
  90. return 0;
  91. err_uhci:
  92. iounmap(hcd->regs);
  93. err_irq:
  94. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  95. err_rmr:
  96. usb_put_hcd(hcd);
  97. return ret;
  98. }
  99. static int uhci_hcd_platform_remove(struct platform_device *pdev)
  100. {
  101. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  102. usb_remove_hcd(hcd);
  103. iounmap(hcd->regs);
  104. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  105. usb_put_hcd(hcd);
  106. platform_set_drvdata(pdev, NULL);
  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 = dev_get_drvdata(&op->dev);
  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 = of_match_ptr(platform_uhci_ids),
  133. },
  134. };