mtk_dp_debug.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright (c) 2020 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mtk_dp_debug.h"
  14. #include "mtk_dp.h"
  15. #include "mtk_dp_api.h"
  16. #if IS_ENABLED(CONFIG_DEBUG_FS)
  17. #include <linux/debugfs.h>
  18. #endif
  19. #if IS_ENABLED(CONFIG_PROC_FS)
  20. #include <linux/proc_fs.h>
  21. #endif
  22. static bool g_dptx_log;
  23. void mtk_dp_debug_enable(bool enable)
  24. {
  25. g_dptx_log = enable;
  26. }
  27. bool mtk_dp_debug_get(void)
  28. {
  29. return g_dptx_log;
  30. }
  31. void mtk_dp_debug(const char *opt)
  32. {
  33. DPTXFUNC("[debug]: %s\n", opt);
  34. if (strncmp(opt, "fakecablein:", 12) == 0) {
  35. if (strncmp(opt + 12, "enable", 6) == 0) {
  36. if (strncmp(opt + 12, "enable4k30P6", 12) == 0)
  37. mtk_dp_fake_plugin(SINK_3840_2160_30, 0);
  38. else if (strncmp(opt + 12, "enable4k30p8", 12) == 0)
  39. mtk_dp_fake_plugin(SINK_3840_2160_30, 1);
  40. else if (strncmp(opt + 12, "enable4k30p10", 13) == 0)
  41. mtk_dp_fake_plugin(SINK_3840_2160_30, 2);
  42. else if (strncmp(opt + 12, "enable4k60p6", 12) == 0)
  43. mtk_dp_fake_plugin(SINK_3840_2160, 0);
  44. else if (strncmp(opt + 12, "enable4k60p8", 12) == 0)
  45. mtk_dp_fake_plugin(SINK_3840_2160, 1);
  46. else if (strncmp(opt + 12, "enable4k60p10", 13) == 0)
  47. mtk_dp_fake_plugin(SINK_3840_2160, 2);
  48. else if (strncmp(opt + 12, "enable720p6", 11) == 0)
  49. mtk_dp_fake_plugin(SINK_1280_720, 0);
  50. else if (strncmp(opt + 12, "enable720p8", 11) == 0)
  51. mtk_dp_fake_plugin(SINK_1280_720, 1);
  52. else if (strncmp(opt + 12, "enable720p10", 12) == 0)
  53. mtk_dp_fake_plugin(SINK_1280_720, 2);
  54. else if (strncmp(opt + 12, "enable480p6", 11) == 0)
  55. mtk_dp_fake_plugin(SINK_640_480, 0);
  56. else if (strncmp(opt + 12, "enable480p8", 11) == 0)
  57. mtk_dp_fake_plugin(SINK_640_480, 1);
  58. else if (strncmp(opt + 12, "enable480p10", 12) == 0)
  59. mtk_dp_fake_plugin(SINK_640_480, 2);
  60. else if (strncmp(opt + 12, "enable1080p6", 12) == 0)
  61. mtk_dp_fake_plugin(SINK_1920_1080, 0);
  62. else if (strncmp(opt + 12, "enable1080p8", 12) == 0)
  63. mtk_dp_fake_plugin(SINK_1920_1080, 1);
  64. else if (strncmp(opt + 12, "enable1080p10", 13) == 0)
  65. mtk_dp_fake_plugin(SINK_1920_1080, 2);
  66. } else
  67. DDPINFO("fakecablein error msg\n");
  68. } else if (strncmp(opt, "fec:", 4) == 0) {
  69. if (strncmp(opt + 4, "enable", 6) == 0)
  70. mtk_dp_fec_enable(1);
  71. else if (strncmp(opt + 4, "disable", 7) == 0)
  72. mtk_dp_fec_enable(0);
  73. else
  74. DDPINFO("fec:enable/disable error msg\n");
  75. } else if (strncmp(opt, "power:", 6) == 0) {
  76. if (strncmp(opt + 6, "on", 2) == 0)
  77. mtk_dp_power_save(0x1);
  78. else if (strncmp(opt + 6, "off", 3) == 0)
  79. mtk_dp_power_save(0x0);
  80. } else if (strncmp(opt, "audio:", 6) == 0) {
  81. if (strncmp(opt + 6, "2ch", 3) == 0)
  82. mtk_dp_force_audio(0, 0xff, 0xff);
  83. else if (strncmp(opt + 6, "8ch", 3) == 0)
  84. mtk_dp_force_audio(6, 0xff, 0xff);
  85. if (strncmp(opt + 9, "32fs", 4) == 0)
  86. mtk_dp_force_audio(0xff, 0, 0xff);
  87. else if (strncmp(opt + 9, "44fs", 4) == 0)
  88. mtk_dp_force_audio(0xff, 1, 0xff);
  89. else if (strncmp(opt + 9, "48fs", 4) == 0)
  90. mtk_dp_force_audio(0xff, 2, 0xff);
  91. else if (strncmp(opt + 9, "96fs", 4) == 0)
  92. mtk_dp_force_audio(0xff, 3, 0xff);
  93. else if (strncmp(opt + 9, "192f", 4) == 0)
  94. mtk_dp_force_audio(0xff, 4, 0xff);
  95. if (strncmp(opt + 13, "16bit", 5) == 0)
  96. mtk_dp_force_audio(0xff, 0xff, 0);
  97. else if (strncmp(opt + 13, "20bit", 5) == 0)
  98. mtk_dp_force_audio(0xff, 0xff, 1);
  99. else if (strncmp(opt + 13, "24bit", 5) == 0)
  100. mtk_dp_force_audio(0xff, 0xff, 2);
  101. } else if (strncmp(opt, "dptest:", 7) == 0) {
  102. if (strncmp(opt + 7, "2", 1) == 0)
  103. mtk_dp_test(2);
  104. else if (strncmp(opt + 7, "4", 1) == 0)
  105. mtk_dp_test(4);
  106. else if (strncmp(opt + 7, "8", 1) == 0)
  107. mtk_dp_test(8);
  108. else
  109. DDPINFO("dptest error msg\n");
  110. } else if (strncmp(opt, "debug_log:", 10) == 0) {
  111. if (strncmp(opt + 10, "on", 2) == 0)
  112. mtk_dp_debug_enable(true);
  113. else if (strncmp(opt + 10, "off", 3) == 0)
  114. mtk_dp_debug_enable(false);
  115. } else if (strncmp(opt, "force_hdcp13:", 13) == 0) {
  116. if (strncmp(opt + 13, "enable", 6) == 0)
  117. mtk_dp_force_hdcp1x(true);
  118. else
  119. mtk_dp_force_hdcp1x(false);
  120. } else if (strncmp(opt, "hdcp:", 5) == 0) {
  121. if (strncmp(opt + 5, "enable", 6) == 0)
  122. mtk_dp_hdcp_enable(true);
  123. else if (strncmp(opt + 5, "disable", 7) == 0)
  124. mtk_dp_hdcp_enable(false);
  125. } else if (strncmp(opt, "adjust_phy:", 11) == 0) {
  126. int ret = 0;
  127. uint8_t index, c0, cp1;
  128. ret = sscanf(opt, "adjust_phy:%d,%d,%d\n", &index, &c0, &cp1);
  129. if (ret != 3) {
  130. DPTXERR("ret = %s\n", ret);
  131. return;
  132. }
  133. mtk_dp_set_adjust_phy(index, c0, cp1);
  134. } else if (strncmp(opt, "setpowermode", 12) == 0) {
  135. mtk_dp_SWInterruptSet(2);
  136. mdelay(100);
  137. mtk_dp_SWInterruptSet(4);
  138. } else if (strncmp(opt, "pattern:", 8) == 0) {
  139. int ret = 0;
  140. uint8_t enable, resolution;
  141. ret = sscanf(opt, "pattern:%d,%d\n", &enable, &resolution);
  142. if (ret != 2) {
  143. DPTXMSG("ret = %s\n", ret);
  144. return;
  145. }
  146. DPTXMSG("Paterrn Gen:enable = %d, resolution =%d\n",
  147. enable, resolution);
  148. mdrv_DPTx_PatternSet(enable, resolution);
  149. } else if (strncmp(opt, "maxlinkrate:", 12) == 0) {
  150. int ret = 0;
  151. uint8_t enable, maxlinkrate;
  152. ret = sscanf(opt, "maxlinkrate:%d,%d\n", &enable, &maxlinkrate);
  153. if (ret != 2) {
  154. DPTXMSG("ret = %s\n", ret);
  155. return;
  156. }
  157. DPTXMSG("set max link rate:enable = %d, maxlinkrate =%d\n",
  158. enable, maxlinkrate);
  159. mdrv_DPTx_set_maxlinkrate(enable, maxlinkrate);
  160. }
  161. }
  162. #if IS_ENABLED(CONFIG_DEBUG_FS)
  163. static struct dentry *mtkdp_dbgfs;
  164. #endif
  165. #if IS_ENABLED(CONFIG_PROC_FS)
  166. static struct proc_dir_entry *mtkdp_procfs;
  167. #endif
  168. struct mtk_dp_debug_info {
  169. char *name;
  170. uint8_t index;
  171. };
  172. enum mtk_dp_debug_index {
  173. DP_INFO_HDCP = 0,
  174. DP_INFO_PHY = 1,
  175. DP_INFO_MAX
  176. };
  177. static struct mtk_dp_debug_info dp_info[DP_INFO_MAX] = {
  178. {"HDCP", DP_INFO_HDCP},
  179. {"PHY", DP_INFO_PHY},
  180. };
  181. static uint8_t g_infoIndex = DP_INFO_HDCP;
  182. static int mtk_dp_debug_open(struct inode *inode, struct file *file)
  183. {
  184. file->private_data = inode->i_private;
  185. return 0;
  186. }
  187. static ssize_t mtk_dp_debug_read(struct file *file, char __user *ubuf,
  188. size_t count, loff_t *ppos)
  189. {
  190. int ret = 0;
  191. char *buffer;
  192. buffer = kmalloc(PAGE_SIZE/8, GFP_KERNEL);
  193. if (!buffer)
  194. return -ENOMEM;
  195. switch (g_infoIndex) {
  196. case DP_INFO_HDCP:
  197. ret = mtk_dp_hdcp_getInfo(buffer, PAGE_SIZE/8);
  198. break;
  199. case DP_INFO_PHY:
  200. ret = mtk_dp_phy_getInfo(buffer, PAGE_SIZE/8);
  201. break;
  202. default:
  203. DPTXERR("Invalid inedx!");
  204. }
  205. if (ret > 0)
  206. ret = simple_read_from_buffer(ubuf, count, ppos, buffer, ret);
  207. kfree(buffer);
  208. return ret;
  209. }
  210. static void mtk_dp_process_dbg_opt(const char *opt)
  211. {
  212. int i = 0;
  213. for (i = 0; i < DP_INFO_MAX; i++) {
  214. if (!strncmp(opt, dp_info[i].name, strlen(dp_info[i].name))) {
  215. g_infoIndex = dp_info[i].index;
  216. break;
  217. }
  218. }
  219. if (g_infoIndex == DP_INFO_MAX)
  220. g_infoIndex = DP_INFO_HDCP;
  221. }
  222. static ssize_t mtk_dp_debug_write(struct file *file, const char __user *ubuf,
  223. size_t count, loff_t *ppos)
  224. {
  225. const int debug_bufmax = 512 - 1;
  226. size_t ret;
  227. char cmd_buffer[512];
  228. char *tok;
  229. char *cmd = cmd_buffer;
  230. ret = count;
  231. if (count > debug_bufmax)
  232. count = debug_bufmax;
  233. if (copy_from_user(&cmd_buffer, ubuf, count) != 0ULL)
  234. return -EFAULT;
  235. cmd_buffer[count] = '\0';
  236. DPTXMSG("[mtkdp_dbg]%s!\n", cmd_buffer);
  237. while ((tok = strsep(&cmd, " ")) != NULL)
  238. mtk_dp_process_dbg_opt(tok);
  239. return ret;
  240. }
  241. static const struct file_operations dp_debug_fops = {
  242. .read = mtk_dp_debug_read,
  243. .write = mtk_dp_debug_write,
  244. .open = mtk_dp_debug_open,
  245. };
  246. int mtk_dp_debugfs_init(void)
  247. {
  248. #if IS_ENABLED(CONFIG_DEBUG_FS)
  249. mtkdp_dbgfs = debugfs_create_file("mtk_dpinfo", 0644,
  250. NULL, NULL, &dp_debug_fops);
  251. if (IS_ERR_OR_NULL(mtkdp_dbgfs))
  252. return -ENOMEM;
  253. #endif
  254. #if IS_ENABLED(CONFIG_PROC_FS)
  255. mtkdp_procfs = proc_create("mtk_dpinfo", 0644, NULL,
  256. &dp_debug_fops);
  257. if (IS_ERR_OR_NULL(mtkdp_procfs))
  258. return -ENOMEM;
  259. #endif
  260. return 0;
  261. }
  262. void mtk_dp_debugfs_deinit(void)
  263. {
  264. #if IS_ENABLED(CONFIG_DEBUG_FS)
  265. debugfs_remove(mtkdp_dbgfs);
  266. mtkdp_dbgfs = NULL;
  267. #endif
  268. #if IS_ENABLED(CONFIG_PROC_FS)
  269. if (mtkdp_procfs) {
  270. proc_remove(mtkdp_procfs);
  271. mtkdp_procfs = NULL;
  272. }
  273. #endif
  274. }