ehci-s5p.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * SAMSUNG S5P USB HOST EHCI Controller
  3. *
  4. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  5. * Author: Jingoo Han <jg1.han@samsung.com>
  6. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/platform_device.h>
  16. #include <mach/regs-pmu.h>
  17. #include <plat/cpu.h>
  18. #include <plat/ehci.h>
  19. #include <plat/usb-phy.h>
  20. struct s5p_ehci_hcd {
  21. struct device *dev;
  22. struct usb_hcd *hcd;
  23. struct clk *clk;
  24. };
  25. static const struct hc_driver s5p_ehci_hc_driver = {
  26. .description = hcd_name,
  27. .product_desc = "S5P EHCI Host Controller",
  28. .hcd_priv_size = sizeof(struct ehci_hcd),
  29. .irq = ehci_irq,
  30. .flags = HCD_MEMORY | HCD_USB2,
  31. .reset = ehci_init,
  32. .start = ehci_run,
  33. .stop = ehci_stop,
  34. .shutdown = ehci_shutdown,
  35. .get_frame_number = ehci_get_frame,
  36. .urb_enqueue = ehci_urb_enqueue,
  37. .urb_dequeue = ehci_urb_dequeue,
  38. .endpoint_disable = ehci_endpoint_disable,
  39. .endpoint_reset = ehci_endpoint_reset,
  40. .hub_status_data = ehci_hub_status_data,
  41. .hub_control = ehci_hub_control,
  42. .bus_suspend = ehci_bus_suspend,
  43. .bus_resume = ehci_bus_resume,
  44. .relinquish_port = ehci_relinquish_port,
  45. .port_handed_over = ehci_port_handed_over,
  46. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  47. };
  48. static int __devinit s5p_ehci_probe(struct platform_device *pdev)
  49. {
  50. struct s5p_ehci_platdata *pdata;
  51. struct s5p_ehci_hcd *s5p_ehci;
  52. struct usb_hcd *hcd;
  53. struct ehci_hcd *ehci;
  54. struct resource *res;
  55. int irq;
  56. int err;
  57. pdata = pdev->dev.platform_data;
  58. if (!pdata) {
  59. dev_err(&pdev->dev, "No platform data defined\n");
  60. return -EINVAL;
  61. }
  62. s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL);
  63. if (!s5p_ehci)
  64. return -ENOMEM;
  65. s5p_ehci->dev = &pdev->dev;
  66. hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
  67. dev_name(&pdev->dev));
  68. if (!hcd) {
  69. dev_err(&pdev->dev, "Unable to create HCD\n");
  70. err = -ENOMEM;
  71. goto fail_hcd;
  72. }
  73. s5p_ehci->hcd = hcd;
  74. s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
  75. if (IS_ERR(s5p_ehci->clk)) {
  76. dev_err(&pdev->dev, "Failed to get usbhost clock\n");
  77. err = PTR_ERR(s5p_ehci->clk);
  78. goto fail_clk;
  79. }
  80. err = clk_enable(s5p_ehci->clk);
  81. if (err)
  82. goto fail_clken;
  83. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  84. if (!res) {
  85. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  86. err = -ENXIO;
  87. goto fail_io;
  88. }
  89. hcd->rsrc_start = res->start;
  90. hcd->rsrc_len = resource_size(res);
  91. hcd->regs = ioremap(res->start, resource_size(res));
  92. if (!hcd->regs) {
  93. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  94. err = -ENOMEM;
  95. goto fail_io;
  96. }
  97. irq = platform_get_irq(pdev, 0);
  98. if (!irq) {
  99. dev_err(&pdev->dev, "Failed to get IRQ\n");
  100. err = -ENODEV;
  101. goto fail;
  102. }
  103. if (pdata->phy_init)
  104. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  105. ehci = hcd_to_ehci(hcd);
  106. ehci->caps = hcd->regs;
  107. ehci->regs = hcd->regs +
  108. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  109. dbg_hcs_params(ehci, "reset");
  110. dbg_hcc_params(ehci, "reset");
  111. /* cache this readonly data; minimize chip reads */
  112. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  113. err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  114. if (err) {
  115. dev_err(&pdev->dev, "Failed to add USB HCD\n");
  116. goto fail;
  117. }
  118. platform_set_drvdata(pdev, s5p_ehci);
  119. return 0;
  120. fail:
  121. iounmap(hcd->regs);
  122. fail_io:
  123. clk_disable(s5p_ehci->clk);
  124. fail_clken:
  125. clk_put(s5p_ehci->clk);
  126. fail_clk:
  127. usb_put_hcd(hcd);
  128. fail_hcd:
  129. kfree(s5p_ehci);
  130. return err;
  131. }
  132. static int __devexit s5p_ehci_remove(struct platform_device *pdev)
  133. {
  134. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  135. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  136. struct usb_hcd *hcd = s5p_ehci->hcd;
  137. usb_remove_hcd(hcd);
  138. if (pdata && pdata->phy_exit)
  139. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  140. iounmap(hcd->regs);
  141. clk_disable(s5p_ehci->clk);
  142. clk_put(s5p_ehci->clk);
  143. usb_put_hcd(hcd);
  144. kfree(s5p_ehci);
  145. return 0;
  146. }
  147. static void s5p_ehci_shutdown(struct platform_device *pdev)
  148. {
  149. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  150. struct usb_hcd *hcd = s5p_ehci->hcd;
  151. if (hcd->driver->shutdown)
  152. hcd->driver->shutdown(hcd);
  153. }
  154. static struct platform_driver s5p_ehci_driver = {
  155. .probe = s5p_ehci_probe,
  156. .remove = __devexit_p(s5p_ehci_remove),
  157. .shutdown = s5p_ehci_shutdown,
  158. .driver = {
  159. .name = "s5p-ehci",
  160. .owner = THIS_MODULE,
  161. }
  162. };
  163. MODULE_ALIAS("platform:s5p-ehci");