blob: def7467882f7d6005eda55a29c2a4d33550c43f2 [file] [log] [blame]
Pratik Patel7831c082011-06-08 21:44:37 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
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.
6 *
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.
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/io.h>
17#include <linux/err.h>
18
19#include "qdss.h"
20
21#define tpiu_writel(tpiu, val, off) __raw_writel((val), tpiu.base + off)
22#define tpiu_readl(tpiu, off) __raw_readl(tpiu.base + off)
23
24#define TPIU_SUPPORTED_PORT_SIZE (0x000)
25#define TPIU_CURRENT_PORT_SIZE (0x004)
26#define TPIU_SUPPORTED_TRIGGER_MODES (0x100)
27#define TPIU_TRIGGER_COUNTER_VALUE (0x104)
28#define TPIU_TRIGGER_MULTIPLIER (0x108)
29#define TPIU_SUPPORTED_TEST_PATTERNM (0x200)
30#define TPIU_CURRENT_TEST_PATTERNM (0x204)
31#define TPIU_TEST_PATTERN_REPEAT_COUNTER (0x208)
32#define TPIU_FORMATTER_AND_FLUSH_STATUS (0x300)
33#define TPIU_FORMATTER_AND_FLUSH_CONTROL (0x304)
34#define TPIU_FORMATTER_SYNCHRONIZATION_COUNTER (0x308)
35#define TPIU_EXTCTL_IN_PORT (0x400)
36#define TPIU_EXTCTL_OUT_PORT (0x404)
37#define TPIU_ITTRFLINACK (0xEE4)
38#define TPIU_ITTRFLIN (0xEE8)
39#define TPIU_ITATBDATA0 (0xEEC)
40#define TPIU_ITATBCTR2 (0xEF0)
41#define TPIU_ITATBCTR1 (0xEF4)
42#define TPIU_ITATBCTR0 (0xEF8)
43
44
45#define TPIU_LOCK() \
46do { \
47 mb(); \
48 tpiu_writel(tpiu, MAGIC2, CS_LAR); \
49} while (0)
50#define TPIU_UNLOCK() \
51do { \
52 tpiu_writel(tpiu, MAGIC1, CS_LAR); \
53 mb(); \
54} while (0)
55
56struct tpiu_ctx {
57 void __iomem *base;
58 bool enabled;
59 atomic_t in_use;
60 struct device *dev;
61};
62
63static struct tpiu_ctx tpiu;
64
65static void __tpiu_disable(void)
66{
67 TPIU_UNLOCK();
68
69 tpiu_writel(tpiu, 0x3000, TPIU_FORMATTER_AND_FLUSH_CONTROL);
70 tpiu_writel(tpiu, 0x3040, TPIU_FORMATTER_AND_FLUSH_CONTROL);
71
72 TPIU_LOCK();
73}
74
75void tpiu_disable(void)
76{
77 __tpiu_disable();
78 tpiu.enabled = false;
79 dev_info(tpiu.dev, "tpiu disabled\n");
80}
81
82static int __devinit tpiu_probe(struct platform_device *pdev)
83{
84 int ret;
85 struct resource *res;
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res) {
89 ret = -EINVAL;
90 goto err_res;
91 }
92
93 tpiu.base = ioremap_nocache(res->start, resource_size(res));
94 if (!tpiu.base) {
95 ret = -EINVAL;
96 goto err_ioremap;
97 }
98
99 tpiu.dev = &pdev->dev;
100
101 return 0;
102
103err_ioremap:
104err_res:
105 return ret;
106}
107
108static int __devexit tpiu_remove(struct platform_device *pdev)
109{
110 if (tpiu.enabled)
111 tpiu_disable();
112 iounmap(tpiu.base);
113
114 return 0;
115}
116
117static struct platform_driver tpiu_driver = {
118 .probe = tpiu_probe,
119 .remove = __devexit_p(tpiu_remove),
120 .driver = {
121 .name = "msm_tpiu",
122 },
123};
124
125static int __init tpiu_init(void)
126{
127 return platform_driver_register(&tpiu_driver);
128}
129module_init(tpiu_init);
130
131static void __exit tpiu_exit(void)
132{
133 platform_driver_unregister(&tpiu_driver);
134}
135module_exit(tpiu_exit);
136
137MODULE_LICENSE("GPL v2");
138MODULE_DESCRIPTION("Coresight Trace Port Interface Unit");