1
0

coresight-dynamic-replicator.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. /*
  33. * replicator_reset : Reset the replicator configuration to sane values.
  34. */
  35. static void replicator_reset(struct replicator_state *drvdata)
  36. {
  37. CS_UNLOCK(drvdata->base);
  38. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
  39. writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
  40. CS_LOCK(drvdata->base);
  41. }
  42. static int replicator_enable(struct coresight_device *csdev, int inport,
  43. int outport)
  44. {
  45. u32 reg;
  46. struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
  47. switch (outport) {
  48. case 0:
  49. reg = REPLICATOR_IDFILTER0;
  50. break;
  51. case 1:
  52. reg = REPLICATOR_IDFILTER1;
  53. break;
  54. default:
  55. WARN_ON(1);
  56. return -EINVAL;
  57. }
  58. CS_UNLOCK(drvdata->base);
  59. /* Ensure that the outport is enabled. */
  60. writel_relaxed(0x00, drvdata->base + reg);
  61. CS_LOCK(drvdata->base);
  62. dev_info(drvdata->dev, "REPLICATOR enabled\n");
  63. return 0;
  64. }
  65. static void replicator_disable(struct coresight_device *csdev, int inport,
  66. int outport)
  67. {
  68. u32 reg;
  69. struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
  70. switch (outport) {
  71. case 0:
  72. reg = REPLICATOR_IDFILTER0;
  73. break;
  74. case 1:
  75. reg = REPLICATOR_IDFILTER1;
  76. break;
  77. default:
  78. WARN_ON(1);
  79. return;
  80. }
  81. CS_UNLOCK(drvdata->base);
  82. /* disable the flow of ATB data through port */
  83. writel_relaxed(0xff, drvdata->base + reg);
  84. CS_LOCK(drvdata->base);
  85. dev_info(drvdata->dev, "REPLICATOR disabled\n");
  86. }
  87. static const struct coresight_ops_link replicator_link_ops = {
  88. .enable = replicator_enable,
  89. .disable = replicator_disable,
  90. };
  91. static const struct coresight_ops replicator_cs_ops = {
  92. .link_ops = &replicator_link_ops,
  93. };
  94. #define coresight_replicator_reg(name, offset) \
  95. coresight_simple_reg32(struct replicator_state, name, offset)
  96. coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
  97. coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
  98. static struct attribute *replicator_mgmt_attrs[] = {
  99. &dev_attr_idfilter0.attr,
  100. &dev_attr_idfilter1.attr,
  101. NULL,
  102. };
  103. static const struct attribute_group replicator_mgmt_group = {
  104. .attrs = replicator_mgmt_attrs,
  105. .name = "mgmt",
  106. };
  107. static const struct attribute_group *replicator_groups[] = {
  108. &replicator_mgmt_group,
  109. NULL,
  110. };
  111. static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
  112. {
  113. int ret;
  114. struct device *dev = &adev->dev;
  115. struct resource *res = &adev->res;
  116. struct coresight_platform_data *pdata = NULL;
  117. struct replicator_state *drvdata;
  118. struct coresight_desc desc = { 0 };
  119. struct device_node *np = adev->dev.of_node;
  120. void __iomem *base;
  121. if (np) {
  122. pdata = of_get_coresight_platform_data(dev, np);
  123. if (IS_ERR(pdata))
  124. return PTR_ERR(pdata);
  125. adev->dev.platform_data = pdata;
  126. }
  127. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  128. if (!drvdata)
  129. return -ENOMEM;
  130. drvdata->dev = &adev->dev;
  131. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  132. if (!IS_ERR(drvdata->atclk)) {
  133. ret = clk_prepare_enable(drvdata->atclk);
  134. if (ret)
  135. return ret;
  136. }
  137. /* Validity for the resource is already checked by the AMBA core */
  138. base = devm_ioremap_resource(dev, res);
  139. if (IS_ERR(base))
  140. return PTR_ERR(base);
  141. drvdata->base = base;
  142. dev_set_drvdata(dev, drvdata);
  143. pm_runtime_put(&adev->dev);
  144. desc.type = CORESIGHT_DEV_TYPE_LINK;
  145. desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  146. desc.ops = &replicator_cs_ops;
  147. desc.pdata = adev->dev.platform_data;
  148. desc.dev = &adev->dev;
  149. desc.groups = replicator_groups;
  150. drvdata->csdev = coresight_register(&desc);
  151. if (!IS_ERR(drvdata->csdev)) {
  152. replicator_reset(drvdata);
  153. return 0;
  154. }
  155. return PTR_ERR(drvdata->csdev);
  156. }
  157. #ifdef CONFIG_PM
  158. static int replicator_runtime_suspend(struct device *dev)
  159. {
  160. struct replicator_state *drvdata = dev_get_drvdata(dev);
  161. if (drvdata && !IS_ERR(drvdata->atclk))
  162. clk_disable_unprepare(drvdata->atclk);
  163. return 0;
  164. }
  165. static int replicator_runtime_resume(struct device *dev)
  166. {
  167. struct replicator_state *drvdata = dev_get_drvdata(dev);
  168. if (drvdata && !IS_ERR(drvdata->atclk))
  169. clk_prepare_enable(drvdata->atclk);
  170. return 0;
  171. }
  172. #endif
  173. static const struct dev_pm_ops replicator_dev_pm_ops = {
  174. SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
  175. replicator_runtime_resume,
  176. NULL)
  177. };
  178. static const struct amba_id replicator_ids[] = {
  179. {
  180. .id = 0x000bb909,
  181. .mask = 0x000fffff,
  182. },
  183. {
  184. /* Coresight SoC-600 */
  185. .id = 0x000bb9ec,
  186. .mask = 0x000fffff,
  187. },
  188. { 0, 0 },
  189. };
  190. static struct amba_driver replicator_driver = {
  191. .drv = {
  192. .name = "coresight-dynamic-replicator",
  193. .pm = &replicator_dev_pm_ops,
  194. .suppress_bind_attrs = true,
  195. },
  196. .probe = replicator_probe,
  197. .id_table = replicator_ids,
  198. };
  199. builtin_amba_driver(replicator_driver);