Linux 4.16.11
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-dynamic-replicator.c
blob043da86b0fe93329a472731953ed149ff6c13c28
1 /*
2 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/amba/bus.h>
15 #include <linux/clk.h>
16 #include <linux/coresight.h>
17 #include <linux/device.h>
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/io.h>
21 #include <linux/kernel.h>
22 #include <linux/of.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/slab.h>
26 #include "coresight-priv.h"
28 #define REPLICATOR_IDFILTER0 0x000
29 #define REPLICATOR_IDFILTER1 0x004
31 /**
32 * struct replicator_state - specifics associated to a replicator component
33 * @base: memory mapped base address for this component.
34 * @dev: the device entity associated with this component
35 * @atclk: optional clock for the core parts of the replicator.
36 * @csdev: component vitals needed by the framework
38 struct replicator_state {
39 void __iomem *base;
40 struct device *dev;
41 struct clk *atclk;
42 struct coresight_device *csdev;
45 static int replicator_enable(struct coresight_device *csdev, int inport,
46 int outport)
48 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
50 CS_UNLOCK(drvdata->base);
53 * Ensure that the other port is disabled
54 * 0x00 - passing through the replicator unimpeded
55 * 0xff - disable (or impede) the flow of ATB data
57 if (outport == 0) {
58 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER0);
59 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
60 } else {
61 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER1);
62 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
65 CS_LOCK(drvdata->base);
67 dev_info(drvdata->dev, "REPLICATOR enabled\n");
68 return 0;
71 static void replicator_disable(struct coresight_device *csdev, int inport,
72 int outport)
74 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
76 CS_UNLOCK(drvdata->base);
78 /* disable the flow of ATB data through port */
79 if (outport == 0)
80 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
81 else
82 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
84 CS_LOCK(drvdata->base);
86 dev_info(drvdata->dev, "REPLICATOR disabled\n");
89 static const struct coresight_ops_link replicator_link_ops = {
90 .enable = replicator_enable,
91 .disable = replicator_disable,
94 static const struct coresight_ops replicator_cs_ops = {
95 .link_ops = &replicator_link_ops,
98 #define coresight_replicator_reg(name, offset) \
99 coresight_simple_reg32(struct replicator_state, name, offset)
101 coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
102 coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
104 static struct attribute *replicator_mgmt_attrs[] = {
105 &dev_attr_idfilter0.attr,
106 &dev_attr_idfilter1.attr,
107 NULL,
110 static const struct attribute_group replicator_mgmt_group = {
111 .attrs = replicator_mgmt_attrs,
112 .name = "mgmt",
115 static const struct attribute_group *replicator_groups[] = {
116 &replicator_mgmt_group,
117 NULL,
120 static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
122 int ret;
123 struct device *dev = &adev->dev;
124 struct resource *res = &adev->res;
125 struct coresight_platform_data *pdata = NULL;
126 struct replicator_state *drvdata;
127 struct coresight_desc desc = { 0 };
128 struct device_node *np = adev->dev.of_node;
129 void __iomem *base;
131 if (np) {
132 pdata = of_get_coresight_platform_data(dev, np);
133 if (IS_ERR(pdata))
134 return PTR_ERR(pdata);
135 adev->dev.platform_data = pdata;
138 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
139 if (!drvdata)
140 return -ENOMEM;
142 drvdata->dev = &adev->dev;
143 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
144 if (!IS_ERR(drvdata->atclk)) {
145 ret = clk_prepare_enable(drvdata->atclk);
146 if (ret)
147 return ret;
150 /* Validity for the resource is already checked by the AMBA core */
151 base = devm_ioremap_resource(dev, res);
152 if (IS_ERR(base))
153 return PTR_ERR(base);
155 drvdata->base = base;
156 dev_set_drvdata(dev, drvdata);
157 pm_runtime_put(&adev->dev);
159 desc.type = CORESIGHT_DEV_TYPE_LINK;
160 desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
161 desc.ops = &replicator_cs_ops;
162 desc.pdata = adev->dev.platform_data;
163 desc.dev = &adev->dev;
164 desc.groups = replicator_groups;
165 drvdata->csdev = coresight_register(&desc);
167 return PTR_ERR_OR_ZERO(drvdata->csdev);
170 #ifdef CONFIG_PM
171 static int replicator_runtime_suspend(struct device *dev)
173 struct replicator_state *drvdata = dev_get_drvdata(dev);
175 if (drvdata && !IS_ERR(drvdata->atclk))
176 clk_disable_unprepare(drvdata->atclk);
178 return 0;
181 static int replicator_runtime_resume(struct device *dev)
183 struct replicator_state *drvdata = dev_get_drvdata(dev);
185 if (drvdata && !IS_ERR(drvdata->atclk))
186 clk_prepare_enable(drvdata->atclk);
188 return 0;
190 #endif
192 static const struct dev_pm_ops replicator_dev_pm_ops = {
193 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
194 replicator_runtime_resume,
195 NULL)
198 static const struct amba_id replicator_ids[] = {
200 .id = 0x000bb909,
201 .mask = 0x000fffff,
204 /* Coresight SoC-600 */
205 .id = 0x000bb9ec,
206 .mask = 0x000fffff,
208 { 0, 0 },
211 static struct amba_driver replicator_driver = {
212 .drv = {
213 .name = "coresight-dynamic-replicator",
214 .pm = &replicator_dev_pm_ops,
215 .suppress_bind_attrs = true,
217 .probe = replicator_probe,
218 .id_table = replicator_ids,
220 builtin_amba_driver(replicator_driver);