coresight-replicator.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  4. *
  5. * Description: CoreSight Replicator driver
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/device.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/io.h>
  11. #include <linux/err.h>
  12. #include <linux/slab.h>
  13. #include <linux/pm_runtime.h>
  14. #include <linux/clk.h>
  15. #include <linux/of.h>
  16. #include <linux/coresight.h>
  17. #include "coresight-priv.h"
  18. /**
  19. * struct replicator_drvdata - specifics associated to a replicator component
  20. * @dev: the device entity associated with this component
  21. * @atclk: optional clock for the core parts of the replicator.
  22. * @csdev: component vitals needed by the framework
  23. */
  24. struct replicator_drvdata {
  25. struct device *dev;
  26. struct clk *atclk;
  27. struct coresight_device *csdev;
  28. };
  29. static int replicator_enable(struct coresight_device *csdev, int inport,
  30. int outport)
  31. {
  32. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  33. dev_dbg(drvdata->dev, "REPLICATOR enabled\n");
  34. return 0;
  35. }
  36. static void replicator_disable(struct coresight_device *csdev, int inport,
  37. int outport)
  38. {
  39. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  40. dev_dbg(drvdata->dev, "REPLICATOR disabled\n");
  41. }
  42. static const struct coresight_ops_link replicator_link_ops = {
  43. .enable = replicator_enable,
  44. .disable = replicator_disable,
  45. };
  46. static const struct coresight_ops replicator_cs_ops = {
  47. .link_ops = &replicator_link_ops,
  48. };
  49. static int replicator_probe(struct platform_device *pdev)
  50. {
  51. int ret;
  52. struct device *dev = &pdev->dev;
  53. struct coresight_platform_data *pdata = NULL;
  54. struct replicator_drvdata *drvdata;
  55. struct coresight_desc desc = { 0 };
  56. struct device_node *np = pdev->dev.of_node;
  57. if (np) {
  58. pdata = of_get_coresight_platform_data(dev, np);
  59. if (IS_ERR(pdata))
  60. return PTR_ERR(pdata);
  61. pdev->dev.platform_data = pdata;
  62. }
  63. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  64. if (!drvdata)
  65. return -ENOMEM;
  66. drvdata->dev = &pdev->dev;
  67. drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */
  68. if (!IS_ERR(drvdata->atclk)) {
  69. ret = clk_prepare_enable(drvdata->atclk);
  70. if (ret)
  71. return ret;
  72. }
  73. pm_runtime_get_noresume(&pdev->dev);
  74. pm_runtime_set_active(&pdev->dev);
  75. pm_runtime_enable(&pdev->dev);
  76. platform_set_drvdata(pdev, drvdata);
  77. desc.type = CORESIGHT_DEV_TYPE_LINK;
  78. desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  79. desc.ops = &replicator_cs_ops;
  80. desc.pdata = pdev->dev.platform_data;
  81. desc.dev = &pdev->dev;
  82. drvdata->csdev = coresight_register(&desc);
  83. if (IS_ERR(drvdata->csdev)) {
  84. ret = PTR_ERR(drvdata->csdev);
  85. goto out_disable_pm;
  86. }
  87. pm_runtime_put(&pdev->dev);
  88. return 0;
  89. out_disable_pm:
  90. if (!IS_ERR(drvdata->atclk))
  91. clk_disable_unprepare(drvdata->atclk);
  92. pm_runtime_put_noidle(&pdev->dev);
  93. pm_runtime_disable(&pdev->dev);
  94. return ret;
  95. }
  96. #ifdef CONFIG_PM
  97. static int replicator_runtime_suspend(struct device *dev)
  98. {
  99. struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
  100. if (drvdata && !IS_ERR(drvdata->atclk))
  101. clk_disable_unprepare(drvdata->atclk);
  102. return 0;
  103. }
  104. static int replicator_runtime_resume(struct device *dev)
  105. {
  106. struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
  107. if (drvdata && !IS_ERR(drvdata->atclk))
  108. clk_prepare_enable(drvdata->atclk);
  109. return 0;
  110. }
  111. #endif
  112. static const struct dev_pm_ops replicator_dev_pm_ops = {
  113. SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
  114. replicator_runtime_resume, NULL)
  115. };
  116. static const struct of_device_id replicator_match[] = {
  117. {.compatible = "arm,coresight-replicator"},
  118. {}
  119. };
  120. static struct platform_driver replicator_driver = {
  121. .probe = replicator_probe,
  122. .driver = {
  123. .name = "coresight-replicator",
  124. .of_match_table = replicator_match,
  125. .pm = &replicator_dev_pm_ops,
  126. .suppress_bind_attrs = true,
  127. },
  128. };
  129. builtin_platform_driver(replicator_driver);