cam_debug_util.h 12 KB

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