coresight-dynamic-replicator.c 5.7 KB

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