blob: fa1563560275c1813f5c409c98e74143ee871b61 [file] [log] [blame]
Pratik Patel17f3b822011-11-21 12:41:47 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Pratik Patel7831c082011-06-08 21:44:37 -07002 *
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
Pratik Patelb27a9352012-03-17 22:37:21 -070021#include "qdss-priv.h"
Pratik Patel7831c082011-06-08 21:44:37 -070022
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
Pratik Patel61de7302012-03-07 12:06:10 -080026#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)
Pratik Patel7831c082011-06-08 21:44:37 -070039#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(); \
Pratik Patel17f3b822011-11-21 12:41:47 -080050 tpiu_writel(tpiu, 0x0, CS_LAR); \
Pratik Patel7831c082011-06-08 21:44:37 -070051} while (0)
52#define TPIU_UNLOCK() \
53do { \
Pratik Patel17f3b822011-11-21 12:41:47 -080054 tpiu_writel(tpiu, CS_UNLOCK_MAGIC, CS_LAR); \
Pratik Patel7831c082011-06-08 21:44:37 -070055 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
Pratik Patel61de7302012-03-07 12:06:10 -080070 tpiu_writel(tpiu, 0x3000, TPIU_FFCR);
71 tpiu_writel(tpiu, 0x3040, TPIU_FFCR);
Pratik Patel7831c082011-06-08 21:44:37 -070072
73 TPIU_LOCK();
74}
75
76void tpiu_disable(void)
77{
78 __tpiu_disable();
79 tpiu.enabled = false;
Pratik Patel61de7302012-03-07 12:06:10 -080080 dev_info(tpiu.dev, "TPIU disabled\n");
Pratik Patel7831c082011-06-08 21:44:37 -070081}
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
Pratik Patel61de7302012-03-07 12:06:10 -0800102 dev_info(tpiu.dev, "TPIU initialized\n");
Pratik Patel7831c082011-06-08 21:44:37 -0700103 return 0;
104
105err_ioremap:
106err_res:
Pratik Patel61de7302012-03-07 12:06:10 -0800107 dev_err(tpiu.dev, "TPIU init failed\n");
Pratik Patel7831c082011-06-08 21:44:37 -0700108 return ret;
109}
110
Pratik Patelf6fe9182012-03-20 14:04:18 -0700111static int __devexit tpiu_remove(struct platform_device *pdev)
Pratik Patel7831c082011-06-08 21:44:37 -0700112{
113 if (tpiu.enabled)
114 tpiu_disable();
115 iounmap(tpiu.base);
116
117 return 0;
118}
119
120static struct platform_driver tpiu_driver = {
121 .probe = tpiu_probe,
Pratik Patelf6fe9182012-03-20 14:04:18 -0700122 .remove = __devexit_p(tpiu_remove),
Pratik Patel7831c082011-06-08 21:44:37 -0700123 .driver = {
124 .name = "msm_tpiu",
125 },
126};
127
Pratik Patelf6fe9182012-03-20 14:04:18 -0700128static int __init tpiu_init(void)
Pratik Patel7831c082011-06-08 21:44:37 -0700129{
130 return platform_driver_register(&tpiu_driver);
131}
Pratik Patelf6fe9182012-03-20 14:04:18 -0700132module_init(tpiu_init);
Pratik Patel7831c082011-06-08 21:44:37 -0700133
Pratik Patelf6fe9182012-03-20 14:04:18 -0700134static void __exit tpiu_exit(void)
Pratik Patel7831c082011-06-08 21:44:37 -0700135{
136 platform_driver_unregister(&tpiu_driver);
137}
Pratik Patelf6fe9182012-03-20 14:04:18 -0700138module_exit(tpiu_exit);
139
140MODULE_LICENSE("GPL v2");
141MODULE_DESCRIPTION("CoreSight Trace Port Interface Unit driver");