diff options
Diffstat (limited to 'drivers/media/video/s5p-fimc')
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-capture.c | 69 | ||||
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-core.c | 19 | ||||
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-lite.c | 73 | ||||
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-mdevice.c | 48 | ||||
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-mdevice.h | 2 |
5 files changed, 120 insertions, 91 deletions
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c index 35457459190..725812aa0c3 100644 --- a/drivers/media/video/s5p-fimc/fimc-capture.c +++ b/drivers/media/video/s5p-fimc/fimc-capture.c | |||
@@ -350,7 +350,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt, | |||
350 | if (pixm) | 350 | if (pixm) |
351 | sizes[i] = max(size, pixm->plane_fmt[i].sizeimage); | 351 | sizes[i] = max(size, pixm->plane_fmt[i].sizeimage); |
352 | else | 352 | else |
353 | sizes[i] = size; | 353 | sizes[i] = max_t(u32, size, frame->payload[i]); |
354 | |||
354 | allocators[i] = ctx->fimc_dev->alloc_ctx; | 355 | allocators[i] = ctx->fimc_dev->alloc_ctx; |
355 | } | 356 | } |
356 | 357 | ||
@@ -479,37 +480,39 @@ static int fimc_capture_set_default_format(struct fimc_dev *fimc); | |||
479 | static int fimc_capture_open(struct file *file) | 480 | static int fimc_capture_open(struct file *file) |
480 | { | 481 | { |
481 | struct fimc_dev *fimc = video_drvdata(file); | 482 | struct fimc_dev *fimc = video_drvdata(file); |
482 | int ret = v4l2_fh_open(file); | 483 | int ret; |
483 | |||
484 | if (ret) | ||
485 | return ret; | ||
486 | 484 | ||
487 | dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); | 485 | dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); |
488 | 486 | ||
489 | /* Return if the corresponding video mem2mem node is already opened. */ | ||
490 | if (fimc_m2m_active(fimc)) | 487 | if (fimc_m2m_active(fimc)) |
491 | return -EBUSY; | 488 | return -EBUSY; |
492 | 489 | ||
493 | set_bit(ST_CAPT_BUSY, &fimc->state); | 490 | set_bit(ST_CAPT_BUSY, &fimc->state); |
494 | pm_runtime_get_sync(&fimc->pdev->dev); | 491 | ret = pm_runtime_get_sync(&fimc->pdev->dev); |
492 | if (ret < 0) | ||
493 | return ret; | ||
495 | 494 | ||
496 | if (++fimc->vid_cap.refcnt == 1) { | 495 | ret = v4l2_fh_open(file); |
497 | ret = fimc_pipeline_initialize(&fimc->pipeline, | 496 | if (ret) |
498 | &fimc->vid_cap.vfd->entity, true); | 497 | return ret; |
499 | if (ret < 0) { | ||
500 | dev_err(&fimc->pdev->dev, | ||
501 | "Video pipeline initialization failed\n"); | ||
502 | pm_runtime_put_sync(&fimc->pdev->dev); | ||
503 | fimc->vid_cap.refcnt--; | ||
504 | v4l2_fh_release(file); | ||
505 | clear_bit(ST_CAPT_BUSY, &fimc->state); | ||
506 | return ret; | ||
507 | } | ||
508 | ret = fimc_capture_ctrls_create(fimc); | ||
509 | 498 | ||
510 | if (!ret && !fimc->vid_cap.user_subdev_api) | 499 | if (++fimc->vid_cap.refcnt != 1) |
511 | ret = fimc_capture_set_default_format(fimc); | 500 | return 0; |
501 | |||
502 | ret = fimc_pipeline_initialize(&fimc->pipeline, | ||
503 | &fimc->vid_cap.vfd->entity, true); | ||
504 | if (ret < 0) { | ||
505 | clear_bit(ST_CAPT_BUSY, &fimc->state); | ||
506 | pm_runtime_put_sync(&fimc->pdev->dev); | ||
507 | fimc->vid_cap.refcnt--; | ||
508 | v4l2_fh_release(file); | ||
509 | return ret; | ||
512 | } | 510 | } |
511 | ret = fimc_capture_ctrls_create(fimc); | ||
512 | |||
513 | if (!ret && !fimc->vid_cap.user_subdev_api) | ||
514 | ret = fimc_capture_set_default_format(fimc); | ||
515 | |||
513 | return ret; | 516 | return ret; |
514 | } | 517 | } |
515 | 518 | ||
@@ -818,9 +821,6 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh, | |||
818 | struct fimc_dev *fimc = video_drvdata(file); | 821 | struct fimc_dev *fimc = video_drvdata(file); |
819 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; | 822 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; |
820 | 823 | ||
821 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
822 | return -EINVAL; | ||
823 | |||
824 | return fimc_fill_format(&ctx->d_frame, f); | 824 | return fimc_fill_format(&ctx->d_frame, f); |
825 | } | 825 | } |
826 | 826 | ||
@@ -833,9 +833,6 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh, | |||
833 | struct v4l2_mbus_framefmt mf; | 833 | struct v4l2_mbus_framefmt mf; |
834 | struct fimc_fmt *ffmt = NULL; | 834 | struct fimc_fmt *ffmt = NULL; |
835 | 835 | ||
836 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
837 | return -EINVAL; | ||
838 | |||
839 | if (pix->pixelformat == V4L2_PIX_FMT_JPEG) { | 836 | if (pix->pixelformat == V4L2_PIX_FMT_JPEG) { |
840 | fimc_capture_try_format(ctx, &pix->width, &pix->height, | 837 | fimc_capture_try_format(ctx, &pix->width, &pix->height, |
841 | NULL, &pix->pixelformat, | 838 | NULL, &pix->pixelformat, |
@@ -887,8 +884,6 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f) | |||
887 | struct fimc_fmt *s_fmt = NULL; | 884 | struct fimc_fmt *s_fmt = NULL; |
888 | int ret, i; | 885 | int ret, i; |
889 | 886 | ||
890 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
891 | return -EINVAL; | ||
892 | if (vb2_is_busy(&fimc->vid_cap.vbq)) | 887 | if (vb2_is_busy(&fimc->vid_cap.vbq)) |
893 | return -EBUSY; | 888 | return -EBUSY; |
894 | 889 | ||
@@ -924,10 +919,10 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f) | |||
924 | pix->width = mf->width; | 919 | pix->width = mf->width; |
925 | pix->height = mf->height; | 920 | pix->height = mf->height; |
926 | } | 921 | } |
922 | |||
927 | fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix); | 923 | fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix); |
928 | for (i = 0; i < ff->fmt->colplanes; i++) | 924 | for (i = 0; i < ff->fmt->colplanes; i++) |
929 | ff->payload[i] = | 925 | ff->payload[i] = pix->plane_fmt[i].sizeimage; |
930 | (pix->width * pix->height * ff->fmt->depth[i]) / 8; | ||
931 | 926 | ||
932 | set_frame_bounds(ff, pix->width, pix->height); | 927 | set_frame_bounds(ff, pix->width, pix->height); |
933 | /* Reset the composition rectangle if not yet configured */ | 928 | /* Reset the composition rectangle if not yet configured */ |
@@ -1045,18 +1040,22 @@ static int fimc_cap_streamon(struct file *file, void *priv, | |||
1045 | { | 1040 | { |
1046 | struct fimc_dev *fimc = video_drvdata(file); | 1041 | struct fimc_dev *fimc = video_drvdata(file); |
1047 | struct fimc_pipeline *p = &fimc->pipeline; | 1042 | struct fimc_pipeline *p = &fimc->pipeline; |
1043 | struct v4l2_subdev *sd = p->subdevs[IDX_SENSOR]; | ||
1048 | int ret; | 1044 | int ret; |
1049 | 1045 | ||
1050 | if (fimc_capture_active(fimc)) | 1046 | if (fimc_capture_active(fimc)) |
1051 | return -EBUSY; | 1047 | return -EBUSY; |
1052 | 1048 | ||
1053 | media_entity_pipeline_start(&p->subdevs[IDX_SENSOR]->entity, | 1049 | ret = media_entity_pipeline_start(&sd->entity, p->m_pipeline); |
1054 | p->m_pipeline); | 1050 | if (ret < 0) |
1051 | return ret; | ||
1055 | 1052 | ||
1056 | if (fimc->vid_cap.user_subdev_api) { | 1053 | if (fimc->vid_cap.user_subdev_api) { |
1057 | ret = fimc_pipeline_validate(fimc); | 1054 | ret = fimc_pipeline_validate(fimc); |
1058 | if (ret) | 1055 | if (ret < 0) { |
1056 | media_entity_pipeline_stop(&sd->entity); | ||
1059 | return ret; | 1057 | return ret; |
1058 | } | ||
1060 | } | 1059 | } |
1061 | return vb2_streamon(&fimc->vid_cap.vbq, type); | 1060 | return vb2_streamon(&fimc->vid_cap.vbq, type); |
1062 | } | 1061 | } |
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c index 92fc5a20fb7..a4646ca1d56 100644 --- a/drivers/media/video/s5p-fimc/fimc-core.c +++ b/drivers/media/video/s5p-fimc/fimc-core.c | |||
@@ -153,7 +153,7 @@ static struct fimc_fmt fimc_formats[] = { | |||
153 | .colplanes = 2, | 153 | .colplanes = 2, |
154 | .flags = FMT_FLAGS_M2M, | 154 | .flags = FMT_FLAGS_M2M, |
155 | }, { | 155 | }, { |
156 | .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr", | 156 | .name = "YUV 4:2:0 non-contig. 2p, Y/CbCr", |
157 | .fourcc = V4L2_PIX_FMT_NV12M, | 157 | .fourcc = V4L2_PIX_FMT_NV12M, |
158 | .color = FIMC_FMT_YCBCR420, | 158 | .color = FIMC_FMT_YCBCR420, |
159 | .depth = { 8, 4 }, | 159 | .depth = { 8, 4 }, |
@@ -161,7 +161,7 @@ static struct fimc_fmt fimc_formats[] = { | |||
161 | .colplanes = 2, | 161 | .colplanes = 2, |
162 | .flags = FMT_FLAGS_M2M, | 162 | .flags = FMT_FLAGS_M2M, |
163 | }, { | 163 | }, { |
164 | .name = "YUV 4:2:0 non-contiguous 3-planar, Y/Cb/Cr", | 164 | .name = "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr", |
165 | .fourcc = V4L2_PIX_FMT_YUV420M, | 165 | .fourcc = V4L2_PIX_FMT_YUV420M, |
166 | .color = FIMC_FMT_YCBCR420, | 166 | .color = FIMC_FMT_YCBCR420, |
167 | .depth = { 8, 2, 2 }, | 167 | .depth = { 8, 2, 2 }, |
@@ -169,7 +169,7 @@ static struct fimc_fmt fimc_formats[] = { | |||
169 | .colplanes = 3, | 169 | .colplanes = 3, |
170 | .flags = FMT_FLAGS_M2M, | 170 | .flags = FMT_FLAGS_M2M, |
171 | }, { | 171 | }, { |
172 | .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr, tiled", | 172 | .name = "YUV 4:2:0 non-contig. 2p, tiled", |
173 | .fourcc = V4L2_PIX_FMT_NV12MT, | 173 | .fourcc = V4L2_PIX_FMT_NV12MT, |
174 | .color = FIMC_FMT_YCBCR420, | 174 | .color = FIMC_FMT_YCBCR420, |
175 | .depth = { 8, 4 }, | 175 | .depth = { 8, 4 }, |
@@ -641,7 +641,7 @@ void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active) | |||
641 | if (!ctrls->ready) | 641 | if (!ctrls->ready) |
642 | return; | 642 | return; |
643 | 643 | ||
644 | mutex_lock(&ctrls->handler.lock); | 644 | mutex_lock(ctrls->handler.lock); |
645 | v4l2_ctrl_activate(ctrls->rotate, active); | 645 | v4l2_ctrl_activate(ctrls->rotate, active); |
646 | v4l2_ctrl_activate(ctrls->hflip, active); | 646 | v4l2_ctrl_activate(ctrls->hflip, active); |
647 | v4l2_ctrl_activate(ctrls->vflip, active); | 647 | v4l2_ctrl_activate(ctrls->vflip, active); |
@@ -660,7 +660,7 @@ void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active) | |||
660 | ctx->hflip = 0; | 660 | ctx->hflip = 0; |
661 | ctx->vflip = 0; | 661 | ctx->vflip = 0; |
662 | } | 662 | } |
663 | mutex_unlock(&ctrls->handler.lock); | 663 | mutex_unlock(ctrls->handler.lock); |
664 | } | 664 | } |
665 | 665 | ||
666 | /* Update maximum value of the alpha color control */ | 666 | /* Update maximum value of the alpha color control */ |
@@ -741,8 +741,8 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, | |||
741 | pix->width = width; | 741 | pix->width = width; |
742 | 742 | ||
743 | for (i = 0; i < pix->num_planes; ++i) { | 743 | for (i = 0; i < pix->num_planes; ++i) { |
744 | u32 bpl = pix->plane_fmt[i].bytesperline; | 744 | struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i]; |
745 | u32 *sizeimage = &pix->plane_fmt[i].sizeimage; | 745 | u32 bpl = plane_fmt->bytesperline; |
746 | 746 | ||
747 | if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width)) | 747 | if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width)) |
748 | bpl = pix->width; /* Planar */ | 748 | bpl = pix->width; /* Planar */ |
@@ -754,8 +754,9 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, | |||
754 | if (i == 0) /* Same bytesperline for each plane. */ | 754 | if (i == 0) /* Same bytesperline for each plane. */ |
755 | bytesperline = bpl; | 755 | bytesperline = bpl; |
756 | 756 | ||
757 | pix->plane_fmt[i].bytesperline = bytesperline; | 757 | plane_fmt->bytesperline = bytesperline; |
758 | *sizeimage = (pix->width * pix->height * fmt->depth[i]) / 8; | 758 | plane_fmt->sizeimage = max((pix->width * pix->height * |
759 | fmt->depth[i]) / 8, plane_fmt->sizeimage); | ||
759 | } | 760 | } |
760 | } | 761 | } |
761 | 762 | ||
diff --git a/drivers/media/video/s5p-fimc/fimc-lite.c b/drivers/media/video/s5p-fimc/fimc-lite.c index 400d701aef0..74ff310db30 100644 --- a/drivers/media/video/s5p-fimc/fimc-lite.c +++ b/drivers/media/video/s5p-fimc/fimc-lite.c | |||
@@ -451,34 +451,44 @@ static void fimc_lite_clear_event_counters(struct fimc_lite *fimc) | |||
451 | static int fimc_lite_open(struct file *file) | 451 | static int fimc_lite_open(struct file *file) |
452 | { | 452 | { |
453 | struct fimc_lite *fimc = video_drvdata(file); | 453 | struct fimc_lite *fimc = video_drvdata(file); |
454 | int ret = v4l2_fh_open(file); | 454 | int ret; |
455 | 455 | ||
456 | if (ret) | 456 | if (mutex_lock_interruptible(&fimc->lock)) |
457 | return ret; | 457 | return -ERESTARTSYS; |
458 | 458 | ||
459 | set_bit(ST_FLITE_IN_USE, &fimc->state); | 459 | set_bit(ST_FLITE_IN_USE, &fimc->state); |
460 | pm_runtime_get_sync(&fimc->pdev->dev); | 460 | ret = pm_runtime_get_sync(&fimc->pdev->dev); |
461 | if (ret < 0) | ||
462 | goto done; | ||
461 | 463 | ||
462 | if (++fimc->ref_count != 1 || fimc->out_path != FIMC_IO_DMA) | 464 | ret = v4l2_fh_open(file); |
463 | return ret; | 465 | if (ret < 0) |
466 | goto done; | ||
464 | 467 | ||
465 | ret = fimc_pipeline_initialize(&fimc->pipeline, &fimc->vfd->entity, | 468 | if (++fimc->ref_count == 1 && fimc->out_path == FIMC_IO_DMA) { |
466 | true); | 469 | ret = fimc_pipeline_initialize(&fimc->pipeline, |
467 | if (ret < 0) { | 470 | &fimc->vfd->entity, true); |
468 | v4l2_err(fimc->vfd, "Video pipeline initialization failed\n"); | 471 | if (ret < 0) { |
469 | pm_runtime_put_sync(&fimc->pdev->dev); | 472 | pm_runtime_put_sync(&fimc->pdev->dev); |
470 | fimc->ref_count--; | 473 | fimc->ref_count--; |
471 | v4l2_fh_release(file); | 474 | v4l2_fh_release(file); |
472 | clear_bit(ST_FLITE_IN_USE, &fimc->state); | 475 | clear_bit(ST_FLITE_IN_USE, &fimc->state); |
473 | } | 476 | } |
474 | 477 | ||
475 | fimc_lite_clear_event_counters(fimc); | 478 | fimc_lite_clear_event_counters(fimc); |
479 | } | ||
480 | done: | ||
481 | mutex_unlock(&fimc->lock); | ||
476 | return ret; | 482 | return ret; |
477 | } | 483 | } |
478 | 484 | ||
479 | static int fimc_lite_close(struct file *file) | 485 | static int fimc_lite_close(struct file *file) |
480 | { | 486 | { |
481 | struct fimc_lite *fimc = video_drvdata(file); | 487 | struct fimc_lite *fimc = video_drvdata(file); |
488 | int ret; | ||
489 | |||
490 | if (mutex_lock_interruptible(&fimc->lock)) | ||
491 | return -ERESTARTSYS; | ||
482 | 492 | ||
483 | if (--fimc->ref_count == 0 && fimc->out_path == FIMC_IO_DMA) { | 493 | if (--fimc->ref_count == 0 && fimc->out_path == FIMC_IO_DMA) { |
484 | clear_bit(ST_FLITE_IN_USE, &fimc->state); | 494 | clear_bit(ST_FLITE_IN_USE, &fimc->state); |
@@ -492,20 +502,39 @@ static int fimc_lite_close(struct file *file) | |||
492 | if (fimc->ref_count == 0) | 502 | if (fimc->ref_count == 0) |
493 | vb2_queue_release(&fimc->vb_queue); | 503 | vb2_queue_release(&fimc->vb_queue); |
494 | 504 | ||
495 | return v4l2_fh_release(file); | 505 | ret = v4l2_fh_release(file); |
506 | |||
507 | mutex_unlock(&fimc->lock); | ||
508 | return ret; | ||
496 | } | 509 | } |
497 | 510 | ||
498 | static unsigned int fimc_lite_poll(struct file *file, | 511 | static unsigned int fimc_lite_poll(struct file *file, |
499 | struct poll_table_struct *wait) | 512 | struct poll_table_struct *wait) |
500 | { | 513 | { |
501 | struct fimc_lite *fimc = video_drvdata(file); | 514 | struct fimc_lite *fimc = video_drvdata(file); |
502 | return vb2_poll(&fimc->vb_queue, file, wait); | 515 | int ret; |
516 | |||
517 | if (mutex_lock_interruptible(&fimc->lock)) | ||
518 | return POLL_ERR; | ||
519 | |||
520 | ret = vb2_poll(&fimc->vb_queue, file, wait); | ||
521 | mutex_unlock(&fimc->lock); | ||
522 | |||
523 | return ret; | ||
503 | } | 524 | } |
504 | 525 | ||
505 | static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma) | 526 | static int fimc_lite_mmap(struct file *file, struct vm_area_struct *vma) |
506 | { | 527 | { |
507 | struct fimc_lite *fimc = video_drvdata(file); | 528 | struct fimc_lite *fimc = video_drvdata(file); |
508 | return vb2_mmap(&fimc->vb_queue, vma); | 529 | int ret; |
530 | |||
531 | if (mutex_lock_interruptible(&fimc->lock)) | ||
532 | return -ERESTARTSYS; | ||
533 | |||
534 | ret = vb2_mmap(&fimc->vb_queue, vma); | ||
535 | mutex_unlock(&fimc->lock); | ||
536 | |||
537 | return ret; | ||
509 | } | 538 | } |
510 | 539 | ||
511 | static const struct v4l2_file_operations fimc_lite_fops = { | 540 | static const struct v4l2_file_operations fimc_lite_fops = { |
@@ -762,7 +791,9 @@ static int fimc_lite_streamon(struct file *file, void *priv, | |||
762 | if (fimc_lite_active(fimc)) | 791 | if (fimc_lite_active(fimc)) |
763 | return -EBUSY; | 792 | return -EBUSY; |
764 | 793 | ||
765 | media_entity_pipeline_start(&sensor->entity, p->m_pipeline); | 794 | ret = media_entity_pipeline_start(&sensor->entity, p->m_pipeline); |
795 | if (ret < 0) | ||
796 | return ret; | ||
766 | 797 | ||
767 | ret = fimc_pipeline_validate(fimc); | 798 | ret = fimc_pipeline_validate(fimc); |
768 | if (ret) { | 799 | if (ret) { |
@@ -1508,7 +1539,7 @@ static int fimc_lite_suspend(struct device *dev) | |||
1508 | return 0; | 1539 | return 0; |
1509 | 1540 | ||
1510 | ret = fimc_lite_stop_capture(fimc, suspend); | 1541 | ret = fimc_lite_stop_capture(fimc, suspend); |
1511 | if (ret) | 1542 | if (ret < 0 || !fimc_lite_active(fimc)) |
1512 | return ret; | 1543 | return ret; |
1513 | 1544 | ||
1514 | return fimc_pipeline_shutdown(&fimc->pipeline); | 1545 | return fimc_pipeline_shutdown(&fimc->pipeline); |
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.c b/drivers/media/video/s5p-fimc/fimc-mdevice.c index 6753c45631b..52cef486542 100644 --- a/drivers/media/video/s5p-fimc/fimc-mdevice.c +++ b/drivers/media/video/s5p-fimc/fimc-mdevice.c | |||
@@ -193,9 +193,13 @@ int __fimc_pipeline_shutdown(struct fimc_pipeline *p) | |||
193 | 193 | ||
194 | int fimc_pipeline_shutdown(struct fimc_pipeline *p) | 194 | int fimc_pipeline_shutdown(struct fimc_pipeline *p) |
195 | { | 195 | { |
196 | struct media_entity *me = &p->subdevs[IDX_SENSOR]->entity; | 196 | struct media_entity *me; |
197 | int ret; | 197 | int ret; |
198 | 198 | ||
199 | if (!p || !p->subdevs[IDX_SENSOR]) | ||
200 | return -EINVAL; | ||
201 | |||
202 | me = &p->subdevs[IDX_SENSOR]->entity; | ||
199 | mutex_lock(&me->parent->graph_mutex); | 203 | mutex_lock(&me->parent->graph_mutex); |
200 | ret = __fimc_pipeline_shutdown(p); | 204 | ret = __fimc_pipeline_shutdown(p); |
201 | mutex_unlock(&me->parent->graph_mutex); | 205 | mutex_unlock(&me->parent->graph_mutex); |
@@ -498,12 +502,12 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd) | |||
498 | * @source: the source entity to create links to all fimc entities from | 502 | * @source: the source entity to create links to all fimc entities from |
499 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null | 503 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null |
500 | * @pad: the source entity pad index | 504 | * @pad: the source entity pad index |
501 | * @fimc_id: index of the fimc device for which link should be enabled | 505 | * @link_mask: bitmask of the fimc devices for which link should be enabled |
502 | */ | 506 | */ |
503 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, | 507 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, |
504 | struct media_entity *source, | 508 | struct media_entity *source, |
505 | struct v4l2_subdev *sensor, | 509 | struct v4l2_subdev *sensor, |
506 | int pad, int fimc_id) | 510 | int pad, int link_mask) |
507 | { | 511 | { |
508 | struct fimc_sensor_info *s_info; | 512 | struct fimc_sensor_info *s_info; |
509 | struct media_entity *sink; | 513 | struct media_entity *sink; |
@@ -520,7 +524,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, | |||
520 | if (!fmd->fimc[i]->variant->has_cam_if) | 524 | if (!fmd->fimc[i]->variant->has_cam_if) |
521 | continue; | 525 | continue; |
522 | 526 | ||
523 | flags = (i == fimc_id) ? MEDIA_LNK_FL_ENABLED : 0; | 527 | flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0; |
524 | 528 | ||
525 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; | 529 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
526 | ret = media_entity_create_link(source, pad, sink, | 530 | ret = media_entity_create_link(source, pad, sink, |
@@ -552,7 +556,10 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, | |||
552 | if (!fmd->fimc_lite[i]) | 556 | if (!fmd->fimc_lite[i]) |
553 | continue; | 557 | continue; |
554 | 558 | ||
555 | flags = (i == fimc_id) ? MEDIA_LNK_FL_ENABLED : 0; | 559 | if (link_mask & (1 << (i + FIMC_MAX_DEVS))) |
560 | flags = MEDIA_LNK_FL_ENABLED; | ||
561 | else | ||
562 | flags = 0; | ||
556 | 563 | ||
557 | sink = &fmd->fimc_lite[i]->subdev.entity; | 564 | sink = &fmd->fimc_lite[i]->subdev.entity; |
558 | ret = media_entity_create_link(source, pad, sink, | 565 | ret = media_entity_create_link(source, pad, sink, |
@@ -614,9 +621,8 @@ static int fimc_md_create_links(struct fimc_md *fmd) | |||
614 | struct s5p_fimc_isp_info *pdata; | 621 | struct s5p_fimc_isp_info *pdata; |
615 | struct fimc_sensor_info *s_info; | 622 | struct fimc_sensor_info *s_info; |
616 | struct media_entity *source, *sink; | 623 | struct media_entity *source, *sink; |
617 | int i, pad, fimc_id = 0; | 624 | int i, pad, fimc_id = 0, ret = 0; |
618 | int ret = 0; | 625 | u32 flags, link_mask = 0; |
619 | u32 flags; | ||
620 | 626 | ||
621 | for (i = 0; i < fmd->num_sensors; i++) { | 627 | for (i = 0; i < fmd->num_sensors; i++) { |
622 | if (fmd->sensor[i].subdev == NULL) | 628 | if (fmd->sensor[i].subdev == NULL) |
@@ -668,19 +674,20 @@ static int fimc_md_create_links(struct fimc_md *fmd) | |||
668 | if (source == NULL) | 674 | if (source == NULL) |
669 | continue; | 675 | continue; |
670 | 676 | ||
677 | link_mask = 1 << fimc_id++; | ||
671 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, | 678 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
672 | pad, fimc_id++); | 679 | pad, link_mask); |
673 | } | 680 | } |
674 | 681 | ||
675 | fimc_id = 0; | ||
676 | for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { | 682 | for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { |
677 | if (fmd->csis[i].sd == NULL) | 683 | if (fmd->csis[i].sd == NULL) |
678 | continue; | 684 | continue; |
679 | source = &fmd->csis[i].sd->entity; | 685 | source = &fmd->csis[i].sd->entity; |
680 | pad = CSIS_PAD_SOURCE; | 686 | pad = CSIS_PAD_SOURCE; |
681 | 687 | ||
688 | link_mask = 1 << fimc_id++; | ||
682 | ret = __fimc_md_create_fimc_sink_links(fmd, source, NULL, | 689 | ret = __fimc_md_create_fimc_sink_links(fmd, source, NULL, |
683 | pad, fimc_id++); | 690 | pad, link_mask); |
684 | } | 691 | } |
685 | 692 | ||
686 | /* Create immutable links between each FIMC's subdev and video node */ | 693 | /* Create immutable links between each FIMC's subdev and video node */ |
@@ -734,8 +741,8 @@ static void fimc_md_put_clocks(struct fimc_md *fmd) | |||
734 | } | 741 | } |
735 | 742 | ||
736 | static int __fimc_md_set_camclk(struct fimc_md *fmd, | 743 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
737 | struct fimc_sensor_info *s_info, | 744 | struct fimc_sensor_info *s_info, |
738 | bool on) | 745 | bool on) |
739 | { | 746 | { |
740 | struct s5p_fimc_isp_info *pdata = s_info->pdata; | 747 | struct s5p_fimc_isp_info *pdata = s_info->pdata; |
741 | struct fimc_camclk_info *camclk; | 748 | struct fimc_camclk_info *camclk; |
@@ -744,12 +751,10 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd, | |||
744 | if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) | 751 | if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) |
745 | return -EINVAL; | 752 | return -EINVAL; |
746 | 753 | ||
747 | if (s_info->clk_on == on) | ||
748 | return 0; | ||
749 | camclk = &fmd->camclk[pdata->clk_id]; | 754 | camclk = &fmd->camclk[pdata->clk_id]; |
750 | 755 | ||
751 | dbg("camclk %d, f: %lu, clk: %p, on: %d", | 756 | dbg("camclk %d, f: %lu, use_count: %d, on: %d", |
752 | pdata->clk_id, pdata->clk_frequency, camclk, on); | 757 | pdata->clk_id, pdata->clk_frequency, camclk->use_count, on); |
753 | 758 | ||
754 | if (on) { | 759 | if (on) { |
755 | if (camclk->use_count > 0 && | 760 | if (camclk->use_count > 0 && |
@@ -760,11 +765,9 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd, | |||
760 | clk_set_rate(camclk->clock, pdata->clk_frequency); | 765 | clk_set_rate(camclk->clock, pdata->clk_frequency); |
761 | camclk->frequency = pdata->clk_frequency; | 766 | camclk->frequency = pdata->clk_frequency; |
762 | ret = clk_enable(camclk->clock); | 767 | ret = clk_enable(camclk->clock); |
768 | dbg("Enabled camclk %d: f: %lu", pdata->clk_id, | ||
769 | clk_get_rate(camclk->clock)); | ||
763 | } | 770 | } |
764 | s_info->clk_on = 1; | ||
765 | dbg("Enabled camclk %d: f: %lu", pdata->clk_id, | ||
766 | clk_get_rate(camclk->clock)); | ||
767 | |||
768 | return ret; | 771 | return ret; |
769 | } | 772 | } |
770 | 773 | ||
@@ -773,7 +776,6 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd, | |||
773 | 776 | ||
774 | if (--camclk->use_count == 0) { | 777 | if (--camclk->use_count == 0) { |
775 | clk_disable(camclk->clock); | 778 | clk_disable(camclk->clock); |
776 | s_info->clk_on = 0; | ||
777 | dbg("Disabled camclk %d", pdata->clk_id); | 779 | dbg("Disabled camclk %d", pdata->clk_id); |
778 | } | 780 | } |
779 | return ret; | 781 | return ret; |
@@ -789,8 +791,6 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd, | |||
789 | * devices to which sensors can be attached, either directly or through | 791 | * devices to which sensors can be attached, either directly or through |
790 | * the MIPI CSI receiver. The clock is allowed here to be used by | 792 | * the MIPI CSI receiver. The clock is allowed here to be used by |
791 | * multiple sensors concurrently if they use same frequency. | 793 | * multiple sensors concurrently if they use same frequency. |
792 | * The per sensor subdev clk_on attribute helps to synchronize accesses | ||
793 | * to the sclk_cam clocks from the video and media device nodes. | ||
794 | * This function should only be called when the graph mutex is held. | 794 | * This function should only be called when the graph mutex is held. |
795 | */ | 795 | */ |
796 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) | 796 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) |
diff --git a/drivers/media/video/s5p-fimc/fimc-mdevice.h b/drivers/media/video/s5p-fimc/fimc-mdevice.h index 3b8a3492a17..1f5dbaff544 100644 --- a/drivers/media/video/s5p-fimc/fimc-mdevice.h +++ b/drivers/media/video/s5p-fimc/fimc-mdevice.h | |||
@@ -47,7 +47,6 @@ struct fimc_camclk_info { | |||
47 | * @pdata: sensor's atrributes passed as media device's platform data | 47 | * @pdata: sensor's atrributes passed as media device's platform data |
48 | * @subdev: image sensor v4l2 subdev | 48 | * @subdev: image sensor v4l2 subdev |
49 | * @host: fimc device the sensor is currently linked to | 49 | * @host: fimc device the sensor is currently linked to |
50 | * @clk_on: sclk_cam clock's state associated with this subdev | ||
51 | * | 50 | * |
52 | * This data structure applies to image sensor and the writeback subdevs. | 51 | * This data structure applies to image sensor and the writeback subdevs. |
53 | */ | 52 | */ |
@@ -55,7 +54,6 @@ struct fimc_sensor_info { | |||
55 | struct s5p_fimc_isp_info *pdata; | 54 | struct s5p_fimc_isp_info *pdata; |
56 | struct v4l2_subdev *subdev; | 55 | struct v4l2_subdev *subdev; |
57 | struct fimc_dev *host; | 56 | struct fimc_dev *host; |
58 | bool clk_on; | ||
59 | }; | 57 | }; |
60 | 58 | ||
61 | /** | 59 | /** |