diff --git a/drivers/media/platform/rockchip/isp/capture.c b/drivers/media/platform/rockchip/isp/capture.c index 57ee38b8d352..c030382c46c9 100644 --- a/drivers/media/platform/rockchip/isp/capture.c +++ b/drivers/media/platform/rockchip/isp/capture.c @@ -217,6 +217,7 @@ int hdr_config_dmatx(struct rkisp_device *dev) { struct rkisp_stream *stream; struct v4l2_pix_format_mplane pixm; + u32 memory = 0; if (atomic_inc_return(&dev->hdr.refcnt) > 1 || !dev->active_sensor || @@ -266,6 +267,7 @@ int hdr_config_dmatx(struct rkisp_device *dev) stream->ops->config_mi(stream); if (!dev->dmarx_dev.trigger) { + memory = stream->memory; pixm = stream->out_fmt; stream = &dev->dmarx_dev.stream[RKISP_STREAM_RAWRD2]; rkisp_dmarx_set_fmt(stream, pixm); @@ -274,7 +276,7 @@ int hdr_config_dmatx(struct rkisp_device *dev) } if (dev->hdr.op_mode != HDR_NORMAL && !dev->dmarx_dev.trigger) { - raw_rd_ctrl(dev->base_addr, dev->csi_dev.memory << 2); + raw_rd_ctrl(dev->base_addr, memory << 2); if (pixm.width && pixm.height) rkisp_rawrd_set_pic_size(dev, pixm.width, pixm.height); } @@ -957,7 +959,7 @@ static int rkisp_set_fmt(struct rkisp_stream *stream, if ((dev->isp_ver == ISP_V20 || dev->isp_ver == ISP_V21) && - !dev->csi_dev.memory && + !stream->memory && fmt->fmt_type == FMT_BAYER && stream->id != RKISP_STREAM_MP && stream->id != RKISP_STREAM_SP) @@ -1128,6 +1130,50 @@ static int rkisp_enum_framesizes(struct file *file, void *prov, return 0; } +static long rkisp_ioctl_default(struct file *file, void *fh, + bool valid_prio, unsigned int cmd, void *arg) +{ + struct rkisp_stream *stream = video_drvdata(file); + long ret = 0; + + if (!arg) + return -EINVAL; + + switch (cmd) { + case RKISP_CMD_GET_CSI_MEMORY_MODE: + if (stream->id != RKISP_STREAM_DMATX0 && + stream->id != RKISP_STREAM_DMATX1 && + stream->id != RKISP_STREAM_DMATX2 && + stream->id != RKISP_STREAM_DMATX3) + ret = -EINVAL; + else if (stream->memory == 0) + *(int *)arg = CSI_MEM_COMPACT; + else if (stream->memory == SW_CSI_RAW_WR_SIMG_MODE) + *(int *)arg = CSI_MEM_WORD_BIG_ALIGN; + else + *(int *)arg = CSI_MEM_WORD_LITTLE_ALIGN; + break; + case RKISP_CMD_SET_CSI_MEMORY_MODE: + if (stream->id != RKISP_STREAM_DMATX0 && + stream->id != RKISP_STREAM_DMATX1 && + stream->id != RKISP_STREAM_DMATX2 && + stream->id != RKISP_STREAM_DMATX3) + ret = -EINVAL; + else if (*(int *)arg == CSI_MEM_COMPACT) + stream->memory = 0; + else if (*(int *)arg == CSI_MEM_WORD_BIG_ALIGN) + stream->memory = SW_CSI_RAW_WR_SIMG_MODE; + else + stream->memory = + SW_CSI_RWA_WR_SIMG_SWP | SW_CSI_RAW_WR_SIMG_MODE; + break; + default: + ret = -EINVAL; + } + + return ret; +} + static int rkisp_enum_frameintervals(struct file *file, void *fh, struct v4l2_frmivalenum *fival) { @@ -1362,6 +1408,7 @@ static const struct v4l2_ioctl_ops rkisp_v4l2_ioctl_ops = { .vidioc_querycap = rkisp_querycap, .vidioc_enum_frameintervals = rkisp_enum_frameintervals, .vidioc_enum_framesizes = rkisp_enum_framesizes, + .vidioc_default = rkisp_ioctl_default, }; void rkisp_unregister_stream_vdev(struct rkisp_stream *stream) diff --git a/drivers/media/platform/rockchip/isp/capture.h b/drivers/media/platform/rockchip/isp/capture.h index c1755386e96d..3fe566dcc070 100644 --- a/drivers/media/platform/rockchip/isp/capture.h +++ b/drivers/media/platform/rockchip/isp/capture.h @@ -225,6 +225,7 @@ struct rkisp_stream { unsigned int burst; atomic_t sequence; struct frame_debug_info dbg; + u32 memory; union { struct rkisp_stream_sp sp; struct rkisp_stream_mp mp; diff --git a/drivers/media/platform/rockchip/isp/capture_v20.c b/drivers/media/platform/rockchip/isp/capture_v20.c index 7b5ea2cb9b81..b97774872999 100644 --- a/drivers/media/platform/rockchip/isp/capture_v20.c +++ b/drivers/media/platform/rockchip/isp/capture_v20.c @@ -539,7 +539,7 @@ static int dmatx3_config_mi(struct rkisp_stream *stream) vc = csi->sink[CSI_SRC_CH4 - 1].index; raw_wr_ctrl(stream, SW_CSI_RAW_WR_CH_EN(vc) | - csi->memory | + stream->memory | SW_CSI_RAW_WR_EN_ORG); mi_set_y_size(stream, in_size); mi_frame_end(stream); @@ -583,7 +583,7 @@ static int dmatx2_config_mi(struct rkisp_stream *stream) raw_wr_set_pic_offs(stream, 0); vc = csi->sink[CSI_SRC_CH3 - 1].index; val = SW_CSI_RAW_WR_CH_EN(vc); - val |= csi->memory; + val |= stream->memory; if (dev->hdr.op_mode != HDR_NORMAL) val |= SW_CSI_RAW_WR_EN_ORG; raw_wr_ctrl(stream, val); @@ -627,7 +627,7 @@ static int dmatx1_config_mi(struct rkisp_stream *stream) raw_wr_set_pic_offs(stream, 0); vc = csi->sink[CSI_SRC_CH2 - 1].index; val = SW_CSI_RAW_WR_CH_EN(vc); - val |= csi->memory; + val |= stream->memory; if (dev->hdr.op_mode != HDR_NORMAL) val |= SW_CSI_RAW_WR_EN_ORG; raw_wr_ctrl(stream, val); @@ -675,7 +675,7 @@ static int dmatx0_config_mi(struct rkisp_stream *stream) raw_wr_set_pic_offs(dmatx, 0); vc = csi->sink[CSI_SRC_CH1 - 1].index; val = SW_CSI_RAW_WR_CH_EN(vc); - val |= csi->memory; + val |= stream->memory; if (dev->hdr.op_mode != HDR_NORMAL) val |= SW_CSI_RAW_WR_EN_ORG; raw_wr_ctrl(dmatx, val); diff --git a/drivers/media/platform/rockchip/isp/capture_v21.c b/drivers/media/platform/rockchip/isp/capture_v21.c index c96ec15081fe..b9dc7f7a00de 100644 --- a/drivers/media/platform/rockchip/isp/capture_v21.c +++ b/drivers/media/platform/rockchip/isp/capture_v21.c @@ -503,7 +503,7 @@ static int dmatx3_config_mi(struct rkisp_stream *stream) vc = csi->sink[CSI_SRC_CH4 - 1].index; raw_wr_ctrl(stream, SW_CSI_RAW_WR_CH_EN(vc) | - csi->memory | + stream->memory | SW_CSI_RAW_WR_EN_ORG); stream->u.dmatx.is_config = true; v4l2_dbg(1, rkisp_debug, &dev->v4l2_dev, @@ -548,7 +548,7 @@ static int dmatx2_config_mi(struct rkisp_stream *stream) mi_raw_length(stream); vc = csi->sink[CSI_SRC_CH3 - 1].index; val = SW_CSI_RAW_WR_CH_EN(vc); - val |= csi->memory; + val |= stream->memory; if (dev->hdr.op_mode != HDR_NORMAL) val |= SW_CSI_RAW_WR_EN_ORG; raw_wr_ctrl(stream, val); @@ -591,7 +591,7 @@ static int dmatx0_config_mi(struct rkisp_stream *stream) mi_raw_length(stream); vc = csi->sink[CSI_SRC_CH1 - 1].index; val = SW_CSI_RAW_WR_CH_EN(vc); - val |= csi->memory; + val |= stream->memory; if (dev->hdr.op_mode != HDR_NORMAL) val |= SW_CSI_RAW_WR_EN_ORG; raw_wr_ctrl(stream, val); diff --git a/drivers/media/platform/rockchip/isp/csi.h b/drivers/media/platform/rockchip/isp/csi.h index 1c21cf85cd66..4a8c7020078b 100644 --- a/drivers/media/platform/rockchip/isp/csi.h +++ b/drivers/media/platform/rockchip/isp/csi.h @@ -61,7 +61,6 @@ struct sink_info { * sink: csi link enable flags * mipi_di: Data Identifier (vc[7:6],dt[5:0]) * tx_first: flags for dmatx first Y_STATE irq - * memory: compact or big/little endian byte order for tx/rx */ struct rkisp_csi_device { struct rkisp_device *ispdev; @@ -73,7 +72,6 @@ struct rkisp_csi_device { u32 irq_cnt; u8 mipi_di[CSI_PAD_MAX - 1]; u8 tx_first[HDR_DMA_MAX]; - u8 memory; }; int rkisp_register_csi_subdev(struct rkisp_device *dev, diff --git a/drivers/media/platform/rockchip/isp/dmarx.c b/drivers/media/platform/rockchip/isp/dmarx.c index ee18fe8ce4a6..54564064ea72 100644 --- a/drivers/media/platform/rockchip/isp/dmarx.c +++ b/drivers/media/platform/rockchip/isp/dmarx.c @@ -347,7 +347,7 @@ static int rawrd_config_mi(struct rkisp_stream *stream) val |= CIF_CSI2_DT_RAW12; } rkisp_write(dev, CSI2RX_RAW_RD_CTRL, - dev->csi_dev.memory << 2, false); + stream->memory << 2, false); rkisp_write(dev, CSI2RX_DATA_IDS_1, val, false); rkisp_rawrd_set_pic_size(dev, stream->out_fmt.width, stream->out_fmt.height); @@ -719,7 +719,7 @@ static int rkisp_set_fmt(struct rkisp_stream *stream, if ((stream->ispdev->isp_ver == ISP_V20 || stream->ispdev->isp_ver == ISP_V21) && fmt->fmt_type == FMT_BAYER && - !stream->ispdev->csi_dev.memory && + !stream->memory && stream->id != RKISP_STREAM_DMARX) bytesperline = ALIGN(width * fmt->bpp[i] / 8, 256); else @@ -834,6 +834,45 @@ static int rkisp_querycap(struct file *file, void *priv, return 0; } +static long rkisp_ioctl_default(struct file *file, void *fh, + bool valid_prio, unsigned int cmd, void *arg) +{ + struct rkisp_stream *stream = video_drvdata(file); + long ret = 0; + + switch (cmd) { + case RKISP_CMD_GET_CSI_MEMORY_MODE: + if (stream->id != RKISP_STREAM_RAWRD0 && + stream->id != RKISP_STREAM_RAWRD1 && + stream->id != RKISP_STREAM_RAWRD2) + ret = -EINVAL; + else if (stream->memory == 0) + *(int *)arg = CSI_MEM_COMPACT; + else if (stream->memory == SW_CSI_RAW_WR_SIMG_MODE) + *(int *)arg = CSI_MEM_WORD_BIG_ALIGN; + else + *(int *)arg = CSI_MEM_WORD_LITTLE_ALIGN; + break; + case RKISP_CMD_SET_CSI_MEMORY_MODE: + if (stream->id != RKISP_STREAM_RAWRD0 && + stream->id != RKISP_STREAM_RAWRD1 && + stream->id != RKISP_STREAM_RAWRD2) + ret = -EINVAL; + else if (*(int *)arg == CSI_MEM_COMPACT) + stream->memory = 0; + else if (*(int *)arg == CSI_MEM_WORD_BIG_ALIGN) + stream->memory = SW_CSI_RAW_WR_SIMG_MODE; + else + stream->memory = + SW_CSI_RWA_WR_SIMG_SWP | SW_CSI_RAW_WR_SIMG_MODE; + break; + default: + ret = -EINVAL; + } + + return ret; +} + static const struct v4l2_ioctl_ops rkisp_dmarx_ioctl = { .vidioc_reqbufs = vb2_ioctl_reqbufs, .vidioc_querybuf = vb2_ioctl_querybuf, @@ -849,6 +888,7 @@ static const struct v4l2_ioctl_ops rkisp_dmarx_ioctl = { .vidioc_s_fmt_vid_out_mplane = rkisp_s_fmt_vid_out_mplane, .vidioc_g_fmt_vid_out_mplane = rkisp_g_fmt_vid_out_mplane, .vidioc_querycap = rkisp_querycap, + .vidioc_default = rkisp_ioctl_default, }; static void rkisp_unregister_dmarx_video(struct rkisp_stream *stream) diff --git a/drivers/media/platform/rockchip/isp/rkisp.c b/drivers/media/platform/rockchip/isp/rkisp.c index 089b37b25992..59b92baa9618 100644 --- a/drivers/media/platform/rockchip/isp/rkisp.c +++ b/drivers/media/platform/rockchip/isp/rkisp.c @@ -2465,15 +2465,6 @@ static long rkisp_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) case RKISP_CMD_TRIGGER_READ_BACK: rkisp_rdbk_trigger_event(isp_dev, T_CMD_QUEUE, arg); break; - case RKISP_CMD_CSI_MEMORY_MODE: - if (*((int *)arg) == CSI_MEM_BYTE_BE) - isp_dev->csi_dev.memory = SW_CSI_RWA_WR_SIMG_SWP | - SW_CSI_RAW_WR_SIMG_MODE; - else if (*((int *)arg) == CSI_MEM_BYTE_LE) - isp_dev->csi_dev.memory = SW_CSI_RAW_WR_SIMG_MODE; - else - isp_dev->csi_dev.memory = 0; - break; case RKISP_CMD_GET_SHARED_BUF: if (!IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP)) { ret = -ENOIOCTLCMD; @@ -2563,7 +2554,6 @@ static long rkisp_compat_ioctl32(struct v4l2_subdev *sd, struct rkisp_thunderboot_shmem shmem; struct isp2x_buf_idxfd idxfd; long ret = 0; - int mode; if (!up && cmd != RKISP_CMD_FREE_SHARED_BUF) return -EINVAL; @@ -2574,11 +2564,6 @@ static long rkisp_compat_ioctl32(struct v4l2_subdev *sd, return -EFAULT; ret = rkisp_ioctl(sd, cmd, &trigger); break; - case RKISP_CMD_CSI_MEMORY_MODE: - if (copy_from_user(&mode, up, sizeof(int))) - return -EFAULT; - ret = rkisp_ioctl(sd, cmd, &mode); - break; case RKISP_CMD_GET_SHARED_BUF: if (!IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP)) { ret = -ENOIOCTLCMD; diff --git a/include/uapi/linux/rkisp2-config.h b/include/uapi/linux/rkisp2-config.h index 9932b44e89e1..1e3d3c996481 100644 --- a/include/uapi/linux/rkisp2-config.h +++ b/include/uapi/linux/rkisp2-config.h @@ -12,12 +12,11 @@ #define RKISP_API_VERSION KERNEL_VERSION(1, 6, 2) +/****************ISP SUBDEV IOCTL*****************************/ + #define RKISP_CMD_TRIGGER_READ_BACK \ _IOW('V', BASE_VIDIOC_PRIVATE + 0, struct isp2x_csi_trigger) -#define RKISP_CMD_CSI_MEMORY_MODE \ - _IOW('V', BASE_VIDIOC_PRIVATE + 1, int) - #define RKISP_CMD_GET_SHARED_BUF \ _IOR('V', BASE_VIDIOC_PRIVATE + 2, struct rkisp_thunderboot_resmem) @@ -36,6 +35,16 @@ #define RKISP_CMD_GET_FBCBUF_FD \ _IOR('V', BASE_VIDIOC_PRIVATE + 7, struct isp2x_buf_idxfd) +/****************ISP VIDEO IOCTL******************************/ + +#define RKISP_CMD_GET_CSI_MEMORY_MODE \ + _IOR('V', BASE_VIDIOC_PRIVATE + 100, int) + +#define RKISP_CMD_SET_CSI_MEMORY_MODE \ + _IOW('V', BASE_VIDIOC_PRIVATE + 101, int) + +/*************************************************************/ + #define ISP2X_ID_DPCC (0) #define ISP2X_ID_BLS (1) #define ISP2X_ID_SDG (2) @@ -231,11 +240,25 @@ struct isp2x_csi_trigger { enum isp2x_trigger_mode mode; } __attribute__ ((packed)); -enum isp2x_csi_memory { +/* isp csi dmatx/dmarx memory mode + * 0: raw12/raw10/raw8 8bit memory compact + * 1: raw12/raw10 16bit memory one pixel + * big endian for rv1126/rv1109 + * |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * | 3| 2| 1| 0| -| -| -| -|11|10| 9| 8| 7| 6| 5| 4| + * little align for rk356x + * |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * | -| -| -| -|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * 2: raw12/raw10 16bit memory one pixel + * big align for rv1126/rv1109/rk356x + * |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * |11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| -| -| -| -| + */ +enum isp_csi_memory { CSI_MEM_COMPACT = 0, - CSI_MEM_BYTE_BE, - CSI_MEM_BYTE_LE, - CSI_MEM_MAX, + CSI_MEM_WORD_BIG_END = 1, + CSI_MEM_WORD_LITTLE_ALIGN = 1, + CSI_MEM_WORD_BIG_ALIGN = 2, }; struct isp2x_ispgain_buf {