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