media: camss: vfe: Format conversion support using PIX interface

Use VFE PIX input interface and do format conversion in VFE.

Supported input format is UYVY (single plane YUV 4:2:2) and
its different sample order variations.

Supported output formats are:
- NV12/NV21 (two plane YUV 4:2:0)
- NV16/NV61 (two plane YUV 4:2:2)

Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
Todor Tomov 2017-08-08 09:30:09 -04:00 коммит произвёл Mauro Carvalho Chehab
Родитель f5c074947f
Коммит 9b5833f7b8
5 изменённых файлов: 883 добавлений и 161 удалений

Просмотреть файл

@ -1003,6 +1003,8 @@ static enum ispif_intf ispif_get_intf(enum vfe_line_id line_id)
return RDI1; return RDI1;
case (VFE_LINE_RDI2): case (VFE_LINE_RDI2):
return RDI2; return RDI2;
case (VFE_LINE_PIX):
return PIX0;
default: default:
return RDI0; return RDI0;
} }

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -30,8 +30,9 @@
#define MSM_VFE_PAD_SRC 1 #define MSM_VFE_PAD_SRC 1
#define MSM_VFE_PADS_NUM 2 #define MSM_VFE_PADS_NUM 2
#define MSM_VFE_LINE_NUM 3 #define MSM_VFE_LINE_NUM 4
#define MSM_VFE_IMAGE_MASTERS_NUM 7 #define MSM_VFE_IMAGE_MASTERS_NUM 7
#define MSM_VFE_COMPOSITE_IRQ_NUM 4
#define MSM_VFE_VFE0_UB_SIZE 1023 #define MSM_VFE_VFE0_UB_SIZE 1023
#define MSM_VFE_VFE0_UB_SIZE_RDI (MSM_VFE_VFE0_UB_SIZE / 3) #define MSM_VFE_VFE0_UB_SIZE_RDI (MSM_VFE_VFE0_UB_SIZE / 3)
@ -51,11 +52,13 @@ enum vfe_line_id {
VFE_LINE_NONE = -1, VFE_LINE_NONE = -1,
VFE_LINE_RDI0 = 0, VFE_LINE_RDI0 = 0,
VFE_LINE_RDI1 = 1, VFE_LINE_RDI1 = 1,
VFE_LINE_RDI2 = 2 VFE_LINE_RDI2 = 2,
VFE_LINE_PIX = 3
}; };
struct vfe_output { struct vfe_output {
u8 wm_idx; u8 wm_num;
u8 wm_idx[3];
int active_buf; int active_buf;
struct camss_buffer *buf[2]; struct camss_buffer *buf[2];
@ -66,6 +69,10 @@ struct vfe_output {
enum vfe_output_state state; enum vfe_output_state state;
unsigned int sequence; unsigned int sequence;
int wait_sof;
int wait_reg_update;
struct completion sof;
struct completion reg_update;
}; };
struct vfe_line { struct vfe_line {

Просмотреть файл

@ -27,71 +27,154 @@
#include "camss-video.h" #include "camss-video.h"
#include "camss.h" #include "camss.h"
struct fract {
u8 numerator;
u8 denominator;
};
/* /*
* struct camss_format_info - ISP media bus format information * struct camss_format_info - ISP media bus format information
* @code: V4L2 media bus format code * @code: V4L2 media bus format code
* @pixelformat: V4L2 pixel format FCC identifier * @pixelformat: V4L2 pixel format FCC identifier
* @bpp: Bits per pixel when stored in memory * @planes: Number of planes
* @hsub: Horizontal subsampling (for each plane)
* @vsub: Vertical subsampling (for each plane)
* @bpp: Bits per pixel when stored in memory (for each plane)
*/ */
static const struct camss_format_info { struct camss_format_info {
u32 code; u32 code;
u32 pixelformat; u32 pixelformat;
unsigned int bpp; u8 planes;
} formats[] = { struct fract hsub[3];
{ MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 16 }, struct fract vsub[3];
{ MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 16 }, unsigned int bpp[3];
{ MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 16 }, };
{ MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 16 },
{ MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 8 }, static const struct camss_format_info formats_rdi[] = {
{ MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 8 }, { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 1,
{ MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 8 }, { { 1, 1 } }, { { 1, 1 } }, { 16 } },
{ MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 8 }, { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 1,
{ MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 10 }, { { 1, 1 } }, { { 1, 1 } }, { 16 } },
{ MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 10 }, { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 1,
{ MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 10 }, { { 1, 1 } }, { { 1, 1 } }, { 16 } },
{ MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 10 }, { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 1,
{ MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 12 }, { { 1, 1 } }, { { 1, 1 } }, { 16 } },
{ MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 12 }, { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 1,
{ MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 12 }, { { 1, 1 } }, { { 1, 1 } }, { 8 } },
{ MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 12 } { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 8 } },
{ MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 8 } },
{ MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 8 } },
{ MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 10 } },
{ MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 10 } },
{ MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 10 } },
{ MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 10 } },
{ MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 12 } },
{ MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 12 } },
{ MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 12 } },
{ MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 1,
{ { 1, 1 } }, { { 1, 1 } }, { 12 } },
};
static const struct camss_format_info formats_pix[] = {
{ MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV12, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV12, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV12, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_YUYV8_1_5X8, V4L2_PIX_FMT_NV21, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_YVYU8_1_5X8, V4L2_PIX_FMT_NV21, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_UYVY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_VYUY8_1_5X8, V4L2_PIX_FMT_NV21, 1,
{ { 1, 1 } }, { { 2, 3 } }, { 8 } },
{ MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV16, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV16, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV16, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV16, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_NV61, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_NV61, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_NV61, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
{ MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_NV61, 1,
{ { 1, 1 } }, { { 1, 2 } }, { 8 } },
}; };
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Helper functions * Helper functions
*/ */
static int video_find_format(u32 code, u32 pixelformat,
const struct camss_format_info *formats,
unsigned int nformats)
{
int i;
for (i = 0; i < nformats; i++) {
if (formats[i].code == code &&
formats[i].pixelformat == pixelformat)
return i;
}
for (i = 0; i < nformats; i++)
if (formats[i].code == code)
return i;
WARN_ON(1);
return -EINVAL;
}
/* /*
* video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane
* @mbus: v4l2_mbus_framefmt format (input) * @mbus: v4l2_mbus_framefmt format (input)
* @pix: v4l2_pix_format_mplane format (output) * @pix: v4l2_pix_format_mplane format (output)
* @f: a pointer to formats array element to be used for the conversion
* *
* Fill the output pix structure with information from the input mbus format. * Fill the output pix structure with information from the input mbus format.
* *
* Return 0 on success or a negative error code otherwise * Return 0 on success or a negative error code otherwise
*/ */
static unsigned int video_mbus_to_pix_mp(const struct v4l2_mbus_framefmt *mbus, static int video_mbus_to_pix_mp(const struct v4l2_mbus_framefmt *mbus,
struct v4l2_pix_format_mplane *pix) struct v4l2_pix_format_mplane *pix,
const struct camss_format_info *f)
{ {
unsigned int i; unsigned int i;
u32 bytesperline; u32 bytesperline;
memset(pix, 0, sizeof(*pix)); memset(pix, 0, sizeof(*pix));
v4l2_fill_pix_format_mplane(pix, mbus); v4l2_fill_pix_format_mplane(pix, mbus);
pix->pixelformat = f->pixelformat;
for (i = 0; i < ARRAY_SIZE(formats); ++i) { pix->num_planes = f->planes;
if (formats[i].code == mbus->code) for (i = 0; i < pix->num_planes; i++) {
break; bytesperline = pix->width / f->hsub[i].numerator *
} f->hsub[i].denominator * f->bpp[i] / 8;
if (WARN_ON(i == ARRAY_SIZE(formats)))
return -EINVAL;
pix->pixelformat = formats[i].pixelformat;
pix->num_planes = 1;
bytesperline = pix->width * formats[i].bpp / 8;
bytesperline = ALIGN(bytesperline, 8); bytesperline = ALIGN(bytesperline, 8);
pix->plane_fmt[0].bytesperline = bytesperline; pix->plane_fmt[i].bytesperline = bytesperline;
pix->plane_fmt[0].sizeimage = bytesperline * pix->height; pix->plane_fmt[i].sizeimage = pix->height /
f->vsub[i].numerator * f->vsub[i].denominator *
bytesperline;
}
return 0; return 0;
} }
@ -131,8 +214,16 @@ static int video_get_subdev_format(struct camss_video *video,
if (ret) if (ret)
return ret; return ret;
ret = video_find_format(fmt.format.code,
format->fmt.pix_mp.pixelformat,
video->formats, video->nformats);
if (ret < 0)
return ret;
format->type = video->type; format->type = video->type;
return video_mbus_to_pix_mp(&fmt.format, &format->fmt.pix_mp);
return video_mbus_to_pix_mp(&fmt.format, &format->fmt.pix_mp,
&video->formats[ret]);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -144,20 +235,55 @@ static int video_queue_setup(struct vb2_queue *q,
unsigned int sizes[], struct device *alloc_devs[]) unsigned int sizes[], struct device *alloc_devs[])
{ {
struct camss_video *video = vb2_get_drv_priv(q); struct camss_video *video = vb2_get_drv_priv(q);
const struct v4l2_pix_format_mplane *format =
&video->active_fmt.fmt.pix_mp;
unsigned int i;
if (*num_planes) { if (*num_planes) {
if (*num_planes != 1) if (*num_planes != format->num_planes)
return -EINVAL; return -EINVAL;
if (sizes[0] < video->active_fmt.fmt.pix_mp.plane_fmt[0].sizeimage) for (i = 0; i < *num_planes; i++)
if (sizes[i] < format->plane_fmt[i].sizeimage)
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
*num_planes = 1; *num_planes = format->num_planes;
sizes[0] = video->active_fmt.fmt.pix_mp.plane_fmt[0].sizeimage; for (i = 0; i < *num_planes; i++)
sizes[i] = format->plane_fmt[i].sizeimage;
return 0;
}
static int video_buf_init(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue);
struct camss_buffer *buffer = container_of(vbuf, struct camss_buffer,
vb);
const struct v4l2_pix_format_mplane *format =
&video->active_fmt.fmt.pix_mp;
struct sg_table *sgt;
unsigned int i;
for (i = 0; i < format->num_planes; i++) {
sgt = vb2_dma_sg_plane_desc(vb, i);
if (!sgt)
return -EFAULT;
buffer->addr[i] = sg_dma_address(sgt->sgl);
}
if (format->pixelformat == V4L2_PIX_FMT_NV12 ||
format->pixelformat == V4L2_PIX_FMT_NV21 ||
format->pixelformat == V4L2_PIX_FMT_NV16 ||
format->pixelformat == V4L2_PIX_FMT_NV61)
buffer->addr[1] = buffer->addr[0] +
format->plane_fmt[0].bytesperline *
format->height;
return 0; return 0;
} }
@ -166,22 +292,16 @@ static int video_buf_prepare(struct vb2_buffer *vb)
{ {
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue);
struct camss_buffer *buffer = container_of(vbuf, struct camss_buffer, const struct v4l2_pix_format_mplane *format =
vb); &video->active_fmt.fmt.pix_mp;
struct sg_table *sgt; unsigned int i;
if (video->active_fmt.fmt.pix_mp.plane_fmt[0].sizeimage > for (i = 0; i < format->num_planes; i++) {
vb2_plane_size(vb, 0)) if (format->plane_fmt[i].sizeimage > vb2_plane_size(vb, i))
return -EINVAL; return -EINVAL;
vb2_set_plane_payload(vb, 0, vb2_set_plane_payload(vb, i, format->plane_fmt[i].sizeimage);
video->active_fmt.fmt.pix_mp.plane_fmt[0].sizeimage); }
sgt = vb2_dma_sg_plane_desc(vb, 0);
if (!sgt)
return -EFAULT;
buffer->addr = sg_dma_address(sgt->sgl);
vbuf->field = V4L2_FIELD_NONE; vbuf->field = V4L2_FIELD_NONE;
@ -203,8 +323,10 @@ static int video_check_format(struct camss_video *video)
struct v4l2_pix_format_mplane *pix = &video->active_fmt.fmt.pix_mp; struct v4l2_pix_format_mplane *pix = &video->active_fmt.fmt.pix_mp;
struct v4l2_format format; struct v4l2_format format;
struct v4l2_pix_format_mplane *sd_pix = &format.fmt.pix_mp; struct v4l2_pix_format_mplane *sd_pix = &format.fmt.pix_mp;
unsigned int i;
int ret; int ret;
sd_pix->pixelformat = pix->pixelformat;
ret = video_get_subdev_format(video, &format); ret = video_get_subdev_format(video, &format);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -213,12 +335,16 @@ static int video_check_format(struct camss_video *video)
pix->height != sd_pix->height || pix->height != sd_pix->height ||
pix->width != sd_pix->width || pix->width != sd_pix->width ||
pix->num_planes != sd_pix->num_planes || pix->num_planes != sd_pix->num_planes ||
pix->num_planes != 1 ||
pix->plane_fmt[0].bytesperline != sd_pix->plane_fmt[0].bytesperline ||
pix->plane_fmt[0].sizeimage != sd_pix->plane_fmt[0].sizeimage ||
pix->field != format.fmt.pix_mp.field) pix->field != format.fmt.pix_mp.field)
return -EPIPE; return -EPIPE;
for (i = 0; i < pix->num_planes; i++)
if (pix->plane_fmt[i].bytesperline !=
sd_pix->plane_fmt[i].bytesperline ||
pix->plane_fmt[i].sizeimage !=
sd_pix->plane_fmt[i].sizeimage)
return -EINVAL;
return 0; return 0;
} }
@ -274,7 +400,6 @@ static void video_stop_streaming(struct vb2_queue *q)
struct media_entity *entity; struct media_entity *entity;
struct media_pad *pad; struct media_pad *pad;
struct v4l2_subdev *subdev; struct v4l2_subdev *subdev;
struct v4l2_subdev *subdev_vfe = NULL;
entity = &vdev->entity; entity = &vdev->entity;
while (1) { while (1) {
@ -289,14 +414,7 @@ static void video_stop_streaming(struct vb2_queue *q)
entity = pad->entity; entity = pad->entity;
subdev = media_entity_to_v4l2_subdev(entity); subdev = media_entity_to_v4l2_subdev(entity);
if (strstr(subdev->name, "vfe")) {
subdev_vfe = subdev;
} else if (strstr(subdev->name, "ispif")) {
v4l2_subdev_call(subdev, video, s_stream, 0); v4l2_subdev_call(subdev, video, s_stream, 0);
v4l2_subdev_call(subdev_vfe, video, s_stream, 0);
} else {
v4l2_subdev_call(subdev, video, s_stream, 0);
}
} }
media_pipeline_stop(&vdev->entity); media_pipeline_stop(&vdev->entity);
@ -308,6 +426,7 @@ static const struct vb2_ops msm_video_vb2_q_ops = {
.queue_setup = video_queue_setup, .queue_setup = video_queue_setup,
.wait_prepare = vb2_ops_wait_prepare, .wait_prepare = vb2_ops_wait_prepare,
.wait_finish = vb2_ops_wait_finish, .wait_finish = vb2_ops_wait_finish,
.buf_init = video_buf_init,
.buf_prepare = video_buf_prepare, .buf_prepare = video_buf_prepare,
.buf_queue = video_buf_queue, .buf_queue = video_buf_queue,
.start_streaming = video_start_streaming, .start_streaming = video_start_streaming,
@ -334,14 +453,34 @@ static int video_querycap(struct file *file, void *fh,
static int video_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) static int video_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
{ {
struct camss_video *video = video_drvdata(file); struct camss_video *video = video_drvdata(file);
int i, j, k;
if (f->type != video->type) if (f->type != video->type)
return -EINVAL; return -EINVAL;
if (f->index >= ARRAY_SIZE(formats)) if (f->index >= video->nformats)
return -EINVAL; return -EINVAL;
f->pixelformat = formats[f->index].pixelformat; /* find index "i" of "k"th unique pixelformat in formats array */
k = -1;
for (i = 0; i < video->nformats; i++) {
for (j = 0; j < i; j++) {
if (video->formats[i].pixelformat ==
video->formats[j].pixelformat)
break;
}
if (j == i)
k++;
if (k == f->index)
break;
}
if (k < f->index)
return -EINVAL;
f->pixelformat = video->formats[i].pixelformat;
return 0; return 0;
} }
@ -358,32 +497,38 @@ static int video_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f) static int __video_try_fmt(struct camss_video *video, struct v4l2_format *f)
{ {
struct v4l2_pix_format_mplane *pix_mp; struct v4l2_pix_format_mplane *pix_mp;
const struct camss_format_info *fi;
u32 width, height; u32 width, height;
u32 bpl; u32 bpl;
int j; int i, j;
pix_mp = &f->fmt.pix_mp; pix_mp = &f->fmt.pix_mp;
for (j = 0; j < ARRAY_SIZE(formats); j++) for (j = 0; j < video->nformats; j++)
if (pix_mp->pixelformat == formats[j].pixelformat) if (pix_mp->pixelformat == video->formats[j].pixelformat)
break; break;
if (j == ARRAY_SIZE(formats)) if (j == video->nformats)
j = 0; /* default format */ j = 0; /* default format */
fi = &video->formats[j];
width = pix_mp->width; width = pix_mp->width;
height = pix_mp->height; height = pix_mp->height;
memset(pix_mp, 0, sizeof(*pix_mp)); memset(pix_mp, 0, sizeof(*pix_mp));
pix_mp->pixelformat = formats[j].pixelformat; pix_mp->pixelformat = fi->pixelformat;
pix_mp->width = clamp_t(u32, width, 1, 8191); pix_mp->width = clamp_t(u32, width, 1, 8191);
pix_mp->height = clamp_t(u32, height, 1, 8191); pix_mp->height = clamp_t(u32, height, 1, 8191);
pix_mp->num_planes = 1; pix_mp->num_planes = fi->planes;
bpl = pix_mp->width * formats[j].bpp / 8; for (i = 0; i < pix_mp->num_planes; i++) {
bpl = pix_mp->width / fi->hsub[i].numerator *
fi->hsub[i].denominator * fi->bpp[i] / 8;
bpl = ALIGN(bpl, 8); bpl = ALIGN(bpl, 8);
pix_mp->plane_fmt[0].bytesperline = bpl; pix_mp->plane_fmt[i].bytesperline = bpl;
pix_mp->plane_fmt[0].sizeimage = bpl * pix_mp->height; pix_mp->plane_fmt[i].sizeimage = pix_mp->height /
fi->vsub[i].numerator * fi->vsub[i].denominator * bpl;
}
pix_mp->field = V4L2_FIELD_NONE; pix_mp->field = V4L2_FIELD_NONE;
pix_mp->colorspace = V4L2_COLORSPACE_SRGB; pix_mp->colorspace = V4L2_COLORSPACE_SRGB;
@ -564,7 +709,7 @@ static int msm_video_init_format(struct camss_video *video)
.fmt.pix_mp = { .fmt.pix_mp = {
.width = 1920, .width = 1920,
.height = 1080, .height = 1080,
.pixelformat = formats[0].pixelformat, .pixelformat = video->formats[0].pixelformat,
}, },
}; };
@ -590,7 +735,7 @@ static int msm_video_init_format(struct camss_video *video)
*/ */
int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev, int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev,
const char *name) const char *name, int is_pix)
{ {
struct media_pad *pad = &video->pad; struct media_pad *pad = &video->pad;
struct video_device *vdev; struct video_device *vdev;
@ -627,6 +772,13 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev,
mutex_init(&video->lock); mutex_init(&video->lock);
video->formats = formats_rdi;
video->nformats = ARRAY_SIZE(formats_rdi);
if (is_pix) {
video->formats = formats_pix;
video->nformats = ARRAY_SIZE(formats_pix);
}
ret = msm_video_init_format(video); ret = msm_video_init_format(video);
if (ret < 0) { if (ret < 0) {
dev_err(v4l2_dev->dev, "Failed to init format: %d\n", ret); dev_err(v4l2_dev->dev, "Failed to init format: %d\n", ret);

Просмотреть файл

@ -29,7 +29,7 @@
struct camss_buffer { struct camss_buffer {
struct vb2_v4l2_buffer vb; struct vb2_v4l2_buffer vb;
dma_addr_t addr; dma_addr_t addr[3];
struct list_head queue; struct list_head queue;
}; };
@ -41,6 +41,8 @@ struct camss_video_ops {
enum vb2_buffer_state state); enum vb2_buffer_state state);
}; };
struct camss_format_info;
struct camss_video { struct camss_video {
struct camss *camss; struct camss *camss;
struct vb2_queue vb2_q; struct vb2_queue vb2_q;
@ -52,12 +54,14 @@ struct camss_video {
const struct camss_video_ops *ops; const struct camss_video_ops *ops;
struct mutex lock; struct mutex lock;
struct mutex q_lock; struct mutex q_lock;
const struct camss_format_info *formats;
unsigned int nformats;
}; };
void msm_video_stop_streaming(struct camss_video *video); void msm_video_stop_streaming(struct camss_video *video);
int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev, int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev,
const char *name); const char *name, int is_pix);
void msm_video_unregister(struct camss_video *video); void msm_video_unregister(struct camss_video *video);