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/module.h>
19 #include <linux/err.h>
20 #include <linux/init.h>
22 #include <linux/kernel.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/slab.h>
27 #include "coresight-priv.h"
29 #define REPLICATOR_IDFILTER0 0x000
30 #define REPLICATOR_IDFILTER1 0x004
33 * struct replicator_state - specifics associated to a replicator component
34 * @base: memory mapped base address for this component.
35 * @dev: the device entity associated with this component
36 * @atclk: optional clock for the core parts of the replicator.
37 * @csdev: component vitals needed by the framework
39 struct replicator_state
{
43 struct coresight_device
*csdev
;
46 static int replicator_enable(struct coresight_device
*csdev
, int inport
,
49 struct replicator_state
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
51 pm_runtime_get_sync(drvdata
->dev
);
53 CS_UNLOCK(drvdata
->base
);
56 * Ensure that the other port is disabled
57 * 0x00 - passing through the replicator unimpeded
58 * 0xff - disable (or impede) the flow of ATB data
61 writel_relaxed(0x00, drvdata
->base
+ REPLICATOR_IDFILTER0
);
62 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER1
);
64 writel_relaxed(0x00, drvdata
->base
+ REPLICATOR_IDFILTER1
);
65 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER0
);
68 CS_LOCK(drvdata
->base
);
70 dev_info(drvdata
->dev
, "REPLICATOR enabled\n");
74 static void replicator_disable(struct coresight_device
*csdev
, int inport
,
77 struct replicator_state
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
79 CS_UNLOCK(drvdata
->base
);
81 /* disable the flow of ATB data through port */
83 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER0
);
85 writel_relaxed(0xff, drvdata
->base
+ REPLICATOR_IDFILTER1
);
87 CS_LOCK(drvdata
->base
);
89 pm_runtime_put(drvdata
->dev
);
91 dev_info(drvdata
->dev
, "REPLICATOR disabled\n");
94 static const struct coresight_ops_link replicator_link_ops
= {
95 .enable
= replicator_enable
,
96 .disable
= replicator_disable
,
99 static const struct coresight_ops replicator_cs_ops
= {
100 .link_ops
= &replicator_link_ops
,
103 static int replicator_probe(struct amba_device
*adev
, const struct amba_id
*id
)
106 struct device
*dev
= &adev
->dev
;
107 struct resource
*res
= &adev
->res
;
108 struct coresight_platform_data
*pdata
= NULL
;
109 struct replicator_state
*drvdata
;
110 struct coresight_desc
*desc
;
111 struct device_node
*np
= adev
->dev
.of_node
;
115 pdata
= of_get_coresight_platform_data(dev
, np
);
117 return PTR_ERR(pdata
);
118 adev
->dev
.platform_data
= pdata
;
121 drvdata
= devm_kzalloc(dev
, sizeof(*drvdata
), GFP_KERNEL
);
125 drvdata
->dev
= &adev
->dev
;
126 drvdata
->atclk
= devm_clk_get(&adev
->dev
, "atclk"); /* optional */
127 if (!IS_ERR(drvdata
->atclk
)) {
128 ret
= clk_prepare_enable(drvdata
->atclk
);
133 /* Validity for the resource is already checked by the AMBA core */
134 base
= devm_ioremap_resource(dev
, res
);
136 return PTR_ERR(base
);
138 drvdata
->base
= base
;
139 dev_set_drvdata(dev
, drvdata
);
140 pm_runtime_put(&adev
->dev
);
142 desc
= devm_kzalloc(dev
, sizeof(*desc
), GFP_KERNEL
);
146 desc
->type
= CORESIGHT_DEV_TYPE_LINK
;
147 desc
->subtype
.link_subtype
= CORESIGHT_DEV_SUBTYPE_LINK_SPLIT
;
148 desc
->ops
= &replicator_cs_ops
;
149 desc
->pdata
= adev
->dev
.platform_data
;
150 desc
->dev
= &adev
->dev
;
151 drvdata
->csdev
= coresight_register(desc
);
152 if (IS_ERR(drvdata
->csdev
))
153 return PTR_ERR(drvdata
->csdev
);
155 dev_info(dev
, "%s initialized\n", (char *)id
->data
);
159 static int replicator_remove(struct amba_device
*adev
)
161 struct replicator_state
*drvdata
= amba_get_drvdata(adev
);
163 pm_runtime_disable(&adev
->dev
);
164 coresight_unregister(drvdata
->csdev
);
169 static int replicator_runtime_suspend(struct device
*dev
)
171 struct replicator_state
*drvdata
= dev_get_drvdata(dev
);
173 if (drvdata
&& !IS_ERR(drvdata
->atclk
))
174 clk_disable_unprepare(drvdata
->atclk
);
179 static int replicator_runtime_resume(struct device
*dev
)
181 struct replicator_state
*drvdata
= dev_get_drvdata(dev
);
183 if (drvdata
&& !IS_ERR(drvdata
->atclk
))
184 clk_prepare_enable(drvdata
->atclk
);
190 static const struct dev_pm_ops replicator_dev_pm_ops
= {
191 SET_RUNTIME_PM_OPS(replicator_runtime_suspend
,
192 replicator_runtime_resume
,
196 static struct amba_id replicator_ids
[] = {
200 .data
= "REPLICATOR 1.0",
205 static struct amba_driver replicator_driver
= {
207 .name
= "coresight-replicator-qcom",
208 .pm
= &replicator_dev_pm_ops
,
210 .probe
= replicator_probe
,
211 .remove
= replicator_remove
,
212 .id_table
= replicator_ids
,
215 module_amba_driver(replicator_driver
);