coresight-tpiu.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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/pm_runtime.h>
  20. #include <linux/coresight.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/clk.h>
  23. #include "coresight-priv.h"
  24. #define TPIU_SUPP_PORTSZ 0x000
  25. #define TPIU_CURR_PORTSZ 0x004
  26. #define TPIU_SUPP_TRIGMODES 0x100
  27. #define TPIU_TRIG_CNTRVAL 0x104
  28. #define TPIU_TRIG_MULT 0x108
  29. #define TPIU_SUPP_TESTPATM 0x200
  30. #define TPIU_CURR_TESTPATM 0x204
  31. #define TPIU_TEST_PATREPCNTR 0x208
  32. #define TPIU_FFSR 0x300
  33. #define TPIU_FFCR 0x304
  34. #define TPIU_FSYNC_CNTR 0x308
  35. #define TPIU_EXTCTL_INPORT 0x400
  36. #define TPIU_EXTCTL_OUTPORT 0x404
  37. #define TPIU_ITTRFLINACK 0xee4
  38. #define TPIU_ITTRFLIN 0xee8
  39. #define TPIU_ITATBDATA0 0xeec
  40. #define TPIU_ITATBCTR2 0xef0
  41. #define TPIU_ITATBCTR1 0xef4
  42. #define TPIU_ITATBCTR0 0xef8
  43. /** register definition **/
  44. /* FFCR - 0x304 */
  45. #define FFCR_FON_MAN BIT(6)
  46. /**
  47. * @base: memory mapped base address for this component.
  48. * @dev: the device entity associated to this component.
  49. * @atclk: optional clock for the core parts of the TPIU.
  50. * @csdev: component vitals needed by the framework.
  51. */
  52. struct tpiu_drvdata {
  53. void __iomem *base;
  54. struct device *dev;
  55. struct clk *atclk;
  56. struct coresight_device *csdev;
  57. };
  58. static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
  59. {
  60. CS_UNLOCK(drvdata->base);
  61. /* TODO: fill this up */
  62. CS_LOCK(drvdata->base);
  63. }
  64. static int tpiu_enable(struct coresight_device *csdev)
  65. {
  66. struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  67. pm_runtime_get_sync(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. pm_runtime_put(csdev->dev.parent);
  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;
  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 = 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. #ifdef CONFIG_PM
  151. static int tpiu_runtime_suspend(struct device *dev)
  152. {
  153. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  154. if (drvdata && !IS_ERR(drvdata->atclk))
  155. clk_disable_unprepare(drvdata->atclk);
  156. return 0;
  157. }
  158. static int tpiu_runtime_resume(struct device *dev)
  159. {
  160. struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
  161. if (drvdata && !IS_ERR(drvdata->atclk))
  162. clk_prepare_enable(drvdata->atclk);
  163. return 0;
  164. }
  165. #endif
  166. static const struct dev_pm_ops tpiu_dev_pm_ops = {
  167. SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL)
  168. };
  169. static struct amba_id tpiu_ids[] = {
  170. {
  171. .id = 0x0003b912,
  172. .mask = 0x0003ffff,
  173. },
  174. {
  175. .id = 0x0004b912,
  176. .mask = 0x0007ffff,
  177. },
  178. { 0, 0},
  179. };
  180. static struct amba_driver tpiu_driver = {
  181. .drv = {
  182. .name = "coresight-tpiu",
  183. .owner = THIS_MODULE,
  184. .pm = &tpiu_dev_pm_ops,
  185. },
  186. .probe = tpiu_probe,
  187. .remove = tpiu_remove,
  188. .id_table = tpiu_ids,
  189. };
  190. module_amba_driver(tpiu_driver);
  191. MODULE_LICENSE("GPL v2");
  192. MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");