ci_hdrc_usb2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. *ci_pdata = ci_default_pdata; /* struct copy */
  48. }
  49. match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
  50. if (match && match->data) {
  51. /* struct copy */
  52. *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
  53. }
  54. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  55. if (!priv)
  56. return -ENOMEM;
  57. priv->clk = devm_clk_get(dev, NULL);
  58. if (!IS_ERR(priv->clk)) {
  59. ret = clk_prepare_enable(priv->clk);
  60. if (ret) {
  61. dev_err(dev, "failed to enable the clock: %d\n", ret);
  62. return ret;
  63. }
  64. }
  65. ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
  66. if (ret)
  67. goto clk_err;
  68. ci_pdata->name = dev_name(dev);
  69. priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
  70. pdev->num_resources, ci_pdata);
  71. if (IS_ERR(priv->ci_pdev)) {
  72. ret = PTR_ERR(priv->ci_pdev);
  73. if (ret != -EPROBE_DEFER)
  74. dev_err(dev,
  75. "failed to register ci_hdrc platform device: %d\n",
  76. ret);
  77. goto clk_err;
  78. }
  79. platform_set_drvdata(pdev, priv);
  80. pm_runtime_no_callbacks(dev);
  81. pm_runtime_enable(dev);
  82. return 0;
  83. clk_err:
  84. if (!IS_ERR(priv->clk))
  85. clk_disable_unprepare(priv->clk);
  86. return ret;
  87. }
  88. static int ci_hdrc_usb2_remove(struct platform_device *pdev)
  89. {
  90. struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
  91. pm_runtime_disable(&pdev->dev);
  92. ci_hdrc_remove_device(priv->ci_pdev);
  93. clk_disable_unprepare(priv->clk);
  94. return 0;
  95. }
  96. static struct platform_driver ci_hdrc_usb2_driver = {
  97. .probe = ci_hdrc_usb2_probe,
  98. .remove = ci_hdrc_usb2_remove,
  99. .driver = {
  100. .name = "chipidea-usb2",
  101. .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
  102. },
  103. };
  104. module_platform_driver(ci_hdrc_usb2_driver);
  105. MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
  106. MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
  107. MODULE_LICENSE("GPL");