Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 271785
b: refs/heads/master
c: 4db5e27
h: refs/heads/master
i:
  271783: 7fed342
v: v3
  • Loading branch information
Sylwester Nawrocki authored and Mauro Carvalho Chehab committed Sep 6, 2011
1 parent cf70338 commit ece6370
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 125 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cf52df8acfda9442d64ab4d3d6085877f6d88d46
refs/heads/master: 4db5e27ed9401a635b3c10994f2971c0441e3c90
118 changes: 54 additions & 64 deletions trunk/drivers/media/video/s5p-fimc/fimc-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ static int fimc_init_capture(struct fimc_dev *fimc)
return ret;
}

static void fimc_capture_state_cleanup(struct fimc_dev *fimc)
static int fimc_capture_state_cleanup(struct fimc_dev *fimc)
{
struct fimc_vid_cap *cap = &fimc->vid_cap;
struct fimc_vid_buffer *buf;
unsigned long flags;

spin_lock_irqsave(&fimc->slock, flags);
fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_PEND |
1 << ST_CAPT_SHUT | 1 << ST_CAPT_STREAM);
1 << ST_CAPT_SHUT | 1 << ST_CAPT_STREAM |
1 << ST_CAPT_ISP_STREAM);

fimc->vid_cap.active_buf_cnt = 0;

Expand All @@ -92,6 +93,11 @@ static void fimc_capture_state_cleanup(struct fimc_dev *fimc)
}

spin_unlock_irqrestore(&fimc->slock, flags);

if (test_bit(ST_CAPT_ISP_STREAM, &fimc->state))
return fimc_pipeline_s_stream(fimc, 0);
else
return 0;
}

static int fimc_stop_capture(struct fimc_dev *fimc)
Expand All @@ -111,11 +117,7 @@ static int fimc_stop_capture(struct fimc_dev *fimc)
!test_bit(ST_CAPT_SHUT, &fimc->state),
FIMC_SHUTDOWN_TIMEOUT);

v4l2_subdev_call(cap->sd, video, s_stream, 0);

fimc_capture_state_cleanup(fimc);
dbg("state: 0x%lx", fimc->state);
return 0;
return fimc_capture_state_cleanup(fimc);
}


Expand All @@ -138,9 +140,14 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)

min_bufs = fimc->vid_cap.reqbufs_count > 1 ? 2 : 1;

if (fimc->vid_cap.active_buf_cnt >= min_bufs)
if (vid_cap->active_buf_cnt >= min_bufs &&
!test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
fimc_activate_capture(ctx);

if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
fimc_pipeline_s_stream(fimc, 1);
}

return 0;
error:
fimc_capture_state_cleanup(fimc);
Expand Down Expand Up @@ -202,19 +209,18 @@ static int buffer_prepare(struct vb2_buffer *vb)
struct fimc_ctx *ctx = vq->drv_priv;
int i;

if (!ctx->d_frame.fmt || vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
if (ctx->d_frame.fmt == NULL)
return -EINVAL;

for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
unsigned long size = get_plane_size(&ctx->d_frame, i);
unsigned long size = ctx->d_frame.payload[i];

if (vb2_plane_size(vb, i) < size) {
v4l2_err(ctx->fimc_dev->vid_cap.vfd,
"User buffer too small (%ld < %ld)\n",
vb2_plane_size(vb, i), size);
return -EINVAL;
}

vb2_set_plane_payload(vb, i, size);
}

Expand All @@ -223,10 +229,10 @@ static int buffer_prepare(struct vb2_buffer *vb)

static void buffer_queue(struct vb2_buffer *vb)
{
struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct fimc_dev *fimc = ctx->fimc_dev;
struct fimc_vid_buffer *buf
= container_of(vb, struct fimc_vid_buffer, vb);
struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct fimc_dev *fimc = ctx->fimc_dev;
struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
unsigned long flags;
int min_bufs;
Expand All @@ -252,11 +258,17 @@ static void buffer_queue(struct vb2_buffer *vb)

min_bufs = vid_cap->reqbufs_count > 1 ? 2 : 1;


if (vb2_is_streaming(&vid_cap->vbq) &&
vid_cap->active_buf_cnt >= min_bufs &&
!test_and_set_bit(ST_CAPT_STREAM, &fimc->state))
!test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) {
fimc_activate_capture(ctx);
spin_unlock_irqrestore(&fimc->slock, flags);

if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
fimc_pipeline_s_stream(fimc, 1);
return;
}
spin_unlock_irqrestore(&fimc->slock, flags);
}

Expand Down Expand Up @@ -321,15 +333,21 @@ static int fimc_capture_open(struct file *file)
if (fimc_m2m_active(fimc))
return -EBUSY;

ret = pm_runtime_get_sync(&fimc->pdev->dev);
if (ret < 0) {
v4l2_fh_release(file);
return ret;
}

if (++fimc->vid_cap.refcnt == 1)
pm_runtime_get_sync(&fimc->pdev->dev);

if (++fimc->vid_cap.refcnt == 1) {
ret = fimc_pipeline_initialize(fimc,
&fimc->vid_cap.vfd->entity, true);
if (ret < 0) {
dev_err(&fimc->pdev->dev,
"Video pipeline initialization failed\n");
pm_runtime_put_sync(&fimc->pdev->dev);
fimc->vid_cap.refcnt--;
v4l2_fh_release(file);
return ret;
}
ret = fimc_capture_ctrls_create(fimc);

}
return ret;
}

Expand All @@ -341,6 +359,7 @@ static int fimc_capture_close(struct file *file)

if (--fimc->vid_cap.refcnt == 0) {
fimc_stop_capture(fimc);
fimc_pipeline_shutdown(fimc);
fimc_ctrls_delete(fimc->vid_cap.ctx);
vb2_queue_release(&fimc->vid_cap.vbq);
}
Expand Down Expand Up @@ -405,41 +424,11 @@ static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv,
return 0;
}

/* Synchronize formats of the camera interface input and attached sensor. */
static int sync_capture_fmt(struct fimc_ctx *ctx)
{
struct fimc_frame *frame = &ctx->s_frame;
struct fimc_dev *fimc = ctx->fimc_dev;
struct v4l2_mbus_framefmt *fmt = &fimc->vid_cap.fmt;
int ret;

fmt->width = ctx->d_frame.o_width;
fmt->height = ctx->d_frame.o_height;

ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_mbus_fmt, fmt);
if (ret == -ENOIOCTLCMD) {
err("s_mbus_fmt failed");
return ret;
}
dbg("w: %d, h: %d, code= %d", fmt->width, fmt->height, fmt->code);

frame->fmt = fimc_find_format(NULL, &fmt->code, FMT_FLAGS_CAM, -1);
if (!frame->fmt) {
err("fimc source format not found\n");
return -EINVAL;
}

frame->f_width = fmt->width;
frame->f_height = fmt->height;
frame->width = fmt->width;
frame->height = fmt->height;
frame->o_width = fmt->width;
frame->o_height = fmt->height;
frame->offs_h = 0;
frame->offs_v = 0;

return 0;
}

static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
struct v4l2_format *f)
Expand All @@ -459,7 +448,7 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
struct fimc_dev *fimc = video_drvdata(file);
struct fimc_ctx *ctx = fimc->vid_cap.ctx;

return fimc_try_fmt_mplane(ctx, f);
return 0;
}

static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
Expand All @@ -475,10 +464,6 @@ static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
return -EINVAL;

ret = fimc_try_fmt_mplane(ctx, f);
if (ret)
return ret;

if (vb2_is_busy(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
return -EBUSY;

Expand Down Expand Up @@ -508,20 +493,21 @@ static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,

ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);

ret = sync_capture_fmt(ctx);
return ret;
}

static int fimc_cap_enum_input(struct file *file, void *priv,
struct v4l2_input *i)
{
struct fimc_dev *fimc = video_drvdata(file);
struct v4l2_subdev *sd = fimc->pipeline.sensor;

if (i->index != 0)
return -EINVAL;


i->type = V4L2_INPUT_TYPE_CAMERA;
if (sd)
strlcpy(i->name, sd->name, sizeof(i->name));
return 0;
}

Expand All @@ -541,14 +527,16 @@ static int fimc_cap_streamon(struct file *file, void *priv,
{
struct fimc_dev *fimc = video_drvdata(file);
struct fimc_ctx *ctx = fimc->vid_cap.ctx;
struct fimc_pipeline *p = &fimc->pipeline;

if (fimc_capture_active(fimc) || !fimc->vid_cap.sd)
if (fimc_capture_active(fimc))
return -EBUSY;

if (!(ctx->state & FIMC_DST_FMT)) {
v4l2_err(fimc->vid_cap.vfd, "Format is not set\n");
return -EINVAL;
}
media_entity_pipeline_start(&p->sensor->entity, p->pipe);

return vb2_streamon(&fimc->vid_cap.vbq, type);
}
Expand All @@ -557,8 +545,13 @@ static int fimc_cap_streamoff(struct file *file, void *priv,
enum v4l2_buf_type type)
{
struct fimc_dev *fimc = video_drvdata(file);
struct v4l2_subdev *sd = fimc->pipeline.sensor;
int ret;

return vb2_streamoff(&fimc->vid_cap.vbq, type);
ret = vb2_streamoff(&fimc->vid_cap.vbq, type);
if (ret == 0)
media_entity_pipeline_stop(&sd->entity);
return ret;
}

static int fimc_cap_reqbufs(struct file *file, void *priv,
Expand Down Expand Up @@ -664,7 +657,6 @@ static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
return 0;
}


static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
.vidioc_querycap = fimc_vidioc_querycap_capture,

Expand Down Expand Up @@ -770,8 +762,6 @@ int fimc_register_capture_device(struct fimc_dev *fimc,
vid_cap->active_buf_cnt = 0;
vid_cap->reqbufs_count = 0;
vid_cap->refcnt = 0;
/* Default color format for image sensor */
vid_cap->fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;

INIT_LIST_HEAD(&vid_cap->pending_buf_q);
INIT_LIST_HEAD(&vid_cap->active_buf_q);
Expand Down
Loading

0 comments on commit ece6370

Please sign in to comment.