blob: 7593ff249d4160f9548c8da33fdc07e886ba44fa [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2009, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -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
14/*
15 * PROC COMM TEST Driver source file
16 */
17
18#include <linux/types.h>
19#include <linux/uaccess.h>
20#include <linux/debugfs.h>
21#include <linux/module.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070022#include <mach/proc_comm.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023
24static struct dentry *dent;
25static int proc_comm_test_res;
26
27static int proc_comm_reverse_test(void)
28{
29 uint32_t data1, data2;
30 int rc;
31
32 data1 = 10;
33 data2 = 20;
34
35 rc = msm_proc_comm(PCOM_OEM_TEST_CMD, &data1, &data2);
36 if (rc)
37 return rc;
38
39 if ((data1 != 20) || (data2 != 10))
40 return -1;
41
42 return 0;
43}
44
45static ssize_t debug_read(struct file *fp, char __user *buf,
46 size_t count, loff_t *pos)
47{
48 char _buf[16];
49
50 snprintf(_buf, sizeof(_buf), "%i\n", proc_comm_test_res);
51
52 return simple_read_from_buffer(buf, count, pos, _buf, strlen(_buf));
53}
54
55static ssize_t debug_write(struct file *fp, const char __user *buf,
56 size_t count, loff_t *pos)
57{
58
59 unsigned char cmd[64];
60 int len;
61
62 if (count < 1)
63 return 0;
64
65 len = count > 63 ? 63 : count;
66
67 if (copy_from_user(cmd, buf, len))
68 return -EFAULT;
69
70 cmd[len] = 0;
71
72 if (cmd[len-1] == '\n') {
73 cmd[len-1] = 0;
74 len--;
75 }
76
77 if (!strncmp(cmd, "reverse_test", 64))
78 proc_comm_test_res = proc_comm_reverse_test();
79 else
80 proc_comm_test_res = -EINVAL;
81
82 if (proc_comm_test_res)
83 pr_err("proc comm test fail %d\n",
84 proc_comm_test_res);
85 else
86 pr_info("proc comm test passed\n");
87
88 return count;
89}
90
91static int debug_release(struct inode *ip, struct file *fp)
92{
93 return 0;
94}
95
96static int debug_open(struct inode *ip, struct file *fp)
97{
98 return 0;
99}
100
101static const struct file_operations debug_ops = {
102 .owner = THIS_MODULE,
103 .open = debug_open,
104 .release = debug_release,
105 .read = debug_read,
106 .write = debug_write,
107};
108
109static void __exit proc_comm_test_mod_exit(void)
110{
111 debugfs_remove(dent);
112}
113
114static int __init proc_comm_test_mod_init(void)
115{
116 dent = debugfs_create_file("proc_comm", 0444, 0, NULL, &debug_ops);
117 proc_comm_test_res = -1;
118 return 0;
119}
120
121module_init(proc_comm_test_mod_init);
122module_exit(proc_comm_test_mod_exit);
123
124MODULE_DESCRIPTION("PROC COMM TEST Driver");
125MODULE_LICENSE("GPL v2");