Lines Matching refs:cx
283 static void cx18_iounmap(struct cx18 *cx)
285 if (!cx)
289 if (cx->enc_mem) {
291 iounmap(cx->enc_mem);
292 cx->enc_mem = NULL;
296 static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
311 void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
323 c->adapter = &cx->i2c_adap[0];
329 switch (cx->card->type) {
338 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
344 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
352 static void cx18_process_eeprom(struct cx18 *cx)
356 cx18_read_eeprom(cx, &tv);
369 cx->card = cx18_get_card(CX18_CARD_HVR_1600_S5H1411);
383 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
396 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
400 cx->v4l2_cap = cx->card->v4l2_capabilities;
401 cx->card_name = cx->card->name;
402 cx->card_i2c = cx->card->i2c;
404 CX18_INFO("Autodetected %s\n", cx->card_name);
409 if (cx->options.tuner == -1)
410 cx->options.tuner = tv.tuner_type;
411 if (cx->options.radio == -1)
412 cx->options.radio = (tv.has_radio != 0);
414 if (cx->std != 0)
427 cx->std = V4L2_STD_ALL;
430 cx->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
433 cx->std |= V4L2_STD_NTSC_M;
436 cx->std |= V4L2_STD_SECAM_L;
439 cx->std |= V4L2_STD_NTSC_M;
443 static v4l2_std_id cx18_parse_std(struct cx18 *cx)
525 static void cx18_process_options(struct cx18 *cx)
529 cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers;
530 cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers;
531 cx->options.megabytes[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_buffers;
532 cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers;
533 cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers;
534 cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
535 cx->options.megabytes[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control only */
537 cx->stream_buffers[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufs;
538 cx->stream_buffers[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufs;
539 cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufs;
540 cx->stream_buffers[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufs;
541 cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_bufs;
542 cx->stream_buffers[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufs;
543 cx->stream_buffers[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control, no data */
545 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufsize;
546 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize;
547 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize;
548 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize;
549 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = VBI_ACTIVE_SAMPLES * 36;
550 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize;
551 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */
555 if (cx->stream_buffers[i] == 0 || /* User said 0 buffers */
556 cx->options.megabytes[i] <= 0 || /* User said 0 MB total */
557 cx->stream_buf_size[i] <= 0) { /* User said buf size 0 */
558 cx->options.megabytes[i] = 0;
559 cx->stream_buffers[i] = 0;
560 cx->stream_buf_size[i] = 0;
574 cx->stream_buf_size[i] *= 1024;
575 cx->stream_buf_size[i] -=
576 (cx->stream_buf_size[i] % CX18_UNIT_ENC_YUV_BUFSIZE);
578 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE)
579 cx->stream_buf_size[i] =
582 cx->stream_buf_size[i] *= 1024;
583 cx->stream_buf_size[i] -=
584 (cx->stream_buf_size[i] % CX18_UNIT_ENC_IDX_BUFSIZE);
586 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_IDX_BUFSIZE)
587 cx->stream_buf_size[i] =
599 if (cx->stream_buffers[i] < 0) {
600 cx->stream_buffers[i] =
601 cx->options.megabytes[i] * 1024 * 1024
602 / cx->stream_buf_size[i];
605 cx->options.megabytes[i] =
606 cx->stream_buffers[i]
607 * cx->stream_buf_size[i]/(1024 * 1024);
611 if (cx->stream_buffers[i] < 0) {
612 cx->stream_buffers[i] =
613 cx->options.megabytes[i] * 1024
614 / cx->stream_buf_size[i];
617 cx->options.megabytes[i] =
618 cx->stream_buffers[i]
619 * cx->stream_buf_size[i] / 1024;
622 cx->stream_buf_size[i] *= 1024;
625 i, cx->options.megabytes[i],
626 cx->stream_buffers[i], cx->stream_buf_size[i]);
629 cx->options.cardtype = cardtype[cx->instance];
630 cx->options.tuner = tuner[cx->instance];
631 cx->options.radio = radio[cx->instance];
633 cx->std = cx18_parse_std(cx);
634 if (cx->options.cardtype == -1) {
638 cx->card = cx18_get_card(cx->options.cardtype - 1);
639 if (cx->card)
640 CX18_INFO("User specified %s card\n", cx->card->name);
641 else if (cx->options.cardtype != 0)
643 if (!cx->card) {
644 if (cx->pci_dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) {
645 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
649 if (!cx->card) {
650 for (i = 0; (cx->card = cx18_get_card(i)); i++) {
651 if (!cx->card->pci_list)
653 for (j = 0; cx->card->pci_list[j].device; j++) {
654 if (cx->pci_dev->device !=
655 cx->card->pci_list[j].device)
657 if (cx->pci_dev->subsystem_vendor !=
658 cx->card->pci_list[j].subsystem_vendor)
660 if (cx->pci_dev->subsystem_device !=
661 cx->card->pci_list[j].subsystem_device)
663 CX18_INFO("Autodetected %s card\n", cx->card->name);
670 if (!cx->card) {
671 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
673 cx->pci_dev->vendor, cx->pci_dev->device);
675 cx->pci_dev->subsystem_vendor,
676 cx->pci_dev->subsystem_device);
677 CX18_ERR("Defaulting to %s card\n", cx->card->name);
682 cx->v4l2_cap = cx->card->v4l2_capabilities;
683 cx->card_name = cx->card->name;
684 cx->card_i2c = cx->card->i2c;
687 static int cx18_create_in_workq(struct cx18 *cx)
689 snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in",
690 cx->v4l2_dev.name);
691 cx->in_work_queue = alloc_ordered_workqueue("%s", 0, cx->in_workq_name);
692 if (!cx->in_work_queue) {
699 static void cx18_init_in_work_orders(struct cx18 *cx)
703 cx->in_work_order[i].cx = cx;
704 cx->in_work_order[i].str = cx->epu_debug_str;
705 INIT_WORK(&cx->in_work_order[i].work, cx18_in_work_handler);
714 static int cx18_init_struct1(struct cx18 *cx)
718 cx->base_addr = pci_resource_start(cx->pci_dev, 0);
720 mutex_init(&cx->serialize_lock);
721 mutex_init(&cx->gpio_lock);
722 mutex_init(&cx->epu2apu_mb_lock);
723 mutex_init(&cx->epu2cpu_mb_lock);
725 ret = cx18_create_in_workq(cx);
729 cx18_init_in_work_orders(cx);
732 cx->open_id = 1;
735 cx->cxhdl.port = CX2341X_PORT_MEMORY;
736 cx->cxhdl.capabilities = CX2341X_CAP_HAS_TS | CX2341X_CAP_HAS_SLICED_VBI;
737 cx->cxhdl.ops = &cx18_cxhdl_ops;
738 cx->cxhdl.func = cx18_api_func;
739 cx->cxhdl.priv = &cx->streams[CX18_ENC_STREAM_TYPE_MPG];
740 ret = cx2341x_handler_init(&cx->cxhdl, 50);
743 cx->v4l2_dev.ctrl_handler = &cx->cxhdl.hdl;
745 cx->temporal_strength = cx->cxhdl.video_temporal_filter->cur.val;
746 cx->spatial_strength = cx->cxhdl.video_spatial_filter->cur.val;
747 cx->filter_mode = cx->cxhdl.video_spatial_filter_mode->cur.val |
748 (cx->cxhdl.video_temporal_filter_mode->cur.val << 1) |
749 (cx->cxhdl.video_median_filter_type->cur.val << 2);
751 init_waitqueue_head(&cx->cap_w);
752 init_waitqueue_head(&cx->mb_apu_waitq);
753 init_waitqueue_head(&cx->mb_cpu_waitq);
754 init_waitqueue_head(&cx->dma_waitq);
757 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
758 cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced;
761 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_buf.list);
762 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.list);
763 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.buf_list);
764 list_add(&cx->vbi.sliced_mpeg_buf.list,
765 &cx->vbi.sliced_mpeg_mdl.buf_list);
771 static void cx18_init_struct2(struct cx18 *cx)
776 if (cx->card->video_inputs[i].video_type == 0)
778 cx->nof_inputs = i;
780 if (cx->card->audio_inputs[i].audio_type == 0)
782 cx->nof_audio_inputs = i;
785 for (i = 0; i < cx->nof_inputs; i++) {
786 if (cx->card->video_inputs[i].video_type ==
790 if (i == cx->nof_inputs)
792 cx->active_input = i;
793 cx->audio_input = cx->card->video_inputs[i].audio_index;
796 static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *pci_dev,
805 CX18_ERR("Can't enable device %d!\n", cx->instance);
809 CX18_ERR("No suitable DMA available, card %d\n", cx->instance);
812 if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) {
814 cx->instance);
823 cx->card_rev = pci_dev->revision;
833 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, irq: %d, latency: %d, memory: 0x%llx\n",
834 cx->pci_dev->device, cx->card_rev, pci_dev->bus->number,
836 cx->pci_dev->irq, pci_latency, (u64)cx->base_addr);
841 static void cx18_init_subdevs(struct cx18 *cx)
843 u32 hw = cx->card->hw_all;
856 cx->hw_flags |= device;
861 cx->hw_flags |= device;
870 if (cx18_gpio_register(cx, device) == 0)
871 cx->hw_flags |= device;
874 if (cx18_i2c_register(cx, i) == 0)
875 cx->hw_flags |= device;
880 if (cx->hw_flags & CX18_HW_418_AV)
881 cx->sd_av = cx18_find_hw(cx, CX18_HW_418_AV);
883 if (cx->card->hw_muxer != 0)
884 cx->sd_extmux = cx18_find_hw(cx, cx->card->hw_muxer);
893 struct cx18 *cx;
903 cx = kzalloc(sizeof(*cx), GFP_ATOMIC);
904 if (!cx)
907 cx->pci_dev = pci_dev;
908 cx->instance = i;
910 retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev);
913 cx->instance);
914 kfree(cx);
917 snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d",
918 cx->instance);
919 CX18_INFO("Initializing card %d\n", cx->instance);
921 cx18_process_options(cx);
922 if (cx->options.cardtype == -1) {
927 retval = cx18_init_struct1(cx);
931 CX18_DEBUG_INFO("base addr: 0x%llx\n", (u64)cx->base_addr);
934 retval = cx18_setup_pci(cx, pci_dev, pci_id);
940 (u64)cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE);
941 cx->enc_mem = ioremap(cx->base_addr + CX18_MEM_OFFSET,
943 if (!cx->enc_mem) {
951 cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET;
952 devtype = cx18_read_reg(cx, 0xC72028);
965 cx18_init_power(cx, 1);
966 cx18_init_memory(cx);
968 cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET);
969 cx18_init_scb(cx);
971 cx18_gpio_init(cx);
974 retval = cx18_av_probe(cx);
981 if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) {
982 if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0)
985 cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL;
990 retval = init_cx18_i2c(cx);
996 if (cx->card->hw_all & CX18_HW_TVEEPROM) {
999 const struct cx18_card *orig_card = cx->card;
1000 cx18_process_eeprom(cx);
1002 if (cx->card != orig_card) {
1004 cx18_gpio_init(cx);
1005 cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
1009 if (cx->card->comment)
1010 CX18_INFO("%s", cx->card->comment);
1011 if (cx->card->v4l2_capabilities == 0) {
1015 cx18_init_memory(cx);
1016 cx18_init_scb(cx);
1019 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
1020 IRQF_SHARED, cx->v4l2_dev.name, (void *)cx);
1026 if (cx->std == 0)
1027 cx->std = V4L2_STD_NTSC_M;
1029 if (cx->options.tuner == -1) {
1031 if ((cx->std & cx->card->tuners[i].std) == 0)
1033 cx->options.tuner = cx->card->tuners[i].tuner;
1038 if (cx->options.tuner == -1 && cx->card->tuners[0].std) {
1039 cx->std = cx->card->tuners[0].std;
1040 if (cx->std & V4L2_STD_PAL)
1041 cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
1042 else if (cx->std & V4L2_STD_NTSC)
1043 cx->std = V4L2_STD_NTSC_M;
1044 else if (cx->std & V4L2_STD_SECAM)
1045 cx->std = V4L2_STD_SECAM_L;
1046 cx->options.tuner = cx->card->tuners[0].tuner;
1048 if (cx->options.radio == -1)
1049 cx->options.radio = (cx->card->radio_input.audio_type != 0);
1053 cx18_init_struct2(cx);
1055 cx18_init_subdevs(cx);
1057 if (cx->std & V4L2_STD_525_60)
1058 cx->is_60hz = 1;
1060 cx->is_50hz = 1;
1062 cx2341x_handler_set_50hz(&cx->cxhdl, !cx->is_60hz);
1064 if (cx->options.radio > 0)
1065 cx->v4l2_cap |= V4L2_CAP_RADIO;
1067 if (cx->options.tuner > -1) {
1071 setup.type = cx->options.tuner;
1074 if (cx->options.radio > 0)
1078 cx18_call_all(cx, tuner, s_type_addr, &setup);
1085 .tuner = cx->options.tuner,
1088 cx18_call_all(cx, tuner, s_config, &cfg);
1094 cx->tuner_std = cx->std;
1095 if (cx->std == V4L2_STD_ALL)
1096 cx->std = V4L2_STD_NTSC_M;
1098 retval = cx18_streams_setup(cx);
1103 retval = cx18_streams_register(cx);
1109 CX18_INFO("Initialized card: %s\n", cx->card_name);
1112 request_modules(cx);
1116 cx18_streams_cleanup(cx, 1);
1118 free_irq(cx->pci_dev->irq, (void *)cx);
1120 exit_cx18_i2c(cx);
1122 cx18_iounmap(cx);
1124 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1126 destroy_workqueue(cx->in_work_queue);
1130 v4l2_device_unregister(&cx->v4l2_dev);
1131 kfree(cx);
1135 int cx18_init_on_first_open(struct cx18 *cx)
1143 fh.cx = cx;
1145 if (test_bit(CX18_F_I_FAILED, &cx->i_flags))
1148 if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags))
1153 if (cx18_firmware_init(cx) == 0)
1160 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1163 set_bit(CX18_F_I_LOADED_FW, &cx->i_flags);
1177 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1178 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1179 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1184 if (cx18_firmware_init(cx) == 0)
1191 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1204 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1205 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1206 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1209 v4l2_subdev_call(cx->sd_av, core, load_fw);
1217 if (cx->std == V4L2_STD_NTSC_M_JP)
1219 else if (cx->std & V4L2_STD_NTSC_M)
1222 video_input = cx->active_input;
1223 cx->active_input++; /* Force update of input */
1228 cx->std++; /* Force full standard initialization */
1229 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
1235 static void cx18_cancel_in_work_orders(struct cx18 *cx)
1239 cancel_work_sync(&cx->in_work_order[i].work);
1242 static void cx18_cancel_out_work_orders(struct cx18 *cx)
1246 if (cx->streams[i].video_dev.v4l2_dev)
1247 cancel_work_sync(&cx->streams[i].out_work_order);
1253 struct cx18 *cx = to_cx18(v4l2_dev);
1258 flush_request_modules(cx);
1262 if (atomic_read(&cx->tot_capturing) > 0)
1263 cx18_stop_all_captures(cx);
1266 cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
1269 cx18_cancel_in_work_orders(cx);
1270 cx18_cancel_out_work_orders(cx);
1273 cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
1275 cx18_halt_firmware(cx);
1277 destroy_workqueue(cx->in_work_queue);
1279 cx18_streams_cleanup(cx, 1);
1281 exit_cx18_i2c(cx);
1283 free_irq(cx->pci_dev->irq, (void *)cx);
1285 cx18_iounmap(cx);
1287 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1289 pci_disable_device(cx->pci_dev);
1291 if (cx->vbi.sliced_mpeg_data[0])
1293 kfree(cx->vbi.sliced_mpeg_data[i]);
1295 v4l2_ctrl_handler_free(&cx->av_state.hdl);
1297 CX18_INFO("Removed %s\n", cx->card_name);
1300 kfree(cx);