dwc3-exynos.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 "core.h"
  24. struct dwc3_exynos {
  25. struct platform_device *dwc3;
  26. struct platform_device *usb2_phy;
  27. struct platform_device *usb3_phy;
  28. struct device *dev;
  29. struct clk *clk;
  30. };
  31. static int __devinit dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
  32. {
  33. struct nop_usb_xceiv_platform_data pdata;
  34. struct platform_device *pdev;
  35. int ret;
  36. memset(&pdata, 0x00, sizeof(pdata));
  37. pdev = platform_device_alloc("nop_usb_xceiv", 0);
  38. if (!pdev)
  39. return -ENOMEM;
  40. exynos->usb2_phy = pdev;
  41. pdata.type = USB_PHY_TYPE_USB2;
  42. ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
  43. if (ret)
  44. goto err1;
  45. pdev = platform_device_alloc("nop_usb_xceiv", 1);
  46. if (!pdev) {
  47. ret = -ENOMEM;
  48. goto err1;
  49. }
  50. exynos->usb3_phy = pdev;
  51. pdata.type = USB_PHY_TYPE_USB3;
  52. ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
  53. if (ret)
  54. goto err2;
  55. ret = platform_device_add(exynos->usb2_phy);
  56. if (ret)
  57. goto err2;
  58. ret = platform_device_add(exynos->usb3_phy);
  59. if (ret)
  60. goto err3;
  61. return 0;
  62. err3:
  63. platform_device_del(exynos->usb2_phy);
  64. err2:
  65. platform_device_put(exynos->usb3_phy);
  66. err1:
  67. platform_device_put(exynos->usb2_phy);
  68. return ret;
  69. }
  70. static int __devinit dwc3_exynos_probe(struct platform_device *pdev)
  71. {
  72. struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
  73. struct platform_device *dwc3;
  74. struct dwc3_exynos *exynos;
  75. struct clk *clk;
  76. int devid;
  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. platform_set_drvdata(pdev, exynos);
  84. devid = dwc3_get_device_id();
  85. if (devid < 0)
  86. goto err1;
  87. ret = dwc3_exynos_register_phys(exynos);
  88. if (ret) {
  89. dev_err(&pdev->dev, "couldn't register PHYs\n");
  90. goto err1;
  91. }
  92. dwc3 = platform_device_alloc("dwc3", devid);
  93. if (!dwc3) {
  94. dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
  95. goto err2;
  96. }
  97. clk = clk_get(&pdev->dev, "usbdrd30");
  98. if (IS_ERR(clk)) {
  99. dev_err(&pdev->dev, "couldn't get clock\n");
  100. ret = -EINVAL;
  101. goto err3;
  102. }
  103. dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
  104. dwc3->dev.parent = &pdev->dev;
  105. dwc3->dev.dma_mask = pdev->dev.dma_mask;
  106. dwc3->dev.dma_parms = pdev->dev.dma_parms;
  107. exynos->dwc3 = dwc3;
  108. exynos->dev = &pdev->dev;
  109. exynos->clk = clk;
  110. clk_enable(exynos->clk);
  111. /* PHY initialization */
  112. if (!pdata) {
  113. dev_dbg(&pdev->dev, "missing platform data\n");
  114. } else {
  115. if (pdata->phy_init)
  116. pdata->phy_init(pdev, pdata->phy_type);
  117. }
  118. ret = platform_device_add_resources(dwc3, pdev->resource,
  119. pdev->num_resources);
  120. if (ret) {
  121. dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
  122. goto err4;
  123. }
  124. ret = platform_device_add(dwc3);
  125. if (ret) {
  126. dev_err(&pdev->dev, "failed to register dwc3 device\n");
  127. goto err4;
  128. }
  129. return 0;
  130. err4:
  131. if (pdata && pdata->phy_exit)
  132. pdata->phy_exit(pdev, pdata->phy_type);
  133. clk_disable(clk);
  134. clk_put(clk);
  135. err3:
  136. platform_device_put(dwc3);
  137. err2:
  138. dwc3_put_device_id(devid);
  139. err1:
  140. kfree(exynos);
  141. err0:
  142. return ret;
  143. }
  144. static int __devexit dwc3_exynos_remove(struct platform_device *pdev)
  145. {
  146. struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
  147. struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
  148. platform_device_unregister(exynos->dwc3);
  149. platform_device_unregister(exynos->usb2_phy);
  150. platform_device_unregister(exynos->usb3_phy);
  151. dwc3_put_device_id(exynos->dwc3->id);
  152. if (pdata && pdata->phy_exit)
  153. pdata->phy_exit(pdev, pdata->phy_type);
  154. clk_disable(exynos->clk);
  155. clk_put(exynos->clk);
  156. kfree(exynos);
  157. return 0;
  158. }
  159. static struct platform_driver dwc3_exynos_driver = {
  160. .probe = dwc3_exynos_probe,
  161. .remove = __devexit_p(dwc3_exynos_remove),
  162. .driver = {
  163. .name = "exynos-dwc3",
  164. },
  165. };
  166. module_platform_driver(dwc3_exynos_driver);
  167. MODULE_ALIAS("platform:exynos-dwc3");
  168. MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
  169. MODULE_LICENSE("GPL");
  170. MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");