coresight-replicator.c 4.2 KB

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