dwc3-exynos.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/slab.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/platform_data/dwc3-exynos.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/clk.h>
  21. #include <linux/usb/otg.h>
  22. #include <linux/usb/nop-usb-xceiv.h>
  23. #include <linux/of.h>
  24. #include "core.h"
  25. struct dwc3_exynos {
  26. struct platform_device *dwc3;
  27. struct platform_device *usb2_phy;
  28. struct platform_device *usb3_phy;
  29. struct device *dev;
  30. struct clk *clk;
  31. };
  32. static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
  33. {
  34. struct nop_usb_xceiv_platform_data pdata;
  35. struct platform_device *pdev;
  36. int ret;
  37. memset(&pdata, 0x00, sizeof(pdata));
  38. pdev = platform_device_alloc("nop_usb_xceiv", 0);
  39. if (!pdev)
  40. return -ENOMEM;
  41. exynos->usb2_phy = pdev;
  42. pdata.type = USB_PHY_TYPE_USB2;
  43. ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
  44. if (ret)
  45. goto err1;
  46. pdev = platform_device_alloc("nop_usb_xceiv", 1);
  47. if (!pdev) {
  48. ret = -ENOMEM;
  49. goto err1;
  50. }
  51. exynos->usb3_phy = pdev;
  52. pdata.type = USB_PHY_TYPE_USB3;
  53. ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
  54. if (ret)
  55. goto err2;
  56. ret = platform_device_add(exynos->usb2_phy);
  57. if (ret)
  58. goto err2;
  59. ret = platform_device_add(exynos->usb3_phy);
  60. if (ret)
  61. goto err3;
  62. return 0;
  63. err3:
  64. platform_device_del(exynos->usb2_phy);
  65. err2:
  66. platform_device_put(exynos->usb3_phy);
  67. err1:
  68. platform_device_put(exynos->usb2_phy);
  69. return ret;
  70. }
  71. static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
  72. static int dwc3_exynos_probe(struct platform_device *pdev)
  73. {
  74. struct platform_device *dwc3;
  75. struct dwc3_exynos *exynos;
  76. struct clk *clk;
  77. int ret = -ENOMEM;
  78. exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
  79. if (!exynos) {
  80. dev_err(&pdev->dev, "not enough memory\n");
  81. goto err0;
  82. }
  83. /*
  84. * Right now device-tree probed devices don't get dma_mask set.
  85. * Since shared usb code relies on it, set it here for now.
  86. * Once we move to full device tree support this will vanish off.
  87. */
  88. if (!pdev->dev.dma_mask)
  89. pdev->dev.dma_mask = &dwc3_exynos_dma_mask;
  90. platform_set_drvdata(pdev, exynos);
  91. ret = dwc3_exynos_register_phys(exynos);
  92. if (ret) {
  93. dev_err(&pdev->dev, "couldn't register PHYs\n");
  94. goto err1;
  95. }
  96. dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
  97. if (!dwc3) {
  98. dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
  99. goto err1;
  100. }
  101. clk = clk_get(&pdev->dev, "usbdrd30");
  102. if (IS_ERR(clk)) {
  103. dev_err(&pdev->dev, "couldn't get clock\n");
  104. ret = -EINVAL;
  105. goto err3;
  106. }
  107. dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
  108. dwc3->dev.parent = &pdev->dev;
  109. dwc3->dev.dma_mask = pdev->dev.dma_mask;
  110. dwc3->dev.dma_parms = pdev->dev.dma_parms;
  111. exynos->dwc3 = dwc3;
  112. exynos->dev = &pdev->dev;
  113. exynos->clk = clk;
  114. clk_enable(exynos->clk);
  115. ret = platform_device_add_resources(dwc3, pdev->resource,
  116. pdev->num_resources);
  117. if (ret) {
  118. dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
  119. goto err4;
  120. }
  121. ret = platform_device_add(dwc3);
  122. if (ret) {
  123. dev_err(&pdev->dev, "failed to register dwc3 device\n");
  124. goto err4;
  125. }
  126. return 0;
  127. err4:
  128. clk_disable(clk);
  129. clk_put(clk);
  130. err3:
  131. platform_device_put(dwc3);
  132. err1:
  133. kfree(exynos);
  134. err0:
  135. return ret;
  136. }
  137. static int dwc3_exynos_remove(struct platform_device *pdev)
  138. {
  139. struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
  140. platform_device_unregister(exynos->dwc3);
  141. platform_device_unregister(exynos->usb2_phy);
  142. platform_device_unregister(exynos->usb3_phy);
  143. clk_disable(exynos->clk);
  144. clk_put(exynos->clk);
  145. kfree(exynos);
  146. return 0;
  147. }
  148. #ifdef CONFIG_OF
  149. static const struct of_device_id exynos_dwc3_match[] = {
  150. { .compatible = "samsung,exynos-dwc3" },
  151. {},
  152. };
  153. MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
  154. #endif
  155. static struct platform_driver dwc3_exynos_driver = {
  156. .probe = dwc3_exynos_probe,
  157. .remove = dwc3_exynos_remove,
  158. .driver = {
  159. .name = "exynos-dwc3",
  160. .of_match_table = of_match_ptr(exynos_dwc3_match),
  161. },
  162. };
  163. module_platform_driver(dwc3_exynos_driver);
  164. MODULE_ALIAS("platform:exynos-dwc3");
  165. MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
  166. MODULE_LICENSE("GPL");
  167. MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");