ci_hdrc_usb2.c 2.8 KB

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