import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / mtprof / mt_printk_ctrl.c
1 #include <linux/proc_fs.h>
2 #include <linux/sched.h>
3 #include <linux/seq_file.h>
4 #include <linux/kallsyms.h>
5 #include <linux/utsname.h>
6 #include <asm/uaccess.h>
7 #include "prof_ctl.h"
8 #include <linux/module.h>
9 #include <linux/pid.h>
10
11 #include <linux/irq.h>
12 #include <linux/interrupt.h>
13
14 #include <linux/aee.h>
15 #include <linux/stacktrace.h>
16
17 #include <linux/printk.h>
18
19 /* Some utility macro*/
20 #define SEQ_printf(m, x...) \
21 do { \
22 if (m) \
23 seq_printf(m, x); \
24 else \
25 pr_err(x); \
26 } while (0)
27
28 #define MT_DEBUG_ENTRY(name) \
29 static int mt_##name##_show(struct seq_file *m, void *v);\
30 static ssize_t mt_##name##_write(struct file *filp, const char *ubuf, ssize_t cnt, loff_t *data);\
31 static int mt_##name##_open(struct inode *inode, struct file *file) \
32 { \
33 return single_open(file, mt_##name##_show, inode->i_private); \
34 } \
35 \
36 static const struct file_operations mt_##name##_fops = { \
37 .open = mt_##name##_open, \
38 .write = mt_##name##_write,\
39 .read = seq_read, \
40 .llseek = seq_lseek, \
41 .release = single_release, \
42 };\
43 void mt_##name##_switch(int on);
44
45 /*
46 * Ease the printing of nsec fields:
47 */
48 /*
49 static long long nsec_high(unsigned long long nsec)
50 {
51 if ((long long)nsec < 0) {
52 nsec = -nsec;
53 do_div(nsec, 1000000);
54 return -nsec;
55 }
56 do_div(nsec, 1000000);
57
58 return nsec;
59 }
60
61 static unsigned long nsec_low(unsigned long long nsec)
62 {
63 if ((long long)nsec < 0)
64 nsec = -nsec;
65
66 return do_div(nsec, 1000000);
67 }
68 #define SPLIT_NS(x) nsec_high(x), nsec_low(x)
69 */
70 /* */
71 /* //////////////////////////////////////////////////////// */
72 /* --------------------------------------------------- */
73 /* Real work */
74 /* --------------------------------------------------- */
75 /* Define Proc entry */
76 /* --------------------------------------------------- */
77 MT_DEBUG_ENTRY(printk_ctrl);
78 int mt_need_uart_console = 0;
79 extern void mt_enable_uart(void); /* printk.c */
80 extern void mt_disable_uart(void); /* printk.c */
81 extern bool printk_disable_uart;
82 static int mt_printk_ctrl_show(struct seq_file *m, void *v)
83 {
84 SEQ_printf(m, "=== mt printk controller ===\n");
85 SEQ_printf(m, "mt_need_uart_console:%d, printk_disable_uart:%d\n", mt_need_uart_console,
86 printk_disable_uart);
87
88 return 0;
89 }
90
91 static ssize_t mt_printk_ctrl_write(struct file *filp, const char *ubuf, ssize_t cnt, loff_t *data)
92 {
93 char buf[64];
94 int val;
95 int ret;
96 if (cnt >= sizeof(buf))
97 return -EINVAL;
98
99 if (copy_from_user(&buf, ubuf, cnt))
100 return -EFAULT;
101
102 buf[cnt] = 0;
103
104 ret = strict_strtoul(buf, 10, (unsigned long *)&val);
105 if (val == 0) {
106 mt_disable_uart();
107 } else if (val == 1) {
108 mt_need_uart_console = 1;
109 mt_enable_uart();
110 pr_err("need uart log\n");
111 }
112 if (ret < 0)
113 return ret;
114 pr_err(" %d\n", val);
115 return cnt;
116 }
117
118 //[BUGFIX]-Add-BEGIN by SCDTABLET.(fangyou.wang),10/10/2015,1097303,
119 //auto reboot after power off
120 void force_enable_uart_log(void)
121 {
122 if(mt_need_uart_console){
123 pr_err("uart log alrady opened!!!!\n");
124 return;
125 }
126
127 mt_need_uart_console = 1;
128 mt_enable_uart();
129 pr_err("--------------need uart log,force open uart log now-------------\n");
130
131 }
132 //[BUGFIX]-Add-END by SCDTABLET.(fangyou.wang)
133
134 static int __init init_mt_printk_ctrl(void)
135 {
136 struct proc_dir_entry *pe;
137 mt_need_uart_console = 0; /* defualt, no uart */
138 pe = proc_create("mtprintk", 0664, NULL, &mt_printk_ctrl_fops);
139 if (!pe)
140 return -ENOMEM;
141 return 0;
142 }
143
144 __initcall(init_mt_printk_ctrl);