cam_debug_util.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_debug_util.h"
  9. static uint debug_mdl;
  10. module_param(debug_mdl, uint, 0644);
  11. struct camera_debug_settings cam_debug;
  12. const struct camera_debug_settings *cam_debug_get_settings()
  13. {
  14. return &cam_debug;
  15. }
  16. static int cam_debug_parse_cpas_settings(const char *setting, u64 value)
  17. {
  18. if (!strcmp(setting, "camnoc_bw")) {
  19. cam_debug.cpas_settings.camnoc_bw = value;
  20. } else if (!strcmp(setting, "mnoc_hf_0_ab_bw")) {
  21. cam_debug.cpas_settings.mnoc_hf_0_ab_bw = value;
  22. } else if (!strcmp(setting, "mnoc_hf_0_ib_bw")) {
  23. cam_debug.cpas_settings.mnoc_hf_0_ib_bw = value;
  24. } else if (!strcmp(setting, "mnoc_hf_1_ab_bw")) {
  25. cam_debug.cpas_settings.mnoc_hf_1_ab_bw = value;
  26. } else if (!strcmp(setting, "mnoc_hf_1_ib_bw")) {
  27. cam_debug.cpas_settings.mnoc_hf_1_ib_bw = value;
  28. } else if (!strcmp(setting, "mnoc_sf_0_ab_bw")) {
  29. cam_debug.cpas_settings.mnoc_sf_0_ab_bw = value;
  30. } else if (!strcmp(setting, "mnoc_sf_0_ib_bw")) {
  31. cam_debug.cpas_settings.mnoc_sf_0_ib_bw = value;
  32. } else if (!strcmp(setting, "mnoc_sf_1_ab_bw")) {
  33. cam_debug.cpas_settings.mnoc_sf_1_ab_bw = value;
  34. } else if (!strcmp(setting, "mnoc_sf_1_ib_bw")) {
  35. cam_debug.cpas_settings.mnoc_sf_1_ib_bw = value;
  36. } else if (!strcmp(setting, "mnoc_sf_icp_ab_bw")) {
  37. cam_debug.cpas_settings.mnoc_sf_icp_ab_bw = value;
  38. } else if (!strcmp(setting, "mnoc_sf_icp_ib_bw")) {
  39. cam_debug.cpas_settings.mnoc_sf_icp_ib_bw = value;
  40. } else {
  41. CAM_ERR(CAM_UTIL, "Unsupported cpas sysfs entry");
  42. return -EINVAL;
  43. }
  44. return 0;
  45. }
  46. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  47. struct device_attribute *attr, const char *buf, size_t count)
  48. {
  49. int rc = 0;
  50. char *local_buf = NULL, *local_buf_temp = NULL;
  51. char *driver;
  52. char *setting = NULL;
  53. char *value_str = NULL;
  54. u64 value;
  55. CAM_INFO(CAM_UTIL, "Sysfs debug attr name:[%s] buf:[%s] bytes:[%d]",
  56. attr->attr.name, buf, count);
  57. local_buf = kmemdup(buf, (count + sizeof(char)), GFP_KERNEL);
  58. local_buf_temp = local_buf;
  59. driver = strsep(&local_buf, "#");
  60. if (!driver) {
  61. CAM_ERR(CAM_UTIL,
  62. "Invalid input driver name buf:[%s], count:%d",
  63. buf, count);
  64. goto error;
  65. }
  66. setting = strsep(&local_buf, "=");
  67. if (!setting) {
  68. CAM_ERR(CAM_UTIL, "Invalid input setting buf:[%s], count:%d",
  69. buf, count);
  70. goto error;
  71. }
  72. value_str = strsep(&local_buf, "=");
  73. if (!value_str) {
  74. CAM_ERR(CAM_UTIL, "Invalid input value buf:[%s], count:%d",
  75. buf, count);
  76. goto error;
  77. }
  78. rc = kstrtou64(value_str, 0, &value);
  79. if (rc < 0) {
  80. CAM_ERR(CAM_UTIL, "Error converting value:[%s], buf:[%s]",
  81. value_str, buf);
  82. goto error;
  83. }
  84. CAM_INFO(CAM_UTIL,
  85. "Processing sysfs store for driver:[%s], setting:[%s], value:[%llu]",
  86. driver, setting, value);
  87. if (!strcmp(driver, "cpas")) {
  88. rc = cam_debug_parse_cpas_settings(setting, value);
  89. if (rc)
  90. goto error;
  91. } else {
  92. CAM_ERR(CAM_UTIL, "Unsupported driver in camera debug node");
  93. goto error;
  94. }
  95. kfree(local_buf_temp);
  96. return count;
  97. error:
  98. kfree(local_buf_temp);
  99. return -EPERM;
  100. }
  101. const char *cam_get_module_name(unsigned int module_id)
  102. {
  103. const char *name = NULL;
  104. switch (module_id) {
  105. case CAM_CDM:
  106. name = "CAM-CDM";
  107. break;
  108. case CAM_CORE:
  109. name = "CAM-CORE";
  110. break;
  111. case CAM_CRM:
  112. name = "CAM-CRM";
  113. break;
  114. case CAM_CPAS:
  115. name = "CAM-CPAS";
  116. break;
  117. case CAM_ISP:
  118. name = "CAM-ISP";
  119. break;
  120. case CAM_SENSOR:
  121. name = "CAM-SENSOR";
  122. break;
  123. case CAM_SMMU:
  124. name = "CAM-SMMU";
  125. break;
  126. case CAM_SYNC:
  127. name = "CAM-SYNC";
  128. break;
  129. case CAM_ICP:
  130. name = "CAM-ICP";
  131. break;
  132. case CAM_JPEG:
  133. name = "CAM-JPEG";
  134. break;
  135. case CAM_FD:
  136. name = "CAM-FD";
  137. break;
  138. case CAM_LRME:
  139. name = "CAM-LRME";
  140. break;
  141. case CAM_FLASH:
  142. name = "CAM-FLASH";
  143. break;
  144. case CAM_ACTUATOR:
  145. name = "CAM-ACTUATOR";
  146. break;
  147. case CAM_CCI:
  148. name = "CAM-CCI";
  149. break;
  150. case CAM_CSIPHY:
  151. name = "CAM-CSIPHY";
  152. break;
  153. case CAM_EEPROM:
  154. name = "CAM-EEPROM";
  155. break;
  156. case CAM_UTIL:
  157. name = "CAM-UTIL";
  158. break;
  159. case CAM_CTXT:
  160. name = "CAM-CTXT";
  161. break;
  162. case CAM_HFI:
  163. name = "CAM-HFI";
  164. break;
  165. case CAM_OIS:
  166. name = "CAM-OIS";
  167. break;
  168. case CAM_IRQ_CTRL:
  169. name = "CAM-IRQ-CTRL";
  170. break;
  171. case CAM_MEM:
  172. name = "CAM-MEM";
  173. break;
  174. case CAM_PERF:
  175. name = "CAM-PERF";
  176. break;
  177. case CAM_REQ:
  178. name = "CAM-REQ";
  179. break;
  180. case CAM_CUSTOM:
  181. name = "CAM-CUSTOM";
  182. break;
  183. case CAM_OPE:
  184. name = "CAM-OPE";
  185. break;
  186. case CAM_PRESIL:
  187. name = "CAM-PRESIL";
  188. break;
  189. case CAM_RES:
  190. name = "CAM-RES";
  191. break;
  192. default:
  193. name = "CAM";
  194. break;
  195. }
  196. return name;
  197. }
  198. void cam_debug_log(unsigned int module_id, const char *func, const int line,
  199. const char *fmt, ...)
  200. {
  201. char str_buffer[STR_BUFFER_MAX_LENGTH];
  202. va_list args;
  203. va_start(args, fmt);
  204. if (debug_mdl & module_id) {
  205. vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
  206. pr_info("CAM_DBG: %s: %s: %d: %s\n",
  207. cam_get_module_name(module_id),
  208. func, line, str_buffer);
  209. }
  210. va_end(args);
  211. }