xref: /OK3568_Linux_fs/kernel/drivers/rkflash/rkflash_debug.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 /* Copyright (c) 2018 Rockchip Electronics Co. Ltd. */
4 
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/printk.h>
8 #include <linux/slab.h>
9 
10 #include "rkflash_debug.h"
11 
12 static unsigned int rkflash_debug;
13 
rkflash_print_dio(const char * fmt,...)14 __printf(1, 2) int rkflash_print_dio(const char *fmt, ...)
15 {
16 	int nret = 0;
17 #if PRINT_SWI_CON_IO
18 	if (rkflash_debug & PRINT_BIT_CON_IO)  {
19 		va_list args;
20 
21 		if (!fmt)
22 			return nret;
23 
24 		va_start(args, fmt);
25 		nret = vprintk(fmt, args);
26 		va_end(args);
27 	}
28 #endif
29 	return nret;
30 }
31 
rkflash_print_bio(const char * fmt,...)32 __printf(1, 2) int rkflash_print_bio(const char *fmt, ...)
33 {
34 	int nret = 0;
35 #if PRINT_SWI_BLK_IO
36 	if (rkflash_debug & PRINT_BIT_BLK_IO)  {
37 		va_list args;
38 
39 		if (!fmt)
40 			return nret;
41 
42 		va_start(args, fmt);
43 		nret = vprintk(fmt, args);
44 		va_end(args);
45 	}
46 #endif
47 	return nret;
48 }
49 
rkflash_print_info(const char * fmt,...)50 __printf(1, 2) int rkflash_print_info(const char *fmt, ...)
51 {
52 	int nret = 0;
53 #if PRINT_SWI_INFO
54 	va_list args;
55 
56 	if (!fmt)
57 		return nret;
58 
59 	va_start(args, fmt);
60 	nret = vprintk(fmt, args);
61 	va_end(args);
62 #endif
63 	return nret;
64 }
65 
rkflash_print_error(const char * fmt,...)66 __printf(1, 2) int rkflash_print_error(const char *fmt, ...)
67 {
68 	int nret = 0;
69 #if PRINT_SWI_ERROR
70 	va_list args;
71 
72 	if (!fmt)
73 		return nret;
74 
75 	va_start(args, fmt);
76 	nret = vprintk(fmt, args);
77 	va_end(args);
78 #endif
79 	return nret;
80 }
81 
rkflash_print_hex(const char * s,const void * buf,int w,size_t len)82 void rkflash_print_hex(const char *s, const void *buf, int w, size_t len)
83 {
84 #if PRINT_SWI_ERROR
85 	return print_hex_dump(KERN_WARNING, s, DUMP_PREFIX_OFFSET, 4, w,
86 			      buf, (len) * w, 0);
87 #endif
88 }
89 
set_val(const char * val,const struct kernel_param * kp)90 static int set_val(const char *val, const struct kernel_param *kp)
91 {
92 	char *tmp = kzalloc(8, GFP_KERNEL);
93 
94 	strncpy(tmp, val, 8);
95 	if (!strncmp(tmp, "0", 1)) {
96 		rkflash_debug = 0;
97 	} else if (!strncmp(tmp, "blk_io", 6)) {
98 		rkflash_debug |= PRINT_BIT_BLK_IO;
99 	} else if (!strncmp(tmp, "con_io", 6)) {
100 		rkflash_debug |= PRINT_BIT_CON_IO;
101 	} else {
102 		pr_info("input error, support 0, blk_io, con_io\n");
103 		rkflash_debug = 0;
104 	}
105 	kfree(tmp);
106 
107 	return 0;
108 }
109 
110 static struct kernel_param_ops rkflash_debug_param_ops = {
111 	.set = set_val,
112 	.get = param_get_uint,
113 };
114 
115 module_param_cb(rkflash_debug, &rkflash_debug_param_ops, &rkflash_debug, 0644);
116 MODULE_PARM_DESC(rkflash_debug, "config rkflash_debug module");
117