ARM: fix put_user() for gcc-8
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-tpiu.c
blob22e10b7d505db26d3dfc6adcba4489d715ca702f
1 /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
17 #include <linux/io.h>
18 #include <linux/err.h>
19 #include <linux/slab.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/coresight.h>
22 #include <linux/amba/bus.h>
23 #include <linux/clk.h>
25 #include "coresight-priv.h"
27 #define TPIU_SUPP_PORTSZ 0x000
28 #define TPIU_CURR_PORTSZ 0x004
29 #define TPIU_SUPP_TRIGMODES 0x100
30 #define TPIU_TRIG_CNTRVAL 0x104
31 #define TPIU_TRIG_MULT 0x108
32 #define TPIU_SUPP_TESTPATM 0x200
33 #define TPIU_CURR_TESTPATM 0x204
34 #define TPIU_TEST_PATREPCNTR 0x208
35 #define TPIU_FFSR 0x300
36 #define TPIU_FFCR 0x304
37 #define TPIU_FSYNC_CNTR 0x308
38 #define TPIU_EXTCTL_INPORT 0x400
39 #define TPIU_EXTCTL_OUTPORT 0x404
40 #define TPIU_ITTRFLINACK 0xee4
41 #define TPIU_ITTRFLIN 0xee8
42 #define TPIU_ITATBDATA0 0xeec
43 #define TPIU_ITATBCTR2 0xef0
44 #define TPIU_ITATBCTR1 0xef4
45 #define TPIU_ITATBCTR0 0xef8
47 /** register definition **/
48 /* FFSR - 0x300 */
49 #define FFSR_FT_STOPPED BIT(1)
50 /* FFCR - 0x304 */
51 #define FFCR_FON_MAN BIT(6)
52 #define FFCR_STOP_FI BIT(12)
54 /**
55 * @base: memory mapped base address for this component.
56 * @dev: the device entity associated to this component.
57 * @atclk: optional clock for the core parts of the TPIU.
58 * @csdev: component vitals needed by the framework.
60 struct tpiu_drvdata {
61 void __iomem *base;
62 struct device *dev;
63 struct clk *atclk;
64 struct coresight_device *csdev;
67 static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
69 CS_UNLOCK(drvdata->base);
71 /* TODO: fill this up */
73 CS_LOCK(drvdata->base);
76 static int tpiu_enable(struct coresight_device *csdev)
78 struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
80 pm_runtime_get_sync(csdev->dev.parent);
81 tpiu_enable_hw(drvdata);
83 dev_info(drvdata->dev, "TPIU enabled\n");
84 return 0;
87 static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
89 CS_UNLOCK(drvdata->base);
91 /* Clear formatter and stop on flush */
92 writel_relaxed(FFCR_STOP_FI, drvdata->base + TPIU_FFCR);
93 /* Generate manual flush */
94 writel_relaxed(FFCR_STOP_FI | FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
95 /* Wait for flush to complete */
96 coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN, 0);
97 /* Wait for formatter to stop */
98 coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED, 1);
100 CS_LOCK(drvdata->base);
103 static void tpiu_disable(struct coresight_device *csdev)
105 struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
107 tpiu_disable_hw(drvdata);
108 pm_runtime_put(csdev->dev.parent);
110 dev_info(drvdata->dev, "TPIU disabled\n");
113 static const struct coresight_ops_sink tpiu_sink_ops = {
114 .enable = tpiu_enable,
115 .disable = tpiu_disable,
118 static const struct coresight_ops tpiu_cs_ops = {
119 .sink_ops = &tpiu_sink_ops,
122 static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
124 int ret;
125 void __iomem *base;
126 struct device *dev = &adev->dev;
127 struct coresight_platform_data *pdata = NULL;
128 struct tpiu_drvdata *drvdata;
129 struct resource *res = &adev->res;
130 struct coresight_desc *desc;
131 struct device_node *np = adev->dev.of_node;
133 if (np) {
134 pdata = of_get_coresight_platform_data(dev, np);
135 if (IS_ERR(pdata))
136 return PTR_ERR(pdata);
137 adev->dev.platform_data = pdata;
140 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
141 if (!drvdata)
142 return -ENOMEM;
144 drvdata->dev = &adev->dev;
145 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
146 if (!IS_ERR(drvdata->atclk)) {
147 ret = clk_prepare_enable(drvdata->atclk);
148 if (ret)
149 return ret;
151 dev_set_drvdata(dev, drvdata);
153 /* Validity for the resource is already checked by the AMBA core */
154 base = devm_ioremap_resource(dev, res);
155 if (IS_ERR(base))
156 return PTR_ERR(base);
158 drvdata->base = base;
160 /* Disable tpiu to support older devices */
161 tpiu_disable_hw(drvdata);
163 pm_runtime_put(&adev->dev);
165 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
166 if (!desc)
167 return -ENOMEM;
169 desc->type = CORESIGHT_DEV_TYPE_SINK;
170 desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
171 desc->ops = &tpiu_cs_ops;
172 desc->pdata = pdata;
173 desc->dev = dev;
174 drvdata->csdev = coresight_register(desc);
175 if (IS_ERR(drvdata->csdev))
176 return PTR_ERR(drvdata->csdev);
178 dev_info(dev, "TPIU initialized\n");
179 return 0;
182 static int tpiu_remove(struct amba_device *adev)
184 struct tpiu_drvdata *drvdata = amba_get_drvdata(adev);
186 coresight_unregister(drvdata->csdev);
187 return 0;
190 #ifdef CONFIG_PM
191 static int tpiu_runtime_suspend(struct device *dev)
193 struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
195 if (drvdata && !IS_ERR(drvdata->atclk))
196 clk_disable_unprepare(drvdata->atclk);
198 return 0;
201 static int tpiu_runtime_resume(struct device *dev)
203 struct tpiu_drvdata *drvdata = dev_get_drvdata(dev);
205 if (drvdata && !IS_ERR(drvdata->atclk))
206 clk_prepare_enable(drvdata->atclk);
208 return 0;
210 #endif
212 static const struct dev_pm_ops tpiu_dev_pm_ops = {
213 SET_RUNTIME_PM_OPS(tpiu_runtime_suspend, tpiu_runtime_resume, NULL)
216 static struct amba_id tpiu_ids[] = {
218 .id = 0x0003b912,
219 .mask = 0x0003ffff,
222 .id = 0x0004b912,
223 .mask = 0x0007ffff,
225 { 0, 0},
228 static struct amba_driver tpiu_driver = {
229 .drv = {
230 .name = "coresight-tpiu",
231 .owner = THIS_MODULE,
232 .pm = &tpiu_dev_pm_ops,
234 .probe = tpiu_probe,
235 .remove = tpiu_remove,
236 .id_table = tpiu_ids,
239 module_amba_driver(tpiu_driver);
241 MODULE_LICENSE("GPL v2");
242 MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");