coresight-funnel.c 6.2 KB

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