ehci-sh.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * SuperH EHCI host controller driver
  3. *
  4. * Copyright (C) 2010 Paul Mundt
  5. *
  6. * Based on ohci-sh.c and ehci-atmel.c.
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/clk.h>
  14. #include <linux/platform_data/ehci-sh.h>
  15. struct ehci_sh_priv {
  16. struct clk *iclk, *fclk;
  17. struct usb_hcd *hcd;
  18. };
  19. static int ehci_sh_reset(struct usb_hcd *hcd)
  20. {
  21. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  22. ehci->caps = hcd->regs;
  23. return ehci_setup(hcd);
  24. }
  25. static const struct hc_driver ehci_sh_hc_driver = {
  26. .description = hcd_name,
  27. .product_desc = "SuperH EHCI",
  28. .hcd_priv_size = sizeof(struct ehci_hcd),
  29. /*
  30. * generic hardware linkage
  31. */
  32. .irq = ehci_irq,
  33. .flags = HCD_USB2 | HCD_MEMORY | HCD_BH,
  34. /*
  35. * basic lifecycle operations
  36. */
  37. .reset = ehci_sh_reset,
  38. .start = ehci_run,
  39. .stop = ehci_stop,
  40. .shutdown = ehci_shutdown,
  41. /*
  42. * managing i/o requests and associated device resources
  43. */
  44. .urb_enqueue = ehci_urb_enqueue,
  45. .urb_dequeue = ehci_urb_dequeue,
  46. .endpoint_disable = ehci_endpoint_disable,
  47. .endpoint_reset = ehci_endpoint_reset,
  48. /*
  49. * scheduling support
  50. */
  51. .get_frame_number = ehci_get_frame,
  52. /*
  53. * root hub support
  54. */
  55. .hub_status_data = ehci_hub_status_data,
  56. .hub_control = ehci_hub_control,
  57. #ifdef CONFIG_PM
  58. .bus_suspend = ehci_bus_suspend,
  59. .bus_resume = ehci_bus_resume,
  60. #endif
  61. .relinquish_port = ehci_relinquish_port,
  62. .port_handed_over = ehci_port_handed_over,
  63. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  64. };
  65. static int ehci_hcd_sh_probe(struct platform_device *pdev)
  66. {
  67. struct resource *res;
  68. struct ehci_sh_priv *priv;
  69. struct ehci_sh_platdata *pdata;
  70. struct usb_hcd *hcd;
  71. int irq, ret;
  72. if (usb_disabled())
  73. return -ENODEV;
  74. irq = platform_get_irq(pdev, 0);
  75. if (irq <= 0) {
  76. dev_err(&pdev->dev,
  77. "Found HC with no IRQ. Check %s setup!\n",
  78. dev_name(&pdev->dev));
  79. ret = -ENODEV;
  80. goto fail_create_hcd;
  81. }
  82. pdata = dev_get_platdata(&pdev->dev);
  83. /* initialize hcd */
  84. hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
  85. dev_name(&pdev->dev));
  86. if (!hcd) {
  87. ret = -ENOMEM;
  88. goto fail_create_hcd;
  89. }
  90. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  91. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  92. if (IS_ERR(hcd->regs)) {
  93. ret = PTR_ERR(hcd->regs);
  94. goto fail_request_resource;
  95. }
  96. hcd->rsrc_start = res->start;
  97. hcd->rsrc_len = resource_size(res);
  98. priv = devm_kzalloc(&pdev->dev, sizeof(struct ehci_sh_priv),
  99. GFP_KERNEL);
  100. if (!priv) {
  101. ret = -ENOMEM;
  102. goto fail_request_resource;
  103. }
  104. /* These are optional, we don't care if they fail */
  105. priv->fclk = devm_clk_get(&pdev->dev, "usb_fck");
  106. if (IS_ERR(priv->fclk))
  107. priv->fclk = NULL;
  108. priv->iclk = devm_clk_get(&pdev->dev, "usb_ick");
  109. if (IS_ERR(priv->iclk))
  110. priv->iclk = NULL;
  111. clk_enable(priv->fclk);
  112. clk_enable(priv->iclk);
  113. if (pdata && pdata->phy_init)
  114. pdata->phy_init();
  115. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  116. if (ret != 0) {
  117. dev_err(&pdev->dev, "Failed to add hcd");
  118. goto fail_add_hcd;
  119. }
  120. device_wakeup_enable(hcd->self.controller);
  121. priv->hcd = hcd;
  122. platform_set_drvdata(pdev, priv);
  123. return ret;
  124. fail_add_hcd:
  125. clk_disable(priv->iclk);
  126. clk_disable(priv->fclk);
  127. fail_request_resource:
  128. usb_put_hcd(hcd);
  129. fail_create_hcd:
  130. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
  131. return ret;
  132. }
  133. static int ehci_hcd_sh_remove(struct platform_device *pdev)
  134. {
  135. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  136. struct usb_hcd *hcd = priv->hcd;
  137. usb_remove_hcd(hcd);
  138. usb_put_hcd(hcd);
  139. clk_disable(priv->fclk);
  140. clk_disable(priv->iclk);
  141. return 0;
  142. }
  143. static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
  144. {
  145. struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
  146. struct usb_hcd *hcd = priv->hcd;
  147. if (hcd->driver->shutdown)
  148. hcd->driver->shutdown(hcd);
  149. }
  150. static struct platform_driver ehci_hcd_sh_driver = {
  151. .probe = ehci_hcd_sh_probe,
  152. .remove = ehci_hcd_sh_remove,
  153. .shutdown = ehci_hcd_sh_shutdown,
  154. .driver = {
  155. .name = "sh_ehci",
  156. },
  157. };
  158. MODULE_ALIAS("platform:sh_ehci");