uhci-platform.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/device.h>
  11. #include <linux/platform_device.h>
  12. static int uhci_platform_init(struct usb_hcd *hcd)
  13. {
  14. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  15. uhci->rh_numports = uhci_count_ports(hcd);
  16. /* Set up pointers to to generic functions */
  17. uhci->reset_hc = uhci_generic_reset_hc;
  18. uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
  19. /* No special actions need to be taken for the functions below */
  20. uhci->configure_hc = NULL;
  21. uhci->resume_detect_interrupts_are_broken = NULL;
  22. uhci->global_suspend_mode_is_broken = NULL;
  23. /* Reset if the controller isn't already safely quiescent. */
  24. check_and_reset_hc(uhci);
  25. return 0;
  26. }
  27. static const struct hc_driver uhci_platform_hc_driver = {
  28. .description = hcd_name,
  29. .product_desc = "Generic UHCI Host Controller",
  30. .hcd_priv_size = sizeof(struct uhci_hcd),
  31. /* Generic hardware linkage */
  32. .irq = uhci_irq,
  33. .flags = HCD_MEMORY | HCD_USB11,
  34. /* Basic lifecycle operations */
  35. .reset = uhci_platform_init,
  36. .start = uhci_start,
  37. #ifdef CONFIG_PM
  38. .pci_suspend = NULL,
  39. .pci_resume = NULL,
  40. .bus_suspend = uhci_rh_suspend,
  41. .bus_resume = uhci_rh_resume,
  42. #endif
  43. .stop = uhci_stop,
  44. .urb_enqueue = uhci_urb_enqueue,
  45. .urb_dequeue = uhci_urb_dequeue,
  46. .endpoint_disable = uhci_hcd_endpoint_disable,
  47. .get_frame_number = uhci_hcd_get_frame_number,
  48. .hub_status_data = uhci_hub_status_data,
  49. .hub_control = uhci_hub_control,
  50. };
  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. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  65. if (ret)
  66. return ret;
  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->regs = devm_ioremap_resource(&pdev->dev, res);
  73. if (IS_ERR(hcd->regs)) {
  74. ret = PTR_ERR(hcd->regs);
  75. goto err_rmr;
  76. }
  77. hcd->rsrc_start = res->start;
  78. hcd->rsrc_len = resource_size(res);
  79. uhci = hcd_to_uhci(hcd);
  80. uhci->regs = hcd->regs;
  81. ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
  82. if (ret)
  83. goto err_rmr;
  84. device_wakeup_enable(hcd->self.controller);
  85. return 0;
  86. err_rmr:
  87. usb_put_hcd(hcd);
  88. return ret;
  89. }
  90. static int uhci_hcd_platform_remove(struct platform_device *pdev)
  91. {
  92. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  93. usb_remove_hcd(hcd);
  94. usb_put_hcd(hcd);
  95. return 0;
  96. }
  97. /* Make sure the controller is quiescent and that we're not using it
  98. * any more. This is mainly for the benefit of programs which, like kexec,
  99. * expect the hardware to be idle: not doing DMA or generating IRQs.
  100. *
  101. * This routine may be called in a damaged or failing kernel. Hence we
  102. * do not acquire the spinlock before shutting down the controller.
  103. */
  104. static void uhci_hcd_platform_shutdown(struct platform_device *op)
  105. {
  106. struct usb_hcd *hcd = platform_get_drvdata(op);
  107. uhci_hc_died(hcd_to_uhci(hcd));
  108. }
  109. static const struct of_device_id platform_uhci_ids[] = {
  110. { .compatible = "generic-uhci", },
  111. { .compatible = "platform-uhci", },
  112. {}
  113. };
  114. MODULE_DEVICE_TABLE(of, platform_uhci_ids);
  115. static struct platform_driver uhci_platform_driver = {
  116. .probe = uhci_hcd_platform_probe,
  117. .remove = uhci_hcd_platform_remove,
  118. .shutdown = uhci_hcd_platform_shutdown,
  119. .driver = {
  120. .name = "platform-uhci",
  121. .of_match_table = platform_uhci_ids,
  122. },
  123. };