[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <15e29f722122e44677ad732293ffcc818ea3adde.camel@mediatek.com>
Date: Fri, 1 Aug 2025 05:45:29 +0000
From: CK Hu (胡俊光) <ck.hu@...iatek.com>
To: "robh@...nel.org" <robh@...nel.org>, "mchehab@...nel.org"
<mchehab@...nel.org>, "krzk+dt@...nel.org" <krzk+dt@...nel.org>,
"conor+dt@...nel.org" <conor+dt@...nel.org>, "matthias.bgg@...il.com"
<matthias.bgg@...il.com>, Shangyao Lin (林上堯)
<Shangyao.Lin@...iatek.com>, AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>
CC: "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
"linaro-mm-sig@...ts.linaro.org" <linaro-mm-sig@...ts.linaro.org>,
Project_Global_Chrome_Upstream_Group
<Project_Global_Chrome_Upstream_Group@...iatek.com>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"dri-devel@...ts.freedesktop.org" <dri-devel@...ts.freedesktop.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-mediatek@...ts.infradead.org"
<linux-mediatek@...ts.infradead.org>
Subject: Re: [PATCH v2 10/13] media: platform: mediatek: add isp_7x video ops
On Mon, 2025-07-07 at 09:31 +0800, shangyao lin wrote:
> From: "shangyao.lin" <shangyao.lin@...iatek.com>
>
> Introduce the V4L2 video interface and feature management for the MediaTek
> ISP7.x CAMSYS. These interfaces provide functionalities such as video operation
> initialization and registration. They also manage MediaTek-specific formats and
> handle buffers for MediaTek camera video devices. This enables CAMSYS
> functionalities to be compatible with the V4L2 framework.
>
> Changes in v2:
> - Removed mtk_cam-feature.c and mtk_cam-feature.h, along with related code
> - Various fixes per review comments
>
> Signed-off-by: shangyao.lin <shangyao.lin@...iatek.com>
> ---
[snip]
> +static int mtk_cam_vb2_queue_setup(struct vb2_queue *vq,
> + unsigned int *num_buffers,
> + unsigned int *num_planes,
> + unsigned int sizes[],
> + struct device *alloc_devs[])
> +{
> + struct mtk_cam_device *cam = vb2_get_drv_priv(vq);
> + struct mtk_cam_video_device *node = mtk_cam_vbq_to_vdev(vq);
> + struct mtk_raw_pipeline *raw_pipeline;
> + unsigned int max_buffer_count = node->desc.max_buf_count;
> + const struct v4l2_format *fmt = &node->active_fmt;
> + unsigned int size;
> + int i;
> +
> + /* Check the limitation of buffer size */
> + if (max_buffer_count)
> + *num_buffers = clamp_val(*num_buffers, 1, max_buffer_count);
> +
> + if (node->desc.smem_alloc)
> + vq->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
I think all buffer should be no kernel mapping.
Which buffer you would access in kernel?
> +
> + if (vq->type == V4L2_BUF_TYPE_META_OUTPUT ||
> + vq->type == V4L2_BUF_TYPE_META_CAPTURE)
> + size = fmt->fmt.meta.buffersize;
> + else
> + size = fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
> +
> + /* Add for q.create_bufs with fmt.g_sizeimage(p) / 2 test */
> + if (*num_planes) {
> + if (sizes[0] < size || *num_planes != 1)
> + return -EINVAL;
> + } else {
> + /* Set default as one plane */
> + *num_planes = 1;
> + sizes[0] = size;
> +
> + if (is_raw_subdev(node->uid.pipe_id)) {
> + raw_pipeline =
> + mtk_cam_dev_get_raw_pipeline(cam, node->uid.pipe_id);
> +
> + if (raw_pipeline &&
> + raw_pipeline->user_res.raw_res.feature &&
> + fmt->fmt.pix_mp.num_planes > 1) {
> + *num_planes = fmt->fmt.pix_mp.num_planes;
> + for (i = 0; i < *num_planes; i++)
> + sizes[i] = size;
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
[snip]
> +
> +int is_mtk_format(u32 pixelformat)
Use mtk_cam_get_img_fmt() to replace is_mtk_format().
When mtk_cam_get_img_fmt() return MTK_CAM_IPI_IMG_FMT_UNKNOWN, it's not mtk image format.
> +{
> + switch (pixelformat) {
> + case V4L2_PIX_FMT_YUYV10:
> + case V4L2_PIX_FMT_YVYU10:
> + case V4L2_PIX_FMT_UYVY10:
> + case V4L2_PIX_FMT_VYUY10:
> + case V4L2_PIX_FMT_YUYV12:
> + case V4L2_PIX_FMT_YVYU12:
> + case V4L2_PIX_FMT_UYVY12:
> + case V4L2_PIX_FMT_VYUY12:
> + case V4L2_PIX_FMT_MTISP_YUYV10P:
> + case V4L2_PIX_FMT_MTISP_YVYU10P:
> + case V4L2_PIX_FMT_MTISP_UYVY10P:
> + case V4L2_PIX_FMT_MTISP_VYUY10P:
> + case V4L2_PIX_FMT_MTISP_YUYV12P:
> + case V4L2_PIX_FMT_MTISP_YVYU12P:
> + case V4L2_PIX_FMT_MTISP_UYVY12P:
> + case V4L2_PIX_FMT_MTISP_VYUY12P:
> + case V4L2_PIX_FMT_NV12_10:
> + case V4L2_PIX_FMT_NV21_10:
> + case V4L2_PIX_FMT_NV16_10:
> + case V4L2_PIX_FMT_NV61_10:
> + case V4L2_PIX_FMT_NV12_12:
> + case V4L2_PIX_FMT_NV21_12:
> + case V4L2_PIX_FMT_NV16_12:
> + case V4L2_PIX_FMT_NV61_12:
> + case V4L2_PIX_FMT_MTISP_NV12_10P:
> + case V4L2_PIX_FMT_MTISP_NV21_10P:
> + case V4L2_PIX_FMT_MTISP_NV16_10P:
> + case V4L2_PIX_FMT_MTISP_NV61_10P:
> + case V4L2_PIX_FMT_MTISP_NV12_12P:
> + case V4L2_PIX_FMT_MTISP_NV21_12P:
> + case V4L2_PIX_FMT_MTISP_NV16_12P:
> + case V4L2_PIX_FMT_MTISP_NV61_12P:
> + case V4L2_PIX_FMT_MTISP_NV12_UFBC:
> + case V4L2_PIX_FMT_MTISP_NV21_UFBC:
> + case V4L2_PIX_FMT_MTISP_NV12_10_UFBC:
> + case V4L2_PIX_FMT_MTISP_NV21_10_UFBC:
> + case V4L2_PIX_FMT_MTISP_NV12_12_UFBC:
> + case V4L2_PIX_FMT_MTISP_NV21_12_UFBC:
> + case V4L2_PIX_FMT_MTISP_BAYER8_UFBC:
> + case V4L2_PIX_FMT_MTISP_BAYER10_UFBC:
> + case V4L2_PIX_FMT_MTISP_BAYER12_UFBC:
> + case V4L2_PIX_FMT_MTISP_BAYER14_UFBC:
> + case V4L2_PIX_FMT_MTISP_SGRB8F:
> + case V4L2_PIX_FMT_MTISP_SGRB10F:
> + case V4L2_PIX_FMT_MTISP_SGRB12F:
> + return 1;
> + default:
> + return 0;
> + }
> +}
> +
[snip]
> +const struct mtk_format_info *mtk_format_info(u32 format)
> +{
> + static const struct mtk_format_info formats[] = {
Move this array out of this function.
> + /* YUV planar formats */
> + { .format = V4L2_PIX_FMT_NV12_10,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
mem_planes is always 1. Use 1 to replace mem_planes. Drop mem_planes.
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV21_10,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
bpp[3] is always 0. So shrink array size of bpp[] to 3.
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV16_10,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV61_10,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_YUYV10,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_YVYU10,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_UYVY10,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_VYUY10,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV12_12,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV21_12,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV16_12,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_NV61_12,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_YUYV12,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_YVYU12,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_UYVY12,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_VYUY12,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 2, .bit_r_den = 1 },
> + /* YUV packed formats */
> + { .format = V4L2_PIX_FMT_MTISP_YUYV10P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_YVYU10P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_UYVY10P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_VYUY10P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV12_10P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV21_10P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV16_10P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV61_10P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_YUYV12P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_YVYU12P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_UYVY12P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_VYUY12P,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_NV12_12P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_NV21_12P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_NV16_12P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_NV61_12P,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + /* YUV UFBC formats */
> + { .format = V4L2_PIX_FMT_MTISP_NV12_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_MTISP_NV21_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 2, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_MTISP_NV12_10_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV21_10_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_NV12_12_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_NV21_12_UFBC,
> + .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_BAYER8_UFBC,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 },
> + .hdiv = 1, .vdiv = 1, .bit_r_num = 1, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_MTISP_BAYER10_UFBC,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 },
> + .hdiv = 1, .vdiv = 1, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_BAYER12_UFBC,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 },
> + .hdiv = 1, .vdiv = 1, .bit_r_num = 3, .bit_r_den = 2 },
> + { .format = V4L2_PIX_FMT_MTISP_BAYER14_UFBC,
> + .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 },
> + .hdiv = 1, .vdiv = 1, .bit_r_num = 7, .bit_r_den = 4 },
> + /* Full-G RGB formats */
> + { .format = V4L2_PIX_FMT_MTISP_SGRB8F,
> + .mem_planes = 1, .comp_planes = 3, .bpp = { 1, 1, 1, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 1, .bit_r_den = 1 },
> + { .format = V4L2_PIX_FMT_MTISP_SGRB10F,
> + .mem_planes = 1, .comp_planes = 3, .bpp = { 1, 1, 1, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 5, .bit_r_den = 4 },
> + { .format = V4L2_PIX_FMT_MTISP_SGRB12F,
> + .mem_planes = 1, .comp_planes = 3, .bpp = { 1, 1, 1, 0 },
> + .hdiv = 2, .vdiv = 2, .bit_r_num = 3, .bit_r_den = 2 },
> + };
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(formats); ++i)
> + if (formats[i].format == format)
> + return &formats[i];
> + return NULL;
> +}
> +
[snip]
> +static void mtk_cam_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt,
> + u32 pixelformat, u32 width, u32 height)
> +{
> + struct v4l2_plane_pix_format *plane;
> + unsigned int ipi_fmt = mtk_cam_get_img_fmt(pixelformat);
mtk_cam_fill_pixfmt_mp() is called only by cal_image_pix_mp() and cal_image_pix_mp() already has ipi_fmt.
So pass ipi_fmt as parameter and do not call mtk_cam_get_img_fmt() again.
> + u8 pixel_bits = mtk_cam_get_pixel_bits(ipi_fmt);
> + u32 stride;
> + u32 aligned_width;
> + u8 bus_size;
> + u8 i;
> +
> + pixfmt->width = width;
> + pixfmt->height = height;
> + pixfmt->pixelformat = pixelformat;
> + plane = &pixfmt->plane_fmt[0];
> + bus_size = mtk_cam_yuv_dma_bus_size(pixel_bits, 0);
> + plane->sizeimage = 0;
> +
> + if (is_mtk_format(pixelformat)) {
mtk_cam_fill_pixfmt_mp() is called only by cal_image_pix_mp(), so this checking is always true.
Drop this checking.
> + const struct mtk_format_info *info;
> +
> + info = mtk_format_info(pixelformat);
> + if (!info)
> + return;
> +
> + pixfmt->num_planes = info->mem_planes;
> + if (info->mem_planes == 1) {
mem_planes is always 1. Drop this checking.
> + if (is_yuv_ufo(pixelformat)) {
> + /* UFO format width should align 64 pixel */
> + aligned_width = ALIGN(width, 64);
> + stride = aligned_width * info->bit_r_num / info->bit_r_den;
> +
> + if (stride > plane->bytesperline)
> + plane->bytesperline = stride;
> + plane->sizeimage = stride * height;
> + plane->sizeimage += stride * height / 2;
> + plane->sizeimage += ALIGN((aligned_width / 64), 8) * height;
> + plane->sizeimage += ALIGN((aligned_width / 64), 8) * height / 2;
> + } else if (is_raw_ufo(pixelformat)) {
> + /* UFO format width should align 64 pixel */
> + aligned_width = ALIGN(width, 64);
> + stride = aligned_width * info->bit_r_num / info->bit_r_den;
> +
> + if (stride > plane->bytesperline)
> + plane->bytesperline = stride;
> + plane->sizeimage = stride * height;
> + plane->sizeimage += ALIGN((aligned_width / 64), 8) * height;
> + } else {
> + /* width should be bus_size align */
> + aligned_width = ALIGN(DIV_ROUND_UP(width
> + * info->bit_r_num, info->bit_r_den), bus_size);
> + stride = aligned_width * info->bpp[0];
> +
> + if (stride > plane->bytesperline)
> + plane->bytesperline = stride;
> +
> + for (i = 0; i < info->comp_planes; i++) {
> + unsigned int hdiv = (i == 0) ? 1 : info->hdiv;
> + unsigned int vdiv = (i == 0) ? 1 : info->vdiv;
> +
> + if (plane->bytesperline > stride &&
> + is_fullg_rb(pixelformat)) {
> + plane->sizeimage +=
> + DIV_ROUND_UP(plane->bytesperline, hdiv)
> + * DIV_ROUND_UP(height, vdiv);
> + } else if (plane->bytesperline > stride &&
> + !is_fullg_rb(pixelformat)) {
> + plane->sizeimage +=
> + plane->bytesperline
> + * DIV_ROUND_UP(height, vdiv);
> + } else {
> + plane->sizeimage += info->bpp[i]
> + * DIV_ROUND_UP(aligned_width, hdiv)
> + * DIV_ROUND_UP(height, vdiv);
> + }
> + }
> + }
> + pr_debug("%s stride %d sizeimage %d\n", __func__,
> + plane->bytesperline, plane->sizeimage);
> + } else {
> + pr_debug("do not support non contiguous mplane\n");
> + }
> + } else {
> + const struct v4l2_format_info *info;
> +
> + pr_debug("pixelformat:0x%x sizeimage:%d\n",
> + pixelformat, plane->sizeimage);
> + info = v4l2_format_info(pixelformat);
> + if (!info)
> + return;
> +
> + pixfmt->num_planes = info->mem_planes;
> + if (info->mem_planes == 1) {
> + aligned_width = ALIGN(width, bus_size);
> + stride = aligned_width * info->bpp[0];
> + if (stride > plane->bytesperline)
> + plane->bytesperline = stride;
> +
> + for (i = 0; i < info->comp_planes; i++) {
> + unsigned int hdiv = (i == 0) ? 1 : info->hdiv;
> + unsigned int vdiv = (i == 0) ? 1 : info->vdiv;
> +
> + plane->sizeimage += info->bpp[i]
> + * DIV_ROUND_UP(aligned_width, hdiv)
> + * DIV_ROUND_UP(height, vdiv);
> + }
> + pr_debug("%s stride %d sizeimage %d\n", __func__,
> + plane->bytesperline, plane->sizeimage);
> + } else {
> + pr_warn("do not support non contiguous mplane\n");
> + }
> + }
> +}
> +
[snip]
> +int mtk_cam_video_set_fmt(struct mtk_cam_video_device *node,
> + struct v4l2_format *f, int raw_feature)
> +{
> + struct mtk_cam_device *cam = video_get_drvdata(&node->vdev);
> + const struct v4l2_format *dev_fmt;
> + struct v4l2_format try_fmt;
> + s32 i;
> +
> + dev_dbg(cam->dev,
> + "%s:pipe(%d):%s:feature(0x%x)\n",
> + __func__, node->uid.pipe_id, node->desc.name, raw_feature);
> +
> + memset(&try_fmt, 0, sizeof(try_fmt));
> + try_fmt.type = f->type;
> +
> + /* Validate pixelformat */
> + dev_fmt = mtk_cam_dev_find_fmt(&node->desc, f->fmt.pix_mp.pixelformat);
> + if (!dev_fmt) {
> + dev_dbg(cam->dev, "unknown fmt:%d\n",
> + f->fmt.pix_mp.pixelformat);
> + dev_fmt = &node->desc.fmts[node->desc.default_fmt_idx].vfmt;
> + }
> + try_fmt.fmt.pix_mp.pixelformat = dev_fmt->fmt.pix_mp.pixelformat;
> +
> + /* Validate image width & height range */
> + try_fmt.fmt.pix_mp.width = clamp_val(f->fmt.pix_mp.width,
> + IMG_MIN_WIDTH, IMG_MAX_WIDTH);
> + try_fmt.fmt.pix_mp.height = clamp_val(f->fmt.pix_mp.height,
> + IMG_MIN_HEIGHT, IMG_MAX_HEIGHT);
> + /* 4 bytes alignment for width */
> + /* width and stride should align bus_size */
> + try_fmt.fmt.pix_mp.width = ALIGN(try_fmt.fmt.pix_mp.width, IMG_PIX_ALIGN);
> + try_fmt.fmt.pix_mp.num_planes = 1;
> +
> + for (i = 0 ; i < try_fmt.fmt.pix_mp.num_planes ; i++)
> + try_fmt.fmt.pix_mp.plane_fmt[i].bytesperline =
> + f->fmt.pix_mp.plane_fmt[i].bytesperline;
Why do you assign this?
You would calculate bytesperline in cal_image_pix_mp().
And you compare new cal_image_pix_mp and old cal_image_pix_mp to do something,
but I think it's not necessary.
Just calculate new bytesperline in cal_image_pix_mp() and don't care about old bytesperline.
> +
> + /* bytesperline & sizeimage calculation */
> + cal_image_pix_mp(node->desc.id, &try_fmt.fmt.pix_mp, 0);
> +
> + /* Constant format fields */
> + try_fmt.fmt.pix_mp.colorspace = V4L2_COLORSPACE_SRGB;
> + try_fmt.fmt.pix_mp.field = V4L2_FIELD_NONE;
> + try_fmt.fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
> + try_fmt.fmt.pix_mp.quantization = V4L2_QUANTIZATION_DEFAULT;
> + try_fmt.fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_SRGB;
> +
> + *f = try_fmt;
> +
> + return 0;
> +}
> +
[snip]
> +/**
> + * struct mtk_cam_video_device - MediaTek video device structure.
> + */
> +struct mtk_cam_video_device {
> + struct mtkcam_ipi_uid uid;
> + struct mtk_cam_dev_node_desc desc;
> + unsigned int enabled;
> +
> + struct vb2_queue vb2_q;
> + struct video_device vdev;
> + struct media_pad pad;
> + struct v4l2_format active_fmt;
> + /* use first 4 elements of reserved field of v4l2_pix_format_mplane as request fd */
> + struct v4l2_format pending_fmt;
pending_fmt is useless. Drop it.
> + /* use first elements of reserved field of v4l2_selection as request fd*/
> + struct v4l2_selection active_crop;
> + /* Serializes vb2 queue and video device operations */
> + struct mutex q_lock;
> + int streaming_id;
> +
> + /* cached ctx info */
> + struct mtk_cam_ctx *ctx;
> +};
> +
> +struct mtk_format_info {
> + u32 format;
> + u8 mem_planes;
mem_planes is always 1. Drop it.
Regards,
CK
> + u8 comp_planes;
> + u8 bpp[4];
> + u8 hdiv;
> + u8 vdiv;
> + u8 bit_r_num; /* numerator of bit ratio */
> + u8 bit_r_den; /* denominator of bit ratio */
> +};
> +
Powered by blists - more mailing lists