Lines Matching refs:itv

310 void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask)
312 itv->irqmask &= ~mask;
313 write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);
316 void ivtv_set_irq_mask(struct ivtv *itv, u32 mask)
318 itv->irqmask |= mask;
319 write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);
322 int ivtv_set_output_mode(struct ivtv *itv, int mode)
326 spin_lock(&itv->lock);
327 old_mode = itv->output_mode;
329 itv->output_mode = old_mode = mode;
330 spin_unlock(&itv->lock);
334 struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv)
336 switch (itv->output_mode) {
338 return &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
340 return &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
375 void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv)
379 itv->i2c_client.addr = 0xA0 >> 1;
380 tveeprom_read(&itv->i2c_client, eedata, sizeof(eedata));
384 static void ivtv_process_eeprom(struct ivtv *itv)
387 int pci_slot = PCI_SLOT(itv->pdev->devfn);
389 ivtv_read_eeprom(itv, &tv);
401 itv->card = ivtv_get_card(IVTV_CARD_PVR_250);
405 itv->card = ivtv_get_card(IVTV_CARD_PVR_350);
410 itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
417 itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
425 itv->card = ivtv_get_card(IVTV_CARD_PVR_350_V1);
431 itv->v4l2_cap = itv->card->v4l2_capabilities;
432 itv->card_name = itv->card->name;
433 itv->card_i2c = itv->card->i2c;
457 itv->card_name = "WinTV PVR 500";
458 itv->card_i2c = &ivtv_i2c_radio;
462 itv->card_name = is_first ? "WinTV PVR 500 (unit #1)" :
470 IVTV_INFO("Autodetected %s\n", itv->card_name);
476 itv->pvr150_workaround = 1;
484 if (itv->options.tuner == -1)
485 itv->options.tuner = tv.tuner_type;
486 if (itv->options.radio == -1)
487 itv->options.radio = (tv.has_radio != 0);
489 if (itv->options.newi2c == -1 && tv.has_ir) {
490 itv->options.newi2c = (tv.has_ir & 4) ? 1 : 0;
491 if (itv->options.newi2c) {
493 exit_ivtv_i2c(itv);
494 init_ivtv_i2c(itv);
498 if (itv->std != 0)
505 itv->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
508 itv->std |= V4L2_STD_NTSC_M;
511 itv->std |= V4L2_STD_SECAM_L;
514 itv->std |= V4L2_STD_NTSC_M;
518 static v4l2_std_id ivtv_parse_std(struct ivtv *itv)
611 static void ivtv_process_options(struct ivtv *itv)
616 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers * 1024;
617 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers * 1024;
618 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers * 1024;
619 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
620 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers * 1024;
621 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers * 1024;
622 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers;
623 itv->options.cardtype = cardtype[itv->instance];
624 itv->options.tuner = tuner[itv->instance];
625 itv->options.radio = radio[itv->instance];
627 itv->options.i2c_clock_period = i2c_clock_period[itv->instance];
628 if (itv->options.i2c_clock_period == -1)
629 itv->options.i2c_clock_period = IVTV_DEFAULT_I2C_CLOCK_PERIOD;
630 else if (itv->options.i2c_clock_period < 10)
631 itv->options.i2c_clock_period = 10;
632 else if (itv->options.i2c_clock_period > 4500)
633 itv->options.i2c_clock_period = 4500;
635 itv->options.newi2c = newi2c;
640 itv->std = ivtv_parse_std(itv);
641 if (itv->std == 0 && tunertype >= 0)
642 itv->std = tunertype ? V4L2_STD_MN : (V4L2_STD_ALL & ~V4L2_STD_MN);
643 itv->has_cx23415 = (itv->pdev->device == PCI_DEVICE_ID_IVTV15);
644 chipname = itv->has_cx23415 ? "cx23415" : "cx23416";
645 if (itv->options.cardtype == -1) {
649 if ((itv->card = ivtv_get_card(itv->options.cardtype - 1))) {
651 itv->card->name, chipname);
652 } else if (itv->options.cardtype != 0) {
655 if (itv->card == NULL) {
656 if (itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE ||
657 itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT1 ||
658 itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT2) {
659 itv->card = ivtv_get_card(itv->has_cx23415 ? IVTV_CARD_PVR_350 : IVTV_CARD_PVR_150);
664 if (itv->card == NULL) {
665 for (i = 0; (itv->card = ivtv_get_card(i)); i++) {
666 if (itv->card->pci_list == NULL)
668 for (j = 0; itv->card->pci_list[j].device; j++) {
669 if (itv->pdev->device !=
670 itv->card->pci_list[j].device)
672 if (itv->pdev->subsystem_vendor !=
673 itv->card->pci_list[j].subsystem_vendor)
675 if (itv->pdev->subsystem_device !=
676 itv->card->pci_list[j].subsystem_device)
679 itv->card->name, chipname);
686 if (itv->card == NULL) {
687 itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
689 itv->pdev->vendor, itv->pdev->device);
691 itv->pdev->subsystem_vendor, itv->pdev->subsystem_device);
693 IVTV_ERR("Defaulting to %s card\n", itv->card->name);
698 itv->v4l2_cap = itv->card->v4l2_capabilities;
699 itv->card_name = itv->card->name;
700 itv->card_i2c = itv->card->i2c;
708 static int ivtv_init_struct1(struct ivtv *itv)
710 itv->base_addr = pci_resource_start(itv->pdev, 0);
711 itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */
712 itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */
714 mutex_init(&itv->serialize_lock);
715 mutex_init(&itv->i2c_bus_lock);
716 mutex_init(&itv->udma.lock);
718 spin_lock_init(&itv->lock);
719 spin_lock_init(&itv->dma_reg_lock);
721 kthread_init_worker(&itv->irq_worker);
722 itv->irq_worker_task = kthread_run(kthread_worker_fn, &itv->irq_worker,
723 "%s", itv->v4l2_dev.name);
724 if (IS_ERR(itv->irq_worker_task)) {
729 sched_set_fifo(itv->irq_worker_task);
731 kthread_init_work(&itv->irq_work, ivtv_irq_work_handler);
734 itv->cxhdl.port = CX2341X_PORT_MEMORY;
735 itv->cxhdl.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
736 init_waitqueue_head(&itv->eos_waitq);
737 init_waitqueue_head(&itv->event_waitq);
738 init_waitqueue_head(&itv->vsync_waitq);
739 init_waitqueue_head(&itv->dma_waitq);
740 timer_setup(&itv->dma_timer, ivtv_unfinished_dma, 0);
742 itv->cur_dma_stream = -1;
743 itv->cur_pio_stream = -1;
746 itv->speed = 1000;
749 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
750 itv->vbi.sliced_in = &itv->vbi.in.fmt.sliced;
753 sg_init_table(itv->udma.SGlist, IVTV_DMA_SG_OSD_ENT);
756 itv->osd_global_alpha_state = 1;
757 itv->osd_global_alpha = 255;
760 atomic_set(&itv->yuv_info.next_dma_frame, -1);
761 itv->yuv_info.lace_mode = ivtv_yuv_mode;
762 itv->yuv_info.lace_threshold = ivtv_yuv_threshold;
763 itv->yuv_info.max_frames_buffered = 3;
764 itv->yuv_info.track_osd = 1;
770 static void ivtv_init_struct2(struct ivtv *itv)
775 if (itv->card->video_inputs[i].video_type == 0)
777 itv->nof_inputs = i;
779 if (itv->card->audio_inputs[i].audio_type == 0)
781 itv->nof_audio_inputs = i;
783 if (itv->card->hw_all & IVTV_HW_CX25840) {
784 itv->vbi.sliced_size = 288; /* multiple of 16, real size = 284 */
786 itv->vbi.sliced_size = 64; /* multiple of 16, real size = 52 */
790 for (i = 0; i < itv->nof_inputs; i++) {
791 if (itv->card->video_inputs[i].video_type ==
795 if (i >= itv->nof_inputs)
797 itv->active_input = i;
798 itv->audio_input = itv->card->video_inputs[i].audio_index;
801 static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *pdev,
817 if (!devm_request_mem_region(&pdev->dev, itv->base_addr,
824 itv->base_addr + IVTV_REG_OFFSET,
830 if (itv->has_cx23415 &&
832 itv->base_addr + IVTV_DECODER_OFFSET,
868 pdev->irq, pci_latency, (u64)itv->base_addr);
873 static void ivtv_load_and_init_modules(struct ivtv *itv)
875 u32 hw = itv->card->hw_all;
886 itv->hw_flags |= device;
889 if (ivtv_i2c_register(itv, i) == 0)
890 itv->hw_flags |= device;
894 if ((itv->hw_flags & IVTV_HW_IR_ANY) == 0)
895 ivtv_i2c_new_ir_legacy(itv);
897 if (itv->card->hw_all & IVTV_HW_CX25840)
898 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_CX25840);
899 else if (itv->card->hw_all & IVTV_HW_SAA717X)
900 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA717X);
901 else if (itv->card->hw_all & IVTV_HW_SAA7114)
902 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7114);
904 itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7115);
905 itv->sd_audio = ivtv_find_hw(itv, itv->card->hw_audio_ctrl);
906 itv->sd_muxer = ivtv_find_hw(itv, itv->card->hw_muxer);
908 hw = itv->hw_flags;
910 if (itv->card->type == IVTV_CARD_CX23416GYC) {
914 itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGRYCS);
916 itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGR);
918 else if (itv->card->type == IVTV_CARD_GV_MVPRX ||
919 itv->card->type == IVTV_CARD_GV_MVPRX2E) {
921 v4l2_subdev_call(itv->sd_video, video, s_crystal_freq,
926 itv->vbi.raw_decoder_line_size = 1444;
927 itv->vbi.raw_decoder_sav_odd_field = 0x20;
928 itv->vbi.raw_decoder_sav_even_field = 0x60;
929 itv->vbi.sliced_decoder_line_size = 272;
930 itv->vbi.sliced_decoder_sav_odd_field = 0xB0;
931 itv->vbi.sliced_decoder_sav_even_field = 0xF0;
936 itv->hw_flags &= ~IVTV_HW_SAA711X;
938 if (strstr(itv->sd_video->name, "saa7114")) {
939 itv->hw_flags |= IVTV_HW_SAA7114;
941 itv->v4l2_cap &= ~(V4L2_CAP_SLICED_VBI_CAPTURE|V4L2_CAP_VBI_CAPTURE);
943 itv->hw_flags |= IVTV_HW_SAA7115;
945 itv->vbi.raw_decoder_line_size = 1443;
946 itv->vbi.raw_decoder_sav_odd_field = 0x25;
947 itv->vbi.raw_decoder_sav_even_field = 0x62;
948 itv->vbi.sliced_decoder_line_size = 51;
949 itv->vbi.sliced_decoder_sav_odd_field = 0xAB;
950 itv->vbi.sliced_decoder_sav_even_field = 0xEC;
954 itv->vbi.raw_decoder_line_size = 1443;
955 itv->vbi.raw_decoder_sav_odd_field = 0x25;
956 itv->vbi.raw_decoder_sav_even_field = 0x62;
957 itv->vbi.sliced_decoder_line_size = 51;
958 itv->vbi.sliced_decoder_sav_odd_field = 0xAB;
959 itv->vbi.sliced_decoder_sav_even_field = 0xEC;
967 struct ivtv *itv;
969 itv = kzalloc(sizeof(struct ivtv), GFP_KERNEL);
970 if (itv == NULL)
972 itv->pdev = pdev;
973 itv->instance = v4l2_device_set_name(&itv->v4l2_dev, "ivtv",
976 retval = v4l2_device_register(&pdev->dev, &itv->v4l2_dev);
978 kfree(itv);
981 IVTV_INFO("Initializing card %d\n", itv->instance);
983 ivtv_process_options(itv);
984 if (itv->options.cardtype == -1) {
988 if (ivtv_init_struct1(itv)) {
992 retval = cx2341x_handler_init(&itv->cxhdl, 50);
995 itv->v4l2_dev.ctrl_handler = &itv->cxhdl.hdl;
996 itv->cxhdl.ops = &ivtv_cxhdl_ops;
997 itv->cxhdl.priv = itv;
998 itv->cxhdl.func = ivtv_api_func;
1000 IVTV_DEBUG_INFO("base addr: 0x%llx\n", (u64)itv->base_addr);
1003 retval = ivtv_setup_pci(itv, pdev, pci_id);
1009 (u64)itv->base_addr + IVTV_ENCODER_OFFSET, IVTV_ENCODER_SIZE);
1010 itv->enc_mem = devm_ioremap(&pdev->dev,
1011 itv->base_addr + IVTV_ENCODER_OFFSET,
1013 if (!itv->enc_mem) {
1022 if (itv->has_cx23415) {
1024 (u64)itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
1025 itv->dec_mem = devm_ioremap(&pdev->dev,
1026 itv->base_addr + IVTV_DECODER_OFFSET,
1028 if (!itv->dec_mem) {
1038 itv->dec_mem = itv->enc_mem;
1043 (u64)itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
1044 itv->reg_mem = devm_ioremap(&pdev->dev,
1045 itv->base_addr + IVTV_REG_OFFSET,
1047 if (!itv->reg_mem) {
1056 retval = ivtv_gpio_init(itv);
1062 if (init_ivtv_i2c(itv)) {
1067 if (itv->card->hw_all & IVTV_HW_TVEEPROM) {
1070 ivtv_process_eeprom(itv);
1072 if (itv->card->comment)
1073 IVTV_INFO("%s", itv->card->comment);
1074 if (itv->card->v4l2_capabilities == 0) {
1080 if (itv->std == 0) {
1081 itv->std = V4L2_STD_NTSC_M;
1084 if (itv->options.tuner == -1) {
1088 if ((itv->std & itv->card->tuners[i].std) == 0)
1090 itv->options.tuner = itv->card->tuners[i].tuner;
1095 if (itv->options.tuner == -1 && itv->card->tuners[0].std) {
1096 itv->std = itv->card->tuners[0].std;
1097 if (itv->std & V4L2_STD_PAL)
1098 itv->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
1099 else if (itv->std & V4L2_STD_NTSC)
1100 itv->std = V4L2_STD_NTSC_M;
1101 else if (itv->std & V4L2_STD_SECAM)
1102 itv->std = V4L2_STD_SECAM_L;
1103 itv->options.tuner = itv->card->tuners[0].tuner;
1105 if (itv->options.radio == -1)
1106 itv->options.radio = (itv->card->radio_input.audio_type != 0);
1110 ivtv_init_struct2(itv);
1112 ivtv_load_and_init_modules(itv);
1114 if (itv->std & V4L2_STD_525_60) {
1115 itv->is_60hz = 1;
1116 itv->is_out_60hz = 1;
1118 itv->is_50hz = 1;
1119 itv->is_out_50hz = 1;
1122 itv->yuv_info.osd_full_w = 720;
1123 itv->yuv_info.osd_full_h = itv->is_out_50hz ? 576 : 480;
1124 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w;
1125 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h;
1127 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1129 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
1130 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
1131 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_MPG] = 0x10000;
1132 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = 0x10000;
1133 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = 0x08000;
1139 itv->vbi.raw_size = 1456;
1146 vbi_buf_size = itv->vbi.raw_size * (itv->is_60hz ? 24 : 36) / 2;
1147 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_VBI] = vbi_buf_size;
1148 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_VBI] = sizeof(struct v4l2_sliced_vbi_data) * 36;
1150 if (itv->options.radio > 0)
1151 itv->v4l2_cap |= V4L2_CAP_RADIO;
1153 if (itv->options.tuner > -1) {
1157 setup.type = itv->options.tuner;
1159 if (itv->options.radio > 0)
1163 ivtv_call_all(itv, tuner, s_type_addr, &setup);
1170 .tuner = itv->options.tuner,
1173 ivtv_call_all(itv, tuner, s_config, &cfg);
1179 itv->tuner_std = itv->std;
1181 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1182 struct v4l2_ctrl_handler *hdl = itv->v4l2_dev.ctrl_handler;
1184 itv->ctrl_pts = v4l2_ctrl_new_std(hdl, &ivtv_hdl_out_ops,
1186 itv->ctrl_frame = v4l2_ctrl_new_std(hdl, &ivtv_hdl_out_ops,
1190 itv->ctrl_audio_playback =
1196 itv->ctrl_audio_multilingual_playback =
1206 v4l2_ctrl_cluster(2, &itv->ctrl_pts);
1207 v4l2_ctrl_cluster(2, &itv->ctrl_audio_playback);
1208 ivtv_call_all(itv, video, s_std_output, itv->std);
1212 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
1216 ivtv_set_irq_mask(itv, 0xffffffff);
1219 retval = request_irq(itv->pdev->irq, ivtv_irq_handler,
1220 IRQF_SHARED, itv->v4l2_dev.name, (void *)itv);
1226 retval = ivtv_streams_setup(itv);
1231 retval = ivtv_streams_register(itv);
1236 IVTV_INFO("Initialized card: %s\n", itv->card_name);
1239 request_modules(itv);
1243 ivtv_streams_cleanup(itv);
1245 free_irq(itv->pdev->irq, (void *)itv);
1247 v4l2_ctrl_handler_free(&itv->cxhdl.hdl);
1248 exit_ivtv_i2c(itv);
1250 kthread_stop(itv->irq_worker_task);
1256 v4l2_device_unregister(&itv->v4l2_dev);
1257 kfree(itv);
1261 int ivtv_init_on_first_open(struct ivtv *itv)
1269 fh.itv = itv;
1272 if (test_bit(IVTV_F_I_FAILED, &itv->i_flags))
1275 if (test_and_set_bit(IVTV_F_I_INITED, &itv->i_flags))
1280 if (ivtv_firmware_init(itv) == 0)
1287 set_bit(IVTV_F_I_FAILED, &itv->i_flags);
1293 ivtv_firmware_versions(itv);
1295 if (itv->card->hw_all & IVTV_HW_CX25840)
1296 v4l2_subdev_call(itv->sd_video, core, load_fw);
1304 if (itv->std == V4L2_STD_NTSC_M_JP) {
1307 else if (itv->std & V4L2_STD_NTSC_M) {
1311 video_input = itv->active_input;
1312 itv->active_input++; /* Force update of input */
1317 itv->std++; /* Force full standard initialization */
1318 itv->std_out = itv->std;
1321 if (itv->card->v4l2_capabilities & V4L2_CAP_VIDEO_OUTPUT) {
1325 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
1326 ivtv_init_mpeg_decoder(itv);
1330 if (!itv->has_cx23415)
1333 ivtv_s_std_enc(itv, itv->tuner_std);
1340 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1341 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC);
1342 ivtv_set_osd_alpha(itv);
1343 ivtv_s_std_dec(itv, itv->tuner_std);
1345 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
1349 cx2341x_handler_setup(&itv->cxhdl);
1356 struct ivtv *itv = to_ivtv(v4l2_dev);
1361 flush_request_modules(itv);
1363 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) {
1366 if (atomic_read(&itv->capturing) > 0)
1367 ivtv_stop_all_captures(itv);
1373 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
1374 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
1375 if (atomic_read(&itv->decoding) > 0) {
1378 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
1382 ivtv_stop_v4l2_decode_stream(&itv->streams[type],
1385 ivtv_halt_firmware(itv);
1389 ivtv_set_irq_mask(itv, 0xffffffff);
1390 timer_shutdown_sync(&itv->dma_timer);
1393 kthread_flush_worker(&itv->irq_worker);
1394 kthread_stop(itv->irq_worker_task);
1396 ivtv_streams_cleanup(itv);
1397 ivtv_udma_free(itv);
1399 v4l2_ctrl_handler_free(&itv->cxhdl.hdl);
1401 exit_ivtv_i2c(itv);
1403 free_irq(itv->pdev->irq, (void *)itv);
1406 kfree(itv->vbi.sliced_mpeg_data[i]);
1408 pr_info("Removed %s\n", itv->card_name);
1410 v4l2_device_unregister(&itv->v4l2_dev);
1411 kfree(itv);