aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/saa7146_video.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-04-29 15:47:47 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-05-14 13:54:58 -0400
commit6e65ca942b9664a987866ac0c62e7e450777056b (patch)
treefcd78f02819a1d3d0559ab51a8bb87412d911783 /drivers/media/common/saa7146_video.c
parent5becbc58a01f1adaf34703c18287d9f7b46a17f6 (diff)
[media] mxb/saa7146: first round of cleanups
Convert to the control framework, fix the easy v4l2-compliance failures. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/common/saa7146_video.c')
-rw-r--r--drivers/media/common/saa7146_video.c210
1 files changed, 38 insertions, 172 deletions
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index ce30533fd97..8818e661a42 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -202,65 +202,6 @@ int saa7146_stop_preview(struct saa7146_fh *fh)
202EXPORT_SYMBOL_GPL(saa7146_stop_preview); 202EXPORT_SYMBOL_GPL(saa7146_stop_preview);
203 203
204/********************************************************************************/ 204/********************************************************************************/
205/* device controls */
206
207static struct v4l2_queryctrl controls[] = {
208 {
209 .id = V4L2_CID_BRIGHTNESS,
210 .name = "Brightness",
211 .minimum = 0,
212 .maximum = 255,
213 .step = 1,
214 .default_value = 128,
215 .type = V4L2_CTRL_TYPE_INTEGER,
216 .flags = V4L2_CTRL_FLAG_SLIDER,
217 },{
218 .id = V4L2_CID_CONTRAST,
219 .name = "Contrast",
220 .minimum = 0,
221 .maximum = 127,
222 .step = 1,
223 .default_value = 64,
224 .type = V4L2_CTRL_TYPE_INTEGER,
225 .flags = V4L2_CTRL_FLAG_SLIDER,
226 },{
227 .id = V4L2_CID_SATURATION,
228 .name = "Saturation",
229 .minimum = 0,
230 .maximum = 127,
231 .step = 1,
232 .default_value = 64,
233 .type = V4L2_CTRL_TYPE_INTEGER,
234 .flags = V4L2_CTRL_FLAG_SLIDER,
235 },{
236 .id = V4L2_CID_VFLIP,
237 .name = "Vertical Flip",
238 .minimum = 0,
239 .maximum = 1,
240 .type = V4L2_CTRL_TYPE_BOOLEAN,
241 },{
242 .id = V4L2_CID_HFLIP,
243 .name = "Horizontal Flip",
244 .minimum = 0,
245 .maximum = 1,
246 .type = V4L2_CTRL_TYPE_BOOLEAN,
247 },
248};
249static int NUM_CONTROLS = sizeof(controls)/sizeof(struct v4l2_queryctrl);
250
251#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 0)
252
253static struct v4l2_queryctrl* ctrl_by_id(int id)
254{
255 int i;
256
257 for (i = 0; i < NUM_CONTROLS; i++)
258 if (controls[i].id == id)
259 return controls+i;
260 return NULL;
261}
262
263/********************************************************************************/
264/* common pagetable functions */ 205/* common pagetable functions */
265 206
266static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *buf) 207static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *buf)
@@ -510,12 +451,13 @@ static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *
510 strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card)); 451 strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card));
511 sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci)); 452 sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci));
512 cap->version = SAA7146_VERSION_CODE; 453 cap->version = SAA7146_VERSION_CODE;
513 cap->capabilities = 454 cap->device_caps =
514 V4L2_CAP_VIDEO_CAPTURE | 455 V4L2_CAP_VIDEO_CAPTURE |
515 V4L2_CAP_VIDEO_OVERLAY | 456 V4L2_CAP_VIDEO_OVERLAY |
516 V4L2_CAP_READWRITE | 457 V4L2_CAP_READWRITE |
517 V4L2_CAP_STREAMING; 458 V4L2_CAP_STREAMING;
518 cap->capabilities |= dev->ext_vv_data->capabilities; 459 cap->device_caps |= dev->ext_vv_data->capabilities;
460 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
519 return 0; 461 return 0;
520} 462}
521 463
@@ -579,135 +521,58 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtd
579 return 0; 521 return 0;
580} 522}
581 523
582static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *c) 524int saa7146_s_ctrl(struct v4l2_ctrl *ctrl)
583{
584 const struct v4l2_queryctrl *ctrl;
585
586 if ((c->id < V4L2_CID_BASE ||
587 c->id >= V4L2_CID_LASTP1) &&
588 (c->id < V4L2_CID_PRIVATE_BASE ||
589 c->id >= V4L2_CID_PRIVATE_LASTP1))
590 return -EINVAL;
591
592 ctrl = ctrl_by_id(c->id);
593 if (ctrl == NULL)
594 return -EINVAL;
595
596 DEB_EE("VIDIOC_QUERYCTRL: id:%d\n", c->id);
597 *c = *ctrl;
598 return 0;
599}
600
601static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
602{ 525{
603 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 526 struct saa7146_dev *dev = container_of(ctrl->handler,
527 struct saa7146_dev, ctrl_handler);
604 struct saa7146_vv *vv = dev->vv_data; 528 struct saa7146_vv *vv = dev->vv_data;
605 const struct v4l2_queryctrl *ctrl; 529 u32 val;
606 u32 value = 0;
607 530
608 ctrl = ctrl_by_id(c->id); 531 switch (ctrl->id) {
609 if (NULL == ctrl)
610 return -EINVAL;
611 switch (c->id) {
612 case V4L2_CID_BRIGHTNESS: 532 case V4L2_CID_BRIGHTNESS:
613 value = saa7146_read(dev, BCS_CTRL); 533 val = saa7146_read(dev, BCS_CTRL);
614 c->value = 0xff & (value >> 24); 534 val &= 0x00ffffff;
615 DEB_D("V4L2_CID_BRIGHTNESS: %d\n", c->value); 535 val |= (ctrl->val << 24);
616 break; 536 saa7146_write(dev, BCS_CTRL, val);
617 case V4L2_CID_CONTRAST:
618 value = saa7146_read(dev, BCS_CTRL);
619 c->value = 0x7f & (value >> 16);
620 DEB_D("V4L2_CID_CONTRAST: %d\n", c->value);
621 break;
622 case V4L2_CID_SATURATION:
623 value = saa7146_read(dev, BCS_CTRL);
624 c->value = 0x7f & (value >> 0);
625 DEB_D("V4L2_CID_SATURATION: %d\n", c->value);
626 break;
627 case V4L2_CID_VFLIP:
628 c->value = vv->vflip;
629 DEB_D("V4L2_CID_VFLIP: %d\n", c->value);
630 break;
631 case V4L2_CID_HFLIP:
632 c->value = vv->hflip;
633 DEB_D("V4L2_CID_HFLIP: %d\n", c->value);
634 break;
635 default:
636 return -EINVAL;
637 }
638 return 0;
639}
640
641static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
642{
643 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
644 struct saa7146_vv *vv = dev->vv_data;
645 const struct v4l2_queryctrl *ctrl;
646
647 ctrl = ctrl_by_id(c->id);
648 if (NULL == ctrl) {
649 DEB_D("unknown control %d\n", c->id);
650 return -EINVAL;
651 }
652
653 switch (ctrl->type) {
654 case V4L2_CTRL_TYPE_BOOLEAN:
655 case V4L2_CTRL_TYPE_MENU:
656 case V4L2_CTRL_TYPE_INTEGER:
657 if (c->value < ctrl->minimum)
658 c->value = ctrl->minimum;
659 if (c->value > ctrl->maximum)
660 c->value = ctrl->maximum;
661 break;
662 default:
663 /* nothing */;
664 }
665
666 switch (c->id) {
667 case V4L2_CID_BRIGHTNESS: {
668 u32 value = saa7146_read(dev, BCS_CTRL);
669 value &= 0x00ffffff;
670 value |= (c->value << 24);
671 saa7146_write(dev, BCS_CTRL, value);
672 saa7146_write(dev, MC2, MASK_22 | MASK_06); 537 saa7146_write(dev, MC2, MASK_22 | MASK_06);
673 break; 538 break;
674 } 539
675 case V4L2_CID_CONTRAST: { 540 case V4L2_CID_CONTRAST:
676 u32 value = saa7146_read(dev, BCS_CTRL); 541 val = saa7146_read(dev, BCS_CTRL);
677 value &= 0xff00ffff; 542 val &= 0xff00ffff;
678 value |= (c->value << 16); 543 val |= (ctrl->val << 16);
679 saa7146_write(dev, BCS_CTRL, value); 544 saa7146_write(dev, BCS_CTRL, val);
680 saa7146_write(dev, MC2, MASK_22 | MASK_06); 545 saa7146_write(dev, MC2, MASK_22 | MASK_06);
681 break; 546 break;
682 } 547
683 case V4L2_CID_SATURATION: { 548 case V4L2_CID_SATURATION:
684 u32 value = saa7146_read(dev, BCS_CTRL); 549 val = saa7146_read(dev, BCS_CTRL);
685 value &= 0xffffff00; 550 val &= 0xffffff00;
686 value |= (c->value << 0); 551 val |= (ctrl->val << 0);
687 saa7146_write(dev, BCS_CTRL, value); 552 saa7146_write(dev, BCS_CTRL, val);
688 saa7146_write(dev, MC2, MASK_22 | MASK_06); 553 saa7146_write(dev, MC2, MASK_22 | MASK_06);
689 break; 554 break;
690 } 555
691 case V4L2_CID_HFLIP: 556 case V4L2_CID_HFLIP:
692 /* fixme: we can support changing VFLIP and HFLIP here... */ 557 /* fixme: we can support changing VFLIP and HFLIP here... */
693 if (IS_CAPTURE_ACTIVE(fh) != 0) { 558 if ((vv->video_status & STATUS_CAPTURE))
694 DEB_D("V4L2_CID_HFLIP while active capture\n");
695 return -EBUSY; 559 return -EBUSY;
696 } 560 vv->hflip = ctrl->val;
697 vv->hflip = c->value;
698 break; 561 break;
562
699 case V4L2_CID_VFLIP: 563 case V4L2_CID_VFLIP:
700 if (IS_CAPTURE_ACTIVE(fh) != 0) { 564 if ((vv->video_status & STATUS_CAPTURE))
701 DEB_D("V4L2_CID_VFLIP while active capture\n");
702 return -EBUSY; 565 return -EBUSY;
703 } 566 vv->vflip = ctrl->val;
704 vv->vflip = c->value;
705 break; 567 break;
568
706 default: 569 default:
707 return -EINVAL; 570 return -EINVAL;
708 } 571 }
709 572
710 if (IS_OVERLAY_ACTIVE(fh) != 0) { 573 if ((vv->video_status & STATUS_OVERLAY) != 0) { /* CHECK: && (vv->video_fh == fh)) */
574 struct saa7146_fh *fh = vv->video_fh;
575
711 saa7146_stop_preview(fh); 576 saa7146_stop_preview(fh);
712 saa7146_start_preview(fh); 577 saa7146_start_preview(fh);
713 } 578 }
@@ -720,6 +585,8 @@ static int vidioc_g_parm(struct file *file, void *fh,
720 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 585 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
721 struct saa7146_vv *vv = dev->vv_data; 586 struct saa7146_vv *vv = dev->vv_data;
722 587
588 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
589 return -EINVAL;
723 parm->parm.capture.readbuffers = 1; 590 parm->parm.capture.readbuffers = 1;
724 v4l2_video_std_frame_period(vv->standard->id, 591 v4l2_video_std_frame_period(vv->standard->id,
725 &parm->parm.capture.timeperframe); 592 &parm->parm.capture.timeperframe);
@@ -787,6 +654,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
787 } 654 }
788 655
789 f->fmt.pix.field = field; 656 f->fmt.pix.field = field;
657 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
790 if (f->fmt.pix.width > maxw) 658 if (f->fmt.pix.width > maxw)
791 f->fmt.pix.width = maxw; 659 f->fmt.pix.width = maxw;
792 if (f->fmt.pix.height > maxh) 660 if (f->fmt.pix.height > maxh)
@@ -1141,9 +1009,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1141 .vidioc_dqbuf = vidioc_dqbuf, 1009 .vidioc_dqbuf = vidioc_dqbuf,
1142 .vidioc_g_std = vidioc_g_std, 1010 .vidioc_g_std = vidioc_g_std,
1143 .vidioc_s_std = vidioc_s_std, 1011 .vidioc_s_std = vidioc_s_std,
1144 .vidioc_queryctrl = vidioc_queryctrl,
1145 .vidioc_g_ctrl = vidioc_g_ctrl,
1146 .vidioc_s_ctrl = vidioc_s_ctrl,
1147 .vidioc_streamon = vidioc_streamon, 1012 .vidioc_streamon = vidioc_streamon,
1148 .vidioc_streamoff = vidioc_streamoff, 1013 .vidioc_streamoff = vidioc_streamoff,
1149 .vidioc_g_parm = vidioc_g_parm, 1014 .vidioc_g_parm = vidioc_g_parm,
@@ -1338,6 +1203,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1338 fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24; 1203 fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24;
1339 fh->video_fmt.bytesperline = 0; 1204 fh->video_fmt.bytesperline = 0;
1340 fh->video_fmt.field = V4L2_FIELD_ANY; 1205 fh->video_fmt.field = V4L2_FIELD_ANY;
1206 fh->video_fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
1341 sfmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat); 1207 sfmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat);
1342 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8; 1208 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8;
1343 1209