uhci-platform.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* Probe number of ports if not already provided by DT */
  16. if (!uhci->rh_numports)
  17. uhci->rh_numports = uhci_count_ports(hcd);
  18. /* Set up pointers to to generic functions */
  19. uhci->reset_hc = uhci_generic_reset_hc;
  20. uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
  21. /* No special actions need to be taken for the functions below */
  22. uhci->configure_hc = NULL;
  23. uhci->resume_detect_interrupts_are_broken = NULL;
  24. uhci->global_suspend_mode_is_broken = NULL;
  25. /* Reset if the controller isn't already safely quiescent. */
  26. check_and_reset_hc(uhci);
  27. return 0;
  28. }
  29. static const struct hc_driver uhci_platform_hc_driver = {
  30. .description = hcd_name,
  31. .product_desc = "Generic UHCI Host Controller",
  32. .hcd_priv_size = sizeof(struct uhci_hcd),
  33. /* Generic hardware linkage */
  34. .irq = uhci_irq,
  35. .flags = HCD_MEMORY | HCD_USB11,
  36. /* Basic lifecycle operations */
  37. .reset = uhci_platform_init,
  38. .start = uhci_start,
  39. #ifdef CONFIG_PM
  40. .pci_suspend = NULL,
  41. .pci_resume = NULL,
  42. .bus_suspend = uhci_rh_suspend,
  43. .bus_resume = uhci_rh_resume,
  44. #endif
  45. .stop = uhci_stop,
  46. .urb_enqueue = uhci_urb_enqueue,
  47. .urb_dequeue = uhci_urb_dequeue,
  48. .endpoint_disable = uhci_hcd_endpoint_disable,
  49. .get_frame_number = uhci_hcd_get_frame_number,
  50. .hub_status_data = uhci_hub_status_data,
  51. .hub_control = uhci_hub_control,
  52. };
  53. static int uhci_hcd_platform_probe(struct platform_device *pdev)
  54. {
  55. struct device_node *np = pdev->dev.of_node;
  56. struct usb_hcd *hcd;
  57. struct uhci_hcd *uhci;
  58. struct resource *res;
  59. int ret;
  60. if (usb_disabled())
  61. return -ENODEV;
  62. /*
  63. * Right now device-tree probed devices don't get dma_mask set.
  64. * Since shared usb code relies on it, set it here for now.
  65. * Once we have dma capability bindings this can go away.
  66. */
  67. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  68. if (ret)
  69. return ret;
  70. hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
  71. pdev->name);
  72. if (!hcd)
  73. return -ENOMEM;
  74. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  75. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  76. if (IS_ERR(hcd->regs)) {
  77. ret = PTR_ERR(hcd->regs);
  78. goto err_rmr;
  79. }
  80. hcd->rsrc_start = res->start;
  81. hcd->rsrc_len = resource_size(res);
  82. uhci = hcd_to_uhci(hcd);
  83. uhci->regs = hcd->regs;
  84. /* Grab some things from the device-tree */
  85. if (np) {
  86. u32 num_ports;
  87. if (of_property_read_u32(np, "#ports", &num_ports) == 0) {
  88. uhci->rh_numports = num_ports;
  89. dev_info(&pdev->dev,
  90. "Detected %d ports from device-tree\n",
  91. num_ports);
  92. }
  93. if (of_device_is_compatible(np, "aspeed,ast2400-uhci") ||
  94. of_device_is_compatible(np, "aspeed,ast2500-uhci")) {
  95. uhci->is_aspeed = 1;
  96. dev_info(&pdev->dev,
  97. "Enabled Aspeed implementation workarounds\n");
  98. }
  99. }
  100. ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
  101. if (ret)
  102. goto err_rmr;
  103. device_wakeup_enable(hcd->self.controller);
  104. return 0;
  105. err_rmr:
  106. usb_put_hcd(hcd);
  107. return ret;
  108. }
  109. static int uhci_hcd_platform_remove(struct platform_device *pdev)
  110. {
  111. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  112. usb_remove_hcd(hcd);
  113. usb_put_hcd(hcd);
  114. return 0;
  115. }
  116. /* Make sure the controller is quiescent and that we're not using it
  117. * any more. This is mainly for the benefit of programs which, like kexec,
  118. * expect the hardware to be idle: not doing DMA or generating IRQs.
  119. *
  120. * This routine may be called in a damaged or failing kernel. Hence we
  121. * do not acquire the spinlock before shutting down the controller.
  122. */
  123. static void uhci_hcd_platform_shutdown(struct platform_device *op)
  124. {
  125. struct usb_hcd *hcd = platform_get_drvdata(op);
  126. uhci_hc_died(hcd_to_uhci(hcd));
  127. }
  128. static const struct of_device_id platform_uhci_ids[] = {
  129. { .compatible = "generic-uhci", },
  130. { .compatible = "platform-uhci", },
  131. {}
  132. };
  133. MODULE_DEVICE_TABLE(of, platform_uhci_ids);
  134. static struct platform_driver uhci_platform_driver = {
  135. .probe = uhci_hcd_platform_probe,
  136. .remove = uhci_hcd_platform_remove,
  137. .shutdown = uhci_hcd_platform_shutdown,
  138. .driver = {
  139. .name = "platform-uhci",
  140. .of_match_table = platform_uhci_ids,
  141. },
  142. };