dwc3-exynos.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 "core.h"
  22. struct dwc3_exynos {
  23. struct platform_device *dwc3;
  24. struct device *dev;
  25. struct clk *clk;
  26. };
  27. static int __devinit dwc3_exynos_probe(struct platform_device *pdev)
  28. {
  29. struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
  30. struct platform_device *dwc3;
  31. struct dwc3_exynos *exynos;
  32. struct clk *clk;
  33. int devid;
  34. int ret = -ENOMEM;
  35. exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
  36. if (!exynos) {
  37. dev_err(&pdev->dev, "not enough memory\n");
  38. goto err0;
  39. }
  40. platform_set_drvdata(pdev, exynos);
  41. devid = dwc3_get_device_id();
  42. if (devid < 0)
  43. goto err1;
  44. dwc3 = platform_device_alloc("dwc3", devid);
  45. if (!dwc3) {
  46. dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
  47. goto err2;
  48. }
  49. clk = clk_get(&pdev->dev, "usbdrd30");
  50. if (IS_ERR(clk)) {
  51. dev_err(&pdev->dev, "couldn't get clock\n");
  52. ret = -EINVAL;
  53. goto err3;
  54. }
  55. dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
  56. dwc3->dev.parent = &pdev->dev;
  57. dwc3->dev.dma_mask = pdev->dev.dma_mask;
  58. dwc3->dev.dma_parms = pdev->dev.dma_parms;
  59. exynos->dwc3 = dwc3;
  60. exynos->dev = &pdev->dev;
  61. exynos->clk = clk;
  62. clk_enable(exynos->clk);
  63. /* PHY initialization */
  64. if (!pdata) {
  65. dev_dbg(&pdev->dev, "missing platform data\n");
  66. } else {
  67. if (pdata->phy_init)
  68. pdata->phy_init(pdev, pdata->phy_type);
  69. }
  70. ret = platform_device_add_resources(dwc3, pdev->resource,
  71. pdev->num_resources);
  72. if (ret) {
  73. dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
  74. goto err4;
  75. }
  76. ret = platform_device_add(dwc3);
  77. if (ret) {
  78. dev_err(&pdev->dev, "failed to register dwc3 device\n");
  79. goto err4;
  80. }
  81. return 0;
  82. err4:
  83. if (pdata && pdata->phy_exit)
  84. pdata->phy_exit(pdev, pdata->phy_type);
  85. clk_disable(clk);
  86. clk_put(clk);
  87. err3:
  88. platform_device_put(dwc3);
  89. err2:
  90. dwc3_put_device_id(devid);
  91. err1:
  92. kfree(exynos);
  93. err0:
  94. return ret;
  95. }
  96. static int __devexit dwc3_exynos_remove(struct platform_device *pdev)
  97. {
  98. struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
  99. struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
  100. platform_device_unregister(exynos->dwc3);
  101. dwc3_put_device_id(exynos->dwc3->id);
  102. if (pdata && pdata->phy_exit)
  103. pdata->phy_exit(pdev, pdata->phy_type);
  104. clk_disable(exynos->clk);
  105. clk_put(exynos->clk);
  106. kfree(exynos);
  107. return 0;
  108. }
  109. static struct platform_driver dwc3_exynos_driver = {
  110. .probe = dwc3_exynos_probe,
  111. .remove = __devexit_p(dwc3_exynos_remove),
  112. .driver = {
  113. .name = "exynos-dwc3",
  114. },
  115. };
  116. module_platform_driver(dwc3_exynos_driver);
  117. MODULE_ALIAS("platform:exynos-dwc3");
  118. MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
  119. MODULE_LICENSE("GPL");
  120. MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");