ci_hdrc_usb2.c 3.0 KB

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