cam_debug_util.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. #define CAM_CDM (1 << 0)
  9. #define CAM_CORE (1 << 1)
  10. #define CAM_CPAS (1 << 2)
  11. #define CAM_ISP (1 << 3)
  12. #define CAM_CRM (1 << 4)
  13. #define CAM_SENSOR (1 << 5)
  14. #define CAM_SMMU (1 << 6)
  15. #define CAM_SYNC (1 << 7)
  16. #define CAM_ICP (1 << 8)
  17. #define CAM_JPEG (1 << 9)
  18. #define CAM_FD (1 << 10)
  19. #define CAM_LRME (1 << 11)
  20. #define CAM_FLASH (1 << 12)
  21. #define CAM_ACTUATOR (1 << 13)
  22. #define CAM_CCI (1 << 14)
  23. #define CAM_CSIPHY (1 << 15)
  24. #define CAM_EEPROM (1 << 16)
  25. #define CAM_UTIL (1 << 17)
  26. #define CAM_HFI (1 << 18)
  27. #define CAM_CTXT (1 << 19)
  28. #define CAM_OIS (1 << 20)
  29. #define CAM_RES (1 << 21)
  30. #define CAM_MEM (1 << 22)
  31. /* CAM_IRQ_CTRL: For events in irq controller */
  32. #define CAM_IRQ_CTRL (1 << 23)
  33. /* CAM_REQ: Tracks a request submitted to KMD */
  34. #define CAM_REQ (1 << 24)
  35. /* CAM_PERF: Used for performance (clock, BW etc) logs */
  36. #define CAM_PERF (1 << 25)
  37. #define CAM_CUSTOM (1 << 26)
  38. #define CAM_OPE (1 << 28)
  39. #define CAM_PRESIL (1 << 27)
  40. /* CAM_IO_ACCESS: Tracks IO read/write */
  41. #define CAM_IO_ACCESS (1 << 29)
  42. #define STR_BUFFER_MAX_LENGTH 1024
  43. /**
  44. * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
  45. */
  46. struct cam_cpas_debug_settings {
  47. uint64_t mnoc_hf_0_ab_bw;
  48. uint64_t mnoc_hf_0_ib_bw;
  49. uint64_t mnoc_hf_1_ab_bw;
  50. uint64_t mnoc_hf_1_ib_bw;
  51. uint64_t mnoc_sf_0_ab_bw;
  52. uint64_t mnoc_sf_0_ib_bw;
  53. uint64_t mnoc_sf_1_ab_bw;
  54. uint64_t mnoc_sf_1_ib_bw;
  55. uint64_t mnoc_sf_icp_ab_bw;
  56. uint64_t mnoc_sf_icp_ib_bw;
  57. uint64_t camnoc_bw;
  58. };
  59. /**
  60. * struct camera_debug_settings - Sysfs debug settings for camera
  61. *
  62. * @cpas_settings: Debug settings for cpas driver.
  63. */
  64. struct camera_debug_settings {
  65. struct cam_cpas_debug_settings cpas_settings;
  66. };
  67. /*
  68. * cam_debug_log()
  69. *
  70. * @brief : Get the Module name from module ID and print
  71. * respective debug logs
  72. *
  73. * @module_id : Respective Module ID which is calling this function
  74. * @func : Function which is calling to print logs
  75. * @line : Line number associated with the function which is calling
  76. * to print log
  77. * @fmt : Formatted string which needs to be print in the log
  78. *
  79. */
  80. void cam_debug_log(unsigned int module_id, const char *func, const int line,
  81. const char *fmt, ...);
  82. /*
  83. * cam_get_module_name()
  84. *
  85. * @brief : Get the module name from module ID
  86. *
  87. * @module_id : Module ID which is using this function
  88. */
  89. const char *cam_get_module_name(unsigned int module_id);
  90. /*
  91. * CAM_ERR
  92. * @brief : This Macro will print error logs
  93. *
  94. * @__module : Respective module id which is been calling this Macro
  95. * @fmt : Formatted string which needs to be print in log
  96. * @args : Arguments which needs to be print in log
  97. */
  98. #define CAM_ERR(__module, fmt, args...) \
  99. pr_info("CAM_ERR: %s: %s: %d " fmt "\n", \
  100. cam_get_module_name(__module), __func__, __LINE__, ##args)
  101. /*
  102. * CAM_WARN
  103. * @brief : This Macro will print warning logs
  104. *
  105. * @__module : Respective module id which is been calling this Macro
  106. * @fmt : Formatted string which needs to be print in log
  107. * @args : Arguments which needs to be print in log
  108. */
  109. #define CAM_WARN(__module, fmt, args...) \
  110. pr_info("CAM_WARN: %s: %s: %d " fmt "\n", \
  111. cam_get_module_name(__module), __func__, __LINE__, ##args)
  112. /*
  113. * CAM_INFO
  114. * @brief : This Macro will print Information logs
  115. *
  116. * @__module : Respective module id which is been calling this Macro
  117. * @fmt : Formatted string which needs to be print in log
  118. * @args : Arguments which needs to be print in log
  119. */
  120. #define CAM_INFO(__module, fmt, args...) \
  121. pr_info("CAM_INFO: %s: %s: %d " fmt "\n", \
  122. cam_get_module_name(__module), __func__, __LINE__, ##args)
  123. /*
  124. * CAM_INFO_RATE_LIMIT
  125. * @brief : This Macro will print info logs with ratelimit
  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_INFO_RATE_LIMIT(__module, fmt, args...) \
  132. pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n", \
  133. cam_get_module_name(__module), __func__, __LINE__, ##args)
  134. /*
  135. * CAM_DBG
  136. * @brief : This Macro will print debug logs when enabled using GROUP
  137. *
  138. * @__module : Respective module id which is been calling this Macro
  139. * @fmt : Formatted string which needs to be print in log
  140. * @args : Arguments which needs to be print in log
  141. */
  142. #define CAM_DBG(__module, fmt, args...) \
  143. cam_debug_log(__module, __func__, __LINE__, fmt, ##args)
  144. /*
  145. * CAM_ERR_RATE_LIMIT
  146. * @brief : This Macro will print error print logs with ratelimit
  147. */
  148. #define CAM_ERR_RATE_LIMIT(__module, fmt, args...) \
  149. pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n", \
  150. cam_get_module_name(__module), __func__, __LINE__, ##args)
  151. /*
  152. * CAM_WARN_RATE_LIMIT
  153. * @brief : This Macro will print warning logs with ratelimit
  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_RATE_LIMIT(__module, fmt, args...) \
  160. pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n", \
  161. cam_get_module_name(__module), __func__, __LINE__, ##args)
  162. /*
  163. * CAM_WARN_RATE_LIMIT_CUSTOM
  164. * @brief : This Macro will print warn logs with custom ratelimit
  165. *
  166. * @__module : Respective module id which is been calling this Macro
  167. * @interval : Time interval in seconds
  168. * @burst : No of logs to print in interval time
  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_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  173. ({ \
  174. static DEFINE_RATELIMIT_STATE(_rs, \
  175. (interval * HZ), \
  176. burst); \
  177. if (__ratelimit(&_rs)) \
  178. pr_info( \
  179. "CAM_WARN: %s: %s: %d " fmt "\n", \
  180. cam_get_module_name(__module), __func__, \
  181. __LINE__, ##args); \
  182. })
  183. /*
  184. * CAM_INFO_RATE_LIMIT_CUSTOM
  185. * @brief : This Macro will print info logs with custom ratelimit
  186. *
  187. * @__module : Respective module id which is been calling this Macro
  188. * @interval : Time interval in seconds
  189. * @burst : No of logs to print in interval time
  190. * @fmt : Formatted string which needs to be print in log
  191. * @args : Arguments which needs to be print in log
  192. */
  193. #define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  194. ({ \
  195. static DEFINE_RATELIMIT_STATE(_rs, \
  196. (interval * HZ), \
  197. burst); \
  198. if (__ratelimit(&_rs)) \
  199. pr_info( \
  200. "CAM_INFO: %s: %s: %d " fmt "\n", \
  201. cam_get_module_name(__module), __func__, \
  202. __LINE__, ##args); \
  203. })
  204. /*
  205. * CAM_ERR_RATE_LIMIT_CUSTOM
  206. * @brief : This Macro will print error logs with custom ratelimit
  207. *
  208. * @__module : Respective module id which is been calling this Macro
  209. * @interval : Time interval in seconds
  210. * @burst : No of logs to print in interval time
  211. * @fmt : Formatted string which needs to be print in log
  212. * @args : Arguments which needs to be print in log
  213. */
  214. #define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  215. ({ \
  216. static DEFINE_RATELIMIT_STATE(_rs, \
  217. (interval * HZ), \
  218. burst); \
  219. if (__ratelimit(&_rs)) \
  220. pr_info( \
  221. "CAM_ERR: %s: %s: %d " fmt "\n", \
  222. cam_get_module_name(__module), __func__, \
  223. __LINE__, ##args); \
  224. })
  225. /**
  226. * @brief : API to get camera debug settings
  227. * @return const struct camera_debug_settings pointer.
  228. */
  229. const struct camera_debug_settings *cam_debug_get_settings(void);
  230. /**
  231. * @brief : API to parse and store input from sysfs debug node
  232. * @return Number of bytes read from buffer on success, or -EPERM on error.
  233. */
  234. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  235. struct device_attribute *attr, const char *buf, size_t count);
  236. #endif /* _CAM_DEBUG_UTIL_H_ */