cam_debug_util.h 15 KB

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