coresight-funnel.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  4. *
  5. * Description: CoreSight Funnel driver
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/types.h>
  10. #include <linux/device.h>
  11. #include <linux/err.h>
  12. #include <linux/fs.h>
  13. #include <linux/slab.h>
  14. #include <linux/pm_runtime.h>
  15. #include <linux/coresight.h>
  16. #include <linux/amba/bus.h>
  17. #include <linux/clk.h>
  18. #include "coresight-priv.h"
  19. #define FUNNEL_FUNCTL 0x000
  20. #define FUNNEL_PRICTL 0x004
  21. #define FUNNEL_HOLDTIME_MASK 0xf00
  22. #define FUNNEL_HOLDTIME_SHFT 0x8
  23. #define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT)
  24. /**
  25. * struct funnel_drvdata - specifics associated to a funnel component
  26. * @base: memory mapped base address for this component.
  27. * @dev: the device entity associated to this component.
  28. * @atclk: optional clock for the core parts of the funnel.
  29. * @csdev: component vitals needed by the framework.
  30. * @priority: port selection order.
  31. */
  32. struct funnel_drvdata {
  33. void __iomem *base;
  34. struct device *dev;
  35. struct clk *atclk;
  36. struct coresight_device *csdev;
  37. unsigned long priority;
  38. };
  39. static void funnel_enable_hw(struct funnel_drvdata *drvdata, int port)
  40. {
  41. u32 functl;
  42. CS_UNLOCK(drvdata->base);
  43. functl = readl_relaxed(drvdata->base + FUNNEL_FUNCTL);
  44. functl &= ~FUNNEL_HOLDTIME_MASK;
  45. functl |= FUNNEL_HOLDTIME;
  46. functl |= (1 << port);
  47. writel_relaxed(functl, drvdata->base + FUNNEL_FUNCTL);
  48. writel_relaxed(drvdata->priority, drvdata->base + FUNNEL_PRICTL);
  49. CS_LOCK(drvdata->base);
  50. }
  51. static int funnel_enable(struct coresight_device *csdev, int inport,
  52. int outport)
  53. {
  54. struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  55. funnel_enable_hw(drvdata, inport);
  56. dev_info(drvdata->dev, "FUNNEL inport %d enabled\n", inport);
  57. return 0;
  58. }
  59. static void funnel_disable_hw(struct funnel_drvdata *drvdata, int inport)
  60. {
  61. u32 functl;
  62. CS_UNLOCK(drvdata->base);
  63. functl = readl_relaxed(drvdata->base + FUNNEL_FUNCTL);
  64. functl &= ~(1 << inport);
  65. writel_relaxed(functl, drvdata->base + FUNNEL_FUNCTL);
  66. CS_LOCK(drvdata->base);
  67. }
  68. static void funnel_disable(struct coresight_device *csdev, int inport,
  69. int outport)
  70. {
  71. struct funnel_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
  72. funnel_disable_hw(drvdata, inport);
  73. dev_info(drvdata->dev, "FUNNEL inport %d disabled\n", inport);
  74. }
  75. static const struct coresight_ops_link funnel_link_ops = {
  76. .enable = funnel_enable,
  77. .disable = funnel_disable,
  78. };
  79. static const struct coresight_ops funnel_cs_ops = {
  80. .link_ops = &funnel_link_ops,
  81. };
  82. static ssize_t priority_show(struct device *dev,
  83. struct device_attribute *attr, char *buf)
  84. {
  85. struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
  86. unsigned long val = drvdata->priority;
  87. return sprintf(buf, "%#lx\n", val);
  88. }
  89. static ssize_t priority_store(struct device *dev,
  90. struct device_attribute *attr,
  91. const char *buf, size_t size)
  92. {
  93. int ret;
  94. unsigned long val;
  95. struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
  96. ret = kstrtoul(buf, 16, &val);
  97. if (ret)
  98. return ret;
  99. drvdata->priority = val;
  100. return size;
  101. }
  102. static DEVICE_ATTR_RW(priority);
  103. static u32 get_funnel_ctrl_hw(struct funnel_drvdata *drvdata)
  104. {
  105. u32 functl;
  106. CS_UNLOCK(drvdata->base);
  107. functl = readl_relaxed(drvdata->base + FUNNEL_FUNCTL);
  108. CS_LOCK(drvdata->base);
  109. return functl;
  110. }
  111. static ssize_t funnel_ctrl_show(struct device *dev,
  112. struct device_attribute *attr, char *buf)
  113. {
  114. u32 val;
  115. struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
  116. pm_runtime_get_sync(drvdata->dev);
  117. val = get_funnel_ctrl_hw(drvdata);
  118. pm_runtime_put(drvdata->dev);
  119. return sprintf(buf, "%#x\n", val);
  120. }
  121. static DEVICE_ATTR_RO(funnel_ctrl);
  122. static struct attribute *coresight_funnel_attrs[] = {
  123. &dev_attr_funnel_ctrl.attr,
  124. &dev_attr_priority.attr,
  125. NULL,
  126. };
  127. ATTRIBUTE_GROUPS(coresight_funnel);
  128. static int funnel_probe(struct amba_device *adev, const struct amba_id *id)
  129. {
  130. int ret;
  131. void __iomem *base;
  132. struct device *dev = &adev->dev;
  133. struct coresight_platform_data *pdata = NULL;
  134. struct funnel_drvdata *drvdata;
  135. struct resource *res = &adev->res;
  136. struct coresight_desc desc = { 0 };
  137. struct device_node *np = adev->dev.of_node;
  138. if (np) {
  139. pdata = of_get_coresight_platform_data(dev, np);
  140. if (IS_ERR(pdata))
  141. return PTR_ERR(pdata);
  142. adev->dev.platform_data = pdata;
  143. }
  144. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  145. if (!drvdata)
  146. return -ENOMEM;
  147. drvdata->dev = &adev->dev;
  148. drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
  149. if (!IS_ERR(drvdata->atclk)) {
  150. ret = clk_prepare_enable(drvdata->atclk);
  151. if (ret)
  152. return ret;
  153. }
  154. dev_set_drvdata(dev, drvdata);
  155. /* Validity for the resource is already checked by the AMBA core */
  156. base = devm_ioremap_resource(dev, res);
  157. if (IS_ERR(base))
  158. return PTR_ERR(base);
  159. drvdata->base = base;
  160. pm_runtime_put(&adev->dev);
  161. desc.type = CORESIGHT_DEV_TYPE_LINK;
  162. desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
  163. desc.ops = &funnel_cs_ops;
  164. desc.pdata = pdata;
  165. desc.dev = dev;
  166. desc.groups = coresight_funnel_groups;
  167. drvdata->csdev = coresight_register(&desc);
  168. return PTR_ERR_OR_ZERO(drvdata->csdev);
  169. }
  170. #ifdef CONFIG_PM
  171. static int funnel_runtime_suspend(struct device *dev)
  172. {
  173. struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
  174. if (drvdata && !IS_ERR(drvdata->atclk))
  175. clk_disable_unprepare(drvdata->atclk);
  176. return 0;
  177. }
  178. static int funnel_runtime_resume(struct device *dev)
  179. {
  180. struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
  181. if (drvdata && !IS_ERR(drvdata->atclk))
  182. clk_prepare_enable(drvdata->atclk);
  183. return 0;
  184. }
  185. #endif
  186. static const struct dev_pm_ops funnel_dev_pm_ops = {
  187. SET_RUNTIME_PM_OPS(funnel_runtime_suspend, funnel_runtime_resume, NULL)
  188. };
  189. static const struct amba_id funnel_ids[] = {
  190. {
  191. .id = 0x000bb908,
  192. .mask = 0x000fffff,
  193. },
  194. {
  195. /* Coresight SoC-600 */
  196. .id = 0x000bb9eb,
  197. .mask = 0x000fffff,
  198. },
  199. { 0, 0},
  200. };
  201. static struct amba_driver funnel_driver = {
  202. .drv = {
  203. .name = "coresight-funnel",
  204. .owner = THIS_MODULE,
  205. .pm = &funnel_dev_pm_ops,
  206. .suppress_bind_attrs = true,
  207. },
  208. .probe = funnel_probe,
  209. .id_table = funnel_ids,
  210. };
  211. builtin_amba_driver(funnel_driver);