Linux 4.2.1
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-replicator-qcom.c
blob584059e9e8660f228f785cb87b9200e3b315d675
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/module.h>
19 #include <linux/err.h>
20 #include <linux/init.h>
21 #include <linux/io.h>
22 #include <linux/kernel.h>
23 #include <linux/of.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
32 /**
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 {
40 void __iomem *base;
41 struct device *dev;
42 struct clk *atclk;
43 struct coresight_device *csdev;
46 static int replicator_enable(struct coresight_device *csdev, int inport,
47 int outport)
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
60 if (outport == 0) {
61 writel_relaxed(0x00, drvdata->base + REPLICATOR_IDFILTER0);
62 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
63 } else {
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");
71 return 0;
74 static void replicator_disable(struct coresight_device *csdev, int inport,
75 int outport)
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 */
82 if (outport == 0)
83 writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
84 else
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)
105 int ret;
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;
112 void __iomem *base;
114 if (np) {
115 pdata = of_get_coresight_platform_data(dev, np);
116 if (IS_ERR(pdata))
117 return PTR_ERR(pdata);
118 adev->dev.platform_data = pdata;
121 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
122 if (!drvdata)
123 return -ENOMEM;
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);
129 if (ret)
130 return ret;
133 /* Validity for the resource is already checked by the AMBA core */
134 base = devm_ioremap_resource(dev, res);
135 if (IS_ERR(base))
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);
143 if (!desc)
144 return -ENOMEM;
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);
156 return 0;
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);
165 return 0;
168 #ifdef CONFIG_PM
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);
176 return 0;
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);
186 return 0;
188 #endif
190 static const struct dev_pm_ops replicator_dev_pm_ops = {
191 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
192 replicator_runtime_resume,
193 NULL)
196 static struct amba_id replicator_ids[] = {
198 .id = 0x0003b909,
199 .mask = 0x0003ffff,
200 .data = "REPLICATOR 1.0",
202 { 0, 0 },
205 static struct amba_driver replicator_driver = {
206 .drv = {
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);