Initial commit
[kernel/linux-3.0.git] / arch / arm / mach-exynos / coresight.c
1 /* Copyright (c) 2012, 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/init.h>
16 #include <linux/types.h>
17 #include <linux/device.h>
18 #include <linux/platform_device.h>
19 #include <linux/io.h>
20 #include <linux/err.h>
21
22 #include "coresight.h"
23
24 enum {
25         CORESIGHT_CLK_OFF,
26         CORESIGHT_CLK_ON_DBG,
27         CORESIGHT_CLK_ON_HSDBG,
28 };
29
30 struct coresight_ctx {
31         struct kobject  *modulekobj;
32         uint8_t         max_clk;
33 };
34
35 static struct coresight_ctx coresight;
36
37
38 struct kobject *coresight_get_modulekobj(void)
39 {
40         return coresight.modulekobj;
41 }
42
43 #define CORESIGHT_ATTR(name)                                            \
44 static struct kobj_attribute name##_attr =                              \
45                 __ATTR(name, S_IRUGO | S_IWUSR, name##_show, name##_store)
46
47 static ssize_t max_clk_store(struct kobject *kobj,
48                         struct kobj_attribute *attr,
49                         const char *buf, size_t n)
50 {
51         unsigned long val;
52
53         if (sscanf(buf, "%lx", &val) != 1)
54                 return -EINVAL;
55
56         coresight.max_clk = val;
57         return n;
58 }
59 static ssize_t max_clk_show(struct kobject *kobj,
60                         struct kobj_attribute *attr,
61                         char *buf)
62 {
63         unsigned long val = coresight.max_clk;
64         return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
65 }
66 CORESIGHT_ATTR(max_clk);
67
68 static int __init coresight_sysfs_init(void)
69 {
70         int ret;
71
72         coresight.modulekobj = kset_find_obj(module_kset, KBUILD_MODNAME);
73         if (!coresight.modulekobj) {
74                 pr_err("failed to find CORESIGHT sysfs module kobject\n");
75                 ret = -ENOENT;
76                 goto err;
77         }
78
79         ret = sysfs_create_file(coresight.modulekobj, &max_clk_attr.attr);
80         if (ret) {
81                 pr_err("failed to create CORESIGHT sysfs max_clk attribute\n");
82                 goto err;
83         }
84
85         return 0;
86 err:
87         return ret;
88 }
89
90 static void coresight_sysfs_exit(void)
91 {
92         sysfs_remove_file(coresight.modulekobj, &max_clk_attr.attr);
93 }
94
95 static int __init coresight_init(void)
96 {
97         int ret;
98
99         ret = coresight_sysfs_init();
100         if (ret)
101                 goto err_sysfs;
102         ret = etb_init();
103         if (ret)
104                 goto err_etb;
105         ret = tpiu_init();
106         if (ret)
107                 goto err_tpiu;
108         ret = funnel_init();
109         if (ret)
110                 goto err_funnel;
111         ret = etm_init();
112         if (ret)
113                 goto err_etm;
114
115         pr_info("CORESIGHT initialized\n");
116         return 0;
117 err_etm:
118         funnel_exit();
119 err_funnel:
120         tpiu_exit();
121 err_tpiu:
122         etb_exit();
123 err_etb:
124         coresight_sysfs_exit();
125 err_sysfs:
126         pr_err("CORESIGHT init failed\n");
127         return ret;
128 }
129 module_init(coresight_init);
130
131 static void __exit coresight_exit(void)
132 {
133         coresight_sysfs_exit();
134         etm_exit();
135         funnel_exit();
136         tpiu_exit();
137         etb_exit();
138 }
139 module_exit(coresight_exit);
140
141 MODULE_LICENSE("GPL v2");
142 MODULE_DESCRIPTION("CoreSight ETM Debug System Driver");