uhci-platform.c 4.8 KB

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