coresight-tpiu.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. /* FFCR - 0x304 */
  46. #define FFCR_FON_MAN BIT(6)
  47. /**
  48. * @base: memory mapped base address for this component.
  49. * @dev: the device entity associated to this component.
  50. * @atclk: optional clock for the core parts of the TPIU.
  51. * @csdev: component vitals needed by the framework.
  52. */
  53. struct tpiu_drvdata {
  54. void __iomem *base;
  55. struct device *dev;
  56. struct clk *atclk;
  57. struct coresight_device *csdev;
  58. };
  59. static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
  60. {
  61. CS_UNLOCK(drvdata->base);
  62. /* TODO: fill this up */
  63. CS_LOCK(drvdata->base);
  64. }
  65. static int tpiu_enable(struct coresight_device *csdev, u32 mode)
  66. {
  67. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  68. tpiu_enable_hw(drvdata);
  69. dev_info(drvdata->dev, "TPIU enabled\n");
  70. return 0;
  71. }
  72. static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
  73. {
  74. CS_UNLOCK(drvdata->base);
  75. /* Clear formatter controle reg. */
  76. writel_relaxed(0x0, drvdata->base + TPIU_FFCR);
  77. /* Generate manual flush */
  78. writel_relaxed(FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
  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. if (IS_ERR(drvdata->csdev))
  136. return PTR_ERR(drvdata->csdev);
  137. return 0;
  138. }
  139. #ifdef CONFIG_PM
  140. static int tpiu_runtime_suspend(struct device *dev)
  141. {
  142. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  143. if (drvdata && !IS_ERR(drvdata->atclk))
  144. clk_disable_unprepare(drvdata->atclk);
  145. return 0;
  146. }
  147. static int tpiu_runtime_resume(struct device *dev)
  148. {
  149. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  150. if (drvdata && !IS_ERR(drvdata->atclk))
  151. clk_prepare_enable(drvdata->atclk);
  152. return 0;
  153. }
  154. #endif
  155. static const struct dev_pm_ops tpiu_dev_pm_ops = {
  156. SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL)
  157. };
  158. static struct amba_id tpiu_ids[] = {
  159. {
  160. .id = 0x0003b912,
  161. .mask = 0x0003ffff,
  162. },
  163. {
  164. .id = 0x0004b912,
  165. .mask = 0x0007ffff,
  166. },
  167. { 0, 0},
  168. };
  169. static struct amba_driver tpiu_driver = {
  170. .drv = {
  171. .name = "coresight-tpiu",
  172. .owner = THIS_MODULE,
  173. .pm = &tpiu_dev_pm_ops,
  174. .suppress_bind_attrs = true,
  175. },
  176. .probe = tpiu_probe,
  177. .id_table = tpiu_ids,
  178. };
  179. builtin_amba_driver(tpiu_driver);