Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundataion. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/io.h> |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 16 | #include "cam_debug_util.h" |
| 17 | |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 18 | static uint debug_mdl; |
| 19 | module_param(debug_mdl, uint, 0644); |
| 20 | |
| 21 | const char *cam_get_module_name(unsigned int module_id) |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 22 | { |
| 23 | const char *name = NULL; |
| 24 | |
| 25 | switch (module_id) { |
| 26 | case CAM_CDM: |
| 27 | name = "CAM-CDM"; |
| 28 | break; |
| 29 | case CAM_CORE: |
| 30 | name = "CAM-CORE"; |
| 31 | break; |
| 32 | case CAM_CRM: |
| 33 | name = "CAM_CRM"; |
| 34 | break; |
| 35 | case CAM_CPAS: |
| 36 | name = "CAM-CPAS"; |
| 37 | break; |
| 38 | case CAM_ISP: |
| 39 | name = "CAM-ISP"; |
| 40 | break; |
| 41 | case CAM_SENSOR: |
| 42 | name = "CAM-SENSOR"; |
| 43 | break; |
| 44 | case CAM_SMMU: |
| 45 | name = "CAM-SMMU"; |
| 46 | break; |
| 47 | case CAM_SYNC: |
| 48 | name = "CAM-SYNC"; |
| 49 | break; |
| 50 | case CAM_ICP: |
| 51 | name = "CAM-ICP"; |
| 52 | break; |
| 53 | case CAM_JPEG: |
| 54 | name = "CAM-JPEG"; |
| 55 | break; |
| 56 | case CAM_FD: |
| 57 | name = "CAM-FD"; |
| 58 | break; |
| 59 | case CAM_LRME: |
| 60 | name = "CAM-LRME"; |
| 61 | break; |
| 62 | case CAM_FLASH: |
| 63 | name = "CAM-FLASH"; |
| 64 | break; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 65 | case CAM_ACTUATOR: |
| 66 | name = "CAM-ACTUATOR"; |
| 67 | break; |
| 68 | case CAM_CCI: |
| 69 | name = "CAM-CCI"; |
| 70 | break; |
| 71 | case CAM_CSIPHY: |
| 72 | name = "CAM-CSIPHY"; |
| 73 | break; |
| 74 | case CAM_EEPROM: |
| 75 | name = "CAM-EEPROM"; |
| 76 | break; |
Pavan Kumar Chilamkurthi | eb8833c | 2017-07-15 19:44:13 -0700 | [diff] [blame] | 77 | case CAM_UTIL: |
| 78 | name = "CAM-UTIL"; |
| 79 | break; |
Lakshmi Narayana Kalavala | adc6ce3 | 2017-07-17 17:19:11 -0700 | [diff] [blame] | 80 | case CAM_CTXT: |
| 81 | name = "CAM-CTXT"; |
| 82 | break; |
| 83 | case CAM_HFI: |
| 84 | name = "CAM-HFI"; |
| 85 | break; |
Vivek Veenam | 281516b | 2017-08-17 17:39:04 +0530 | [diff] [blame] | 86 | case CAM_OIS: |
| 87 | name = "CAM-OIS"; |
| 88 | break; |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 89 | default: |
| 90 | name = "CAM"; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | return name; |
| 95 | } |
| 96 | |
| 97 | void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level, |
| 98 | const char *func, const int line, const char *fmt, ...) |
| 99 | { |
| 100 | char str_buffer[STR_BUFFER_MAX_LENGTH]; |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 101 | va_list args; |
| 102 | |
| 103 | va_start(args, fmt); |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 104 | |
| 105 | switch (dbg_level) { |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 106 | case CAM_LEVEL_DBG: |
| 107 | if (debug_mdl & module_id) { |
| 108 | vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); |
| 109 | pr_info("CAM_DBG: %s: %s: %d: %s\n", |
| 110 | cam_get_module_name(module_id), |
| 111 | func, line, str_buffer); |
| 112 | va_end(args); |
| 113 | } |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 114 | break; |
| 115 | case CAM_LEVEL_ERR: |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 116 | vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 117 | pr_err("CAM_ERR: %s: %s: %d: %s\n", |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 118 | cam_get_module_name(module_id), func, line, str_buffer); |
| 119 | va_end(args); |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 120 | break; |
Jigarkumar Zala | 0fbb1d9 | 2017-07-11 18:55:58 -0700 | [diff] [blame] | 121 | case CAM_LEVEL_INFO: |
| 122 | vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); |
| 123 | pr_info("CAM_INFO: %s: %s: %d: %s\n", |
| 124 | cam_get_module_name(module_id), func, line, str_buffer); |
| 125 | va_end(args); |
| 126 | break; |
| 127 | case CAM_LEVEL_WARN: |
| 128 | vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args); |
| 129 | pr_warn("CAM_WARN: %s: %s: %d: %s\n", |
| 130 | cam_get_module_name(module_id), func, line, str_buffer); |
| 131 | va_end(args); |
Jigarkumar Zala | ddcb9d3 | 2017-06-23 16:21:33 -0700 | [diff] [blame] | 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
| 136 | } |