Lines Matching full:cx
282 static void cx18_iounmap(struct cx18 *cx)
284 if (!cx)
288 if (cx->enc_mem) {
290 iounmap(cx->enc_mem);
291 cx->enc_mem = NULL;
295 static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
310 void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
322 c->adapter = &cx->i2c_adap[0];
328 switch (cx->card->type) {
337 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
343 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
351 static void cx18_process_eeprom(struct cx18 *cx)
355 cx18_read_eeprom(cx, &tv);
368 cx->card = cx18_get_card(CX18_CARD_HVR_1600_S5H1411);
382 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
395 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
399 cx->v4l2_cap = cx->card->v4l2_capabilities;
400 cx->card_name = cx->card->name;
401 cx->card_i2c = cx->card->i2c;
403 CX18_INFO("Autodetected %s\n", cx->card_name);
408 if (cx->options.tuner == -1)
409 cx->options.tuner = tv.tuner_type;
410 if (cx->options.radio == -1)
411 cx->options.radio = (tv.has_radio != 0);
413 if (cx->std != 0)
426 cx->std = V4L2_STD_ALL;
429 cx->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
432 cx->std |= V4L2_STD_NTSC_M;
435 cx->std |= V4L2_STD_SECAM_L;
438 cx->std |= V4L2_STD_NTSC_M;
442 static v4l2_std_id cx18_parse_std(struct cx18 *cx)
524 static void cx18_process_options(struct cx18 *cx)
528 cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers;
529 cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers;
530 cx->options.megabytes[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_buffers;
531 cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers;
532 cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers;
533 cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
534 cx->options.megabytes[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control only */
536 cx->stream_buffers[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufs;
537 cx->stream_buffers[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufs;
538 cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufs;
539 cx->stream_buffers[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufs;
540 cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_bufs;
541 cx->stream_buffers[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufs;
542 cx->stream_buffers[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control, no data */
544 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufsize;
545 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize;
546 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize;
547 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize;
548 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = VBI_ACTIVE_SAMPLES * 36;
549 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize;
550 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */
554 if (cx->stream_buffers[i] == 0 || /* User said 0 buffers */
555 cx->options.megabytes[i] <= 0 || /* User said 0 MB total */
556 cx->stream_buf_size[i] <= 0) { /* User said buf size 0 */
557 cx->options.megabytes[i] = 0;
558 cx->stream_buffers[i] = 0;
559 cx->stream_buf_size[i] = 0;
573 cx->stream_buf_size[i] *= 1024;
574 cx->stream_buf_size[i] -=
575 (cx->stream_buf_size[i] % CX18_UNIT_ENC_YUV_BUFSIZE);
577 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE)
578 cx->stream_buf_size[i] =
581 cx->stream_buf_size[i] *= 1024;
582 cx->stream_buf_size[i] -=
583 (cx->stream_buf_size[i] % CX18_UNIT_ENC_IDX_BUFSIZE);
585 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_IDX_BUFSIZE)
586 cx->stream_buf_size[i] =
598 if (cx->stream_buffers[i] < 0) {
599 cx->stream_buffers[i] =
600 cx->options.megabytes[i] * 1024 * 1024
601 / cx->stream_buf_size[i];
604 cx->options.megabytes[i] =
605 cx->stream_buffers[i]
606 * cx->stream_buf_size[i]/(1024 * 1024);
610 if (cx->stream_buffers[i] < 0) {
611 cx->stream_buffers[i] =
612 cx->options.megabytes[i] * 1024
613 / cx->stream_buf_size[i];
616 cx->options.megabytes[i] =
617 cx->stream_buffers[i]
618 * cx->stream_buf_size[i] / 1024;
621 cx->stream_buf_size[i] *= 1024;
624 i, cx->options.megabytes[i],
625 cx->stream_buffers[i], cx->stream_buf_size[i]);
628 cx->options.cardtype = cardtype[cx->instance];
629 cx->options.tuner = tuner[cx->instance];
630 cx->options.radio = radio[cx->instance];
632 cx->std = cx18_parse_std(cx);
633 if (cx->options.cardtype == -1) {
637 cx->card = cx18_get_card(cx->options.cardtype - 1);
638 if (cx->card)
639 CX18_INFO("User specified %s card\n", cx->card->name);
640 else if (cx->options.cardtype != 0)
642 if (!cx->card) {
643 if (cx->pci_dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) {
644 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
648 if (!cx->card) {
649 for (i = 0; (cx->card = cx18_get_card(i)); i++) {
650 if (!cx->card->pci_list)
652 for (j = 0; cx->card->pci_list[j].device; j++) {
653 if (cx->pci_dev->device !=
654 cx->card->pci_list[j].device)
656 if (cx->pci_dev->subsystem_vendor !=
657 cx->card->pci_list[j].subsystem_vendor)
659 if (cx->pci_dev->subsystem_device !=
660 cx->card->pci_list[j].subsystem_device)
662 CX18_INFO("Autodetected %s card\n", cx->card->name);
669 if (!cx->card) {
670 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
672 cx->pci_dev->vendor, cx->pci_dev->device);
674 cx->pci_dev->subsystem_vendor,
675 cx->pci_dev->subsystem_device);
676 CX18_ERR("Defaulting to %s card\n", cx->card->name);
681 cx->v4l2_cap = cx->card->v4l2_capabilities;
682 cx->card_name = cx->card->name;
683 cx->card_i2c = cx->card->i2c;
686 static int cx18_create_in_workq(struct cx18 *cx)
688 snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in",
689 cx->v4l2_dev.name);
690 cx->in_work_queue = alloc_ordered_workqueue("%s", 0, cx->in_workq_name);
691 if (!cx->in_work_queue) {
698 static void cx18_init_in_work_orders(struct cx18 *cx)
702 cx->in_work_order[i].cx = cx;
703 cx->in_work_order[i].str = cx->epu_debug_str;
704 INIT_WORK(&cx->in_work_order[i].work, cx18_in_work_handler);
713 static int cx18_init_struct1(struct cx18 *cx)
717 cx->base_addr = pci_resource_start(cx->pci_dev, 0);
719 mutex_init(&cx->serialize_lock);
720 mutex_init(&cx->gpio_lock);
721 mutex_init(&cx->epu2apu_mb_lock);
722 mutex_init(&cx->epu2cpu_mb_lock);
724 ret = cx18_create_in_workq(cx);
728 cx18_init_in_work_orders(cx);
731 cx->open_id = 1;
734 cx->cxhdl.port = CX2341X_PORT_MEMORY;
735 cx->cxhdl.capabilities = CX2341X_CAP_HAS_TS | CX2341X_CAP_HAS_SLICED_VBI;
736 cx->cxhdl.ops = &cx18_cxhdl_ops;
737 cx->cxhdl.func = cx18_api_func;
738 cx->cxhdl.priv = &cx->streams[CX18_ENC_STREAM_TYPE_MPG];
739 ret = cx2341x_handler_init(&cx->cxhdl, 50);
742 cx->v4l2_dev.ctrl_handler = &cx->cxhdl.hdl;
744 cx->temporal_strength = cx->cxhdl.video_temporal_filter->cur.val;
745 cx->spatial_strength = cx->cxhdl.video_spatial_filter->cur.val;
746 cx->filter_mode = cx->cxhdl.video_spatial_filter_mode->cur.val |
747 (cx->cxhdl.video_temporal_filter_mode->cur.val << 1) |
748 (cx->cxhdl.video_median_filter_type->cur.val << 2);
750 init_waitqueue_head(&cx->cap_w);
751 init_waitqueue_head(&cx->mb_apu_waitq);
752 init_waitqueue_head(&cx->mb_cpu_waitq);
753 init_waitqueue_head(&cx->dma_waitq);
756 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
757 cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced;
760 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_buf.list);
761 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.list);
762 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.buf_list);
763 list_add(&cx->vbi.sliced_mpeg_buf.list,
764 &cx->vbi.sliced_mpeg_mdl.buf_list);
770 static void cx18_init_struct2(struct cx18 *cx)
775 if (cx->card->video_inputs[i].video_type == 0)
777 cx->nof_inputs = i;
779 if (cx->card->audio_inputs[i].audio_type == 0)
781 cx->nof_audio_inputs = i;
784 for (i = 0; i < cx->nof_inputs; i++) {
785 if (cx->card->video_inputs[i].video_type ==
789 if (i == cx->nof_inputs)
791 cx->active_input = i;
792 cx->audio_input = cx->card->video_inputs[i].audio_index;
795 static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *pci_dev,
804 CX18_ERR("Can't enable device %d!\n", cx->instance);
808 CX18_ERR("No suitable DMA available, card %d\n", cx->instance);
811 if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) {
813 cx->instance);
822 cx->card_rev = pci_dev->revision;
832 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, irq: %d, latency: %d, memory: 0x%llx\n",
833 cx->pci_dev->device, cx->card_rev, pci_dev->bus->number,
835 cx->pci_dev->irq, pci_latency, (u64)cx->base_addr);
840 static void cx18_init_subdevs(struct cx18 *cx)
842 u32 hw = cx->card->hw_all;
855 cx->hw_flags |= device;
860 cx->hw_flags |= device;
869 if (cx18_gpio_register(cx, device) == 0)
870 cx->hw_flags |= device;
873 if (cx18_i2c_register(cx, i) == 0)
874 cx->hw_flags |= device;
879 if (cx->hw_flags & CX18_HW_418_AV)
880 cx->sd_av = cx18_find_hw(cx, CX18_HW_418_AV);
882 if (cx->card->hw_muxer != 0)
883 cx->sd_extmux = cx18_find_hw(cx, cx->card->hw_muxer);
892 struct cx18 *cx;
902 cx = kzalloc(sizeof(*cx), GFP_KERNEL);
903 if (!cx)
906 cx->pci_dev = pci_dev;
907 cx->instance = i;
909 retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev);
912 cx->instance);
913 kfree(cx);
916 snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d",
917 cx->instance);
918 CX18_INFO("Initializing card %d\n", cx->instance);
920 cx18_process_options(cx);
921 if (cx->options.cardtype == -1) {
926 retval = cx18_init_struct1(cx);
930 CX18_DEBUG_INFO("base addr: 0x%llx\n", (u64)cx->base_addr);
933 retval = cx18_setup_pci(cx, pci_dev, pci_id);
939 (u64)cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE);
940 cx->enc_mem = ioremap(cx->base_addr + CX18_MEM_OFFSET,
942 if (!cx->enc_mem) {
950 cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET;
951 devtype = cx18_read_reg(cx, 0xC72028);
964 cx18_init_power(cx, 1);
965 cx18_init_memory(cx);
967 cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET);
968 cx18_init_scb(cx);
970 cx18_gpio_init(cx);
973 retval = cx18_av_probe(cx);
980 if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) {
981 if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0)
984 cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL;
989 retval = init_cx18_i2c(cx);
995 if (cx->card->hw_all & CX18_HW_TVEEPROM) {
998 const struct cx18_card *orig_card = cx->card;
999 cx18_process_eeprom(cx);
1001 if (cx->card != orig_card) {
1003 cx18_gpio_init(cx);
1004 cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
1008 if (cx->card->comment)
1009 CX18_INFO("%s", cx->card->comment);
1010 if (cx->card->v4l2_capabilities == 0) {
1014 cx18_init_memory(cx);
1015 cx18_init_scb(cx);
1018 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
1019 IRQF_SHARED, cx->v4l2_dev.name, (void *)cx);
1025 if (cx->std == 0)
1026 cx->std = V4L2_STD_NTSC_M;
1028 if (cx->options.tuner == -1) {
1030 if ((cx->std & cx->card->tuners[i].std) == 0)
1032 cx->options.tuner = cx->card->tuners[i].tuner;
1037 if (cx->options.tuner == -1 && cx->card->tuners[0].std) {
1038 cx->std = cx->card->tuners[0].std;
1039 if (cx->std & V4L2_STD_PAL)
1040 cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
1041 else if (cx->std & V4L2_STD_NTSC)
1042 cx->std = V4L2_STD_NTSC_M;
1043 else if (cx->std & V4L2_STD_SECAM)
1044 cx->std = V4L2_STD_SECAM_L;
1045 cx->options.tuner = cx->card->tuners[0].tuner;
1047 if (cx->options.radio == -1)
1048 cx->options.radio = (cx->card->radio_input.audio_type != 0);
1052 cx18_init_struct2(cx);
1054 cx18_init_subdevs(cx);
1056 if (cx->std & V4L2_STD_525_60)
1057 cx->is_60hz = 1;
1059 cx->is_50hz = 1;
1061 cx2341x_handler_set_50hz(&cx->cxhdl, !cx->is_60hz);
1063 if (cx->options.radio > 0)
1064 cx->v4l2_cap |= V4L2_CAP_RADIO;
1066 if (cx->options.tuner > -1) {
1070 setup.type = cx->options.tuner;
1073 if (cx->options.radio > 0)
1077 cx18_call_all(cx, tuner, s_type_addr, &setup);
1084 .tuner = cx->options.tuner,
1087 cx18_call_all(cx, tuner, s_config, &cfg);
1093 cx->tuner_std = cx->std;
1094 if (cx->std == V4L2_STD_ALL)
1095 cx->std = V4L2_STD_NTSC_M;
1097 retval = cx18_streams_setup(cx);
1102 retval = cx18_streams_register(cx);
1108 CX18_INFO("Initialized card: %s\n", cx->card_name);
1111 request_modules(cx);
1115 cx18_streams_cleanup(cx, 1);
1117 free_irq(cx->pci_dev->irq, (void *)cx);
1119 exit_cx18_i2c(cx);
1121 cx18_iounmap(cx);
1123 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1125 destroy_workqueue(cx->in_work_queue);
1129 v4l2_device_unregister(&cx->v4l2_dev);
1130 kfree(cx);
1134 int cx18_init_on_first_open(struct cx18 *cx)
1142 fh.cx = cx;
1144 if (test_bit(CX18_F_I_FAILED, &cx->i_flags))
1147 if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags))
1152 if (cx18_firmware_init(cx) == 0)
1159 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1162 set_bit(CX18_F_I_LOADED_FW, &cx->i_flags);
1176 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1177 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1178 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1183 if (cx18_firmware_init(cx) == 0)
1190 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1203 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1204 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1205 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1208 v4l2_subdev_call(cx->sd_av, core, load_fw);
1216 if (cx->std == V4L2_STD_NTSC_M_JP)
1218 else if (cx->std & V4L2_STD_NTSC_M)
1221 video_input = cx->active_input;
1222 cx->active_input++; /* Force update of input */
1227 cx->std++; /* Force full standard initialization */
1228 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
1234 static void cx18_cancel_in_work_orders(struct cx18 *cx)
1238 cancel_work_sync(&cx->in_work_order[i].work);
1241 static void cx18_cancel_out_work_orders(struct cx18 *cx)
1245 if (cx->streams[i].video_dev.v4l2_dev)
1246 cancel_work_sync(&cx->streams[i].out_work_order);
1252 struct cx18 *cx = to_cx18(v4l2_dev);
1257 flush_request_modules(cx);
1261 if (atomic_read(&cx->tot_capturing) > 0)
1262 cx18_stop_all_captures(cx);
1265 cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
1268 cx18_cancel_in_work_orders(cx);
1269 cx18_cancel_out_work_orders(cx);
1272 cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
1274 cx18_halt_firmware(cx);
1276 destroy_workqueue(cx->in_work_queue);
1278 cx18_streams_cleanup(cx, 1);
1280 exit_cx18_i2c(cx);
1282 free_irq(cx->pci_dev->irq, (void *)cx);
1284 cx18_iounmap(cx);
1286 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1288 pci_disable_device(cx->pci_dev);
1290 if (cx->vbi.sliced_mpeg_data[0])
1292 kfree(cx->vbi.sliced_mpeg_data[i]);
1294 v4l2_ctrl_handler_free(&cx->av_state.hdl);
1296 CX18_INFO("Removed %s\n", cx->card_name);
1299 kfree(cx);