coresight-tpiu.c 4.9 KB

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