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 CS_UNLOCK(drvdata->base);
54 * Ensure that the other port is disabled
55 * 0x00 - passing through the replicator unimpeded
56 * 0xff - disable (or impede) the flow of ATB data
59 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER0);
60 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
62 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER1);
63 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
66 CS_LOCK(drvdata->base);
68 dev_info(drvdata->dev, "REPLICATOR enabled\n");
72 static void replicator_disable(struct coresight_device *csdev, int inport,
75 struct replicator_state *drvdata = dev_get_drvdata(csdev->dev.parent);
77 CS_UNLOCK(drvdata->base);
79 /* disable the flow of ATB data through port */
81 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
83 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
85 CS_LOCK(drvdata->base);
87 dev_info(drvdata->dev, "REPLICATOR disabled\n");
90 static const struct coresight_ops_link replicator_link_ops = {
91 .enable = replicator_enable,
92 .disable = replicator_disable,
95 static const struct coresight_ops replicator_cs_ops = {
96 .link_ops = &replicator_link_ops,
99 static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
102 struct device *dev = &adev->dev;
103 struct resource *res = &adev->res;
104 struct coresight_platform_data *pdata = NULL;
105 struct replicator_state *drvdata;
106 struct coresight_desc *desc;
107 struct device_node *np = adev->dev.of_node;
111 pdata = of_get_coresight_platform_data(dev, np);
113 return PTR_ERR(pdata);
114 adev->dev.platform_data = pdata;
117 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
121 drvdata->dev = &adev->dev;
122 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
123 if (!IS_ERR(drvdata->atclk)) {
124 ret = clk_prepare_enable(drvdata->atclk);
129 /* Validity for the resource is already checked by the AMBA core */
130 base = devm_ioremap_resource(dev, res);
132 return PTR_ERR(base);
134 drvdata->base = base;
135 dev_set_drvdata(dev, drvdata);
136 pm_runtime_put(&adev->dev);
138 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
142 desc->type = CORESIGHT_DEV_TYPE_LINK;
143 desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
144 desc->ops = &replicator_cs_ops;
145 desc->pdata = adev->dev.platform_data;
146 desc->dev = &adev->dev;
147 drvdata->csdev = coresight_register(desc);
148 if (IS_ERR(drvdata->csdev))
149 return PTR_ERR(drvdata->csdev);
151 dev_info(dev, "%s initialized\n", (char *)id->data);
156 static int replicator_runtime_suspend(struct device *dev)
158 struct replicator_state *drvdata = dev_get_drvdata(dev);
160 if (drvdata && !IS_ERR(drvdata->atclk))
161 clk_disable_unprepare(drvdata->atclk);
166 static int replicator_runtime_resume(struct device *dev)
168 struct replicator_state *drvdata = dev_get_drvdata(dev);
170 if (drvdata && !IS_ERR(drvdata->atclk))
171 clk_prepare_enable(drvdata->atclk);
177 static const struct dev_pm_ops replicator_dev_pm_ops = {
178 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
179 replicator_runtime_resume,
183 static struct amba_id replicator_ids[] = {
187 .data = "REPLICATOR 1.0",
192 static struct amba_driver replicator_driver = {
194 .name = "coresight-replicator-qcom",
195 .pm = &replicator_dev_pm_ops,
196 .suppress_bind_attrs = true,
198 .probe = replicator_probe,
199 .id_table = replicator_ids,
202 module_amba_driver(replicator_driver);