coresight-funnel.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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/types.h>
  16. #include <linux/device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/io.h>
  19. #include <linux/err.h>
  20. #include <linux/slab.h>
  21. #include <linux/clk.h>
  22. #include <linux/of_coresight.h>
  23. #include <linux/coresight.h>
  24. #include "coresight-priv.h"
  25. #define funnel_writel(drvdata, val, off) \
  26. __raw_writel((val), drvdata->base + off)
  27. #define funnel_readl(drvdata, off) \
  28. __raw_readl(drvdata->base + off)
  29. #define FUNNEL_LOCK(drvdata) \
  30. do { \
  31. mb(); \
  32. funnel_writel(drvdata, 0x0, CORESIGHT_LAR); \
  33. } while (0)
  34. #define FUNNEL_UNLOCK(drvdata) \
  35. do { \
  36. funnel_writel(drvdata, CORESIGHT_UNLOCK, CORESIGHT_LAR); \
  37. mb(); \
  38. } while (0)
  39. #define FUNNEL_FUNCTL (0x000)
  40. #define FUNNEL_PRICTL (0x004)
  41. #define FUNNEL_ITATBDATA0 (0xEEC)
  42. #define FUNNEL_ITATBCTR2 (0xEF0)
  43. #define FUNNEL_ITATBCTR1 (0xEF4)
  44. #define FUNNEL_ITATBCTR0 (0xEF8)
  45. #define FUNNEL_HOLDTIME_MASK (0xF00)
  46. #define FUNNEL_HOLDTIME_SHFT (0x8)
  47. #define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT)
  48. struct funnel_drvdata {
  49. void __iomem *base;
  50. struct device *dev;
  51. struct coresight_device *csdev;
  52. struct clk *clk;
  53. uint32_t priority;
  54. };
  55. static void __funnel_enable(struct funnel_drvdata *drvdata, int port)
  56. {
  57. uint32_t functl;
  58. FUNNEL_UNLOCK(drvdata);
  59. functl = funnel_readl(drvdata, FUNNEL_FUNCTL);
  60. functl &= ~FUNNEL_HOLDTIME_MASK;
  61. functl |= FUNNEL_HOLDTIME;
  62. functl |= (1 << port);
  63. funnel_writel(drvdata, functl, FUNNEL_FUNCTL);
  64. funnel_writel(drvdata, drvdata->priority, FUNNEL_PRICTL);
  65. FUNNEL_LOCK(drvdata);
  66. }
  67. static int funnel_enable(struct coresight_device *csdev, int inport,
  68. int outport)
  69. {
  70. struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  71. int ret;
  72. ret = clk_prepare_enable(drvdata->clk);
  73. if (ret)
  74. return ret;
  75. __funnel_enable(drvdata, inport);
  76. dev_info(drvdata->dev, "FUNNEL inport %d enabled\n", inport);
  77. return 0;
  78. }
  79. static void __funnel_disable(struct funnel_drvdata *drvdata, int inport)
  80. {
  81. uint32_t functl;
  82. FUNNEL_UNLOCK(drvdata);
  83. functl = funnel_readl(drvdata, FUNNEL_FUNCTL);
  84. functl &= ~(1 << inport);
  85. funnel_writel(drvdata, functl, FUNNEL_FUNCTL);
  86. FUNNEL_LOCK(drvdata);
  87. }
  88. static void funnel_disable(struct coresight_device *csdev, int inport,
  89. int outport)
  90. {
  91. struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  92. __funnel_disable(drvdata, inport);
  93. clk_disable_unprepare(drvdata->clk);
  94. dev_info(drvdata->dev, "FUNNEL inport %d disabled\n", inport);
  95. }
  96. static const struct coresight_ops_link funnel_link_ops = {
  97. .enable = funnel_enable,
  98. .disable = funnel_disable,
  99. };
  100. static const struct coresight_ops funnel_cs_ops = {
  101. .link_ops = &funnel_link_ops,
  102. };
  103. static ssize_t funnel_show_priority(struct device *dev,
  104. struct device_attribute *attr, char *buf)
  105. {
  106. struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
  107. unsigned long val = drvdata->priority;
  108. return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
  109. }
  110. static ssize_t funnel_store_priority(struct device *dev,
  111. struct device_attribute *attr,
  112. const char *buf, size_t size)
  113. {
  114. struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
  115. unsigned long val;
  116. if (sscanf(buf, "%lx", &val) != 1)
  117. return -EINVAL;
  118. drvdata->priority = val;
  119. return size;
  120. }
  121. static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, funnel_show_priority,
  122. funnel_store_priority);
  123. static struct attribute *funnel_attrs[] = {
  124. &dev_attr_priority.attr,
  125. NULL,
  126. };
  127. static struct attribute_group funnel_attr_grp = {
  128. .attrs = funnel_attrs,
  129. };
  130. static const struct attribute_group *funnel_attr_grps[] = {
  131. &funnel_attr_grp,
  132. NULL,
  133. };
  134. static int __devinit funnel_probe(struct platform_device *pdev)
  135. {
  136. int ret;
  137. struct device *dev = &pdev->dev;
  138. struct coresight_platform_data *pdata;
  139. struct funnel_drvdata *drvdata;
  140. struct resource *res;
  141. struct coresight_desc *desc;
  142. if (coresight_fuse_access_disabled())
  143. return -EPERM;
  144. if (pdev->dev.of_node) {
  145. pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node);
  146. if (IS_ERR(pdata))
  147. return PTR_ERR(pdata);
  148. pdev->dev.platform_data = pdata;
  149. }
  150. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  151. if (!drvdata)
  152. return -ENOMEM;
  153. drvdata->dev = &pdev->dev;
  154. platform_set_drvdata(pdev, drvdata);
  155. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "funnel-base");
  156. if (!res)
  157. return -ENODEV;
  158. drvdata->base = devm_ioremap(dev, res->start, resource_size(res));
  159. if (!drvdata->base)
  160. return -ENOMEM;
  161. drvdata->clk = devm_clk_get(dev, "core_clk");
  162. if (IS_ERR(drvdata->clk))
  163. return PTR_ERR(drvdata->clk);
  164. ret = clk_set_rate(drvdata->clk, CORESIGHT_CLK_RATE_TRACE);
  165. if (ret)
  166. return ret;
  167. desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
  168. if (!desc)
  169. return -ENOMEM;
  170. desc->type = CORESIGHT_DEV_TYPE_LINK;
  171. desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
  172. desc->ops = &funnel_cs_ops;
  173. desc->pdata = pdev->dev.platform_data;
  174. desc->dev = &pdev->dev;
  175. desc->groups = funnel_attr_grps;
  176. desc->owner = THIS_MODULE;
  177. drvdata->csdev = coresight_register(desc);
  178. if (IS_ERR(drvdata->csdev))
  179. return PTR_ERR(drvdata->csdev);
  180. dev_info(dev, "FUNNEL initialized\n");
  181. return 0;
  182. }
  183. static int __devexit funnel_remove(struct platform_device *pdev)
  184. {
  185. struct funnel_drvdata *drvdata = platform_get_drvdata(pdev);
  186. coresight_unregister(drvdata->csdev);
  187. return 0;
  188. }
  189. static struct of_device_id funnel_match[] = {
  190. {.compatible = "arm,coresight-funnel"},
  191. {}
  192. };
  193. static struct platform_driver funnel_driver = {
  194. .probe = funnel_probe,
  195. .remove = __devexit_p(funnel_remove),
  196. .driver = {
  197. .name = "coresight-funnel",
  198. .owner = THIS_MODULE,
  199. .of_match_table = funnel_match,
  200. },
  201. };
  202. static int __init funnel_init(void)
  203. {
  204. return platform_driver_register(&funnel_driver);
  205. }
  206. module_init(funnel_init);
  207. static void __exit funnel_exit(void)
  208. {
  209. platform_driver_unregister(&funnel_driver);
  210. }
  211. module_exit(funnel_exit);
  212. MODULE_LICENSE("GPL v2");
  213. MODULE_DESCRIPTION("CoreSight Funnel driver");