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
;
37 static int replicator_enable(struct coresight_device
*csdev
, int inport
,
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
50 writel_relaxed(0x00, drvdata
->base
+ REPLICATOR_IDFILTER0
);
51 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER1
);
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");
63 static void replicator_disable(struct coresight_device
*csdev
, int inport
,
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 */
72 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER0
);
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
,
102 static const struct attribute_group replicator_mgmt_group
= {
103 .attrs
= replicator_mgmt_attrs
,
107 static const struct attribute_group
*replicator_groups
[] = {
108 &replicator_mgmt_group
,
112 static int replicator_probe(struct amba_device
*adev
, const struct amba_id
*id
)
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
;
124 pdata
= of_get_coresight_platform_data(dev
, np
);
126 return PTR_ERR(pdata
);
127 adev
->dev
.platform_data
= pdata
;
130 drvdata
= devm_kzalloc(dev
, sizeof(*drvdata
), GFP_KERNEL
);
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
);
142 /* Validity for the resource is already checked by the AMBA core */
143 base
= devm_ioremap_resource(dev
, res
);
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
);
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
);
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
);
184 static const struct dev_pm_ops replicator_dev_pm_ops
= {
185 SET_RUNTIME_PM_OPS(replicator_runtime_suspend
,
186 replicator_runtime_resume
,
190 static const struct amba_id replicator_ids
[] = {
196 /* Coresight SoC-600 */
203 static struct amba_driver replicator_driver
= {
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
);