cam_debug_util.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. /* Log level types */
  41. #define CAM_TYPE_TRACE (1 << 0)
  42. #define CAM_TYPE_ERR (1 << 1)
  43. #define CAM_TYPE_WARN (1 << 2)
  44. #define CAM_TYPE_INFO (1 << 3)
  45. #define CAM_TYPE_DBG (1 << 4)
  46. #define STR_BUFFER_MAX_LENGTH 512
  47. /*
  48. * enum cam_debug_priority - Priority of debug log (0 = Lowest)
  49. */
  50. enum cam_debug_priority {
  51. CAM_DBG_PRIORITY_0,
  52. CAM_DBG_PRIORITY_1,
  53. CAM_DBG_PRIORITY_2,
  54. };
  55. /**
  56. * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
  57. */
  58. struct cam_cpas_debug_settings {
  59. uint64_t mnoc_hf_0_ab_bw;
  60. uint64_t mnoc_hf_0_ib_bw;
  61. uint64_t mnoc_hf_1_ab_bw;
  62. uint64_t mnoc_hf_1_ib_bw;
  63. uint64_t mnoc_sf_0_ab_bw;
  64. uint64_t mnoc_sf_0_ib_bw;
  65. uint64_t mnoc_sf_1_ab_bw;
  66. uint64_t mnoc_sf_1_ib_bw;
  67. uint64_t mnoc_sf_icp_ab_bw;
  68. uint64_t mnoc_sf_icp_ib_bw;
  69. uint64_t camnoc_bw;
  70. };
  71. /**
  72. * struct camera_debug_settings - Sysfs debug settings for camera
  73. *
  74. * @cpas_settings: Debug settings for cpas driver.
  75. */
  76. struct camera_debug_settings {
  77. struct cam_cpas_debug_settings cpas_settings;
  78. };
  79. /*
  80. * cam_debug_log()
  81. *
  82. * @brief : Get the Module name from module ID and print
  83. * respective debug logs
  84. *
  85. * @module_id : Respective Module ID which is calling this function
  86. * @priority : Priority of the debug log
  87. * @func : Function which is calling to print logs
  88. * @line : Line number associated with the function which is calling
  89. * to print log
  90. * @fmt : Formatted string which needs to be print in the log
  91. *
  92. */
  93. void cam_debug_log(unsigned int module_id, unsigned int priority,
  94. const char *func, const int line, const char *fmt, ...);
  95. /*
  96. * cam_debug_trace()
  97. *
  98. * @brief : Get the Module name from module ID and print
  99. * respective debug logs in ftrace
  100. *
  101. * @tag : Tag indicating whether TRACE, ERR, WARN, INFO, DBG
  102. * @module_id : Respective Module ID which is calling this function
  103. * @func : Function which is calling to print logs
  104. * @line : Line number associated with the function which is calling
  105. * to print log
  106. * @fmt : Formatted string which needs to be print in the log
  107. *
  108. */
  109. void cam_debug_trace(unsigned int tag, unsigned int module_id,
  110. const char *func, const int line, const char *fmt, ...);
  111. /*
  112. * cam_get_module_name()
  113. *
  114. * @brief : Get the module name from module ID
  115. *
  116. * @module_id : Module ID which is using this function
  117. */
  118. const char *cam_get_module_name(unsigned int module_id);
  119. /*
  120. * CAM_TRACE
  121. * @brief : This Macro will print logs in ftrace
  122. *
  123. * @__module : Respective module id which is been calling this Macro
  124. * @fmt : Formatted string which needs to be print in log
  125. * @args : Arguments which needs to be print in log
  126. */
  127. #define CAM_TRACE(__module, fmt, args...) \
  128. ({ \
  129. cam_debug_trace(CAM_TYPE_TRACE, __module, __func__, __LINE__, \
  130. fmt, ##args); \
  131. })
  132. /*
  133. * CAM_ERR
  134. * @brief : This Macro will print error logs
  135. *
  136. * @__module : Respective module id which is been calling this Macro
  137. * @fmt : Formatted string which needs to be print in log
  138. * @args : Arguments which needs to be print in log
  139. */
  140. #define CAM_ERR(__module, fmt, args...) \
  141. ({ \
  142. pr_info("CAM_ERR: %s: %s: %d " fmt "\n", \
  143. cam_get_module_name(__module), __func__, \
  144. __LINE__, ##args); \
  145. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  146. fmt, ##args); \
  147. })
  148. /*
  149. * CAM_WARN
  150. * @brief : This Macro will print warning logs
  151. *
  152. * @__module : Respective module id which is been calling this Macro
  153. * @fmt : Formatted string which needs to be print in log
  154. * @args : Arguments which needs to be print in log
  155. */
  156. #define CAM_WARN(__module, fmt, args...) \
  157. ({ \
  158. pr_info("CAM_WARN: %s: %s: %d " fmt "\n", \
  159. cam_get_module_name(__module), __func__, \
  160. __LINE__, ##args); \
  161. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  162. fmt, ##args); \
  163. })
  164. /*
  165. * CAM_INFO
  166. * @brief : This Macro will print Information logs
  167. *
  168. * @__module : Respective module id which is been calling this Macro
  169. * @fmt : Formatted string which needs to be print in log
  170. * @args : Arguments which needs to be print in log
  171. */
  172. #define CAM_INFO(__module, fmt, args...) \
  173. ({ \
  174. pr_info("CAM_INFO: %s: %s: %d " fmt "\n", \
  175. cam_get_module_name(__module), __func__, \
  176. __LINE__, ##args); \
  177. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  178. fmt, ##args); \
  179. })
  180. /*
  181. * CAM_INFO_RATE_LIMIT
  182. * @brief : This Macro will print info logs with ratelimit
  183. *
  184. * @__module : Respective module id which is been calling this Macro
  185. * @fmt : Formatted string which needs to be print in log
  186. * @args : Arguments which needs to be print in log
  187. */
  188. #define CAM_INFO_RATE_LIMIT(__module, fmt, args...) \
  189. ({ \
  190. pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n", \
  191. cam_get_module_name(__module), __func__, \
  192. __LINE__, ##args); \
  193. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  194. fmt, ##args); \
  195. })
  196. /*
  197. * CAM_DBG
  198. * @brief : This Macro will print debug logs when enabled using GROUP and
  199. * if its priority is greater than the priority parameter
  200. *
  201. * @__module : Respective module id which is been calling this Macro
  202. * @fmt : Formatted string which needs to be print in log
  203. * @args : Arguments which needs to be print in log
  204. */
  205. #define CAM_DBG(__module, fmt, args...) \
  206. cam_debug_log(__module, CAM_DBG_PRIORITY_0, __func__, __LINE__, \
  207. fmt, ##args)
  208. #define CAM_DBG_PR1(__module, fmt, args...) \
  209. cam_debug_log(__module, CAM_DBG_PRIORITY_1, __func__, __LINE__, \
  210. fmt, ##args)
  211. #define CAM_DBG_PR2(__module, fmt, args...) \
  212. cam_debug_log(__module, CAM_DBG_PRIORITY_2, __func__, __LINE__, \
  213. fmt, ##args)
  214. /*
  215. * CAM_ERR_RATE_LIMIT
  216. * @brief : This Macro will print error print logs with ratelimit
  217. */
  218. #define CAM_ERR_RATE_LIMIT(__module, fmt, args...) \
  219. ({ \
  220. pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n", \
  221. cam_get_module_name(__module), __func__, \
  222. __LINE__, ##args); \
  223. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  224. fmt, ##args); \
  225. })
  226. /*
  227. * CAM_WARN_RATE_LIMIT
  228. * @brief : This Macro will print warning logs with ratelimit
  229. *
  230. * @__module : Respective module id which is been calling this Macro
  231. * @fmt : Formatted string which needs to be print in log
  232. * @args : Arguments which needs to be print in log
  233. */
  234. #define CAM_WARN_RATE_LIMIT(__module, fmt, args...) \
  235. ({ \
  236. pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n", \
  237. cam_get_module_name(__module), __func__, \
  238. __LINE__, ##args); \
  239. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  240. fmt, ##args); \
  241. })
  242. /*
  243. * CAM_WARN_RATE_LIMIT_CUSTOM
  244. * @brief : This Macro will print warn logs with custom ratelimit
  245. *
  246. * @__module : Respective module id which is been calling this Macro
  247. * @interval : Time interval in seconds
  248. * @burst : No of logs to print in interval time
  249. * @fmt : Formatted string which needs to be print in log
  250. * @args : Arguments which needs to be print in log
  251. */
  252. #define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  253. ({ \
  254. static DEFINE_RATELIMIT_STATE(_rs, \
  255. (interval * HZ), \
  256. burst); \
  257. if (__ratelimit(&_rs)) \
  258. pr_info( \
  259. "CAM_WARN: %s: %s: %d " fmt "\n", \
  260. cam_get_module_name(__module), __func__, \
  261. __LINE__, ##args); \
  262. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  263. fmt, ##args); \
  264. })
  265. /*
  266. * CAM_INFO_RATE_LIMIT_CUSTOM
  267. * @brief : This Macro will print info logs with custom ratelimit
  268. *
  269. * @__module : Respective module id which is been calling this Macro
  270. * @interval : Time interval in seconds
  271. * @burst : No of logs to print in interval time
  272. * @fmt : Formatted string which needs to be print in log
  273. * @args : Arguments which needs to be print in log
  274. */
  275. #define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  276. ({ \
  277. static DEFINE_RATELIMIT_STATE(_rs, \
  278. (interval * HZ), \
  279. burst); \
  280. if (__ratelimit(&_rs)) \
  281. pr_info( \
  282. "CAM_INFO: %s: %s: %d " fmt "\n", \
  283. cam_get_module_name(__module), __func__, \
  284. __LINE__, ##args); \
  285. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  286. fmt, ##args); \
  287. })
  288. /*
  289. * CAM_ERR_RATE_LIMIT_CUSTOM
  290. * @brief : This Macro will print error logs with custom ratelimit
  291. *
  292. * @__module : Respective module id which is been calling this Macro
  293. * @interval : Time interval in seconds
  294. * @burst : No of logs to print in interval time
  295. * @fmt : Formatted string which needs to be print in log
  296. * @args : Arguments which needs to be print in log
  297. */
  298. #define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  299. ({ \
  300. static DEFINE_RATELIMIT_STATE(_rs, \
  301. (interval * HZ), \
  302. burst); \
  303. if (__ratelimit(&_rs)) \
  304. pr_info( \
  305. "CAM_ERR: %s: %s: %d " fmt "\n", \
  306. cam_get_module_name(__module), __func__, \
  307. __LINE__, ##args); \
  308. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  309. fmt, ##args); \
  310. })
  311. /**
  312. * @brief : API to get camera debug settings
  313. * @return const struct camera_debug_settings pointer.
  314. */
  315. const struct camera_debug_settings *cam_debug_get_settings(void);
  316. /**
  317. * @brief : API to parse and store input from sysfs debug node
  318. * @return Number of bytes read from buffer on success, or -EPERM on error.
  319. */
  320. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  321. struct device_attribute *attr, const char *buf, size_t count);
  322. #endif /* _CAM_DEBUG_UTIL_H_ */