ehci-s5p.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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->clk = clk_get(&pdev->dev, "usbhost");
  74. if (IS_ERR(s5p_ehci->clk)) {
  75. dev_err(&pdev->dev, "Failed to get usbhost clock\n");
  76. err = PTR_ERR(s5p_ehci->clk);
  77. goto fail_clk;
  78. }
  79. err = clk_enable(s5p_ehci->clk);
  80. if (err)
  81. goto fail_clken;
  82. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  83. if (!res) {
  84. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  85. err = -ENXIO;
  86. goto fail_io;
  87. }
  88. hcd->rsrc_start = res->start;
  89. hcd->rsrc_len = resource_size(res);
  90. hcd->regs = ioremap(res->start, resource_size(res));
  91. if (!hcd->regs) {
  92. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  93. err = -ENOMEM;
  94. goto fail_io;
  95. }
  96. irq = platform_get_irq(pdev, 0);
  97. if (!irq) {
  98. dev_err(&pdev->dev, "Failed to get IRQ\n");
  99. err = -ENODEV;
  100. goto fail;
  101. }
  102. if (pdata->phy_init)
  103. pdata->phy_init(pdev, S5P_USB_PHY_HOST);
  104. ehci = hcd_to_ehci(hcd);
  105. ehci->caps = hcd->regs;
  106. ehci->regs = hcd->regs +
  107. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  108. dbg_hcs_params(ehci, "reset");
  109. dbg_hcc_params(ehci, "reset");
  110. /* cache this readonly data; minimize chip reads */
  111. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  112. err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  113. if (err) {
  114. dev_err(&pdev->dev, "Failed to add USB HCD\n");
  115. goto fail;
  116. }
  117. platform_set_drvdata(pdev, s5p_ehci);
  118. return 0;
  119. fail:
  120. iounmap(hcd->regs);
  121. fail_io:
  122. clk_disable(s5p_ehci->clk);
  123. fail_clken:
  124. clk_put(s5p_ehci->clk);
  125. fail_clk:
  126. usb_put_hcd(hcd);
  127. fail_hcd:
  128. kfree(s5p_ehci);
  129. return err;
  130. }
  131. static int __devexit s5p_ehci_remove(struct platform_device *pdev)
  132. {
  133. struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
  134. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  135. struct usb_hcd *hcd = s5p_ehci->hcd;
  136. usb_remove_hcd(hcd);
  137. if (pdata && pdata->phy_exit)
  138. pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
  139. iounmap(hcd->regs);
  140. clk_disable(s5p_ehci->clk);
  141. clk_put(s5p_ehci->clk);
  142. usb_put_hcd(hcd);
  143. kfree(s5p_ehci);
  144. return 0;
  145. }
  146. static void s5p_ehci_shutdown(struct platform_device *pdev)
  147. {
  148. struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
  149. struct usb_hcd *hcd = s5p_ehci->hcd;
  150. if (hcd->driver->shutdown)
  151. hcd->driver->shutdown(hcd);
  152. }
  153. static struct platform_driver s5p_ehci_driver = {
  154. .probe = s5p_ehci_probe,
  155. .remove = __devexit_p(s5p_ehci_remove),
  156. .shutdown = s5p_ehci_shutdown,
  157. .driver = {
  158. .name = "s5p-ehci",
  159. .owner = THIS_MODULE,
  160. }
  161. };
  162. MODULE_ALIAS("platform:s5p-ehci");