coresight-dynamic-replicator.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/amba/bus.h>
  6. #include <linux/clk.h>
  7. #include <linux/coresight.h>
  8. #include <linux/device.h>
  9. #include <linux/err.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/kernel.h>
  13. #include <linux/of.h>
  14. #include <linux/pm_runtime.h>
  15. #include <linux/slab.h>
  16. #include "coresight-priv.h"
  17. #define REPLICATOR_IDFILTER0 0x000
  18. #define REPLICATOR_IDFILTER1 0x004
  19. /**
  20. * struct replicator_state - specifics associated to a replicator component
  21. * @base: memory mapped base address for this component.
  22. * @dev: the device entity associated with this component
  23. * @atclk: optional clock for the core parts of the replicator.
  24. * @csdev: component vitals needed by the framework
  25. */
  26. struct replicator_state {
  27. void __iomem *base;
  28. struct device *dev;
  29. struct clk *atclk;
  30. struct coresight_device *csdev;
  31. };
  32. static int replicator_enable(struct coresight_device *csdev, int inport,
  33. int outport)
  34. {
  35. struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
  36. CS_UNLOCK(drvdata->base);
  37. /*
  38. * Ensure that the other port is disabled
  39. * 0x00 - passing through the replicator unimpeded
  40. * 0xff - disable (or impede) the flow of ATB data
  41. */
  42. if (outport == 0) {
  43. writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER0);
  44. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
  45. } else {
  46. writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER1);
  47. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
  48. }
  49. CS_LOCK(drvdata->base);
  50. dev_info(drvdata->dev, "REPLICATOR enabled\n");
  51. return 0;
  52. }
  53. static void replicator_disable(struct coresight_device *csdev, int inport,
  54. int outport)
  55. {
  56. struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
  57. CS_UNLOCK(drvdata->base);
  58. /* disable the flow of ATB data through port */
  59. if (outport == 0)
  60. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
  61. else
  62. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
  63. CS_LOCK(drvdata->base);
  64. dev_info(drvdata->dev, "REPLICATOR disabled\n");
  65. }
  66. static const struct coresight_ops_link replicator_link_ops = {
  67. .enable = replicator_enable,
  68. .disable = replicator_disable,
  69. };
  70. static const struct coresight_ops replicator_cs_ops = {
  71. .link_ops = &replicator_link_ops,
  72. };
  73. #define coresight_replicator_reg(name, offset) \
  74. coresight_simple_reg32(struct replicator_state, name, offset)
  75. coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
  76. coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
  77. static struct attribute *replicator_mgmt_attrs[] = {
  78. &dev_attr_idfilter0.attr,
  79. &dev_attr_idfilter1.attr,
  80. NULL,
  81. };
  82. static const struct attribute_group replicator_mgmt_group = {
  83. .attrs = replicator_mgmt_attrs,
  84. .name = "mgmt",
  85. };
  86. static const struct attribute_group *replicator_groups[] = {
  87. &replicator_mgmt_group,
  88. NULL,
  89. };
  90. static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
  91. {
  92. int ret;
  93. struct device *dev = &adev->dev;
  94. struct resource *res = &adev->res;
  95. struct coresight_platform_data *pdata = NULL;
  96. struct replicator_state *drvdata;
  97. struct coresight_desc desc = { 0 };
  98. struct device_node *np = adev->dev.of_node;
  99. void __iomem *base;
  100. if (np) {
  101. pdata = of_get_coresight_platform_data(dev, np);
  102. if (IS_ERR(pdata))
  103. return PTR_ERR(pdata);
  104. adev->dev.platform_data = pdata;
  105. }
  106. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  107. if (!drvdata)
  108. return -ENOMEM;
  109. drvdata->dev = &adev->dev;
  110. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  111. if (!IS_ERR(drvdata->atclk)) {
  112. ret = clk_prepare_enable(drvdata->atclk);
  113. if (ret)
  114. return ret;
  115. }
  116. /* Validity for the resource is already checked by the AMBA core */
  117. base = devm_ioremap_resource(dev, res);
  118. if (IS_ERR(base))
  119. return PTR_ERR(base);
  120. drvdata->base = base;
  121. dev_set_drvdata(dev, drvdata);
  122. pm_runtime_put(&adev->dev);
  123. desc.type = CORESIGHT_DEV_TYPE_LINK;
  124. desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  125. desc.ops = &replicator_cs_ops;
  126. desc.pdata = adev->dev.platform_data;
  127. desc.dev = &adev->dev;
  128. desc.groups = replicator_groups;
  129. drvdata->csdev = coresight_register(&desc);
  130. return PTR_ERR_OR_ZERO(drvdata->csdev);
  131. }
  132. #ifdef CONFIG_PM
  133. static int replicator_runtime_suspend(struct device *dev)
  134. {
  135. struct replicator_state *drvdata = dev_get_drvdata(dev);
  136. if (drvdata && !IS_ERR(drvdata->atclk))
  137. clk_disable_unprepare(drvdata->atclk);
  138. return 0;
  139. }
  140. static int replicator_runtime_resume(struct device *dev)
  141. {
  142. struct replicator_state *drvdata = dev_get_drvdata(dev);
  143. if (drvdata && !IS_ERR(drvdata->atclk))
  144. clk_prepare_enable(drvdata->atclk);
  145. return 0;
  146. }
  147. #endif
  148. static const struct dev_pm_ops replicator_dev_pm_ops = {
  149. SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
  150. replicator_runtime_resume,
  151. NULL)
  152. };
  153. static const struct amba_id replicator_ids[] = {
  154. {
  155. .id = 0x000bb909,
  156. .mask = 0x000fffff,
  157. },
  158. {
  159. /* Coresight SoC-600 */
  160. .id = 0x000bb9ec,
  161. .mask = 0x000fffff,
  162. },
  163. { 0, 0 },
  164. };
  165. static struct amba_driver replicator_driver = {
  166. .drv = {
  167. .name = "coresight-dynamic-replicator",
  168. .pm = &replicator_dev_pm_ops,
  169. .suppress_bind_attrs = true,
  170. },
  171. .probe = replicator_probe,
  172. .id_table = replicator_ids,
  173. };
  174. builtin_amba_driver(replicator_driver);