cam_debug_util.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_DEBUG_UTIL_H_
  6. #define _CAM_DEBUG_UTIL_H_
  7. #include <linux/platform_device.h>
  8. /* Module IDs used for debug logging */
  9. #define CAM_CDM (1 << 0)
  10. #define CAM_CORE (1 << 1)
  11. #define CAM_CPAS (1 << 2)
  12. #define CAM_ISP (1 << 3)
  13. #define CAM_CRM (1 << 4)
  14. #define CAM_SENSOR (1 << 5)
  15. #define CAM_SMMU (1 << 6)
  16. #define CAM_SYNC (1 << 7)
  17. #define CAM_ICP (1 << 8)
  18. #define CAM_JPEG (1 << 9)
  19. #define CAM_FD (1 << 10)
  20. #define CAM_LRME (1 << 11)
  21. #define CAM_FLASH (1 << 12)
  22. #define CAM_ACTUATOR (1 << 13)
  23. #define CAM_CCI (1 << 14)
  24. #define CAM_CSIPHY (1 << 15)
  25. #define CAM_EEPROM (1 << 16)
  26. #define CAM_UTIL (1 << 17)
  27. #define CAM_HFI (1 << 18)
  28. #define CAM_CTXT (1 << 19)
  29. #define CAM_OIS (1 << 20)
  30. #define CAM_RES (1 << 21)
  31. #define CAM_MEM (1 << 22)
  32. #define CAM_IRQ_CTRL (1 << 23)
  33. #define CAM_REQ (1 << 24)
  34. #define CAM_PERF (1 << 25)
  35. #define CAM_CUSTOM (1 << 26)
  36. #define CAM_PRESIL (1 << 27)
  37. #define CAM_OPE (1 << 28)
  38. #define CAM_IO_ACCESS (1 << 29)
  39. #define CAM_SFE (1 << 30)
  40. #define CAM_CRE (1 << 31)
  41. /* Log level types */
  42. #define CAM_TYPE_TRACE (1 << 0)
  43. #define CAM_TYPE_ERR (1 << 1)
  44. #define CAM_TYPE_WARN (1 << 2)
  45. #define CAM_TYPE_INFO (1 << 3)
  46. #define CAM_TYPE_DBG (1 << 4)
  47. #define STR_BUFFER_MAX_LENGTH 512
  48. /*
  49. * enum cam_debug_priority - Priority of debug log (0 = Lowest)
  50. */
  51. enum cam_debug_priority {
  52. CAM_DBG_PRIORITY_0,
  53. CAM_DBG_PRIORITY_1,
  54. CAM_DBG_PRIORITY_2,
  55. };
  56. /**
  57. * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
  58. */
  59. struct cam_cpas_debug_settings {
  60. uint64_t mnoc_hf_0_ab_bw;
  61. uint64_t mnoc_hf_0_ib_bw;
  62. uint64_t mnoc_hf_1_ab_bw;
  63. uint64_t mnoc_hf_1_ib_bw;
  64. uint64_t mnoc_sf_0_ab_bw;
  65. uint64_t mnoc_sf_0_ib_bw;
  66. uint64_t mnoc_sf_1_ab_bw;
  67. uint64_t mnoc_sf_1_ib_bw;
  68. uint64_t mnoc_sf_icp_ab_bw;
  69. uint64_t mnoc_sf_icp_ib_bw;
  70. uint64_t camnoc_bw;
  71. };
  72. /**
  73. * struct camera_debug_settings - Sysfs debug settings for camera
  74. *
  75. * @cpas_settings: Debug settings for cpas driver.
  76. */
  77. struct camera_debug_settings {
  78. struct cam_cpas_debug_settings cpas_settings;
  79. };
  80. /*
  81. * cam_debug_log()
  82. *
  83. * @brief : Get the Module name from module ID and print
  84. * respective debug logs
  85. *
  86. * @module_id : Respective Module ID which is calling this function
  87. * @priority : Priority of the debug log
  88. * @func : Function which is calling to print logs
  89. * @line : Line number associated with the function which is calling
  90. * to print log
  91. * @fmt : Formatted string which needs to be print in the log
  92. *
  93. */
  94. void cam_debug_log(unsigned int module_id, unsigned int priority,
  95. const char *func, const int line, const char *fmt, ...);
  96. /*
  97. * cam_debug_trace()
  98. *
  99. * @brief : Get the Module name from module ID and print
  100. * respective debug logs in ftrace
  101. *
  102. * @tag : Tag indicating whether TRACE, ERR, WARN, INFO, DBG
  103. * @module_id : Respective Module ID which is calling this function
  104. * @func : Function which is calling to print logs
  105. * @line : Line number associated with the function which is calling
  106. * to print log
  107. * @fmt : Formatted string which needs to be print in the log
  108. *
  109. */
  110. void cam_debug_trace(unsigned int tag, unsigned int module_id,
  111. const char *func, const int line, const char *fmt, ...);
  112. /*
  113. * cam_get_module_name()
  114. *
  115. * @brief : Get the module name from module ID
  116. *
  117. * @module_id : Module ID which is using this function
  118. */
  119. const char *cam_get_module_name(unsigned int module_id);
  120. /*
  121. * CAM_TRACE
  122. * @brief : This Macro will print logs in ftrace
  123. *
  124. * @__module : Respective module id which is been calling this Macro
  125. * @fmt : Formatted string which needs to be print in log
  126. * @args : Arguments which needs to be print in log
  127. */
  128. #define CAM_TRACE(__module, fmt, args...) \
  129. ({ \
  130. cam_debug_trace(CAM_TYPE_TRACE, __module, __func__, __LINE__, \
  131. fmt, ##args); \
  132. })
  133. /*
  134. * CAM_ERR
  135. * @brief : This Macro will print error logs
  136. *
  137. * @__module : Respective module id which is been calling this Macro
  138. * @fmt : Formatted string which needs to be print in log
  139. * @args : Arguments which needs to be print in log
  140. */
  141. #define CAM_ERR(__module, fmt, args...) \
  142. ({ \
  143. pr_info("CAM_ERR: %s: %s: %d " fmt "\n", \
  144. cam_get_module_name(__module), __func__, \
  145. __LINE__, ##args); \
  146. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  147. fmt, ##args); \
  148. })
  149. /*
  150. * CAM_WARN
  151. * @brief : This Macro will print warning logs
  152. *
  153. * @__module : Respective module id which is been calling this Macro
  154. * @fmt : Formatted string which needs to be print in log
  155. * @args : Arguments which needs to be print in log
  156. */
  157. #define CAM_WARN(__module, fmt, args...) \
  158. ({ \
  159. pr_info("CAM_WARN: %s: %s: %d " fmt "\n", \
  160. cam_get_module_name(__module), __func__, \
  161. __LINE__, ##args); \
  162. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  163. fmt, ##args); \
  164. })
  165. /*
  166. * CAM_INFO
  167. * @brief : This Macro will print Information logs
  168. *
  169. * @__module : Respective module id which is been calling this Macro
  170. * @fmt : Formatted string which needs to be print in log
  171. * @args : Arguments which needs to be print in log
  172. */
  173. #define CAM_INFO(__module, fmt, args...) \
  174. ({ \
  175. pr_info("CAM_INFO: %s: %s: %d " fmt "\n", \
  176. cam_get_module_name(__module), __func__, \
  177. __LINE__, ##args); \
  178. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  179. fmt, ##args); \
  180. })
  181. /*
  182. * CAM_INFO_RATE_LIMIT
  183. * @brief : This Macro will print info logs with ratelimit
  184. *
  185. * @__module : Respective module id which is been calling this Macro
  186. * @fmt : Formatted string which needs to be print in log
  187. * @args : Arguments which needs to be print in log
  188. */
  189. #define CAM_INFO_RATE_LIMIT(__module, fmt, args...) \
  190. ({ \
  191. pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n", \
  192. cam_get_module_name(__module), __func__, \
  193. __LINE__, ##args); \
  194. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  195. fmt, ##args); \
  196. })
  197. /*
  198. * CAM_DBG
  199. * @brief : This Macro will print debug logs when enabled using GROUP and
  200. * if its priority is greater than the priority parameter
  201. *
  202. * @__module : Respective module id which is been calling this Macro
  203. * @fmt : Formatted string which needs to be print in log
  204. * @args : Arguments which needs to be print in log
  205. */
  206. #define CAM_DBG(__module, fmt, args...) \
  207. cam_debug_log(__module, CAM_DBG_PRIORITY_0, __func__, __LINE__, \
  208. fmt, ##args)
  209. #define CAM_DBG_PR1(__module, fmt, args...) \
  210. cam_debug_log(__module, CAM_DBG_PRIORITY_1, __func__, __LINE__, \
  211. fmt, ##args)
  212. #define CAM_DBG_PR2(__module, fmt, args...) \
  213. cam_debug_log(__module, CAM_DBG_PRIORITY_2, __func__, __LINE__, \
  214. fmt, ##args)
  215. /*
  216. * CAM_ERR_RATE_LIMIT
  217. * @brief : This Macro will print error print logs with ratelimit
  218. */
  219. #define CAM_ERR_RATE_LIMIT(__module, fmt, args...) \
  220. ({ \
  221. pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n", \
  222. cam_get_module_name(__module), __func__, \
  223. __LINE__, ##args); \
  224. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  225. fmt, ##args); \
  226. })
  227. /*
  228. * CAM_WARN_RATE_LIMIT
  229. * @brief : This Macro will print warning logs with ratelimit
  230. *
  231. * @__module : Respective module id which is been calling this Macro
  232. * @fmt : Formatted string which needs to be print in log
  233. * @args : Arguments which needs to be print in log
  234. */
  235. #define CAM_WARN_RATE_LIMIT(__module, fmt, args...) \
  236. ({ \
  237. pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n", \
  238. cam_get_module_name(__module), __func__, \
  239. __LINE__, ##args); \
  240. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  241. fmt, ##args); \
  242. })
  243. /*
  244. * CAM_WARN_RATE_LIMIT_CUSTOM
  245. * @brief : This Macro will print warn logs with custom ratelimit
  246. *
  247. * @__module : Respective module id which is been calling this Macro
  248. * @interval : Time interval in seconds
  249. * @burst : No of logs to print in interval time
  250. * @fmt : Formatted string which needs to be print in log
  251. * @args : Arguments which needs to be print in log
  252. */
  253. #define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  254. ({ \
  255. static DEFINE_RATELIMIT_STATE(_rs, \
  256. (interval * HZ), \
  257. burst); \
  258. if (__ratelimit(&_rs)) \
  259. pr_info( \
  260. "CAM_WARN: %s: %s: %d " fmt "\n", \
  261. cam_get_module_name(__module), __func__, \
  262. __LINE__, ##args); \
  263. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  264. fmt, ##args); \
  265. })
  266. /*
  267. * CAM_INFO_RATE_LIMIT_CUSTOM
  268. * @brief : This Macro will print info logs with custom ratelimit
  269. *
  270. * @__module : Respective module id which is been calling this Macro
  271. * @interval : Time interval in seconds
  272. * @burst : No of logs to print in interval time
  273. * @fmt : Formatted string which needs to be print in log
  274. * @args : Arguments which needs to be print in log
  275. */
  276. #define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  277. ({ \
  278. static DEFINE_RATELIMIT_STATE(_rs, \
  279. (interval * HZ), \
  280. burst); \
  281. if (__ratelimit(&_rs)) \
  282. pr_info( \
  283. "CAM_INFO: %s: %s: %d " fmt "\n", \
  284. cam_get_module_name(__module), __func__, \
  285. __LINE__, ##args); \
  286. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  287. fmt, ##args); \
  288. })
  289. /*
  290. * CAM_ERR_RATE_LIMIT_CUSTOM
  291. * @brief : This Macro will print error logs with custom ratelimit
  292. *
  293. * @__module : Respective module id which is been calling this Macro
  294. * @interval : Time interval in seconds
  295. * @burst : No of logs to print in interval time
  296. * @fmt : Formatted string which needs to be print in log
  297. * @args : Arguments which needs to be print in log
  298. */
  299. #define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  300. ({ \
  301. static DEFINE_RATELIMIT_STATE(_rs, \
  302. (interval * HZ), \
  303. burst); \
  304. if (__ratelimit(&_rs)) \
  305. pr_info( \
  306. "CAM_ERR: %s: %s: %d " fmt "\n", \
  307. cam_get_module_name(__module), __func__, \
  308. __LINE__, ##args); \
  309. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  310. fmt, ##args); \
  311. })
  312. /**
  313. * cam_print_to_buffer
  314. * @brief: Function to print to camera logs to a buffer. Don't use directly. Use macros
  315. * provided below.
  316. *
  317. * @buf: Buffer to print into
  318. * @buf_size: Total size of the buffer
  319. * @len: Pointer to variable used to keep track of the length
  320. * @tag: Log level tag to be prefixed
  321. * @module_id: Module id tag to be prefixed
  322. * @fmt: Formatted string which needs to be print in log
  323. * @args: Arguments which needs to be print in log
  324. */
  325. void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag,
  326. unsigned int module_id, const char *fmt, ...);
  327. /**
  328. * CAM_[ERR/WARN/INFO]_BUF
  329. * @brief: Macro to print a new line into log buffer.
  330. *
  331. * @module_id: Module id tag to be prefixed
  332. * @buf: Buffer to print into
  333. * @buf_size: Total size of the buffer
  334. * @len: Pointer to the variable used to keep track of the length
  335. * @fmt: Formatted string which needs to be print in log
  336. * @args: Arguments which needs to be print in log
  337. */
  338. #define CAM_ERR_BUF(module_id, buf, buf_size, len, fmt, args...) \
  339. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_ERR, module_id, fmt, ##args)
  340. #define CAM_WARN_BUF(module_id, buf, buf_size, len, fmt, args...) \
  341. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_WARN, module_id, fmt, ##args)
  342. #define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...) \
  343. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args)
  344. /**
  345. * @brief : API to get camera debug settings
  346. * @return const struct camera_debug_settings pointer.
  347. */
  348. const struct camera_debug_settings *cam_debug_get_settings(void);
  349. /**
  350. * @brief : API to parse and store input from sysfs debug node
  351. * @return Number of bytes read from buffer on success, or -EPERM on error.
  352. */
  353. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  354. struct device_attribute *attr, const char *buf, size_t count);
  355. #endif /* _CAM_DEBUG_UTIL_H_ */