Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fbb1d92 authored by Jigarkumar Zala's avatar Jigarkumar Zala
Browse files

msm: camera: add/update debug macros and dynamic group selection



Add/updte common logging debug macros, and add dynamic group
selection in order to choose debugging module/modules at runtime.

Sysfs entry can be found under
/sys/module/cam_debug_util/parameters/

Sysfs entry usage with root privilege:
- adb root
- adb remount
- adb shell "echo 0x(module/modules_flag)/Decimal_value >
   "/sys/module/cam_debug_util/parameters/debug_mdl"

CRs-Fixed: 2056624
Change-Id: Ifc093a0f290e110466f4a03b7bbd4d3dea06f571
Signed-off-by: default avatarJigarkumar Zala <jzala@codeaurora.org>
parent 6f935319
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -11,9 +11,14 @@
 */

#include <linux/io.h>
#include <linux/module.h>

#include "cam_debug_util.h"

static const char *cam_debug_module_id_to_name(unsigned int module_id)
static uint debug_mdl;
module_param(debug_mdl, uint, 0644);

const char *cam_get_module_name(unsigned int module_id)
{
	const char *name = NULL;

@@ -69,31 +74,37 @@ void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
	const char *func, const int line, const char *fmt, ...)
{
	char str_buffer[STR_BUFFER_MAX_LENGTH];
	const char *module_name;
	va_list args;

	va_start(args, fmt);
	vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
	va_end(args);

	module_name = cam_debug_module_id_to_name(module_id);

	switch (dbg_level) {
	case CAM_LEVEL_DBG:
		if (debug_mdl & module_id) {
			vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
			pr_info("CAM_DBG: %s: %s: %d: %s\n",
				cam_get_module_name(module_id),
				func, line, str_buffer);
			va_end(args);
		}
		break;
	case CAM_LEVEL_ERR:
		vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
		pr_err("CAM_ERR: %s: %s: %d: %s\n",
			cam_get_module_name(module_id), func, line, str_buffer);
		va_end(args);
		break;
	case CAM_LEVEL_INFO:
		vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
		pr_info("CAM_INFO: %s: %s: %d: %s\n",
			module_name, func, line, str_buffer);
			cam_get_module_name(module_id), func, line, str_buffer);
		va_end(args);
		break;
	case CAM_LEVEL_WARN:
		vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
		pr_warn("CAM_WARN: %s: %s: %d: %s\n",
			module_name, func, line, str_buffer);
		break;
	case CAM_LEVEL_ERR:
		pr_err("CAM_ERR: %s: %s: %d: %s\n",
			module_name, func, line, str_buffer);
		break;
	case CAM_LEVEL_DBG:
		pr_info("CAM_DBG: %s: %s: %d: %s\n",
			module_name, func, line, str_buffer);
			cam_get_module_name(module_id), func, line, str_buffer);
		va_end(args);
		break;
	default:
		break;
+31 −29
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@
#define CAM_FLASH  (1 << 12)

#define STR_BUFFER_MAX_LENGTH  1024
#define GROUP                  0x0000

enum cam_debug_level {
	CAM_LEVEL_INFO,
@@ -40,7 +39,7 @@ enum cam_debug_level {
/*
 *  cam_debug_log()
 *
 * @brief:        Get the Module name form module ID and print
 * @brief     :  Get the Module name from module ID and print
 *               respective debug logs
 *
 * @module_id :  Respective Module ID which is calling this function
@@ -54,6 +53,15 @@ enum cam_debug_level {
void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
	const char *func, const int line, const char *fmt, ...);

/*
 * cam_get_module_name()
 *
 * @brief     :  Get the module name from module ID
 *
 * @module_id :  Module ID which is using this function
 */
const char *cam_get_module_name(unsigned int module_id);

/*
 * CAM_ERR
 * @brief    :  This Macro will print error logs
@@ -63,10 +71,7 @@ void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
 * @args     :  Arguments which needs to be print in log
 */
#define CAM_ERR(__module, fmt, args...)                            \
	{                                                          \
		cam_debug_log(__module, CAM_LEVEL_ERR,             \
			__func__, __LINE__, fmt, ##args);          \
	}
	cam_debug_log(__module, CAM_LEVEL_ERR, __func__, __LINE__, fmt, ##args)

/*
 * CAM_WARN
@@ -77,10 +82,7 @@ void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
 * @args     :  Arguments which needs to be print in log
 */
#define CAM_WARN(__module, fmt, args...)                           \
	{                                                          \
		cam_debug_log(__module, CAM_LEVEL_WARN,            \
			__func__, __LINE__, fmt, ##args);          \
	}
	cam_debug_log(__module, CAM_LEVEL_WARN, __func__, __LINE__, fmt, ##args)

/*
 * CAM_INFO
@@ -91,10 +93,7 @@ void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
 * @args     :  Arguments which needs to be print in log
 */
#define CAM_INFO(__module, fmt, args...)                           \
	{                                                          \
		cam_debug_log(__module, CAM_LEVEL_INFO,            \
			__func__, __LINE__, fmt, ##args);          \
	}
	cam_debug_log(__module, CAM_LEVEL_INFO, __func__, __LINE__, fmt, ##args)

/*
 * CAM_DBG
@@ -105,11 +104,14 @@ void cam_debug_log(unsigned int module_id, enum cam_debug_level dbg_level,
 * @args     :  Arguments which needs to be print in log
 */
#define CAM_DBG(__module, fmt, args...)                            \
	do {                                                       \
		if (GROUP & __module) {                            \
			cam_debug_log(__module, CAM_LEVEL_DBG,     \
				__func__, __LINE__, fmt, ##args);  \
		}                                                  \
	} while (0)
	cam_debug_log(__module, CAM_LEVEL_DBG, __func__, __LINE__, fmt, ##args)

/*
 * CAM_ERR_RATE_LIMIT
 * @brief :     This Macro will prevent error print logs with ratelimit
 */
#define CAM_ERR_RATE_LIMIT(__module, fmt, args...)                 \
	pr_err_ratelimited("CAM_ERR: %s: %s: %d\n" fmt,            \
		cam_get_module_name(__module), __func__,  __LINE__, ##args)

#endif /* _CAM_DEBUG_UTIL_H_ */