aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylwester Nawrocki <s.nawrocki@samsung.com>2013-03-25 15:43:08 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-03-31 09:41:59 -0400
commitee12b049104118a58ac13da207a84c867191b17a (patch)
tree468c6d8cbdf6458f47d1be9abba494de83edf3fc
parentc444914af9261b57c9a559cc324dcadce7765bd2 (diff)
[media] s5p-fimc: Use vb2 ioctl helpers in fimc-lite
Replace some ioctl, file and video buffer queue operation handlers with the videobuf2 helpers. This allows to get rid of significant amount of boilerplate. Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite.c170
1 files changed, 45 insertions, 125 deletions
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.c b/drivers/media/platform/s5p-fimc/fimc-lite.c
index d8afbbc3999b..b64297ba35d3 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.c
+++ b/drivers/media/platform/s5p-fimc/fimc-lite.c
@@ -425,24 +425,12 @@ static void buffer_queue(struct vb2_buffer *vb)
425 spin_unlock_irqrestore(&fimc->slock, flags); 425 spin_unlock_irqrestore(&fimc->slock, flags);
426} 426}
427 427
428static void fimc_lock(struct vb2_queue *vq)
429{
430 struct fimc_lite *fimc = vb2_get_drv_priv(vq);
431 mutex_lock(&fimc->lock);
432}
433
434static void fimc_unlock(struct vb2_queue *vq)
435{
436 struct fimc_lite *fimc = vb2_get_drv_priv(vq);
437 mutex_unlock(&fimc->lock);
438}
439
440static const struct vb2_ops fimc_lite_qops = { 428static const struct vb2_ops fimc_lite_qops = {
441 .queue_setup = queue_setup, 429 .queue_setup = queue_setup,
442 .buf_prepare = buffer_prepare, 430 .buf_prepare = buffer_prepare,
443 .buf_queue = buffer_queue, 431 .buf_queue = buffer_queue,
444 .wait_prepare = fimc_unlock, 432 .wait_prepare = vb2_ops_wait_prepare,
445 .wait_finish = fimc_lock, 433 .wait_finish = vb2_ops_wait_finish,
446 .start_streaming = start_streaming, 434 .start_streaming = start_streaming,
447 .stop_streaming = stop_streaming, 435 .stop_streaming = stop_streaming,
448}; 436};
@@ -467,99 +455,69 @@ static int fimc_lite_open(struct file *file)
467 mutex_lock(&fimc->lock); 455 mutex_lock(&fimc->lock);
468 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) { 456 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) {
469 ret = -EBUSY; 457 ret = -EBUSY;
470 goto done; 458 goto unlock;
471 } 459 }
472 460
473 set_bit(ST_FLITE_IN_USE, &fimc->state); 461 set_bit(ST_FLITE_IN_USE, &fimc->state);
474 ret = pm_runtime_get_sync(&fimc->pdev->dev); 462 ret = pm_runtime_get_sync(&fimc->pdev->dev);
475 if (ret < 0) 463 if (ret < 0)
476 goto done; 464 goto unlock;
477 465
478 ret = v4l2_fh_open(file); 466 ret = v4l2_fh_open(file);
479 if (ret < 0) 467 if (ret < 0)
480 goto done; 468 goto err_pm;
481 469
482 if (++fimc->ref_count == 1 && 470 if (!v4l2_fh_is_singular_file(file) ||
483 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { 471 atomic_read(&fimc->out_path) != FIMC_IO_DMA)
484 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 472 goto unlock;
485 &fimc->vfd.entity, true);
486 if (ret < 0) {
487 pm_runtime_put_sync(&fimc->pdev->dev);
488 fimc->ref_count--;
489 v4l2_fh_release(file);
490 clear_bit(ST_FLITE_IN_USE, &fimc->state);
491 }
492 473
474 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline,
475 me, true);
476 if (!ret) {
493 fimc_lite_clear_event_counters(fimc); 477 fimc_lite_clear_event_counters(fimc);
478 fimc->ref_count++;
479 goto unlock;
494 } 480 }
495done: 481
482 v4l2_fh_release(file);
483err_pm:
484 pm_runtime_put_sync(&fimc->pdev->dev);
485 clear_bit(ST_FLITE_IN_USE, &fimc->state);
486unlock:
496 mutex_unlock(&fimc->lock); 487 mutex_unlock(&fimc->lock);
497 mutex_unlock(&me->parent->graph_mutex); 488 mutex_unlock(&me->parent->graph_mutex);
498 return ret; 489 return ret;
499} 490}
500 491
501static int fimc_lite_close(struct file *file) 492static int fimc_lite_release(struct file *file)
502{ 493{
503 struct fimc_lite *fimc = video_drvdata(file); 494 struct fimc_lite *fimc = video_drvdata(file);
504 int ret;
505 495
506 mutex_lock(&fimc->lock); 496 mutex_lock(&fimc->lock);
507 497
508 if (--fimc->ref_count == 0 && 498 if (v4l2_fh_is_singular_file(file) &&
509 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { 499 atomic_read(&fimc->out_path) == FIMC_IO_DMA) {
510 clear_bit(ST_FLITE_IN_USE, &fimc->state); 500 clear_bit(ST_FLITE_IN_USE, &fimc->state);
511 fimc_lite_stop_capture(fimc, false); 501 fimc_lite_stop_capture(fimc, false);
512 fimc_pipeline_call(fimc, close, &fimc->pipeline); 502 fimc_pipeline_call(fimc, close, &fimc->pipeline);
513 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); 503 fimc->ref_count--;
514 } 504 }
515 505
506 vb2_fop_release(file);
516 pm_runtime_put(&fimc->pdev->dev); 507 pm_runtime_put(&fimc->pdev->dev);
508 clear_bit(ST_FLITE_SUSPENDED, &fimc->state);
517 509
518 if (fimc->ref_count == 0)
519 vb2_queue_release(&fimc->vb_queue);
520
521 ret = v4l2_fh_release(file);
522
523 mutex_unlock(&fimc->lock);
524 return ret;
525}
526
527static unsigned int fimc_lite_poll(struct file *file,
528 struct poll_table_struct *wait)
529{
530 struct fimc_lite *fimc = video_drvdata(file);
531 int ret;
532
533 if (mutex_lock_interruptible(&fimc->lock))
534 return POLL_ERR;
535
536 ret = vb2_poll(&fimc->vb_queue, file, wait);
537 mutex_unlock(&fimc->lock);
538
539 return ret;
540}
541
542static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma)
543{
544 struct fimc_lite *fimc = video_drvdata(file);
545 int ret;
546
547 if (mutex_lock_interruptible(&fimc->lock))
548 return -ERESTARTSYS;
549
550 ret = vb2_mmap(&fimc->vb_queue, vma);
551 mutex_unlock(&fimc->lock); 510 mutex_unlock(&fimc->lock);
552 511 return 0;
553 return ret;
554} 512}
555 513
556static const struct v4l2_file_operations fimc_lite_fops = { 514static const struct v4l2_file_operations fimc_lite_fops = {
557 .owner = THIS_MODULE, 515 .owner = THIS_MODULE,
558 .open = fimc_lite_open, 516 .open = fimc_lite_open,
559 .release = fimc_lite_close, 517 .release = fimc_lite_release,
560 .poll = fimc_lite_poll, 518 .poll = vb2_fop_poll,
561 .unlocked_ioctl = video_ioctl2, 519 .unlocked_ioctl = video_ioctl2,
562 .mmap = fimc_lite_mmap, 520 .mmap = vb2_fop_mmap,
563}; 521};
564 522
565/* 523/*
@@ -720,7 +678,6 @@ static int fimc_lite_try_fmt_mplane(struct file *file, void *fh,
720 struct v4l2_format *f) 678 struct v4l2_format *f)
721{ 679{
722 struct fimc_lite *fimc = video_drvdata(file); 680 struct fimc_lite *fimc = video_drvdata(file);
723
724 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL); 681 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL);
725} 682}
726 683
@@ -812,12 +769,15 @@ static int fimc_lite_streamon(struct file *file, void *priv,
812 return ret; 769 return ret;
813 770
814 ret = fimc_pipeline_validate(fimc); 771 ret = fimc_pipeline_validate(fimc);
815 if (ret) { 772 if (ret < 0)
816 media_entity_pipeline_stop(entity); 773 goto err_p_stop;
817 return ret;
818 }
819 774
820 return vb2_streamon(&fimc->vb_queue, type); 775 ret = vb2_ioctl_streamon(file, priv, type);
776 if (!ret)
777 return ret;
778err_p_stop:
779 media_entity_pipeline_stop(entity);
780 return 0;
821} 781}
822 782
823static int fimc_lite_streamoff(struct file *file, void *priv, 783static int fimc_lite_streamoff(struct file *file, void *priv,
@@ -826,7 +786,7 @@ static int fimc_lite_streamoff(struct file *file, void *priv,
826 struct fimc_lite *fimc = video_drvdata(file); 786 struct fimc_lite *fimc = video_drvdata(file);
827 int ret; 787 int ret;
828 788
829 ret = vb2_streamoff(&fimc->vb_queue, type); 789 ret = vb2_ioctl_streamoff(file, priv, type);
830 if (ret == 0) 790 if (ret == 0)
831 media_entity_pipeline_stop(&fimc->vfd.entity); 791 media_entity_pipeline_stop(&fimc->vfd.entity);
832 return ret; 792 return ret;
@@ -839,53 +799,13 @@ static int fimc_lite_reqbufs(struct file *file, void *priv,
839 int ret; 799 int ret;
840 800
841 reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count); 801 reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count);
842 ret = vb2_reqbufs(&fimc->vb_queue, reqbufs); 802 ret = vb2_ioctl_reqbufs(file, priv, reqbufs);
843 if (!ret) 803 if (!ret)
844 fimc->reqbufs_count = reqbufs->count; 804 fimc->reqbufs_count = reqbufs->count;
845 805
846 return ret; 806 return ret;
847} 807}
848 808
849static int fimc_lite_querybuf(struct file *file, void *priv,
850 struct v4l2_buffer *buf)
851{
852 struct fimc_lite *fimc = video_drvdata(file);
853
854 return vb2_querybuf(&fimc->vb_queue, buf);
855}
856
857static int fimc_lite_qbuf(struct file *file, void *priv,
858 struct v4l2_buffer *buf)
859{
860 struct fimc_lite *fimc = video_drvdata(file);
861
862 return vb2_qbuf(&fimc->vb_queue, buf);
863}
864
865static int fimc_lite_dqbuf(struct file *file, void *priv,
866 struct v4l2_buffer *buf)
867{
868 struct fimc_lite *fimc = video_drvdata(file);
869
870 return vb2_dqbuf(&fimc->vb_queue, buf, file->f_flags & O_NONBLOCK);
871}
872
873static int fimc_lite_create_bufs(struct file *file, void *priv,
874 struct v4l2_create_buffers *create)
875{
876 struct fimc_lite *fimc = video_drvdata(file);
877
878 return vb2_create_bufs(&fimc->vb_queue, create);
879}
880
881static int fimc_lite_prepare_buf(struct file *file, void *priv,
882 struct v4l2_buffer *b)
883{
884 struct fimc_lite *fimc = video_drvdata(file);
885
886 return vb2_prepare_buf(&fimc->vb_queue, b);
887}
888
889/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */ 809/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
890static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b) 810static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
891{ 811{
@@ -965,11 +885,11 @@ static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = {
965 .vidioc_g_selection = fimc_lite_g_selection, 885 .vidioc_g_selection = fimc_lite_g_selection,
966 .vidioc_s_selection = fimc_lite_s_selection, 886 .vidioc_s_selection = fimc_lite_s_selection,
967 .vidioc_reqbufs = fimc_lite_reqbufs, 887 .vidioc_reqbufs = fimc_lite_reqbufs,
968 .vidioc_querybuf = fimc_lite_querybuf, 888 .vidioc_querybuf = vb2_ioctl_querybuf,
969 .vidioc_prepare_buf = fimc_lite_prepare_buf, 889 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
970 .vidioc_create_bufs = fimc_lite_create_bufs, 890 .vidioc_create_bufs = vb2_ioctl_create_bufs,
971 .vidioc_qbuf = fimc_lite_qbuf, 891 .vidioc_qbuf = vb2_ioctl_qbuf,
972 .vidioc_dqbuf = fimc_lite_dqbuf, 892 .vidioc_dqbuf = vb2_ioctl_dqbuf,
973 .vidioc_streamon = fimc_lite_streamon, 893 .vidioc_streamon = fimc_lite_streamon,
974 .vidioc_streamoff = fimc_lite_streamoff, 894 .vidioc_streamoff = fimc_lite_streamoff,
975}; 895};
@@ -1310,8 +1230,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1310 vfd->v4l2_dev = sd->v4l2_dev; 1230 vfd->v4l2_dev = sd->v4l2_dev;
1311 vfd->minor = -1; 1231 vfd->minor = -1;
1312 vfd->release = video_device_release_empty; 1232 vfd->release = video_device_release_empty;
1313 vfd->lock = &fimc->lock; 1233 vfd->queue = q;
1314 fimc->ref_count = 0;
1315 fimc->reqbufs_count = 0; 1234 fimc->reqbufs_count = 0;
1316 1235
1317 INIT_LIST_HEAD(&fimc->pending_buf_q); 1236 INIT_LIST_HEAD(&fimc->pending_buf_q);
@@ -1325,6 +1244,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1325 q->buf_struct_size = sizeof(struct flite_buffer); 1244 q->buf_struct_size = sizeof(struct flite_buffer);
1326 q->drv_priv = fimc; 1245 q->drv_priv = fimc;
1327 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1246 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1247 q->lock = &fimc->lock;
1328 1248
1329 ret = vb2_queue_init(q); 1249 ret = vb2_queue_init(q);
1330 if (ret < 0) 1250 if (ret < 0)