import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / hdmi / Sii8338 / si_osdebug.c
1 #include "si_common.h"
2 #include "si_osdebug.h"
3 #include <linux/slab.h>
4 #include <linux/string.h>
5 #define ChannelIndex(channel) (channel >> 3)
6 #define ChannelMask(channel) (1 << (channel & 7))
7 extern unsigned char DebugChannelMasks[];
8 extern ushort DebugFormat;
9 void SiiOsDebugChannelEnable(SiiOsalDebugChannels_e channel)
10 {
11 #if defined(DEBUG)
12 uint8_t index = ChannelIndex(channel);
13 uint8_t mask = ChannelMask(channel);
14 DebugChannelMasks[index] |= mask;
15 #endif
16 }
17
18 void SiiOsDebugChannelDisable(SiiOsalDebugChannels_e channel)
19 {
20 #if defined(DEBUG)
21 uint8_t index = ChannelIndex(channel);
22 uint8_t mask = ChannelMask(channel);
23 DebugChannelMasks[index] &= ~mask;
24 #endif
25 }
26
27 bool_t SiiOsDebugChannelIsEnabled(SiiOsalDebugChannels_e channel)
28 {
29 #if defined(DEBUG)
30 uint8_t index = ChannelIndex(channel);
31 uint8_t mask = ChannelMask(channel);
32 return (DebugChannelMasks[index] & mask) ? true : false;
33 #else
34 return false;
35 #endif
36 }
37
38 void SiiOsDebugSetConfig(uint16_t flags)
39 {
40 #if defined(DEBUG)
41 DebugFormat = flags;
42 #endif
43 }
44
45 uint16_t SiiOsDebugGetConfig(void)
46 {
47 #if defined(DEBUG)
48 return DebugFormat;
49 #else
50 return 0;
51 #endif
52 }
53
54 void SiiOsDebugPrintSimple(SiiOsalDebugChannels_e channel, char *pszFormat, ...)
55 {
56 #if 1
57 /* #if defined(DEBUG) */
58 if (SiiOsDebugChannelIsEnabled(channel)) {
59 va_list ap;
60 va_start(ap, pszFormat);
61 printk(pszFormat, ap);
62 va_end(ap);
63 }
64 #endif
65 }
66
67 void SiiOsDebugPrintShort(SiiOsalDebugChannels_e channel, char *pszFormat, ...)
68 {
69 /* #if defined(DEBUG) */
70 #if 1
71 if (SiiOsDebugChannelIsEnabled(channel)) {
72 va_list ap;
73 va_start(ap, pszFormat);
74 SiiOsDebugPrint(NULL, 0, channel, pszFormat, ap);
75 va_end(ap);
76 }
77 #endif
78 }
79
80 #define MAX_DEBUG_MSG_SIZE 512
81 void SiiOsDebugPrint(const char *pszFileName, uint32_t iLineNum, uint32_t channel,
82 const char *pszFormat, ...)
83 {
84 #if defined(DEBUG)
85 uint8_t *pBuf = NULL;
86 uint8_t *pBufOffset;
87 int remainingBufLen = MAX_DEBUG_MSG_SIZE;
88 int len;
89 va_list ap;
90 if (SiiOsDebugChannelIsEnabled(channel)) {
91 pBuf = kmalloc(remainingBufLen, GFP_KERNEL);
92 if (pBuf == NULL)
93 return;
94 pBufOffset = pBuf;
95 if (pszFileName != NULL && (SII_OS_DEBUG_FORMAT_FILEINFO & DebugFormat)) {
96 const char *pc;
97 for (pc = &pszFileName[strlen(pszFileName)]; pc >= pszFileName; --pc) {
98 if ('\\' == *pc) {
99 ++pc;
100 break;
101 }
102 if ('/' == *pc) {
103 ++pc;
104 break;
105 }
106 }
107 len = scnprintf(pBufOffset, remainingBufLen, "%s:%d ", pc, (int)iLineNum);
108 if (len < 0) {
109 kfree(pBuf);
110 return;
111 }
112 remainingBufLen -= len;
113 pBufOffset += len;
114 }
115 if (SII_OS_DEBUG_FORMAT_CHANNEL & DebugFormat) {
116 len = scnprintf(pBufOffset, remainingBufLen, "Chan:%d ", channel);
117 if (len < 0) {
118 kfree(pBuf);
119 return;
120 }
121 remainingBufLen -= len;
122 pBufOffset += len;
123 }
124 va_start(ap, pszFormat);
125 vsnprintf(pBufOffset, remainingBufLen, pszFormat, ap);
126 va_end(ap);
127 printk(pBuf);
128 kfree(pBuf);
129 }
130 #endif
131 }