debug.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #if defined(CONFIG_MTK_HDMI_SUPPORT)
  2. #include <linux/string.h>
  3. #include <linux/time.h>
  4. #include <linux/uaccess.h>
  5. #include <linux/debugfs.h>
  6. #include <mach/mt_typedefs.h>
  7. #if defined(CONFIG_MTK_INTERNAL_HDMI_SUPPORT)
  8. #include "internal_hdmi_drv.h"
  9. #elif defined(CONFIG_MTK_INTERNAL_MHL_SUPPORT)
  10. #include "inter_mhl_drv.h"
  11. #else
  12. #include "hdmi_drv.h"
  13. #endif
  14. #include "linux/hdmitx.h"
  15. /*
  16. void DBG_Init(void);
  17. void DBG_Deinit(void);
  18. extern void hdmi_log_enable(int enable);
  19. extern void hdmi_cable_fake_plug_in(void);
  20. extern void hdmi_cable_fake_plug_out(void);
  21. */
  22. /* --------------------------------------------------------------------------- */
  23. /* External variable declarations */
  24. /* --------------------------------------------------------------------------- */
  25. /* extern LCM_DRIVER *lcm_drv; */
  26. /* --------------------------------------------------------------------------- */
  27. /* Debug Options */
  28. /* --------------------------------------------------------------------------- */
  29. static char STR_HELP[] =
  30. "\n"
  31. "USAGE\n"
  32. " echo [ACTION]... > hdmi\n"
  33. "\n" "ACTION\n" " hdmitx:[on|off]\n" " enable hdmi video output\n" "\n";
  34. /* extern void hdmi_log_enable(int enable); */
  35. /* TODO: this is a temp debug solution */
  36. /* extern void hdmi_cable_fake_plug_in(void); */
  37. /* extern int hdmi_drv_init(void); */
  38. static void process_dbg_opt(const char *opt)
  39. {
  40. if (0)
  41. ;/* to do*/
  42. #if defined(CONFIG_MTK_HDMI_SUPPORT)
  43. else if (0 == strncmp(opt, "on", 2)) {
  44. hdmi_power_on();
  45. } else if (0 == strncmp(opt, "off", 3)) {
  46. hdmi_power_off();
  47. } else if (0 == strncmp(opt, "suspend", 7)) {
  48. hdmi_suspend();
  49. } else if (0 == strncmp(opt, "resume", 6)) {
  50. hdmi_resume();
  51. /* } else if (0 == strncmp(opt, "colorbar", 8)) { */
  52. /*} else if (0 == strncmp(opt, "ldooff", 6)) { */
  53. } else if (0 == strncmp(opt, "loglv:", 6)) {
  54. unsigned int lv = *(opt + 6) - '0';
  55. if (lv >= 0 && lv <= 9)
  56. hdmi_log_level(lv);
  57. } else if (0 == strncmp(opt, "log:", 4)) {
  58. if (0 == strncmp(opt + 4, "on", 2))
  59. hdmi_log_enable(true);
  60. else if (0 == strncmp(opt + 4, "off", 3))
  61. hdmi_log_enable(false);
  62. else
  63. goto Error;
  64. } else if (0 == strncmp(opt, "fakecablein:", 12)) {
  65. if (0 == strncmp(opt + 12, "enable", 6))
  66. hdmi_cable_fake_plug_in();
  67. else if (0 == strncmp(opt + 12, "disable", 7))
  68. hdmi_cable_fake_plug_out();
  69. else
  70. goto Error;
  71. }
  72. #endif
  73. else
  74. goto Error;
  75. return;
  76. Error:
  77. pr_err("[hdmitx] parse command error!\n\n%s", STR_HELP);
  78. }
  79. static void process_dbg_cmd(char *cmd)
  80. {
  81. char *tok;
  82. pr_info("[hdmitx] %s\n", cmd);
  83. while ((tok = strsep(&cmd, " ")) != NULL)
  84. process_dbg_opt(tok);
  85. }
  86. /* --------------------------------------------------------------------------- */
  87. /* Debug FileSystem Routines */
  88. /* --------------------------------------------------------------------------- */
  89. struct dentry *hdmitx_dbgfs = NULL;
  90. static ssize_t debug_open(struct inode *inode, struct file *file)
  91. {
  92. file->private_data = inode->i_private;
  93. return 0;
  94. }
  95. static char debug_buffer[2048];
  96. static ssize_t debug_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos)
  97. {
  98. const int debug_bufmax = sizeof(debug_buffer) - 1;
  99. int n = 0;
  100. n += scnprintf(debug_buffer + n, debug_bufmax - n, STR_HELP);
  101. debug_buffer[n++] = 0;
  102. return simple_read_from_buffer(ubuf, count, ppos, debug_buffer, n);
  103. }
  104. static ssize_t debug_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
  105. {
  106. const int debug_bufmax = sizeof(debug_buffer) - 1;
  107. size_t ret;
  108. ret = count;
  109. if (count > debug_bufmax)
  110. count = debug_bufmax;
  111. if (copy_from_user(&debug_buffer, ubuf, count))
  112. return -EFAULT;
  113. debug_buffer[count] = 0;
  114. process_dbg_cmd(debug_buffer);
  115. return ret;
  116. }
  117. static const struct file_operations debug_fops = {
  118. .read = debug_read,
  119. .write = debug_write,
  120. .open = debug_open,
  121. };
  122. void HDMI_DBG_Init(void)
  123. {
  124. hdmitx_dbgfs = debugfs_create_file("hdmi", S_IFREG | S_IRUGO, NULL, (void *)0, &debug_fops);
  125. }
  126. void HDMI_DBG_Deinit(void)
  127. {
  128. debugfs_remove(hdmitx_dbgfs);
  129. }
  130. #endif