aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/coresight.c
blob: 26e25b06e0906bf1fea89668603fd9e0613d697d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/err.h>

#include "coresight.h"

enum {
	CORESIGHT_CLK_OFF,
	CORESIGHT_CLK_ON_DBG,
	CORESIGHT_CLK_ON_HSDBG,
};

struct coresight_ctx {
	struct kobject	*modulekobj;
	uint8_t		max_clk;
};

static struct coresight_ctx coresight;


struct kobject *coresight_get_modulekobj(void)
{
	return coresight.modulekobj;
}

#define CORESIGHT_ATTR(name)						\
static struct kobj_attribute name##_attr =				\
		__ATTR(name, S_IRUGO | S_IWUSR, name##_show, name##_store)

static ssize_t max_clk_store(struct kobject *kobj,
			struct kobj_attribute *attr,
			const char *buf, size_t n)
{
	unsigned long val;

	if (sscanf(buf, "%lx", &val) != 1)
		return -EINVAL;

	coresight.max_clk = val;
	return n;
}
static ssize_t max_clk_show(struct kobject *kobj,
			struct kobj_attribute *attr,
			char *buf)
{
	unsigned long val = coresight.max_clk;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}
CORESIGHT_ATTR(max_clk);

static int __init coresight_sysfs_init(void)
{
	int ret;

	coresight.modulekobj = kset_find_obj(module_kset, KBUILD_MODNAME);
	if (!coresight.modulekobj) {
		pr_err("failed to find CORESIGHT sysfs module kobject\n");
		ret = -ENOENT;
		goto err;
	}

	ret = sysfs_create_file(coresight.modulekobj, &max_clk_attr.attr);
	if (ret) {
		pr_err("failed to create CORESIGHT sysfs max_clk attribute\n");
		goto err;
	}

	return 0;
err:
	return ret;
}

static void coresight_sysfs_exit(void)
{
	sysfs_remove_file(coresight.modulekobj, &max_clk_attr.attr);
}

static int __init coresight_init(void)
{
	int ret;

	ret = coresight_sysfs_init();
	if (ret)
		goto err_sysfs;
	ret = etb_init();
	if (ret)
		goto err_etb;
	ret = tpiu_init();
	if (ret)
		goto err_tpiu;
	ret = funnel_init();
	if (ret)
		goto err_funnel;
	ret = etm_init();
	if (ret)
		goto err_etm;

	pr_info("CORESIGHT initialized\n");
	return 0;
err_etm:
	funnel_exit();
err_funnel:
	tpiu_exit();
err_tpiu:
	etb_exit();
err_etb:
	coresight_sysfs_exit();
err_sysfs:
	pr_err("CORESIGHT init failed\n");
	return ret;
}
module_init(coresight_init);

static void __exit coresight_exit(void)
{
	coresight_sysfs_exit();
	etm_exit();
	funnel_exit();
	tpiu_exit();
	etb_exit();
}
module_exit(coresight_exit);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("CoreSight ETM Debug System Driver");