coresight-replicator.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* Copyright (c) 2011-2013, 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/platform_device.h>
  17. #include <linux/io.h>
  18. #include <linux/err.h>
  19. #include <linux/slab.h>
  20. #include <linux/clk.h>
  21. #include <linux/of_coresight.h>
  22. #include <linux/coresight.h>
  23. #include "coresight-priv.h"
  24. #define replicator_writel(drvdata, val, off) \
  25. __raw_writel((val), drvdata->base + off)
  26. #define replicator_readl(drvdata, off) \
  27. __raw_readl(drvdata->base + off)
  28. #define REPLICATOR_LOCK(drvdata) \
  29. do { \
  30. mb(); \
  31. replicator_writel(drvdata, 0x0, CORESIGHT_LAR); \
  32. } while (0)
  33. #define REPLICATOR_UNLOCK(drvdata) \
  34. do { \
  35. replicator_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \
  36. mb(); \
  37. } while (0)
  38. #define REPLICATOR_IDFILTER0 (0x000)
  39. #define REPLICATOR_IDFILTER1 (0x004)
  40. #define REPLICATOR_ITATBCTR0 (0xEFC)
  41. #define REPLICATOR_ITATBCTR1 (0xEF8)
  42. struct replicator_drvdata {
  43. void __iomem *base;
  44. struct device *dev;
  45. struct coresight_device *csdev;
  46. struct clk *clk;
  47. };
  48. static void __replicator_enable(struct replicator_drvdata *drvdata, int outport)
  49. {
  50. REPLICATOR_UNLOCK(drvdata);
  51. if (outport == 0) {
  52. replicator_writel(drvdata, 0x0, REPLICATOR_IDFILTER0);
  53. replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER1);
  54. } else {
  55. replicator_writel(drvdata, 0x0, REPLICATOR_IDFILTER1);
  56. replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER0);
  57. }
  58. REPLICATOR_LOCK(drvdata);
  59. }
  60. static int replicator_enable(struct coresight_device *csdev, int inport,
  61. int outport)
  62. {
  63. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  64. int ret;
  65. ret = clk_prepare_enable(drvdata->clk);
  66. if (ret)
  67. return ret;
  68. __replicator_enable(drvdata, outport);
  69. dev_info(drvdata->dev, "REPLICATOR enabled\n");
  70. return 0;
  71. }
  72. static void __replicator_disable(struct replicator_drvdata *drvdata,
  73. int outport)
  74. {
  75. REPLICATOR_UNLOCK(drvdata);
  76. if (outport == 0)
  77. replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER0);
  78. else
  79. replicator_writel(drvdata, 0xFF, REPLICATOR_IDFILTER1);
  80. REPLICATOR_LOCK(drvdata);
  81. }
  82. static void replicator_disable(struct coresight_device *csdev, int inport,
  83. int outport)
  84. {
  85. struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  86. __replicator_disable(drvdata, outport);
  87. clk_disable_unprepare(drvdata->clk);
  88. dev_info(drvdata->dev, "REPLICATOR disabled\n");
  89. }
  90. static const struct coresight_ops_link replicator_link_ops = {
  91. .enable = replicator_enable,
  92. .disable = replicator_disable,
  93. };
  94. static const struct coresight_ops replicator_cs_ops = {
  95. .link_ops = &replicator_link_ops,
  96. };
  97. static int __devinit replicator_probe(struct platform_device *pdev)
  98. {
  99. int ret;
  100. struct device *dev = &pdev->dev;
  101. struct coresight_platform_data *pdata;
  102. struct replicator_drvdata *drvdata;
  103. struct resource *res;
  104. struct coresight_desc *desc;
  105. if (coresight_fuse_access_disabled())
  106. return -EPERM;
  107. if (pdev->dev.of_node) {
  108. pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node);
  109. if (IS_ERR(pdata))
  110. return PTR_ERR(pdata);
  111. pdev->dev.platform_data = pdata;
  112. }
  113. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  114. if (!drvdata)
  115. return -ENOMEM;
  116. drvdata->dev = &pdev->dev;
  117. platform_set_drvdata(pdev, drvdata);
  118. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  119. "replicator-base");
  120. if (!res)
  121. return -ENODEV;
  122. drvdata->base = devm_ioremap(dev, res->start, resource_size(res));
  123. if (!drvdata->base)
  124. return -ENOMEM;
  125. drvdata->clk = devm_clk_get(dev, "core_clk");
  126. if (IS_ERR(drvdata->clk))
  127. return PTR_ERR(drvdata->clk);
  128. ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE);
  129. if (ret)
  130. return ret;
  131. desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
  132. if (!desc)
  133. return -ENOMEM;
  134. desc->type = CORESIGHT_DEV_TYPE_LINK;
  135. desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
  136. desc->ops = &replicator_cs_ops;
  137. desc->pdata = pdev->dev.platform_data;
  138. desc->dev = &pdev->dev;
  139. desc->owner = THIS_MODULE;
  140. drvdata->csdev = coresight_register(desc);
  141. if (IS_ERR(drvdata->csdev))
  142. return PTR_ERR(drvdata->csdev);
  143. dev_info(dev, "REPLICATOR initialized\n");
  144. return 0;
  145. }
  146. static int __devexit replicator_remove(struct platform_device *pdev)
  147. {
  148. struct replicator_drvdata *drvdata = platform_get_drvdata(pdev);
  149. coresight_unregister(drvdata->csdev);
  150. return 0;
  151. }
  152. static struct of_device_id replicator_match[] = {
  153. {.compatible = "qcom,coresight-replicator"},
  154. {}
  155. };
  156. static struct platform_driver replicator_driver = {
  157. .probe = replicator_probe,
  158. .remove = __devexit_p(replicator_remove),
  159. .driver = {
  160. .name = "coresight-replicator",
  161. .owner = THIS_MODULE,
  162. .of_match_table = replicator_match,
  163. },
  164. };
  165. static int __init replicator_init(void)
  166. {
  167. return platform_driver_register(&replicator_driver);
  168. }
  169. module_init(replicator_init);
  170. static void __exit replicator_exit(void)
  171. {
  172. platform_driver_unregister(&replicator_driver);
  173. }
  174. module_exit(replicator_exit);
  175. MODULE_LICENSE("GPL v2");
  176. MODULE_DESCRIPTION("CoreSight Replicator driver");