Commit ef7af59b authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] s5p-fimc: Conversion to multiplanar formats

Conversion to multiplanar color formats and minor cleanup.
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2dab38e2
......@@ -280,34 +280,16 @@ static int stop_streaming(struct vb2_queue *q)
return fimc_stop_capture(fimc);
}
static unsigned int get_plane_size(struct fimc_frame *frame, unsigned int plane)
static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
{
unsigned long size = 0;
if (!frame || plane > frame->fmt->buff_cnt - 1)
if (!fr || plane >= fr->fmt->memplanes)
return 0;
if (1 == frame->fmt->planes_cnt) {
size = (frame->width * frame->height * frame->fmt->depth) >> 3;
} else if (frame->fmt->planes_cnt <= 3) {
switch (plane) {
case 0:
size = frame->width * frame->height;
break;
case 1:
case 2:
if (S5P_FIMC_YCBCR420 == frame->fmt->color
&& 2 != frame->fmt->planes_cnt)
size = (frame->width * frame->height) >> 2;
else /* 422 */
size = (frame->width * frame->height) >> 1;
break;
}
} else {
size = 0;
}
dbg("%s: w: %d. h: %d. depth[%d]: %d",
__func__, fr->width, fr->height, plane, fr->fmt->depth[plane]);
return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8;
return size;
}
static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
......@@ -315,25 +297,24 @@ static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
void *allocators[])
{
struct fimc_ctx *ctx = vq->drv_priv;
struct fimc_fmt *fmt = fmt = ctx->d_frame.fmt;
struct fimc_frame *frame;
struct fimc_fmt *fmt = ctx->d_frame.fmt;
int i;
if (!fmt)
return -EINVAL;
*num_planes = fmt->buff_cnt;
*num_planes = fmt->memplanes;
dbg("%s, buffer count=%d, plane count=%d",
__func__, *num_buffers, *num_planes);
frame = ctx_get_frame(ctx, vq->type);
if (IS_ERR(frame))
return PTR_ERR(frame);
sizes[0] = get_plane_size(frame, 0);
allocators[0] = ctx->fimc_dev->alloc_ctx;
for (i = 0; i < fmt->memplanes; i++) {
sizes[i] = get_plane_size(&ctx->d_frame, i);
dbg("plane: %u, plane_size: %lu", i, sizes[i]);
allocators[i] = ctx->fimc_dev->alloc_ctx;
}
return -EINVAL;
return 0;
}
static int buffer_init(struct vb2_buffer *vb)
......@@ -347,16 +328,13 @@ static int buffer_prepare(struct vb2_buffer *vb)
struct vb2_queue *vq = vb->vb2_queue;
struct fimc_ctx *ctx = vq->drv_priv;
struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
struct fimc_frame *frame;
unsigned long size;
int i;
frame = ctx_get_frame(ctx, vq->type);
if (IS_ERR(frame))
return PTR_ERR(frame);
if (!ctx->d_frame.fmt || vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
for (i = 0; i < frame->fmt->buff_cnt; i++) {
size = get_plane_size(frame, i);
for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
unsigned long size = get_plane_size(&ctx->d_frame, i);
if (vb2_plane_size(vb, i) < size) {
v4l2_err(v4l2_dev, "User buffer too small (%ld < %ld)\n",
......@@ -451,7 +429,6 @@ static int fimc_capture_close(struct file *file)
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
if (--fimc->vid_cap.refcnt == 0) {
......@@ -519,7 +496,8 @@ static int fimc_vidioc_querycap_capture(struct file *file, void *priv,
strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
cap->bus_info[0] = 0;
cap->version = KERNEL_VERSION(1, 0, 0);
cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE;
cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_VIDEO_CAPTURE_MPLANE;
return 0;
}
......@@ -560,19 +538,20 @@ static int sync_capture_fmt(struct fimc_ctx *ctx)
return 0;
}
static int fimc_cap_s_fmt(struct file *file, void *priv,
struct v4l2_format *f)
static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
struct v4l2_format *f)
{
struct fimc_ctx *ctx = priv;
struct fimc_dev *fimc = ctx->fimc_dev;
struct fimc_frame *frame;
struct v4l2_pix_format *pix;
struct v4l2_pix_format_mplane *pix;
int ret;
int i;
if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
ret = fimc_vidioc_try_fmt(file, priv, f);
ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
if (ret)
return ret;
......@@ -583,10 +562,12 @@ static int fimc_cap_s_fmt(struct file *file, void *priv,
ret = -EBUSY;
goto sf_unlock;
}
if (vb2_is_streaming(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
return -EBUSY;
frame = &ctx->d_frame;
pix = &f->fmt.pix;
pix = &f->fmt.pix_mp;
frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM);
if (!frame->fmt) {
err("fimc target format not found\n");
......@@ -594,14 +575,17 @@ static int fimc_cap_s_fmt(struct file *file, void *priv,
goto sf_unlock;
}
for (i = 0; i < frame->fmt->colplanes; i++)
frame->payload[i] = pix->plane_fmt[i].bytesperline * pix->height;
/* Output DMA frame pixel size and offsets. */
frame->f_width = pix->bytesperline * 8 / frame->fmt->depth;
frame->f_width = pix->plane_fmt[0].bytesperline * 8
/ frame->fmt->depth[0];
frame->f_height = pix->height;
frame->width = pix->width;
frame->height = pix->height;
frame->o_width = pix->width;
frame->o_height = pix->height;
frame->size = (pix->width * pix->height * frame->fmt->depth) >> 3;
frame->offs_h = 0;
frame->offs_v = 0;
......@@ -769,7 +753,7 @@ static int fimc_cap_streamoff(struct file *file, void *priv,
}
static int fimc_cap_reqbufs(struct file *file, void *priv,
struct v4l2_requestbuffers *reqbufs)
struct v4l2_requestbuffers *reqbufs)
{
struct fimc_ctx *ctx = priv;
struct fimc_dev *fimc = ctx->fimc_dev;
......@@ -870,13 +854,13 @@ static int fimc_cap_cropcap(struct file *file, void *fh,
struct fimc_ctx *ctx = fh;
struct fimc_dev *fimc = ctx->fimc_dev;
if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
f = &ctx->s_frame;
cr->bounds.left = 0;
cr->bounds.top = 0;
cr->bounds.width = f->o_width;
......@@ -953,10 +937,10 @@ static int fimc_cap_s_crop(struct file *file, void *fh,
static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
.vidioc_querycap = fimc_vidioc_querycap_capture,
.vidioc_enum_fmt_vid_cap = fimc_vidioc_enum_fmt,
.vidioc_try_fmt_vid_cap = fimc_vidioc_try_fmt,
.vidioc_s_fmt_vid_cap = fimc_cap_s_fmt,
.vidioc_g_fmt_vid_cap = fimc_vidioc_g_fmt,
.vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane,
.vidioc_try_fmt_vid_cap_mplane = fimc_vidioc_try_fmt_mplane,
.vidioc_s_fmt_vid_cap_mplane = fimc_cap_s_fmt_mplane,
.vidioc_g_fmt_vid_cap_mplane = fimc_vidioc_g_fmt_mplane,
.vidioc_reqbufs = fimc_cap_reqbufs,
.vidioc_querybuf = fimc_cap_querybuf,
......@@ -980,6 +964,7 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
.vidioc_g_input = fimc_cap_g_input,
};
/* fimc->lock must be already initialized */
int fimc_register_capture_device(struct fimc_dev *fimc)
{
struct v4l2_device *v4l2_dev = &fimc->vid_cap.v4l2_dev;
......@@ -987,6 +972,7 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
struct fimc_vid_cap *vid_cap;
struct fimc_ctx *ctx;
struct v4l2_format f;
struct fimc_frame *fr;
struct vb2_queue *q;
int ret;
......@@ -999,8 +985,12 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
ctx->out_path = FIMC_DMA;
ctx->state = FIMC_CTX_CAP;
f.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
ctx->d_frame.fmt = find_format(&f, FMT_FLAGS_M2M);
/* Default format of the output frames */
f.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
fr = &ctx->d_frame;
fr->fmt = find_format(&f, FMT_FLAGS_M2M);
fr->width = fr->f_width = fr->o_width = 640;
fr->height = fr->f_height = fr->o_height = 480;
if (!v4l2_dev->name[0])
snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
......@@ -1030,7 +1020,7 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
vid_cap->active_buf_cnt = 0;
vid_cap->reqbufs_count = 0;
vid_cap->refcnt = 0;
/* The default color format for image sensor. */
/* Default color format for image sensor */
vid_cap->fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
INIT_LIST_HEAD(&vid_cap->pending_buf_q);
......@@ -1040,7 +1030,7 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
q = &fimc->vid_cap.vbq;
memset(q, 0, sizeof(*q));
q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
q->io_modes = VB2_MMAP | VB2_USERPTR;
q->drv_priv = fimc->vid_cap.ctx;
q->ops = &fimc_capture_qops;
......
This diff is collapsed.
......@@ -84,7 +84,6 @@ enum fimc_color_fmt {
S5P_FIMC_RGB888,
S5P_FIMC_RGB30_LOCAL,
S5P_FIMC_YCBCR420 = 0x20,
S5P_FIMC_YCBCR422,
S5P_FIMC_YCBYCR422,
S5P_FIMC_YCRYCB422,
S5P_FIMC_CBYCRY422,
......@@ -151,18 +150,18 @@ enum fimc_color_fmt {
* @name: format description
* @fourcc: the fourcc code for this format, 0 if not applicable
* @color: the corresponding fimc_color_fmt
* @depth: driver's private 'number of bits per pixel'
* @buff_cnt: number of physically non-contiguous data planes
* @planes_cnt: number of physically contiguous data planes
* @depth: per plane driver's private 'number of bits per pixel'
* @memplanes: number of physically non-contiguous data planes
* @colplanes: number of physically contiguous data planes
*/
struct fimc_fmt {
enum v4l2_mbus_pixelcode mbus_code;
char *name;
u32 fourcc;
u32 color;
u16 buff_cnt;
u16 planes_cnt;
u16 depth;
u16 memplanes;
u16 colplanes;
u8 depth[VIDEO_MAX_PLANES];
u16 flags;
#define FMT_FLAGS_CAM (1 << 0)
#define FMT_FLAGS_M2M (1 << 1)
......@@ -272,7 +271,7 @@ struct fimc_vid_buffer {
* @height: image pixel weight
* @paddr: image frame buffer physical addresses
* @buf_cnt: number of buffers depending on a color format
* @size: image size in bytes
* @payload: image size in bytes (w x h x bpp)
* @color: color format
* @dma_offset: DMA offset in bytes
*/
......@@ -285,7 +284,7 @@ struct fimc_frame {
u32 offs_v;
u32 width;
u32 height;
u32 size;
unsigned long payload[VIDEO_MAX_PLANES];
struct fimc_addr paddr;
struct fimc_dma_offset dma_offset;
struct fimc_fmt *fmt;
......@@ -479,7 +478,7 @@ struct fimc_ctx {
static inline int tiled_fmt(struct fimc_fmt *fmt)
{
return 0;
return fmt->fourcc == V4L2_PIX_FMT_NV12MT;
}
static inline void fimc_hw_clear_irq(struct fimc_dev *dev)
......@@ -535,12 +534,12 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
{
struct fimc_frame *frame;
if (V4L2_BUF_TYPE_VIDEO_OUTPUT == type) {
if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
if (ctx->state & FIMC_CTX_M2M)
frame = &ctx->s_frame;
else
return ERR_PTR(-EINVAL);
} else if (V4L2_BUF_TYPE_VIDEO_CAPTURE == type) {
} else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
frame = &ctx->d_frame;
} else {
v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
......@@ -582,7 +581,7 @@ void fimc_hw_set_input_path(struct fimc_ctx *ctx);
void fimc_hw_set_output_path(struct fimc_ctx *ctx);
void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr);
void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr,
int index);
int index);
int fimc_hw_set_camera_source(struct fimc_dev *fimc,
struct s3c_fimc_isp_info *cam);
int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f);
......@@ -593,12 +592,12 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
/* -----------------------------------------------------*/
/* fimc-core.c */
int fimc_vidioc_enum_fmt(struct file *file, void *priv,
struct v4l2_fmtdesc *f);
int fimc_vidioc_g_fmt(struct file *file, void *priv,
struct v4l2_format *f);
int fimc_vidioc_try_fmt(struct file *file, void *priv,
struct v4l2_format *f);
int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
struct v4l2_fmtdesc *f);
int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
struct v4l2_format *f);
int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
struct v4l2_format *f);
int fimc_vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *qc);
int fimc_vidioc_g_ctrl(struct file *file, void *priv,
......
......@@ -143,7 +143,7 @@ void fimc_hw_set_target_format(struct fimc_ctx *ctx)
case S5P_FIMC_YCRYCB422:
case S5P_FIMC_CBYCRY422:
case S5P_FIMC_CRYCBY422:
if (frame->fmt->planes_cnt == 1)
if (frame->fmt->colplanes == 1)
cfg |= S5P_CITRGFMT_YCBCR422_1P;
else
cfg |= S5P_CITRGFMT_YCBCR422;
......@@ -219,11 +219,11 @@ void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
S5P_CIOCTRL_YCBCR_PLANE_MASK);
if (frame->fmt->planes_cnt == 1)
if (frame->fmt->colplanes == 1)
cfg |= ctx->out_order_1p;
else if (frame->fmt->planes_cnt == 2)
else if (frame->fmt->colplanes == 2)
cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
else if (frame->fmt->planes_cnt == 3)
else if (frame->fmt->colplanes == 3)
cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
writel(cfg, dev->regs + S5P_CIOCTRL);
......@@ -428,7 +428,7 @@ void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
case S5P_FIMC_YCBCR420:
cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
if (frame->fmt->planes_cnt == 2)
if (frame->fmt->colplanes == 2)
cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
else
cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
......@@ -438,13 +438,13 @@ void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
case S5P_FIMC_YCRYCB422:
case S5P_FIMC_CBYCRY422:
case S5P_FIMC_CRYCBY422:
if (frame->fmt->planes_cnt == 1) {
if (frame->fmt->colplanes == 1) {
cfg |= ctx->in_order_1p
| S5P_MSCTRL_INFORMAT_YCBCR422_1P;
} else {
cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
if (frame->fmt->planes_cnt == 2)
if (frame->fmt->colplanes == 2)
cfg |= ctx->in_order_2p
| S5P_MSCTRL_C_INT_IN_2PLANE;
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment