diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-05-08 14:20:21 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-05-20 07:43:18 -0400 |
commit | 34caed8b3a1ec07a5b8fde42b7c4784aa2fb9440 (patch) | |
tree | 18f6aaea2e21274991f42b693c9c4b765424b14a | |
parent | 5fa1a89d37efa35b80d51a70b89aaa8cf54ab180 (diff) |
[media] c-qcam: convert to the latest frameworks
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/c-qcam.c | 137 |
1 files changed, 65 insertions, 72 deletions
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c index 73c65c2bf178..ec51e1f12e82 100644 --- a/drivers/media/video/c-qcam.c +++ b/drivers/media/video/c-qcam.c | |||
@@ -40,10 +40,14 @@ | |||
40 | #include <media/v4l2-device.h> | 40 | #include <media/v4l2-device.h> |
41 | #include <media/v4l2-common.h> | 41 | #include <media/v4l2-common.h> |
42 | #include <media/v4l2-ioctl.h> | 42 | #include <media/v4l2-ioctl.h> |
43 | #include <media/v4l2-fh.h> | ||
44 | #include <media/v4l2-ctrls.h> | ||
45 | #include <media/v4l2-event.h> | ||
43 | 46 | ||
44 | struct qcam { | 47 | struct qcam { |
45 | struct v4l2_device v4l2_dev; | 48 | struct v4l2_device v4l2_dev; |
46 | struct video_device vdev; | 49 | struct video_device vdev; |
50 | struct v4l2_ctrl_handler hdl; | ||
47 | struct pardevice *pdev; | 51 | struct pardevice *pdev; |
48 | struct parport *pport; | 52 | struct parport *pport; |
49 | int width, height; | 53 | int width, height; |
@@ -515,7 +519,8 @@ static int qcam_querycap(struct file *file, void *priv, | |||
515 | strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver)); | 519 | strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver)); |
516 | strlcpy(vcap->card, "Color Quickcam", sizeof(vcap->card)); | 520 | strlcpy(vcap->card, "Color Quickcam", sizeof(vcap->card)); |
517 | strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info)); | 521 | strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info)); |
518 | vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; | 522 | vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; |
523 | vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS; | ||
519 | return 0; | 524 | return 0; |
520 | } | 525 | } |
521 | 526 | ||
@@ -543,73 +548,6 @@ static int qcam_s_input(struct file *file, void *fh, unsigned int inp) | |||
543 | return (inp > 0) ? -EINVAL : 0; | 548 | return (inp > 0) ? -EINVAL : 0; |
544 | } | 549 | } |
545 | 550 | ||
546 | static int qcam_queryctrl(struct file *file, void *priv, | ||
547 | struct v4l2_queryctrl *qc) | ||
548 | { | ||
549 | switch (qc->id) { | ||
550 | case V4L2_CID_BRIGHTNESS: | ||
551 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 240); | ||
552 | case V4L2_CID_CONTRAST: | ||
553 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 192); | ||
554 | case V4L2_CID_GAMMA: | ||
555 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); | ||
556 | } | ||
557 | return -EINVAL; | ||
558 | } | ||
559 | |||
560 | static int qcam_g_ctrl(struct file *file, void *priv, | ||
561 | struct v4l2_control *ctrl) | ||
562 | { | ||
563 | struct qcam *qcam = video_drvdata(file); | ||
564 | int ret = 0; | ||
565 | |||
566 | switch (ctrl->id) { | ||
567 | case V4L2_CID_BRIGHTNESS: | ||
568 | ctrl->value = qcam->brightness; | ||
569 | break; | ||
570 | case V4L2_CID_CONTRAST: | ||
571 | ctrl->value = qcam->contrast; | ||
572 | break; | ||
573 | case V4L2_CID_GAMMA: | ||
574 | ctrl->value = qcam->whitebal; | ||
575 | break; | ||
576 | default: | ||
577 | ret = -EINVAL; | ||
578 | break; | ||
579 | } | ||
580 | return ret; | ||
581 | } | ||
582 | |||
583 | static int qcam_s_ctrl(struct file *file, void *priv, | ||
584 | struct v4l2_control *ctrl) | ||
585 | { | ||
586 | struct qcam *qcam = video_drvdata(file); | ||
587 | int ret = 0; | ||
588 | |||
589 | mutex_lock(&qcam->lock); | ||
590 | switch (ctrl->id) { | ||
591 | case V4L2_CID_BRIGHTNESS: | ||
592 | qcam->brightness = ctrl->value; | ||
593 | break; | ||
594 | case V4L2_CID_CONTRAST: | ||
595 | qcam->contrast = ctrl->value; | ||
596 | break; | ||
597 | case V4L2_CID_GAMMA: | ||
598 | qcam->whitebal = ctrl->value; | ||
599 | break; | ||
600 | default: | ||
601 | ret = -EINVAL; | ||
602 | break; | ||
603 | } | ||
604 | if (ret == 0) { | ||
605 | parport_claim_or_block(qcam->pdev); | ||
606 | qc_setup(qcam); | ||
607 | parport_release(qcam->pdev); | ||
608 | } | ||
609 | mutex_unlock(&qcam->lock); | ||
610 | return ret; | ||
611 | } | ||
612 | |||
613 | static int qcam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt) | 551 | static int qcam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
614 | { | 552 | { |
615 | struct qcam *qcam = video_drvdata(file); | 553 | struct qcam *qcam = video_drvdata(file); |
@@ -713,8 +651,41 @@ static ssize_t qcam_read(struct file *file, char __user *buf, | |||
713 | return len; | 651 | return len; |
714 | } | 652 | } |
715 | 653 | ||
654 | static int qcam_s_ctrl(struct v4l2_ctrl *ctrl) | ||
655 | { | ||
656 | struct qcam *qcam = | ||
657 | container_of(ctrl->handler, struct qcam, hdl); | ||
658 | int ret = 0; | ||
659 | |||
660 | mutex_lock(&qcam->lock); | ||
661 | switch (ctrl->id) { | ||
662 | case V4L2_CID_BRIGHTNESS: | ||
663 | qcam->brightness = ctrl->val; | ||
664 | break; | ||
665 | case V4L2_CID_CONTRAST: | ||
666 | qcam->contrast = ctrl->val; | ||
667 | break; | ||
668 | case V4L2_CID_GAMMA: | ||
669 | qcam->whitebal = ctrl->val; | ||
670 | break; | ||
671 | default: | ||
672 | ret = -EINVAL; | ||
673 | break; | ||
674 | } | ||
675 | if (ret == 0) { | ||
676 | parport_claim_or_block(qcam->pdev); | ||
677 | qc_setup(qcam); | ||
678 | parport_release(qcam->pdev); | ||
679 | } | ||
680 | mutex_unlock(&qcam->lock); | ||
681 | return ret; | ||
682 | } | ||
683 | |||
716 | static const struct v4l2_file_operations qcam_fops = { | 684 | static const struct v4l2_file_operations qcam_fops = { |
717 | .owner = THIS_MODULE, | 685 | .owner = THIS_MODULE, |
686 | .open = v4l2_fh_open, | ||
687 | .release = v4l2_fh_release, | ||
688 | .poll = v4l2_ctrl_poll, | ||
718 | .unlocked_ioctl = video_ioctl2, | 689 | .unlocked_ioctl = video_ioctl2, |
719 | .read = qcam_read, | 690 | .read = qcam_read, |
720 | }; | 691 | }; |
@@ -724,13 +695,17 @@ static const struct v4l2_ioctl_ops qcam_ioctl_ops = { | |||
724 | .vidioc_g_input = qcam_g_input, | 695 | .vidioc_g_input = qcam_g_input, |
725 | .vidioc_s_input = qcam_s_input, | 696 | .vidioc_s_input = qcam_s_input, |
726 | .vidioc_enum_input = qcam_enum_input, | 697 | .vidioc_enum_input = qcam_enum_input, |
727 | .vidioc_queryctrl = qcam_queryctrl, | 698 | .vidioc_enum_fmt_vid_cap = qcam_enum_fmt_vid_cap, |
728 | .vidioc_g_ctrl = qcam_g_ctrl, | ||
729 | .vidioc_s_ctrl = qcam_s_ctrl, | ||
730 | .vidioc_enum_fmt_vid_cap = qcam_enum_fmt_vid_cap, | ||
731 | .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap, | 699 | .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap, |
732 | .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap, | 700 | .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap, |
733 | .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap, | 701 | .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap, |
702 | .vidioc_log_status = v4l2_ctrl_log_status, | ||
703 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, | ||
704 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, | ||
705 | }; | ||
706 | |||
707 | static const struct v4l2_ctrl_ops qcam_ctrl_ops = { | ||
708 | .s_ctrl = qcam_s_ctrl, | ||
734 | }; | 709 | }; |
735 | 710 | ||
736 | /* Initialize the QuickCam driver control structure. */ | 711 | /* Initialize the QuickCam driver control structure. */ |
@@ -753,6 +728,20 @@ static struct qcam *qcam_init(struct parport *port) | |||
753 | return NULL; | 728 | return NULL; |
754 | } | 729 | } |
755 | 730 | ||
731 | v4l2_ctrl_handler_init(&qcam->hdl, 3); | ||
732 | v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops, | ||
733 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 240); | ||
734 | v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops, | ||
735 | V4L2_CID_CONTRAST, 0, 255, 1, 192); | ||
736 | v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops, | ||
737 | V4L2_CID_GAMMA, 0, 255, 1, 128); | ||
738 | if (qcam->hdl.error) { | ||
739 | v4l2_err(v4l2_dev, "couldn't register controls\n"); | ||
740 | v4l2_ctrl_handler_free(&qcam->hdl); | ||
741 | kfree(qcam); | ||
742 | return NULL; | ||
743 | } | ||
744 | |||
756 | qcam->pport = port; | 745 | qcam->pport = port; |
757 | qcam->pdev = parport_register_device(port, "c-qcam", NULL, NULL, | 746 | qcam->pdev = parport_register_device(port, "c-qcam", NULL, NULL, |
758 | NULL, 0, NULL); | 747 | NULL, 0, NULL); |
@@ -761,6 +750,7 @@ static struct qcam *qcam_init(struct parport *port) | |||
761 | 750 | ||
762 | if (qcam->pdev == NULL) { | 751 | if (qcam->pdev == NULL) { |
763 | v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name); | 752 | v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name); |
753 | v4l2_ctrl_handler_free(&qcam->hdl); | ||
764 | kfree(qcam); | 754 | kfree(qcam); |
765 | return NULL; | 755 | return NULL; |
766 | } | 756 | } |
@@ -770,6 +760,8 @@ static struct qcam *qcam_init(struct parport *port) | |||
770 | qcam->vdev.fops = &qcam_fops; | 760 | qcam->vdev.fops = &qcam_fops; |
771 | qcam->vdev.ioctl_ops = &qcam_ioctl_ops; | 761 | qcam->vdev.ioctl_ops = &qcam_ioctl_ops; |
772 | qcam->vdev.release = video_device_release_empty; | 762 | qcam->vdev.release = video_device_release_empty; |
763 | qcam->vdev.ctrl_handler = &qcam->hdl; | ||
764 | set_bit(V4L2_FL_USE_FH_PRIO, &qcam->vdev.flags); | ||
773 | video_set_drvdata(&qcam->vdev, qcam); | 765 | video_set_drvdata(&qcam->vdev, qcam); |
774 | 766 | ||
775 | mutex_init(&qcam->lock); | 767 | mutex_init(&qcam->lock); |
@@ -844,6 +836,7 @@ static int init_cqcam(struct parport *port) | |||
844 | static void close_cqcam(struct qcam *qcam) | 836 | static void close_cqcam(struct qcam *qcam) |
845 | { | 837 | { |
846 | video_unregister_device(&qcam->vdev); | 838 | video_unregister_device(&qcam->vdev); |
839 | v4l2_ctrl_handler_free(&qcam->hdl); | ||
847 | parport_unregister_device(qcam->pdev); | 840 | parport_unregister_device(qcam->pdev); |
848 | kfree(qcam); | 841 | kfree(qcam); |
849 | } | 842 | } |