coresight-tpiu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  4. *
  5. * Description: CoreSight Trace Port Interface Unit driver
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/device.h>
  10. #include <linux/io.h>
  11. #include <linux/err.h>
  12. #include <linux/slab.h>
  13. #include <linux/pm_runtime.h>
  14. #include <linux/coresight.h>
  15. #include <linux/amba/bus.h>
  16. #include <linux/clk.h>
  17. #include "coresight-priv.h"
  18. #define TPIU_SUPP_PORTSZ 0x000
  19. #define TPIU_CURR_PORTSZ 0x004
  20. #define TPIU_SUPP_TRIGMODES 0x100
  21. #define TPIU_TRIG_CNTRVAL 0x104
  22. #define TPIU_TRIG_MULT 0x108
  23. #define TPIU_SUPP_TESTPATM 0x200
  24. #define TPIU_CURR_TESTPATM 0x204
  25. #define TPIU_TEST_PATREPCNTR 0x208
  26. #define TPIU_FFSR 0x300
  27. #define TPIU_FFCR 0x304
  28. #define TPIU_FSYNC_CNTR 0x308
  29. #define TPIU_EXTCTL_INPORT 0x400
  30. #define TPIU_EXTCTL_OUTPORT 0x404
  31. #define TPIU_ITTRFLINACK 0xee4
  32. #define TPIU_ITTRFLIN 0xee8
  33. #define TPIU_ITATBDATA0 0xeec
  34. #define TPIU_ITATBCTR2 0xef0
  35. #define TPIU_ITATBCTR1 0xef4
  36. #define TPIU_ITATBCTR0 0xef8
  37. /** register definition **/
  38. /* FFSR - 0x300 */
  39. #define FFSR_FT_STOPPED BIT(1)
  40. /* FFCR - 0x304 */
  41. #define FFCR_FON_MAN BIT(6)
  42. #define FFCR_STOP_FI BIT(12)
  43. /**
  44. * @base: memory mapped base address for this component.
  45. * @dev: the device entity associated to this component.
  46. * @atclk: optional clock for the core parts of the TPIU.
  47. * @csdev: component vitals needed by the framework.
  48. */
  49. struct tpiu_drvdata {
  50. void __iomem *base;
  51. struct device *dev;
  52. struct clk *atclk;
  53. struct coresight_device *csdev;
  54. };
  55. static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
  56. {
  57. CS_UNLOCK(drvdata->base);
  58. /* TODO: fill this up */
  59. CS_LOCK(drvdata->base);
  60. }
  61. static int tpiu_enable(struct coresight_device *csdev, u32 mode)
  62. {
  63. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  64. tpiu_enable_hw(drvdata);
  65. dev_info(drvdata->dev, "TPIU enabled\n");
  66. return 0;
  67. }
  68. static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
  69. {
  70. CS_UNLOCK(drvdata->base);
  71. /* Clear formatter and stop on flush */
  72. writel_relaxed(FFCR_STOP_FI, drvdata->base + TPIU_FFCR);
  73. /* Generate manual flush */
  74. writel_relaxed(FFCR_STOP_FI | FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
  75. /* Wait for flush to complete */
  76. coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN, 0);
  77. /* Wait for formatter to stop */
  78. coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED, 1);
  79. CS_LOCK(drvdata->base);
  80. }
  81. static void tpiu_disable(struct coresight_device *csdev)
  82. {
  83. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  84. tpiu_disable_hw(drvdata);
  85. dev_info(drvdata->dev, "TPIU disabled\n");
  86. }
  87. static const struct coresight_ops_sink tpiu_sink_ops = {
  88. .enable = tpiu_enable,
  89. .disable = tpiu_disable,
  90. };
  91. static const struct coresight_ops tpiu_cs_ops = {
  92. .sink_ops = &tpiu_sink_ops,
  93. };
  94. static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
  95. {
  96. int ret;
  97. void __iomem *base;
  98. struct device *dev = &adev->dev;
  99. struct coresight_platform_data *pdata = NULL;
  100. struct tpiu_drvdata *drvdata;
  101. struct resource *res = &adev->res;
  102. struct coresight_desc desc = { 0 };
  103. struct device_node *np = adev->dev.of_node;
  104. if (np) {
  105. pdata = of_get_coresight_platform_data(dev, np);
  106. if (IS_ERR(pdata))
  107. return PTR_ERR(pdata);
  108. adev->dev.platform_data = pdata;
  109. }
  110. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  111. if (!drvdata)
  112. return -ENOMEM;
  113. drvdata->dev = &adev->dev;
  114. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  115. if (!IS_ERR(drvdata->atclk)) {
  116. ret = clk_prepare_enable(drvdata->atclk);
  117. if (ret)
  118. return ret;
  119. }
  120. dev_set_drvdata(dev, drvdata);
  121. /* Validity for the resource is already checked by the AMBA core */
  122. base = devm_ioremap_resource(dev, res);
  123. if (IS_ERR(base))
  124. return PTR_ERR(base);
  125. drvdata->base = base;
  126. /* Disable tpiu to support older devices */
  127. tpiu_disable_hw(drvdata);
  128. pm_runtime_put(&adev->dev);
  129. desc.type = CORESIGHT_DEV_TYPE_SINK;
  130. desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
  131. desc.ops = &tpiu_cs_ops;
  132. desc.pdata = pdata;
  133. desc.dev = dev;
  134. drvdata->csdev = coresight_register(&desc);
  135. return PTR_ERR_OR_ZERO(drvdata->csdev);
  136. }
  137. #ifdef CONFIG_PM
  138. static int tpiu_runtime_suspend(struct device *dev)
  139. {
  140. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  141. if (drvdata && !IS_ERR(drvdata->atclk))
  142. clk_disable_unprepare(drvdata->atclk);
  143. return 0;
  144. }
  145. static int tpiu_runtime_resume(struct device *dev)
  146. {
  147. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  148. if (drvdata && !IS_ERR(drvdata->atclk))
  149. clk_prepare_enable(drvdata->atclk);
  150. return 0;
  151. }
  152. #endif
  153. static const struct dev_pm_ops tpiu_dev_pm_ops = {
  154. SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL)
  155. };
  156. static const struct amba_id tpiu_ids[] = {
  157. {
  158. .id = 0x000bb912,
  159. .mask = 0x000fffff,
  160. },
  161. {
  162. .id = 0x0004b912,
  163. .mask = 0x0007ffff,
  164. },
  165. {
  166. /* Coresight SoC-600 */
  167. .id = 0x000bb9e7,
  168. .mask = 0x000fffff,
  169. },
  170. { 0, 0},
  171. };
  172. static struct amba_driver tpiu_driver = {
  173. .drv = {
  174. .name = "coresight-tpiu",
  175. .owner = THIS_MODULE,
  176. .pm = &tpiu_dev_pm_ops,
  177. .suppress_bind_attrs = true,
  178. },
  179. .probe = tpiu_probe,
  180. .id_table = tpiu_ids,
  181. };
  182. builtin_amba_driver(tpiu_driver);