diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2011-06-10 14:36:50 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-09-06 16:37:18 -0400 |
commit | e578588eb01d9493513ca1527f464715cfd3f47f (patch) | |
tree | 8073e81fb2d3463117c9c2db1defec6990bfcbd3 /drivers/media/video/s5p-fimc/fimc-capture.c | |
parent | d3953223b0905437fef7ce60506b5fdfaf98dda6 (diff) |
[media] s5p-fimc: Conversion to use struct v4l2_fh
This is a prerequisite for the patch converting the driver to use
the control framework. As the capture driver does not use per file
handle contexts, two separate ioctl handlers are created for it
(vidioc_try_fmt_mplane, and vidioc_g_fmt_mplane) so there is no
handlers shared between the memory-to-memory and capture video node.
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>
Diffstat (limited to 'drivers/media/video/s5p-fimc/fimc-capture.c')
-rw-r--r-- | drivers/media/video/s5p-fimc/fimc-capture.c | 114 |
1 files changed, 63 insertions, 51 deletions
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c index a1ac986a5e72..562b23c7d486 100644 --- a/drivers/media/video/s5p-fimc/fimc-capture.c +++ b/drivers/media/video/s5p-fimc/fimc-capture.c | |||
@@ -276,7 +276,10 @@ static struct vb2_ops fimc_capture_qops = { | |||
276 | static int fimc_capture_open(struct file *file) | 276 | static int fimc_capture_open(struct file *file) |
277 | { | 277 | { |
278 | struct fimc_dev *fimc = video_drvdata(file); | 278 | struct fimc_dev *fimc = video_drvdata(file); |
279 | int ret = 0; | 279 | int ret = v4l2_fh_open(file); |
280 | |||
281 | if (ret) | ||
282 | return ret; | ||
280 | 283 | ||
281 | dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); | 284 | dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); |
282 | 285 | ||
@@ -285,11 +288,12 @@ static int fimc_capture_open(struct file *file) | |||
285 | return -EBUSY; | 288 | return -EBUSY; |
286 | 289 | ||
287 | ret = pm_runtime_get_sync(&fimc->pdev->dev); | 290 | ret = pm_runtime_get_sync(&fimc->pdev->dev); |
288 | if (ret) | 291 | if (ret < 0) { |
292 | v4l2_fh_release(file); | ||
289 | return ret; | 293 | return ret; |
294 | } | ||
290 | 295 | ||
291 | ++fimc->vid_cap.refcnt; | 296 | ++fimc->vid_cap.refcnt; |
292 | file->private_data = fimc->vid_cap.ctx; | ||
293 | 297 | ||
294 | return 0; | 298 | return 0; |
295 | } | 299 | } |
@@ -307,22 +311,20 @@ static int fimc_capture_close(struct file *file) | |||
307 | 311 | ||
308 | pm_runtime_put(&fimc->pdev->dev); | 312 | pm_runtime_put(&fimc->pdev->dev); |
309 | 313 | ||
310 | return 0; | 314 | return v4l2_fh_release(file); |
311 | } | 315 | } |
312 | 316 | ||
313 | static unsigned int fimc_capture_poll(struct file *file, | 317 | static unsigned int fimc_capture_poll(struct file *file, |
314 | struct poll_table_struct *wait) | 318 | struct poll_table_struct *wait) |
315 | { | 319 | { |
316 | struct fimc_ctx *ctx = file->private_data; | 320 | struct fimc_dev *fimc = video_drvdata(file); |
317 | struct fimc_dev *fimc = ctx->fimc_dev; | ||
318 | 321 | ||
319 | return vb2_poll(&fimc->vid_cap.vbq, file, wait); | 322 | return vb2_poll(&fimc->vid_cap.vbq, file, wait); |
320 | } | 323 | } |
321 | 324 | ||
322 | static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma) | 325 | static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma) |
323 | { | 326 | { |
324 | struct fimc_ctx *ctx = file->private_data; | 327 | struct fimc_dev *fimc = video_drvdata(file); |
325 | struct fimc_dev *fimc = ctx->fimc_dev; | ||
326 | 328 | ||
327 | return vb2_mmap(&fimc->vid_cap.vbq, vma); | 329 | return vb2_mmap(&fimc->vid_cap.vbq, vma); |
328 | } | 330 | } |
@@ -340,8 +342,7 @@ static const struct v4l2_file_operations fimc_capture_fops = { | |||
340 | static int fimc_vidioc_querycap_capture(struct file *file, void *priv, | 342 | static int fimc_vidioc_querycap_capture(struct file *file, void *priv, |
341 | struct v4l2_capability *cap) | 343 | struct v4l2_capability *cap) |
342 | { | 344 | { |
343 | struct fimc_ctx *ctx = file->private_data; | 345 | struct fimc_dev *fimc = video_drvdata(file); |
344 | struct fimc_dev *fimc = ctx->fimc_dev; | ||
345 | 346 | ||
346 | strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1); | 347 | strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1); |
347 | strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1); | 348 | strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1); |
@@ -388,20 +389,41 @@ static int sync_capture_fmt(struct fimc_ctx *ctx) | |||
388 | return 0; | 389 | return 0; |
389 | } | 390 | } |
390 | 391 | ||
392 | static int fimc_cap_g_fmt_mplane(struct file *file, void *fh, | ||
393 | struct v4l2_format *f) | ||
394 | { | ||
395 | struct fimc_dev *fimc = video_drvdata(file); | ||
396 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; | ||
397 | |||
398 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
399 | return -EINVAL; | ||
400 | |||
401 | return fimc_fill_format(&ctx->d_frame, f); | ||
402 | } | ||
403 | |||
404 | static int fimc_cap_try_fmt_mplane(struct file *file, void *fh, | ||
405 | struct v4l2_format *f) | ||
406 | { | ||
407 | struct fimc_dev *fimc = video_drvdata(file); | ||
408 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; | ||
409 | |||
410 | return fimc_try_fmt_mplane(ctx, f); | ||
411 | } | ||
412 | |||
391 | static int fimc_cap_s_fmt_mplane(struct file *file, void *priv, | 413 | static int fimc_cap_s_fmt_mplane(struct file *file, void *priv, |
392 | struct v4l2_format *f) | 414 | struct v4l2_format *f) |
393 | { | 415 | { |
394 | struct fimc_ctx *ctx = priv; | 416 | struct fimc_dev *fimc = video_drvdata(file); |
395 | struct fimc_dev *fimc = ctx->fimc_dev; | 417 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; |
396 | struct fimc_frame *frame; | ||
397 | struct v4l2_pix_format_mplane *pix; | 418 | struct v4l2_pix_format_mplane *pix; |
419 | struct fimc_frame *frame; | ||
398 | int ret; | 420 | int ret; |
399 | int i; | 421 | int i; |
400 | 422 | ||
401 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | 423 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
402 | return -EINVAL; | 424 | return -EINVAL; |
403 | 425 | ||
404 | ret = fimc_vidioc_try_fmt_mplane(file, priv, f); | 426 | ret = fimc_try_fmt_mplane(ctx, f); |
405 | if (ret) | 427 | if (ret) |
406 | return ret; | 428 | return ret; |
407 | 429 | ||
@@ -443,7 +465,7 @@ static int fimc_cap_s_fmt_mplane(struct file *file, void *priv, | |||
443 | static int fimc_cap_enum_input(struct file *file, void *priv, | 465 | static int fimc_cap_enum_input(struct file *file, void *priv, |
444 | struct v4l2_input *i) | 466 | struct v4l2_input *i) |
445 | { | 467 | { |
446 | struct fimc_ctx *ctx = priv; | 468 | struct fimc_dev *fimc = video_drvdata(file); |
447 | 469 | ||
448 | if (i->index != 0) | 470 | if (i->index != 0) |
449 | return -EINVAL; | 471 | return -EINVAL; |
@@ -467,8 +489,8 @@ static int fimc_cap_g_input(struct file *file, void *priv, unsigned int *i) | |||
467 | static int fimc_cap_streamon(struct file *file, void *priv, | 489 | static int fimc_cap_streamon(struct file *file, void *priv, |
468 | enum v4l2_buf_type type) | 490 | enum v4l2_buf_type type) |
469 | { | 491 | { |
470 | struct fimc_ctx *ctx = priv; | 492 | struct fimc_dev *fimc = video_drvdata(file); |
471 | struct fimc_dev *fimc = ctx->fimc_dev; | 493 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; |
472 | 494 | ||
473 | if (fimc_capture_active(fimc) || !fimc->vid_cap.sd) | 495 | if (fimc_capture_active(fimc) || !fimc->vid_cap.sd) |
474 | return -EBUSY; | 496 | return -EBUSY; |
@@ -484,8 +506,7 @@ static int fimc_cap_streamon(struct file *file, void *priv, | |||
484 | static int fimc_cap_streamoff(struct file *file, void *priv, | 506 | static int fimc_cap_streamoff(struct file *file, void *priv, |
485 | enum v4l2_buf_type type) | 507 | enum v4l2_buf_type type) |
486 | { | 508 | { |
487 | struct fimc_ctx *ctx = priv; | 509 | struct fimc_dev *fimc = video_drvdata(file); |
488 | struct fimc_dev *fimc = ctx->fimc_dev; | ||
489 | 510 | ||
490 | return vb2_streamoff(&fimc->vid_cap.vbq, type); | 511 | return vb2_streamoff(&fimc->vid_cap.vbq, type); |
491 | } | 512 | } |
@@ -493,47 +514,43 @@ static int fimc_cap_streamoff(struct file *file, void *priv, | |||
493 | static int fimc_cap_reqbufs(struct file *file, void *priv, | 514 | static int fimc_cap_reqbufs(struct file *file, void *priv, |
494 | struct v4l2_requestbuffers *reqbufs) | 515 | struct v4l2_requestbuffers *reqbufs) |
495 | { | 516 | { |
496 | struct fimc_ctx *ctx = priv; | 517 | struct fimc_dev *fimc = video_drvdata(file); |
497 | struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; | 518 | int ret = vb2_reqbufs(&fimc->vid_cap.vbq, reqbufs); |
498 | int ret; | ||
499 | |||
500 | 519 | ||
501 | ret = vb2_reqbufs(&cap->vbq, reqbufs); | ||
502 | if (!ret) | 520 | if (!ret) |
503 | cap->reqbufs_count = reqbufs->count; | 521 | fimc->vid_cap.reqbufs_count = reqbufs->count; |
504 | |||
505 | return ret; | 522 | return ret; |
506 | } | 523 | } |
507 | 524 | ||
508 | static int fimc_cap_querybuf(struct file *file, void *priv, | 525 | static int fimc_cap_querybuf(struct file *file, void *priv, |
509 | struct v4l2_buffer *buf) | 526 | struct v4l2_buffer *buf) |
510 | { | 527 | { |
511 | struct fimc_ctx *ctx = priv; | 528 | struct fimc_dev *fimc = video_drvdata(file); |
512 | struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; | ||
513 | 529 | ||
514 | return vb2_querybuf(&cap->vbq, buf); | 530 | return vb2_querybuf(&fimc->vid_cap.vbq, buf); |
515 | } | 531 | } |
516 | 532 | ||
517 | static int fimc_cap_qbuf(struct file *file, void *priv, | 533 | static int fimc_cap_qbuf(struct file *file, void *priv, |
518 | struct v4l2_buffer *buf) | 534 | struct v4l2_buffer *buf) |
519 | { | 535 | { |
520 | struct fimc_ctx *ctx = priv; | 536 | struct fimc_dev *fimc = video_drvdata(file); |
521 | struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; | 537 | |
522 | return vb2_qbuf(&cap->vbq, buf); | 538 | return vb2_qbuf(&fimc->vid_cap.vbq, buf); |
523 | } | 539 | } |
524 | 540 | ||
525 | static int fimc_cap_dqbuf(struct file *file, void *priv, | 541 | static int fimc_cap_dqbuf(struct file *file, void *priv, |
526 | struct v4l2_buffer *buf) | 542 | struct v4l2_buffer *buf) |
527 | { | 543 | { |
528 | struct fimc_ctx *ctx = priv; | 544 | struct fimc_dev *fimc = video_drvdata(file); |
529 | return vb2_dqbuf(&ctx->fimc_dev->vid_cap.vbq, buf, | 545 | |
530 | file->f_flags & O_NONBLOCK); | 546 | return vb2_dqbuf(&fimc->vid_cap.vbq, buf, file->f_flags & O_NONBLOCK); |
531 | } | 547 | } |
532 | 548 | ||
533 | static int fimc_cap_s_ctrl(struct file *file, void *priv, | 549 | static int fimc_cap_s_ctrl(struct file *file, void *priv, |
534 | struct v4l2_control *ctrl) | 550 | struct v4l2_control *ctrl) |
535 | { | 551 | { |
536 | struct fimc_ctx *ctx = priv; | 552 | struct fimc_dev *fimc = video_drvdata(file); |
553 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; | ||
537 | int ret = -EINVAL; | 554 | int ret = -EINVAL; |
538 | 555 | ||
539 | /* Allow any controls but 90/270 rotation while streaming */ | 556 | /* Allow any controls but 90/270 rotation while streaming */ |
@@ -556,14 +573,12 @@ static int fimc_cap_s_ctrl(struct file *file, void *priv, | |||
556 | static int fimc_cap_cropcap(struct file *file, void *fh, | 573 | static int fimc_cap_cropcap(struct file *file, void *fh, |
557 | struct v4l2_cropcap *cr) | 574 | struct v4l2_cropcap *cr) |
558 | { | 575 | { |
559 | struct fimc_frame *f; | 576 | struct fimc_dev *fimc = video_drvdata(file); |
560 | struct fimc_ctx *ctx = fh; | 577 | struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; |
561 | 578 | ||
562 | if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | 579 | if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
563 | return -EINVAL; | 580 | return -EINVAL; |
564 | 581 | ||
565 | f = &ctx->s_frame; | ||
566 | |||
567 | cr->bounds.left = 0; | 582 | cr->bounds.left = 0; |
568 | cr->bounds.top = 0; | 583 | cr->bounds.top = 0; |
569 | cr->bounds.width = f->o_width; | 584 | cr->bounds.width = f->o_width; |
@@ -575,10 +590,8 @@ static int fimc_cap_cropcap(struct file *file, void *fh, | |||
575 | 590 | ||
576 | static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) | 591 | static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) |
577 | { | 592 | { |
578 | struct fimc_frame *f; | 593 | struct fimc_dev *fimc = video_drvdata(file); |
579 | struct fimc_ctx *ctx = file->private_data; | 594 | struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; |
580 | |||
581 | f = &ctx->s_frame; | ||
582 | 595 | ||
583 | cr->c.left = f->offs_h; | 596 | cr->c.left = f->offs_h; |
584 | cr->c.top = f->offs_v; | 597 | cr->c.top = f->offs_v; |
@@ -588,12 +601,11 @@ static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) | |||
588 | return 0; | 601 | return 0; |
589 | } | 602 | } |
590 | 603 | ||
591 | static int fimc_cap_s_crop(struct file *file, void *fh, | 604 | static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) |
592 | struct v4l2_crop *cr) | ||
593 | { | 605 | { |
606 | struct fimc_dev *fimc = video_drvdata(file); | ||
607 | struct fimc_ctx *ctx = fimc->vid_cap.ctx; | ||
594 | struct fimc_frame *f; | 608 | struct fimc_frame *f; |
595 | struct fimc_ctx *ctx = file->private_data; | ||
596 | struct fimc_dev *fimc = ctx->fimc_dev; | ||
597 | int ret = -EINVAL; | 609 | int ret = -EINVAL; |
598 | 610 | ||
599 | if (fimc_capture_active(fimc)) | 611 | if (fimc_capture_active(fimc)) |
@@ -631,9 +643,9 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = { | |||
631 | .vidioc_querycap = fimc_vidioc_querycap_capture, | 643 | .vidioc_querycap = fimc_vidioc_querycap_capture, |
632 | 644 | ||
633 | .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane, | 645 | .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane, |
634 | .vidioc_try_fmt_vid_cap_mplane = fimc_vidioc_try_fmt_mplane, | 646 | .vidioc_try_fmt_vid_cap_mplane = fimc_cap_try_fmt_mplane, |
635 | .vidioc_s_fmt_vid_cap_mplane = fimc_cap_s_fmt_mplane, | 647 | .vidioc_s_fmt_vid_cap_mplane = fimc_cap_s_fmt_mplane, |
636 | .vidioc_g_fmt_vid_cap_mplane = fimc_vidioc_g_fmt_mplane, | 648 | .vidioc_g_fmt_vid_cap_mplane = fimc_cap_g_fmt_mplane, |
637 | 649 | ||
638 | .vidioc_reqbufs = fimc_cap_reqbufs, | 650 | .vidioc_reqbufs = fimc_cap_reqbufs, |
639 | .vidioc_querybuf = fimc_cap_querybuf, | 651 | .vidioc_querybuf = fimc_cap_querybuf, |