cam_debug_util.h 12 KB

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