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

« back to all changes in this revision

Viewing changes to drivers/media/video/ivtv/ivtv-ioctl.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:
313
313
 
314
314
static int ivtv_g_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
315
315
{
316
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
316
        struct ivtv *itv = fh2id(fh)->itv;
317
317
        struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
318
318
 
319
319
        vbifmt->reserved[0] = 0;
334
334
 
335
335
static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
336
336
{
337
 
        struct ivtv_open_id *id = fh;
 
337
        struct ivtv_open_id *id = fh2id(fh);
338
338
        struct ivtv *itv = id->itv;
339
339
        struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
340
340
 
358
358
 
359
359
static int ivtv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
360
360
{
361
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
361
        struct ivtv *itv = fh2id(fh)->itv;
362
362
        struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
363
363
 
364
364
        vbifmt->sampling_rate = 27000000;
377
377
static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
378
378
{
379
379
        struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
380
 
        struct ivtv_open_id *id = fh;
 
380
        struct ivtv_open_id *id = fh2id(fh);
381
381
        struct ivtv *itv = id->itv;
382
382
 
383
383
        vbifmt->reserved[0] = 0;
398
398
 
399
399
static int ivtv_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
400
400
{
401
 
        struct ivtv_open_id *id = fh;
 
401
        struct ivtv_open_id *id = fh2id(fh);
402
402
        struct ivtv *itv = id->itv;
403
403
        struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
404
404
 
439
439
 
440
440
static int ivtv_g_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
441
441
{
442
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
442
        struct ivtv *itv = fh2id(fh)->itv;
443
443
        struct v4l2_window *winfmt = &fmt->fmt.win;
444
444
 
445
445
        if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
463
463
 
464
464
static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
465
465
{
466
 
        struct ivtv_open_id *id = fh;
 
466
        struct ivtv_open_id *id = fh2id(fh);
467
467
        struct ivtv *itv = id->itv;
468
468
        int w = fmt->fmt.pix.width;
469
469
        int h = fmt->fmt.pix.height;
492
492
static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
493
493
{
494
494
        struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
495
 
        struct ivtv_open_id *id = fh;
 
495
        struct ivtv_open_id *id = fh2id(fh);
496
496
        struct ivtv *itv = id->itv;
497
497
 
498
498
        if (id->type == IVTV_DEC_STREAM_TYPE_VBI)
512
512
 
513
513
static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
514
514
{
515
 
        struct ivtv_open_id *id = fh;
 
515
        struct ivtv_open_id *id = fh2id(fh);
516
516
        s32 w = fmt->fmt.pix.width;
517
517
        s32 h = fmt->fmt.pix.height;
518
518
        int field = fmt->fmt.pix.field;
546
546
 
547
547
static int ivtv_try_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
548
548
{
549
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
549
        struct ivtv *itv = fh2id(fh)->itv;
550
550
        u32 chromakey = fmt->fmt.win.chromakey;
551
551
        u8 global_alpha = fmt->fmt.win.global_alpha;
552
552
 
565
565
 
566
566
static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
567
567
{
568
 
        struct ivtv_open_id *id = fh;
 
568
        struct ivtv_open_id *id = fh2id(fh);
569
569
        struct ivtv *itv = id->itv;
570
570
        struct v4l2_mbus_framefmt mbus_fmt;
571
571
        int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
594
594
 
595
595
static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
596
596
{
597
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
597
        struct ivtv *itv = fh2id(fh)->itv;
598
598
 
599
599
        if (!ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
600
600
                return -EBUSY;
607
607
static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
608
608
{
609
609
        struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
610
 
        struct ivtv_open_id *id = fh;
 
610
        struct ivtv_open_id *id = fh2id(fh);
611
611
        struct ivtv *itv = id->itv;
612
612
        int ret = ivtv_try_fmt_sliced_vbi_cap(file, fh, fmt);
613
613
 
625
625
 
626
626
static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
627
627
{
628
 
        struct ivtv_open_id *id = fh;
 
628
        struct ivtv_open_id *id = fh2id(fh);
629
629
        struct ivtv *itv = id->itv;
630
630
        struct yuv_playback_info *yi = &itv->yuv_info;
631
631
        int ret = ivtv_try_fmt_vid_out(file, fh, fmt);
670
670
 
671
671
static int ivtv_s_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
672
672
{
673
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
673
        struct ivtv *itv = fh2id(fh)->itv;
674
674
        int ret = ivtv_try_fmt_vid_out_overlay(file, fh, fmt);
675
675
 
676
676
        if (ret == 0) {
683
683
 
684
684
static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip)
685
685
{
686
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
686
        struct ivtv *itv = fh2id(fh)->itv;
687
687
 
688
688
        chip->ident = V4L2_IDENT_NONE;
689
689
        chip->revision = 0;
727
727
 
728
728
static int ivtv_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
729
729
{
730
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
730
        struct ivtv *itv = fh2id(fh)->itv;
731
731
 
732
732
        if (v4l2_chip_match_host(&reg->match))
733
733
                return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg);
739
739
 
740
740
static int ivtv_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
741
741
{
742
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
742
        struct ivtv *itv = fh2id(fh)->itv;
743
743
 
744
744
        if (v4l2_chip_match_host(&reg->match))
745
745
                return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg);
750
750
}
751
751
#endif
752
752
 
753
 
static int ivtv_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
754
 
{
755
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
756
 
 
757
 
        *p = v4l2_prio_max(&itv->prio);
758
 
 
759
 
        return 0;
760
 
}
761
 
 
762
 
static int ivtv_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
763
 
{
764
 
        struct ivtv_open_id *id = fh;
765
 
        struct ivtv *itv = id->itv;
766
 
 
767
 
        return v4l2_prio_change(&itv->prio, &id->prio, prio);
768
 
}
769
 
 
770
753
static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vcap)
771
754
{
772
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
755
        struct ivtv *itv = fh2id(fh)->itv;
773
756
 
774
757
        strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
775
758
        strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
781
764
 
782
765
static int ivtv_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
783
766
{
784
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
767
        struct ivtv *itv = fh2id(fh)->itv;
785
768
 
786
769
        return ivtv_get_audio_input(itv, vin->index, vin);
787
770
}
788
771
 
789
772
static int ivtv_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
790
773
{
791
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
774
        struct ivtv *itv = fh2id(fh)->itv;
792
775
 
793
776
        vin->index = itv->audio_input;
794
777
        return ivtv_get_audio_input(itv, vin->index, vin);
796
779
 
797
780
static int ivtv_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
798
781
{
799
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
782
        struct ivtv *itv = fh2id(fh)->itv;
800
783
 
801
784
        if (vout->index >= itv->nof_audio_inputs)
802
785
                return -EINVAL;
809
792
 
810
793
static int ivtv_enumaudout(struct file *file, void *fh, struct v4l2_audioout *vin)
811
794
{
812
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
795
        struct ivtv *itv = fh2id(fh)->itv;
813
796
 
814
797
        /* set it to defaults from our table */
815
798
        return ivtv_get_audio_output(itv, vin->index, vin);
817
800
 
818
801
static int ivtv_g_audout(struct file *file, void *fh, struct v4l2_audioout *vin)
819
802
{
820
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
803
        struct ivtv *itv = fh2id(fh)->itv;
821
804
 
822
805
        vin->index = 0;
823
806
        return ivtv_get_audio_output(itv, vin->index, vin);
825
808
 
826
809
static int ivtv_s_audout(struct file *file, void *fh, struct v4l2_audioout *vout)
827
810
{
828
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
811
        struct ivtv *itv = fh2id(fh)->itv;
829
812
 
830
813
        return ivtv_get_audio_output(itv, vout->index, vout);
831
814
}
832
815
 
833
816
static int ivtv_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
834
817
{
835
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
818
        struct ivtv *itv = fh2id(fh)->itv;
836
819
 
837
820
        /* set it to defaults from our table */
838
821
        return ivtv_get_input(itv, vin->index, vin);
840
823
 
841
824
static int ivtv_enum_output(struct file *file, void *fh, struct v4l2_output *vout)
842
825
{
843
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
826
        struct ivtv *itv = fh2id(fh)->itv;
844
827
 
845
828
        return ivtv_get_output(itv, vout->index, vout);
846
829
}
847
830
 
848
831
static int ivtv_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
849
832
{
850
 
        struct ivtv_open_id *id = fh;
 
833
        struct ivtv_open_id *id = fh2id(fh);
851
834
        struct ivtv *itv = id->itv;
852
835
        struct yuv_playback_info *yi = &itv->yuv_info;
853
836
        int streamtype;
884
867
 
885
868
static int ivtv_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
886
869
{
887
 
        struct ivtv_open_id *id = fh;
 
870
        struct ivtv_open_id *id = fh2id(fh);
888
871
        struct ivtv *itv = id->itv;
889
872
        struct yuv_playback_info *yi = &itv->yuv_info;
890
873
        int streamtype;
910
893
 
911
894
static int ivtv_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
912
895
{
913
 
        struct ivtv_open_id *id = fh;
 
896
        struct ivtv_open_id *id = fh2id(fh);
914
897
        struct ivtv *itv = id->itv;
915
898
        struct yuv_playback_info *yi = &itv->yuv_info;
916
899
        int streamtype;
952
935
 
953
936
static int ivtv_enum_fmt_vid_out(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
954
937
{
955
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
938
        struct ivtv *itv = fh2id(fh)->itv;
956
939
 
957
940
        static struct v4l2_fmtdesc formats[] = {
958
941
                { 0, 0, 0,
980
963
 
981
964
static int ivtv_g_input(struct file *file, void *fh, unsigned int *i)
982
965
{
983
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
966
        struct ivtv *itv = fh2id(fh)->itv;
984
967
 
985
968
        *i = itv->active_input;
986
969
 
989
972
 
990
973
int ivtv_s_input(struct file *file, void *fh, unsigned int inp)
991
974
{
992
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
975
        struct ivtv *itv = fh2id(fh)->itv;
993
976
 
994
977
        if (inp < 0 || inp >= itv->nof_inputs)
995
978
                return -EINVAL;
1023
1006
 
1024
1007
static int ivtv_g_output(struct file *file, void *fh, unsigned int *i)
1025
1008
{
1026
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1009
        struct ivtv *itv = fh2id(fh)->itv;
1027
1010
 
1028
1011
        if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1029
1012
                return -EINVAL;
1035
1018
 
1036
1019
static int ivtv_s_output(struct file *file, void *fh, unsigned int outp)
1037
1020
{
1038
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1021
        struct ivtv *itv = fh2id(fh)->itv;
1039
1022
 
1040
1023
        if (outp >= itv->card->nof_outputs)
1041
1024
                return -EINVAL;
1057
1040
 
1058
1041
static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1059
1042
{
1060
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1043
        struct ivtv *itv = fh2id(fh)->itv;
1061
1044
 
1062
1045
        if (vf->tuner != 0)
1063
1046
                return -EINVAL;
1068
1051
 
1069
1052
int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1070
1053
{
1071
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1054
        struct ivtv *itv = fh2id(fh)->itv;
1072
1055
 
1073
1056
        if (vf->tuner != 0)
1074
1057
                return -EINVAL;
1082
1065
 
1083
1066
static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std)
1084
1067
{
1085
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1068
        struct ivtv *itv = fh2id(fh)->itv;
1086
1069
 
1087
1070
        *std = itv->std;
1088
1071
        return 0;
1089
1072
}
1090
1073
 
1091
 
int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
 
1074
void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id *std)
1092
1075
{
1093
 
        DEFINE_WAIT(wait);
1094
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1095
 
        struct yuv_playback_info *yi = &itv->yuv_info;
1096
 
        int f;
1097
 
 
1098
 
        if ((*std & V4L2_STD_ALL) == 0)
1099
 
                return -EINVAL;
1100
 
 
1101
 
        if (*std == itv->std)
1102
 
                return 0;
1103
 
 
1104
 
        if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
1105
 
            atomic_read(&itv->capturing) > 0 ||
1106
 
            atomic_read(&itv->decoding) > 0) {
1107
 
                /* Switching standard would turn off the radio or mess
1108
 
                   with already running streams, prevent that by
1109
 
                   returning EBUSY. */
1110
 
                return -EBUSY;
1111
 
        }
1112
 
 
1113
1076
        itv->std = *std;
1114
1077
        itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
1115
1078
        itv->is_50hz = !itv->is_60hz;
1123
1086
        if (itv->hw_flags & IVTV_HW_CX25840)
1124
1087
                itv->vbi.sliced_decoder_line_size = itv->is_60hz ? 272 : 284;
1125
1088
 
1126
 
        IVTV_DEBUG_INFO("Switching standard to %llx.\n", (unsigned long long)itv->std);
1127
 
 
1128
1089
        /* Tuner */
1129
1090
        ivtv_call_all(itv, core, s_std, itv->std);
1130
 
 
1131
 
        if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1132
 
                /* set display standard */
1133
 
                itv->std_out = *std;
1134
 
                itv->is_out_60hz = itv->is_60hz;
1135
 
                itv->is_out_50hz = itv->is_50hz;
1136
 
                ivtv_call_all(itv, video, s_std_output, itv->std_out);
1137
 
 
1138
 
                /*
1139
 
                 * The next firmware call is time sensitive. Time it to
1140
 
                 * avoid risk of a hard lock, by trying to ensure the call
1141
 
                 * happens within the first 100 lines of the top field.
1142
 
                 * Make 4 attempts to sync to the decoder before giving up.
1143
 
                 */
1144
 
                for (f = 0; f < 4; f++) {
1145
 
                        prepare_to_wait(&itv->vsync_waitq, &wait,
1146
 
                                        TASK_UNINTERRUPTIBLE);
1147
 
                        if ((read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16) < 100)
1148
 
                                break;
1149
 
                        schedule_timeout(msecs_to_jiffies(25));
1150
 
                }
1151
 
                finish_wait(&itv->vsync_waitq, &wait);
1152
 
 
1153
 
                if (f == 4)
1154
 
                        IVTV_WARN("Mode change failed to sync to decoder\n");
1155
 
 
1156
 
                ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1157
 
                itv->main_rect.left = itv->main_rect.top = 0;
1158
 
                itv->main_rect.width = 720;
1159
 
                itv->main_rect.height = itv->cxhdl.height;
1160
 
                ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1161
 
                        720, itv->main_rect.height, 0, 0);
1162
 
                yi->main_rect = itv->main_rect;
1163
 
                if (!itv->osd_info) {
1164
 
                        yi->osd_full_w = 720;
1165
 
                        yi->osd_full_h = itv->is_out_50hz ? 576 : 480;
1166
 
                }
1167
 
        }
 
1091
}
 
1092
 
 
1093
void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id *std)
 
1094
{
 
1095
        struct yuv_playback_info *yi = &itv->yuv_info;
 
1096
        DEFINE_WAIT(wait);
 
1097
        int f;
 
1098
 
 
1099
        /* set display standard */
 
1100
        itv->std_out = *std;
 
1101
        itv->is_out_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
 
1102
        itv->is_out_50hz = !itv->is_out_60hz;
 
1103
        ivtv_call_all(itv, video, s_std_output, itv->std_out);
 
1104
 
 
1105
        /*
 
1106
         * The next firmware call is time sensitive. Time it to
 
1107
         * avoid risk of a hard lock, by trying to ensure the call
 
1108
         * happens within the first 100 lines of the top field.
 
1109
         * Make 4 attempts to sync to the decoder before giving up.
 
1110
         */
 
1111
        for (f = 0; f < 4; f++) {
 
1112
                prepare_to_wait(&itv->vsync_waitq, &wait,
 
1113
                                TASK_UNINTERRUPTIBLE);
 
1114
                if ((read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16) < 100)
 
1115
                        break;
 
1116
                schedule_timeout(msecs_to_jiffies(25));
 
1117
        }
 
1118
        finish_wait(&itv->vsync_waitq, &wait);
 
1119
 
 
1120
        if (f == 4)
 
1121
                IVTV_WARN("Mode change failed to sync to decoder\n");
 
1122
 
 
1123
        ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
 
1124
        itv->main_rect.left = 0;
 
1125
        itv->main_rect.top = 0;
 
1126
        itv->main_rect.width = 720;
 
1127
        itv->main_rect.height = itv->is_out_50hz ? 576 : 480;
 
1128
        ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
 
1129
                720, itv->main_rect.height, 0, 0);
 
1130
        yi->main_rect = itv->main_rect;
 
1131
        if (!itv->osd_info) {
 
1132
                yi->osd_full_w = 720;
 
1133
                yi->osd_full_h = itv->is_out_50hz ? 576 : 480;
 
1134
        }
 
1135
}
 
1136
 
 
1137
int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
 
1138
{
 
1139
        struct ivtv *itv = fh2id(fh)->itv;
 
1140
 
 
1141
        if ((*std & V4L2_STD_ALL) == 0)
 
1142
                return -EINVAL;
 
1143
 
 
1144
        if (*std == itv->std)
 
1145
                return 0;
 
1146
 
 
1147
        if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
 
1148
            atomic_read(&itv->capturing) > 0 ||
 
1149
            atomic_read(&itv->decoding) > 0) {
 
1150
                /* Switching standard would mess with already running
 
1151
                   streams, prevent that by returning EBUSY. */
 
1152
                return -EBUSY;
 
1153
        }
 
1154
 
 
1155
        IVTV_DEBUG_INFO("Switching standard to %llx.\n",
 
1156
                (unsigned long long)itv->std);
 
1157
 
 
1158
        ivtv_s_std_enc(itv, std);
 
1159
        if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
 
1160
                ivtv_s_std_dec(itv, std);
 
1161
 
1168
1162
        return 0;
1169
1163
}
1170
1164
 
1171
1165
static int ivtv_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1172
1166
{
1173
 
        struct ivtv_open_id *id = fh;
 
1167
        struct ivtv_open_id *id = fh2id(fh);
1174
1168
        struct ivtv *itv = id->itv;
1175
1169
 
1176
1170
        if (vt->index != 0)
1183
1177
 
1184
1178
static int ivtv_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1185
1179
{
1186
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1180
        struct ivtv *itv = fh2id(fh)->itv;
1187
1181
 
1188
1182
        if (vt->index != 0)
1189
1183
                return -EINVAL;
1190
1184
 
1191
1185
        ivtv_call_all(itv, tuner, g_tuner, vt);
1192
1186
 
1193
 
        if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
 
1187
        if (vt->type == V4L2_TUNER_RADIO)
1194
1188
                strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
1195
 
                vt->type = V4L2_TUNER_RADIO;
1196
 
        } else {
 
1189
        else
1197
1190
                strlcpy(vt->name, "ivtv TV Tuner", sizeof(vt->name));
1198
 
                vt->type = V4L2_TUNER_ANALOG_TV;
1199
 
        }
1200
 
 
1201
1191
        return 0;
1202
1192
}
1203
1193
 
1204
1194
static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced_vbi_cap *cap)
1205
1195
{
1206
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1196
        struct ivtv *itv = fh2id(fh)->itv;
1207
1197
        int set = itv->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
1208
1198
        int f, l;
1209
1199
 
1233
1223
 
1234
1224
static int ivtv_g_enc_index(struct file *file, void *fh, struct v4l2_enc_idx *idx)
1235
1225
{
1236
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1226
        struct ivtv *itv = fh2id(fh)->itv;
1237
1227
        struct v4l2_enc_idx_entry *e = idx->entry;
1238
1228
        int entries;
1239
1229
        int i;
1256
1246
 
1257
1247
static int ivtv_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1258
1248
{
1259
 
        struct ivtv_open_id *id = fh;
 
1249
        struct ivtv_open_id *id = fh2id(fh);
1260
1250
        struct ivtv *itv = id->itv;
1261
1251
 
1262
1252
 
1308
1298
 
1309
1299
static int ivtv_try_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1310
1300
{
1311
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1301
        struct ivtv *itv = fh2id(fh)->itv;
1312
1302
 
1313
1303
        switch (enc->cmd) {
1314
1304
        case V4L2_ENC_CMD_START:
1338
1328
 
1339
1329
static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1340
1330
{
1341
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1331
        struct ivtv *itv = fh2id(fh)->itv;
1342
1332
        u32 data[CX2341X_MBOX_MAX_DATA];
1343
1333
        struct yuv_playback_info *yi = &itv->yuv_info;
1344
1334
 
1425
1415
 
1426
1416
static int ivtv_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1427
1417
{
1428
 
        struct ivtv_open_id *id = fh;
 
1418
        struct ivtv_open_id *id = fh2id(fh);
1429
1419
        struct ivtv *itv = id->itv;
1430
1420
        struct yuv_playback_info *yi = &itv->yuv_info;
1431
1421
 
1445
1435
 
1446
1436
static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
1447
1437
{
1448
 
        struct ivtv_open_id *id = fh;
 
1438
        struct ivtv_open_id *id = fh2id(fh);
1449
1439
        struct ivtv *itv = id->itv;
1450
1440
 
1451
1441
        if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1470
1460
 
1471
1461
static int ivtv_log_status(struct file *file, void *fh)
1472
1462
{
1473
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1463
        struct ivtv *itv = fh2id(fh)->itv;
1474
1464
        u32 data[CX2341X_MBOX_MAX_DATA];
1475
1465
 
1476
1466
        int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT;
1795
1785
        return 0;
1796
1786
}
1797
1787
 
1798
 
static long ivtv_default(struct file *file, void *fh, int cmd, void *arg)
 
1788
static long ivtv_default(struct file *file, void *fh, bool valid_prio,
 
1789
                         int cmd, void *arg)
1799
1790
{
1800
 
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
1791
        struct ivtv *itv = fh2id(fh)->itv;
 
1792
 
 
1793
        if (!valid_prio) {
 
1794
                switch (cmd) {
 
1795
                case VIDEO_PLAY:
 
1796
                case VIDEO_STOP:
 
1797
                case VIDEO_FREEZE:
 
1798
                case VIDEO_CONTINUE:
 
1799
                case VIDEO_COMMAND:
 
1800
                case VIDEO_SELECT_SOURCE:
 
1801
                case AUDIO_SET_MUTE:
 
1802
                case AUDIO_CHANNEL_SELECT:
 
1803
                case AUDIO_BILINGUAL_CHANNEL_SELECT:
 
1804
                        return -EBUSY;
 
1805
                }
 
1806
        }
1801
1807
 
1802
1808
        switch (cmd) {
1803
1809
        case VIDIOC_INT_RESET: {
1836
1842
                unsigned int cmd, unsigned long arg)
1837
1843
{
1838
1844
        struct video_device *vfd = video_devdata(filp);
1839
 
        struct ivtv_open_id *id = fh2id(filp->private_data);
1840
1845
        long ret;
1841
1846
 
1842
 
        /* check priority */
1843
 
        switch (cmd) {
1844
 
        case VIDIOC_S_CTRL:
1845
 
        case VIDIOC_S_STD:
1846
 
        case VIDIOC_S_INPUT:
1847
 
        case VIDIOC_S_OUTPUT:
1848
 
        case VIDIOC_S_TUNER:
1849
 
        case VIDIOC_S_FREQUENCY:
1850
 
        case VIDIOC_S_FMT:
1851
 
        case VIDIOC_S_CROP:
1852
 
        case VIDIOC_S_AUDIO:
1853
 
        case VIDIOC_S_AUDOUT:
1854
 
        case VIDIOC_S_EXT_CTRLS:
1855
 
        case VIDIOC_S_FBUF:
1856
 
        case VIDIOC_S_PRIORITY:
1857
 
        case VIDIOC_OVERLAY:
1858
 
                ret = v4l2_prio_check(&itv->prio, id->prio);
1859
 
                if (ret)
1860
 
                        return ret;
1861
 
        }
1862
 
 
1863
1847
        if (ivtv_debug & IVTV_DBGFLG_IOCTL)
1864
1848
                vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
1865
1849
        ret = video_ioctl2(filp, cmd, arg);
1884
1868
 
1885
1869
static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1886
1870
        .vidioc_querycap                    = ivtv_querycap,
1887
 
        .vidioc_g_priority                  = ivtv_g_priority,
1888
 
        .vidioc_s_priority                  = ivtv_s_priority,
1889
1871
        .vidioc_s_audio                     = ivtv_s_audio,
1890
1872
        .vidioc_g_audio                     = ivtv_g_audio,
1891
1873
        .vidioc_enumaudio                   = ivtv_enumaudio,