coresight-tpiu.c 5.5 KB

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