import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / ext_disp / mt8127 / debug.c
1 #if defined(CONFIG_MTK_HDMI_SUPPORT)
2 #include <linux/string.h>
3 #include <linux/time.h>
4 #include <linux/uaccess.h>
5
6 #include <linux/debugfs.h>
7
8 #include <mach/mt_typedefs.h>
9
10
11 #if defined(CONFIG_MTK_INTERNAL_HDMI_SUPPORT)
12 #include "internal_hdmi_drv.h"
13 #elif defined(MTK_INTERNAL_MHL_SUPPORT)
14 #include "inter_mhl_drv.h"
15 #else
16 #include "hdmi_drv.h"
17 #endif
18 //#include "hdmitx.h"
19 //#include "hdmitx_drv.h"
20
21 #if defined(MTK_INTERNAL_MHL_SUPPORT)
22 #include "mhl_dbg.h"
23 #endif
24
25 void DBG_Init(void);
26 void DBG_Deinit(void);
27
28 extern void hdmi_log_enable(int enable);
29 extern void hdmi_cable_fake_plug_in(void);
30 extern void hdmi_cable_fake_plug_out(void);
31 extern void hdmi_mmp_enable(int enable);
32 extern void hdmi_pattern(int enable);
33
34
35 // ---------------------------------------------------------------------------
36 // External variable declarations
37 // ---------------------------------------------------------------------------
38
39 //extern LCM_DRIVER *lcm_drv;
40 // ---------------------------------------------------------------------------
41 // Debug Options
42 // ---------------------------------------------------------------------------
43
44
45 static char STR_HELP[] =
46 "\n"
47 "USAGE\n"
48 " echo [ACTION]... > hdmi\n"
49 "\n"
50 "ACTION\n"
51 " hdmitx:[on|off]\n"
52 " enable hdmi video output\n"
53 "\n";
54
55 extern void hdmi_log_enable(int enable);
56 extern void init_hdmi_mmp_events(void);
57
58 // TODO: this is a temp debug solution
59 //extern void hdmi_cable_fake_plug_in(void);
60 //extern int hdmi_drv_init(void);
61 static void process_dbg_opt(const char *opt)
62 {
63 if (0)
64 {
65
66 }
67
68 #if defined(MTK_HDMI_SUPPORT)
69 else if (0 == strncmp(opt, "on", 2))
70 {
71 hdmi_power_on();
72 }
73 else if (0 == strncmp(opt, "off", 3))
74 {
75 hdmi_power_off();
76 }
77 else if (0 == strncmp(opt, "suspend", 7))
78 {
79 hdmi_suspend();
80 }
81 else if (0 == strncmp(opt, "resume", 6))
82 {
83 hdmi_resume();
84 }
85 else if (0 == strncmp(opt, "colorbar", 8))
86 {
87
88 }
89 else if (0 == strncmp(opt, "ldooff", 6))
90 {
91
92 }
93 else if (0 == strncmp(opt, "log:", 4))
94 {
95 if (0 == strncmp(opt + 4, "on", 2))
96 {
97 hdmi_log_enable(true);
98 }
99 else if (0 == strncmp(opt + 4, "off", 3))
100 {
101 hdmi_log_enable(false);
102 }
103 else
104 {
105 goto Error;
106 }
107 }
108 else if (0 == strncmp(opt, "fakecablein:", 12))
109 {
110 if (0 == strncmp(opt + 12, "enable", 6))
111 {
112 hdmi_cable_fake_plug_in();
113 }
114 else if (0 == strncmp(opt + 12, "disable", 7))
115 {
116 hdmi_cable_fake_plug_out();
117 }
118 else
119 {
120 goto Error;
121 }
122 }
123 #if defined(MTK_INTERNAL_MHL_SUPPORT)
124 else if((0 == strncmp(opt, "dbgtype:", 8))||
125 (0 == strncmp(opt, "w:", 2))||
126 (0 == strncmp(opt, "r:", 2))||
127 (0 == strncmp(opt, "w6:", 3))||
128 (0 == strncmp(opt, "r6:", 3))||
129 (0 == strncmp(opt, "hdcp:", 5))||
130 (0 == strncmp(opt, "status", 6))||
131 (0 == strncmp(opt, "help", 4))||
132 (0 == strncmp(opt, "res:", 4))||
133 (0 == strncmp(opt, "edid", 4)))
134 {
135 mt_hdmi_debug_write(opt);
136 }
137 #endif
138 #endif
139 else if (0 == strncmp(opt, "hdmimmp:", 8))
140 {
141 if (0 == strncmp(opt + 8, "on", 2))
142 {
143 hdmi_mmp_enable(1);
144 }
145 else if (0 == strncmp(opt + 8, "init", 4))
146 {
147 init_hdmi_mmp_events();
148 }
149 else if (0 == strncmp(opt + 8, "off", 3))
150 {
151 hdmi_mmp_enable(0);
152 }
153 else if (0 == strncmp(opt + 8, "img", 3))
154 {
155 hdmi_mmp_enable(7);
156 }
157 else
158 {
159 goto Error;
160 }
161 }
162 else if (0 == strncmp(opt, "hdmi_pattern:", 13))
163 {
164 if (0 == strncmp(opt + 13, "on", 2))
165 {
166 hdmi_pattern(1);
167 }
168 else if (0 == strncmp(opt + 13, "off", 3))
169 {
170 hdmi_pattern(0);
171 }
172 else if (0 == strncmp(opt + 13, "svp", 3))
173 {
174 hdmi_pattern(2);
175 }
176 else
177 {
178 goto Error;
179 }
180 }
181 else
182 {
183 goto Error;
184 }
185
186 return;
187
188 Error:
189 printk("[hdmitx] parse command error!\n\n%s", STR_HELP);
190 }
191
192 static void process_dbg_cmd(char *cmd)
193 {
194 char *tok;
195
196 printk("[hdmitx] %s\n", cmd);
197
198 while ((tok = strsep(&cmd, " ")) != NULL)
199 {
200 process_dbg_opt(tok);
201 }
202 }
203
204 // ---------------------------------------------------------------------------
205 // Debug FileSystem Routines
206 // ---------------------------------------------------------------------------
207
208 struct dentry *hdmitx_dbgfs = NULL;
209
210
211 static ssize_t debug_open(struct inode *inode, struct file *file)
212 {
213 file->private_data = inode->i_private;
214 return 0;
215 }
216
217
218 static char debug_buffer[2048];
219
220 static ssize_t debug_read(struct file *file,
221 char __user *ubuf, size_t count, loff_t *ppos)
222 {
223 const int debug_bufmax = sizeof(debug_buffer) - 1;
224 int n = 0;
225
226 n += scnprintf(debug_buffer + n, debug_bufmax - n, STR_HELP);
227 debug_buffer[n++] = 0;
228
229 return simple_read_from_buffer(ubuf, count, ppos, debug_buffer, n);
230 }
231
232
233 static ssize_t debug_write(struct file *file,
234 const char __user *ubuf, size_t count, loff_t *ppos)
235 {
236 const int debug_bufmax = sizeof(debug_buffer) - 1;
237 size_t ret;
238
239 ret = count;
240
241 if (count > debug_bufmax)
242 {
243 count = debug_bufmax;
244 }
245
246 if (copy_from_user(&debug_buffer, ubuf, count))
247 {
248 return -EFAULT;
249 }
250
251 debug_buffer[count] = 0;
252
253 process_dbg_cmd(debug_buffer);
254
255 return ret;
256 }
257
258
259 static struct file_operations debug_fops =
260 {
261 .read = debug_read,
262 .write = debug_write,
263 .open = debug_open,
264 };
265
266
267 void HDMI_DBG_Init(void)
268 {
269 hdmitx_dbgfs = debugfs_create_file("hdmi",
270 S_IFREG | S_IRUGO, NULL, (void *)0, &debug_fops);
271 }
272
273
274 void HDMI_DBG_Deinit(void)
275 {
276 debugfs_remove(hdmitx_dbgfs);
277 }
278
279 #endif