ci_hdrc_usb2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Antoine Tenart <antoine.tenart@free-electrons.com>
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/phy/phy.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/usb/chipidea.h>
  18. #include <linux/usb/hcd.h>
  19. #include <linux/usb/ulpi.h>
  20. #include "ci.h"
  21. struct ci_hdrc_usb2_priv {
  22. struct platform_device *ci_pdev;
  23. struct clk *clk;
  24. };
  25. static const struct ci_hdrc_platform_data ci_default_pdata = {
  26. .capoffset = DEF_CAPOFFSET,
  27. .flags = CI_HDRC_DISABLE_STREAMING,
  28. };
  29. static struct ci_hdrc_platform_data ci_zynq_pdata = {
  30. .capoffset = DEF_CAPOFFSET,
  31. };
  32. static const struct of_device_id ci_hdrc_usb2_of_match[] = {
  33. { .compatible = "chipidea,usb2"},
  34. { .compatible = "xlnx,zynq-usb-2.20a", .data = &ci_zynq_pdata},
  35. { }
  36. };
  37. MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
  38. static int ci_hdrc_usb2_probe(struct platform_device *pdev)
  39. {
  40. struct device *dev = &pdev->dev;
  41. struct ci_hdrc_usb2_priv *priv;
  42. struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
  43. int ret;
  44. const struct of_device_id *match;
  45. if (!ci_pdata) {
  46. ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
  47. if (!ci_pdata)
  48. return -ENOMEM;
  49. *ci_pdata = ci_default_pdata; /* struct copy */
  50. }
  51. match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
  52. if (match && match->data) {
  53. /* struct copy */
  54. *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
  55. }
  56. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  57. if (!priv)
  58. return -ENOMEM;
  59. priv->clk = devm_clk_get(dev, NULL);
  60. if (!IS_ERR(priv->clk)) {
  61. ret = clk_prepare_enable(priv->clk);
  62. if (ret) {
  63. dev_err(dev, "failed to enable the clock: %d\n", ret);
  64. return ret;
  65. }
  66. }
  67. ci_pdata->name = dev_name(dev);
  68. priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
  69. pdev->num_resources, ci_pdata);
  70. if (IS_ERR(priv->ci_pdev)) {
  71. ret = PTR_ERR(priv->ci_pdev);
  72. if (ret != -EPROBE_DEFER)
  73. dev_err(dev,
  74. "failed to register ci_hdrc platform device: %d\n",
  75. ret);
  76. goto clk_err;
  77. }
  78. platform_set_drvdata(pdev, priv);
  79. pm_runtime_no_callbacks(dev);
  80. pm_runtime_enable(dev);
  81. return 0;
  82. clk_err:
  83. if (!IS_ERR(priv->clk))
  84. clk_disable_unprepare(priv->clk);
  85. return ret;
  86. }
  87. static int ci_hdrc_usb2_remove(struct platform_device *pdev)
  88. {
  89. struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
  90. pm_runtime_disable(&pdev->dev);
  91. ci_hdrc_remove_device(priv->ci_pdev);
  92. clk_disable_unprepare(priv->clk);
  93. return 0;
  94. }
  95. static struct platform_driver ci_hdrc_usb2_driver = {
  96. .probe = ci_hdrc_usb2_probe,
  97. .remove = ci_hdrc_usb2_remove,
  98. .driver = {
  99. .name = "chipidea-usb2",
  100. .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
  101. },
  102. };
  103. module_platform_driver(ci_hdrc_usb2_driver);
  104. MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
  105. MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
  106. MODULE_LICENSE("GPL");