aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-s5pv210/level.c
blob: 12cf8bbac90c062019e6f01b50d2d679061bf016 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/fcntl.h>

#include <asm/uaccess.h>

#define LEVEL_DEV_NAME	"level"

#define LEVEL_DEV_IOCTL_CMD   0xee

#define LEVEL_DEV_UNSET_UPLOAD    _IO(LEVEL_DEV_IOCTL_CMD, 0x1)
#define LEVEL_DEV_SET_AUTOTEST    _IO(LEVEL_DEV_IOCTL_CMD, 0x2)
#define LEVEL_DEV_SET_DEBUGLEVEL    _IO(LEVEL_DEV_IOCTL_CMD, 0x3)
#define LEVEL_DEV_GET_DEBUGLEVEL    _IO(LEVEL_DEV_IOCTL_CMD, 0x4)

#define KERNEL_SEC_DEBUG_LEVEL_LOW 0xA0A0
#define KERNEL_SEC_DEBUG_LEVEL_MID 0xB0B0
#define KERNEL_SEC_DEBUG_LEVEL_HIGH 0xC0C0
#define FAKED_DEBUG_LEVEL KERNEL_SEC_DEBUG_LEVEL_HIGH


static unsigned int get_debug_level(void);

static ssize_t show_control(struct device *d,
		struct device_attribute *attr, char *buf);
static ssize_t store_control(struct device *d,
		struct device_attribute *attr, const char *buf, size_t count);
		
static DEVICE_ATTR(control, S_IRUGO | S_IWUGO, show_control, store_control);

static struct attribute *levelctl_attributes[] = {
	&dev_attr_control.attr,
	NULL
};

static const struct attribute_group levelctl_group = {
	.attrs = levelctl_attributes,
};

static ssize_t show_control(struct device *d,
		struct device_attribute *attr, char *buf)
{
	char *p = buf;
	unsigned int val;

	val = get_debug_level();
	
	p += sprintf(p, "0x%4x\n",val);

	return p - buf;
}

static ssize_t store_control(struct device *d,
		struct device_attribute *attr, const char *buf, size_t count)
{

	if(!strncmp(buf, "clear", 5)) {
		// clear upload magic number
		printk("fake_level: %s clear", __func__);
		//kernel_sec_clear_upload_magic_number();
		return count;
	}

	if(!strncmp(buf, "autotest", 8)) {
		// set auto test
		printk("fake_level: %s autotest", __func__);
		//kernel_sec_set_autotest();
		return count;
	}

	if(!strncmp(buf, "set", 3)) {
		// set debug level
		printk("fake_level: %s set", __func__);
		//set_debug_level();
		return count;
	}

return count;
}

static int level_open(struct inode *inode, struct file *filp)
{
	printk("level Device open\n");

	return 0;
}

static int level_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
	unsigned int val;

	switch (cmd) {
		case LEVEL_DEV_UNSET_UPLOAD:
			printk("fake_level: %s LEVEL_DEV_UNSET_UPLOAD", __func__);
			//kernel_sec_clear_upload_magic_number();
			return 0;

		case LEVEL_DEV_SET_AUTOTEST:
			printk("fake_level: %s LEVEL_DEV_SET_AUTOTEST", __func__);
			//kernel_sec_set_autotest();
			return 0;

		case LEVEL_DEV_SET_DEBUGLEVEL:
			printk("fake_level: %s LEVEL_DEV_SET_DEBUGLEVEL", __func__);
			//set_debug_level();
			return 0;
			
		case LEVEL_DEV_GET_DEBUGLEVEL:
		{
			val = get_debug_level();
			return copy_to_user((unsigned int *)arg, &val, sizeof(val));
		}
		default:
			printk("Unknown Cmd: %x\n", cmd);
			break;
		}
	return -ENOTSUPP;
}

static unsigned int get_debug_level()
{
	return FAKED_DEBUG_LEVEL;
}

static struct file_operations level_fops = 
{
	.owner = THIS_MODULE,
	.open = level_open,
	.unlocked_ioctl = level_ioctl,
};

static struct miscdevice level_device = {
	.minor  = MISC_DYNAMIC_MINOR,
	.name   = LEVEL_DEV_NAME,
	.fops   = &level_fops,
};

/* init & cleanup. */
static int __init level_init(void)
{
	int result;

	printk("level device init\n");

	result = misc_register(&level_device);
	if (result <0) 
		return result;
	
  result = sysfs_create_group(&level_device.this_device->kobj, &levelctl_group);
	if (result < 0) {
		printk("failed to create sysfs files\n");
	}

	return 0;
}

static void __exit level_exit(void)
{
	printk("level device exit\n");
	misc_deregister(&level_device);
}

module_init(level_init);
module_exit(level_exit);