From 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 13 May 2024 10:30:14 +0000
Subject: [PATCH] modify sin led gpio
---
kernel/drivers/video/rockchip/vehicle/vehicle_cif.c | 190 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 153 insertions(+), 37 deletions(-)
diff --git a/kernel/drivers/video/rockchip/vehicle/vehicle_cif.c b/kernel/drivers/video/rockchip/vehicle/vehicle_cif.c
index 7d2e08e..96c2bfb 100644
--- a/kernel/drivers/video/rockchip/vehicle/vehicle_cif.c
+++ b/kernel/drivers/video/rockchip/vehicle/vehicle_cif.c
@@ -37,7 +37,6 @@
#include <media/v4l2-mediabus.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>
-#include <dt-bindings/soc/rockchip-system-status.h>
#include <soc/rockchip/rockchip-system-status.h>
#include <linux/phy/phy.h>
#include <linux/uaccess.h>
@@ -2266,6 +2265,31 @@
return index;
}
+static enum cif_reg_index get_reg_index_of_frm_num(int channel_id)
+{
+ enum cif_reg_index index;
+
+ switch (channel_id) {
+ case 0:
+ index = CIF_REG_MIPI_FRAME_NUM_VC0;
+ break;
+ case 1:
+ index = CIF_REG_MIPI_FRAME_NUM_VC1;
+ break;
+ case 2:
+ index = CIF_REG_MIPI_FRAME_NUM_VC2;
+ break;
+ case 3:
+ index = CIF_REG_MIPI_FRAME_NUM_VC3;
+ break;
+ default:
+ index = CIF_REG_MIPI_FRAME_NUM_VC0;
+ break;
+ }
+
+ return index;
+}
+
static enum cif_reg_index get_reg_index_of_frm1_y_addr(int channel_id)
{
enum cif_reg_index index;
@@ -2758,14 +2782,14 @@
VEHICLE_DG("%s, LINE=%d, channel->fmt_val = 0x%x", __func__, __LINE__, channel->fmt_val);
if (cfg->input_format == CIF_INPUT_FORMAT_PAL ||
cfg->input_format == CIF_INPUT_FORMAT_NTSC) {
- VEHICLE_DG("CVBS IN PAL or NTSC config.");
+ VEHICLE_INFO("CVBS IN PAL or NTSC config.");
channel->virtual_width *= 2;
cif->interlaced_enable = true;
cif->interlaced_offset = channel->width;
cif->interlaced_counts = 0;
cif->interlaced_buffer = 0;
channel->height /= 2;
- VEHICLE_DG("do denterlaced.\n");
+ VEHICLE_INFO("do denterlaced.\n");
}
channel->data_type = get_data_type(cfg->mbus_code,
@@ -3930,7 +3954,7 @@
static unsigned long temp_y_addr, temp_uv_addr;
int commit_buf = 0;
struct vehicle_rkcif_dummy_buffer *dummy_buf = &cif->dummy_buf;
-
+ u32 frm_num_reg, frame_id = 0;
VEHICLE_DG("@%s, enter, mipi_id(%d)\n", __func__, mipi_id);
if ((frame_ready > 1) || (cif->cif_cfg.buf_num < 2) ||
@@ -3946,6 +3970,10 @@
frm0_addr_uv = get_reg_index_of_frm0_uv_addr(mipi_id);
frm1_addr_y = get_reg_index_of_frm1_y_addr(mipi_id);
frm1_addr_uv = get_reg_index_of_frm1_uv_addr(mipi_id);
+ frm_num_reg = get_reg_index_of_frm_num(mipi_id);
+ frame_id = rkcif_read_reg(cif, frm_num_reg);
+ VEHICLE_DG("@%s, frm_num_reg(0x%x), frame_id:0x%x\n", __func__,
+ frm_num_reg, frame_id);
} else {
frm0_addr_y = get_dvp_reg_index_of_frm0_y_addr(mipi_id);
frm0_addr_uv = get_dvp_reg_index_of_frm0_uv_addr(mipi_id);
@@ -3979,10 +4007,11 @@
uv_addr = temp_uv_addr;
commit_buf = 0;
} else {
- if ((cif->interlaced_counts % 2) == 0) {
+ if ((frame_id != 0 && (frame_id & 0xffff) % 2 == 0) ||
+ (frame_id == 0 && (cif->interlaced_counts % 2 == 0))) {
temp_y_addr = vehicle_flinger_request_cif_buffer();
if (temp_y_addr == 0) {
- VEHICLE_INFO("%s,warnning request buffer failed\n", __func__);
+ VEHICLE_DGERR("%s,warnning request buffer failed\n", __func__);
spin_unlock(&cif->vbq_lock);
return -1;
}
@@ -3995,6 +4024,11 @@
//uv_addr = temp_uv_addr;
uv_addr = temp_uv_addr + cif->interlaced_offset;
commit_buf = 0; //even & odd field add
+ if (temp_y_addr == 0) {
+ VEHICLE_DGERR("%s,warnning temp_y_addr is NULL!\n", __func__);
+ spin_unlock(&cif->vbq_lock);
+ return -1;
+ }
}
WARN_ON(y_addr == cif->interlaced_offset);
WARN_ON(uv_addr == cif->interlaced_offset);
@@ -4453,6 +4487,37 @@
return IRQ_HANDLED;
}
+#define vehicle_csi2_err_strncat(dst_str, src_str) {\
+ if (strlen(dst_str) + strlen(src_str) < CSI_ERRSTR_LEN)\
+ strncat(dst_str, src_str, strlen(src_str)); }
+
+static void vehicle_csi2_find_err_vc(int val, char *vc_info)
+{
+ int i;
+ char cur_str[CSI_VCINFO_LEN] = {0};
+
+ memset(vc_info, 0, sizeof(*vc_info));
+ for (i = 0; i < 4; i++) {
+ if ((val >> i) & 0x1) {
+ snprintf(cur_str, CSI_VCINFO_LEN, " %d", i);
+ if (strlen(vc_info) + strlen(cur_str) < CSI_VCINFO_LEN)
+ strncat(vc_info, cur_str, strlen(cur_str));
+ }
+ }
+}
+
+static void vehicle_csi2_err_print_work(struct work_struct *work)
+{
+ struct vehicle_csi2_err_state_work *err_state = container_of(work,
+ struct vehicle_csi2_err_state_work,
+ work);
+
+ pr_err("mipi_csi2: ERR%d:0x%x %s\n", err_state->err_num,
+ err_state->err_val, err_state->err_str);
+ if (err_state->err_num == 1)
+ pr_info("mipi_csi2: err_stat:0x%x\n", err_state->err_stat);
+}
+
static irqreturn_t vehicle_csirx_irq1(int irq, void *data)
{
struct vehicle_cif *cif = (struct vehicle_cif *)data;
@@ -4460,6 +4525,9 @@
struct csi2_err_stats *err_list = NULL;
unsigned long err_stat = 0;
u32 val;
+ char err_str[CSI_ERRSTR_LEN] = {0};
+ char cur_str[CSI_ERRSTR_LEN] = {0};
+ char vc_info[CSI_VCINFO_LEN] = {0};
val = read_reg(hw->csi2_base, CSIHOST_ERR1);
if (val) {
@@ -4469,53 +4537,69 @@
if (val & CSIHOST_ERR1_PHYERR_SPTSYNCHS) {
err_list = &hw->err_list[RK_CSI2_ERR_SOTSYN];
err_list->cnt++;
- VEHICLE_DGERR(
- "ERR1: start of transmission error, reg: 0x%x,cnt:%d\n",
- val, err_list->cnt);
+
+ vehicle_csi2_find_err_vc(val & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(sot sync,lane:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
}
if (val & CSIHOST_ERR1_ERR_BNDRY_MATCH) {
err_list = &hw->err_list[RK_CSI2_ERR_FS_FE_MIS];
err_list->cnt++;
- VEHICLE_DGERR(
- "ERR1: error matching frame start with frame end, reg: 0x%x,cnt:%d\n",
- val, err_list->cnt);
+ vehicle_csi2_find_err_vc((val >> 4) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(fs/fe miss,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+
}
if (val & CSIHOST_ERR1_ERR_SEQ) {
err_list = &hw->err_list[RK_CSI2_ERR_FRM_SEQ_ERR];
err_list->cnt++;
- VEHICLE_DGERR("ERR1: incorrect frame sequence detected, reg: 0x%x,cnt:%d\n",
- val, err_list->cnt);
+ vehicle_csi2_find_err_vc((val >> 8) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(f_seq,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+
}
if (val & CSIHOST_ERR1_ERR_FRM_DATA) {
err_list = &hw->err_list[RK_CSI2_ERR_CRC_ONCE];
err_list->cnt++;
- VEHICLE_DGERR("ERR1: at least one crc error, reg: 0x%x\n,cnt:%d",
- val, err_list->cnt);
+ vehicle_csi2_find_err_vc((val >> 12) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err_data,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+
}
if (val & CSIHOST_ERR1_ERR_CRC) {
err_list = &hw->err_list[RK_CSI2_ERR_CRC];
err_list->cnt++;
- VEHICLE_DGERR("ERR1: crc errors, reg: 0x%x, cnt:%d\n",
- val, err_list->cnt);
+ vehicle_csi2_find_err_vc((val >> 24) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(crc,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+
}
if (val & CSIHOST_ERR1_ERR_ECC2) {
err_list = &hw->err_list[RK_CSI2_ERR_CRC];
err_list->cnt++;
- VEHICLE_DGERR("ERR1: ecc errors, reg: 0x%x, cnt:%d\n",
- val, err_list->cnt);
- }
- if (val & CSIHOST_ERR1_ERR_CTRL)
- VEHICLE_DGERR("ERR1: ctrl errors, reg: 0x%x\n", val);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc2) ");
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ if (val & CSIHOST_ERR1_ERR_CTRL) {
+ vehicle_csi2_find_err_vc((val >> 16) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ctrl,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
hw->err_list[RK_CSI2_ERR_ALL].cnt++;
err_stat = ((hw->err_list[RK_CSI2_ERR_FS_FE_MIS].cnt & 0xff) << 8) |
((hw->err_list[RK_CSI2_ERR_ALL].cnt) & 0xff);
- VEHICLE_INFO("%s: err_stat: %x\n", err_stat);
+
+ cif->err_state.err_val = val;
+ cif->err_state.err_num = 1;
+ cif->err_state.err_stat = err_stat;
+ strscpy(cif->err_state.err_str, err_str, CSI_ERRSTR_LEN);
+ queue_work(cif->err_state.err_print_wq, &cif->err_state.work);
}
@@ -4527,22 +4611,41 @@
struct vehicle_cif *cif = (struct vehicle_cif *)data;
struct csi2_dphy_hw *hw = cif->dphy_hw;
u32 val;
+ char cur_str[CSI_ERRSTR_LEN] = {0};
+ char err_str[CSI_ERRSTR_LEN] = {0};
+ char vc_info[CSI_VCINFO_LEN] = {0};
val = read_reg(hw->csi2_base, CSIHOST_ERR2);
if (val) {
- if (val & CSIHOST_ERR2_PHYERR_ESC)
- VEHICLE_DGERR("ERR2: escape entry error(ULPM), reg: 0x%x\n", val);
- if (val & CSIHOST_ERR2_PHYERR_SOTHS)
- VEHICLE_DGERR(
- "ERR2: start of transmission error, reg: 0x%x\n", val);
- if (val & CSIHOST_ERR2_ECC_CORRECTED)
- VEHICLE_DGERR(
- "ERR2: header error detected and corrected, reg: 0x%x\n", val);
- if (val & CSIHOST_ERR2_ERR_ID)
- VEHICLE_DGERR(
- "ERR2: unrecognized data type detected, reg: 0x%x\n", val);
- if (val & CSIHOST_ERR2_PHYERR_CODEHS)
- VEHICLE_DGERR("ERR2: receive error code, reg: 0x%x\n", val);
+ if (val & CSIHOST_ERR2_PHYERR_ESC) {
+ vehicle_csi2_find_err_vc(val & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ULPM,lane:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ if (val & CSIHOST_ERR2_PHYERR_SOTHS) {
+ vehicle_csi2_find_err_vc((val >> 4) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(sot,lane:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ if (val & CSIHOST_ERR2_ECC_CORRECTED) {
+ vehicle_csi2_find_err_vc((val >> 8) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ if (val & CSIHOST_ERR2_ERR_ID) {
+ vehicle_csi2_find_err_vc((val >> 12) & 0xf, vc_info);
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err id,vc:%s) ", vc_info);
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ if (val & CSIHOST_ERR2_PHYERR_CODEHS) {
+ snprintf(cur_str, CSI_ERRSTR_LEN, "(err code) ");
+ vehicle_csi2_err_strncat(err_str, cur_str);
+ }
+ cif->err_state.err_val = val;
+ cif->err_state.err_num = 2;
+ strscpy(cif->err_state.err_str, err_str, CSI_ERRSTR_LEN);
+ queue_work(cif->err_state.err_print_wq, &cif->err_state.work);
+
}
return IRQ_HANDLED;
@@ -4661,6 +4764,7 @@
cif->stopping = true;
cancel_delayed_work_sync(&(cif->work));
flush_delayed_work(&(cif->work));
+ cancel_work_sync(&cif->err_state.work);
ret = wait_event_timeout(cif->wq_stopped,
cif->state != RKCIF_STATE_STREAMING,
@@ -5118,6 +5222,7 @@
if (inf_id == RKCIF_MIPI_LVDS) {
/* 5. set csi2-mipi-dphy reg */
if (cif->dphy_hw->chip_id == CHIP_ID_RK3588 ||
+ cif->dphy_hw->chip_id == CHIP_ID_RK3568 ||
cif->dphy_hw->chip_id == CHIP_ID_RK3562)
cif->dphy_hw->csi2_dphy_base = cif->csi2_dphy_base;
@@ -5140,6 +5245,13 @@
init_waitqueue_head(&cif->wq_stopped);
spin_lock_init(&cif->vbq_lock);
+
+ INIT_WORK(&cif->err_state.work, vehicle_csi2_err_print_work);
+ cif->err_state.err_print_wq = create_workqueue("cis2_err_print_queue");
+ if (cif->err_state.err_print_wq == NULL) {
+ dev_err(dev, "%s: %s create failed.\n", __func__,
+ "csi2_err_print_wq");
+ }
return 0;
}
@@ -5211,6 +5323,10 @@
free_irq(cif->csi2_irq1, cif);
free_irq(cif->csi2_irq2, cif);
}
+ if (cif->err_state.err_print_wq) {
+ flush_workqueue(cif->err_state.err_print_wq);
+ destroy_workqueue(cif->err_state.err_print_wq);
+ }
return 0;
}
--
Gitblit v1.6.2