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