v4l2: fixed imx219 date error at the first line
authorchanghuang.liang <changhuang.liang@starfivetech.com>
Tue, 26 Jul 2022 12:56:07 +0000 (20:56 +0800)
committerchanghuang.liang <changhuang.liang@starfivetech.com>
Tue, 26 Jul 2022 12:56:07 +0000 (20:56 +0800)
fixed imx219 date error at the first line

Signed-off-by: changhuang.liang <changhuang.liang@starfivetech.com>
drivers/media/platform/starfive/v4l2_driver/stf_csi.c
drivers/media/platform/starfive/v4l2_driver/stf_csi.h
drivers/media/platform/starfive/v4l2_driver/stf_csi_hw_ops.c

index 6fef42a..a07cef3 100644 (file)
@@ -64,17 +64,37 @@ __csi_get_format(struct stf_csi_dev *csi_dev,
        return &csi_dev->fmt[pad];
 }
 
+static u32 code_to_data_type(int code)
+{
+       switch (code) {
+       case MEDIA_BUS_FMT_SRGGB10_1X10:
+       case MEDIA_BUS_FMT_SGRBG10_1X10:
+       case MEDIA_BUS_FMT_SGBRG10_1X10:
+       case MEDIA_BUS_FMT_SBGGR10_1X10:
+               return 0x2b;
+       case MEDIA_BUS_FMT_YUYV8_2X8:
+               return 0x1E;
+       case MEDIA_BUS_FMT_RGB565_2X8_LE:
+               return 0x22;
+       default:
+               return 0x2b;
+       }
+}
+
 static int csi_set_stream(struct v4l2_subdev *sd, int enable)
 {
        struct stf_csi_dev *csi_dev = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt *format;
-       int ret = 0, is_raw10 = 0;
-       u32 code;
+       int ret = 0;
+       u32 code, width, dt;
 
        format = __csi_get_format(csi_dev, NULL, STF_CSI_PAD_SRC,
                                V4L2_SUBDEV_FORMAT_ACTIVE);
        if (format == NULL)
                return -EINVAL;
+
+       width = format->width;
+
        ret = csi_find_format(format->code,
                                csi_dev->formats,
                                csi_dev->nformats);
@@ -82,27 +102,20 @@ static int csi_set_stream(struct v4l2_subdev *sd, int enable)
                return ret;
 
        code = csi_dev->formats[ret].code;
-       if (code == MEDIA_BUS_FMT_SBGGR10_1X10 ||
-               code == MEDIA_BUS_FMT_SGBRG10_1X10 ||
-               code == MEDIA_BUS_FMT_SGRBG10_1X10 ||
-               code == MEDIA_BUS_FMT_SRGGB10_1X10)
-               is_raw10 = 1;
+       dt = code_to_data_type(code);
 
        mutex_lock(&csi_dev->stream_lock);
        if (enable) {
                if (csi_dev->stream_count == 0) {
                        csi_dev->hw_ops->csi_clk_enable(csi_dev);
-                       csi_dev->hw_ops->csi_set_format(csi_dev,
-                                       format->height,
-                                       csi_dev->formats[ret].bpp, is_raw10);
-                       csi_dev->hw_ops->csi_stream_set(csi_dev, enable);
+                       csi_dev->hw_ops->csi_stream_set(csi_dev, enable, dt, width);
                }
                csi_dev->stream_count++;
        } else {
                if (csi_dev->stream_count == 0)
                        goto exit;
                if (csi_dev->stream_count == 1) {
-                       csi_dev->hw_ops->csi_stream_set(csi_dev, enable);
+                       csi_dev->hw_ops->csi_stream_set(csi_dev, enable, dt, width);
                        csi_dev->hw_ops->csi_clk_disable(csi_dev);
                }
                csi_dev->stream_count--;
index 34279a1..a826c4b 100644 (file)
@@ -30,7 +30,7 @@ struct csi_hw_ops {
        int (*csi_clk_disable)(struct stf_csi_dev *csi_dev);
        int (*csi_set_format)(struct stf_csi_dev *csi_dev,
                        u32 vsize, u8 bpp, int is_raw10);
-       int (*csi_stream_set)(struct stf_csi_dev *csi_dev, int on);
+       int (*csi_stream_set)(struct stf_csi_dev *csi_dev, int on, u32 dt, u32 width);
 };
 
 struct stf_csi_dev {
index bbc6d93..3b2cc55 100644 (file)
@@ -28,6 +28,7 @@
 
 #define CSI2RX_STREAM_DATA_CFG_REG(n)          (CSI2RX_STREAM_BASE(n) + 0x008)
 #define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT    BIT(31)
+#define CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 BIT(7)
 #define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)    BIT((n) + 16)
 
 #define CSI2RX_STREAM_CFG_REG(n)               (CSI2RX_STREAM_BASE(n) + 0x00c)
@@ -94,28 +95,6 @@ static int stf_csi_clk_disable(struct stf_csi_dev *csi_dev)
        return 0;
 }
 
-static int stf_csi_set_format(struct stf_csi_dev *csi_dev,
-                       u32 vsize, u8 bpp, int is_raw10)
-{
-       struct stf_vin_dev *vin = csi_dev->stfcamss->vin;
-
-       switch (csi_dev->s_type) {
-       case SENSOR_VIN:
-               st_err(ST_CSI, "%s, %d: need todo\n", __func__, __LINE__);
-               break;
-       case SENSOR_ISP:
-               if (is_raw10)
-                       reg_set_bit(vin->sysctrl_base,  SYSCONSAIF_SYSCFG_36,
-                               BIT(12),
-                               1 << 12);
-               break;
-       default:
-               break;
-       }
-
-       return 0;
-}
-
 static void csi2rx_reset(void *reg_base)
 {
        writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
@@ -126,7 +105,7 @@ static void csi2rx_reset(void *reg_base)
        writel(0, reg_base + CSI2RX_SOFT_RESET_REG);
 }
 
-static int csi2rx_start(struct stf_csi_dev *csi_dev, void *reg_base)
+static int csi2rx_start(struct stf_csi_dev *csi_dev, void *reg_base, u32 dt)
 {
        struct stfcamss *stfcamss = csi_dev->stfcamss;
        struct csi2phy_cfg *csiphy =
@@ -198,7 +177,8 @@ static int csi2rx_start(struct stf_csi_dev *csi_dev, void *reg_base)
                       reg_base + CSI2RX_STREAM_CFG_REG(i));
 
                writel(CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT |
-                      CSI2RX_STREAM_DATA_CFG_VC_SELECT(i),
+                      CSI2RX_STREAM_DATA_CFG_VC_SELECT(i) |
+                      CSI2RX_STREAM_DATA_CFG_EN_DATA_TYPE_0 | dt,
                       reg_base + CSI2RX_STREAM_DATA_CFG_REG(i));
 
                writel(CSI2RX_STREAM_CTRL_START,
@@ -216,7 +196,8 @@ static void csi2rx_stop(struct stf_csi_dev *csi_dev, void *reg_base)
                writel(0, reg_base + CSI2RX_STREAM_CTRL_REG(i));
 }
 
-static int stf_csi_stream_set(struct stf_csi_dev *csi_dev, int on)
+static int stf_csi_stream_set(struct stf_csi_dev *csi_dev,
+                                       int on, u32 dt, u32 width)
 {
        struct stfcamss *stfcamss = csi_dev->stfcamss;
        struct stf_vin_dev *vin = csi_dev->stfcamss->vin;
@@ -238,7 +219,7 @@ static int stf_csi_stream_set(struct stf_csi_dev *csi_dev, int on)
                        0<<15);         //u0_vin_cnfg_axiwr0_pixel_high_bit_sel
                reg_set_bit(vin->sysctrl_base, SYSCONSAIF_SYSCFG_28,
                        BIT(12)|BIT(11)|BIT(10)|BIT(9)|BIT(8)|BIT(7)|BIT(6)|BIT(5)|BIT(4)|BIT(3)|BIT(2),
-                       (1920 / 4 - 1)<<2);     //u0_vin_cnfg_axiwr0_pix_cnt_end
+                       (width / 4 - 1)<<2);    //u0_vin_cnfg_axiwr0_pix_cnt_end
                break;
        case SENSOR_ISP:
                clk_set_parent(stfcamss->sys_clk[STFCLK_WRAPPER_CLK_C].clk,
@@ -256,13 +237,18 @@ static int stf_csi_stream_set(struct stf_csi_dev *csi_dev, int on)
                reg_set_bit(vin->sysctrl_base,  SYSCONSAIF_SYSCFG_36,
                        BIT(16)|BIT(15)|BIT(14)|BIT(13),
                        0<<13);         //u0_vin_cnfg_pix_num
+
+               if (dt == 0x2b)
+                       reg_set_bit(vin->sysctrl_base,  SYSCONSAIF_SYSCFG_36,
+                               BIT(12),
+                               1 << 12);
                break;
        default:
                break;
        }
 
        if (on)
-               csi2rx_start(csi_dev, reg_base);
+               csi2rx_start(csi_dev, reg_base, dt);
        else
                csi2rx_stop(csi_dev, reg_base);
 
@@ -287,6 +273,5 @@ struct csi_hw_ops csi_ops = {
        .csi_power_on          = stf_csi_power_on,
        .csi_clk_enable        = stf_csi_clk_enable,
        .csi_clk_disable       = stf_csi_clk_disable,
-       .csi_set_format        = stf_csi_set_format,
        .csi_stream_set        = stf_csi_stream_set,
 };