Linux 4.18.10
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-dynamic-replicator.c
blobf6d0571ab9dd59e10066f6143d6206f69b022dc7
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
4 */
6 #include <linux/amba/bus.h>
7 #include <linux/clk.h>
8 #include <linux/coresight.h>
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/kernel.h>
14 #include <linux/of.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/slab.h>
18 #include "coresight-priv.h"
20 #define REPLICATOR_IDFILTER0 0x000
21 #define REPLICATOR_IDFILTER1 0x004
23 /**
24 * struct replicator_state - specifics associated to a replicator component
25 * @base: memory mapped base address for this component.
26 * @dev: the device entity associated with this component
27 * @atclk: optional clock for the core parts of the replicator.
28 * @csdev: component vitals needed by the framework
30 struct replicator_state {
31 void __iomem *base;
32 struct device *dev;
33 struct clk *atclk;
34 struct coresight_device *csdev;
37 static int replicator_enable(struct coresight_device *csdev, int inport,
38 int outport)
40 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
42 CS_UNLOCK(drvdata->base);
45 * Ensure that the other port is disabled
46 * 0x00 - passing through the replicator unimpeded
47 * 0xff - disable (or impede) the flow of ATB data
49 if (outport == 0) {
50 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER0);
51 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
52 } else {
53 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER1);
54 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
57 CS_LOCK(drvdata->base);
59 dev_info(drvdata->dev, "REPLICATOR enabled\n");
60 return 0;
63 static void replicator_disable(struct coresight_device *csdev, int inport,
64 int outport)
66 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
68 CS_UNLOCK(drvdata->base);
70 /* disable the flow of ATB data through port */
71 if (outport == 0)
72 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
73 else
74 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
76 CS_LOCK(drvdata->base);
78 dev_info(drvdata->dev, "REPLICATOR disabled\n");
81 static const struct coresight_ops_link replicator_link_ops = {
82 .enable = replicator_enable,
83 .disable = replicator_disable,
86 static const struct coresight_ops replicator_cs_ops = {
87 .link_ops = &replicator_link_ops,
90 #define coresight_replicator_reg(name, offset) \
91 coresight_simple_reg32(struct replicator_state, name, offset)
93 coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
94 coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
96 static struct attribute *replicator_mgmt_attrs[] = {
97 &dev_attr_idfilter0.attr,
98 &dev_attr_idfilter1.attr,
99 NULL,
102 static const struct attribute_group replicator_mgmt_group = {
103 .attrs = replicator_mgmt_attrs,
104 .name = "mgmt",
107 static const struct attribute_group *replicator_groups[] = {
108 &replicator_mgmt_group,
109 NULL,
112 static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
114 int ret;
115 struct device *dev = &adev->dev;
116 struct resource *res = &adev->res;
117 struct coresight_platform_data *pdata = NULL;
118 struct replicator_state *drvdata;
119 struct coresight_desc desc = { 0 };
120 struct device_node *np = adev->dev.of_node;
121 void __iomem *base;
123 if (np) {
124 pdata = of_get_coresight_platform_data(dev, np);
125 if (IS_ERR(pdata))
126 return PTR_ERR(pdata);
127 adev->dev.platform_data = pdata;
130 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
131 if (!drvdata)
132 return -ENOMEM;
134 drvdata->dev = &adev->dev;
135 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
136 if (!IS_ERR(drvdata->atclk)) {
137 ret = clk_prepare_enable(drvdata->atclk);
138 if (ret)
139 return ret;
142 /* Validity for the resource is already checked by the AMBA core */
143 base = devm_ioremap_resource(dev, res);
144 if (IS_ERR(base))
145 return PTR_ERR(base);
147 drvdata->base = base;
148 dev_set_drvdata(dev, drvdata);
149 pm_runtime_put(&adev->dev);
151 desc.type = CORESIGHT_DEV_TYPE_LINK;
152 desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
153 desc.ops = &replicator_cs_ops;
154 desc.pdata = adev->dev.platform_data;
155 desc.dev = &adev->dev;
156 desc.groups = replicator_groups;
157 drvdata->csdev = coresight_register(&desc);
159 return PTR_ERR_OR_ZERO(drvdata->csdev);
162 #ifdef CONFIG_PM
163 static int replicator_runtime_suspend(struct device *dev)
165 struct replicator_state *drvdata = dev_get_drvdata(dev);
167 if (drvdata && !IS_ERR(drvdata->atclk))
168 clk_disable_unprepare(drvdata->atclk);
170 return 0;
173 static int replicator_runtime_resume(struct device *dev)
175 struct replicator_state *drvdata = dev_get_drvdata(dev);
177 if (drvdata && !IS_ERR(drvdata->atclk))
178 clk_prepare_enable(drvdata->atclk);
180 return 0;
182 #endif
184 static const struct dev_pm_ops replicator_dev_pm_ops = {
185 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
186 replicator_runtime_resume,
187 NULL)
190 static const struct amba_id replicator_ids[] = {
192 .id = 0x000bb909,
193 .mask = 0x000fffff,
196 /* Coresight SoC-600 */
197 .id = 0x000bb9ec,
198 .mask = 0x000fffff,
200 { 0, 0 },
203 static struct amba_driver replicator_driver = {
204 .drv = {
205 .name = "coresight-dynamic-replicator",
206 .pm = &replicator_dev_pm_ops,
207 .suppress_bind_attrs = true,
209 .probe = replicator_probe,
210 .id_table = replicator_ids,
212 builtin_amba_driver(replicator_driver);