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