ci_hdrc_usb2.c 2.7 KB

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