cam_debug_util.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #define STR_BUFFER_MAX_LENGTH 1024
  41. /**
  42. * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
  43. */
  44. struct cam_cpas_debug_settings {
  45. uint64_t mnoc_hf_0_ab_bw;
  46. uint64_t mnoc_hf_0_ib_bw;
  47. uint64_t mnoc_hf_1_ab_bw;
  48. uint64_t mnoc_hf_1_ib_bw;
  49. uint64_t mnoc_sf_0_ab_bw;
  50. uint64_t mnoc_sf_0_ib_bw;
  51. uint64_t mnoc_sf_1_ab_bw;
  52. uint64_t mnoc_sf_1_ib_bw;
  53. uint64_t mnoc_sf_icp_ab_bw;
  54. uint64_t mnoc_sf_icp_ib_bw;
  55. uint64_t camnoc_bw;
  56. };
  57. /**
  58. * struct camera_debug_settings - Sysfs debug settings for camera
  59. *
  60. * @cpas_settings: Debug settings for cpas driver.
  61. */
  62. struct camera_debug_settings {
  63. struct cam_cpas_debug_settings cpas_settings;
  64. };
  65. /*
  66. * cam_debug_log()
  67. *
  68. * @brief : Get the Module name from module ID and print
  69. * respective debug logs
  70. *
  71. * @module_id : Respective Module ID which is calling this function
  72. * @func : Function which is calling to print logs
  73. * @line : Line number associated with the function which is calling
  74. * to print log
  75. * @fmt : Formatted string which needs to be print in the log
  76. *
  77. */
  78. void cam_debug_log(unsigned int module_id, const char *func, const int line,
  79. const char *fmt, ...);
  80. /*
  81. * cam_get_module_name()
  82. *
  83. * @brief : Get the module name from module ID
  84. *
  85. * @module_id : Module ID which is using this function
  86. */
  87. const char *cam_get_module_name(unsigned int module_id);
  88. /*
  89. * CAM_ERR
  90. * @brief : This Macro will print error logs
  91. *
  92. * @__module : Respective module id which is been calling this Macro
  93. * @fmt : Formatted string which needs to be print in log
  94. * @args : Arguments which needs to be print in log
  95. */
  96. #define CAM_ERR(__module, fmt, args...) \
  97. pr_info("CAM_ERR: %s: %s: %d " fmt "\n", \
  98. cam_get_module_name(__module), __func__, __LINE__, ##args)
  99. /*
  100. * CAM_WARN
  101. * @brief : This Macro will print warning logs
  102. *
  103. * @__module : Respective module id which is been calling this Macro
  104. * @fmt : Formatted string which needs to be print in log
  105. * @args : Arguments which needs to be print in log
  106. */
  107. #define CAM_WARN(__module, fmt, args...) \
  108. pr_info("CAM_WARN: %s: %s: %d " fmt "\n", \
  109. cam_get_module_name(__module), __func__, __LINE__, ##args)
  110. /*
  111. * CAM_INFO
  112. * @brief : This Macro will print Information logs
  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_INFO(__module, fmt, args...) \
  119. pr_info("CAM_INFO: %s: %s: %d " fmt "\n", \
  120. cam_get_module_name(__module), __func__, __LINE__, ##args)
  121. /*
  122. * CAM_INFO_RATE_LIMIT
  123. * @brief : This Macro will print info logs with ratelimit
  124. *
  125. * @__module : Respective module id which is been calling this Macro
  126. * @fmt : Formatted string which needs to be print in log
  127. * @args : Arguments which needs to be print in log
  128. */
  129. #define CAM_INFO_RATE_LIMIT(__module, fmt, args...) \
  130. pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n", \
  131. cam_get_module_name(__module), __func__, __LINE__, ##args)
  132. /*
  133. * CAM_DBG
  134. * @brief : This Macro will print debug logs when enabled using GROUP
  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_DBG(__module, fmt, args...) \
  141. cam_debug_log(__module, __func__, __LINE__, fmt, ##args)
  142. /*
  143. * CAM_ERR_RATE_LIMIT
  144. * @brief : This Macro will print error print logs with ratelimit
  145. */
  146. #define CAM_ERR_RATE_LIMIT(__module, fmt, args...) \
  147. pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n", \
  148. cam_get_module_name(__module), __func__, __LINE__, ##args)
  149. /*
  150. * CAM_WARN_RATE_LIMIT
  151. * @brief : This Macro will print warning logs with ratelimit
  152. *
  153. * @__module : Respective module id which is been calling this Macro
  154. * @fmt : Formatted string which needs to be print in log
  155. * @args : Arguments which needs to be print in log
  156. */
  157. #define CAM_WARN_RATE_LIMIT(__module, fmt, args...) \
  158. pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n", \
  159. cam_get_module_name(__module), __func__, __LINE__, ##args)
  160. /*
  161. * CAM_WARN_RATE_LIMIT_CUSTOM
  162. * @brief : This Macro will print warn logs with custom ratelimit
  163. *
  164. * @__module : Respective module id which is been calling this Macro
  165. * @interval : Time interval in seconds
  166. * @burst : No of logs to print in interval time
  167. * @fmt : Formatted string which needs to be print in log
  168. * @args : Arguments which needs to be print in log
  169. */
  170. #define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  171. ({ \
  172. static DEFINE_RATELIMIT_STATE(_rs, \
  173. (interval * HZ), \
  174. burst); \
  175. if (__ratelimit(&_rs)) \
  176. pr_info( \
  177. "CAM_WARN: %s: %s: %d " fmt "\n", \
  178. cam_get_module_name(__module), __func__, \
  179. __LINE__, ##args); \
  180. })
  181. /*
  182. * CAM_INFO_RATE_LIMIT_CUSTOM
  183. * @brief : This Macro will print info logs with custom ratelimit
  184. *
  185. * @__module : Respective module id which is been calling this Macro
  186. * @interval : Time interval in seconds
  187. * @burst : No of logs to print in interval time
  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_CUSTOM(__module, interval, burst, fmt, args...) \
  192. ({ \
  193. static DEFINE_RATELIMIT_STATE(_rs, \
  194. (interval * HZ), \
  195. burst); \
  196. if (__ratelimit(&_rs)) \
  197. pr_info( \
  198. "CAM_INFO: %s: %s: %d " fmt "\n", \
  199. cam_get_module_name(__module), __func__, \
  200. __LINE__, ##args); \
  201. })
  202. /*
  203. * CAM_ERR_RATE_LIMIT_CUSTOM
  204. * @brief : This Macro will print error logs with custom ratelimit
  205. *
  206. * @__module : Respective module id which is been calling this Macro
  207. * @interval : Time interval in seconds
  208. * @burst : No of logs to print in interval time
  209. * @fmt : Formatted string which needs to be print in log
  210. * @args : Arguments which needs to be print in log
  211. */
  212. #define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  213. ({ \
  214. static DEFINE_RATELIMIT_STATE(_rs, \
  215. (interval * HZ), \
  216. burst); \
  217. if (__ratelimit(&_rs)) \
  218. pr_info( \
  219. "CAM_ERR: %s: %s: %d " fmt "\n", \
  220. cam_get_module_name(__module), __func__, \
  221. __LINE__, ##args); \
  222. })
  223. /**
  224. * @brief : API to get camera debug settings
  225. * @return const struct camera_debug_settings pointer.
  226. */
  227. const struct camera_debug_settings *cam_debug_get_settings(void);
  228. /**
  229. * @brief : API to parse and store input from sysfs debug node
  230. * @return Number of bytes read from buffer on success, or -EPERM on error.
  231. */
  232. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  233. struct device_attribute *attr, const char *buf, size_t count);
  234. #endif /* _CAM_DEBUG_UTIL_H_ */