/arch/arm/mach-msm/proc_comm_test.c
C | 130 lines | 82 code | 28 blank | 20 comment | 11 complexity | 4a26674227f3d63be7dff4a87babf0de MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
1/* Copyright (c) 2009, 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 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 */
18
19/*
20 * PROC COMM TEST Driver source file
21 */
22
23#include <linux/types.h>
24#include <linux/uaccess.h>
25#include <linux/debugfs.h>
26#include <linux/module.h>
27#include "proc_comm.h"
28
29static struct dentry *dent;
30static int proc_comm_test_res;
31
32static int proc_comm_reverse_test(void)
33{
34 uint32_t data1, data2;
35 int rc;
36
37 data1 = 10;
38 data2 = 20;
39
40 rc = msm_proc_comm(PCOM_OEM_TEST_CMD, &data1, &data2);
41 if (rc)
42 return rc;
43
44 if ((data1 != 20) || (data2 != 10))
45 return -1;
46
47 return 0;
48}
49
50static ssize_t debug_read(struct file *fp, char __user *buf,
51 size_t count, loff_t *pos)
52{
53 char _buf[16];
54
55 snprintf(_buf, sizeof(_buf), "%i\n", proc_comm_test_res);
56
57 return simple_read_from_buffer(buf, count, pos, _buf, strlen(_buf));
58}
59
60static ssize_t debug_write(struct file *fp, const char __user *buf,
61 size_t count, loff_t *pos)
62{
63
64 unsigned char cmd[64];
65 int len;
66
67 if (count < 1)
68 return 0;
69
70 len = count > 63 ? 63 : count;
71
72 if (copy_from_user(cmd, buf, len))
73 return -EFAULT;
74
75 cmd[len] = 0;
76
77 if (cmd[len-1] == '\n') {
78 cmd[len-1] = 0;
79 len--;
80 }
81
82 if (!strncmp(cmd, "reverse_test", 64))
83 proc_comm_test_res = proc_comm_reverse_test();
84 else
85 proc_comm_test_res = -EINVAL;
86
87 if (proc_comm_test_res)
88 pr_err("proc comm test fail %d\n",
89 proc_comm_test_res);
90 else
91 pr_info("proc comm test passed\n");
92
93 return count;
94}
95
96static int debug_release(struct inode *ip, struct file *fp)
97{
98 return 0;
99}
100
101static int debug_open(struct inode *ip, struct file *fp)
102{
103 return 0;
104}
105
106static const struct file_operations debug_ops = {
107 .owner = THIS_MODULE,
108 .open = debug_open,
109 .release = debug_release,
110 .read = debug_read,
111 .write = debug_write,
112};
113
114static void __exit proc_comm_test_mod_exit(void)
115{
116 debugfs_remove(dent);
117}
118
119static int __init proc_comm_test_mod_init(void)
120{
121 dent = debugfs_create_file("proc_comm", 0444, 0, NULL, &debug_ops);
122 proc_comm_test_res = -1;
123 return 0;
124}
125
126module_init(proc_comm_test_mod_init);
127module_exit(proc_comm_test_mod_exit);
128
129MODULE_DESCRIPTION("PROC COMM TEST Driver");
130MODULE_LICENSE("GPL v2");