فهرست منبع

msm: camera: utils: Add support for multiline printing to log buffers

Introduce new macros to print into log buffers that prefix the
appropriate tags. This allows the usual search filters to pick up all
the lines of the log.

CRs-Fixed: 2928828
Change-Id: I3d27490b324e884eb9cce2bfd184e82418099484
Signed-off-by: Anand Ravi <[email protected]>
Anand Ravi 4 سال پیش
والد
کامیت
27ad84d827

+ 17 - 32
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c

@@ -3965,58 +3965,49 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler(
 		evt_payload->irq_status[CAM_IFE_CSID_IRQ_REG_RX]);
 
 	if (irq_status) {
-		len += scnprintf(log_buf, CAM_IFE_CSID_LOG_BUF_LEN - len,
-			"Fatal Errors:\n");
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "Fatal Errors:\n");
 
 		if (irq_status & IFE_CSID_VER1_RX_LANE0_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER1_RX_LANE1_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER1_RX_LANE2_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER1_RX_LANE3_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER1_RX_TG_FIFO_OVERFLOW) {
 			event_type |= CAM_ISP_HW_ERROR_CSID_FIFO_OVERFLOW;
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"RX_ERROR_TPG_FIFO_OVERFLOW: Backpressure from IFE\n");
 		}
 
 		if (irq_status & IFE_CSID_VER1_RX_CPHY_PH_CRC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"CPHY_PH_CRC: Pkt Hdr CRC mismatch\n");
 
 		if (irq_status & IFE_CSID_VER1_RX_STREAM_UNDERFLOW) {
 			val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 				csi2_reg->captured_long_pkt_0_addr);
 
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr\n",
 				val & 0xFFFF);
 		}
 
 		if (irq_status & IFE_CSID_VER1_RX_ERROR_ECC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"DPHY_ERROR_ECC: Pkt hdr errors unrecoverable\n");
 	}
 
@@ -4024,30 +4015,26 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler(
 		csi2_reg->part_fatal_err_mask;
 
 	if (irq_status) {
-		len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len,
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 			"Recoverable-errors:\n");
 
 		if (irq_status & IFE_CSID_VER1_RX_CPHY_EOT_RECEPTION)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u)\n",
 				csid_hw->rx_cfg.epd_supported,
 				(csid_hw->rx_cfg.lane_type) ? "cphy" : "dphy",
 				csid_hw->rx_cfg.lane_type);
 
 		if (irq_status & IFE_CSID_VER1_RX_CPHY_SOT_RECEPTION)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"CPHY_SOT_RECEPTION: Less SOTs on lane/s\n");
 
 		if (irq_status & IFE_CSID_VER1_RX_ERROR_CRC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"CPHY_ERROR_CRC: Long pkt payload CRC mismatch\n");
 
 		if (irq_status & IFE_CSID_VER1_RX_UNBOUNDED_FRAME)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"UNBOUNDED_FRAME: Frame started with EOF or No EOF\n");
 	}
 
@@ -4055,14 +4042,13 @@ static int cam_ife_csid_ver1_rx_bottom_half_handler(
 		csi2_reg->non_fatal_err_mask;
 
 	if (irq_status) {
-		len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len,
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 			"Non-fatal errors:\n");
 		if (irq_status & IFE_CSID_VER1_RX_MMAPPED_VC_DT) {
 			val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 				csi2_reg->captured_long_pkt_0_addr);
 
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths\n",
 				(val >> 22), ((val >> 16) & 0x3F));
 		}
@@ -4112,8 +4098,7 @@ static int cam_ife_csid_ver1_path_bottom_half_handler(
 
 	while (irq_status) {
 		if ((irq_status & 0x1))
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
 				"%s\n", ver1_path_irq_desc[bit_pos]);
 		bit_pos++;
 		irq_status >>= 1;

+ 34 - 46
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c

@@ -792,7 +792,7 @@ static int cam_ife_csid_ver2_rx_err_bottom_half(
 	uint8_t                                    *log_buf = NULL;
 	uint32_t                                    irq_status;
 	uint32_t                                    rx_irq_status = 0;
-	uint32_t                                    len = 0;
+	size_t                                      len = 0;
 	uint32_t                                    val = 0;
 	uint32_t                                    event_type = 0;
 	bool                                        fatal_err_detected = false;
@@ -817,52 +817,45 @@ static int cam_ife_csid_ver2_rx_err_bottom_half(
 			csi2_reg->fatal_err_mask;
 
 	if (irq_status) {
-		len += scnprintf(log_buf, CAM_IFE_CSID_LOG_BUF_LEN - len,
-			"Fatal Errors:\n");
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+			"Fatal Errors:");
 
 		if (irq_status & IFE_CSID_VER2_RX_LANE0_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"RX_ERROR_LANE0_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER2_RX_LANE1_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"RX_ERROR_LANE1_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER2_RX_LANE2_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"RX_ERROR_LANE2_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER2_RX_LANE3_FIFO_OVERFLOW)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"RX_ERROR_LANE3_FIFO_OVERFLOW: Skew/Less Data on lanes/ Slow csid clock:%luHz",
 				soc_info->applied_src_clk_rate);
 
 		if (irq_status & IFE_CSID_VER2_RX_ERROR_CPHY_PH_CRC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"CPHY_PH_CRC: Pkt Hdr CRC mismatch\n");
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"CPHY_PH_CRC: Pkt Hdr CRC mismatch");
 
 		if (irq_status & IFE_CSID_VER2_RX_STREAM_UNDERFLOW) {
 			val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 				csi2_reg->captured_long_pkt_0_addr);
 
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"ERROR_STREAM_UNDERFLOW: Fewer bytes rcvd than WC:%d in pkt hdr",
 				val & 0xFFFF);
 		}
 
 		if (irq_status & IFE_CSID_VER2_RX_ERROR_ECC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"DPHY_ERROR_ECC: Pkt hdr errors unrecoverable\n");
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"DPHY_ERROR_ECC: Pkt hdr errors unrecoverable");
 
 		rx_irq_status |= irq_status;
 		fatal_err_detected = true;
@@ -872,31 +865,27 @@ static int cam_ife_csid_ver2_rx_err_bottom_half(
 		csi2_reg->part_fatal_err_mask;
 
 	if (irq_status) {
-		len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len,
-			"Recoverable-errors:\n");
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+			"Recoverable-errors:");
 
 		if (irq_status & IFE_CSID_VER2_RX_CPHY_EOT_RECEPTION)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u) \n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"CPHY_EOT_RECEPTION: No EOT on lane/s, is_EPD: %d, PHY_Type: %s(%u) ",
 				csid_hw->rx_cfg.epd_supported,
 				(csid_hw->rx_cfg.lane_type) ? "cphy" : "dphy",
 				csid_hw->rx_cfg.lane_type);
 
 		if (irq_status & IFE_CSID_VER2_RX_CPHY_SOT_RECEPTION)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"CPHY_SOT_RECEPTION: Less SOTs on lane/s\n");
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"CPHY_SOT_RECEPTION: Less SOTs on lane/s");
 
 		if (irq_status & IFE_CSID_VER2_RX_ERROR_CRC)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"CPHY_ERROR_CRC: Long pkt payload CRC mismatch\n");
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"CPHY_ERROR_CRC: Long pkt payload CRC mismatch");
 
 		if (irq_status & IFE_CSID_VER2_RX_UNBOUNDED_FRAME)
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"UNBOUNDED_FRAME: Frame started with EOF or No EOF\n");
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"UNBOUNDED_FRAME: Frame started with EOF or No EOF");
 
 		rx_irq_status |= irq_status;
 		fatal_err_detected = true;
@@ -906,16 +895,15 @@ static int cam_ife_csid_ver2_rx_err_bottom_half(
 		csi2_reg->non_fatal_err_mask;
 
 	if (irq_status) {
-		len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len,
-			"Non-fatal-errors:\n");
+		CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+			"Non-fatal-errors:");
 
 		if (irq_status & IFE_CSID_VER2_RX_MMAPPED_VC_DT) {
 			val = cam_io_r_mb(soc_info->reg_map[0].mem_base +
 				csi2_reg->captured_long_pkt_0_addr);
 
-			len += scnprintf(log_buf + len,
-				CAM_IFE_CSID_LOG_BUF_LEN - len,
-				"MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths\n",
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len,
+				"MMAPPED_VC_DT: VC:%d DT:%d mapped to more than 1 csid paths",
 				(val >> 22), ((val >> 16) & 0x3F));
 		}
 	}
@@ -1014,7 +1002,7 @@ static int cam_ife_csid_ver2_parse_path_irq_status(
 	uint32_t                         bit_pos = 0;
 	uint32_t                         status;
 	uint32_t                         sof_irq_debug_en = 0;
-	uint32_t                         len = 0;
+	size_t                           len = 0;
 	uint8_t                         *log_buf = NULL;
 
 	log_buf = csid_hw->log_buf;
@@ -1025,8 +1013,8 @@ static int cam_ife_csid_ver2_parse_path_irq_status(
 	status = irq_status & err_mask;
 	while (status) {
 		if (status & 0x1 )
-			len += scnprintf(log_buf + len, CAM_IFE_CSID_LOG_BUF_LEN - len,
-			"\n%s", ver2_path_irq_desc[bit_pos].desc);
+			CAM_ERR_BUF(CAM_ISP, log_buf, CAM_IFE_CSID_LOG_BUF_LEN, &len, "%s",
+				ver2_path_irq_desc[bit_pos].desc);
 		bit_pos++;
 		status >>= 1;
 	}

+ 4 - 5
drivers/cam_isp/isp_hw_mgr/isp_hw/sfe_hw/sfe_top/cam_sfe_top.c

@@ -389,7 +389,8 @@ static void cam_sfe_top_check_module_status(
 	const struct cam_sfe_top_debug_info status_list[][8])
 {
 	bool found = false;
-	uint32_t i, j, val = 0, len = 0;
+	uint32_t i, j, val = 0;
+	size_t len = 0;
 	uint8_t log_buf[1024];
 
 	if (!status_list)
@@ -406,11 +407,9 @@ static void cam_sfe_top_check_module_status(
 			if (val == 0 || val == 5)
 				continue;
 
-			len += scnprintf(log_buf + len, 1024 -
-				len, "\nCAM_INFO: %s [I:%u V:%u R:%u]",
+			CAM_INFO_BUF(CAM_SFE, log_buf, 1024, &len, "%s [I:%u V:%u R:%u]",
 				status_list[i][j].clc_name,
-				((val >> 2) & 1), ((val >> 1) & 1),
-				(val & 1));
+				((val >> 2) & 1), ((val >> 1) & 1), (val & 1));
 			found = true;
 		}
 		if (found)

+ 10 - 12
drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_top/cam_vfe_top_ver4.c

@@ -852,7 +852,8 @@ static void cam_vfe_top_ver4_check_module_status(
 	const struct cam_vfe_top_debug_info status_list[][8])
 {
 	bool found = false;
-	uint32_t i, j, val = 0, len = 0;
+	uint32_t i, j, val = 0;
+	size_t len = 0;
 	uint8_t log_buf[1024];
 
 	if (!status_list)
@@ -869,10 +870,9 @@ static void cam_vfe_top_ver4_check_module_status(
 			if (val == 0 || val == 5)
 				continue;
 
-			len += scnprintf(log_buf + len, 1024 -
-				len, "\nCAM_INFO: %s [I:%u V:%u R:%u]",
-				status_list[i][j].clc_name, ((val >> 2) & 1),
-				((val >> 1) & 1), (val & 1));
+			CAM_INFO_BUF(CAM_ISP, log_buf, 1024, &len, "%s [I:%u V:%u R:%u]",
+				status_list[i][j].clc_name,
+				((val >> 2) & 1), ((val >> 1) & 1), (val & 1));
 			found = true;
 		}
 		if (found)
@@ -889,7 +889,8 @@ static void cam_vfe_top_ver4_print_debug_reg_status(
 	struct cam_vfe_top_ver4_reg_offset_common  *common_reg;
 	uint32_t                                    val = 0;
 	uint32_t                                    num_reg =  0;
-	uint32_t                                    i = 0, j, len = 0;
+	uint32_t                                    i = 0, j;
+	size_t                                      len = 0;
 	uint8_t                                    *log_buf;
 	uint32_t                                   *reg_val = NULL;
 	struct cam_hw_soc_info                     *soc_info;
@@ -908,17 +909,14 @@ static void cam_vfe_top_ver4_print_debug_reg_status(
 		return;
 
 	while (i < num_reg) {
-		len += scnprintf(log_buf + len, CAM_VFE_LEN_LOG_BUF - len,
-				"VFE[%u]: Top Debug Status",
-				soc_info->index);
 		for(j = 0; j < 4 && i < num_reg; j++, i++) {
 			val = cam_io_r(base +
 				common_reg->top_debug[i]);
 			reg_val[i] = val;
-			len += scnprintf(log_buf + len, CAM_VFE_LEN_LOG_BUF -
-				len, "\nstatus %2d : 0x%08x", i, val);
+			CAM_INFO_BUF(CAM_ISP, log_buf, CAM_VFE_LEN_LOG_BUF, &len,
+				"status %2d : 0x%08x", i, val);
 		}
-		CAM_INFO(CAM_ISP, "%s", log_buf);
+		CAM_INFO(CAM_ISP, "VFE[%u]: Top Debug Status: %s", soc_info->index, log_buf);
 		len = 0;
 		memset(log_buf, 0, sizeof(uint8_t)*CAM_VFE_LEN_LOG_BUF);
 	}

+ 45 - 37
drivers/cam_utils/cam_debug_util.c

@@ -257,58 +257,66 @@ const char *cam_get_tag_name(unsigned int tag_id)
 	return name;
 }
 
-void cam_debug_log(unsigned int module_id, unsigned int priority,
-	const char *func, const int line, const char *fmt, ...)
+static inline void __cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len,
+	unsigned int tag, unsigned int module_id, const char *func, const int line,
+	const bool is_final_print, const char *fmt, va_list args)
+{
+	size_t buf_len = *len;
+
+	if (is_final_print)
+		buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "%s: %s: %s: %d: ",
+			cam_get_tag_name(tag), cam_get_module_name(module_id), func, line);
+	else
+		buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "\n%-8s: %s:\t",
+			cam_get_tag_name(tag), cam_get_module_name(module_id));
+	buf_len += vscnprintf(buf + buf_len, (buf_size - buf_len), fmt, args);
+
+	*len = buf_len;
+}
+
+void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag,
+	unsigned int module_id, const char *fmt, ...)
 {
 	va_list args;
 
 	va_start(args, fmt);
+	__cam_print_to_buffer(buf, buf_size, len, tag, module_id, "", 0, false, fmt, args);
+	va_end(args);
+}
 
+void cam_debug_log(unsigned int module_id, unsigned int priority,
+	const char *func, const int line, const char *fmt, ...)
+{
 	if ((debug_mdl & module_id) && (priority >= debug_priority)) {
-		char str_buffer[STR_BUFFER_MAX_LENGTH];
-
-		vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
-
-		if ((debug_type == 0) || (debug_type == 2)) {
-			pr_info("CAM_DBG: %s: %s: %d: %s\n",
-				cam_get_module_name(module_id),
-				func, line, str_buffer);
-		}
-
-		if ((debug_type == 1) || (debug_type == 2)) {
-			char trace_buffer[STR_BUFFER_MAX_LENGTH];
-
-			snprintf(trace_buffer, sizeof(trace_buffer),
-				"%s: %s: %s: %d: %s",
-				cam_get_tag_name(CAM_TYPE_DBG),
-				cam_get_module_name(module_id),
-				func, line, str_buffer);
-			trace_cam_log_debug(trace_buffer);
-		}
-	}
+		char str_buf[STR_BUFFER_MAX_LENGTH];
+		size_t len = 0;
+		va_list args;
 
-	va_end(args);
+		va_start(args, fmt);
+		__cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_DBG, module_id,
+			func, line, true, fmt, args);
+
+		if ((debug_type == 0) || (debug_type == 2))
+			pr_info("%s\n", str_buf);
+		if ((debug_type == 1) || (debug_type == 2))
+			trace_cam_log_debug(str_buf);
+
+		va_end(args);
+	}
 }
 
 void cam_debug_trace(unsigned int tag, unsigned int module_id,
 	const char *func, const int line, const char *fmt, ...)
 {
-	char str_buffer[STR_BUFFER_MAX_LENGTH];
-	va_list args;
-
 	if ((tag == CAM_TYPE_TRACE) || (debug_type == 1) || (debug_type == 2)) {
-		char trace_buffer[STR_BUFFER_MAX_LENGTH];
+		char str_buf[STR_BUFFER_MAX_LENGTH];
+		size_t len = 0;
+		va_list args;
 
 		va_start(args, fmt);
-
-		vsnprintf(str_buffer, STR_BUFFER_MAX_LENGTH, fmt, args);
-
-		snprintf(trace_buffer, sizeof(trace_buffer),
-			"%s: %s: %s: %d: %s",
-			cam_get_tag_name(tag), cam_get_module_name(module_id),
-			func, line, str_buffer);
-		trace_cam_log_debug(trace_buffer);
-
+		__cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_TRACE,
+			module_id, func, line, true, fmt, args);
+		trace_cam_log_debug(str_buf);
 		va_end(args);
 	}
 }

+ 34 - 0
drivers/cam_utils/cam_debug_util.h

@@ -331,6 +331,40 @@ const char *cam_get_module_name(unsigned int module_id);
 			fmt, ##args);                                         \
 	})
 
+/**
+ * cam_print_to_buffer
+ * @brief:         Function to print to camera logs to a buffer. Don't use directly. Use macros
+ *                 provided below.
+ *
+ * @buf:           Buffer to print into
+ * @buf_size:      Total size of the buffer
+ * @len:           Pointer to variable used to keep track of the length
+ * @tag:           Log level tag to be prefixed
+ * @module_id:     Module id tag to be prefixed
+ * @fmt:           Formatted string which needs to be print in log
+ * @args:          Arguments which needs to be print in log
+ */
+void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag,
+	unsigned int module_id, const char *fmt, ...);
+
+/**
+ * CAM_[ERR/WARN/INFO]_BUF
+ * @brief:         Macro to print a new line into log buffer.
+ *
+ * @module_id:     Module id tag to be prefixed
+ * @buf:           Buffer to print into
+ * @buf_size:      Total size of the buffer
+ * @len:           Pointer to the variable used to keep track of the length
+ * @fmt:           Formatted string which needs to be print in log
+ * @args:          Arguments which needs to be print in log
+ */
+#define CAM_ERR_BUF(module_id, buf, buf_size, len, fmt, args...)                                   \
+	cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_ERR, module_id, fmt, ##args)
+#define CAM_WARN_BUF(module_id, buf, buf_size, len, fmt, args...)                                  \
+	cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_WARN, module_id, fmt, ##args)
+#define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...)                                  \
+	cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args)
+
 /**
  * @brief : API to get camera debug settings
  * @return const struct camera_debug_settings pointer.