coresight-replicator-qcom.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
  82. {
  83. int ret;
  84. struct device *dev = &adev->dev;
  85. struct resource *res = &adev->res;
  86. struct coresight_platform_data *pdata = NULL;
  87. struct replicator_state *drvdata;
  88. struct coresight_desc desc = { 0 };
  89. struct device_node *np = adev->dev.of_node;
  90. void __iomem *base;
  91. if (np) {
  92. pdata = of_get_coresight_platform_data(dev, np);
  93. if (IS_ERR(pdata))
  94. return PTR_ERR(pdata);
  95. adev->dev.platform_data = pdata;
  96. }
  97. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  98. if (!drvdata)
  99. return -ENOMEM;
  100. drvdata->dev = &adev->dev;
  101. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  102. if (!IS_ERR(drvdata->atclk)) {
  103. ret = clk_prepare_enable(drvdata->atclk);
  104. if (ret)
  105. return ret;
  106. }
  107. /* Validity for the resource is already checked by the AMBA core */
  108. base = devm_ioremap_resource(dev, res);
  109. if (IS_ERR(base))
  110. return PTR_ERR(base);
  111. drvdata->base = base;
  112. dev_set_drvdata(dev, drvdata);
  113. pm_runtime_put(&adev->dev);
  114. desc.type = CORESIGHT_DEV_TYPE_LINK;
  115. desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  116. desc.ops = &replicator_cs_ops;
  117. desc.pdata = adev->dev.platform_data;
  118. desc.dev = &adev->dev;
  119. drvdata->csdev = coresight_register(&desc);
  120. if (IS_ERR(drvdata->csdev))
  121. return PTR_ERR(drvdata->csdev);
  122. dev_info(dev, "%s initialized\n", (char *)id->data);
  123. return 0;
  124. }
  125. #ifdef CONFIG_PM
  126. static int replicator_runtime_suspend(struct device *dev)
  127. {
  128. struct replicator_state *drvdata = dev_get_drvdata(dev);
  129. if (drvdata && !IS_ERR(drvdata->atclk))
  130. clk_disable_unprepare(drvdata->atclk);
  131. return 0;
  132. }
  133. static int replicator_runtime_resume(struct device *dev)
  134. {
  135. struct replicator_state *drvdata = dev_get_drvdata(dev);
  136. if (drvdata && !IS_ERR(drvdata->atclk))
  137. clk_prepare_enable(drvdata->atclk);
  138. return 0;
  139. }
  140. #endif
  141. static const struct dev_pm_ops replicator_dev_pm_ops = {
  142. SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
  143. replicator_runtime_resume,
  144. NULL)
  145. };
  146. static struct amba_id replicator_ids[] = {
  147. {
  148. .id = 0x0003b909,
  149. .mask = 0x0003ffff,
  150. .data = "REPLICATOR 1.0",
  151. },
  152. { 0, 0 },
  153. };
  154. static struct amba_driver replicator_driver = {
  155. .drv = {
  156. .name = "coresight-replicator-qcom",
  157. .pm = &replicator_dev_pm_ops,
  158. .suppress_bind_attrs = true,
  159. },
  160. .probe = replicator_probe,
  161. .id_table = replicator_ids,
  162. };
  163. builtin_amba_driver(replicator_driver);