~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/media/video/cx18/cx18-fileops.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
static void cx18_dualwatch(struct cx18 *cx)
161
161
{
162
162
        struct v4l2_tuner vt;
163
 
        u32 new_bitmap;
164
163
        u32 new_stereo_mode;
165
 
        const u32 stereo_mask = 0x0300;
166
164
        const u32 dual = 0x0200;
167
 
        u32 h;
168
165
 
169
 
        new_stereo_mode = cx->params.audio_properties & stereo_mask;
 
166
        new_stereo_mode = v4l2_ctrl_g_ctrl(cx->cxhdl.audio_mode);
170
167
        memset(&vt, 0, sizeof(vt));
171
168
        cx18_call_all(cx, tuner, g_tuner, &vt);
172
169
        if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 &&
176
173
        if (new_stereo_mode == cx->dualwatch_stereo_mode)
177
174
                return;
178
175
 
179
 
        new_bitmap = new_stereo_mode
180
 
                        | (cx->params.audio_properties & ~stereo_mask);
181
 
 
182
 
        CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. "
183
 
                        "new audio_bitmask=0x%ux\n",
184
 
                        cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
185
 
 
186
 
        h = cx18_find_handle(cx);
187
 
        if (h == CX18_INVALID_TASK_HANDLE) {
188
 
                CX18_DEBUG_INFO("dualwatch: can't find valid task handle\n");
189
 
                return;
190
 
        }
191
 
 
192
 
        if (cx18_vapi(cx,
193
 
                      CX18_CPU_SET_AUDIO_PARAMETERS, 2, h, new_bitmap) == 0) {
194
 
                cx->dualwatch_stereo_mode = new_stereo_mode;
195
 
                return;
196
 
        }
197
 
        CX18_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
 
176
        CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x.\n",
 
177
                           cx->dualwatch_stereo_mode, new_stereo_mode);
 
178
        if (v4l2_ctrl_s_ctrl(cx->cxhdl.audio_mode, new_stereo_mode))
 
179
                CX18_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
198
180
}
199
181
 
200
182
 
603
585
ssize_t cx18_v4l2_read(struct file *filp, char __user *buf, size_t count,
604
586
                loff_t *pos)
605
587
{
606
 
        struct cx18_open_id *id = filp->private_data;
 
588
        struct cx18_open_id *id = file2id(filp);
607
589
        struct cx18 *cx = id->cx;
608
590
        struct cx18_stream *s = &cx->streams[id->type];
609
591
        int rc;
615
597
        mutex_unlock(&cx->serialize_lock);
616
598
        if (rc)
617
599
                return rc;
 
600
 
 
601
        if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
 
602
                (id->type == CX18_ENC_STREAM_TYPE_YUV)) {
 
603
                return videobuf_read_stream(&s->vbuf_q, buf, count, pos, 0,
 
604
                        filp->f_flags & O_NONBLOCK);
 
605
        }
 
606
 
618
607
        return cx18_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK);
619
608
}
620
609
 
621
610
unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait)
622
611
{
623
 
        struct cx18_open_id *id = filp->private_data;
 
612
        struct cx18_open_id *id = file2id(filp);
624
613
        struct cx18 *cx = id->cx;
625
614
        struct cx18_stream *s = &cx->streams[id->type];
626
615
        int eof = test_bit(CX18_F_S_STREAMOFF, &s->s_flags);
640
629
                CX18_DEBUG_FILE("Encoder poll started capture\n");
641
630
        }
642
631
 
 
632
        if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
 
633
                (id->type == CX18_ENC_STREAM_TYPE_YUV)) {
 
634
                int videobuf_poll = videobuf_poll_stream(filp, &s->vbuf_q, wait);
 
635
                if (eof && videobuf_poll == POLLERR)
 
636
                        return POLLHUP;
 
637
                else
 
638
                        return videobuf_poll;
 
639
        }
 
640
 
643
641
        /* add stream's waitq to the poll list */
644
642
        CX18_DEBUG_HI_FILE("Encoder poll\n");
645
643
        poll_wait(filp, &s->waitq, wait);
651
649
        return 0;
652
650
}
653
651
 
 
652
int cx18_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
 
653
{
 
654
        struct cx18_open_id *id = file->private_data;
 
655
        struct cx18 *cx = id->cx;
 
656
        struct cx18_stream *s = &cx->streams[id->type];
 
657
        int eof = test_bit(CX18_F_S_STREAMOFF, &s->s_flags);
 
658
 
 
659
        if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
 
660
                (id->type == CX18_ENC_STREAM_TYPE_YUV)) {
 
661
 
 
662
                /* Start a capture if there is none */
 
663
                if (!eof && !test_bit(CX18_F_S_STREAMING, &s->s_flags)) {
 
664
                        int rc;
 
665
 
 
666
                        mutex_lock(&cx->serialize_lock);
 
667
                        rc = cx18_start_capture(id);
 
668
                        mutex_unlock(&cx->serialize_lock);
 
669
                        if (rc) {
 
670
                                CX18_DEBUG_INFO(
 
671
                                        "Could not start capture for %s (%d)\n",
 
672
                                        s->name, rc);
 
673
                                return -EINVAL;
 
674
                        }
 
675
                        CX18_DEBUG_FILE("Encoder mmap started capture\n");
 
676
                }
 
677
 
 
678
                return videobuf_mmap_mapper(&s->vbuf_q, vma);
 
679
        }
 
680
 
 
681
        return -EINVAL;
 
682
}
 
683
 
 
684
void cx18_vb_timeout(unsigned long data)
 
685
{
 
686
        struct cx18_stream *s = (struct cx18_stream *)data;
 
687
        struct cx18_videobuf_buffer *buf;
 
688
        unsigned long flags;
 
689
 
 
690
        /* Return all of the buffers in error state, so the vbi/vid inode
 
691
         * can return from blocking.
 
692
         */
 
693
        spin_lock_irqsave(&s->vb_lock, flags);
 
694
        while (!list_empty(&s->vb_capture)) {
 
695
                buf = list_entry(s->vb_capture.next,
 
696
                        struct cx18_videobuf_buffer, vb.queue);
 
697
                list_del(&buf->vb.queue);
 
698
                buf->vb.state = VIDEOBUF_ERROR;
 
699
                wake_up(&buf->vb.done);
 
700
        }
 
701
        spin_unlock_irqrestore(&s->vb_lock, flags);
 
702
}
 
703
 
654
704
void cx18_stop_capture(struct cx18_open_id *id, int gop_end)
655
705
{
656
706
        struct cx18 *cx = id->cx;
694
744
 
695
745
int cx18_v4l2_close(struct file *filp)
696
746
{
697
 
        struct cx18_open_id *id = filp->private_data;
 
747
        struct v4l2_fh *fh = filp->private_data;
 
748
        struct cx18_open_id *id = fh2id(fh);
698
749
        struct cx18 *cx = id->cx;
699
750
        struct cx18_stream *s = &cx->streams[id->type];
700
751
 
701
752
        CX18_DEBUG_IOCTL("close() of %s\n", s->name);
702
753
 
703
 
        v4l2_prio_close(&cx->prio, id->prio);
 
754
        v4l2_fh_del(fh);
 
755
        v4l2_fh_exit(fh);
704
756
 
705
757
        /* Easy case first: this stream was never claimed by us */
706
758
        if (s->id != id->open_id) {
724
776
                if (atomic_read(&cx->ana_capturing) > 0) {
725
777
                        /* Undo video mute */
726
778
                        cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle,
727
 
                                cx->params.video_mute |
728
 
                                        (cx->params.video_mute_yuv << 8));
 
779
                            (v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute) |
 
780
                            (v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute_yuv) << 8)));
729
781
                }
730
782
                /* Done! Unmute and continue. */
731
783
                cx18_unmute(cx);
732
784
                cx18_release_stream(s);
733
785
        } else {
734
786
                cx18_stop_capture(id, 0);
 
787
                if (id->type == CX18_ENC_STREAM_TYPE_YUV)
 
788
                        videobuf_mmap_free(&id->vbuf_q);
735
789
        }
736
790
        kfree(id);
737
791
        mutex_unlock(&cx->serialize_lock);
746
800
        CX18_DEBUG_FILE("open %s\n", s->name);
747
801
 
748
802
        /* Allocate memory */
749
 
        item = kmalloc(sizeof(struct cx18_open_id), GFP_KERNEL);
 
803
        item = kzalloc(sizeof(struct cx18_open_id), GFP_KERNEL);
750
804
        if (NULL == item) {
751
805
                CX18_DEBUG_WARN("nomem on v4l2 open\n");
752
806
                return -ENOMEM;
753
807
        }
 
808
        v4l2_fh_init(&item->fh, s->video_dev);
 
809
 
754
810
        item->cx = cx;
755
811
        item->type = s->type;
756
 
        v4l2_prio_open(&cx->prio, &item->prio);
757
812
 
758
813
        item->open_id = cx->open_id++;
759
 
        filp->private_data = item;
 
814
        filp->private_data = &item->fh;
760
815
 
761
816
        if (item->type == CX18_ENC_STREAM_TYPE_RAD) {
762
817
                /* Try to claim this stream */
763
818
                if (cx18_claim_stream(item, item->type)) {
764
819
                        /* No, it's already in use */
 
820
                        v4l2_fh_exit(&item->fh);
765
821
                        kfree(item);
766
822
                        return -EBUSY;
767
823
                }
771
827
                                /* switching to radio while capture is
772
828
                                   in progress is not polite */
773
829
                                cx18_release_stream(s);
 
830
                                v4l2_fh_exit(&item->fh);
774
831
                                kfree(item);
775
832
                                return -EBUSY;
776
833
                        }
787
844
                /* Done! Unmute and continue. */
788
845
                cx18_unmute(cx);
789
846
        }
 
847
        v4l2_fh_add(&item->fh);
790
848
        return 0;
791
849
}
792
850