/arch/arm/mach-msm/proc_comm_test.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 130 lines · 82 code · 28 blank · 20 comment · 11 complexity · 4a26674227f3d63be7dff4a87babf0de MD5 · raw file

  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. * PROC COMM TEST Driver source file
  20. */
  21. #include <linux/types.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/module.h>
  25. #include "proc_comm.h"
  26. static struct dentry *dent;
  27. static int proc_comm_test_res;
  28. static int proc_comm_reverse_test(void)
  29. {
  30. uint32_t data1, data2;
  31. int rc;
  32. data1 = 10;
  33. data2 = 20;
  34. rc = msm_proc_comm(PCOM_OEM_TEST_CMD, &data1, &data2);
  35. if (rc)
  36. return rc;
  37. if ((data1 != 20) || (data2 != 10))
  38. return -1;
  39. return 0;
  40. }
  41. static ssize_t debug_read(struct file *fp, char __user *buf,
  42. size_t count, loff_t *pos)
  43. {
  44. char _buf[16];
  45. snprintf(_buf, sizeof(_buf), "%i\n", proc_comm_test_res);
  46. return simple_read_from_buffer(buf, count, pos, _buf, strlen(_buf));
  47. }
  48. static ssize_t debug_write(struct file *fp, const char __user *buf,
  49. size_t count, loff_t *pos)
  50. {
  51. unsigned char cmd[64];
  52. int len;
  53. if (count < 1)
  54. return 0;
  55. len = count > 63 ? 63 : count;
  56. if (copy_from_user(cmd, buf, len))
  57. return -EFAULT;
  58. cmd[len] = 0;
  59. if (cmd[len-1] == '\n') {
  60. cmd[len-1] = 0;
  61. len--;
  62. }
  63. if (!strncmp(cmd, "reverse_test", 64))
  64. proc_comm_test_res = proc_comm_reverse_test();
  65. else
  66. proc_comm_test_res = -EINVAL;
  67. if (proc_comm_test_res)
  68. pr_err("proc comm test fail %d\n",
  69. proc_comm_test_res);
  70. else
  71. pr_info("proc comm test passed\n");
  72. return count;
  73. }
  74. static int debug_release(struct inode *ip, struct file *fp)
  75. {
  76. return 0;
  77. }
  78. static int debug_open(struct inode *ip, struct file *fp)
  79. {
  80. return 0;
  81. }
  82. static const struct file_operations debug_ops = {
  83. .owner = THIS_MODULE,
  84. .open = debug_open,
  85. .release = debug_release,
  86. .read = debug_read,
  87. .write = debug_write,
  88. };
  89. static void __exit proc_comm_test_mod_exit(void)
  90. {
  91. debugfs_remove(dent);
  92. }
  93. static int __init proc_comm_test_mod_init(void)
  94. {
  95. dent = debugfs_create_file("proc_comm", 0444, 0, NULL, &debug_ops);
  96. proc_comm_test_res = -1;
  97. return 0;
  98. }
  99. module_init(proc_comm_test_mod_init);
  100. module_exit(proc_comm_test_mod_exit);
  101. MODULE_DESCRIPTION("PROC COMM TEST Driver");
  102. MODULE_LICENSE("GPL v2");