coresight: Remove name from platform description
[linux-2.6-microblaze.git] / drivers / hwtracing / coresight / coresight-replicator.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
4  *
5  * Description: CoreSight Replicator driver
6  */
7
8 #include <linux/amba/bus.h>
9 #include <linux/kernel.h>
10 #include <linux/device.h>
11 #include <linux/platform_device.h>
12 #include <linux/io.h>
13 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/clk.h>
17 #include <linux/of.h>
18 #include <linux/coresight.h>
19
20 #include "coresight-priv.h"
21
22 #define REPLICATOR_IDFILTER0            0x000
23 #define REPLICATOR_IDFILTER1            0x004
24
25 /**
26  * struct replicator_drvdata - specifics associated to a replicator component
27  * @base:       memory mapped base address for this component. Also indicates
28  *              whether this one is programmable or not.
29  * @atclk:      optional clock for the core parts of the replicator.
30  * @csdev:      component vitals needed by the framework
31  */
32 struct replicator_drvdata {
33         void __iomem            *base;
34         struct clk              *atclk;
35         struct coresight_device *csdev;
36 };
37
38 static void dynamic_replicator_reset(struct replicator_drvdata *drvdata)
39 {
40         CS_UNLOCK(drvdata->base);
41
42         if (!coresight_claim_device_unlocked(drvdata->base)) {
43                 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
44                 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
45                 coresight_disclaim_device_unlocked(drvdata->base);
46         }
47
48         CS_LOCK(drvdata->base);
49 }
50
51 /*
52  * replicator_reset : Reset the replicator configuration to sane values.
53  */
54 static inline void replicator_reset(struct replicator_drvdata *drvdata)
55 {
56         if (drvdata->base)
57                 dynamic_replicator_reset(drvdata);
58 }
59
60 static int dynamic_replicator_enable(struct replicator_drvdata *drvdata,
61                                      int inport, int outport)
62 {
63         int rc = 0;
64         u32 reg;
65
66         switch (outport) {
67         case 0:
68                 reg = REPLICATOR_IDFILTER0;
69                 break;
70         case 1:
71                 reg = REPLICATOR_IDFILTER1;
72                 break;
73         default:
74                 WARN_ON(1);
75                 return -EINVAL;
76         }
77
78         CS_UNLOCK(drvdata->base);
79
80         if ((readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0) == 0xff) &&
81             (readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1) == 0xff))
82                 rc = coresight_claim_device_unlocked(drvdata->base);
83
84         /* Ensure that the outport is enabled. */
85         if (!rc)
86                 writel_relaxed(0x00, drvdata->base + reg);
87         CS_LOCK(drvdata->base);
88
89         return rc;
90 }
91
92 static int replicator_enable(struct coresight_device *csdev, int inport,
93                              int outport)
94 {
95         int rc = 0;
96         struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
97
98         if (drvdata->base)
99                 rc = dynamic_replicator_enable(drvdata, inport, outport);
100         if (!rc)
101                 dev_dbg(&csdev->dev, "REPLICATOR enabled\n");
102         return rc;
103 }
104
105 static void dynamic_replicator_disable(struct replicator_drvdata *drvdata,
106                                        int inport, int outport)
107 {
108         u32 reg;
109
110         switch (outport) {
111         case 0:
112                 reg = REPLICATOR_IDFILTER0;
113                 break;
114         case 1:
115                 reg = REPLICATOR_IDFILTER1;
116                 break;
117         default:
118                 WARN_ON(1);
119                 return;
120         }
121
122         CS_UNLOCK(drvdata->base);
123
124         /* disable the flow of ATB data through port */
125         writel_relaxed(0xff, drvdata->base + reg);
126
127         if ((readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0) == 0xff) &&
128             (readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1) == 0xff))
129                 coresight_disclaim_device_unlocked(drvdata->base);
130         CS_LOCK(drvdata->base);
131 }
132
133 static void replicator_disable(struct coresight_device *csdev, int inport,
134                                int outport)
135 {
136         struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
137
138         if (drvdata->base)
139                 dynamic_replicator_disable(drvdata, inport, outport);
140         dev_dbg(&csdev->dev, "REPLICATOR disabled\n");
141 }
142
143 static const struct coresight_ops_link replicator_link_ops = {
144         .enable         = replicator_enable,
145         .disable        = replicator_disable,
146 };
147
148 static const struct coresight_ops replicator_cs_ops = {
149         .link_ops       = &replicator_link_ops,
150 };
151
152 #define coresight_replicator_reg(name, offset) \
153         coresight_simple_reg32(struct replicator_drvdata, name, offset)
154
155 coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
156 coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
157
158 static struct attribute *replicator_mgmt_attrs[] = {
159         &dev_attr_idfilter0.attr,
160         &dev_attr_idfilter1.attr,
161         NULL,
162 };
163
164 static const struct attribute_group replicator_mgmt_group = {
165         .attrs = replicator_mgmt_attrs,
166         .name = "mgmt",
167 };
168
169 static const struct attribute_group *replicator_groups[] = {
170         &replicator_mgmt_group,
171         NULL,
172 };
173
174 static int replicator_probe(struct device *dev, struct resource *res)
175 {
176         int ret = 0;
177         struct coresight_platform_data *pdata = NULL;
178         struct replicator_drvdata *drvdata;
179         struct coresight_desc desc = { 0 };
180         void __iomem *base;
181
182         pdata = coresight_get_platform_data(dev);
183         if (IS_ERR(pdata))
184                 return PTR_ERR(pdata);
185         dev->platform_data = pdata;
186
187         if (is_of_node(dev_fwnode(dev)) &&
188             of_device_is_compatible(dev->of_node, "arm,coresight-replicator"))
189                 pr_warn_once("Uses OBSOLETE CoreSight replicator binding\n");
190
191         drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
192         if (!drvdata)
193                 return -ENOMEM;
194
195         drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */
196         if (!IS_ERR(drvdata->atclk)) {
197                 ret = clk_prepare_enable(drvdata->atclk);
198                 if (ret)
199                         return ret;
200         }
201
202         /*
203          * Map the device base for dynamic-replicator, which has been
204          * validated by AMBA core
205          */
206         if (res) {
207                 base = devm_ioremap_resource(dev, res);
208                 if (IS_ERR(base)) {
209                         ret = PTR_ERR(base);
210                         goto out_disable_clk;
211                 }
212                 drvdata->base = base;
213                 desc.groups = replicator_groups;
214         }
215
216         dev_set_drvdata(dev, drvdata);
217
218         desc.type = CORESIGHT_DEV_TYPE_LINK;
219         desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
220         desc.ops = &replicator_cs_ops;
221         desc.pdata = dev->platform_data;
222         desc.dev = dev;
223         desc.name = dev_name(dev);
224
225         drvdata->csdev = coresight_register(&desc);
226         if (IS_ERR(drvdata->csdev)) {
227                 ret = PTR_ERR(drvdata->csdev);
228                 goto out_disable_clk;
229         }
230
231         replicator_reset(drvdata);
232         pm_runtime_put(dev);
233
234 out_disable_clk:
235         if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
236                 clk_disable_unprepare(drvdata->atclk);
237         return ret;
238 }
239
240 static int static_replicator_probe(struct platform_device *pdev)
241 {
242         int ret;
243
244         pm_runtime_get_noresume(&pdev->dev);
245         pm_runtime_set_active(&pdev->dev);
246         pm_runtime_enable(&pdev->dev);
247
248         /* Static replicators do not have programming base */
249         ret = replicator_probe(&pdev->dev, NULL);
250
251         if (ret) {
252                 pm_runtime_put_noidle(&pdev->dev);
253                 pm_runtime_disable(&pdev->dev);
254         }
255
256         return ret;
257 }
258
259 #ifdef CONFIG_PM
260 static int replicator_runtime_suspend(struct device *dev)
261 {
262         struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
263
264         if (drvdata && !IS_ERR(drvdata->atclk))
265                 clk_disable_unprepare(drvdata->atclk);
266
267         return 0;
268 }
269
270 static int replicator_runtime_resume(struct device *dev)
271 {
272         struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
273
274         if (drvdata && !IS_ERR(drvdata->atclk))
275                 clk_prepare_enable(drvdata->atclk);
276
277         return 0;
278 }
279 #endif
280
281 static const struct dev_pm_ops replicator_dev_pm_ops = {
282         SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
283                            replicator_runtime_resume, NULL)
284 };
285
286 static const struct of_device_id static_replicator_match[] = {
287         {.compatible = "arm,coresight-replicator"},
288         {.compatible = "arm,coresight-static-replicator"},
289         {}
290 };
291
292 static struct platform_driver static_replicator_driver = {
293         .probe          = static_replicator_probe,
294         .driver         = {
295                 .name   = "coresight-static-replicator",
296                 .of_match_table = static_replicator_match,
297                 .pm     = &replicator_dev_pm_ops,
298                 .suppress_bind_attrs = true,
299         },
300 };
301 builtin_platform_driver(static_replicator_driver);
302
303 static int dynamic_replicator_probe(struct amba_device *adev,
304                                     const struct amba_id *id)
305 {
306         return replicator_probe(&adev->dev, &adev->res);
307 }
308
309 static const struct amba_id dynamic_replicator_ids[] = {
310         {
311                 .id     = 0x000bb909,
312                 .mask   = 0x000fffff,
313         },
314         {
315                 /* Coresight SoC-600 */
316                 .id     = 0x000bb9ec,
317                 .mask   = 0x000fffff,
318         },
319         { 0, 0 },
320 };
321
322 static struct amba_driver dynamic_replicator_driver = {
323         .drv = {
324                 .name   = "coresight-dynamic-replicator",
325                 .pm     = &replicator_dev_pm_ops,
326                 .suppress_bind_attrs = true,
327         },
328         .probe          = dynamic_replicator_probe,
329         .id_table       = dynamic_replicator_ids,
330 };
331 builtin_amba_driver(dynamic_replicator_driver);