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