1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
6 #include <linux/amba/bus.h>
8 #include <linux/coresight.h>
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/init.h>
13 #include <linux/kernel.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
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 {
34 struct coresight_device *csdev;
38 * replicator_reset : Reset the replicator configuration to sane values.
40 static void replicator_reset(struct replicator_state *drvdata)
42 CS_UNLOCK(drvdata->base);
44 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
45 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
47 CS_LOCK(drvdata->base);
50 static int replicator_enable(struct coresight_device *csdev, int inport,
54 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
58 reg = REPLICATOR_IDFILTER0;
61 reg = REPLICATOR_IDFILTER1;
68 CS_UNLOCK(drvdata->base);
71 /* Ensure that the outport is enabled. */
72 writel_relaxed(0x00, drvdata->base + reg);
73 CS_LOCK(drvdata->base);
75 dev_info(drvdata->dev, "REPLICATOR enabled\n");
79 static void replicator_disable(struct coresight_device *csdev, int inport,
83 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
87 reg = REPLICATOR_IDFILTER0;
90 reg = REPLICATOR_IDFILTER1;
97 CS_UNLOCK(drvdata->base);
99 /* disable the flow of ATB data through port */
100 writel_relaxed(0xff, drvdata->base + reg);
102 CS_LOCK(drvdata->base);
104 dev_info(drvdata->dev, "REPLICATOR disabled\n");
107 static const struct coresight_ops_link replicator_link_ops = {
108 .enable = replicator_enable,
109 .disable = replicator_disable,
112 static const struct coresight_ops replicator_cs_ops = {
113 .link_ops = &replicator_link_ops,
116 #define coresight_replicator_reg(name, offset) \
117 coresight_simple_reg32(struct replicator_state, name, offset)
119 coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
120 coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
122 static struct attribute *replicator_mgmt_attrs[] = {
123 &dev_attr_idfilter0.attr,
124 &dev_attr_idfilter1.attr,
128 static const struct attribute_group replicator_mgmt_group = {
129 .attrs = replicator_mgmt_attrs,
133 static const struct attribute_group *replicator_groups[] = {
134 &replicator_mgmt_group,
138 static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
141 struct device *dev = &adev->dev;
142 struct resource *res = &adev->res;
143 struct coresight_platform_data *pdata = NULL;
144 struct replicator_state *drvdata;
145 struct coresight_desc desc = { 0 };
146 struct device_node *np = adev->dev.of_node;
150 pdata = of_get_coresight_platform_data(dev, np);
152 return PTR_ERR(pdata);
153 adev->dev.platform_data = pdata;
156 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
160 drvdata->dev = &adev->dev;
161 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
162 if (!IS_ERR(drvdata->atclk)) {
163 ret = clk_prepare_enable(drvdata->atclk);
168 /* Validity for the resource is already checked by the AMBA core */
169 base = devm_ioremap_resource(dev, res);
171 return PTR_ERR(base);
173 drvdata->base = base;
174 dev_set_drvdata(dev, drvdata);
175 pm_runtime_put(&adev->dev);
177 desc.type = CORESIGHT_DEV_TYPE_LINK;
178 desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
179 desc.ops = &replicator_cs_ops;
180 desc.pdata = adev->dev.platform_data;
181 desc.dev = &adev->dev;
182 desc.groups = replicator_groups;
183 drvdata->csdev = coresight_register(&desc);
185 if (!IS_ERR(drvdata->csdev)) {
186 replicator_reset(drvdata);
189 return PTR_ERR(drvdata->csdev);
193 static int replicator_runtime_suspend(struct device *dev)
195 struct replicator_state *drvdata = dev_get_drvdata(dev);
197 if (drvdata && !IS_ERR(drvdata->atclk))
198 clk_disable_unprepare(drvdata->atclk);
203 static int replicator_runtime_resume(struct device *dev)
205 struct replicator_state *drvdata = dev_get_drvdata(dev);
207 if (drvdata && !IS_ERR(drvdata->atclk))
208 clk_prepare_enable(drvdata->atclk);
214 static const struct dev_pm_ops replicator_dev_pm_ops = {
215 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
216 replicator_runtime_resume,
220 static const struct amba_id replicator_ids[] = {
226 /* Coresight SoC-600 */
233 static struct amba_driver replicator_driver = {
235 .name = "coresight-dynamic-replicator",
236 .pm = &replicator_dev_pm_ops,
237 .suppress_bind_attrs = true,
239 .probe = replicator_probe,
240 .id_table = replicator_ids,
242 builtin_amba_driver(replicator_driver);