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>
18 #include <linux/err.h>
19 #include <linux/slab.h>
20 #include <linux/clk.h>
21 #include <linux/coresight.h>
22 #include <linux/amba/bus.h>
24 #include "coresight-priv.h"
26 #define TPIU_SUPP_PORTSZ 0x000
27 #define TPIU_CURR_PORTSZ 0x004
28 #define TPIU_SUPP_TRIGMODES 0x100
29 #define TPIU_TRIG_CNTRVAL 0x104
30 #define TPIU_TRIG_MULT 0x108
31 #define TPIU_SUPP_TESTPATM 0x200
32 #define TPIU_CURR_TESTPATM 0x204
33 #define TPIU_TEST_PATREPCNTR 0x208
34 #define TPIU_FFSR 0x300
35 #define TPIU_FFCR 0x304
36 #define TPIU_FSYNC_CNTR 0x308
37 #define TPIU_EXTCTL_INPORT 0x400
38 #define TPIU_EXTCTL_OUTPORT 0x404
39 #define TPIU_ITTRFLINACK 0xee4
40 #define TPIU_ITTRFLIN 0xee8
41 #define TPIU_ITATBDATA0 0xeec
42 #define TPIU_ITATBCTR2 0xef0
43 #define TPIU_ITATBCTR1 0xef4
44 #define TPIU_ITATBCTR0 0xef8
46 /** register definition **/
48 #define FFCR_FON_MAN BIT(6)
51 * @base: memory mapped base address for this component.
52 * @dev: the device entity associated to this component.
53 * @csdev: component vitals needed by the framework.
54 * @clk: the clock this component is associated to.
59 struct coresight_device
*csdev
;
63 static void tpiu_enable_hw(struct tpiu_drvdata
*drvdata
)
65 CS_UNLOCK(drvdata
->base
);
67 /* TODO: fill this up */
69 CS_LOCK(drvdata
->base
);
72 static int tpiu_enable(struct coresight_device
*csdev
)
74 struct tpiu_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
77 ret
= clk_prepare_enable(drvdata
->clk
);
81 tpiu_enable_hw(drvdata
);
83 dev_info(drvdata
->dev
, "TPIU enabled\n");
87 static void tpiu_disable_hw(struct tpiu_drvdata
*drvdata
)
89 CS_UNLOCK(drvdata
->base
);
91 /* Clear formatter controle reg. */
92 writel_relaxed(0x0, drvdata
->base
+ TPIU_FFCR
);
93 /* Generate manual flush */
94 writel_relaxed(FFCR_FON_MAN
, drvdata
->base
+ TPIU_FFCR
);
96 CS_LOCK(drvdata
->base
);
99 static void tpiu_disable(struct coresight_device
*csdev
)
101 struct tpiu_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
103 tpiu_disable_hw(drvdata
);
105 clk_disable_unprepare(drvdata
->clk
);
107 dev_info(drvdata
->dev
, "TPIU disabled\n");
110 static const struct coresight_ops_sink tpiu_sink_ops
= {
111 .enable
= tpiu_enable
,
112 .disable
= tpiu_disable
,
115 static const struct coresight_ops tpiu_cs_ops
= {
116 .sink_ops
= &tpiu_sink_ops
,
119 static int tpiu_probe(struct amba_device
*adev
, const struct amba_id
*id
)
123 struct device
*dev
= &adev
->dev
;
124 struct coresight_platform_data
*pdata
= NULL
;
125 struct tpiu_drvdata
*drvdata
;
126 struct resource
*res
= &adev
->res
;
127 struct coresight_desc
*desc
;
128 struct device_node
*np
= adev
->dev
.of_node
;
131 pdata
= of_get_coresight_platform_data(dev
, np
);
133 return PTR_ERR(pdata
);
134 adev
->dev
.platform_data
= pdata
;
137 drvdata
= devm_kzalloc(dev
, sizeof(*drvdata
), GFP_KERNEL
);
141 drvdata
->dev
= &adev
->dev
;
142 dev_set_drvdata(dev
, drvdata
);
144 /* Validity for the resource is already checked by the AMBA core */
145 base
= devm_ioremap_resource(dev
, res
);
147 return PTR_ERR(base
);
149 drvdata
->base
= base
;
151 drvdata
->clk
= adev
->pclk
;
152 ret
= clk_prepare_enable(drvdata
->clk
);
156 /* Disable tpiu to support older devices */
157 tpiu_disable_hw(drvdata
);
159 clk_disable_unprepare(drvdata
->clk
);
161 desc
= devm_kzalloc(dev
, sizeof(*desc
), GFP_KERNEL
);
165 desc
->type
= CORESIGHT_DEV_TYPE_SINK
;
166 desc
->subtype
.sink_subtype
= CORESIGHT_DEV_SUBTYPE_SINK_PORT
;
167 desc
->ops
= &tpiu_cs_ops
;
170 drvdata
->csdev
= coresight_register(desc
);
171 if (IS_ERR(drvdata
->csdev
))
172 return PTR_ERR(drvdata
->csdev
);
174 dev_info(dev
, "TPIU initialized\n");
178 static int tpiu_remove(struct amba_device
*adev
)
180 struct tpiu_drvdata
*drvdata
= amba_get_drvdata(adev
);
182 coresight_unregister(drvdata
->csdev
);
186 static struct amba_id tpiu_ids
[] = {
194 static struct amba_driver tpiu_driver
= {
196 .name
= "coresight-tpiu",
197 .owner
= THIS_MODULE
,
200 .remove
= tpiu_remove
,
201 .id_table
= tpiu_ids
,
204 module_amba_driver(tpiu_driver
);
206 MODULE_LICENSE("GPL v2");
207 MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");