cam_debug_util.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundataion. All rights reserved.
  4. */
  5. #include <linux/io.h>
  6. #include <linux/slab.h>
  7. #include <linux/module.h>
  8. #include "cam_trace.h"
  9. #include "cam_debug_util.h"
  10. static uint debug_mdl;
  11. module_param(debug_mdl, uint, 0644);
  12. /* 0x0 - only logs, 0x1 - only trace, 0x2 - logs + trace */
  13. static uint debug_type;
  14. module_param(debug_type, uint, 0644);
  15. struct camera_debug_settings cam_debug;
  16. const struct camera_debug_settings *cam_debug_get_settings()
  17. {
  18. return &cam_debug;
  19. }
  20. static int cam_debug_parse_cpas_settings(const char *setting, u64 value)
  21. {
  22. if (!strcmp(setting, "camnoc_bw")) {
  23. cam_debug.cpas_settings.camnoc_bw = value;
  24. } else if (!strcmp(setting, "mnoc_hf_0_ab_bw")) {
  25. cam_debug.cpas_settings.mnoc_hf_0_ab_bw = value;
  26. } else if (!strcmp(setting, "mnoc_hf_0_ib_bw")) {
  27. cam_debug.cpas_settings.mnoc_hf_0_ib_bw = value;
  28. } else if (!strcmp(setting, "mnoc_hf_1_ab_bw")) {
  29. cam_debug.cpas_settings.mnoc_hf_1_ab_bw = value;
  30. } else if (!strcmp(setting, "mnoc_hf_1_ib_bw")) {
  31. cam_debug.cpas_settings.mnoc_hf_1_ib_bw = value;
  32. } else if (!strcmp(setting, "mnoc_sf_0_ab_bw")) {
  33. cam_debug.cpas_settings.mnoc_sf_0_ab_bw = value;
  34. } else if (!strcmp(setting, "mnoc_sf_0_ib_bw")) {
  35. cam_debug.cpas_settings.mnoc_sf_0_ib_bw = value;
  36. } else if (!strcmp(setting, "mnoc_sf_1_ab_bw")) {
  37. cam_debug.cpas_settings.mnoc_sf_1_ab_bw = value;
  38. } else if (!strcmp(setting, "mnoc_sf_1_ib_bw")) {
  39. cam_debug.cpas_settings.mnoc_sf_1_ib_bw = value;
  40. } else if (!strcmp(setting, "mnoc_sf_icp_ab_bw")) {
  41. cam_debug.cpas_settings.mnoc_sf_icp_ab_bw = value;
  42. } else if (!strcmp(setting, "mnoc_sf_icp_ib_bw")) {
  43. cam_debug.cpas_settings.mnoc_sf_icp_ib_bw = value;
  44. } else {
  45. CAM_ERR(CAM_UTIL, "Unsupported cpas sysfs entry");
  46. return -EINVAL;
  47. }
  48. return 0;
  49. }
  50. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  51. struct device_attribute *attr, const char *buf, size_t count)
  52. {
  53. int rc = 0;
  54. char *local_buf = NULL, *local_buf_temp = NULL;
  55. char *driver;
  56. char *setting = NULL;
  57. char *value_str = NULL;
  58. u64 value;
  59. CAM_INFO(CAM_UTIL, "Sysfs debug attr name:[%s] buf:[%s] bytes:[%d]",
  60. attr->attr.name, buf, count);
  61. local_buf = kmemdup(buf, (count + sizeof(char)), GFP_KERNEL);
  62. local_buf_temp = local_buf;
  63. driver = strsep(&local_buf, "#");
  64. if (!driver) {
  65. CAM_ERR(CAM_UTIL,
  66. "Invalid input driver name buf:[%s], count:%d",
  67. buf, count);
  68. goto error;
  69. }
  70. setting = strsep(&local_buf, "=");
  71. if (!setting) {
  72. CAM_ERR(CAM_UTIL, "Invalid input setting buf:[%s], count:%d",
  73. buf, count);
  74. goto error;
  75. }
  76. value_str = strsep(&local_buf, "=");
  77. if (!value_str) {
  78. CAM_ERR(CAM_UTIL, "Invalid input value buf:[%s], count:%d",
  79. buf, count);
  80. goto error;
  81. }
  82. rc = kstrtou64(value_str, 0, &value);
  83. if (rc < 0) {
  84. CAM_ERR(CAM_UTIL, "Error converting value:[%s], buf:[%s]",
  85. value_str, buf);
  86. goto error;
  87. }
  88. CAM_INFO(CAM_UTIL,
  89. "Processing sysfs store for driver:[%s], setting:[%s], value:[%llu]",
  90. driver, setting, value);
  91. if (!strcmp(driver, "cpas")) {
  92. rc = cam_debug_parse_cpas_settings(setting, value);
  93. if (rc)
  94. goto error;
  95. } else {
  96. CAM_ERR(CAM_UTIL, "Unsupported driver in camera debug node");
  97. goto error;
  98. }
  99. kfree(local_buf_temp);
  100. return count;
  101. error:
  102. kfree(local_buf_temp);
  103. return -EPERM;
  104. }
  105. const char *cam_get_module_name(unsigned int module_id)
  106. {
  107. const char *name = NULL;
  108. switch (module_id) {
  109. case CAM_CDM:
  110. name = "CAM-CDM";
  111. break;
  112. case CAM_CORE:
  113. name = "CAM-CORE";
  114. break;
  115. case CAM_CRM:
  116. name = "CAM-CRM";
  117. break;
  118. case CAM_CPAS:
  119. name = "CAM-CPAS";
  120. break;
  121. case CAM_ISP:
  122. name = "CAM-ISP";
  123. break;
  124. case CAM_SENSOR:
  125. name = "CAM-SENSOR";
  126. break;
  127. case CAM_SMMU:
  128. name = "CAM-SMMU";
  129. break;
  130. case CAM_SYNC:
  131. name = "CAM-SYNC";
  132. break;
  133. case CAM_ICP:
  134. name = "CAM-ICP";
  135. break;
  136. case CAM_JPEG:
  137. name = "CAM-JPEG";
  138. break;
  139. case CAM_FD:
  140. name = "CAM-FD";
  141. break;
  142. case CAM_LRME:
  143. name = "CAM-LRME";
  144. break;
  145. case CAM_FLASH:
  146. name = "CAM-FLASH";
  147. break;
  148. case CAM_ACTUATOR:
  149. name = "CAM-ACTUATOR";
  150. break;
  151. case CAM_CCI:
  152. name = "CAM-CCI";
  153. break;
  154. case CAM_CSIPHY:
  155. name = "CAM-CSIPHY";
  156. break;
  157. case CAM_EEPROM:
  158. name = "CAM-EEPROM";
  159. break;
  160. case CAM_UTIL:
  161. name = "CAM-UTIL";
  162. break;
  163. case CAM_CTXT:
  164. name = "CAM-CTXT";
  165. break;
  166. case CAM_HFI:
  167. name = "CAM-HFI";
  168. break;
  169. case CAM_OIS:
  170. name = "CAM-OIS";
  171. break;
  172. case CAM_IRQ_CTRL:
  173. name = "CAM-IRQ-CTRL";
  174. break;
  175. case CAM_MEM:
  176. name = "CAM-MEM";
  177. break;
  178. case CAM_PERF:
  179. name = "CAM-PERF";
  180. break;
  181. case CAM_REQ:
  182. name = "CAM-REQ";
  183. break;
  184. case CAM_CUSTOM:
  185. name = "CAM-CUSTOM";
  186. break;
  187. case CAM_OPE:
  188. name = "CAM-OPE";
  189. break;
  190. case CAM_PRESIL:
  191. name = "CAM-PRESIL";
  192. break;
  193. case CAM_RES:
  194. name = "CAM-RES";
  195. break;
  196. case CAM_IO_ACCESS:
  197. name = "CAM-IO-ACCESS";
  198. break;
  199. case CAM_SFE:
  200. name = "CAM-SFE";
  201. break;
  202. default:
  203. name = "CAM";
  204. break;
  205. }
  206. return name;
  207. }
  208. const char *cam_get_tag_name(unsigned int tag_id)
  209. {
  210. const char *name = NULL;
  211. switch (tag_id) {
  212. case CAM_TYPE_TRACE:
  213. name = "CAM_TRACE";
  214. break;
  215. case CAM_TYPE_ERR:
  216. name = "CAM_ERR";
  217. break;
  218. case CAM_TYPE_WARN:
  219. name = "CAM_WARN";
  220. break;
  221. case CAM_TYPE_INFO:
  222. name = "CAM_INFO";
  223. break;
  224. case CAM_TYPE_DBG:
  225. name = "CAM_DBG";
  226. break;
  227. default:
  228. name = "CAM";
  229. break;
  230. }
  231. return name;
  232. }
  233. void cam_debug_log(unsigned int module_id, const char *func, const int line,
  234. const char *fmt, ...)
  235. {
  236. char str_buffer[STR_BUFFER_MAX_LENGTH];
  237. va_list args;
  238. va_start(args, fmt);
  239. if (debug_mdl & module_id) {
  240. vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
  241. if ((debug_type == 0) || (debug_type == 2)) {
  242. pr_info("CAM_DBG: %s: %s: %d: %s\n",
  243. cam_get_module_name(module_id),
  244. func, line, str_buffer);
  245. }
  246. if ((debug_type == 1) || (debug_type == 2)) {
  247. char trace_buffer[STR_BUFFER_MAX_LENGTH];
  248. snprintf(trace_buffer, sizeof(trace_buffer),
  249. "%s: %s: %s: %d: %s",
  250. cam_get_tag_name(CAM_TYPE_DBG),
  251. cam_get_module_name(module_id),
  252. func, line, str_buffer);
  253. trace_cam_log_debug(trace_buffer);
  254. }
  255. }
  256. va_end(args);
  257. }
  258. void cam_debug_trace(unsigned int tag, unsigned int module_id,
  259. const char *func, const int line, const char *fmt, ...)
  260. {
  261. char str_buffer[STR_BUFFER_MAX_LENGTH];
  262. va_list args;
  263. if ((tag == CAM_TYPE_TRACE) || (debug_type == 1) || (debug_type == 2)) {
  264. char trace_buffer[STR_BUFFER_MAX_LENGTH];
  265. va_start(args, fmt);
  266. vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
  267. snprintf(trace_buffer, sizeof(trace_buffer),
  268. "%s: %s: %s: %d: %s",
  269. cam_get_tag_name(tag), cam_get_module_name(module_id),
  270. func, line, str_buffer);
  271. trace_cam_log_debug(trace_buffer);
  272. va_end(args);
  273. }
  274. }