coresight-tpiu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_FON_MAN BIT(6)
  43. #define FFCR_STOP_FI BIT(12)
  44. /**
  45. * @base: memory mapped base address for this component.
  46. * @dev: the device entity associated to this component.
  47. * @atclk: optional clock for the core parts of the TPIU.
  48. * @csdev: component vitals needed by the framework.
  49. */
  50. struct tpiu_drvdata {
  51. void __iomem *base;
  52. struct device *dev;
  53. struct clk *atclk;
  54. struct coresight_device *csdev;
  55. };
  56. static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
  57. {
  58. CS_UNLOCK(drvdata->base);
  59. /* TODO: fill this up */
  60. CS_LOCK(drvdata->base);
  61. }
  62. static int tpiu_enable(struct coresight_device *csdev, u32 mode)
  63. {
  64. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  65. tpiu_enable_hw(drvdata);
  66. dev_info(drvdata->dev, "TPIU enabled\n");
  67. return 0;
  68. }
  69. static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
  70. {
  71. CS_UNLOCK(drvdata->base);
  72. /* Clear formatter and stop on flush */
  73. writel_relaxed(FFCR_STOP_FI, drvdata->base + TPIU_FFCR);
  74. /* Generate manual flush */
  75. writel_relaxed(FFCR_STOP_FI | FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
  76. /* Wait for flush to complete */
  77. coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN_BIT, 0);
  78. /* Wait for formatter to stop */
  79. coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED_BIT, 1);
  80. CS_LOCK(drvdata->base);
  81. }
  82. static void tpiu_disable(struct coresight_device *csdev)
  83. {
  84. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  85. tpiu_disable_hw(drvdata);
  86. dev_info(drvdata->dev, "TPIU disabled\n");
  87. }
  88. static const struct coresight_ops_sink tpiu_sink_ops = {
  89. .enable = tpiu_enable,
  90. .disable = tpiu_disable,
  91. };
  92. static const struct coresight_ops tpiu_cs_ops = {
  93. .sink_ops = &tpiu_sink_ops,
  94. };
  95. static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
  96. {
  97. int ret;
  98. void __iomem *base;
  99. struct device *dev = &adev->dev;
  100. struct coresight_platform_data *pdata = NULL;
  101. struct tpiu_drvdata *drvdata;
  102. struct resource *res = &adev->res;
  103. struct coresight_desc desc = { 0 };
  104. struct device_node *np = adev->dev.of_node;
  105. if (np) {
  106. pdata = of_get_coresight_platform_data(dev, np);
  107. if (IS_ERR(pdata))
  108. return PTR_ERR(pdata);
  109. adev->dev.platform_data = pdata;
  110. }
  111. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  112. if (!drvdata)
  113. return -ENOMEM;
  114. drvdata->dev = &adev->dev;
  115. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  116. if (!IS_ERR(drvdata->atclk)) {
  117. ret = clk_prepare_enable(drvdata->atclk);
  118. if (ret)
  119. return ret;
  120. }
  121. dev_set_drvdata(dev, drvdata);
  122. /* Validity for the resource is already checked by the AMBA core */
  123. base = devm_ioremap_resource(dev, res);
  124. if (IS_ERR(base))
  125. return PTR_ERR(base);
  126. drvdata->base = base;
  127. /* Disable tpiu to support older devices */
  128. tpiu_disable_hw(drvdata);
  129. pm_runtime_put(&adev->dev);
  130. desc.type = CORESIGHT_DEV_TYPE_SINK;
  131. desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
  132. desc.ops = &tpiu_cs_ops;
  133. desc.pdata = pdata;
  134. desc.dev = dev;
  135. drvdata->csdev = coresight_register(&desc);
  136. return PTR_ERR_OR_ZERO(drvdata->csdev);
  137. }
  138. #ifdef CONFIG_PM
  139. static int tpiu_runtime_suspend(struct device *dev)
  140. {
  141. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  142. if (drvdata && !IS_ERR(drvdata->atclk))
  143. clk_disable_unprepare(drvdata->atclk);
  144. return 0;
  145. }
  146. static int tpiu_runtime_resume(struct device *dev)
  147. {
  148. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  149. if (drvdata && !IS_ERR(drvdata->atclk))
  150. clk_prepare_enable(drvdata->atclk);
  151. return 0;
  152. }
  153. #endif
  154. static const struct dev_pm_ops tpiu_dev_pm_ops = {
  155. SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL)
  156. };
  157. static const struct amba_id tpiu_ids[] = {
  158. {
  159. .id = 0x000bb912,
  160. .mask = 0x000fffff,
  161. },
  162. {
  163. .id = 0x0004b912,
  164. .mask = 0x0007ffff,
  165. },
  166. {
  167. /* Coresight SoC-600 */
  168. .id = 0x000bb9e7,
  169. .mask = 0x000fffff,
  170. },
  171. { 0, 0},
  172. };
  173. static struct amba_driver tpiu_driver = {
  174. .drv = {
  175. .name = "coresight-tpiu",
  176. .owner = THIS_MODULE,
  177. .pm = &tpiu_dev_pm_ops,
  178. .suppress_bind_attrs = true,
  179. },
  180. .probe = tpiu_probe,
  181. .id_table = tpiu_ids,
  182. };
  183. builtin_amba_driver(tpiu_driver);